"Contestant who earns a score equal to or greater than the k-th place finisher's score will advance to the next round, as long as the contestant earns a positive score..." — an excerpt from contest rules.A total of n participants took part in the contest (n ≥ k), and you already know their scores. Calculate how many participants will advance to the next round.

The first line of the input contains two integers n and k (1 ≤ k ≤ n ≤ 50) separated by a single space. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 100), where ai is the score earned by the participant who got the i-th place. The given sequence is non-increasing (that is, for all i from 1 to n - 1 the following condition is fulfilled: ai ≥ ai + 1).

Output the number of participants who advance to the next round.

NoteIn the first example the participant on the 5th place earned 7 points. As the participant on the 6th place also earned 7 points, there are 6 advancers.In the second example nobody got a positive score.

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

void main(){
	int n, k; readf("%d %d\n", &n, &k);
	auto buf = readln.split.map!(to!int).array;
	(buf[0] == 0) ? writeln(0) : buf.count!(a => a>=buf[k-1] && a>0 ).writeln;
}

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

void main(){
	int n, k; readf("%d %d\n", &n, &k);
	auto buf = readln.split.map!(to!int).array;
	buf.count!(a => (a >= buf[k-1]) && (a > 0) ).writeln;
}

import std.stdio;

int main(string[] argv)
{
	int n, pos;
    readf(" %d %d", &n, &pos);
	int[] a = new int[n];
	for (int i = 0; i < n; ++i)
		readf(" %d", &a[i]);
	int j = pos - 1;

	if (a[j] == 0)
		while (j >= 0 && a[j] == 0)
			--j;
	else
		while (j+1 <= n-1 && a[j] == a[j+1])
			++j;

	writeln(j+1);
	readln;
    return 0;
}

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

void main() {
  string[] l1 = readln().chomp().split();
  auto n = to!int(l1[0]);
  auto k = to!int(l1[1]);
  string[] l2 = readln().chomp().split();
  auto tot = 0;
  for (auto i=0; i<k; i++) {
    if (to!int(l2[i]) > 0) {
      tot += 1;
    }
  }
  auto kv = to!int(l2[k-1]);
  if (kv > 0) {
    while (tot < n && to!int(l2[tot]) == kv) {
      tot += 1;
    }
  }
  writeln(tot);
}

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

void main() {

	byte n, k;

	readf("%s %s\n", &n, &k);

	short max, ki;
	foreach (idx, score; readln.split) {
		if (idx == k - 1)
			ki = score.to!byte;
		if (idx > k - 1 && score.to!byte < ki || score.to!byte == 0)
			break;
		++max;
	}

	writeln(max);
}

import std.stdio : readf, readln, writeln;
import std.math : ceil;
import std.conv : to;
import std.array : split;

void main()
{
    uint[] nums;
    uint n, k;
    uint counter;
    uint pass;

    readf("%s %s\n", &n, &k);

    foreach(uint i, string num; split(readln))
    {
        uint unum = to!uint(num);
        if ((i+1)==k) pass = unum;
        nums ~= unum;
    }
    foreach(num; nums)
    {
        if (num > 0 && num >= pass) ++counter;
    }

    writeln(counter);
}

import std.stdio;

void main() {
    int n, k;
    readf("%d %d\n", &n, &k);

    int[] scores = new int[n];

    for (int i = 0; i < n-1; ++i) {
        readf("%d ", &scores[i]);
    }
    readf("%d\n", &scores[n-1]);

    int kScore = scores[k-1];
    int nextRound = 0;

    for (int i = 0; i < n; ++i) {
        if (scores[i] > 0 && scores[i] >= kScore) {
            nextRound++;
        }
    }

    writefln("%d", nextRound);
}

import std.stdio;
import std.algorithm;

void main()
{
    int n, k;
    scanf("%d %d", &n, &k);

    int[] a = new int[n];

    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }

    int f = a[k - 1];

    a.sort();

    int ans = 0;

    for (int i = 0; i < n; ++i) {

        if (a[i] > 0 && a[i] >= f)
            ans++;
    }

    printf("%d\n", ans);

}

import std.stdio;
import core.stdc.stdio;
import std.conv;
import std.container;

int main(string[] argv)
{
	int n, k;
	scanf("%d %d", &n, &k);
	int[] contestants = new int[n];
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &contestants[i]);
	}
	int score = contestants[k-1];
	int result = 0;
	for (int i = 0; i < n; i++)
	{
		result += (contestants[i] > 0 && contestants[i] >= score) ? 1 : 0;
	}
	writeln(result);
	return 0;
}

import std.stdio;
void main() {
	int n, k;
	readf(" %s",&n);
	readf(" %s",&k);
	k--;
	int[] a = new int[n];
	for (int i = 0; i < n; i++) {
		readf(" %s",&a[i]);
	}
	a = a.sort.reverse;
	//writeln(a);
	int answer = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] > 0 && a[i] >= a[k]) {
			answer++;
		}
	}
	writeln(answer);
}

// https://codeforces.com/problemset/problem/158/A
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

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

    string input = readln;
    int[] a = input.split.map!(x => x.to!int).array;

    a.filter!(x => (x >= a[k-1]) && (x > 0)).count.writeln;
}

// https://codeforces.com/problemset/problem/158/A
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

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

    string input = readln;
    int[] a = input.split.map!(x => x.to!int).array;

    a.count!(x => (x >= a[k-1]) && (x > 0)).writeln;
}

//ahmat
import core.stdc.stdio:scanf,printf,puts;
import core.bitop;
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.container;
pragma(inline,true);

void main(){
    int k,n;
    readf!"%d %d"(n,k);
    readln;
    auto a=readln.splitter
                 .map!(to!int)
                 .array;
    k--;
    a.count!((x)=>x>0 && x>=a[k]).writeln;
}

import std.stdio;
void main()
{
    int [100000+10]arr;
    int n,k;
    readf("%d %d ",&n,&k);
    for(int i=1;i<=n;i++)readf("%d ",&arr[i]);
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        if(arr[i]>=arr[k] && arr[i]>0)ans++;
    }
    writeln(ans);
}

module main;

import std.c.stdio;

int main(string[] argv)
{
	int n,k;
	scanf("%d %d", &n, &k);
	int [] arr = new int[n];
	for(int i = 0; i<n; i++)
		scanf("%d", &arr[i]);
	int q;
	for(int i = 0; i<n; i++)
		if(arr[i] >= arr[k-1] && arr[i] >0)
			q++;
	printf("%d", q);
	return 0;
}

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

void main(){
	int n, k; readf("%d %d\n", &n, &k);
	auto buf = readln.split.map!(to!int).array;
	(buf[0] == 0) ? writeln(0) : buf.count!(a => a>=buf[k-1]).writeln;
}

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

void main() {
  string[] l1 = readln().chomp().split();
  auto n = to!int(l1[0]);
  auto k = to!int(l1[1]);
  string[] l2 = readln().chomp().split();
  auto tot = k;
  auto kv = to!int(l2[k-1]);
  if (kv > 0) {
    while (tot < n && to!int(l2[tot]) == kv) {
      tot += 1;
    }
    writeln(tot);
  } else {
    writeln(0);
  }
}

import std.stdio : readf, readln, writeln;
import std.math : ceil;
import std.conv : to;
import std.array : split;

void main()
{
	uint[] nums;
	uint n, k;
	uint counter;
	uint pass;

	readf("%s %s\n", &n, &k);

	foreach(uint i, string num; split(readln))
	{
		uint unum = to!uint(num);
		if (i==k) pass = unum;
		nums ~= unum;
	}
	foreach(num; nums)
	{
		if (num > 0 && num >= pass) ++counter;
	}

	writeln(counter);
}

import std.stdio;
import std.algorithm;

void main()
{
    int n, k;
    scanf("%d %d", &n, &k);

    int[] a = new int[n];

    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }

    a.sort();

    int ans = 0;

    for (int i = 0; i < n; ++i) {
        if (a[i] > 0 && a[i] >= a[k - 1])
            ans++;
    }

    printf("%d\n", ans);

}

import std.stdio;
import core.stdc.stdio;
import std.conv;
import std.container;

int main(string[] argv)
{
	int n, k;
	scanf("%d %d", &n, &k);
	int[] contestants = new int[n];
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &contestants[i]);
	}
	int score = contestants[k];
	int result = 0;
	for (int i = 0; i < n; i++)
	{
		result += (contestants[i] > 0 && contestants[i] >= score) ? 1 : 0;
	}
	writeln(result);
	return 0;
}

import std.stdio;
void main() {
	int n, k;
	readf(" %s",&n);
	readf(" %s",&k);
	k--;
	int[] a = new int[n];
	for (int i = 0; i < n; i++) {
		readf(" %s",&a[i]);
	}
	a = a.reverse;
	int answer = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] > 0 && a[i] >= a[k]) {
			answer++;
		}
	}
	writeln(answer);
}

// https://codeforces.com/problemset/problem/158/A
import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

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

    string input = readln;
    int[] a = input.split.map!(x => x.to!int).array;

    a.filter!(x => (x >= a[k-1]) && (x > 0));
    a.length.writeln;
}


Ilya got tired of sports programming, left university and got a job in the subway. He was given the task to determine the escalator load factor. Let's assume that n people stand in the queue for the escalator. At each second one of the two following possibilities takes place: either the first person in the queue enters the escalator with probability p, or the first person in the queue doesn't move with probability (1 - p), paralyzed by his fear of escalators and making the whole queue wait behind him.Formally speaking, the i-th person in the queue cannot enter the escalator until people with indices from 1 to i - 1 inclusive enter it. In one second only one person can enter the escalator. The escalator is infinite, so if a person enters it, he never leaves it, that is he will be standing on the escalator at any following second. Ilya needs to count the expected value of the number of people standing on the escalator after t seconds. Your task is to help him solve this complicated task.

The first line of the input contains three numbers n, p, t (1 ≤ n, t ≤ 2000, 0 ≤ p ≤ 1). Numbers n and t are integers, number p is real, given with exactly two digits after the decimal point.

Print a single real number — the expected number of people who will be standing on the escalator after t seconds. The absolute or relative error mustn't exceed 10 - 6.

import std.stdio, std.string;
import std.algorithm;

double saiki(int n, int t, double p, double[][] dp)
{
    if (dp[n][t] != -1)
    {
        return dp[n][t];
    }
    if (n == 0)
    {
        dp[n][t] = 0.0;
        return 0.0;
    }
    if (t == 0)
    {
        dp[n][t] = cast(double)n;
        return cast(double)n;
    }
    auto ret0 = saiki(n - 1, t - 1, p, dp);
    auto ret1 = saiki(n, t - 1, p, dp);
    dp[n][t] = p * ret0 + (1.0 - p) * ret1;
    return dp[n][t];
}

void solve(int n, double p, int t)
{
    auto dp = new double[][](n + 1, t + 1);
    foreach (i; 0 .. n + 1)
    {
        fill(dp[i], -1);
    }
    auto res = saiki(n, t, p, dp);
    writefln("%.10f", cast(double)n - res);
}

int main(string[] args)
{
    int n, t;
    double p;
    while (readf("%d %f %d\n", &n, &p, &t) == 3)
    {
        solve(n, p, t);
    }
    return 0;
}

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;
import core.bitop;

void main ()
{
	int n, t;
	real p;
	while (readf (" %s %s %s", &n, &p, &t) > 0)
	{
		real q = 1.0 - p;
		auto f = new real [] [] (t + 1, n + 1);
		foreach (ref g; f)
		{
			g[] = 0.0;
		}
		f[0][0] = 1.0;

		foreach (i; 0..t)
		{
			foreach (j; 0..n)
			{
				f[i + 1][j + 1] += f[i][j] * p;
				f[i + 1][j + 0] += f[i][j] * q;
			}
			f[i + 1][n] += f[i][n];
		}

		real res = 0.0;
		foreach (j; 0..n + 1)
		{
			res += f[t][j] * j;
		}
		writefln ("%.10f", res);
	}
}


Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly n houses in Ultimate Thule, Vova wants the city to have exactly n pipes, each such pipe should be connected to the water supply. A pipe can be connected to the water supply if there's water flowing out of it. Initially Vova has only one pipe with flowing water. Besides, Vova has several splitters.A splitter is a construction that consists of one input (it can be connected to a water pipe) and x output pipes. When a splitter is connected to a water pipe, water flows from each output pipe. You can assume that the output pipes are ordinary pipes. For example, you can connect water supply to such pipe if there's water flowing out from it. At most one splitter can be connected to any water pipe.  The figure shows a 4-output splitter Vova has one splitter of each kind: with 2, 3, 4, ..., k outputs. Help Vova use the minimum number of splitters to build the required pipeline or otherwise state that it's impossible.Vova needs the pipeline to have exactly n pipes with flowing out water. Note that some of those pipes can be the output pipes of the splitters.

The first line contains two space-separated integers n and k (1 ≤ n ≤ 1018, 2 ≤ k ≤ 109). Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Print a single integer — the minimum number of splitters needed to build the pipeline. If it is impossible to build a pipeline with the given splitters, print -1.

module sigod.codeforces.p287B;

import std.stdio;

void main()
{
	long n, k;
	stdin.readf("%s %s", &n, &k);

	long count = solve(n, k);

	stdout.writeln(count);
}

long solve(long n, long k)
{
	if (n == 1) return 0;
	else if (n <= k) return 1;

	long S = s(k - 1, k);
	if (n > S) return -1;
	else if (n == S) return k - 1;

	long min_count;
	long min = long.max;

	long left_count = 1;
	long right_count = k - 1;

	while (left_count < right_count - 1) {
		long middle_count = (left_count + right_count) / 2;
		long middle = s(middle_count, k);

		if (middle < n) {
			left_count = middle_count;
		}
		else {
			right_count = middle_count;

			if (min > middle) {
				min_count = middle_count;
				min = middle;
			}
		}
	}

	return min_count;
}

private
long s(long count, long k)
{
	//long S = (1 + (k - 1)) * (k - 1) / 2 + 1;
	return (k - count + k - 1) * count / 2 + 1;
}

unittest {
	static assert(solve(4, 3) == 2);
	static assert(solve(5, 5) == 1);
	static assert(solve(8, 4) == -1);
}

module sigod.codeforces.p287B;

import std.stdio;

void main()
{
	long n, k;
	stdin.readf("%s %s", &n, &k);

	long count = solve(n, k);

	stdout.writeln(count);
}

long solve(long n, long k)
{
	if (n <= k) return 1;

	long S = s(k - 1, k);
	if (n > S) return -1;
	else if (n == S) return k - 1;

	long min_count;
	long min = long.max;

	long left_count = 1;
	long right_count = k - 1;

	while (left_count < right_count - 1) {
		long middle_count = (left_count + right_count) / 2;
		long middle = s(middle_count, k);

		if (middle < n) {
			left_count = middle_count;
		}
		else {
			right_count = middle_count;

			if (min > middle) {
				min_count = middle_count;
				min = middle;
			}
		}
	}

	return min_count;
}

private
long s(long count, long k)
{
	//long S = (1 + (k - 1)) * (k - 1) / 2 + 1;
	return (k - count + k - 1) * count / 2 + 1;
}

unittest {
	static assert(solve(4, 3) == 2);
	static assert(solve(5, 5) == 1);
	static assert(solve(8, 4) == -1);
}


Stepan has a very big positive integer.Let's consider all cyclic shifts of Stepan's integer (if we look at his integer like at a string) which are also integers (i.e. they do not have leading zeros). Let's call such shifts as good shifts. For example, for the integer 10203 the good shifts are the integer itself 10203 and integers 20310 and 31020.Stepan wants to know the minimum remainder of the division by the given number m among all good shifts. Your task is to determine the minimum remainder of the division by m.

The first line contains the integer which Stepan has. The length of Stepan's integer is between 2 and 200 000 digits, inclusive. It is guaranteed that Stepan's integer does not contain leading zeros. The second line contains the integer m (2 ≤ m ≤ 108) — the number by which Stepan divides good shifts of his integer.

Print the minimum remainder which Stepan can get if he divides all good shifts of his integer by the given number m.

NoteIn the first example all good shifts of the integer 521 (good shifts are equal to 521, 215 and 152) has same remainder 2 when dividing by 3.In the second example there are only two good shifts: the Stepan's integer itself and the shift by one position to the right. The integer itself is 1001 and the remainder after dividing it by 5 equals 1. The shift by one position to the right equals to 1100 and the remainder after dividing it by 5 equals 0, which is the minimum possible remainder.

import std.stdio, std.bigint, std.string;

void main() {
    auto a_ = readln.strip;
    auto n = a_.length;
    auto a = BigInt(a_);
    // auto b = BigInt(readln.strip);
    long b;
    scanf("%ld", &b);
    auto ans = a % b;
    auto pow10n = 1; for (int i=0; i<n; i++) pow10n = (pow10n * 10) % b;
    long left=0L;
    auto apow10i = long((a*10L)%b);
    for (int i=1; i<n; i++) {
        left = (left * 10L + (a_[i-1]-'0')) % b;
        // if (i <= 5) write(left, ' ',apow10i % b, ' ');
        auto _a = (b + (apow10i + left - left * pow10n) % b) % b;
        // writeln(_a % b);
        apow10i = (apow10i * 10L) % b;
        // if (i <= 5) writeln(left, ' ', _a, ' ', _a % b);
        if (a_[i] != '0') {
            // writeln(left, ' ', _a, ' ', _a % b);
            // writeln(i, ' ', _a % b);
            if (_a % b < ans)
                ans = _a % b;
        }
    }
    writeln(ans);
}

import std.stdio, std.bigint, std.string;

void main() {
    auto a_ = readln.strip;
    auto n = a_.length;
    auto a = BigInt(a_);
    // auto b = BigInt(readln.strip);
    long b;
    scanf("%ld", &b);

    auto ans = a % b;
    auto pow10n = 1; for (int i=0; i<n; i++) pow10n = (pow10n * 10) % b;
    long left=0L;
    auto apow10i = long((a*10L)%b);

    for (int i=1; i<n; i++) {
        left = (left * 10L + (a_[i-1]-'0')) % b;
        auto _a = (b + (apow10i + left - left * pow10n) % b) % b;
        apow10i = (apow10i * 10L) % b;
        if (a_[i] != '0') {
            if (_a % b < ans)
                ans = _a % b;
        }
    }
    writeln(ans);
}

import std.stdio;

const int N = cast(int)(2e5 + 5);

int n, mod;
int[N] s;
int[N] a, b, p10;

int min(int a, int b) { return a < b ? a : b; }

int main(string[] args)
{
	int ch;
	while ((ch = getchar()) != '\n') s[++n] = ch - '0';
	scanf("%d", &mod);
	for (int i = 1; i <= n; ++i)
		a[i] = (a[i-1] * 10 + s[i]) % mod;
	p10[0] = 1;
	for (int i = 1; i <= n; ++i) p10[i] = p10[i-1] * 10 % mod;
	for (int i = n; i; --i)
		b[i] = (b[i+1] + s[i] * p10[n - i]) % mod;
	int ans = cast(int)(2e9);
	for (int i = 1; i <= n; ++i)
	{
		if (s[i] == 0) continue;
		long t = cast(long)(b[i]) * p10[i - 1] + a[i - 1];
		ans = min(ans, cast(int)(t % mod));
	}
	writeln(ans);
	return 0;
}

import std.stdio, std.bigint, std.string;

void main() {
    auto a_ = readln.strip;
    auto n = a_.length;
    auto a = BigInt(a_);
    // auto b = BigInt(readln.strip);
    int b;
    scanf("%d", &b);
    if (n > 100) {
        writeln(b);
        writeln(a);
    }
    auto ans = a % b;
    auto pow10n = 1; for (int i=0; i<n; i++) pow10n = (pow10n * 10) % b;
    auto left=0;
    auto apow10i = int((a*10)%b);
    for (int i=1; i<n; i++) {
        left = (left * 10 + (a_[i-1]-'0')) % b;
        auto _a = (b + (apow10i + left - left * pow10n) % b) % b;
        apow10i = (apow10i * 10) % b;

        if (a_[i] != '0') {
            // writeln(left, ' ', _a, ' ', _a % b);
            if (_a % b < ans)
                ans = _a % b;
        }
    }
    writeln(ans);
}

import std.stdio, std.bigint, std.string;

void main() {
    auto a_ = readln.strip;
    auto n = a_.length;
    auto a = BigInt(a_);
    // auto b = BigInt(readln.strip);
    int b;
    scanf("%d", &b);
    if (n > 100) {
        writeln(a);
        writeln(b);
    }
    auto ans = a % b;
    // auto pow10n = (BigInt(10) ^^ n);
    auto pow10n = 1;
    for (int i=0; i<n; i++) pow10n = (pow10n * 10) % b;
    // writeln(pow10n);
    auto left=0; // BigInt(0);
    auto apow10i = int((a*10)%b);
    for (int i=1; i<n; i++) {
        left = (left * 10 + (a_[i-1]-'0')) % b;
        auto _a = (b + (apow10i + left - left * pow10n) % b) % b;
        apow10i = (apow10i * 10) % b;
        if (a_[i] != '0') {
            // writeln(left, ' ', _a, ' ', _a % b);
            if (_a % b < ans)
                ans = _a % b;
        }
    }
    writeln(ans);
}

import std.stdio, std.bigint, std.string;

void main() {
    auto a_ = readln.strip;
    auto n = a_.length;
    auto a = BigInt(a_);
    // auto b = BigInt(readln.strip);
    int b;
    scanf("%d", &b);
    auto ans = a % b;
    // auto pow10n = (BigInt(10) ^^ n);
    auto pow10n = 1;
    for (int i=0; i<n; i++) pow10n = (pow10n * 10) % b;
    // writeln(pow10n);
    auto left=0; // BigInt(0);
    auto apow10i = int((a*10)%b);
    for (int i=1; i<n; i++) {
        left = (left * 10 + (a_[i-1]-'0')) % b;
        auto _a = (b + (apow10i + left - left * pow10n) % b) % b;
        apow10i = (apow10i * 10) % b;
        if (a_[i] != '0') {
            // writeln(left, ' ', _a, ' ', _a % b);
            if (_a % b < ans)
                ans = _a % b;
        }
    }
    writeln(ans);
}

import std.stdio;

const int N = cast(int)(2e5 + 5);

int n, mod;
int[N] s, a, b, p10;

int min(int a, int b) { return a < b ? a : b; }

int main(string[] args)
{
	int ch;
	while ((ch = getchar()) != '\n') s[++n] = ch - '0';
	scanf("%d", &mod);
	for (int i = 1; i <= n; ++i)
		a[i] = (a[i-1] * 10 + s[i]) % mod;
	p10[0] = 1;
	for (int i = 1; i <= n; ++i) p10[i] = p10[i-1] * 10 % mod;
	for (int i = n; i; --i)
		b[i] = (b[i+1] + s[i] * p10[n - i]) % mod;
	int ans = cast(int)(2e9);
	for (int i = 1; i <= n; ++i)
	{
		if (s[i] == '0') continue;
		ans = min(ans, (b[i] * p10[i - 1] + a[i - 1]) % mod);
	}
	writeln(ans);
	return 0;
}

import std.stdio;

const int N = cast(int)(2e5 + 5);

int n, mod;
string s;
int[N] a, b, p10;

int min(int a, int b) { return a < b ? a : b; }

int main(string[] args)
{
	s = readln();
	n = cast(int)(s.length);
	s = " " ~ s;
	scanf("%d", &mod);
	for (int i = 1; i <= n; ++i)
		a[i] = (a[i-1] * 10 + s[i] - '0') % mod;
	p10[0] = 1;
	for (int i = 1; i <= n; ++i) p10[i] = p10[i-1] * 10 % mod;
	for (int i = n; i; --i)
		b[i] = (b[i+1] + (s[i] - '0') * p10[n - i]) % mod;
	int ans = cast(int)(2e9);
	for (int i = 1; i <= n; ++i)
	{
		if (s[i] == '0') continue;
		ans = min(ans, (b[i] * p10[i - 1] + a[i - 1]) % mod);
	}
	writeln(ans);
	return 0;
}


From beginning till end, this message has been waiting to be conveyed.For a given unordered multiset of n lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repeat the following operation n - 1 times:  Remove any two elements s and t from the set, and add their concatenation s + t to the set. The cost of such operation is defined to be , where f(s, c) denotes the number of times character c appears in string s.Given a non-negative integer k, construct any valid non-empty set of no more than 100 000 letters, such that the minimum accumulative cost of the whole process is exactly k. It can be shown that a solution always exists.

The first and only line of input contains a non-negative integer k (0 ≤ k ≤ 100 000) — the required minimum cost.

Output a non-empty string of no more than 100 000 lowercase English letters — any multiset satisfying the requirements, concatenated to be a string. Note that the printed string doesn't need to be the final concatenated string. It only needs to represent an unordered multiset of letters.

NoteFor the multiset {'a', 'b', 'a', 'b', 'a', 'b', 'a', 'b'}, one of the ways to complete the process is as follows:  {"ab", "a", "b", "a", "b", "a", "b"}, with a cost of 0;  {"aba", "b", "a", "b", "a", "b"}, with a cost of 1;  {"abab", "a", "b", "a", "b"}, with a cost of 1;  {"abab", "ab", "a", "b"}, with a cost of 0;  {"abab", "aba", "b"}, with a cost of 1;  {"abab", "abab"}, with a cost of 1;  {"abababab"}, with a cost of 8. The total cost is 12, and it can be proved to be the minimum cost of the process.

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;

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

    if (N == 0) {
        "a".writeln;
        return;
    }

    string ans = "";
    char c = 'a';

    while (N > 0) {
        ans ~= c;
        int tmp = 1;
        while (N - tmp >= 0) {
            N -= tmp;
            ans ~= c;
            tmp += 1;
        }
        c += 1;
    }

    ans.writeln;
}

module main;
__gshared:
import core.bitop, std.algorithm, std.bigint, std.bitmanip, std.complex,
	std.container, std.conv, std.datetime, std.functional, std.math, std.meta,
	std.numeric, std.parallelism, std.random, std.range, std.regex, std.stdio,
	std.string, std.traits, std.typecons, std.uni, std.variant;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
enum mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///lcm
		T lcm(T)(auto ref T a, auto ref T b)
		{
			return a / gcd(a, b) * b;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///BigInt greatest common divizor
		BigInt gcd(BigInt a, BigInt b)
		{
			while (b)
			{
				a %= b;
				swap(a, b);
			}
			return a;
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///integer size
		int sz(T)(T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///posicion lower bound
		size_t lowb(T, X)(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;
		}
		///posicion upper bound
		size_t upb(T, X)(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;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return binf(a, g) != a.length;
		}
	}
	///write an array
	void putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)
	{
		writefln("%(%s" ~ ch ~ "%)", a);
	}
	///write a matrix
	void putarr(X)(in X a)
			if (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))
	{
		writefln("%(%(%s %)\n%)", a);
	}
	///get an array
	bool getarr(X)(X a, in size_t n)
	{
		bool b = 1;
		foreach (ref i; a[0 .. n])
			b = input(&i);
		return b;
	}
	///read without format
	bool input(T...)(ref T ptrs) if (ptrs.length > 0)
	{
		size_t s = 0;
		foreach (ref e; ptrs)
		{
			if (isSomeChar!(Unqual!(typeof(e))))
				s += readf(" %c", &e);
			else
				s += readf(" %s", &e);
		}
		return s == ptrs.length;
	}
	///readln without format
	bool read(T...)(ref T ptrs) if (ptrs.length > 0)
	{
		size_t s = 0;
		foreach (ref e; ptrs)
		{
			if (isSomeChar!(Unqual!(typeof(e))))
				s += readf(" %c", &e);
			else
				s += readf(" %s", &e);
		}
		readln;
		return s == ptrs.length;
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------

void main()
{
	version (home)
	{
		freopen("input.txt", "r", core.stdc.stdio.stdin);
		//freopen("output.txt", "w", core.stdc.stdio.stdout);
		/*StopWatch sw;
		sw.start;
		scope (exit)
		{
			sw.stop;
			stderr.writefln("\nTime: %d ms", sw.peek.msecs);
		}*/
	}
	int k;
	loop: while (read(k))
	{
		foreach (ch; 'a' .. 'z' + 1)
		{
			int i;
			while (i * (i + 1) / 2 <= k)
				i++;
			k -= i * (i - 1) / 2;
			foreach (_; 0 .. i)
			{
				write(cast(char) ch);
			}
		}
		writeln;
	}
}

/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.6.0"
+/

import std.stdio, std.algorithm, std.range, std.conv;
// import dcomp.foundation, dcomp.scanner;

int main() {
    auto sc = new Scanner(stdin);
    int k;
    sc.read(k); k *= 2;
    if (k == 0) {
        writeln("miku");
        return 0;
    }
    string s;
    char nw = 'a';
    while (k) {
        foreach (i; 1..1000) {
            if (k < (i+1)*(i)) {
                k -= i*(i-1);
                s ~= nw.repeat.take(i).array;
                nw++;
                break;
            }
        }
    }
    writeln(s);
    return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/foundation.d */
// module dcomp.foundation;

static if (__VERSION__ <= 2070) {
    template fold(fun...) if (fun.length >= 1) {
        auto fold(R, S...)(R r, S seed) {
            import std.algorithm : reduce;
            static if (S.length < 2) {
                return reduce!fun(seed, r);
            } else {
                import std.typecons : tuple;
                return reduce!fun(tuple(seed), r);
            }
        }
    }

}
version (X86) static if (__VERSION__ < 2071) {
    import core.bitop : bsf, bsr, popcnt;
    int bsf(ulong v) {
        foreach (i; 0..64) {
            if (v & (1UL << i)) return i;
        }
        return -1;
    }
    int bsr(ulong v) {
        foreach_reverse (i; 0..64) {
            if (v & (1UL << i)) return i;
        }
        return -1;
    }
    int popcnt(ulong v) {
        int c = 0;
        foreach (i; 0..64) {
            if (v & (1UL << i)) c++;
        }
        return c;
    }
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray;
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    char[512] lineBuf;
    char[] line;
    private bool succ() {
        import std.range.primitives : empty, front, popFront;
        import std.ascii : isWhite;
        while (true) {
            while (!line.empty && line.front.isWhite) {
                line.popFront;
            }
            if (!line.empty) break;
            if (f.eof) return false;
            line = lineBuf[];
            f.readln(line);
        }
        return true;
    }

    private bool readSingle(T)(ref T x) {
        import std.algorithm : findSplitBefore;
        import std.string : strip;
        import std.conv : parse;
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {

                auto r = line.findSplitBefore(" ");
                x = r[0].strip.dup;
                line = r[1];
            } else {
                auto buf = line.split.map!(to!E).array;
                static if (isStaticArray!T) {

                    assert(buf.length == T.length);
                }
                x = buf;
                line.length = 0;
            }
        } else {
            x = line.parse!T;
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

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;

immutable int limit = 1003;

void main ()
{
	auto f = new int [limit];
	f[0] = 0;
	f[1] = 0;
	foreach (j; 2..limit)
	{
		f[j] = int.max;
		foreach (k; 1..j)
		{
			f[j] = min (f[j], f[k] + f[j - k] + k * (j - k));
		}
	}
	debug
	{
		foreach (j; 0..limit)
		{
			writefln ("%6s: %6s", j, f[j]);
		}
	}

	int n;
	while (readf (" %s", &n) > 0)
	{
		string res;
		foreach (c; 'a'..'p')
		{
			int len = 0;
			while (f[len + 1] <= n)
			{
				len += 1;
			}
			n -= f[len];
			foreach (i; 0..len)
			{
				res ~= c;
			}
		}
		writeln (res);
	}
}

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

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

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

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

enum LIM = 10^^5 + 5;

void main() {
  auto prev = new int[LIM];
  prev[] = -1;
  prev[0] = 0;
  foreach (i; 0 .. 3) {
    foreach_reverse (x; 0 .. LIM) {
      if (prev[x] != -1) {
        for (int a = 2; x + a * (a - 1) / 2 < LIM; ++a) {
          const xx = x + a * (a - 1) / 2;
          if (prev[xx] == -1) {
            prev[xx] = a;
          }
        }
      }
    }
  }
  foreach (x; 0 .. LIM) {
    assert(prev[x] != -1);
  }

  try {
    for (; ; ) {
      const K = readInt();

      int[] as;
      as ~= 1;
      for (int x = K; x > 0; ) {
        const a = prev[x];
        as ~= a;
        x -= a * (a - 1) / 2;
      }

      string ans;
      foreach (i, a; as) {
        ans ~= (cast(char)('a' + i)).repeat(a).array;
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}

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;

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

    string ans = "";
    char c = 'a';

    while (N > 0) {
        ans ~= c;
        int tmp = 1;
        while (N - tmp >= 0) {
            N -= tmp;
            ans ~= c;
            tmp += 1;
        }
        c += 1;
    }

    ans.writeln;
}

module main;
__gshared:
import core.bitop, std.algorithm, std.bigint, std.bitmanip, std.complex,
	std.container, std.conv, std.datetime, std.functional, std.math, std.meta,
	std.numeric, std.parallelism, std.random, std.range, std.regex, std.stdio,
	std.string, std.traits, std.typecons, std.uni, std.variant;

alias pair(X, Y) = Tuple!(X, "fi", Y, "se");
alias mp = make_pair;
alias pii = pair!(int, int);
alias pll = pair!(long, long);
alias gcd = std.numeric.gcd;
alias lint = long;
alias rbt = RedBlackTree;
///modulo
enum mod = 10 ^^ 9 + 7, mod2 = mod + 2;
public
{
	pure nothrow
	{
		///lcm
		T lcm(T)(auto ref T a, auto ref T b)
		{
			return a / gcd(a, b) * b;
		}
		///make_pair
		pair!(X, Y) make_pair(X, Y)(in X x_, in Y y_)
		{
			return tuple!(X, "fi", Y, "se")(x_, y_);
		}
		///BigInt greatest common divizor
		BigInt gcd(BigInt a, BigInt b)
		{
			while (b)
			{
				a %= b;
				swap(a, b);
			}
			return a;
		}
		///square
		@property X sqr(X)(in X a_)
		{
			return a_ * a_;
		}
		///cube
		@property X cub(X)(in X a_)
		{
			return a_ * a_ * a_;
		}
		///integer size
		int sz(T)(T a) if (hasLength!T)
		{
			return cast(int) a.length;
		}
		///posicion lower bound
		size_t lowb(T, X)(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;
		}
		///posicion upper bound
		size_t upb(T, X)(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;
		}
		///posicion binary search
		size_t binf(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			auto pos = lowb(a, g);
			return (g == a[pos]) ? pos : a.length;
		}
		///binary search
		bool binary_search(T, X)(T a, auto ref X g)
				if (isRandomAccessRange!T && hasLength!T && is(typeof(g < a[0]) == bool))
		{
			return binf(a, g) != a.length;
		}
	}
	///write an array
	void putarr(X)(in X a, in char ch = ' ') if (isInputRange!X)
	{
		writefln("%(%s" ~ ch ~ "%)", a);
	}
	///write a matrix
	void putarr(X)(in X a)
			if (isInputRange!X && isInputRange!(ElementType!X) && !isSomeString!(ElementType!X))
	{
		writefln("%(%(%s %)\n%)", a);
	}
	///get an array
	bool getarr(X)(X a, in size_t n)
	{
		bool b = 1;
		foreach (ref i; a[0 .. n])
			b = input(&i);
		return b;
	}
	///read without format
	bool input(T...)(ref T ptrs) if (ptrs.length > 0)
	{
		size_t s = 0;
		foreach (ref e; ptrs)
		{
			if (isSomeChar!(Unqual!(typeof(e))))
				s += readf(" %c", &e);
			else
				s += readf(" %s", &e);
		}
		return s == ptrs.length;
	}
	///readln without format
	bool read(T...)(ref T ptrs) if (ptrs.length > 0)
	{
		size_t s = 0;
		foreach (ref e; ptrs)
		{
			if (isSomeChar!(Unqual!(typeof(e))))
				s += readf(" %c", &e);
			else
				s += readf(" %s", &e);
		}
		readln;
		return s == ptrs.length;
	}
	///opening file
	nothrow auto inf(in char* name)
	{
		return freopen(name, "r", core.stdc.stdio.stdin);
	}
	///closing file
	nothrow auto ouf(in char* name)
	{
		return freopen(name, "w", core.stdc.stdio.stdout);
	}
	///parsing array from line
	@property auto arread(T)()
	{
		return readln.splitter.map!(to!(T)).array;
	}
	///outbuffer
	void enter(T...)(T args)
	{
		writeln(args);
		stdout.flush;
	}
}
//foreach_reverse isAlpha isNumber isWhite isLower isUpper toLower toUpper mixin
//cumulativeFold return static heapify join filter foreach
//------------------------------------------program beginning--------------------------

void main()
{
	version (home)
	{
		freopen("input.txt", "r", core.stdc.stdio.stdin);
		//freopen("output.txt", "w", core.stdc.stdio.stdout);
		/*StopWatch sw;
		sw.start;
		scope (exit)
		{
			sw.stop;
			stderr.writefln("\nTime: %d ms", sw.peek.msecs);
		}*/
	}
	int k;
	loop: while (read(k))
	{
		foreach (ch; 'a' .. 'z' + 1)
		{
			int i = 1;
			while (i * (i - 1) / 2 <= k)
				i++;
			k -= i * (i - 1) / 2;
			foreach (_; 0 .. i - 1)
			{
				write(cast(char) ch);
			}
		}
		writeln;
	}
}

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

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

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

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

enum LIM = 10^^5 + 5;

void main() {
  auto prev = new int[LIM];
  prev[] = -1;
  prev[0] = 0;
  foreach (i; 0 .. 3) {
    foreach_reverse (x; 0 .. LIM) {
      if (prev[x] != -1) {
        for (int a = 2; x + a * (a - 1) / 2 < LIM; ++a) {
          const xx = x + a * (a - 1) / 2;
          if (prev[xx] == -1) {
            prev[xx] = a;
          }
        }
      }
    }
  }
  foreach (x; 0 .. LIM) {
    assert(prev[x] != -1);
  }

  try {
    for (; ; ) {
      const K = readInt();

      int[] as;
      for (int x = K; x > 0; ) {
        const a = prev[x];
        as ~= a;
        x -= a * (a - 1) / 2;
      }

      string ans;
      foreach (i, a; as) {
        ans ~= (cast(char)('a' + i)).repeat(a).array;
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


A string $$$s$$$ of length $$$n$$$ can be encrypted by the following algorithm:  iterate over all divisors of $$$n$$$ in decreasing order (i.e. from $$$n$$$ to $$$1$$$),  for each divisor $$$d$$$, reverse the substring $$$s[1 \dots d]$$$ (i.e. the substring which starts at position $$$1$$$ and ends at position $$$d$$$). For example, the above algorithm applied to the string $$$s$$$="codeforces" leads to the following changes: "codeforces" $$$\to$$$ "secrofedoc" $$$\to$$$ "orcesfedoc" $$$\to$$$ "rocesfedoc" $$$\to$$$ "rocesfedoc" (obviously, the last reverse operation doesn't change the string because $$$d=1$$$).You are given the encrypted string $$$t$$$. Your task is to decrypt this string, i.e., to find a string $$$s$$$ such that the above algorithm results in string $$$t$$$. It can be proven that this string $$$s$$$ always exists and is unique.

The first line of input consists of a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the length of the string $$$t$$$. The second line of input consists of the string $$$t$$$. The length of $$$t$$$ is $$$n$$$, and it consists only of lowercase Latin letters.

Print a string $$$s$$$ such that the above algorithm results in $$$t$$$.

NoteThe first example is described in the problem statement.

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;
import std.range.interfaces;

void main()
{
    readln;

    auto s = readln.chomp.map!(to!dchar).array;

    foreach (i; 2..(s.length+1)) {
        if (s.length % i != 0) continue;

        s = s[0..i].retro.array ~ s[i..$];
    }

    s.writeln;
}


Ehab is interested in the bitwise-xor operation and the special graphs. Mahmoud gave him a problem that combines both. He has a complete graph consisting of n vertices numbered from 0 to n - 1. For all 0 ≤ u < v < n, vertex u and vertex v are connected with an undirected edge that has weight  (where  is the bitwise-xor operation). Can you find the weight of the minimum spanning tree of that graph?You can read about complete graphs in https://en.wikipedia.org/wiki/Complete_graphYou can read about the minimum spanning tree in https://en.wikipedia.org/wiki/Minimum_spanning_treeThe weight of the minimum spanning tree is the sum of the weights on the edges included in it.

The only line contains an integer n (2 ≤ n ≤ 1012), the number of vertices in the graph.

The only line contains an integer x, the weight of the graph's minimum spanning tree.

NoteIn the first sample:  The weight of the minimum spanning tree is 1+2+1=4.

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

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  long n; readV(n);

  auto s = 0L, i = 0;
  while (n > 1) {
    s += n/2 * 2L^^(i++);
    n = n/2+n%2;
  }

  writeln(s);
}

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

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}
void readA(T)(size_t n,ref T t){t=new T(n);auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(ElementType!T);r.popFront;}}
void readM(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=readln.splitter;foreach(ref v;t){v[i]=r.front.to!(ElementType!(typeof(v)));r.popFront;}}}
void readS(T)(size_t n,ref T t){t=new T(n);foreach(ref v;t){auto r=readln.splitter;foreach(ref j;v.tupleof){j=r.front.to!(typeof(j));r.popFront;}}}

void main()
{
  long n; readV(n);

  auto s = 0L, i = 0;
  while (n > 1) {
    s += n/2 * 2^^(i++);
    n = n/2+n%2;
  }

  writeln(s);
}


Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...There are four guardposts in Dima's dorm. Each post contains two guards (in Russia they are usually elderly women). You can bribe a guard by a chocolate bar or a box of juice. For each guard you know the minimum price of the chocolate bar she can accept as a gift and the minimum price of the box of juice she can accept as a gift. If a chocolate bar for some guard costs less than the minimum chocolate bar price for this guard is, or if a box of juice for some guard costs less than the minimum box of juice price for this guard is, then the guard doesn't accept such a gift.In order to pass through a guardpost, one needs to bribe both guards.The shop has an unlimited amount of juice and chocolate of any price starting with 1. Dima wants to choose some guardpost, buy one gift for each guard from the guardpost and spend exactly n rubles on it.Help him choose a post through which he can safely sneak Inna or otherwise say that this is impossible. Mind you, Inna would be very sorry to hear that!

The first line of the input contains integer n (1 ≤ n ≤ 105) — the money Dima wants to spend. Then follow four lines describing the guardposts. Each line contains four integers a, b, c, d (1 ≤ a, b, c, d ≤ 105) — the minimum price of the chocolate and the minimum price of the juice for the first guard and the minimum price of the chocolate and the minimum price of the juice for the second guard, correspondingly.

In a single line of the output print three space-separated integers: the number of the guardpost, the cost of the first present and the cost of the second present. If there is no guardpost Dima can sneak Inna through at such conditions, print -1 in a single line.  The guardposts are numbered from 1 to 4 according to the order given in the input. If there are multiple solutions, you can print any of them.

NoteExplanation of the first example.The only way to spend 10 rubles to buy the gifts that won't be less than the minimum prices is to buy two 5 ruble chocolates to both guards from the first guardpost.Explanation of the second example.Dima needs 12 rubles for the first guardpost, 14 for the second one, 16 for the fourth one. So the only guardpost we can sneak through is the third one. So, Dima can buy 4 ruble chocolate for the first guard and 6 ruble juice of the second guard.

import std.stdio;

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

    //writeln("%s",
    int n;
    readf(" %s", &n);
    foreach (k; 1..5) {
        int[4] gs;
        readf(" %s %s %s %s", &gs[0], &gs[1], &gs[2], &gs[3]);
        foreach (i; 0..2) {
            foreach (j; 2..4) {
                if (gs[i] + gs[j] <= n) {
                    writefln("%s %s %s", k, gs[i], n - gs[i]);
                    return 0;
                }
            }
        }
    }
    writeln("-1");

    return 0;
}

import std.stdio;

void main() {
    debug stdin = File("input.txt", "r");

    int n;
    readf(" %s", &n);
    foreach (i; 0 .. 4) {
        int[] a = new int[2];
        int[] b = new int[2];
        readf(" %s %s %s %s", &a[0], &a[1], &b[0], &b[1]);
        foreach (j; 0 .. 2) {
            foreach (k; 0 .. 2) {
                if (a[j] + b[k] <= n) {
                    writeln(i + 1, " ", n - b[k], " ", b[k]);
                    return;
                }
            }
        }
    }

    writeln(-1);
}


Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its beaches, sun and sea. Dot chose Transylvania as the most mysterious and unpredictable place.But to their great regret, the leave turned to be very short, so it will be enough to visit one of the three above named places. That's why Yakko, as the cleverest, came up with a truly genius idea: let each of the three roll an ordinary six-sided die, and the one with the highest amount of points will be the winner, and will take the other two to the place of his/her dreams.Yakko thrown a die and got Y points, Wakko — W points. It was Dot's turn. But she didn't hurry. Dot wanted to know for sure what were her chances to visit Transylvania.It is known that Yakko and Wakko are true gentlemen, that's why if they have the same amount of points with Dot, they will let Dot win.

The only line of the input file contains two natural numbers Y and W — the results of Yakko's and Wakko's die rolls.

Output the required probability in the form of irreducible fraction in format «A/B», where A — the numerator, and B — the denominator. If the required probability equals to zero, output «0/1». If the required probability equals to 1, output «1/1».

NoteDot will go to Transylvania, if she is lucky to roll 4, 5 or 6 points.

import std.stdio;
import std.algorithm;

string getMessage(int bigger) {
    final switch (bigger) {
        case 1:
            return "1/1";
        case 2:
            return "5/6";
        case 3:
            return "2/3";
        case 4:
            return "1/2";
        case 5:
            return "1/3";
        case 6:
            return "1/6";
    }
}

void main() {
    int a, b;
    readf("%d %d", &a, &b);
    writeln(getMessage(max(a, b)));
}


Alice and Bob are playing a game with a string of characters, with Alice going first. The string consists n characters, each of which is one of the first k letters of the alphabet. On a player’s turn, they can either arbitrarily permute the characters in the words, or delete exactly one character in the word (if there is at least one character). In addition, their resulting word cannot have appeared before throughout the entire game. The player unable to make a valid move loses the game.Given n, k, p, find the number of words with exactly n characters consisting of the first k letters of the alphabet such that Alice will win if both Alice and Bob play optimally. Return this number modulo the prime number p.

The first line of input will contain three integers n, k, p (1 ≤ n ≤ 250 000, 1 ≤ k ≤ 26, 108 ≤ p ≤ 109 + 100, p will be prime).

Print a single integer, the number of winning words for Alice, modulo p.

NoteThere are 14 strings that that Alice can win with. For example, some strings are "bbaa" and "baaa". Alice will lose on strings like "aaaa" or "bbbb".

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

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

alias Mint = ModInt;

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

T[][] zeta(T)(const(T[]) as) {
  const n = bsr(as.length);
  assert(as.length == 1 << n, "zeta: |as| = 2^n must hold");
  auto zas = new T[][](n + 1, 1 << n);
  foreach (h; 0 .. 1 << n) zas[popcnt(h)][h] = as[h];
  foreach (k; 0 .. n + 1) foreach (i; 0 .. n) foreach (h; 0 .. 1 << n) {
    if (!(h & 1 << i)) zas[k][h | 1 << i] += zas[k][h];
  }
  return zas;
}

// Modifies zas
T[] moebius(T)(T[][] zas) {
  const n = cast(int)(zas.length) - 1;
  foreach (k; 0 .. n + 1) foreach (i; 0 .. n) foreach (h; 0 .. 1 << n) {
    if (!(h & 1 << i)) zas[k][h | 1 << i] -= zas[k][h];
  }
  auto as = new T[1 << n];
  foreach (h; 0 .. 1 << n) as[h] = zas[popcnt(h)][h];
  return as;
}

Mint[] subsetMul(const(Mint[]) as, const(Mint[]) bs) {
  const n = bsr(as.length);
  assert(as.length == 1 << n, "subsetMul: |as| = 2^n must hold");
  assert(bs.length == 1 << n, "subsetMul: |bs| = 2^n must hold");
  const zas = zeta(as);
  const zbs = zeta(bs);
  auto zcs = new Mint[][](n + 1, 1 << n);
  foreach (k; 0 .. n + 1) foreach (l; 0 .. n - k + 1) foreach (h; 0 .. 1 << n) {
    zcs[k + l][h] += zas[k][h] * zbs[l][h];
  }
  return moebius(zcs);
}

// Needs inv[1], ..., inv[n]
Mint[] subsetExp(const(Mint[]) as) {
  const n = bsr(as.length);
  assert(as.length == 1 << n, "subsetExp: |as| = 2^n must hold");
  assert(as[0].x == 0, "subsetExp: as[0] = 1 must hold");
  foreach (k; 1 .. n + 1) {
    assert((k * inv[k]).x == 1, "subsetExp: inv must be prepared");
  }
  const zas = zeta(as);
  auto zbs = new Mint[][](n + 1, 1 << n);
  zbs[0][] = Mint(1);
  foreach (h; 0 .. 1 << n) foreach (k; 1 .. n + 1) {
    Mint sum;
    foreach (l; 1 .. k + 1) sum += l * zas[l][h] * zbs[k - l][h];
    zbs[k][h] = inv[k] * sum;
  }
  return moebius(zbs);
}

// Needs inv[1], ..., inv[n]
Mint[] subsetLog(const(Mint[]) as) {
  const n = bsr(as.length);
  assert(as.length == 1 << n, "subsetLog: |as| = 2^n must hold");
  assert(as[0].x == 1, "subsetLog: as[0] = 1 must hold");
  foreach (k; 1 .. n + 1) {
    assert((k * inv[k]).x == 1, "subsetLog: inv must be prepared");
  }
  const zas = zeta(as);
  auto zbs = new Mint[][](n + 1, 1 << n);
  foreach (h; 0 .. 1 << n) foreach (k; 1 .. n + 1) {
    Mint sum;
    foreach (l; 1 .. k) sum += l * zas[k - l][h] * zbs[l][h];
    zbs[k][h] = zas[k][h] - inv[k] * sum;
  }
  return moebius(zbs);
}

// Needs inv[1], ..., inv[n]
Mint[] subsetPow(const(Mint[]) as, Mint e) {
  const n = bsr(as.length);
  assert(as.length == 1 << n, "subsetPow: |as| = 2^n must hold");
  assert(as[0].x == 1, "subsetPow: as[0] = 1 must hold");
  foreach (k; 1 .. n + 1) {
    assert((k * inv[k]).x == 1, "subsetPow: inv must be prepared");
  }
  const zas = zeta(as);
  auto zbs = new Mint[][](n + 1, 1 << n);
  auto fs = new Mint[n + 1], gs = new Mint[n + 1];
  zbs[0][] = Mint(1);
  foreach (h; 0 .. 1 << n) {
    fs[0] = 0;
    foreach (k; 1 .. n + 1) {
      Mint sum;
      foreach (l; 1 .. k) sum += l * zas[k - l][h] * fs[l];
      fs[k] = zas[k][h] - inv[k] * sum;
    }
    foreach (k; 1 .. n + 1) fs[k] *= e;
    foreach (k; 1 .. n + 1) {
      Mint sum;
      foreach (l; 1 .. k + 1) sum += l * fs[l] * zbs[k - l][h];
      zbs[k][h] = inv[k] * sum;
    }
  }
  return moebius(zbs);
}

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

      Mint.M = P;
      prepare;

      Mint ans = Mint(K)^^N;
      if (N % 2 == 0) {
        int[] es;
        foreach (e; 1 .. bsr(N) + 1) {
          if (N & 1 << e) {
            es ~= e;
          }
        }
        const esLen = cast(int)(es.length);
        auto sums = new int[1 << esLen];
        sums[0] = 0;
        foreach (u; 0 .. esLen) {
          foreach (h; 0 .. 1 << u) {
            sums[h | 1 << u] = sums[h] | 1 << es[u];
          }
        }
        auto as = new Mint[1 << esLen];
        foreach (h; 0 .. 1 << esLen) {
          as[h] = invFac[sums[h]];
        }
        const bs = subsetPow(as, Mint(K));
        ans -= fac[sums[$ - 1]] * bs[$ - 1];
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


It is the easy version of the problem. The difference is that in this version, there are no nodes with already chosen colors.Theofanis is starving, and he wants to eat his favorite food, sheftalia. However, he should first finish his homework. Can you help him with this problem?You have a perfect binary tree of $$$2^k - 1$$$ nodes — a binary tree where all vertices $$$i$$$ from $$$1$$$ to $$$2^{k - 1} - 1$$$ have exactly two children: vertices $$$2i$$$ and $$$2i + 1$$$. Vertices from $$$2^{k - 1}$$$ to $$$2^k - 1$$$ don't have any children. You want to color its vertices with the $$$6$$$ Rubik's cube colors (White, Green, Red, Blue, Orange and Yellow).Let's call a coloring good when all edges connect nodes with colors that are neighboring sides in the Rubik's cube.  A picture of Rubik's cube and its 2D map. More formally:   a white node can not be neighboring with white and yellow nodes;  a yellow node can not be neighboring with white and yellow nodes;  a green node can not be neighboring with green and blue nodes;  a blue node can not be neighboring with green and blue nodes;  a red node can not be neighboring with red and orange nodes;  an orange node can not be neighboring with red and orange nodes; You want to calculate the number of the good colorings of the binary tree. Two colorings are considered different if at least one node is colored with a different color.The answer may be too large, so output the answer modulo $$$10^9+7$$$.

The first and only line contains the integers $$$k$$$ ($$$1 \le k \le 60$$$) — the number of levels in the perfect binary tree you need to color.

Print one integer — the number of the different colorings modulo $$$10^9+7$$$.

NoteIn the picture below, you can see one of the correct colorings of the first example.

// Cheese-Cracker: cheese-cracker.github.io

const ll MOD = to!long(1e9) + 7L;
ll modexp(ll base, ll exp){
    ll x = base % MOD;
    ll y = exp;
    ll res = 1;
    while(y > 0){
        if(y & 1){
            res *= x; res %= MOD;
        }
        x *= x; x %= MOD;
        y >>= 1;
    }
    return res;
}

void solve(){
    ll k = scan;
    ll ex = 1;
    for(int i = 0; i < k; ++i) ex *= 2;
    ll res = 6;
    res *= modexp(4, ex-2);
    res %= MOD;
    writeln(res);
}

void main(){
    solve;
}

/**************    *****    That's All Folks!    *****    **************/
import std.stdio, std.range, std.conv, std.typecons, std.algorithm, std.container, std.math;
string[] tk; T scan(T=long)(){while(!tk.length)tk = readln.split; string a=tk.front; tk.popFront; return a.to!T;}
T[] scanArray(T=long)(){ auto r = readln.split.to!(T[]); return r; }
void show(A...)(A a){ debug{ foreach(t; a){stderr.write(t, "| ");} stderr.writeln; } }
alias ll = long, tup = Tuple!(long, "x",  long, "y");

import std.stdio, std.algorithm, std.array, std.math, std.typecons, std.bigint, std.conv;

void main()
{
    int k;
    scanf("%d", &k);
    long res1 = 2UL^^k - 2;
    BigInt n = 4;
    BigInt res2 = powmod(n, to!BigInt(res1), to!BigInt(10^^9 + 7));

    writeln((res2 * to!BigInt(6)) % (10^^9 + 7));
}


You are given an integer N. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and N, inclusive; there will be  of them.You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis. Find the minimal number of layers you have to use for the given N.

The only input line contains a single integer N (1 ≤ N ≤ 100).

Output a single integer - the minimal number of layers required to draw the segments for the given N.

NoteAs an example, here are the segments and their optimal arrangement into layers for N = 4.

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

void main() {
    int n;
    scan(n);

    int k = n/2;
    int ans = (n&1 ? (k+1)^^2 : k*(k+1));

    writeln(ans);
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    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);
        }
    }
}


Luke Skywalker got locked up in a rubbish shredder between two presses. R2D2 is already working on his rescue, but Luke needs to stay alive as long as possible. For simplicity we will assume that everything happens on a straight line, the presses are initially at coordinates 0 and L, and they move towards each other with speed v1 and v2, respectively. Luke has width d and is able to choose any position between the presses. Luke dies as soon as the distance between the presses is less than his width. Your task is to determine for how long Luke can stay alive.

The first line of the input contains four integers d, L, v1, v2 (1 ≤ d, L, v1, v2 ≤ 10 000, d < L) — Luke's width, the initial position of the second press and the speed of the first and second presses, respectively.

Print a single real value — the maximum period of time Luke can stay alive for. Your answer will be considered correct if its absolute or relative error does not exceed 10 - 6.  Namely: let's assume that your answer is a, and the answer of the jury is b. The checker program will consider your answer correct, if .

NoteIn the first sample Luke should stay exactly in the middle of the segment, that is at coordinates [2;4], as the presses move with the same speed.In the second sample he needs to occupy the position . In this case both presses move to his edges at the same time.

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

        double read_double() {
                return read_string.to!double;
        }
        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // int t = cin.read_int;
        while (t--) {
                double d = cin.read_double;
                double L = cin.read_double;
                double v1 = cin.read_double;
                double v2 = cin.read_double;

                double rel_vel = v1 + v2;
                double dist = L - d;
                writefln("%.*f", 18, (dist) / (rel_vel));
        }
}

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

        double read_double() {
                return read_string.to!double;
        }
        string[] tokens;
}

void main() {
        IO cin;
        int t = 1;
        // int t = cin.read_int;
        while (t--) {
                double d = cin.read_double;
                double L = cin.read_double;
                double v1 = cin.read_double;
                double v2 = cin.read_double;

                double rel_vel = v1 + v2 + 0.0;
                double dist = L - d - 0.0;
                writefln("%.*f", 18, (dist) / (rel_vel));
        }
}


You are developing a new feature for the website which sells airline tickets: being able to sort tickets by price! You have already extracted the tickets' prices, so there's just the last step to be done...You are given an array of integers. Sort it in non-descending order.

The input consists of a single line of space-separated integers. The first number is n (1 ≤ n ≤ 10) — the size of the array. The following n numbers are the elements of the array (1 ≤ ai ≤ 100).

Output space-separated elements of the sorted array.

NoteRemember, this is a very important feature, and you have to make sure the customers appreciate it!

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)
	{
		auto a = readln.split.map !(to !(int)).array;
		sort (a);
		foreach (i; 0..1_000_000_000)
		{
			if (n == -1)
			{
				assert (false);
			}
			n ^= 2;
		}
		writefln ("%(%s %)", a);
	}
}


Our bear's forest has a checkered field. The checkered field is an n × n table, the rows are numbered from 1 to n from top to bottom, the columns are numbered from 1 to n from left to right. Let's denote a cell of the field on the intersection of row x and column y by record (x, y). Each cell of the field contains growing raspberry, at that, the cell (x, y) of the field contains x + y raspberry bushes.The bear came out to walk across the field. At the beginning of the walk his speed is (dx, dy). Then the bear spends exactly t seconds on the field. Each second the following takes place:  Let's suppose that at the current moment the bear is in cell (x, y).  First the bear eats the raspberry from all the bushes he has in the current cell. After the bear eats the raspberry from k bushes, he increases each component of his speed by k. In other words, if before eating the k bushes of raspberry his speed was (dx, dy), then after eating the berry his speed equals (dx + k, dy + k).  Let's denote the current speed of the bear (dx, dy) (it was increased after the previous step). Then the bear moves from cell (x, y) to cell (((x + dx - 1) mod n) + 1, ((y + dy - 1) mod n) + 1).  Then one additional raspberry bush grows in each cell of the field. You task is to predict the bear's actions. Find the cell he ends up in if he starts from cell (sx, sy). Assume that each bush has infinitely much raspberry and the bear will never eat all of it.

The first line of the input contains six space-separated integers: n, sx, sy, dx, dy, t (1 ≤ n ≤ 109; 1 ≤ sx, sy ≤ n;  - 100 ≤ dx, dy ≤ 100; 0 ≤ t ≤ 1018).

Print two integers — the coordinates of the cell the bear will end up in after t seconds.

NoteOperation a mod b means taking the remainder after dividing a by b. Note that the result of the operation is always non-negative. For example, ( - 1) mod 3 = 2.In the first sample before the first move the speed vector will equal (3,4) and the bear will get to cell (4,1). Before the second move the speed vector will equal (9,10) and he bear will get to cell (3,1). Don't forget that at the second move, the number of berry bushes increased by 1.In the second sample before the first move the speed vector will equal (1,1) and the bear will get to cell (1,1). Before the second move, the speed vector will equal (4,4) and the bear will get to cell (1,1). Don't forget that at the second move, the number of berry bushes increased by 1.

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;
import core.bitop;

int mod;

struct modint
{
	long value;

	alias value this;

	this (long nvalue)
	{
		value = nvalue % mod;
	}

	modint opBinary (string op) (long other)
	{
		return mixin ("modint ((value " ~ op ~ " other) % mod)");
	}

	modint opBinary (string op) (modint other)
	{
		return opBinary !(op) (other.value);
	}

	modint opAssign (long nvalue)
	{
		value = nvalue % mod;
		return this;
	}

	modint opOpAssign (string op, T) (T other)
	{
		mixin ("this = this " ~ op ~ " other;");
		return this;
	}

	string toString ()
	{
		return to !(string) (value);
	}
}

immutable int SIDE = 6;
alias modint [SIDE] vector;
alias vector [SIDE] matrix;

matrix mult (const ref matrix a, const ref matrix b)
{
	matrix res;
	foreach (i; 0..SIDE)
	{
		foreach (j; 0..SIDE)
		{
			foreach (k; 0..SIDE)
			{
				res[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	return res;
}

vector mult (const ref matrix a, const ref vector b)
{
	vector res;
	foreach (i; 0..SIDE)
	{
		foreach (j; 0..SIDE)
		{
			res[i] += a[i][j] * b[j];
		}
	}
	return res;
}

matrix powmod (matrix a, long b)
{
	matrix res;
	foreach (i; 0..SIDE)
	{
		res[i][i] = 1;
	}
	while (b)
	{
		if (b & 1)
		{
			res = mult (res, a);
		}
		a = mult (a, a);
		b >>= 1;
	}
	return res;
}

void main ()
{
	int n, sx, sy, dx, dy;
	long t;
	mod = 1_000_000_000;
	matrix m = cast (matrix)
/*
x, y, dx, dy, t, 1:
x       x + dx + x + y + t + 2
y       y + dy + x + y + t + 2
dx      dx + x + y + t + 2
dy      dy + x + y + t + 2
t       t + 1
1       1
*/
	[[2L, 1L, 1L, 0L, 1L, 0L],
	 [1L, 2L, 0L, 1L, 1L, 0L],
	 [1L, 1L, 1L, 0L, 1L, 0L],
	 [1L, 1L, 0L, 1L, 1L, 0L],
	 [0L, 0L, 0L, 0L, 1L, 1L],
	 [0L, 0L, 0L, 0L, 0L, 1L]];
	while (readf (" %s %s %s %s %s %s", &n, &sx, &sy, &dx, &dy, &t) > 0)
	{
		mod = n;
		vector v = [modint (sx), modint (sy),
		    modint (dx), modint (dy), modint (0), modint (1)];
		matrix a = powmod (m, t);
		vector res = mult (a, v);
		int x = cast (int) (res[0] - 1 + mod);
		int y = cast (int) (res[1] - 1 + mod);
		enforce (0 <= x && x < n);
		enforce (0 <= y && y < n);
		writeln (x + 1, ' ', y + 1);
	}
}

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;
import core.bitop;

int mod;

struct modint
{
	int value;

	alias value this;

	this (int nvalue)
	{
		value = nvalue % mod;
	}

	modint opBinary (string op) (int other)
	{
		return mixin ("modint ((cast (long) value " ~
		              op ~ " other) % mod)");
	}

	modint opOpAssign (string op, T) (T other)
	{
		return mixin ("(this = this " ~ op ~ " other)");
	}
}

immutable int SIDE = 6;
alias modint [SIDE] vector;
alias vector [SIDE] matrix;

matrix mult (const ref matrix a, const ref matrix b)
{
	matrix res;
	foreach (i; 0..SIDE)
	{
		foreach (j; 0..SIDE)
		{
			foreach (k; 0..SIDE)
			{
				res[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	return res;
}

vector mult (const ref matrix a, const ref vector b)
{
	vector res;
	foreach (i; 0..SIDE)
	{
		foreach (j; 0..SIDE)
		{
			res[i] += a[i][j] * b[j];
		}
	}
	return res;
}

matrix powmod (matrix a, long b)
{
	matrix res;
	foreach (i; 0..SIDE)
	{
		res[i][i] = 1;
	}
	while (b)
	{
		if (b & 1)
		{
			res = mult (res, a);
		}
		a = mult (a, a);
		b >>= 1;
	}
	return res;
}

void main ()
{
	int n, sx, sy, dx, dy;
	long t;
	matrix m = cast (matrix)
/*
x, y, dx, dy, t, 1:
x       x + dx + x + y + t + 2
y       y + dy + x + y + t + 2
dx      dx + x + y + t + 2
dy      dy + x + y + t + 2
t       t + 1
1       1
*/
	[[2, 1, 1, 0, 1, 2],
	 [1, 2, 0, 1, 1, 2],
	 [1, 1, 1, 0, 1, 2],
	 [1, 1, 0, 1, 1, 2],
	 [0, 0, 0, 0, 1, 1],
	 [0, 0, 0, 0, 0, 1]];
	while (readf (" %s %s %s %s %s %s", &n, &sx, &sy, &dx, &dy, &t) > 0)
	{
		mod = n;
		vector v = [modint (sx - 1), modint (sy - 1),
		    modint (dx), modint (dy), modint (0), modint (1)];
		auto a = powmod (m, t);
		vector res = mult (a, v);
		writeln (cast (int) (res[0] + mod) + 1, ' ',
		         cast (int) (res[1] + mod) + 1);
	}
}

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;
import core.bitop;

int mod;

struct modint
{
	int value;

	alias value this;

	this (int nvalue)
	{
		value = nvalue % mod;
	}

	modint opBinary (string op) (int other)
	{
		return mixin ("modint (((cast (long) (value)) " ~
		              op ~ " (other)) % mod)");
	}

	modint opOpAssign (string op, T) (T other)
	{
		return mixin ("((this) = ((this) " ~ op ~ " (other)))");
	}
}

immutable int SIDE = 6;
alias modint [SIDE] vector;
alias vector [SIDE] matrix;

matrix mult (const ref matrix a, const ref matrix b)
{
	matrix res;
	foreach (i; 0..SIDE)
	{
		foreach (j; 0..SIDE)
		{
			foreach (k; 0..SIDE)
			{
				res[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	return res;
}

vector mult (const ref matrix a, const ref vector b)
{
	vector res;
	foreach (i; 0..SIDE)
	{
		foreach (j; 0..SIDE)
		{
			res[i] += a[i][j] * b[j];
		}
	}
	return res;
}

matrix powmod (matrix a, long b)
{
	matrix res;
	foreach (i; 0..SIDE)
	{
		res[i][i] = 1;
	}
	while (b)
	{
		if (b & 1)
		{
			res = mult (res, a);
		}
		a = mult (a, a);
		b >>= 1;
	}
	return res;
}

void main ()
{
	int n, sx, sy, dx, dy;
	long t;
	matrix m = cast (matrix)
/*
x, y, dx, dy, t, 1:
x       x + dx + x + y + t + 2
y       y + dy + x + y + t + 2
dx      dx + x + y + t + 2
dy      dy + x + y + t + 2
t       t + 1
1       1
*/
	[[2, 1, 1, 0, 1, 0],
	 [1, 2, 0, 1, 1, 0],
	 [1, 1, 1, 0, 1, 0],
	 [1, 1, 0, 1, 1, 0],
	 [0, 0, 0, 0, 1, 1],
	 [0, 0, 0, 0, 0, 1]];
	while (readf (" %s %s %s %s %s %s", &n, &sx, &sy, &dx, &dy, &t) > 0)
	{
		mod = n;
		vector v = [modint (sx), modint (sy),
		    modint (dx), modint (dy), modint (0), modint (1)];
		matrix a = powmod (m, t);
		vector res = mult (a, v);
		writeln (cast (int) (res[0] + mod - 1) + 1, ' ',
		         cast (int) (res[1] + mod - 1) + 1);
	}
}

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;
import core.bitop;

int mod;

struct modint
{
	int value;

	alias value this;

	this (int nvalue)
	{
		value = nvalue % mod;
	}

	modint opBinary (string op) (int other)
	{
		return mixin ("modint (((cast (long) (value)) " ~
		              op ~ " (other)) % mod)");
	}

	modint opOpAssign (string op, T) (T other)
	{
		return mixin ("((this) = ((this) " ~ op ~ " (other)))");
	}
}

immutable int SIDE = 6;
alias modint [SIDE] vector;
alias vector [SIDE] matrix;

matrix mult (const ref matrix a, const ref matrix b)
{
	matrix res;
	foreach (i; 0..SIDE)
	{
		foreach (j; 0..SIDE)
		{
			foreach (k; 0..SIDE)
			{
				res[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	return res;
}

vector mult (const ref matrix a, const ref vector b)
{
	vector res;
	foreach (i; 0..SIDE)
	{
		foreach (j; 0..SIDE)
		{
			res[i] += a[i][j] * b[j];
		}
	}
	return res;
}

matrix powmod (matrix a, long b)
{
	matrix res;
	foreach (i; 0..SIDE)
	{
		res[i][i] = 1;
	}
	while (b)
	{
		if (b & 1)
		{
			res = mult (res, a);
		}
		a = mult (a, a);
		b >>= 1;
	}
	return res;
}

void main ()
{
	int n, sx, sy, dx, dy;
	long t;
	matrix m = cast (matrix)
/*
x, y, dx, dy, t, 1:
x       x + dx + x + y + t + 2
y       y + dy + x + y + t + 2
dx      dx + x + y + t + 2
dy      dy + x + y + t + 2
t       t + 1
1       1
*/
	[[2, 1, 1, 0, 1, 2],
	 [1, 2, 0, 1, 1, 2],
	 [1, 1, 1, 0, 1, 2],
	 [1, 1, 0, 1, 1, 2],
	 [0, 0, 0, 0, 1, 1],
	 [0, 0, 0, 0, 0, 1]];
	while (readf (" %s %s %s %s %s %s", &n, &sx, &sy, &dx, &dy, &t) > 0)
	{
		mod = n;
		vector v = [modint (sx - 1), modint (sy - 1),
		    modint (dx), modint (dy), modint (0), modint (1)];
		auto a = powmod (m, t);
		vector res;
		if (t < 10000)
		{
			res = v;
			foreach (s; 0..t)
			{
				res = mult (m, res);
			}
		}
		else
		{
			res = mult (a, v);
		}
		writeln (cast (int) (res[0] + mod) + 1, ' ',
		         cast (int) (res[1] + mod) + 1);
	}
}

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;
import core.bitop;

int mod;

struct modint
{
	int value;

	alias value this;

	this (int nvalue)
	{
		value = nvalue % mod;
	}

	modint opBinary (string op) (int other)
	{
		return mixin ("modint (((cast (long) (value)) " ~
		              op ~ " (other)) % mod)");
	}

	modint opOpAssign (string op, T) (T other)
	{
		return mixin ("((this) = ((this) " ~ op ~ " (other)))");
	}
}

immutable int SIDE = 6;
alias modint [SIDE] vector;
alias vector [SIDE] matrix;

matrix mult (const ref matrix a, const ref matrix b)
{
	matrix res;
	foreach (i; 0..SIDE)
	{
		foreach (j; 0..SIDE)
		{
			foreach (k; 0..SIDE)
			{
				res[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	return res;
}

vector mult (const ref matrix a, const ref vector b)
{
	vector res;
	foreach (i; 0..SIDE)
	{
		foreach (j; 0..SIDE)
		{
			res[i] += a[i][j] * b[j];
		}
	}
	return res;
}

matrix powmod (matrix a, long b)
{
	matrix res;
	foreach (i; 0..SIDE)
	{
		res[i][i] = 1;
	}
	while (b)
	{
		if (b & 1)
		{
			res = mult (res, a);
		}
		a = mult (a, a);
		b >>= 1;
	}
	return res;
}

void main ()
{
	int n, sx, sy, dx, dy;
	long t;
	matrix m = cast (matrix)
/*
x, y, dx, dy, t, 1:
x       x + dx + x + y + t + 2
y       y + dy + x + y + t + 2
dx      dx + x + y + t + 2
dy      dy + x + y + t + 2
t       t + 1
1       1
*/
	[[2, 1, 1, 0, 1, 0],
	 [1, 2, 0, 1, 1, 0],
	 [1, 1, 1, 0, 1, 0],
	 [1, 1, 0, 1, 1, 0],
	 [0, 0, 0, 0, 1, 1],
	 [0, 0, 0, 0, 0, 1]];
	while (readf (" %s %s %s %s %s %s", &n, &sx, &sy, &dx, &dy, &t) > 0)
	{
		mod = n;
		vector v = [modint (sx), modint (sy),
		    modint (dx), modint (dy), modint (0), modint (1)];
		matrix a = powmod (m, t);
		vector res = mult (a, v);
		writeln (cast (int) (res[0] - 1 + mod) + 1, ' ',
		         cast (int) (res[1] - 1 + mod) + 1);
	}
}

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;
import core.bitop;

int mod;

struct modint
{
	int value;

	alias value this;

	this (int nvalue)
	{
		value = nvalue;
	}

	modint opBinary (string op) (int other)
	{
		return mixin ("modint ((cast (long) value " ~
		              op ~ " other) % mod)");
	}

	modint opOpAssign (string op, T) (T other)
	{
		return mixin ("(this = this " ~ op ~ " other)");
	}
}

immutable int SIDE = 6;
alias modint [SIDE] vector;
alias vector [SIDE] matrix;

matrix mult (const ref matrix a, const ref matrix b)
{
	matrix res;
	foreach (i; 0..SIDE)
	{
		foreach (j; 0..SIDE)
		{
			foreach (k; 0..SIDE)
			{
				res[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	return res;
}

vector mult (const ref matrix a, const ref vector b)
{
	vector res;
	foreach (i; 0..SIDE)
	{
		foreach (j; 0..SIDE)
		{
			res[i] += a[i][j] * b[j];
		}
	}
	return res;
}

matrix powmod (matrix a, long b)
{
	matrix res;
	foreach (i; 0..SIDE)
	{
		res[i][i] = 1;
	}
	while (b)
	{
		if (b & 1)
		{
			res = mult (res, a);
		}
		a = mult (a, a);
		b >>= 1;
	}
	return res;
}

void main ()
{
	int n, sx, sy, dx, dy;
	long t;
	matrix m = cast (matrix)
/*
x, y, dx, dy, t, 1:
x       x + dx + x + y + t + 2
y       y + dy + x + y + t + 2
dx      dx + x + y + t + 2
dy      dy + x + y + t + 2
t       t + 1
1       1
*/
	[[2, 1, 1, 0, 1, 2],
	 [1, 2, 0, 1, 1, 2],
	 [1, 1, 1, 0, 1, 2],
	 [1, 1, 0, 1, 1, 2],
	 [0, 0, 0, 0, 1, 1],
	 [0, 0, 0, 0, 0, 1]];
	while (readf (" %s %s %s %s %s %s", &n, &sx, &sy, &dx, &dy, &t) > 0)
	{
		mod = n;
		vector v = [modint (sx - 1), modint (sy - 1),
		    modint (dx), modint (dy), modint (0), modint (1)];
		auto a = powmod (m, t);
		vector res = mult (a, v);
		writeln (cast (int) (res[0] + mod) + 1, ' ',
		         cast (int) (res[1] + mod) + 1);
	}
}

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;
import core.bitop;

int mod;

struct modint
{
	int value;

	alias value this;

	this (int nvalue)
	{
		value = nvalue % mod;
	}

	modint opBinary (string op) (int other)
	{
		return mixin ("modint (((cast (long) (value)) " ~
		              op ~ " (other)) % mod)");
	}

	modint opOpAssign (string op, T) (T other)
	{
		return mixin ("((this) = ((this) " ~ op ~ " (other)))");
	}
}

immutable int SIDE = 6;
alias modint [SIDE] vector;
alias vector [SIDE] matrix;

matrix mult (const ref matrix a, const ref matrix b)
{
	matrix res;
	foreach (i; 0..SIDE)
	{
		foreach (j; 0..SIDE)
		{
			foreach (k; 0..SIDE)
			{
				res[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	return res;
}

vector mult (const ref matrix a, const ref vector b)
{
	vector res;
	foreach (i; 0..SIDE)
	{
		foreach (j; 0..SIDE)
		{
			res[i] += a[i][j] * b[j];
		}
	}
	return res;
}

matrix powmod (matrix a, long b)
{
	matrix res;
	foreach (i; 0..SIDE)
	{
		res[i][i] = 1;
	}
	while (b)
	{
		if (b & 1)
		{
			res = mult (res, a);
		}
		a = mult (a, a);
		b >>= 1;
	}
	return res;
}

void main ()
{
	int n, sx, sy, dx, dy;
	long t;
	mod = 1_000_000_000;
	matrix m = cast (matrix)
/*
x, y, dx, dy, t, 1:
x       x + dx + x + y + t + 2
y       y + dy + x + y + t + 2
dx      dx + x + y + t + 2
dy      dy + x + y + t + 2
t       t + 1
1       1
*/
	[[2, 1, 1, 0, 1, 0],
	 [1, 2, 0, 1, 1, 0],
	 [1, 1, 1, 0, 1, 0],
	 [1, 1, 0, 1, 1, 0],
	 [0, 0, 0, 0, 1, 1],
	 [0, 0, 0, 0, 0, 1]];
	while (readf (" %s %s %s %s %s %s", &n, &sx, &sy, &dx, &dy, &t) > 0)
	{
		mod = n;
		vector v = [modint (sx), modint (sy),
		    modint (dx), modint (dy), modint (0), modint (1)];
		matrix a = powmod (m, t);
		vector res = mult (a, v);
		int x = res[0] - 1 + mod;
		int y = res[1] - 1 + mod;
		enforce (0 <= x && x < n);
		enforce (0 <= y && y < n);
		writeln (x + 1, ' ', y + 1);
	}
}


Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area.To prove his skills, Ivan decided to demonstrate his friends a concept of random picture. A picture is a field of $$$n$$$ rows and $$$m$$$ columns, where each cell is either black or white. Ivan calls the picture random if for every cell it has at most one adjacent cell of the same color. Two cells are considered adjacent if they share a side.Ivan's brothers spent some time trying to explain that it's not how the randomness usually works. Trying to convince Ivan, they want to count the number of different random (according to Ivan) pictures. Two pictures are considered different if at least one cell on those two picture is colored differently. Since the number of such pictures may be quite large, print it modulo $$$10^9 + 7$$$.

The only line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 100\,000$$$), the number of rows and the number of columns of the field.

Print one integer, the number of random pictures modulo $$$10^9 + 7$$$.

NoteThe picture below shows all possible random pictures of size $$$2$$$ by $$$3$$$.

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

void main()
{
    immutable int MD = 10 ^^ 9 + 7;
    int n, m;
    readf("%s %s", &n, &m);
    readln;

    int[] dp;
    dp ~= 0;
    dp ~= 2;
    dp ~= 4;
    foreach (i; 3 .. max(n, m) + 1) {
        dp ~= (dp[i-1] + dp[i-2]) % MD;
    }

    debug { dp.writeln; }

    int ans = (((dp[n] + dp[m] - 2) % MD) + MD) % MD;

    ans.writeln;
}

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

immutable int mod = 10 ^^ 9 + 7;
immutable int limit = 100_005;

void main ()
{
	auto f = new int [limit];
	f[0] = 1;
	f[1] = 1;
	foreach (i; 2..limit)
	{
		f[i] = (f[i - 1] + f[i - 2]) % mod;
	}

	int m, n;
	while (readf !(" %s %s") (&m, &n) > 0)
	{
		int res = 0;
		res = (res + f[m]) % mod;
		res = (res + f[n]) % mod;
		res = (res + mod - 1) % mod;
		res = (res * 2) % mod;
		writeln (res);
	}
}


Natasha is planning an expedition to Mars for $$$n$$$ people. One of the important tasks is to provide food for each participant.The warehouse has $$$m$$$ daily food packages. Each package has some food type $$$a_i$$$.Each participant must eat exactly one food package each day. Due to extreme loads, each participant must eat the same food type throughout the expedition. Different participants may eat different (or the same) types of food.Formally, for each participant $$$j$$$ Natasha should select his food type $$$b_j$$$ and each day $$$j$$$-th participant will eat one food package of type $$$b_j$$$. The values $$$b_j$$$ for different participants may be different.What is the maximum possible number of days the expedition can last, following the requirements above?

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 100$$$, $$$1 \le m \le 100$$$) — the number of the expedition participants and the number of the daily food packages available. The second line contains sequence of integers $$$a_1, a_2, \dots, a_m$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the type of $$$i$$$-th food package.

Print the single integer — the number of days the expedition can last. If it is not possible to plan the expedition for even one day, print 0.

NoteIn the first example, Natasha can assign type $$$1$$$ food to the first participant, the same type $$$1$$$ to the second, type $$$5$$$ to the third and type $$$2$$$ to the fourth. In this case, the expedition can last for $$$2$$$ days, since each participant can get two food packages of his food type (there will be used $$$4$$$ packages of type $$$1$$$, two packages of type $$$2$$$ and two packages of type $$$5$$$).In the second example, there are $$$100$$$ participants and only $$$1$$$ food package. In this case, the expedition can't last even $$$1$$$ day.

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

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

    int [int] cnt;
    readln.chomp.split.map!(to!int).array.each!(x => ++cnt[x]);

    debug { cnt.writeln; }

    auto okDays = (int days) => cnt.values.map!(x => x / days).sum >= n;
    auto ans = okDays(1) ? (101).iota.dropOne.until!(days => !okDays(days)).array.back : 0;

    ans.writeln;
}

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

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		auto b = new int [101];
		foreach (c; a)
		{
			b[c] += 1;
		}
		int res = 1;
		while (b.map !(x => x / res).sum >= n)
		{
			res += 1;
		}
		writeln (res - 1);
	}
}

import std.algorithm, std.conv, std.range, std.stdio;
void main () {
	int r = 1, n = readln.split[0].to!int;
	int [101] b;
	foreach (c; readln.split) b[c.to!int]++;
	while (b[].map !(x => x / r).sum >= n) r++;
	writeln (r - 1);
}