<file_sep>// https://codeforces.com/contest/520/problem/B
// https://codeforces.com/contest/520/submission/17434691

#include <iostream>
using namespace std;

int main() {
	int n, m, CNT;
	cin >> m >> n;
	for (CNT = 0; n > m; (n&1) ? n++ : n>>= 1, CNT++);
	cout << CNT + (m - n);
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/742/problem/B
// https://codeforces.com/contest/742/submission/22797691

#include <stdio.h>
#include <iostream>
#include <vector>
using namespace std;


int main()
{
   vector<int> frecv(200005, 0);
   int n, k, x;
   long long cnt = 0;
   scanf("%d %d", &n, &k);

   while (n--)
   {
      scanf("%d", &x);
      cnt += frecv[x^k];
      frecv[x]++;
   }

   cout << cnt;

   return 0;
}<file_sep>// https://codeforces.com/contest/455/problem/A
// https://codeforces.com/contest/455/submission/15059708

#include <iostream>

using namespace std;

long long v[100001];

int main()
{
    int x,n;
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>x;
        v[x]+=x;
    }
    v[0] = 0;
    for (int i = 2; i<= 100000;i++)
    {
            v[i] = max(v[i-2]+v[i],v[i-1]);
    }
    cout<<v[100000];
    return 0;
}
<file_sep>// https://codeforces.com/contest/155/problem/A
// https://codeforces.com/contest/155/submission/13958025

#include <iostream>
using namespace std;

int main()
{
    int x,n,mins,maxs,nr;
    cin>>n;
    cin>>mins;
    maxs=mins;
    nr=0;
    while (n-1>0)
    {
        cin>>x;
        if (x<mins)
        {
            nr++;
            mins=x;
        }
        if (x>maxs)
        {
            nr++;
            maxs=x;
        }
        n--;
    }
    cout<<nr;
    return 0;
}
<file_sep>// https://codeforces.com/contest/683/problem/A
// https://codeforces.com/contest/683/submission/18524836

fun main(args: Array<String>) {
    val (a, x, y) = readLine()!!.split(' ').map(String::toInt)
    if (x < 0) println(2);
    else if (y < 0) println(2);
    else{
		if (x == 0){
			if (y <= a) println(1);
			else println(2); 
		}
		else if (y == 0){
			if (x <= a) println(1);
			else println(2);
		}
		else{
        if (a > x){
            if (a == y) println(1);
            else if (a > y) println(0);
            else println(2);
        }else if (a==x){
            if (y > a) println(2);
            else println(1);
        }else println(2);
		}
    }
}<file_sep>// https://codeforces.com/contest/620/problem/A
// https://codeforces.com/contest/620/submission/18017494

#include <iostream>
#include <algorithm>
using namespace std;



int main() {

	int xi, yi, xf, yf;
	cin >> xi >> yi >> xf >> yf;
	cout << max(abs(xf - xi), abs(yf - yi));


	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/746/problem/D
// https://codeforces.com/contest/746/submission/23107000

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

void doString(string& s, int nmb, char c)
{
   string kappa = "";
   for (int i = 0; i < nmb; ++i)
   {
      kappa += c;
   }
   s += kappa;
}

int main()
{
   int n, k, a, b;
   cin >> n >> k >> a >> b;
   bool ok = true;
   string sol = "";
   int mx;

   while (a > 0 && b > 0)
   {
      if (a > b)
      {
         if (sol != "" && sol[sol.size() - 1] == 'G')
         {
            b--;
            sol += 'B';
         }
         mx = min(a, k);
         doString(sol, mx, 'G');
         a -= mx;
      }
      else
      {
         if (sol != "" && sol[sol.size() - 1] == 'B')
         {
            a--;
            sol += 'G';
         }
         mx = min(b, k);
         doString(sol, mx, 'B');
         b -= mx;
      }
   }
   if (a > k || (a > 0 && sol[sol.size() - 1] == 'G')) ok = false;
   else doString(sol, a, 'G');
   if (b > k || (b > 0 && sol[sol.size() - 1] == 'B')) ok = false;
   else doString(sol, b, 'B');

   sol += '\n';
   if (!ok) puts("NO");
   else cout << sol;
   return 0;
}<file_sep>// https://codeforces.com/contest/678/problem/A
// https://codeforces.com/contest/678/submission/18418106

#include <iostream>
using namespace std;

int main() {
	int n, k, nr = 1;
	cin >> n >> k;
	nr += n / k;

	cout << k * nr;



	return 0;
}<file_sep>// https://codeforces.com/contest/798/problem/A
// https://codeforces.com/contest/798/submission/46797924

#include <iostream>
#include <string>
using namespace std;

int Sol(const std::string& s)
{
	int nr = 0;
	for (size_t i = 0, j = s.size() - 1; i < j; ++i, --j)
	{
		if (s[i] != s[j]) nr++;
	}
	
	if (nr == 0 && s.size() % 2 != 0) return 1;
	return nr;
}

int main()
{
	string s; 
	cin >> s;

	Sol(s) == 1 ? cout << "YES" : cout << "NO";

	return 0;
}<file_sep>// https://codeforces.com/contest/534/problem/A
// https://codeforces.com/contest/534/submission/18029863

#include <iostream>
using namespace std;


int main() {

	int n, prim, ultim;
	cin >> n;
	if (n == 1 || n == 2) cout << "1\n1";
	else if (n == 3) cout << "2\n1 3";
	else if (n == 4) cout << "4\n3 1 4 2";
	else {
		cout << n << "\n";
		for (prim = 1, ultim = (n + 1) / 2 + 1; prim <= (n + 1) / 2; prim++, ultim++) {
			cout << prim << " "; if (ultim <= n) cout << ultim << " ";
		}
	}
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/230/problem/B
// https://codeforces.com/contest/230/submission/17466110

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

bool prime(long long x) {
	if (x == 1) return false;
	for (long long i = 2; i <= long long(sqrt(double(x))); i++) {
		if (x % i == 0) return false;
	}
	return true;
}

int main() {

	long long n, t, i;
	scanf("%I64d", &n);
	for (; n > 0; n--) {
		scanf("%I64d", &t);
		i = long long(sqrt(double(t)));
		if (i * i != t) puts("NO");
		else {
			if (prime(i)) puts("YES");
			else puts("NO");
		}
	}

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/456/problem/A
// https://codeforces.com/contest/456/submission/16613518

#include <iostream>
#include <malloc.h>
#include <algorithm>
using namespace std;


typedef struct {
	int quality, price;
}MyVector;

bool compare(MyVector a, MyVector b) { return a.price < b.price; }
char* solve(MyVector*, int);

int main(int argc, char*argv[]) {

	int n;
	MyVector *v;
	cin >> n;
	v = (MyVector*)malloc(n*sizeof(MyVector));
	for (int i = 0; i < n; i++) cin >> v[i].price >> v[i].quality;
	sort(v, v + n, compare);
	cout << solve(v, n);
	free(v);
	return EXIT_SUCCESS;
}

char* solve(MyVector* v, int size) {
	for (int i = 0; i < size - 1; i++) if (v[i].quality > v[i + 1].quality) return "Happy Alex";
	return "Poor Alex";
}<file_sep># https://codeforces.com/contest/441/problem/A
# https://codeforces.com/contest/441/submission/14872818

n, v = map(int,input().split())
vanz = []
i = 1
while (i<=n):
    l = list(map(int,input().split()))
    if v > min(l[1:]):
        vanz.append(i)
    i += 1
print(len(vanz))
for el in vanz:
    print(el, end = ' ' )
<file_sep>// https://www.spoj.com/problems/ACODE/

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long
#define ull unsigned long long

/*------------------------------------------------------------------*/

int main()
{
   ios_base::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr);

   string s;
   cin >> s;
   ull best[5005];
   int m;

   while (s != "0")
   {
      m = s.length();
      best[m - 1] = best[m] = 1;

      s += '4';

      for (int i = m - 2; i >= 0; --i)
      {
         best[i] = best[i + 1];
         if (s[i] != '1' && s[i] != '2' && s[i+1] == '0')
         {
            best[0] = 0;
            break;
         }
         if (s[i] != '0' && s[i + 1] == '0') continue;
         if (s[i + 2] == '0') continue;
         if (s[i] == '1' || (s[i] == '2' && s[i + 1] <= '7')) best[i] += best[i + 2];
      }
      jmp:
      cout << best[0] << '\n';
      cin >> s;
   }


   return 0;
}
<file_sep>// https://codeforces.com/contest/276/problem/A
// https://codeforces.com/contest/276/submission/17523475

#include <iostream>
using namespace std;

#define MAX 0x3B9ACA01

int main() {

	int n, k, max = -MAX, joy, t;
	cin >> n >> k;
	for (; n > 0; n--) {
		cin >> joy >> t;
		if (k >= t) {
			if (max < joy)max = joy;
		}
		else if (max < joy - (t - k)) max = joy - (t - k);
	}
	cout << max;

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/262/problem/A
// https://codeforces.com/contest/262/submission/17331632

#include <iostream>
using std::cin;
using std::cout;

int main() {

	int n, k, x, nr = 0, aux;
	cin >> n >> k;
	for (; n > 0; n--) {
		cin >> x;
		aux = 0;
		for (; x != 0;x /= 10) if (x % 10 == 4 || x % 10 == 7) aux++;
		if (aux <= k) nr++;
	}
	cout << nr;
	return EXIT_SUCCESS;

}<file_sep>// https://codeforces.com/contest/551/problem/A
// https://codeforces.com/contest/551/submission/14410809

#include <iostream>

using namespace std;

int r[2001],e[2001],v[2001];

int main()
{
    int n;
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>e[i];
        v[e[i]]++;
    }
    r[2000]=0;
    for (int i=1999;i>=1;i--)
    {
        r[i] = v[i+1]+r[i+1];
    }
    for (int i=1;i<=n;i++)
    {
        cout<<r[e[i]]+1<<" ";
    }
    return 0;
}
<file_sep>// https://codeforces.com/contest/583/problem/B
// https://codeforces.com/contest/583/submission/17567732

#include <iostream>
using namespace std;


int main() {
	
	int v[1001], n, nr = -1, cnt = 0, i, j;
	char ok = '0';
	cin >> n;
	for (int i = 0; i < n; i++)cin >> v[i];
	while (cnt < n) {
		nr++;
		if (ok == '0') j = 1, i = 0, ok = '1';
		else j = -1, i = n - 1, ok = '0';
		for (; i < n && i >= 0; i += j) {
			if (v[i] <= cnt) cnt++, v[i] = 1001;
		}
	}
	cout << nr;

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/664/problem/A
// https://codeforces.com/contest/664/submission/17350147

#include <string>
#include <iostream>
using namespace std;


int main() {
	string a, b;
	cin >> a >> b;
	if (a != b)cout << "1";
	else cout << a;
	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/461/problem/A
# https://codeforces.com/contest/461/submission/14447388

n = int(input())
m = sorted(list(map(int,input().split())))
s = sum(m)
if n!=1:
    for i in range(n-1):
        s += m[i]*(i+1)
    s+=m[n-1]*(n-1)
print(s)
<file_sep># https://codeforces.com/contest/490/problem/A
# https://codeforces.com/contest/490/submission/14398111

n = int(input())
l = list(map(int,input().split()))
d = {1:[],2:[],3:[]}
for i in range (n):
    d[l[i]].append(i+1)
t = min(len(d[1]),len(d[2]),len(d[3]))
print(t)
while t>0:
    print(d[1].pop(),d[2].pop(),d[3].pop())
    t-=1
<file_sep>// https://codeforces.com/contest/683/problem/B
// https://codeforces.com/contest/683/submission/18525721

fun main(args: Array<String>) {
    val (a) = readLine()!!.split('\n').map(String::toInt)
    var i = 1;
    var arr =  IntArray(a + 2);
    var num =  arrayOfNulls<String>(a + 2);
    while (i <= a){
        val (nm , h) = readLine()!!.split(' ');
        arr[i] = h.toInt();
        num[i] = nm;
        i++;
    }
    i = 1;
    while (i <= a){
        var j = i + 1;
        while (j <= a){
            if (arr[i] > arr[j]){
                var aux1 = arr[i];
                var aux2 = num[i];
                arr[i] = arr[j];
                arr[j] = aux1;
                num[i] = num[j];
                num[j] = aux2;
            }
            j++;
        }
        i++;
    }
    i = 1;
    while (i <= a){
        println(num[i]);
        i++;
    }
}<file_sep>// https://codeforces.com/contest/320/problem/A
// https://codeforces.com/contest/320/submission/17146992

#include <iostream>
#include <string>
using namespace std;

#define YES true
#define NO !true

int main()
{
	int i;
	string s;
	bool ok;

	i  = 0;
	ok = YES;
	cin >> s;
	
	while (i < s.length())
	{
		if (s[i] == '1')
		{
			if ( (i + 1) < s.length() && s[i + 1] == '4')
			{
				
				if ( (i + 2) < s.length() && s[i + 2] == '4') i++;
				i++;
			}
			i++;
		}
		else { ok = NO; i++; }
	}

	if (ok) cout << "YES";
	else cout << "NO";

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/787/problem/B
// https://codeforces.com/contest/787/submission/25740045

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long 
#define ull unsigned long long

/*------------------------------------------------------------------*/

int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

   int n, m, mx, x;
   unordered_map<int, int> mp;
   bool ok = true;

   cin >> n >> m;

   for(int i = 1;i <=m && ok; ++i)
   {
      mp.clear();
      ok = false;
      cin >> mx;
      for(int j = 1; j<=mx;++j)
      {
         cin >> x;
         mp[x] = 1;
         if (mp.find(-x) != mp.end()) ok = true;
      }
   }

   (!ok) ? puts("YES") : puts("NO");


   return 0;
}<file_sep>// https://www.spoj.com/problems/PRIME1/

#include <vector>
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

void BuildSieve(vector<int>& Sieve)
{
    const int limit = static_cast<int>(5e5) + 1;
    vector<bool> isPrime(limit, true);

    for (int i = 2; i < limit; ++i)
    {
        if (!isPrime[i]) continue;
        Sieve.push_back(i);

        for (int j = i + i; j < limit; j += i)
        {
            isPrime[j] = false;
        }
    }
}


bool IsPrime(vector<int>& Sieve, long long X)
{
    long long limit = static_cast<long long>(sqrt(static_cast<double>(X))) + 1;
    bool isPrime = X != 1;


    for (const auto& p : Sieve)
    {
        if (p >= limit || !isPrime) break;
        if (X % p == 0) isPrime = false;
    }

    if (isPrime) return true;

    for (long long p = Sieve.back(); p < limit && !isPrime; ++p)
    {
        if (X % p == 0) isPrime = false;
    }

    return isPrime;
}

void SolvePrimes(vector<int>& Sieve, long long m, long long n)
{
    for (long long i = m; i <= n; ++i)
    {
        if (IsPrime(Sieve, i)) cout << i << "\n";
    }

}

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int t;
    vector<int> sieve;
    long long n, m;
    cin >> t;

    BuildSieve(sieve);

    while (t--)
    {
        cin >> m >> n;
        SolvePrimes(sieve, m, n);
        cout << "\n";
    }

    return 0;
}<file_sep>// https://codeforces.com/contest/435/problem/A
// https://codeforces.com/contest/435/submission/17434848

#include <iostream>
using namespace std;


int main() {

	int n, m, cnt, s,x;
	cin >> n >> m;
	for (cnt = 1, s = 0; n > 0; n--) {
		cin >> x;
		if (s + x > m) s = x, cnt++;
		else s += x;
	}
	cout << cnt;

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/752/problem/C
// https://codeforces.com/contest/752/submission/23310300

#include <iostream>
#include <string>
using namespace std;


int main()
{
   int n;
   int cnt = 0, xAxis = 0, yAxis = 0;
   string s;

   cin >> n >> s;
   for (int i = 0; i < n; ++i)
   {
      if (s[i] == 'U')
      {
         if (yAxis == 2) cnt++, xAxis = 0;
         yAxis = 1;
      }
      else if (s[i] == 'D')
      {
         if (yAxis == 1) cnt++, xAxis = 0;
         yAxis = 2;
      }
      else if (s[i] == 'R')
      {
         if (xAxis == 2) cnt++, yAxis = 0;
         xAxis = 1;
      }
      else if (s[i] == 'L')
      {
         if (xAxis == 1) cnt++, yAxis = 0;
         xAxis = 2;
      }
   }

   cout << cnt + 1;

   return 0;
}<file_sep># https://codeforces.com/contest/71/problem/A
# https://codeforces.com/contest/71/submission/13404842

n=input()
n=int(n)
for i in range(n):
    s=input()
    if (len(s)>10):
        print(s[0],len(s)-2,s[len(s)-1], sep='')
    else:
        print(s)
<file_sep>// https://codeforces.com/contest/584/problem/A
// https://codeforces.com/contest/584/submission/14045532

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,n,k;
    scanf("%d %d",&n,&k);
    if (k==10 && n==1){printf("-1");}
    else{
    if (k==10){printf("1");}
    else{printf("%d",k);}
    for (i=1;i<=n-1;i++)
    {
        printf("0");
    }
    }
    return 0;
}
<file_sep>// https://codeforces.com/contest/479/problem/C
// https://codeforces.com/contest/479/submission/17480481

#include <iostream>
#include <algorithm>
using namespace std;

typedef struct _ELEM {
	int o1, o2;
}ELEM;

int main() {

	ELEM v[5001];
	int n, maxs;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> v[i].o1 >> v[i].o2;
	sort(v, v + n, [](ELEM st, ELEM dr) {return (st.o1 < dr.o1 || st.o1 == dr.o1 && st.o2 < dr.o2); });
	maxs = min(v[0].o1, v[0].o2);
	for (int i = 1; i < n; i++)
		(min(v[i].o1, v[i].o2) >= maxs) ? maxs = min(v[i].o1, v[i].o2) : maxs = max(v[i].o1, v[i].o2);
	cout << maxs;
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/725/problem/B
// https://codeforces.com/contest/725/submission/21679692

#include <string>
#include <iostream>
using namespace std;

int val(char dgt)
{
   if (dgt == 'f') return 1;
   if (dgt == 'e') return 2;
   if (dgt == 'd') return 3;
   if (dgt == 'a') return 4;
   if (dgt == 'b') return 5;
   if (dgt == 'c') return 6;
}

int main()
{
   string s;
   char c;
   int r;
   unsigned long long  num, cmp = 0;
   cin >> s;
   c = s[s.size() - 1];
   num = stoull(s.substr(0, s.size() - 1));
   
   r = num % 4;
   if (r == 0) num--;
   cmp = 16 * (num / 4);

   if (r == 1 || r == 3)
   {
      cmp += val(c);
   }
   else if (r == 2 || r == 0)
   {
      cmp += 7 + val(c);
   }

   cout << cmp;

   return 0;
}<file_sep>// https://codeforces.com/contest/729/problem/A
// https://codeforces.com/contest/729/submission/22715444

#include <iostream>
#include <string>
using namespace std;


int main()
{
   string sol = "";
   int n;
   string s;
   cin >> n >> s;

   size_t i = 0;
   size_t j;
   while (i < s.size())
   {
      if (i + 2 < s.size())
      {
         if (s[i] == 'o' && s[i + 1] == 'g' && s[i + 2] == 'o')
         {
            j = i + 3;
            bool ok = true;
            while (j < s.size() && ok)
            {
               if (j + 1 < s.size())
               {
                  if (s[j] == 'g' && s[j + 1] == 'o') j += 2;
                  else ok = false;
               }
               else (ok = false);
            }
            sol += "***";
            i = j;
         }
         else
         {
            sol += s[i];
            i++;
         }
      }
      else
      {
         sol += s[i];
         i++;
      }
   }
   cout << sol;
   return 0;
}<file_sep>// https://codeforces.com/contest/496/problem/A
// https://codeforces.com/contest/496/submission/47180521

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;



int main()
{
	ios::sync_with_stdio(false); cin.tie(NULL);
	int n;
	cin >> n;
	vector<int> v(n, 0);
	int best1 = 0;
	int best2 = 0;

	for (int i = 0; i < n; ++i)
	{
		cin >> v[i];
	}

	best1 = max(v[1] - v[0], v[2] - v[1]);
	best2 = v[2] - v[0];
	for (int i = 3; i < n; ++i)
	{
		best1 = max(best1, v[i] - v[i - 1]);
		best2 = min(best2, v[i] - v[i - 2]);
	}

	cout << max(best1, best2);
	return 0;
}<file_sep># https://codeforces.com/contest/583/problem/A
# https://codeforces.com/contest/583/submission/14410627

n = int(input())
v = [0]*(n+1)
h = [0]*(n+1)
i = 1
while (i<=n*n):
    a,b=map(int,input().split())
    if v[a]==0 and h[b]==0:
        v[a]=h[b]=1
        print(i,sep=' ',end=' ')
    i+=1
<file_sep>// https://codeforces.com/gym/101191/problem/F
// https://codeforces.com/gym/101191/submission/47884686

#include <iostream>
#include <string>
using namespace std;

inline unsigned int DoSum(long long Number)
{
	unsigned int sum = 0;

	for (; Number != 0; Number /= 10)
	{
		sum += (Number % 10);
	}

	return sum;
}

long long Solve(std::string& original)
{
	std::string str = "";
	long long target = std::stoll(original);
	unsigned int sum = DoSum(target);
	unsigned int no9 = sum / 9;
	unsigned int rem = sum % 9;

	str.push_back(rem + '0');

	for (unsigned int i = 1; i <= no9; ++i) str.push_back('9');

	if (std::stoll(str) != target && std::stoll(str) <= 1e9)
	{
		return std::stoll(str);
	}

	while (str.size() < 3) str.push_back('0');
	
	swap(str[0], str[1]);
	if (std::stoll(str) != target && std::stoll(str) <= 1e9)
	{
		return std::stoll(str);
	}
	swap(str[0], str[1]);
	
	str.insert(str.begin() + 1, '0');
	if (std::stoll(str) != target && std::stoll(str) <= 1e9)
	{
		return std::stoll(str);
	}

	str.erase(str.begin() + 1);
	str.insert(str.begin() + 2, '0');

	if (std::stoll(str) != target && std::stoll(str) <= 1e9)
	{
		return std::stoll(str);
	}

	return -1;
}


int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);

	string init;

	cin >> init;
	cout << Solve(init);

	return 0;
}<file_sep># https://codeforces.com/contest/479/problem/A
# https://codeforces.com/contest/479/submission/13613997

a = int(input())
b = int(input())
c = int(input())


if a==1:
    b=b+1
if b==1:
    if a<c:
        a=a+1
    else:
        c=c+1
if c==1:
    b=b+1
print(a*b*c)
<file_sep>// https://codeforces.com/contest/727/problem/A
// https://codeforces.com/contest/727/submission/21693330

#include <iostream>
using namespace std;

bool sols = false;
long long sol[100];

long long a, b;

void printSol(int k)
{
   cout << "YES\n" << k + 1 << "\n";
   cout << a << " ";
   for (int i = 0; i < k; ++i) cout << sol[i] << " ";
}

void rec(long long a, long long b, int k)
{
   if (a < b)
   {
      for (int i = 0; i < 2; i++)
      {
         if (i == 0) sol[k] = 2 * a;
         else sol[k] = 10 * a + 1;
         if (!sols)
            rec(sol[k], b, k + 1);
      }
      sol[k] = 0;
   }
   else if (a == b)
   {
      sols = true;
      printSol(k);
   }
}

int main()
{
   cin >> a >> b;
   rec(a, b, 0);
   if (!sols) puts("NO\n");

   return 0;
}<file_sep>// https://codeforces.com/contest/546/problem/B
// https://codeforces.com/contest/546/submission/17523253

#include <iostream>
#include <algorithm>
using namespace std;

int main() {

	int n, s = 0, v[3002], x;
	memset(v, 0, 3002 * sizeof(int));
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		v[x]++;
	}
	for (int i = 1; i <= n; i++) {
		if (v[i] > 1) s += v[i] - 1, v[i + 1] += v[i] - 1;
	}
	s += v[n+1] * (v[n+1] - 1) / 2;
	cout << s;
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/460/problem/A
// https://codeforces.com/contest/460/submission/13875673

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,m,nr;
    scanf("%d",&n);
    scanf("%d",&m);
    nr = 0;
    while (n>0)
    {
        nr++;
        if (nr % m != 0){n--;}
    }
    printf("%d",nr);
    return 0;
}
<file_sep>// https://codeforces.com/contest/766/problem/D
// https://codeforces.com/contest/766/submission/47708811

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;

int find(int x, vector<int>& parent)
{
    if (x == parent[x]) return x;
    return parent[x] = find(parent[x], parent);
}

void uni(int x, int y, vector<int>& parent)
{
    parent[min(x, y)] = max(x, y);
}

bool make_sin(int x, int y, vector<int>& sinonime, vector<int>& antonime)
{
    auto sinX = find(x, sinonime); auto antX = find(antonime[sinX], sinonime);
    auto sinY = find(y, sinonime); auto antY = find(antonime[sinY], sinonime);

    if (sinX == antY || sinY == antX) return false;
    
    uni(sinX, sinY, sinonime);
    if (antX != 0 && antY != 0) uni(antX, antY, sinonime);

    antonime[max(sinX, sinY)] = max(antX, antY);

    return true;
}

bool make_ant(int x, int y, vector<int>& sinonime, vector<int>& antonime)
{
    auto sinX = find(x, sinonime); auto antX = find(antonime[sinX], sinonime);
    auto sinY = find(y, sinonime); auto antY = find(antonime[sinY], sinonime);

    if (sinX == sinY || (antX == antY && antX != 0)) return false;

    if (antY != 0) sinonime[antY] = sinX;  
    if (antX != 0) sinonime[antX] = sinY;
    
    antonime[sinX] = sinY;
    antonime[sinY] = sinX;

    return true;
}

bool make_rel(int r, int x, int y, vector<int>& sinonime, vector<int>& antonime)
{
    return (r == 1) ? make_sin(x, y, sinonime, antonime) : make_ant(x, y, sinonime, antonime);
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, m, q, r;
    string x, y;

    cin >> n >> m >> q;

    map<string, int> hash;
    vector<int> sinonime(n + 1, 0);
    vector<int> antonime(n + 1, 0);

    for (int i = 1; i <= n; ++i)
    {
        sinonime[i] = i;

        cin >> x;
        hash[x] = i;
    }

    for (int i = 1; i <= m; ++i)
    {
        cin >> r >> x >> y;
        (make_rel(r, hash[x], hash[y], sinonime, antonime)) ? cout << "YES\n" : cout << "NO\n";
    }

    for (int i = 1; i <= q; ++i)
    {
        cin >> x >> y;
        auto px = hash[x];      
        auto py = hash[y]; 
        auto ay = antonime[find(py, sinonime)];

        if (find(px, sinonime) == find(py, sinonime)) cout << "1\n";
        else if (find(px, sinonime) == find(ay, sinonime)) cout << "2\n";
        else cout << "3\n";
    }


    return 0;
}
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
using namespace std;

int find(int x, vector<int>& parent)
{
    if (x == parent[x]) return x;
    return parent[x] = find(parent[x], parent);
}

bool make_sin(int x, int y, vector<int>& sinonime, vector<int>& antonime)
{
    auto sinX = find(x, sinonime); auto antX = find(antonime[sinX], sinonime);
    auto sinY = find(y, sinonime); auto antY = find(antonime[sinY], sinonime);

    if (sinX == antY || sinY == antX) return false;
 
    sinonime[sinY] = sinX;
    antonime[sinX] = max(antX, antY);
    if (antX != 0 && antY != 0) sinonime[min(antX, antY)] = max(antX, antY);    
    
    return true;
}

bool make_ant(int x, int y, vector<int>& sinonime, vector<int>& antonime)
{
    auto sinX = find(x, sinonime); auto antX = find(antonime[sinX], sinonime);
    auto sinY = find(y, sinonime); auto antY = find(antonime[sinY], sinonime);

    if (sinX == sinY || (antX == antY && antX != 0)) return false;

    if (antY != 0) sinonime[antY] = sinX;  
    if (antX != 0) sinonime[antX] = sinY;
    
    antonime[sinX] = sinY;
    antonime[sinY] = sinX;

    return true;
}

bool make_rel(int r, int x, int y, vector<int>& sinonime, vector<int>& antonime)
{
    return (r == 1) ? make_sin(x, y, sinonime, antonime) : make_ant(x, y, sinonime, antonime);
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, m, q, r;
    string x, y;

    cin >> n >> m >> q;

    map<string, int> hash;
    vector<int> sinonime(n + 1, 0);
    vector<int> antonime(n + 1, 0);

    for (int i = 1; i <= n; ++i)
    {
        sinonime[i] = i;

        cin >> x;
        hash[x] = i;
    }

    for (int i = 1; i <= m; ++i)
    {
        cin >> r >> x >> y;
        (make_rel(r, hash[x], hash[y], sinonime, antonime)) ? cout << "YES\n" : cout << "NO\n";
    }

    for (int i = 1; i <= q; ++i)
    {
        cin >> x >> y;
        auto px = hash[x];      
        auto py = hash[y]; 
        auto ay = antonime[find(py, sinonime)];

        if (find(px, sinonime) == find(py, sinonime)) cout << "1\n";
        else if (find(px, sinonime) == find(ay, sinonime)) cout << "2\n";
        else cout << "3\n";
    }


    return 0;
}<file_sep>// https://codeforces.com/contest/447/problem/B
// https://codeforces.com/contest/447/submission/18017766

#include <iostream>
#include <string>
using namespace std;


int main() {

	string s;
	long long k, max = 0, sum = 0, v[26];

	cin >> s >> k;

	for (size_t i = 0; i < 26; i++) {
		cin >> v[i];
		if (v[i] > max) max = v[i];
	}

	for (size_t i = 0; i < s.size(); i++) {
		sum += (v[s[i] - 'a']) * (i + 1);
	}
	for (size_t i = s.size() + 1; i <= s.size() + k; i++) {
		sum += max*i;
	}
	cout << sum;

	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/439/problem/A
# https://codeforces.com/contest/439/submission/14449216

n, d = map(int,input().split())
l = list(map(int,input().split()))
s = sum(l)
if s+(n-1)*10 > d:
    print(-1)
else:
    d = d-s
    print(d//5)
<file_sep>// https://codeforces.com/contest/1037/problem/D
// https://codeforces.com/contest/1037/submission/48033461


#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
using namespace std;

bool CheckBfs(map<int, set<int>>& graph, vector<int>& bfs)
{
    queue<int> q;
    size_t idx = 1;
    vector<bool> visited(graph.size() + 1, false);
    q.push(1);
    visited[1] = true;

    if (bfs[0] != 1) return false;
    while (idx < bfs.size())
    {
        auto in = q.front(); q.pop();
        set<int> toVisit;
       
        for (auto neighbour : graph[in])
        {
            if (!visited[neighbour]) toVisit.insert(neighbour);
        }

        for (size_t i = 0; i < toVisit.size(); ++i)
        {
            if (idx == bfs.size()) return false;
            if (toVisit.find(bfs[idx]) == toVisit.end()) return false;
            if (visited[bfs[idx]]) return false;

            q.push(bfs[idx]);
            visited[bfs[idx]] = true;
            idx++;
        }
    }

    for (size_t i = 1; i < visited.size(); ++i)
    {
        if (!visited[i]) return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int n, x, y;
    vector<int> bfs;
    map<int, set<int>> graph;

    cin >> n;

    for (int i = 1; i < n; ++i)
    {
        cin >> x >> y;
        graph[x].insert(y);
        graph[y].insert(x);
    }

    for (int i = 1; i <= n; ++i)
    {
        cin >> x;
        bfs.push_back(x);
    }

    CheckBfs(graph, bfs) ? cout << "Yes\n" : cout << "No\n";

    return 0;
}<file_sep>// https://codeforces.com/contest/777/problem/B
// https://codeforces.com/contest/777/submission/24969556

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;


int main()
{
   ios::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr);
   
   int n;
   string a, b;
   cin >> n >> a >> b;
   int fS[10] = { 0 };
   int fM[10] = { 0 };
   int fMax[10] = { 0 };

   for (auto c : a) fS[c - '0']++, fM[c-'0']++;
   for (auto c : b) fM[c - '0']--, fMax[c - '0']++;

   auto res = 0;
   auto flicks = 0;
   for(auto i = 9; i >= 0; --i)
   {
      if (fM[i] < 0) res += (-1 * fM[i]);
      else
      {
         if (res >= fM[i]) res -= fM[i];
         else
         {
            fM[i] -= res;
            res = 0;
            flicks += fM[i];
         }
      }
   }

   cout << flicks << "\n";

   res = fMax[9];
   flicks = 0;

   for(auto i = 8; i>= 0; --i)
   {
      if (res >= fS[i])
      {
         flicks += fS[i];
         res -= fS[i];
      }
      else
      {
         flicks += res;
         res = 0;
      }
      res += fMax[i];
   }

   cout << flicks;
   return 0;
}<file_sep># https://codeforces.com/contest/110/problem/A
# https://codeforces.com/contest/110/submission/13477477

def is_lucky(a):
    
    """
     Check if a given number (a) is lucky.
     @input: an integer a (1<=a<=10^18)
     @output: True - if a is lucky
              False - if a is not lucky
    """
    if a==0:
        ok=False
    else:
        ok=True
       # We assume that a is lucky
    
    while (a>0 and ok==True):
        if (int(a%10) == 4 or int(a%10) == 7):
            a=a//10
        else:
            ok=False
    return ok
def nearly_lucky(n):

    """
     Check if a given number (n) is nearly lucky.
     @input: an integer n (1<=n<=10^18)
     @output: True - if n is nearly lucky
              False - if n is not nearly lucky
    """

    ok=False
    nr=0
    while n>0:
        if is_lucky(n%10)==True:
            nr+=1
        n=n//10
    if is_lucky(nr)==True:
        ok=True
    return(ok)

def citire():

    """
     Read an integer.
     @output: an integer n (1<=n<=10^18)
    """

    return int(input())

n=citire() #read n
if (nearly_lucky(n)==True):
    print("YES")
else:
    print("NO")
<file_sep>// https://codeforces.com/contest/651/problem/A
// https://codeforces.com/contest/651/submission/17366362

#include <iostream>



int main() {
	int cont, a, b;
	std::cin >> a >> b;
	if (a == b && b == 1) a = 0;
	for (cont = 0; a != 0 && b != 0; cont++) {
		if (a > b) a -= 2, b++;
		else a++, b -= 2;
	}
	std::cout << cont;

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/463/problem/B
// https://codeforces.com/contest/463/submission/17433406

#include <iostream>
using namespace std;


int main() {

	int n, x, sum = 0, h = 0, e = 0;
	cin >> n;
	for (; n > 0; n--) {
		cin >> x;
		e += h - x;
		if (e < 0) { sum += -e, e = 0; }
		h = x;
	}
	cout << sum;
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/552/problem/B
// https://codeforces.com/contest/552/submission/16639895

#include <iostream> 
using namespace std;



int main() {

	unsigned long long v[12], pow10[12], n, nein = 9, i ;
	cin >> n;
	v[0] = 0;
	pow10[0] = 1;
	for (i = 1; i <= 11; i++) {
		v[i] = i * nein + v[i - 1];
		nein *= 10;
		pow10[i] = 10 * pow10[i - 1];
	}
	for (i = 1; pow10[i] <= n; i++);
	cout << v[i - 1] + (n - pow10[i-1] + 1) * i;
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/problemset/problem/987/A
// https://codeforces.com/contest/987/submission/68116433

#include <vector>
#include <string>
#include <map>
#include <iostream>
using namespace std;


int main()
{
    int n;
    string s;

    map<string, string> needed = 
    {
        {"purple", "Power"},
        {"green",  "Time"},
        {"blue",   "Space"},
        {"orange", "Soul"},
        {"red",    "Reality"},
        {"yellow", "Mind"}
    };

    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> s;
        needed.erase(s);
    }
 
    cout << needed.size() << std::endl;
    for (const auto& keyValuePair : needed)
    {
        cout << keyValuePair.second << std::endl;
    }

    return 0;
}<file_sep># https://codeforces.com/contest/785/problem/C
# https://codeforces.com/contest/785/submission/25529811

n,m = map(int,input().split())

def binSearch(n,m):
    lo = 1
    hi = n
    p = -1
    S = 0
    while(lo <= hi):
        k = (lo + hi) // 2
        S = ((k-1)* (k+2)) // 2
        S += m + 1
        if (n - S > 0):
            lo = k + 1
        else:
            p = k
            hi = k - 1
    return p

if (m>=n):
    print(n)
else:
    print(m + binSearch(n,m))<file_sep>// https://codeforces.com/contest/465/problem/B
// https://codeforces.com/contest/465/submission/18017411

#include <iostream>
using namespace std;

int main() {

	int n, x = 0, t = 0, i = 0;
	bool ok1 = false, ok2 = false;
	cin >> n;
	while (i < n && x == 0) cin >> x, i++;
	if (x == 1) t++;
	while (i < n) {
		cin >> x;
		i++;
		if (x == 1) {
			t++;
			if (ok1 == true) t++;
			ok1 = false; ok2 = false;
		}
		else if (x == 0 && ok1 == false) ok1 = true;
		else if (x == 0 && ok1 == true && ok2 == false) ok2 = true;
	}
	cout << t;

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/466/problem/C
// https://codeforces.com/contest/466/submission/47156701

#include <iostream>
#include <vector>
using namespace std;


int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    int n = 0;
    long long s = 0, s_23 = 0, s_13 = 0;
    unsigned long long n1 = 0, n2 = 0, nr = 0;

    cin >> n;
    vector<long long> v(n + 1, 0);
    for (int i = 1; i <= n; ++i)
    {
        cin >> v[i];
        v[i] += v[i - 1];
    }

    s = v[n]; 
    s_13 = v[n] / 3; 
    s_23 = 2 * s_13;
    
    if (s % 3 != 0)
    {
        cout << 0;
        return 0;
    }

    for (int i = 1; i < n; ++i)
    {
        if (v[i] == s_23)
        {
            n2++;
            nr = nr + n1;
        }
        if (v[i] == s_13)
        {
            n1++;
        }
    }

    cout << nr;

    return 0;
}<file_sep># https://codeforces.com/contest/236/problem/A
# https://codeforces.com/contest/236/submission/13420128

dict={'a':0, 'b':0, 'c':0, 'd':0, 'e':0, 'f':0, 'g':0, 'h':0, 'i':0, 'j':0, 'k':0, 'l':0, 'm':0, 'n':0, 'o':0, 'p':0, 'q':0, 'r':0, 's':0, 't':0, 'u':0, 'v':0 , 'w':0, 'x':0, 'y':0, 'z':0}
s=input()
nr=0
for i in range(len(s)):
    dict[s[i]]+=1
    if dict[s[i]]==1:
        nr+=1
if (int(nr%2)==0):
    print("CHAT WITH HER!")
else:
    print("IGNORE HIM!")
<file_sep>// https://codeforces.com/contest/988/problem/A
// https://codeforces.com/contest/988/submission/46797091

#include <iostream>
#include <map>
using namespace std;


int main()
{
	int n, k, x;
	map<int, int> mp;
	cin >> n >> k;

	for (int i = 1; i <= n; ++i)
	{
		cin >> x;
		mp[x] = i;
	}

	if (mp.size() < k) cout << "NO";
	else
	{
		cout << "YES\n";
		for (const auto& p : mp)
		{
			cout << p.second << " ";
			if (--k == 0) break;
		}
	}

	return 0;
}<file_sep>// https://codeforces.com/contest/606/problem/A
// https://codeforces.com/contest/606/submission/17916507

#include <iostream>
using namespace std;


int main() {

	int a[3], v[3], n = 0, s = 0;
	cin >> a[0] >> a[1] >> a[2] >> v[0] >> v[1] >> v[2];
	for (int i = 0; i < 3; i++) {
		if (a[i] > v[i]) s += (a[i] - v[i]) / 2;
		else n += v[i] - a[i];
	}
	(s >= n) ? puts("Yes") : puts("No");
	

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/38/problem/A
// https://codeforces.com/contest/38/submission/17147878

#include <iostream>
using namespace std;


int main(){

	int v[101], x, n;

	cin >> n;
	v[1] = 0;
	for (int i = 2; i <= n; i++) {
		cin >> x;
		v[i] = v[i - 1] + x;
	}

	cin >> x >> n;
	cout << v[n] - v[x];

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/678/problem/B
// https://codeforces.com/contest/678/submission/21700809

#include <iostream>
using namespace std;

bool is_leap(int x)
{
   return (x % 400 == 0 || (x % 4 == 0 && x % 100 != 0));
}

int main()
{

   int x;
   bool leap;
   bool sol = false;
   bool leapY;

   cin >> x;
   leap = is_leap(x);
   
   int day = 0;

   while (!sol)
   {
      x++;
      leapY = is_leap(x);
      (leapY) ? day += 2 : day += 1;
      day %= 7;

      if (day == 0)
      {
         if (leapY == leap) sol = true;
      }
   }

   cout << x;

   return 0;
}<file_sep>// https://codeforces.com/contest/723/problem/B
// https://codeforces.com/contest/723/submission/21321513

#include <stdio.h>
#include <stdlib.h>


int main()
{

   int n;
   char str[255];

   scanf("%d", &n);
   scanf("%s", &str);

   int out = 1;
   int i = -1;
   int wordLen = 0, wordIn = 0, maxLenOut = 0;
   while (++i < n)
   {
      if (str[i] == '(')
      {
         if (wordLen > maxLenOut)
         {
            maxLenOut = wordLen;
         }
         out = 0;
         wordLen = 0;
     }
      else if (str[i] == ')')
      {
         if (wordLen > 0)
         {
            wordIn++;
         }
         out = 1;
         wordLen = 0;
      }
      else if (str[i] == '_')
      {
         if (out == 1)
         {
            if (wordLen > maxLenOut)
            {
               maxLenOut = wordLen;
            }
         }
         else if (wordLen > 0)
         {
            wordIn++;
         }
         wordLen = 0;
      }
      else
      {
         wordLen++;
      }
   }

   if (wordLen > maxLenOut)
   {
      maxLenOut = wordLen;
   }

   printf("%d %d", maxLenOut, wordIn);

   return 0;
}<file_sep># https://codeforces.com/contest/148/problem/A
# https://codeforces.com/contest/148/submission/13473365

a=[]
for i in range(4):
    x=int(input())
    a.append(x)
n=int(input())
v=[]
for i in range(n+1):
    v.append(0)
for i in range(4):
    aux=a[i]
    while a[i]<n+1:
        v[a[i]]=1
        a[i]+=aux
nr=0
for i in range(1,n+1):
    if v[i]==1:
        nr+=1
print(nr)
<file_sep>// https://codeforces.com/contest/381/problem/A
// https://codeforces.com/contest/381/submission/17434256

#include <iostream>
using namespace std;


int main()
{
	int v[1001], n, Sereja = 0, Dima = 0;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> v[i];
	for (int c = 0, j = n - 1, i = 0; i <= j;) {
		if (c == 0) {
			if (v[i] > v[j]) Sereja += v[i], i++;
			else Sereja += v[j], j--;
			c = 1;
		}
		else {
			if (v[i] > v[j]) Dima += v[i], i++;
			else Dima += v[j], j--;
			c = 0;
		}
	}
	cout << Sereja << " " << Dima << endl;
	return EXIT_SUCCESS;
}

<file_sep>// https://codeforces.com/contest/678/problem/C
// https://codeforces.com/contest/678/submission/18421949

#include <iostream>
#include <algorithm>
using namespace std;


long long gcd(const long long& a, const long long& b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

int main() {

	long long n, a, b, p, q, lcm, nra, nrb, nrc;
	cin >> n>> a >> b >> p >> q;

	lcm = (a*b) / gcd(a, b);
	nrc = n / lcm;
	nra = n / a - nrc;
	nrb = n / b - nrc;

	cout << nrc * max(p, q) + nra * p + nrb * q;
	return 0;
}<file_sep># https://codeforces.com/contest/214/problem/A
# https://codeforces.com/contest/214/submission/14926990

n,m = map(int,input().split())
nr = 0
for i in range(1001):
    for j in range(1001):
        if i*i + j == n and i + j*j == m:
            nr += 1
print(nr)
<file_sep>// https://codeforces.com/contest/746/problem/C
// https://codeforces.com/contest/746/submission/23095903

#include <iostream>
#include <algorithm>
using namespace std;


int main()
{
   int Sursa, igorPos, igorDest, vitezaIgor, vitezaTren, trenPos, directieTren, directieIgor;
   cin >> Sursa >> igorPos >> igorDest >> vitezaTren >> vitezaIgor >> trenPos >> directieTren;

   if (igorPos > igorDest) directieIgor = -1;
   else directieIgor = 1;

   int igorTime = abs(igorPos - igorDest) * vitezaIgor;
   int trainTime = 0;

   if (directieTren == 1 && directieIgor == -1)
   {
      trainTime += abs(trenPos - Sursa) * vitezaTren;
      trainTime += abs(Sursa - igorDest) * vitezaTren;
   }
   else if (directieTren == -1 && directieIgor == 1)
   {
      trainTime += trenPos * vitezaTren;
      trainTime += igorDest * vitezaTren;
   }
   else if (directieTren == 1 && directieIgor == 1 && igorPos < trenPos)
   {
      trainTime += abs(trenPos - Sursa) * vitezaTren;
      trainTime += Sursa * vitezaTren;
      trainTime += igorDest * vitezaTren;
   }
   else if (directieTren == -1 && directieIgor == -1 && igorPos > trenPos)
   {
      trainTime += trenPos * vitezaTren;
      trainTime += Sursa * vitezaTren;
      trainTime += abs(Sursa - igorDest) * vitezaTren;
   }
   else
   {
      trainTime += abs(trenPos - igorDest) * vitezaTren;
   }

   cout << min(trainTime, igorTime);

   return 0;
}<file_sep>// https://codeforces.com/contest/676/problem/A
// https://codeforces.com/contest/676/submission/18780987

#ifndef _CRT_NONSTDC_NO_WARNINGS
#define _CRT_NONSTDC_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;


int main() {

	int n, poz1, pozn, i, x;
	for (scanf("%d", &n), i = 1; i <= n; ++i) {
		scanf("%d", &x);
		if (x == 1) poz1 = i;
		else if (x == n) pozn = i;
	}
	printf("%d", max(max(abs(1 - poz1), abs(n - poz1)), max(abs(1 - pozn), abs(n - pozn))));

	return EXIT_SUCCESS;
}

#endif //_CRT_NONSTDC_NO_WARNINGS<file_sep>// https://codeforces.com/contest/735/problem/B
// https://codeforces.com/contest/735/submission/22540632

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
using namespace std;

bool cmp(int a, int b)
{
   return b < a;
}

int main()
{
   int n, m, k;
   double s1a, s1b, s2a, s2b;
   scanf("%d %d %d", &n, &m, &k);
   vector<int> v(n, 0);

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

   s1a = s1b = s2a = s2b = 0;
   sort(v.begin(), v.end(), cmp);

   for (int i = 0; i < m; ++i) s1a += v[i];
   for (int i = m, q = k; q > 0; q--, i++) s1b += v[i];

   for (int i = 0; i < k; ++i) s2a += v[i];
   for (int i = k, q = m; q > 0; q--, i++) s2b += v[i];

   double s1 = s1a / m + s1b / k;
   double s2 = s2a / k + s2b / m;

   printf("%.7lf",max(s1, s2));


   return 0;
}<file_sep>// https://codeforces.com/contest/1281/problem/A
// https://codeforces.com/contest/1281/submission/67973469

#include <iostream>
#include <string>
using namespace std;


int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);

    int queries = 0;
    string s;

    cin >> queries;

    while (queries--)
    {
        cin >> s;

        switch (s.back())
        {
        case 'o':
            cout << "FILIPINO\n"; break;
        case 'a':
            cout << "KOREAN\n"; break;
        default:
            cout << "JAPANESE\n"; break;
        }
    }

    return 0;
}<file_sep>// https://codeforces.com/contest/743/problem/C
// https://codeforces.com/contest/743/submission/22980441

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <iostream>
using namespace std;


int main()
{
   int n;
   scanf("%d", &n);
   if (n == 1) puts("-1");
   else printf("%d %d %d", n, n + 1, n*(n + 1));

   return 0;
}
<file_sep># https://codeforces.com/contest/466/problem/A
# https://codeforces.com/contest/466/submission/14009138

n,m,a,b=map(int,input().split())
if m>n:
    m=n
if m%n==0:
    rez=0
else:
    rez=1
var1=a*n
impr=int(n/m)
var2=((impr+rez)*b)
pcs=(n-(impr*m))
var3=(impr*b+(pcs*a))
print(min(var1,var2,var3))
    
<file_sep>// https://codeforces.com/contest/681/problem/C
// https://codeforces.com/contest/681/submission/18480382

#include <iostream>
#include <stdio.h>
#include <string>
#include <functional>
#include <queue>
using namespace std;


int main() {
	string s;
	vector<pair<string, int>> rez;
	priority_queue<int, vector<int>, greater<int>> head;
	int n, value;
	for (cin >> n; n > 0; n--) {
		cin >> s;
		if (s == "removeMin") {
			if (head.empty()) {
				rez.push_back({ "insert ", 1 });
				rez.push_back({ "removeMin ", 0 });
			}
			else {
				head.pop();
				rez.push_back({ "removeMin ", 0 });
			}
		}
		else if (s == "insert") {
			cin >> value;
			head.push(value);
			rez.push_back({ "insert ", value });
		}
		else {
			cin >> value;
			if (head.empty()) {
				rez.push_back({ "insert ", value });
				head.push(value);
				rez.push_back({ "getMin ", value });
			}
			else {
				while ( !head.empty() && head.top() < value) {
					rez.push_back({ "removeMin ", 0 });
					head.pop();
				}
				if (head.empty() || head.top() > value) {
					rez.push_back({ "insert ", value });
					head.push(value);
				}
				rez.push_back({ "getMin ", value });
			}
		}
	}
	cout << rez.size() << "\n";
	for (const auto& el : rez) {
		cout << el.first;
		if (el.first != "removeMin ") cout << el.second;
		cout << '\n';
	}


	return EXIT_SUCCESS;
}<file_sep>// https://www.spoj.com/problems/FCTRL/

#include <iostream>
#include <fstream>
#include <chrono>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>
using namespace std;

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);

    int T = 0;
    unsigned long long N = 0;
    unsigned long long Result = 0;
    
    cin >> T;
    while (T--)
    {
        cin >> N;

        Result = 0;
        for (unsigned long long S = 5; S <= N; S *= 5)
        {
            Result += (N / S);
        }

        cout << Result << "\n";
    }


    return 0;
}<file_sep># https://codeforces.com/contest/112/problem/A
# https://codeforces.com/contest/112/submission/13407948

s1=input()
s2=input()
if s1.lower()==s2.lower():
    print("0")
elif s1.lower()<s2.lower():
    print("-1")
else:
    print("1")
<file_sep># https://codeforces.com/contest/546/problem/A
# https://codeforces.com/contest/546/submission/13588873

n,m,k=map(int,input().split())
if ((((n+(n*k))*k)//2)-m > 0):
    print((((n+(n*k))*k)//2)-m)
else:
    print(0)


<file_sep>// https://codeforces.com/contest/545/problem/A
// https://codeforces.com/contest/545/submission/17418609

#include <iostream>
using namespace std;


int main() {
	int n, v[101], k = 0, x;
	bool ok;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		ok = true;
		for (int j = 1; j <= n; j++) {
			cin >> x;
			if (x == 1 || x==3) ok = false;
		}
		if (ok) {k++; v[k] = i;}
	}
	cout << k << endl;
	for (int i = 1; i <= k; i++)cout << v[i] << " ";

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/520/problem/A
// https://codeforces.com/contest/520/submission/13876957

#include <stdio.h>
#include <stdlib.h>

int main()
{
   int v[30],n,i,cord;
   char c;
   scanf("%d\n",&n);
   for (i=1;i<=n;i++)
   {
       scanf("%c",&c);
       cord = c;
       if (cord<97)
       {
           v[cord-65]=1;
       }
       else
       {
           v[cord-97]=1;
       }
   }
   cord = 1;
   for (i=0;i<=25;i++)
   {
       if (v[i]!=1)
       {
           cord = -1;
       }
   }
   if (cord == -1 ){printf("NO");}
   else {printf("YES");}
   return 0;
}
<file_sep>// https://codeforces.com/contest/746/problem/A
// https://codeforces.com/contest/746/submission/23082946

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;


int main()
{
   int a, b, c, ans;
   scanf("%d %d %d", &a, &b, &c);
   b = b / 2;
   c = c / 4;
   ans = min(a, min(b, c));
   printf("%d", ans + ans*2 + ans*4);

   return 0;
}<file_sep># https://codeforces.com/contest/228/problem/A
# https://codeforces.com/contest/228/submission/13960789

l = list(map(int,input().split()))
a = set(l)
print(4-len(a))
<file_sep>// https://codeforces.com/contest/791/problem/A
// https://codeforces.com/contest/791/submission/25610192

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long 
#define ull unsigned long long

/*------------------------------------------------------------------*/


int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
   int a, b;
   ll  k = 1, ans = 0, pw2 = 1, pw3 = 1;
   cin >> a >> b;
   while (!ans)
   {
      pw2 *= 2;
      pw3 *= 3;
      if (a * pw3 <= b * pw2) k++;
      else ans = k;
   }
   cout << ans;
   

   return 0;
}<file_sep>// https://codeforces.com/contest/706/problem/B
// https://codeforces.com/contest/706/submission/46624969

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int Find(const vector<int>& V, int X)
{
	int lo = 0;
	int hi = V.size() - 1;
	int m = 0;
	int found = -1;

	while (lo <= hi)
	{
		m = (lo + hi) / 2;
		if (V[m] > X) hi = m - 1;
		else found = m, lo = m + 1;
	}
	
	return found;
}

int main()
{
	int n, d, x;
	
	cin >> n;
	vector<int> v(n, 0);
	for (int i = 0; i < n; ++i) cin >> v[i];

	sort(v.begin(), v.end());

	cin >> d;
	while (d--)
	{
		cin >> x;
		cout << Find(v, x) + 1 << "\n";
	}

	return 0;
}<file_sep># https://codeforces.com/contest/467/problem/B
# https://codeforces.com/contest/467/submission/14468665

n,m,k = map(int,input().split())
l = []
while (m+1>0):
    x = int(input())
    l.append(x)
    m-=1
nr = 0
for i in range (len(l)-1):
    c = l[i]^l[len(l)-1]
    if bin(c).count("1")<=k:
            nr+=1
print(nr)
<file_sep>#include <iostream>
#include <string>
#include <vector>
using namespace std;


int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    
    string on;
    bool ok = false;
    vector<string> hand(5);

    cin >> on;
    for (size_t i = 0; i < hand.size(); ++i) cin >> hand[i];

    for (const auto& h : hand)
    {
        ok = ok || h[0] == on[0] || h[1] == on[1];
    }

    (ok) ? cout << "YES\n" : cout << "NO\n";

    return 0;
}
<file_sep># https://codeforces.com/contest/588/problem/A
# https://codeforces.com/contest/588/submission/14543201

n = int(input())
a, kilo =map(int,input().split())
s = kilo*a
while n-1>0:
    a,b = map(int,input().split())
    if b<kilo:
        kilo = b
    s += kilo*a
    n -= 1
print(s)
<file_sep>// https://codeforces.com/contest/747/problem/A
// https://codeforces.com/contest/747/submission/23259014

#include <iostream>
#include <algorithm>
using namespace std;


int main()
{

   int n;
   int mxa, mxb, mx;
   cin >> n;
   mxa = 1; 
   mxb = n;
   mx = n - 1;
   for (int i = 2; i < n; ++i)
   {
      if (n % i == 0)
      {
         if (abs(n / i - i) < mx)
         {
            mx = abs(n / i - i);
            mxa = min(n / i, i);
            mxb = max(n / i, i);
         }
      }
   }

   cout << mxa << " " << mxb;

   return 0;
}<file_sep>// https://codeforces.com/contest/1030/problem/A
// https://codeforces.com/contest/1030/submission/46625301


#include <iostream>

using namespace std;

int main()
{
    int n;
    bool res = false, b = false;

    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> b;
        res = res || b;
    }
    
    res ? cout << "hard"
        : cout << "easy";

    return 0;
}<file_sep>// https://codeforces.com/contest/789/problem/C
// https://codeforces.com/contest/789/submission/25930865

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long
#define ull unsigned long long

/*------------------------------------------------------------------*/


int n;
long long v[100004];
vector<long long> pare, impare;

long long sum(vector<long long>& vc)
{
   long long sumMax = 0;
   long long sumCur = 0;
   long long c = 0;

   for(size_t i = 0; i < vc.size(); ++i)
   {
      sumCur += vc[i];
      sumMax = max(sumMax, sumCur);
      sumCur = max(c, sumCur);
   }

   return sumMax;
}

int main()
{
   ios_base::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr);
   cin >> n;
   for (int i = 1; i <= n; ++i) cin >> v[i];

   for(int i = 1; i<=n-1; ++i)
   {
      if (i & 1) impare.push_back(abs(v[i] - v[i + 1]));
      else impare.push_back(-abs(v[i] - v[i + 1]));
   }

   for(int i = 2; i<=n-1; ++i)
   {
      if (i & 1) pare.push_back(-abs(v[i] - v[i + 1]));
      else pare.push_back(abs(v[i] - v[i + 1]));
   } 

   cout << max(sum(pare), sum(impare));

   return 0;
}
<file_sep>// https://codeforces.com/contest/339/problem/D
// https://codeforces.com/contest/339/submission/25572718

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;

#define ll long long 
#define ull unsigned long long 
/*--------------------------------------------------------------------------------------*/

typedef struct node
{
   ll value;
   bool xorField;
   node() { value = 0; xorField = true; }
}node;

const int MAXN = 1 << 18;


node arb[4 * MAXN + 66];
int n, m;

void update(int node, int start, int end, int& pos, ll& val)
{
   if (start == end)
   {
      arb[node].value = val;
      arb[node].xorField = true;
      return;
   }

   int mid = (start + end) / 2;
   if (pos <= mid) update(node * 2, start, mid, pos, val);
   else update(node * 2 + 1, mid + 1, end, pos, val);

   arb[node].xorField = !arb[node * 2].xorField;
   if (arb[node].xorField) arb[node].value = arb[node * 2].value ^ arb[node * 2 + 1].value;
   else arb[node].value = arb[node * 2].value | arb[node * 2 + 1].value;
}


int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);


   scanf("%d", &n);
   scanf("%d", &m);

   ll x;
   n = 1 << n;
   for (int i = 1; i <= n; ++i)
   {
      scanf("%I64d", &x);
      update(1, 1, n, i, x);
   }

   int pos;
   for (int i = 1; i <= m; ++i)
   {
      scanf("%d %I64d", &pos, &x);
      update(1, 1, n, pos, x);
      printf("%I64d\n", arb[1].value);
   }



   return 0;
}
<file_sep>// https://codeforces.com/contest/766/problem/A
// https://codeforces.com/contest/766/submission/28727945

#include <iostream>
#include <string>
using namespace std;



int main() {

      string a, b;
      cin>>a>>b;
      
      if( a == b)
        cout<<"-1";
    else
        cout<<max(a.size(), b.size());

    return 0;
    
}
<file_sep>// https://codeforces.com/contest/777/problem/D
// https://codeforces.com/contest/777/submission/24971940

#include <iostream>
#include <string>
#include <vector>
using namespace std;



int main()
{
   ios::sync_with_stdio(false);
   int n, j, sz1, sz2;
   string curr,s,prec;
   vector<string> v;
   vector<string> sol;

   cin >> n;
   
   for(auto i = 0; i < n; ++i)
   {
      cin >> s;
      v.push_back(s);
   }

   sol.push_back(v[n - 1]);
   for(auto i = n - 2; i>= 0; --i)
   {
      prec = sol.back();
      curr = v[i];
      sz1 = prec.size();
      sz2 = curr.size();
      for (j = 0; j < sz1 && j < sz2 && prec[j] == curr[j]; j++);
      if (j < sz1 && j < sz2 && prec[j] > curr[j]) j = sz2;
      sol.push_back(curr.substr(0, j));
   }

   for (auto i = n - 1; i >= 0; --i)cout << sol[i] << "\n";

   return 0;
}<file_sep>// https://codeforces.com/problemset/problem/919/B
// https://codeforces.com/contest/919/submission/49355568
#include <iostream>
#include <fstream>
#include <chrono>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>
using namespace std;

vector<long long> Compute()
{
    long long current = 19;
    vector<long long> result;

    while (result.size() < 10000)
    {
        int sum = 0;
        for (auto c = current; c > 0; c = c / 10) sum += (c % 10);

        if (sum == 10) result.push_back(current);
        current++;
    }

    return result;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);

    auto all = Compute();

    int k;
    cin >> k;

    cout << all[k - 1];

    return 0;
}<file_sep>// https://codeforces.com/contest/592/problem/A
// https://codeforces.com/contest/592/submission/13993887

#include <iostream>
using namespace std;

char s[10][10];
int minb=9,minw=9,p;

int calc_min(int el, int i, int j)
{
    int m=9;
    if (el=='B')
    {
        for(int k=i+1;k<=8;k++)
        {
            if (s[k][j]!='.'){return m;}
        }
        return 8-i;
    }
    else
    {
        for(int k=i-1;k>=1;k--)
        {
            if (s[k][j]!='.'){return m;}
        }
        return i-1;
    }
}

int main()
{
    for (int i=1;i<=8;i++)
    {
        for (int j=1;j<=8;j++)
        {
            cin>>s[i][j];
        }
    }
    for (int i=1;i<=8;i++)
    {
        for (int j=1;j<=8;j++)
        {
            if (s[i][j]!='.'){p=calc_min(s[i][j],i,j);}
            if ((s[i][j]=='B')&&(p<minb))
            {
                minb=p;
            }
            if ((s[i][j]=='W')&&(p<minw))
            {
                minw=p;
            }
        }
    }
    if (minb<minw){cout<<'B';}
    else{cout<<'A';}
    return 0;
}
<file_sep># https://codeforces.com/contest/451/problem/A
# https://codeforces.com/contest/451/submission/13960967

n,m=map(int,input().split())
if (n==1) or (m==1):
    rez=1;
else:
    if (n>m):
        diff=m
    else:
        diff=n
    if diff%2==0:
        rez=0
    else:
        rez=1
if rez==0:
    print("Malvika")
else:
    print("Akshat")
<file_sep>// https://codeforces.com/contest/604/problem/A
// https://codeforces.com/contest/604/submission/17336525

#include <iostream>
#include <algorithm>
using namespace std;


int main() {

	int m1, m2, m3, m4, m5, w1, w2, w3, w4, w5, s, u;
	double sm = 0;
	cin >> m1 >> m2 >> m3 >> m4 >> m5 >> w1 >> w2 >> w3 >> w4 >> w5 >> s >> u;
	sm += max(0.3 * 500,  (1 - m1 / 250.0) * 500 - 50.0 * w1)  +
		  max(0.3 * 1000, (1 - m2 / 250.0) * 1000 - 50.0 * w2) +
		  max(0.3 * 1500, (1 - m3 / 250.0) * 1500 - 50.0 * w3) +
		  max(0.3 * 2000, (1 - m4 / 250.0) * 2000 - 50.0 * w4) +
		  max(0.3 * 2500, (1 - m5 / 250.0) * 2500 - 50.0 * w5) +
		  s * 100 - u * 50;
	cout << int(sm);
}  <file_sep># https://codeforces.com/contest/469/problem/A
# https://codeforces.com/contest/469/submission/13960730

n=int(input())
l=list(map(int,input().split()))
l1=list(map(int,input().split()))
lc=[]
for _ in range(0,n+1):
    lc.append(0)
for i in range(1,len(l)):
    lc[l[i]]=1
for i in range (1,len(l1)):
    lc[l1[i]]=1
ok = 0
for i in range(1,n+1):
    if lc[i]!=1:
        print('Oh, my keyboard!')
        ok = 1;
        break
if ok == 0:
    print('I become the guy.')
        
<file_sep># https://codeforces.com/contest/459/problem/A
# https://codeforces.com/contest/459/submission/14411162

x1,y1,x2,y2 = map(int,input().split())
if x1 == x2:
    l = abs(y2-y1)
    if x1+l>1000:
        l=-l
    x3 = x4 = x1+l
    print(x3,y1,x4,y2)
elif y1==y2:
    l = abs(x2-x1)
    if y1+l>1000:
        l = -l
    y3 = y4 = y1+l
    print(x1,y3,x2,y4)
else:
    if abs(y2-y1)!=abs(x2-x1):
        print(-1)
    else:
        print(x1,y2,x2,y1)
<file_sep>// https://codeforces.com/contest/732/problem/A
// https://codeforces.com/contest/732/submission/21642425

#include <stdio.h>
#include <stdlib.h>


int main()
{
   int k, r, rz;
   scanf("%d %d", &k, &r);

   for (int i = 1; i <= 10; ++i)
   {
      rz = i * k;
      if (rz % 10 == 0 || (rz - r) % 10 == 0)
      {
         printf("%d", i);
         break;
      }
   }


   return EXIT_SUCCESS;
}<file_sep>// https://www.spoj.com/problems/BGSHOOT/
#include <vector>
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

class SegmentedTree
{
public:
    SegmentedTree(const vector<int>& Array) : 
        arraySize{Array.size()},
        tree(Array.size() * 4 + 4, 0)
    {
        Build(Array, 1, 0, arraySize - 1);
    }

    int Query(size_t Low, size_t High)
    {
        return Query(1, 0, arraySize - 1, Low, High);
    }

    ~SegmentedTree() = default;

private:

    void Build(const vector<int>& Array, size_t Node, size_t Start, size_t End)
    {
        if (Start == End)
        {
            tree[Node] = Array[Start];
            return;
        }

        int mid = (Start + End) / 2;

        Build(Array, Node * 2, Start, mid);
        Build(Array, Node * 2 + 1, mid + 1, End);

        tree[Node] = max(tree[Node * 2], tree[Node * 2 + 1]);
    }

    int Query(size_t Node, size_t Start, size_t End, size_t Low, size_t High)
    {
        if (Low > End || High < Start)
        {
            return numeric_limits<int>::min();
        }

        if (Start >= Low && End <= High)
        {
            return tree[Node];
        }

        size_t mid = (Start + End) / 2;

        auto left = Query(Node * 2, Start, mid, Low, High);
        auto right = Query(Node * 2 + 1, mid + 1, End, Low, High);

        return max(left, right);
    }

    vector<int> tree;
    size_t arraySize;
};

vector<pair<int, int>> ReadPairs()
{
    int noPairs;

    cin >> noPairs;
    vector<pair<int, int>> pairs(noPairs);

    for (int i = 0; i < noPairs; ++i)
    {
        cin >> pairs[i].first >> pairs[i].second;
    }
    
    return pairs;
}

map<int, int> CoordinateCompression(const vector<pair<int, int>>& Data, const vector<pair<int, int>>& Queries)
{
    set<int> uniques;
    map<int, int> compression;

    for (const auto& d : Data)
    {
        uniques.insert(d.first);
        uniques.insert(d.second);
    }

    for (const auto& q : Queries)
    {
        uniques.insert(q.first);
        uniques.insert(q.second);
    }

    int noElements = 0;
    for (const auto& u : uniques)
    {
        compression[u] = noElements++;
    }

    return compression;
}


int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    auto data = ReadPairs();
    auto queries = ReadPairs();
    auto compressed = CoordinateCompression(data, queries);

    vector<int> arr(compressed.size() + 1, 0);

    for (const auto& d : data)
    {
        arr[compressed[d.first]]++;
        arr[compressed[d.second] + 1]--;
    }

    for (size_t i = 1; i < arr.size(); ++i)
    {
        arr[i] += arr[i - 1];
    }

    SegmentedTree tree(arr);

    for (const auto& q : queries)
    {
        auto x = compressed[q.first];
        auto y = compressed[q.second];

        cout << tree.Query(x, y) << "\n";
    }

    return 0;
}<file_sep># https://codeforces.com/contest/527/problem/A
# https://codeforces.com/contest/527/submission/14458555

a,b = map(int,input().split())
s = 0
while a%b!=0:
    s+= a//b
    a,b = max(a%b,b),min(a%b,b)
s+=a//b
print(s)
<file_sep>// https://codeforces.com/contest/84/problem/A
// https://codeforces.com/contest/84/submission/18009090

#include <iostream>
using namespace std;

int main() {

	int n;
	cin >> n;
	cout << 3 * (n / 2);

	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/118/problem/A
# https://codeforces.com/contest/118/submission/13405524

s=input()
i=0
s2=""
vowellist=['a','e','i','o','u','y']
while (i<len(s)):
    if s[i].lower() not in vowellist:
       s2=s2+"."+s[i]
    i+=1
print(s2.lower())

    
<file_sep>// https://codeforces.com/problemset/problem/1005/A
// https://codeforces.com/contest/1005/submission/48101104

#include <vector>
#include <iostream>
using namespace std;


int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);

    vector<int> res; 
    int n, x, curr = 1;

    cin >> n >> x;
    for (int i = 2; i <= n; ++i)
    {
        cin >> x;
        if (x == 1)
        {
            res.push_back(curr);
            curr = 0;
        }
        ++curr;
    }
    res.push_back(curr);

    cout << res.size() << "\n";
    for (auto& c : res) cout << c << " ";

    return 0;
}<file_sep>// https://codeforces.com/contest/706/problem/A
// https://codeforces.com/contest/706/submission/22852236

#define _CRT_SECURE_NO_WARNINGS


#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <limits>
#include <cmath>
using namespace std;


inline double distance(int ax, int ay, int bx, int by)
{
   return sqrt((ax - bx) * (ax - bx) + (ay - by) * (ay - by));
}


int main()
{
   int vx, vy, n, bx, by, vb;
   double mx = numeric_limits<double>::max();
   double time;

   scanf("%d %d %d", &vx, &vy, &n);
   while (n--)
   {
      scanf("%d %d %d", &bx, &by, &vb);
      time = (distance(vx, vy, bx, by)) / vb;
      if (mx > time) mx = time;
   }

   printf("%.10lf\n", mx);
   return 0;
}<file_sep>// https://codeforces.com/contest/356/problem/A
// https://codeforces.com/contest/356/submission/25574265

#include <iostream>
using namespace std;

const int MAXN = 300009;

int tata[MAXN];
int beatenBy[MAXN];

int n, m;

int find(int x)
{
   if (x == tata[x]) return x;
   return tata[x] = find(tata[x]);
}


int main()
{

   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
   
   cin >> n >> m;
   for(int i = 1; i<=n; ++i)
   {
      beatenBy[i] = 0;
      tata[i] = i;
   }
   tata[n + 1] = n + 1;

   int l, r, winner,sef;

   for(int i = 1; i<=m; ++i)
   {
      cin >> l >> r >> winner;
      sef = find(l);
      while(sef <= r)
      {

         if (sef == winner)
         {
            sef++;
         }
         else {
            beatenBy[sef] = winner;
            tata[sef] = sef + 1;
         }
         sef = find(sef);
      }
   }

   for (int i = 1; i <= n; ++i) cout << beatenBy[i] << " ";

   



   return 0;
}<file_sep>// https://codeforces.com/contest/683/problem/F
// https://codeforces.com/contest/683/submission/18529476

fun main(args: Array<String>) {
    val (q) = readLine()!!.split('\n');
    var a = q.trim();
    a += ' ';
    var len = a.length;
    var i = 0;
    var word = "";
    var cap = 1;
	var st = "";
    
    while (i < len){
        while (i < len && a[i] == ' '){ 
            i++;
        }
        while ( i < len && ((a[i] >= 'a' && a[i] <= 'z' ) || (a[i] >= 'A' && a[i] <= 'Z'))){
            word += a[i];
            i++;
        }
        word = word.toLowerCase();
        if (cap == 1) word = word.capitalize();
        if (word != "") st+= word;
        var char = ' '
        if (i < len) char = a[i];
        while (i < len && a[i] == ' '){ 
            i++;
            if (i < len) char = a[i];
        }
        cap = 0;
        word = "";
        if (char == ','){ st+=", "; i++;};
        else if (char == '.'){
            st+=". ";
            cap = 1;
            i++;
        }else if (i < len && ((a[i] >= 'a' && a[i] <= 'z' ) || (a[i] >= 'A' && a[i] <= 'Z'))){
            st+=' ';

        }
    }
    word = word.toLowerCase();
    if (cap == 1) word = word.capitalize();
    st+=word;
	println(st.trim());

}
<file_sep>// https://codeforces.com/contest/660/problem/A
// https://codeforces.com/contest/660/submission/18716745

#ifndef _CRT_NONSTDC_NO_WARNINGS
#define _CRT_NONSTDC_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
using namespace std;

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

int main() {

	int n, v[1002], i = 0, sz;
	vector<int> fin;

	for (scanf("%d", &n); i < n; scanf("%d", &v[i++]));
	for (i = 0; i < n - 1; i++) {
		fin.push_back(v[i]);
		if (gcd(v[i], v[i + 1]) != 1) fin.push_back(1);
	}
	fin.push_back(v[n - 1]);
	sz = (int)fin.size();

	for (printf("%d\n", sz - n), i = 0; i < sz ; printf("%d ", fin[i++]));

	return EXIT_SUCCESS;
}

#endif //_CRT_NONSTDC_NO_WARNINGS<file_sep>// https://codeforces.com/contest/686/problem/B
// https://codeforces.com/contest/686/submission/18716425

#ifndef _CRT_NONSTDC_NO_WARNINGS
#define _CRT_NONSTDC_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
using namespace std;

void swap(int& a, int&b) {
	auto aux = a;
	a = b;
	b = aux;
}

int main() {

	int n, v[105], i = 0;
	char ok = 0;

	for (scanf("%d", &n); i < n; scanf("%d", &v[i++]));
	while (ok == 0) {
		ok = 1;
		for (int i = 1; i < n; i++) {
			if (v[i] < v[i - 1]) swap(v[i], v[i - 1]), ok = 0, printf("%d %d\n", i, i+1);
		}
	}


	return EXIT_SUCCESS;
}

#endif //_CRT_NONSTDC_NO_WARNINGS<file_sep>// https://codeforces.com/contest/721/problem/B
// https://codeforces.com/contest/721/submission/21808148

#include <iostream>
#include <vector>
#include <string>
using namespace std;


int main()
{
   ios::sync_with_stdio(false);

   vector<int> v(105, 0);
   string s;

   int n, k;
   cin >> n >> k;

   for (;n--;)
   {
      cin >> s;
      v[s.size()]++;
   }
   int sum = 0;
   int pp = 0;
   cin >> s;

   for (size_t i = 0; i < s.size(); ++i)
   {
      sum += v[i];
   }

   pp = (sum / k) * 5;
   cout << sum + pp + 1 << " ";
   sum += v[s.size()] - 1;
   pp = (sum / k) * 5;
   cout << sum + pp + 1;

   return EXIT_SUCCESS;
}

<file_sep># https://codeforces.com/contest/141/problem/A
# https://codeforces.com/contest/141/submission/14008308

s=input()
l=[]
for _ in range(0,27):
    l.append(0)
for i in range (len(s)):
    l[ord(s[i])-64]+=1
del(s)
s=input()
for i in range (len(s)):
    l[ord(s[i])-64]+=1
del(s)
s=input()
for i in range (len(s)):
    l[ord(s[i])-64]-=1
ok='YES'
for i in range (27):
    if l[i]!=0:
        ok='NO'
print(ok)

<file_sep>// https://www.spoj.com/problems/FREQUENT/
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct Node
{
    Node() = default;
    ~Node() = default;

    Node(int Value)
    {
        LeftValue = Value;
        RightValue = Value;
        LeftMaxCounter = 1;
        RightMaxCounter = 1;
        CombinedMaxCounter = 1;
    }

    int LeftValue = 0;
    int RightValue = 0;
    int LeftMaxCounter = 0;
    int RightMaxCounter = 0;
    int CombinedMaxCounter = 0;
};

class SegmentTree
{
public:
    SegmentTree(const vector<int>& Array) :
        Array{ Array },
        Tree( Array.size() * 4 + 4, Node())
    {
        Build(1, 0, Array.size() - 1);
    }

    int Query(size_t Low, size_t High)
    {
        vector<size_t> path;
        Query(1, 0, Array.size() - 1, Low, High, path);

        Node node = Tree[path[0]];
        for (size_t i = 1; i < path.size(); ++i)
        {
            Node n = Tree[path[i]];
            node = Combine(node, n);
        }

        return max(node.CombinedMaxCounter, max(node.LeftMaxCounter, node.RightMaxCounter));
    }

private:
    void Build(size_t Node, size_t Start, size_t End)
    {
        if (Start == End)
        {
            Tree[Node] = ::Node(Array[Start]);
            return;
        }

        size_t mid = (Start + End) / 2;

        Build(Node * 2, Start, mid);
        Build(Node * 2 + 1, mid + 1, End);

        Tree[Node] = Combine(Tree[Node * 2], Tree[Node * 2 + 1]);
    }

    void Query(size_t Node, size_t Start, size_t End, size_t Low, size_t High, vector<size_t>& Path)
    {
        if (Start > High || End < Low)
        {
            return;
        }

        if (Low <= Start && End <= High)
        {
            Path.push_back(Node);
            return;
        }

        size_t mid = (Start + End) / 2;

        Query(Node * 2, Start, mid, Low, High, Path);
        Query(Node * 2 + 1, mid + 1, End, Low, High, Path);
    }

    Node Combine(const Node& Left, const Node& Right)
    {
        Node node;

        node.LeftValue = Left.LeftValue;
        node.RightValue = Right.RightValue;

        node.LeftMaxCounter = Left.LeftMaxCounter;
        node.RightMaxCounter = Right.RightMaxCounter;

        node.CombinedMaxCounter = max(Left.CombinedMaxCounter, Right.CombinedMaxCounter);

        if (Right.LeftValue == Left.LeftValue)
        {
            node.LeftMaxCounter += Right.LeftMaxCounter;
        }

        if (Left.RightValue == Right.RightValue)
        {
            node.RightMaxCounter += Left.RightMaxCounter;
        }

        if (Right.LeftValue == Left.RightValue)
        {
            node.CombinedMaxCounter = max(node.CombinedMaxCounter, Left.RightMaxCounter + Right.LeftMaxCounter);
        }

        return node;
    }

    vector<int> Array;
    vector<Node> Tree;
};


int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    
    int n, q, r, l;

    cin >> n;
    while (n != 0)
    {
        cin >> q;
        vector<int> v(n, 0);

        for (int i = 0; i < n; ++i) cin >> v[i];
        SegmentTree tree(v);

        for (int i = 1; i <= q; ++i)
        {
            cin >> r >> l;
            cout << tree.Query(r - 1, l - 1) << '\n';
        }

        cin >> n;
    }

    return 0;
}<file_sep>// https://codeforces.com/contest/1/problem/B
// https://codeforces.com/contest/1/submission/18717562

#ifndef _CRT_NONSTDC_NO_WARNINGS
#define _CRT_NONSTDC_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
using namespace std;

void excelConvert(const string&column, const string& row);
void reverseConvert(const string&row, const string&rowNumber, const string&column, const string& columnNumber);

int main() {

	int n, i, size;
	string s, r, nr1, c, nr2;

	scanf("%d", &n);
	
	while (n--) {
		cin >> s;
		
		size = (int)s.size();
		r = nr1 = c = nr2 = "";
		i = 0;

		while (i < size && (s[i] >= 'A' && s[i] <= 'Z')) r += s[i++];
		while (i < size && (s[i] >= '0' && s[i] <= '9')) nr1 += s[i++];
		while (i < size && (s[i] >= 'A' && s[i] <= 'Z')) c += s[i++];
		while (i < size && (s[i] >= '0' && s[i] <= '9')) nr2 += s[i++];

		(c == "") ? excelConvert(r, nr1) : reverseConvert(r, nr1, c, nr2);
	}


	return EXIT_SUCCESS;
}


void excelConvert(const string&column, const string& row) {

	string rez = "R" + row + "C";
	int col = 0, size = (int)column.size();

	for (int i = 0; i < size; i++) col = col * 26 + column[i] - 'A' + 1;

	rez += to_string(col);
	cout << rez << "\n";

}

void reverseConvert(const string&row, const string&rowNumber, const string&column, const string& columnNumber){

	string rez = "";
	int col = stoi(columnNumber), md;

	while (col > 0) {
		md = (col - 1) % 26;
		rez = (char)('A' + md) + rez;
		col = (col - md) / 26;
	}

	rez += rowNumber;
	cout << rez << "\n";

}

#endif //_CRT_NONSTDC_NO_WARNINGS<file_sep>// https://codeforces.com/contest/1118/problem/A
// https://codeforces.com/contest/1118/submission/67975573
#include <iostream>
#include <algorithm>
using namespace std;


int main()
{
    ios::sync_with_stdio(false); 
    cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);

    unsigned long long queries, n, a, b;
    cin >> queries;

    while (queries--)
    {
        unsigned long long cost = 0;

        cin >> n >> a >> b;
        b = min(a + a, b);

        cost = (n % 2) * a + (n / 2) * b;
        cout << cost << "\n";
    }

    return 0;
}<file_sep>// https://codeforces.com/contest/513/problem/A
// https://codeforces.com/contest/513/submission/14045349

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n1,n2,k1,k2;
    scanf("%d %d %d %d",&n1,&n2,&k1,&k2);
    if (n1<=n2){printf("Second");}
    else{printf("First");}
    return 0;
}
<file_sep># https://codeforces.com/contest/133/problem/A
# https://codeforces.com/contest/133/submission/13408036

s=input()
if "H" in s or "Q" in s or "9" in s:
    print("YES")
else:
    print("NO")
<file_sep>// https://codeforces.com/contest/702/problem/A
// https://codeforces.com/contest/702/submission/46818106

#include <iostream>
using namespace std;


int main()
{
	int n, prev, cur, mx = 1, pc = 1;
	cin >> n >> prev;

	for (int i = 1; i < n; ++i)
	{
		cin >> cur;
		cur > prev ? ++pc : pc = 1;
		if (mx < pc) mx = pc;
		prev = cur;
	}

	cout << mx;
	return 0;
}<file_sep>// https://codeforces.com/contest/681/problem/B
// https://codeforces.com/contest/681/submission/18471034

#include <iostream>
using namespace std;

const int house = 1234567;
const int car = 123456;
const int comp = 1234;

int main() {
	int n, rez;
	bool ok = false;
	cin >> n;
	for (int i = 0; ok == false && house*i <= n; i++) {
		for (int j = 0; ok == false && i*house + j * car <= n; j++) {
			rez = i * house + j * car;
			if ((n - rez) % comp == 0) ok = true;
		}
	}
	(ok) ? puts("YES") : puts("NO");


	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/509/problem/A
// https://codeforces.com/contest/509/submission/14045227

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a[10][10],maxs,i,j,n;
    scanf("%d",&n);
    maxs=1;
    for (i=0;i<n;i++)
    {
        for (j=0;j<n;j++)
        {
            if (j==0 || i==0)
            {
                a[i][j]=1;
            }
            else
            {
                a[i][j]=a[i-1][j]+a[i][j-1];
            }
            if (a[i][j]>maxs)
            {
                maxs=a[i][j];
            }
        }
    }
    printf("%d",maxs);
    return 0;
}
<file_sep>// https://codeforces.com/contest/659/problem/A
// https://codeforces.com/contest/659/submission/17562007

#include <stdio.h>
#include <stdlib.h>



int main() {

	int n, a, b, c;
	scanf("%d %d %d", &n, &a, &b);
	a = (a + b) % n;
	if (a < 0) a = n + a;
	else if (a == 0) a = n;
	printf("%d",a);
}<file_sep>// https://codeforces.com/contest/725/problem/A
// https://codeforces.com/contest/725/submission/21672549

#include <iostream>
#include <string>
using namespace std;

int main()
{
   int n;

   int cnt = 0;
   int all = 0;

   string s;
   cin >> n >> s;
   size_t sz = s.size();
   bool ok;

   ok = (s[0] == '<');
   (ok) ? all++ : cnt++;

   for (auto i = 1; i < sz; ++i)
   {
      if (s[i] == '<')
      {
         cnt = 0;
         if (ok) all++;
      }
      else
      {
         cnt++;
         ok = false;
      }
   }
   all += cnt;

   cout << all;

   return 0;

}<file_sep>// https://codeforces.com/contest/313/problem/B
// https://codeforces.com/contest/313/submission/17171423

#include <iostream>
using namespace std;


int main(){

	int v[100001], n, m, l, r;
	char x, y = 'e';
	x = getchar();
	y = getchar();
	v[1] = 0;
	n = 1;
	while (y != '\n')
	{
		n++;
		if (x == y) v[n] = v[n - 1] + 1;
		else { v[n] = v[n-1]; x = y; }
		y = getchar();
	}
	cin >> m;
	for (; m > 0; m--)
	{
		cin >> l >> r;
		cout << v[r] - v[l] << endl;
	}
	
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/630/problem/A
// https://codeforces.com/contest/630/submission/17205264

#include <stdio.h>
#include <stdlib.h>

int main()
{
	putchar('2'); putchar('5');
    return EXIT_SUCCESS;
}


#include <iostream>
using namespace std;

int main()
{
	unsigned long long n;
	cout << 25;
    return EXIT_SUCCESS;
}

<file_sep>// https://www.spoj.com/problems/IWGBS/

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long
#define ull unsigned long long

/*---------------------------*/

inline int digit(char c)
{
   return c - '0';
}

inline char chr(int d)
{
   return d + '0';
}

void add(string& a, string& b, string& res)
{
   int n = a.size();
   int m = b.size();
   int i = n - 1;
   int j = m - 1;
   int cap = 0;
   int ps;

   res = "";

   for (; i >= 0 && j >= 0; --i , --j)
   {
      ps = digit(a[i]) + digit(b[j]) + cap;
      res += chr(ps % 10);
      cap = ps / 10;
   }

   for (; i >= 0; --i)
   {
      ps = digit(a[i]) + cap;
      res += chr(ps % 10);
      cap = ps / 10;
   }

   for(; j >= 0; --j)
   {
      ps = digit(b[j]) + cap;
      res += chr(ps % 10);
      cap = ps / 10;
   }

   if (cap > 0) res += chr(cap);

   reverse(res.begin(), res.end());
   
}

int main()
{
   ios_base::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr);

   int n;
   cin >> n;
   
   string prevZeros = "1", prevOnes = "1", currentZeros = "1", currentOnes = "1";

   for (int i = n - 1; i > 0; --i)
   {
      currentZeros = prevOnes;
      add(prevZeros, prevOnes, currentOnes);
      
      prevOnes = currentOnes;
      prevZeros = currentZeros;
   }

   add(currentOnes, currentZeros, prevZeros);
   cout << prevZeros;

   return 0;
}
<file_sep>// https://codeforces.com/contest/427/problem/A
// https://codeforces.com/contest/427/submission/14061277

#include <iostream>

using namespace std;

int main()
{
    int n,x,nrp=0,nrn=0;
    cin>>n;
    while (n>0)
    {
        cin>>x;
        if (x==-1 && nrp==0)
        {
            nrn++;
        }
        else if(x==-1 && nrp>0)
        {
            nrp--;
        }
        else if (x>=0)
        {
            nrp+=x;
        }
        n--;
    }
     cout<<nrn;
     return 0;
}
<file_sep>// https://codeforces.com/contest/499/problem/A
// https://codeforces.com/contest/499/submission/17592521

#include <iostream>
using namespace std;




int main() {

	int n, x, t = 0, ra = 1, l, r;
	cin >> n >> x;
	for (; n > 0; n--) {
		cin >> l >> r;
		t += (r - l) + 1;
		for (; ra + x <= l; ra += x);
		if (ra < l) t += (l - ra);
		ra = r + 1;
	}
	cout << t;
	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/158/problem/B
# https://codeforces.com/contest/158/submission/13419053

n=int(input())
x=list(map(int,input().split()))
v=[0,0,0,0,0]
for i in range(n):
    v[x[i]]+=1
nr=v[4]
while (v[1]>0 and v[3]>0):
    nr+=1
    v[3]-=1
    v[1]-=1
while (v[3]>0):
    nr+=1
    v[3]-=1
while(v[1]>=2):
    v[2]+=1
    v[1]-=2
while (v[2]>=2):
    nr+=1
    v[2]-=2
if (v[2]>0 or v[1]>0):
    nr+=1
print(nr)
<file_sep>// https://codeforces.com/contest/581/problem/A
// https://codeforces.com/contest/581/submission/14061199

#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {

	int a, b;
	int time = 0;

	cin >> a;
	cin >> b;

	time = min(a, b);

	int maxnum = max(a, b) - time;

	cout << time << " ";

	cout << maxnum / 2 << endl;

	return 0;
}
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    cout<<min(a,b)<<" "<<(max(a,b)-min(a,b))/2;
    return 0;


}
<file_sep>// https://codeforces.com/contest/630/problem/Q
// https://codeforces.com/contest/630/submission/17316827

#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <math.h>

int main()
{
	int lT, lP, lH;
	double V;
	std::cin >> lT >> lP >> lH;

	V = (lT*lT*lT) /( 6.0*sqrt(2.0)) + (lP*lP*lP*sqrt(2.0)) / 6.0 + (5.0 + sqrt(5.0))*lH*lH*lH / 24.0;
	printf("%.10lf", V);

    return EXIT_SUCCESS;
}

<file_sep># https://codeforces.com/contest/96/problem/A
# https://codeforces.com/contest/96/submission/13407917

s=input()
i=0
ok='true'
while i<=len(s)-7 and ok=='true':
    if s[i:i+7]=="0000000" or s[i:i+7]=="1111111":
        ok='false'
    else:
        i+=1
if ok=='false':
    print("YES")
else:
    print("NO")
<file_sep>// https://codeforces.com/contest/1257/problem/A
// https://codeforces.com/contest/1257/submission/67974889

#include <iostream>
#include <algorithm>
using namespace std;


int main()
{
    ios::sync_with_stdio(false); 
    cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);

    int n, x, a, b, t;
    cin >> t;

    while (t--)
    {
        cin >> n >> x >> a >> b;
        if (b < a) swap(a, b);

        if (b < n)
        {
            auto prevB = b;
            b = min(b + x, n);
            x -= (b - prevB);
        }
        if (a > 1)
        {
            a = max(1, a - x);
        }

        cout << b - a << "\n";
    }

    return 0;
}<file_sep>// https://codeforces.com/contest/711/problem/A
// https://codeforces.com/contest/711/submission/20556856

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char rows[1001][6];
    int n;
    bool ok = false;

    scanf("%d",&n);


    int i;
    for(i = 0; i < n; i++)
    {
        scanf("%s",&rows[i]);
        if (!ok)
        {
            if (rows[i][0] == 'O' && rows[i][1] == 'O')
            {
                ok = true;
                rows[i][0] = '+';
                rows[i][1] = '+';
            }
            else if (rows[i][3] == 'O' && rows[i][4] == 'O')
            {
                ok = true;
                rows[i][3] = '+';
                rows[i][4] = '+';
            }
        }
    }
    if (!ok)
    {
        printf("NO");
    }
    else
    {
        printf("YES\n");
        for (i = 0; i < n; i++)
        {
            printf("%s\n", rows[i]);
        }
    }

    return 0;
}
<file_sep>// https://codeforces.com/contest/439/problem/B
// https://codeforces.com/contest/439/submission/18275375

#include <cstdio>
#include <cstdlib>
#include <algorithm>


int main() {

	unsigned long long n, x, s = 0, v[100001];
	scanf("%llu %llu", &n, &x);
	for (unsigned long long i = 0; i < n; i++)scanf("%llu", &v[i]);
	std::sort(v, v + n);
	for (unsigned long long i = 0; i < n; i++) {
		s += x*v[i];
		x--;
		if (x < 1) x = 1;
	}

	printf("%llu\n", s);

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/problemset/problem/1077/A
// https://codeforces.com/contest/1077/submission/48048633

#include <iostream>
using namespace std;

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int t;
    long long a, b, k;

    cin >> t;
    while (t--)
    {
        cin >> a >> b >> k;
        cout << ((k / 2) + (k % 2)) * a - (k / 2) * b << "\n";
    }

    return 0;
}<file_sep>// https://codeforces.com/contest/339/problem/B
// https://codeforces.com/contest/339/submission/14410462

#include <iostream>

using namespace std;

int main()
{
    long long x,pozcur=1,n,m,grande=0;
    cin>>n>>m;
    while (m>0)
    {
        cin>>x;
        if (x>pozcur)
        {
            grande += x - pozcur ;
        }
        else if (x<pozcur)
        {
            grande += n - pozcur + x;
        }
        pozcur = x;
        m--;
    }
    cout<<grande;
    return 0;


}
<file_sep>// https://codeforces.com/contest/471/problem/A
// https://codeforces.com/contest/471/submission/14395079

#include <iostream>

using namespace std;

int a[10];

int find_picioare()
{
    int aux = -1;
    for (int i = 1;i <= 9;i++)
    {
        if (a[i]>=4)
        {
            aux = i;
        }
    }
    return aux;
}

int cauta_elefant()
{
    int aux = -1;
    for (int i=1;i<=9;i++)
    {
        if (a[i]>=2)
        {
            aux = i;
        }
    }
    return aux;
}

int main()
{
   int x;
   for (int i = 1;i <= 6;i++)
   {
       cin >> x;
       a[x]++;
   }
   int p = find_picioare();
   if (p==-1)
   {
       cout<<"Alien";
   }
   else
   {
       a[p]-=4;
       p = cauta_elefant();
       if (p==-1)
       {
           cout<<"Bear";
       }
       else
       {
           cout<<"Elephant";
       }
   }
   return 0;
}
<file_sep># https://codeforces.com/contest/697/problem/A
# https://codeforces.com/contest/697/submission/25661932

t,s,x = map(int,input().split())
if (x % s == t % s and t <= x or x % s == (t + 1) % s and t+1 < x):
    print('YES')
else:
    print('NO')
<file_sep>// https://codeforces.com/contest/656/problem/F
// https://codeforces.com/contest/656/submission/18043270

#include <iostream>
using namespace std;


int main() {
	int s = 1;
	char c;
	getchar();

	for (int i = 1; i <= 6; i++) {
		c = getchar();
		if (c == '1') s += 10;
		else s += c - 48;
	}

	cout << s;

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/722/problem/B
// https://codeforces.com/contest/722/submission/21723154

#include <iostream>
#include <string.h>
using namespace std;

bool is_vowel(char c)
{
   return (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' || c == 'y');
}

int main()
{
   int nr, n, v[102];
   char s[105];
   cin >> n;
   bool ok = true;

   for (int i = 0; i < n; ++i) cin >> v[i];
   fgets(s, 105, stdin);
   for (int i = 0; i < n; ++i)
   {
      nr = 0;
      fgets(s, 105, stdin);
      size_t sz = strlen(s);
      for (size_t k = 0; k < sz; ++k)
      {
         if (is_vowel(s[k])) nr++;
      }
      if (nr != v[i]) ok = false;
   }
   (ok) ? puts("YES") : puts("NO");

   return 0;
}<file_sep># https://codeforces.com/contest/158/problem/A
# https://codeforces.com/contest/158/submission/13406190

n,k = map(int, input().split())
x=list(map(int,input().split()))
nr=0
meta_number=x[k-1]
for i in range(n):
    if ((i<k and x[i]>0) or (i>=k and x[i]>0 and meta_number==x[i])):
        nr+=1
print(nr)
<file_sep># https://codeforces.com/contest/515/problem/A
# https://codeforces.com/contest/515/submission/14397592

n,m,s=map(int,input().split())
s = s - (abs(n)+abs(m))
if s<0:
    s=1
if s%2==0:
    print('Yes')
else:
    print('No')
<file_sep>// https://codeforces.com/contest/556/problem/A
// https://codeforces.com/contest/556/submission/14410932

#include <iostream>

using namespace std;

int main()
{
  char c;
  int n,nr0=0,nr1=0;
  cin>>n;
  for (int i=1;i<=n;i++)
  {
      cin>>c;
      if (c=='0')
      {
          nr0++;
      }
      else
      {
          nr1++;
      }
      if (nr1>0 && nr0>0)
      {
            if (nr1>nr0)
            {
                nr1-=nr0;
                nr0=0;
            }
            else
            {
                nr0-=nr1;
                nr1=0;
            }
      }
  }
  cout<<max(nr0,nr1);
}
<file_sep>// https://codeforces.com/contest/25/problem/A
// https://codeforces.com/contest/25/submission/14048259

#include <stdio.h>
#include <stdlib.h>

int main()
{
   int x,i=1,nrpar=0,nrimpar=0,n,indexpar=0,indeximpar=0;
   scanf("%d",&n);
   while (n>0)
   {
       scanf("%d",&x);
       if (x%2==0)
       {
           nrpar++;
           indexpar=i;
       }
       else
       {
           nrimpar++;
           indeximpar=i;
       }
       i++;
       n--;
   }
   if (nrimpar>nrpar)
   {
       printf("%d",indexpar);
   }
   else
   {
       printf("%d",indeximpar);
   }
   return 0;
}
<file_sep># https://codeforces.com/contest/268/problem/A
# https://codeforces.com/contest/268/submission/13613840

n = int(input())
a = []
b = []
for _ in range(n):
    x,y=list(map(int,input().split()))
    a.append(x)
    b.append(y)
nr = 0
for i in range(n):
    for j in range(n):
        if b[i]==a[j]:
            nr+=1
print(nr)
<file_sep>// https://codeforces.com/contest/656/problem/A
// https://codeforces.com/contest/656/submission/17154162

#include <iostream>
using namespace std;


int main()
{
	unsigned long long n, t = 1;;

	cin >> n;
	t <<= n;
	if (n >= 13) t -= (1 << (n - 13)) * 100;
	cout << t;
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/750/problem/B
// https://codeforces.com/contest/750/submission/23458730

#include <iostream>
#include <string>
using namespace std;


int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
   
   int n, km, scc = 0, d = 'N';
   bool ok = true;
   string s;

   cin >> n;
   while(n-- && ok)
   {
      if (scc == 0) d = 'N';
      else if (scc == 20000) d = 'S';
      else if (scc < 0 || scc > 20000) ok = false;
      else d = 'U';

      cin >> km >> s;
      if (d == 'N' && s != "South") ok = false;
      else if (d == 'S' && s != "North") ok = false;
      else if (s == "South") scc += km;
      else if (s == "North") scc -= km;
   }
   d = (scc == 0) ? 'N' : 'U';

   (ok && d == 'N') ? puts("YES") : puts("NO");

   return 0;
}<file_sep># https://codeforces.com/contest/507/problem/A
# https://codeforces.com/contest/507/submission/14530591

def recursie(s,i):
    if i<n and s+p[i][1]<=k :
            recursie(s+p[i][1],i+1)
            print(p[i][0]+1,sep = ' ', end=' ')
    else:
        print(i)
n, k = map(int,input().split())
l = list(map(int,input().split()))
p = []
for i in range(n):
    p.append([i,l[i]])
p = sorted(p,key=lambda x: x[1])
s = 0
i = 0
recursie(s,i)
<file_sep># https://codeforces.com/contest/4/problem/C
# https://codeforces.com/contest/4/submission/15134542

n = int(input())
dictio = {}
while n > 0:
    s = input()
    try:
        dictio[s] += 1
        print(s,dictio[s],sep='')
    except:
        dictio[s] = 0
        print('OK')
    n -= 1
<file_sep># https://codeforces.com/contest/116/problem/A
# https://codeforces.com/contest/116/submission/13407618

n=int(input())
nr_max=0
nr_curent=0
for i in range(n):
    pas_out,pas_in=map(int, input().split())
    nr_curent=nr_curent-pas_out+pas_in
    if nr_curent>nr_max:
        nr_max=nr_curent
print(nr_max)
    
<file_sep># https://codeforces.com/contest/599/problem/A
# https://codeforces.com/contest/599/submission/14384482

d1,d2,d3 = map(int, input().split())
l = min(d1,d2)
total = l
h = max(d1,d2)
p = min(l+h,d3)
total += p
p = min(h,d3+l)
total += p
print(total)
<file_sep>// https://codeforces.com/contest/734/problem/B
// https://codeforces.com/contest/734/submission/22307571

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
   int k2, k3, k5, k6, m;
   cin >> k2 >> k3 >> k5 >> k6;
   m = min(k2, min(k5, k6));
   cout << m * 256 + min(k2 - m, k3) * 32;
   return 0;
}<file_sep>// https://codeforces.com/contest/740/problem/A
// https://codeforces.com/contest/740/submission/22715054

#include <iostream>
using namespace std;


int main()
{
   long long s, n, a, b, c, min;
   cin >> n >> a >> b >> c;

   min = LLONG_MAX;

   for (int i = 0; i <= 4; i++)
   {
      for (int j = 0; j <= 4; j++)
      {
         for (int p = 0; p <= 4; p++)
         {
            if ((n + i + 2*j + 3*p) % 4 == 0)
            {
               s = i*a + j * b + p * c;
               if (s < min) min = s;
            }
         }
      }
   }
   cout << min;

   return 0;
}<file_sep>// https://codeforces.com/contest/749/problem/A
// https://codeforces.com/contest/749/submission/23144602

#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <stdio.h>
using namespace std;


int main()
{
   int n;
   int nr;
   bool o3 = false;
   scanf("%d", &n);

   if (n & 1) o3 = true, n -= 3;
   nr = n / 2;

   if (o3) printf("%d\n3 ", nr + 1);
   else printf("%d\n",nr);
   while (nr--) printf("2 ");

   return 0;
}<file_sep>// https://codeforces.com/contest/743/problem/B
// https://codeforces.com/contest/743/submission/22979867

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <iostream>
using namespace std;


int main()
{

   unsigned long long k, poz, el, adv;
   int n;
   cin >> n >> k;
  
   el = 1;
   poz = 1;

   while (poz <= k)
   {
      el++;
      poz <<= 1;
   }

   el--;
   poz >>= 1;
   adv = (unsigned long long) 1 << el;

   for (;;)
   {
      if (poz == k) break;
      else {
         if ((k - poz) % adv == 0) break;
         el--;
         poz >>= 1;
         adv >>= 1;
      }
   }

   cout << el;
   
   return 0;
}
<file_sep>// https://codeforces.com/contest/977/problem/A
// https://codeforces.com/contest/977/submission/46371984

#include <iostream>
using namespace std;


int main()
{
	unsigned long long n = 0;
	int k = 0;
	cin >> n >> k;

	while (k > 0)
	{
		if (n % 10 != 0)
		{
			if (k > n % 10)
			{
				k -= (n % 10);
				n -= (n % 10);
			}
			else
			{
				n -= k;
				k = 0;
			}
		}
		else
		{
			n = n / 10;
			--k;
		}
	}
	cout << n;

	return 0;
}<file_sep># https://codeforces.com/contest/616/problem/A
# https://codeforces.com/contest/616/submission/15329901

a = input().lstrip("0")
b = input().lstrip("0")
if len(a) > len (b) or len(a) == len(b) and a > b:
    print('>')
elif len(a) < len(b) or len(a) == len(b) and a < b:
    print('<')
elif a == b:
    print('=')
<file_sep># https://codeforces.com/contest/476/problem/A
# https://codeforces.com/contest/476/submission/14268179

n,m = map(int,input().split())
if n%2==0:
    high = n//2
else:
    high = n//2 + 1
if high%m==0:
    div = high//m
else:
    div = high//m +1
if m*div<=n:
    print(m*div)
else:
    print(-1)
<file_sep>// https://codeforces.com/contest/549/problem/A
// https://codeforces.com/contest/549/submission/17147407

#include <iostream>
using namespace std;

void check(char x, int tab[27])
{
	if (x == 'f' || x == 'a' || x == 'c' || x == 'e') tab[x - 'a']++;
}

bool face(int x, int y, char mat[52][52])
{
	int tab[27];
	memset(tab, 0, 27 * sizeof(int));
	check(mat[x][y],tab);
	check(mat[x + 1][y],tab);
	check(mat[x][y + 1],tab);
	check(mat[x + 1][y + 1],tab);
	return ((tab['a' - 'a'] == 1) &&
			(tab['e' - 'a'] == 1) &&
			(tab['c' - 'a'] == 1) &&
			(tab['f' - 'a'] == 1));
}

int main()
{
	char mat[52][52];
	int n, m, cont = 0;

	cin >> n >> m;

	for (int i = 1; i <= n + 1; i++) {
		for (int j = 1; j <= m + 1; j++) {
			if ( i == n + 1 || j == m + 1) mat[i][j] = 'X';
			else cin >> mat[i][j];
		}
	}

	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= m; j++)
			if (face(i,j,mat)) cont++;
	cout << cont;

	return EXIT_SUCCESS;
}

<file_sep>// https://codeforces.com/contest/313/problem/A
// https://codeforces.com/contest/313/submission/14057579

#include <iostream>
#include <stdlib.h>
using namespace std;

int main()
{
    long long n,aux;
    cin>>n;
    aux=n;
    int lc,sc;
    lc=abs(n%10);
    aux=aux/10;
    sc=abs(aux%10);
    aux=aux/10;
   if (n>=0)
    {
        cout<<n;
    }
    else
    {
        if (lc>=sc)
        {
            cout<<n/10;

        }
        else
        {
           n=n/100;
           n=n*10;;
           n-=lc;
           cout<<n;
        }
    }
    return 0;
}
<file_sep>// https://codeforces.com/contest/447/problem/A
// https://codeforces.com/contest/447/submission/18041709

#include <iostream>
using namespace std;



int main() {

	int x, n, p, v[301];
	memset(v, 0, 301 * sizeof(int));
	
	cin >> p >> n;
	for (int i = 1; i <= n; i++) {
		cin >> x;
		if (v[x % p] != 0) {
			cout << i;
			goto out;
		}
		else v[x%p] = 1;
	}
	cout << "-1";

out:
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/707/problem/A
// https://codeforces.com/contest/707/submission/21341900

#include <stdio.h>
#include <stdlib.h>


int main()
{
   int n, m, elms;
   char c;
   int ok = 0, i = 0;

   scanf("%d %d", &n, &m);

   elms = n * m;
   while (ok == 0 && i++ < elms)
   {
      c = getchar();
      c = getchar();
      ok = (c != 'B' && c != 'W' && c!= 'G');
   }

   (ok == 0) ? puts("#Black&White") : puts("#Color");

   return EXIT_SUCCESS;
}<file_sep>// https://www.spoj.com/problems/MARTIAN/

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long
#define ull unsigned long long

/*------------------------------------------------------------------*/

int n, m;
int yeyenium[505][505], bloggium[505][505], ans[505][505];


int main()
{
   ios_base::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr);

   cin >> n >> m;
   while (n != 0 && m != 0)
   {
      for (int i = 1; i <= n; ++i)
      {
         for (int j = 1; j <= m; ++j)
         {
            cin >> yeyenium[i][j];
            yeyenium[i][j] += yeyenium[i][j - 1];
         }
      }

      for (int i = 1; i <= n; ++i)
      {
         for (int j = 1; j <= m; ++j)
         {
            cin >> bloggium[i][j];
            bloggium[i][j] += bloggium[i - 1][j];
         }
      }

      for(int i = 1; i<=n; ++i)
      {
         for(int j = 1; j<=m; ++j)
         {
            ans[i][j] = max(ans[i - 1][j] + yeyenium[i][j], ans[i][j - 1] + bloggium[i][j]);
         }
      }

      cout << ans[n][m] << "\n";
      cin >> n >> m;

   }


   return 0;
}
<file_sep>// https://codeforces.com/contest/745/problem/A
// https://codeforces.com/contest/745/submission/23052557

#include <stdio.h>
#include <iostream>
#include <set>
#include <string>
using namespace std;


void shift(string& s)
{
   string p;
   p = s.substr(1, s.size() - 1);
   p += s[0];
   s = p;
}

int main()
{
   string s;
   set<string> multime;
   cin >> s;
   multime.insert(s);
   for (int i = 1; i <= (int)s.size() + 1; ++i)
   {
      shift(s);
      multime.insert(s);
   }
   cout << multime.size();
   return 0;
}<file_sep>// https://www.spoj.com/problems/EDIST/

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long 
#define ull unsigned long long

/*------------------------------------------------------------------*/

int mat[2005][2005];

int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
   string s, p;
   int t, n, m, cost;
   cin >> t;
   while(t--)
   {
      cin >> s >> p;
      n = s.length();
      m = p.length();
      
      for (int i = 0; i <= m + 1; ++i) mat[0][i] = i;
      for (int i = 0; i <= n + 1; ++i) mat[i][0] = i;

      for(int i = 1; i<=n;++i)
      {
         for(int j = 1; j<=m;++j)
         {
            cost = 1;
            if (s[i - 1] == p[j - 1]) cost = 0;
            mat[i][j] = min(mat[i - 1][j - 1] + cost, min(mat[i - 1][j] + 1, mat[i][j - 1] + 1));
         }
      }
      cout << mat[n][m] << '\n';
   }


   return 0;
}<file_sep>// https://codeforces.com/contest/617/problem/A
// https://codeforces.com/contest/617/submission/16293561

#include <stdio.h>
#include <stdlib.h>


int main()
{
    int n,contor,p;
    scanf("%d",&n);
    p = 5;
    contor = 0;
    while (p > 0 && n != 0)
    {
        contor += n/p;
        n -= p* (n/p);
        p--;
    }
    printf("%d",contor);
    return 0;
}
<file_sep>// https://codeforces.com/contest/489/problem/C
// https://codeforces.com/contest/489/submission/22857330

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;


int main()
{
   vector<int> min(10, 0), max(10,0);
   int m, s, n, p;
   scanf("%d %d", &m, &s);
   n = m;
   p = s;

   while (m--)
   {
      if (s >= 9) max[9]++, min[9]++, s -= 9;
      else max[s]++, min[s]++, s -= s;
   }

   if (s > 0 || (n > 1 && p == 0)) puts("-1 -1");
   else
   {
      string solMin = "";
      string solMax = "";
      if (min[0] == 1 && n == 1) solMin = "0";
      else
      {
         if (min[1] != 0) solMin += '1', min[1]--;
         else if (min[0] > 0 && n > 1)
         {
            min[0]--;
            for (int i = 2; i <= 9; ++i)
            {
               if (min[i] != 0)
               {
                  min[i]--;
                  solMin += '1';
                  min[i - 1]++;
                  break;
               }
            }
         }

         for (int i = 0; i <= 9; ++i)
         {
            for (int k = 1; k <= min[i]; k++)solMin += (char)(i + '0');
         }
      
      }

      if (max[0] == 1 && n == 1) solMax = "0";
      else
      {
         for (int i = 9; i >= 0; --i)
         {
            for (int k = 1; k <= max[i]; k++)solMax += (char)(i + '0');
         }
      }
      cout << solMin << " " << solMax;
   }

   return 0;
}

<file_sep># https://codeforces.com/contest/572/problem/A
# https://codeforces.com/contest/572/submission/14898609

a, b = map(int,input().split())
k, m = map(int,input().split())
l1 = list(map(int,input().split()))
l2 = list(map(int,input().split()))
if l1[k - 1] < l2[b - m]:
    print('YES')
else:
    print('NO')
<file_sep>// https://codeforces.com/contest/258/problem/A
// https://codeforces.com/contest/258/submission/17172639

#include <iostream>
#include <string>
using namespace std;

int main()
{
	string line;
	getline(cin, line);
	bool ok = (line[0] == '1');
	int i = 0, len = line.length();

	while (ok == true && i < len - 1)
	{
		putchar('1');
		i++;
		ok = line[i] == '1';
	}

	if (ok == true || i == len - 1) return 0;
	i++;
	for (; i < len;i++) putchar(line[i]);

	return EXIT_SUCCESS;
}

<file_sep>// https://codeforces.com/contest/735/problem/D
// https://codeforces.com/contest/735/submission/22544920

#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;

bool is_prime(long long n)
{
   double x = sqrt(n);
   long long k = (long long)x + 1;
   for (long long i = 2; i < k; ++i)
   {
      if (n % i == 0) return false;
   }
   return true;
}


int main()
{

   long long n;
   cin >> n;
   if (is_prime(n)) puts("1");
   else if (n & 1) {
      if (is_prime(n - 2)) puts("2");
      else puts("3");
   }
   else puts("2");

   return 0;
}<file_sep>// https://codeforces.com/contest/777/problem/A
// https://codeforces.com/contest/777/submission/24967162

#include <iostream>
#include <vector>
using namespace std;



int main()
{
   ios::sync_with_stdio(false);
   
   int moves[6][3] = { {0, 1, 2}, {1, 0, 2}, {1, 2, 0}, {2, 1, 0}, {2, 0, 1}, {0, 2, 1} };

   long long n, pos;
   cin >> n >> pos;
   cout<<moves[n % 6][pos];



   return 0;
}<file_sep>// https://codeforces.com/problemset/problem/1015/A
// https://codeforces.com/contest/1015/submission/48889387
#include <iostream>
#include <fstream>
#include <chrono>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>
using namespace std;

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);
    int n, m, l, r;
    cin >> n >> m;

    set<int> s;
    for (int i = 1; i <= m; ++i)
    {
        s.insert(i);
    }


    for (int i = 1; i <= n; ++i)
    {
        cin >> l >> r;
        for (int k = l; k <= r; ++k) s.erase(k);
    }

    cout << s.size() << "\n";
    for (const auto& p : s) cout << p << " ";



    return 0;
}<file_sep>// https://codeforces.com/contest/255/problem/A
// https://codeforces.com/contest/255/submission/16294406

#include <stdio.h>
#include <stdlib.h>
struct muscles
{
    char* name;
    int value;
};



int main()
{
    struct muscles muscle[3];
    int i,n,x,j;
    muscle[0].name = "chest";
    muscle[0].value = 0;
    muscle[1].name = "biceps";
    muscle[1].value = 0;
    muscle[2].name = "back";
    muscle[2].value = 0;
    scanf("%d",&n);
    for (i = 1; i <=n; i++)
    {
        scanf("%d",&x);
        if (i % 3 == 0) muscle[2].value += x;
        else if (i % 3 == 2) muscle[1].value += x;
        else muscle[0].value += x;
    }
    for (i = 0; i < 3; i++)
    {
        for (j = i + 1; j < 3; j++)
        {
            if (muscle[i].value < muscle[j].value)
            {
                struct muscles aux;
                aux = muscle[i];
                muscle[i] = muscle[j];
                muscle[j] = aux;
            }
        }
    }
    printf("%s",muscle[0].name);
    return 0;

}
<file_sep>// https://codeforces.com/contest/686/problem/A
// https://codeforces.com/contest/686/submission/18716299

#ifndef _CRT_NONSTDC_NO_WARNINGS
#define _CRT_NONSTDC_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
using namespace std;


int main() {

	long long n, x, d, ct = 0;
	char sign;

	scanf("%lld %lld", &n, &x);
	
	while (n--) {
		scanf("%c %c %lld", &sign, &sign, &d);
		(sign == '+') ? x += d : ((x >= d) ? x -= d : ct++);
	}
	printf("%lld %lld \n", x, ct);


	return EXIT_SUCCESS;
}

#endif //_CRT_NONSTDC_NO_WARNINGS<file_sep>// https://codeforces.com/contest/580/problem/A
// https://codeforces.com/contest/580/submission/13753520

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,n,former,x,len,max_len;
    scanf("%d",&n);
    scanf("%d",&former);
    len = 1;
    max_len = 1;
    for (i=2;i<=n;i+=1)
    {
        scanf("%d",&x);
        if (x>=former)
        {
            len+=1;
        }
        else
        {
            if (len>max_len){max_len=len;}
            len = 1;
        }
        former = x;
    }
    if (len>max_len){max_len=len;}
    printf("%d",max_len);
    return 0;
}
<file_sep>// https://codeforces.com/contest/688/problem/A
// https://codeforces.com/contest/688/submission/22867613

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
using namespace std;


int main()
{
   string s;
   int n, d;
   scanf("%d %d", &n, &d);

   int current = 0;
   int mx = 0;
   int cr = 0;

   for (int i = 0; i < d; ++i)
   {
      cin >> s;
      current = 0;
      for (int k = 0; k < n; ++k)
      {
         if (s[k] == '1') current++;
      }
      if (current == n) cr = 0;
      else cr++;
      if (cr > mx) mx = cr;
   }

   cout << mx;

   return 0;
}
<file_sep>// https://codeforces.com/contest/622/problem/A
// https://codeforces.com/contest/622/submission/17340093

#include <iostream>
using namespace std;


int main() {
	long long n, i;
	cin >> n;
	for (i = 1; ((1 + i) * i )/ 2 < n; i++);
	cout << n - ((i - 1) * i) / 2;
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/703/problem/A
// https://codeforces.com/contest/703/submission/21342039

#include <stdio.h>
#include <stdlib.h>


int main()
{

   int n, M = 0, C = 0, m, c;
   scanf("%d", &n);
   while (n--)
   {
      scanf("%d %d", &m, &c);
      if (m != c)
      {
         (m > c) ? M++ : C++;
      }
   }
   (M == C) ? puts("Friendship is magic!^^") : (M > C) ? puts("Mishka") : puts("Chris");

   return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/334/problem/A
// https://codeforces.com/contest/334/submission/18030157

#include <iostream>
using namespace std;


int main() {

	int n;
	cin >> n;
	for (int i = 1, t = 2; i <= n*n / 2; i++, t += 2) {
		cout << i << " " << n*n - i + 1 << " ";
		if (t % n == 0) cout << "\n";
	}

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/1206/problem/B
// https://codeforces.com/contest/1206/submission/67974231

#include <iostream>
using namespace std;


int main()
{
    ios::sync_with_stdio(false); 
    cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);

    long long negative = 0, positive = 0, zero = 0;
    long long n = 0, x = 0, cost = 0;

    cin >> n;
    while (n--)
    {
        cin >> x;
        if (x == 0) zero++;
        else if (x > 0)
        {
            cost += (x - 1);
            positive++;
        }
        else
        {
            cost += (-x - 1);
            negative++;
        }
    }

    if (negative % 2 == 1)
    {
        if (zero > 0)
        {
            zero--;
            cost++;
        }
        else
        {
            negative--;
            positive++;
            cost += 2;
        }
    }
    cost += zero;
    cout << cost;

    return 0;
}<file_sep>// https://codeforces.com/contest/489/problem/B
// https://codeforces.com/contest/489/submission/17433045

#include <iostream>
#include <algorithm>
using namespace std;


int main() {

	int n, m, a[100], b[100];
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	cin >> m;
	for (int i = 0; i < m; i++) cin >> b[i];
	sort(a, a + n, [](int left, int right) {return left > right; });
	sort(b, b + m, [](int left, int right) {return left > right; });
	int i = 0, j = 0, count = 0;
	while (i < n && j < m) {
		if (a[i] > b[j] + 1) i++;
		else if (b[j] > a[i] + 1) j++;
		else i++, j++, count++;
	}
	cout << count;
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/732/problem/E
// https://codeforces.com/contest/732/submission/21668163

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
using namespace std;

typedef struct _STRUCT
{
   int pow;
   int idx;
}STRUCT;


bool compStructs(STRUCT left, STRUCT right)
{
   return (left.pow < right.pow);
}


STRUCT sockets[200005];
vector<int> adaptoare(200005, 0);
vector<int> connected(200005, 0);
map<int, queue<int>> comps;

int n, m;


int main()
{
   int pw, u = 0, c = 0, k = 0, r = 0;
   scanf("%d %d", &n, &m);
  

   for (int i = 1; i <= n; ++i)
   {
      scanf("%d", &pw);
      comps[pw].push(i);
   }

   for (int i = 1; i <= m; ++i) scanf("%d", &sockets[i]), sockets[i].idx = i;
   sort(sockets + 1, sockets + m + 1, compStructs);
  
   for (int i = 1; i <= m; ++i)
   {

      k = 0;
      pw = sockets[i].pow;
      auto it = comps.find(pw);
      while (it == comps.end() && k < 33)
      {
         (pw % 2 == 0) ? r = 0 : r = 1;
         pw = pw / 2 + r;
         it = comps.find(pw);
         k++;
      }

      if (k > 32)
      {
         continue;
      }

      int first = (it->second).front();
      (it->second).pop();
      if (it->second.empty()) comps.erase(it);

      c++;
      u += k;
      adaptoare[sockets[i].idx] = k;
      connected[first] = sockets[i].idx;
   }

   printf("%d %d\n", c, u);

   for (int i = 1; i <= m; ++i) printf("%d ", adaptoare[i]);
   printf("\n");

   for (int i = 1; i <= n; ++i) printf("%d ", connected[i]);

   return 0;
}<file_sep># https://codeforces.com/contest/454/problem/A
# https://codeforces.com/contest/454/submission/14543739

n = int(input())
k = 1
for i in range(1,n+1):
    for j in range(1,(n-k)//2+1):
        print('*',end='')
    for l in range(k):
        print('D',end='')
    for j in range(1,(n-k)//2+1):
        print('*',end='')
    if i<(n//2)+1:
        k+=2
    else:
        k-=2
    print()
        
<file_sep>// https://codeforces.com/contest/327/problem/A
// https://codeforces.com/contest/327/submission/15059968

#include <iostream>

using namespace std;

int v[101];

int main()
{
    int n,no1=0,max,fin;
    cin>>n;
    for (int i = 1; i<=n;i++)
    {
        cin>>v[i];
        if (v[i] == 1) no1++;
    }
    fin = 0;
    for (int i = 1; i<=n; i++)
    {
        max = no1;
        for (int j = i; j<=n;j++ )
        {
            if (v[j] == 1) max--;
            else max++;
            if (max>fin) fin = max;
        }
    }
    cout<<fin;
    return 0;
}
<file_sep>// https://codeforces.com/contest/591/problem/A
// https://codeforces.com/contest/591/submission/18018381

#include <iostream>
#include <iomanip> 
using namespace std;


int main() {

	int l, p, q;
	cin >> l >> p >> q;
	cout << setprecision(10) << (double)(l * p) / (p + q * 1.0);

	return EXIT_SUCCESS;
}<file_sep>// https://www.spoj.com/problems/ABCPATH/

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <cstring>
#include <queue>
#include <string>
using namespace std;

#define ll long long
#define ull unsigned long long

/*------------------------------------------------------------------*/

char mat[55][55];
int vis[55][55];
int vec[30];
int h, w;
int best = 0;
int arrx[] = { -1,0,1,1,1,0,-1,-1 };
int arry[] = { -1,-1,-1,0,1,1,1,0 };
queue<pair<int, int>> boje;

void citire()
{
   string s;
   for (int i = 1; i <= h; ++i)
   {
      cin >> s;
      for (int j = 1; j <= w; ++j)
      {
         vis[i][j] = 0;
         mat[i][j] = s[j - 1];
         if (mat[i][j] == 'A') boje.push(make_pair(i, j));
      }
   }
}

void solve(int x, int y, char c, int current)
{
   if (current > best) best = current;
   vis[x][y] = 1;
   int tx, ty;

   for (int i = 0; i < 8; ++i)
   {
      tx = arrx[i] + x;
      ty = arry[i] + y;
      if ((mat[tx][ty] == c + 1) && vis[tx][ty] == 0)
         solve(tx, ty, mat[tx][ty], current + 1);
   }
}


int main()
{
   //ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

   cin >> h >> w;
   pair<int, int> psd;
   int ct = 1;

   while (h != 0 && w != 0)
   {
      best = 0;
      citire();
      while (!boje.empty())
      {
         psd = boje.front();
         boje.pop();
         solve(psd.first, psd.second, mat[psd.first][psd.second], 1);
      }
      printf("Case %d: %d\n", ct, best);
      ct++;
      cin >> h >> w;
   }

   return 0;
}<file_sep>// https://codeforces.com/contest/683/problem/C
// https://codeforces.com/contest/683/submission/18526804

fun main(args: Array<String>) {

    var arr1 = IntArray(3000); 
    var arr2 = IntArray(3000); 
    var arr3 = IntArray(3000);

    val (line) = readLine()!!.split('\n')
    
    var y = line.split(Regex("\\s+"))
    var n1 = y[0].toInt();
    
    var i = 1;
    while (i <= n1){
        arr1[i] = y[i].toInt();
        i++;
    }
    
    val (line2) = readLine()!!.split('\n')
    var y2 = line2.split(Regex("\\s+"))
    var n2 = y2[0].toInt();
    
    i = 1;
    while (i <= n2){
        arr2[i] = y2[i].toInt();
        i++;
    }
    
    var k = 0;
    i = 1;
    
    while (i <= n1){
        var j = 1;
        var p = 0;
        while (j <= n2){
            if (arr1[i] == arr2[j]) p = 1;
            j++;
        }
        if (p == 0){
            k++;
            arr3[k] = arr1[i];
        }
        i++;
    }
    
    i = 1;
    while (i <= n2){
        var j = 1;
        var p = 0;
        while (j <= n1){
            if (arr2[i] == arr1[j]) p = 1;
            j++;
        }
        if (p == 0){
            k++;
            arr3[k] = arr2[i];
        }
        i++;
    }
    
    print(k);
    print(' ');
    i = 1;
    while (i <= k){
        print(arr3[i]);
        print(' ');
        i++;
    }
    
    
    
    
}
<file_sep>// https://codeforces.com/problemset/problem/996/A
// https://codeforces.com/contest/996/submission/49053280
#include <iostream>
#include <fstream>
#include <chrono>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>
using namespace std;

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);
    
    int n, r = 0;
    vector<int> v = { 100, 20, 10, 5,1 };
    cin >> n;

    for (size_t i = 0; i < v.size(); ++i)
    {
        r += (n / v[i]);
        n = n % v[i];
    }

    cout << r;

    return 0;
}<file_sep>// https://codeforces.com/problemset/problem/1256/A
// https://codeforces.com/contest/1256/submission/67693035

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int queries;
    cin >> queries;

    while (queries--)
    {
        int a, b, n, s;
        cin >> a >> b >> n >> s;

        auto cat = (s / n);

        b = (b - s % n);

        cat -= min(cat, a);

        if (cat > 0)
        {
            b -= (cat * n);
        }

        (b < 0) ? cout << "NO\n" : cout << "YES\n";
    }

    return 0;
}<file_sep>// https://codeforces.com/contest/233/problem/A
// https://codeforces.com/contest/233/submission/17701678

#include <iostream>
using namespace std;


int main() {

	int c;
	cin >> c;
	if (c & 1) puts("-1");
	else for (int i = 1; i <= c; i += 2) cout << i + 1 << " " << i << " ";

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/279/problem/B
// https://codeforces.com/contest/279/submission/46925339

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int main()
{
    std::ios::sync_with_stdio(false); cin.tie(NULL);

    int n, t;
    cin >> n >> t;

    vector<int> v(n, 0);
    for (int i = 0; i < n; ++i) cin >> v[i];


    int p1 = 0, p2 = 0, s = 0, _max = 0;
    while (p1 < n && p2 < n)
    {
        if (p1 > p2) s += v[p2++];
        else if (s > t) s -= v[p1++];
        else
        {
            s += v[p2++];
            if (s <= t) _max = max(_max, p2 - p1);
        }
    }

    cout << _max;
    return 0;
}<file_sep>// https://codeforces.com/contest/835/problem/A
// https://codeforces.com/contest/835/submission/29155915

// Example program
#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;

int mat[12][102][102];

int main()
{
    int s, v1, v2, t1, t2, r1, r2 ;
    scanf("%d %d %d %d %d", &s, &v1, &v2, &t1, &t2);
    r1 = v1 * s + 2 * t1;
    r2 = v2 * s + 2 * t2;
    
    if (r1 < r2) cout << "First";
    else if (r2 < r1 ) cout << "Second";
    else cout << "Friendship";
    return 0;    
}
<file_sep># https://codeforces.com/contest/344/problem/A
# https://codeforces.com/contest/344/submission/13589209

n = int(input())
nr = 0
prev = '-1'
for _ in range(n):
    x = input()
    if x != prev:
        nr+=1
        prev = x
print(nr)
<file_sep>// https://codeforces.com/contest/618/problem/A
// https://codeforces.com/contest/618/submission/18010612

#include <iostream>
using namespace std;


int main() {

	int n, t, s;

	cin >> n;
	while (n > 0) {
		t = 0;
		s = 1;
		for (; s <= n; s <<= 1) t++;
		s >>= 1;
		n -= s;
		cout << t << " ";
	}

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/742/problem/A
// https://codeforces.com/contest/742/submission/22766765

#include <iostream>
using namespace std;

int main()
{
   int n, r;
   cin >> n;
   r = n % 4;
   if (n == 0) puts("1");
   else if (r == 1) puts("8");
   else if (r == 2) puts("4");
   else if (r == 3) puts("2");
   else if (r == 0) puts("6");

   return 0;
}<file_sep>// https://codeforces.com/contest/1091/problem/A
// https://codeforces.com/contest/1091/submission/48048474

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int y, b, r;
    
    cin >> y >> b >> r;

    b = min(r - 1, b);
    y = min(b - 1, y);
    cout << 3 * y + 3;

    return 0;
}<file_sep>// https://codeforces.com/contest/507/problem/B
// https://codeforces.com/contest/507/submission/18029581

#include <cstdio>
#include <cstdlib>
#include <cmath>


int main() {

	long r, x1, y1, x2, y2;
	double dist, ct = 0;
	scanf("%ld %ld %ld %ld %ld", &r, &x1, &y1, &x2, &y2);
	dist = (sqrt(double(x1 - x2) * double(x1 - x2) + double(y1 - y2) * double(y1 - y2)));
	if (x1 == x2 &&  y1 == y2) goto out;
	ct = ceil(dist / r / 2.0);
	
out:
	printf("%.0lf", ct);
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/628/problem/B
// https://codeforces.com/contest/628/submission/47967159

#include <string>
#include <iostream>
using namespace std;

inline uint8_t ToDigit(char c)
{
    return c - '0';
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string s;
    unsigned long long count = 0;

    cin >> s;
    if (ToDigit(s[0]) % 4 == 0) count = 1;

    for (size_t i = 1; i < s.size(); ++i)
    {
        if (ToDigit(s[i]) % 4 == 0) ++count;
        
        uint8_t nmb = ToDigit(s[i - 1]) * 10 + ToDigit(s[i]);
        if (nmb % 4 == 0) count += i;
    }

    cout << count;
    return 0;
}<file_sep>// https://codeforces.com/contest/518/problem/A
// https://codeforces.com/contest/518/submission/18055216

#include <string>
#include <iostream>
using namespace std;


int main() {

	string s, t;
	size_t i;

	cin >> s >> t;
	
	for (i = s.size() - 1; i >= 0; i--) {
		if (s[i] != 'z') break;
	}
	s[i] = s[i] + 1;
	i++;
	for (; i < s.size(); i++) s[i] = 'a';
	(s < t) ? cout << s : cout << "No such string\n";
	
	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/450/problem/A
# https://codeforces.com/contest/450/submission/15261021

n,m = map(int,input().split())
lis = list(map(int,input().split()))
copii = [x for x in range(1, n+1 )]
while lis != []:
    x = lis.pop(0)
    y = copii.pop(0)
    if (x-m) > 0 :
        lis.append(x-m)
        copii.append(y)
print(y)
    
        
<file_sep>// https://codeforces.com/contest/545/problem/B
// https://codeforces.com/contest/545/submission/18454030

#include <iostream>
#include <string>
using namespace std;


int main() {
	string a, b, rez = "";
	int diffa = 0, diffb = 0, len;
	cin >> a >> b;
	len = a.size();
	for (int i = 0; i < len; i++) {
		if (a[i] == b[i]) rez += a[i];
		else {
			if (diffa > diffb) {
				diffb++;
				rez += b[i];
			}
			else diffa++, rez += a[i];
		}
	}
	if (diffa != diffb) rez = "impossible";
	cout << rez;
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/550/problem/C
// https://codeforces.com/contest/550/submission/46638716

#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
using namespace std;

set<int> multiplii2;
set<int> multiplii3;
map<int, vector<int>> occurences;

void BuildSet()
{
    int i = 16;
    for (; i < 100; i = i + 8) multiplii2.insert(i);
    for (; i < 1000; i = i + 8) multiplii3.insert(i);
}

void BuildOcc(const std::string& str)
{
    for (size_t i = 0; i < str.size(); ++i)
    {
        occurences[str[i] - '0'].push_back(i);
    }
}

bool Check1(int& res)
{
    if (occurences[0].size() > 0)
    {
        res = 0;
        return true;
    }
    if (occurences[8].size() > 0)
    {
        res = 8;
        return true;
    }
    return false;
}


bool Check2(int& res)
{
    for (const auto& m2 : multiplii2)
    {
        int d1 = m2 / 10;
        int d2 = m2 % 10;
        if (occurences[d1].size() > 0 && occurences[d2].size() > 0 && occurences[d1][0] < occurences[d2].back())
        {
            res = m2;
            return true;
        }
    }

    return false;
}

bool Check3(int& res)
{
    for (const auto& m3 : multiplii3)
    {
        int d1 = m3 / 100;
        int d2 = (m3 / 10) % 10;
        int d3 = m3 % 10;
        if (occurences[d1].size() > 0 && occurences[d2].size() > 0 && occurences[d3].size() > 0)
        {
            for (const auto& pos : occurences[d2])
            {
                if (pos > occurences[d1][0] && pos < occurences[d3].back())
                {
                    res = m3;
                    return true;
                }
            }
        }
    }

    return false;

}

int main()
{
    string str;
    int res;
    cin >> str;
    BuildSet();
    BuildOcc(str);

    if (Check1(res)) cout << "YES\n" << res;
    else if (Check2(res)) cout << "YES\n" << res;
    else if (Check3(res)) cout << "YES\n" << res;
    else cout << "NO\n";

    return 0;
}
<file_sep>// https://codeforces.com/contest/683/problem/D
// https://codeforces.com/contest/683/submission/18527258

fun main(args: Array<String>) {
    val (q) = readLine()!!.split('\n').map(String::toInt)
    var i = 1;
    while (i <= q){
        val (n, m, p) = readLine()!!.split(' ').map(String::toInt)
        var j = 1;
        var o = 0;
        while (j <= n){
            var k = 1;
            while (k <= m){
                if (j * k == p) o = 1;
                k++;
                }
            j++;
        }
        if (o == 1) println("Yes")
        else println("No");
        i++;
    }
}
<file_sep>// https://codeforces.com/contest/535/problem/B
// https://codeforces.com/contest/535/submission/17147803

#include <iostream>
using namespace std;

int main()
{
	int n = 0;
	char str[11];
	
	cin >> str;
	for (int i = 0; i < strlen(str); i++)
	{
		n <<= 1;
		if (str[i] == '4') n++;
		else n += 2;
	}

	cout << n;
	return EXIT_SUCCESS;
}

<file_sep>// https://codeforces.com/contest/785/problem/B
// https://codeforces.com/contest/785/submission/25527550

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;


typedef struct point{
   int x;
   int y;
}point;




bool compare(const point& a, const point&b)
{
   return a.x < b.x || (a.x == b.x && a.y < b.y);
}

bool compareb(const point& a, const point&b)
{
   return a.y < b.y || (a.y == b.y && a.x < b.x);
}

int dist(const point& a, const point& b)
{
   if (a.x <= b.x && b.x <= a.y) return 0;
   if (a.x <= b.y && b.y <= a.y) return 0;
   if (b.x <= a.x && a.x <= b.y) return 0;
   if (b.x <= a.y && a.y <= b.y) return 0;
   if (a.y < b.x) return b.x - a.y;
   return a.x - b.y;
}



int n, m;
int mx = 0;
vector<point> a, b;


void bsearch(const point& x)
{
   int mid, lo = 0, hi = m - 1, p =0;
   point k;
   while(lo <= hi)
   {
      mid = (lo + hi) / 2;
      k = b[mid];
      p = dist(x, k);
      mx = max(p, mx);
      lo = mid + 1;
   }

   lo = 0, hi = m - 1;
   while (lo <= hi)
   {
      mid = (lo + hi) / 2;
      k = b[mid];
      p = dist(x, k);
      mx = max(p, mx);
      hi = mid - 1;
   }
}


int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

   point k;

   cin >> n;
   for(int i = 0; i< n; ++i)
   {
      cin >> k.x >> k.y;
      a.push_back(k);
   }

   cin >> m;
   for(int i = 0; i < m; ++i)
   {
      cin >> k.x >> k.y;
      b.push_back(k);
   }

   sort(a.begin(), a.end(), compare);
   sort(b.begin(), b.end(), compareb);

   for (int i = 0; i < n; ++i) bsearch(a[i]);


   sort(a.begin(), a.end(), compareb);
   sort(b.begin(), b.end(), compare);

   for (int i = 0; i < n; ++i) bsearch(a[i]);



   cout << mx;

   return 0;
}<file_sep>// https://codeforces.com/contest/749/problem/C
// https://codeforces.com/contest/749/submission/23153097

#include<string>
#include<iostream>
using namespace std;


int main()
{
   int n;
   string s;
   cin >> n >> s;
   string p;
   int D = 0;
   int R = 0;
   string q;
   while (s.size() != 1)
   {
      n = s.size();
      p = "";
      for (int i = 0; i < n; ++i)
      {
         if (s[i] == 'D')
         {
            if (D == 0) R--, p += 'D';
            else D++;
         }
         else
         {
            if (R == 0) D--, p += 'R';
            else R++;
         }
      }
      if (s == p) break;
      s = p;

   }

   cout << s[0];

   return 0;
}<file_sep>// https://codeforces.com/gym/100810/problem/H
// https://codeforces.com/gym/100810/submission/18206141


#include <iostream>
#include <vector>
#include <string>
#include <string.h>
#include <cmath>
#include <algorithm>
using namespace std;

typedef struct _TEAM {
	string name;
	int gD = 0, gP = 0, index, w = 0, d = 0, l = 0;
	_TEAM(const string& nume, const int& index) :name{ nume }, index{ index } { 
		gD = 0, gP = 0, w = 0, d = 0, l = 0;
	};
}TEAM;

vector<TEAM> tournament;
string results[100][100];

int cautaEchipa(const string& teamName) {
	for (size_t i = 0; i < tournament.size(); ++i) {
		if (tournament[i].name == teamName) return i;
	}
	return -1;
}

void initEchipe(int nrEchipe) {
	for (int i = 0; i <= nrEchipe; i++) {
		for (int j = 0; j <= nrEchipe; j++) {
			results[i][j] = "";
		}
	}
}

int getLen(int numar) {
	int nr = 0;
	if (numar == 0) return 1;
	for (; numar > 0; numar /= 10, nr++);
	return nr;
}

int main() {

	int nrEchipe = -1, meciuri, pozA, pozB;
	string echipa, teamA, teamB, score, del;
	int maxTeamName, maxime[10];

	for (cin >> nrEchipe; nrEchipe != 0; cin >> nrEchipe) {

		maxTeamName = -1;
		tournament.clear();
		del = "+";
		initEchipe(nrEchipe);
		memset(maxime, 0, 10 * sizeof(int));

		for (int i = 1; i <= nrEchipe; i++) {
			cin >> echipa;
			if ((int)echipa.size() > maxTeamName) maxTeamName = (int)echipa.size();
			tournament.push_back(TEAM{ echipa,i });
		}

		echipa = "|";
		for (int i = 1; i <= maxTeamName; ++i) del += "-", echipa+=" ";
		del += "+";
		for (int i = 1; i <= nrEchipe; ++i) del += "---+";

		results[0][0] = echipa;

		for (int i = 0; i < nrEchipe; ++i) {
			echipa = "|"; teamA = "|";
			if (tournament[i].name.size() == 1) echipa = echipa + tournament[i].name + "  ";
			else if (tournament[i].name.size() == 2) echipa = echipa + tournament[i].name + " ";
			else echipa = echipa + tournament[i].name.substr(0, 3);
			if (i + 1 == nrEchipe) echipa += "|";

			teamA += tournament[i].name;
			for (int k = (int)tournament[i].name.size(); k < maxTeamName; k++) teamA += " ";
			teamA += "|";
			results[0][i+1] = echipa;
			results[i + 1][0] = teamA;
		}

		cin >> meciuri;


		for (int i = 1; i <= meciuri; ++i) {
			cin >> teamA >> teamB >> teamB >> score;
			pozA = cautaEchipa(teamA);
			pozB = cautaEchipa(teamB);
			
			results[pozA + 1][pozB + 1] = score;

			tournament[pozA].gD += score[0] - 48;
			tournament[pozA].gP += score[2] - 48;
			tournament[pozB].gD += score[2] - 48;
			tournament[pozB].gP += score[0] - 48;

			if (score[0] > score[2]) {
				tournament[pozA].w++;
				tournament[pozB].l++;
			}
			else if (score[0] < score[2]) {
				tournament[pozA].l++;
				tournament[pozB].w++;
			}
			else {
				tournament[pozA].d++;
				tournament[pozB].d++;
			}
		}

		cout << "RESULTS:\n" << del << "\n";
		for (int i = 0; i <= nrEchipe; i++) {
			for (int j = 0; j <= nrEchipe; j++) {
				if (i != 0 && j != 0) {
					if (i == j) cout << " X |";
					else if (results[i][j] == "") cout << "   |";
					else cout << results[i][j]<<"|";
				}
				else { cout << results[i][j]; }
			}
			cout << "\n"<<del << "\n";;
		}
		cout <<"\nSTANDINGS:\n----------\n";
		sort(tournament.begin(), tournament.end(), [&](const TEAM& teamA, const TEAM& teamB) {
			if (teamA.w * 3 + teamA.d != teamB.w * 3 + teamB.d) return (teamA.w * 3 + teamA.d > teamB.w * 3 + teamB.d);
			if (teamA.gD - teamA.gP != teamB.gD - teamB.gP) return (teamA.gD - teamA.gP > teamB.gD - teamB.gP);
			if (teamA.gD != teamB.gD) return (teamA.gD > teamB.gD);
			if (teamA.w != teamB.w) return (teamA.w > teamB.w);
			return (teamA.index > teamB.index);
		});

		for (int i = 0; i < nrEchipe; i++) {
			maxime[0] = max(maxime[0], getLen(tournament[i].w + tournament[i].d + tournament[i].l));
			maxime[1] = max(maxime[1], getLen(tournament[i].w));
			maxime[2] = max(maxime[2], getLen(tournament[i].d));
			maxime[3] = max(maxime[3], getLen(tournament[i].l));
			maxime[4] = max(maxime[4], getLen(tournament[i].gD) + getLen(tournament[i].gP) + 1);
			maxime[5] = max(maxime[5], getLen(tournament[i].w * 3 + tournament[i].d));
		}
		
		for (int i = 0; i < nrEchipe; i++) {
			if (nrEchipe >= 10 && i < 9) cout << " ";
			cout << i + 1 << ". ";
			echipa = tournament[i].name;
			for (int k = tournament[i].name.size(); k < maxTeamName; k++)echipa += " ";
			cout << echipa<<" ";

			teamA = "";
			echipa = to_string(tournament[i].w + tournament[i].d + tournament[i].l);
			for (int k = echipa.size(); k < maxime[0]; k++) teamA += " ";
			teamA += echipa;
			cout << teamA << " ";

			teamA = "";
			echipa = to_string(tournament[i].w);
			for (int k = echipa.size(); k < maxime[1]; k++) teamA += " ";
			teamA += echipa;
			cout << teamA << " ";

			teamA = "";
			echipa = to_string(tournament[i].d);
			for (int k = echipa.size(); k < maxime[2]; k++) teamA += " ";
			teamA += echipa;
			cout << teamA << " ";


			teamA = "";
			echipa = to_string(tournament[i].l);
			for (int k = echipa.size(); k < maxime[3]; k++) teamA += " ";
			teamA += echipa;
			cout << teamA << " ";

			teamA = "";
			echipa = to_string(tournament[i].gD) + ":" + to_string(tournament[i].gP);
			for (int k = echipa.size(); k < maxime[4]; k++) teamA += " ";
			teamA += echipa;
			cout << teamA << " ";

			teamA = "";
			echipa = to_string(tournament[i].w * 3 + tournament[i].d);
			for (int k = echipa.size(); k < maxime[5]; k++) teamA += " ";
			teamA += echipa;
			cout << teamA << "\n";
		}

		cout << "\n";

	}

	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/1/problem/A
# https://codeforces.com/contest/1/submission/13419183

n,m,a=map(int,input().split())
nr1=int(n/a)
if (int(n%a)>0):
    nr1+=1
nr2=int(m/a)
if (int(m%a)>0):
    nr2+=1
print(nr1*nr2)
<file_sep>// https://codeforces.com/contest/745/problem/B
// https://codeforces.com/contest/745/submission/23059000

#include <iostream>
#include <string>
using namespace std;


int main()
{
   string s, cmp;
   int n, m;
   cin >> n >> m >> s;
   bool ok = true;
   bool x = false;
   while (--n)
   {
      cin >> cmp;
      if (s == cmp) goto peste;
      if (s.find('X') == string::npos && cmp.find('X') != string::npos) goto peste;
      if (s.find('X') != string::npos && cmp.find('X') == string::npos) goto peste;
      ok = false;
      peste:
         s = cmp;
   }
   (ok) ? puts("YES") : puts("NO");
   return 0;
}<file_sep>// https://codeforces.com/contest/580/problem/C
// https://codeforces.com/contest/580/submission/46924788

#include <map>
#include <vector>
#include <iostream>
using namespace std;

int dfs(map<int, vector<int>>& graph, int maxCats, int currentNode, int currentCats, vector<bool>& cats, vector<bool>& visited)
{
    (cats[currentNode]) ? currentCats++ : currentCats = 0;
    visited[currentNode] = true;

    if (currentCats > maxCats) return 0;
    
    int res = 0;
    bool leaf = true;
    for (auto& neighbour : graph[currentNode])
    {
        if (visited[neighbour]) continue;
        leaf = false;
        res += dfs(graph, maxCats, neighbour, currentCats, cats, visited);
        visited[neighbour] = false;
    }
    
    if (leaf) return 1;
    return res;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    
    int n, m, x, y;
    cin >> n >> m;

    map<int, vector<int>> graph;
    vector<bool> cats(n + 1, false);
    vector<bool> visited(n + 1, false);
    for (int i = 1; i <= n; ++i)
    {
        cin >> x;
        cats[i] = (x == 1);
    }

    for (int i = 0; i < n - 1; ++i)
    {
        cin >> x >> y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }

    cout << dfs(graph, m, 1, 0, cats, visited);
    return 0;
}<file_sep>// https://codeforces.com/contest/573/problem/A
// https://codeforces.com/contest/573/submission/17470800

#include <iostream>
using namespace std;


int main() {
	int a, n, rez;
	cin >> n >> a;
	for (; a % 2 == 0; a /= 2);
	for (; a % 3 == 0; a /= 3);
	rez = a;
	for (; n-1 > 0; n--) {
		cin >> a;
		for (; a % 2 == 0; a /= 2);
		for (; a % 3 == 0; a /= 3);
		if (a != rez) { puts("NO"); return 0; }
	}
	puts("YES");

	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/577/problem/A
# https://codeforces.com/contest/577/submission/14450756

n,k = map(int,input().split())
contor = 0
for i in range(1,n+1):
    if (k%i==0)and(k//i<=n):
        contor+=1
print(contor)
<file_sep># https://codeforces.com/contest/281/problem/A
# https://codeforces.com/contest/281/submission/13419952

s=input()
print(s[0].capitalize(),s[1:len(s)],sep='')
<file_sep>// https://codeforces.com/contest/746/problem/B
// https://codeforces.com/contest/746/submission/23086002

#include <string>
#include <iostream>
using namespace std;


int main()
{
   int sz;
   string s;
   int ct = 0;
   cin >> sz >> s;
   string p;
   while (sz--)
   {
      if (sz & 1) p = s[0] + p;
      else p = p + s[0];
      s = s.substr(1, s.size() - 1);
   }
   cout << p;
   return 0;
}<file_sep>// https://codeforces.com/contest/835/problem/B
// https://codeforces.com/contest/835/submission/29156583

// Example program
#include <stdio.h>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

int v[10];

int main()
{
    int k,  s = 0, res = 0, pk = 0;
    cin >> k;
    getchar();
    
    
    for(char c = getchar(); c!='\n'; c = getchar())
    {
        v[c-'0']++;
        s += (c-'0');
    }

    res = max(0, k - s);
    for (int i = 0; i < 10 && res ;++i)
    {
        if(!v[i])continue;
        k = (9 - i) * v[i];
        if (k - res >= 0)
        {
            pk += (res / (9-i) + (res %(9-i) !=0));
            res = 0;
        }
        else
        {
            res -= k;
            pk += v[i];
        }
    }
    cout<<pk;
    
    return 0;    
}
<file_sep>// https://codeforces.com/contest/752/problem/A
// https://codeforces.com/contest/752/submission/23309643

#include <iostream>
#include <stdio.h>
using namespace std;


int main()
{
   int n, m, k, lanes, desks;
   char c;
   scanf("%d %d %d", &n, &m, &k);
   
   c = (k & 1) ? 'L' : 'R';
   lanes = k / (2 * m ) + 1;
   if (k % (2 * m) == 0) lanes--;
   k = k - (lanes - 1) * (2 * m);
   desks = (k - 1) / 2 + 1;

   printf("%d %d %c\n", lanes, desks, c);

   return 0;
}<file_sep># https://codeforces.com/contest/41/problem/A
# https://codeforces.com/contest/41/submission/13583435

def is_correct(s,t):
    if len(s) != len(t):
        return 'NO'
    for i in range(len(s)):
        if s[i] != t[len(t)-1-i]:
            return 'NO'
    return 'YES'
s=input()
t=input()
print(is_correct(s,t))
<file_sep># https://codeforces.com/contest/200/problem/B
# https://codeforces.com/contest/200/submission/14572603

n = int(input())
s = sum(list(map(int,input().split())))
print("%.12f" %float(s/n))
<file_sep>// https://codeforces.com/contest/670/problem/A
// https://codeforces.com/contest/670/submission/30912901

#include <iostream>
#include <algorithm>
using namespace std;

inline int GetMin(const int& n)
{
	switch (n % 7)
	{
	case 6:  return (n / 7) * 2 + 1;
	default: return (n / 7) * 2;
	}
}

inline int GetMax(const int& n)
{
	switch (n % 7)
	{
	case 0:  return (n / 7) * 2;
	case 1:  return (n / 7) * 2 + 1;
	default: return (n / 7) * 2 + 2;
	}
}

int main()
{
	int n = 0;
	
	cin >> n;
	cout << GetMin(n) << " " << GetMax(n);
	return 0;
}<file_sep>// https://codeforces.com/contest/538/problem/B
// https://codeforces.com/contest/538/submission/17462106

#include <iostream>
using namespace std;

int main() {

	int n, v[10], max = 0;
	bool ok;
	memset(v, 0, 10 * sizeof(int));
	cin >> n;
	for (int i = 1; n != 0; n /= 10, ++i) {
		v[i] = n % 10; if (v[i] > max) max = v[i];
	}
	cout << max << endl;
	for (int i = 1; i <= max; i++) {
		ok = false;
		for (int j = 9; j > 0; j--) {
			if (v[j] != 0) ok = true, putchar('1'), v[j]--;
			else if (v[j] == 0 && ok) putchar('0');
		}
		putchar(' ');
	}

	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/58/problem/A
# https://codeforces.com/contest/58/submission/13420486

s=input()
h=s.find('h')
e=s.find('e',h)
l1=s.find('l',e)
l2=s.find('l',l1+1)
o=s.find('o',l2)
if (h<e and e<l1 and l1<l2 and l2<o):
    print("YES")
else:
    print("NO")
<file_sep>// https://codeforces.com/problemset/problem/1207/A
// https://codeforces.com/contest/1207/submission/67692150

#include <iostream>
#include <algorithm>
using namespace std;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int query;
    cin >> query;

    while (query--)
    {
        int buns, beefs, chickens, priceBeef, priceChicken;
        cin >> buns >> beefs >> chickens >> priceBeef >> priceChicken;

        int profit = 0;
        
        if (priceBeef < priceChicken)
        {
            swap(priceBeef, priceChicken);
            swap(beefs, chickens);
        }

        auto hamburgers = min(buns / 2, beefs);
        profit += (hamburgers * priceBeef);
        buns -= (hamburgers * 2);

        hamburgers = min(buns / 2, chickens);
        profit += (hamburgers * priceChicken);

        cout << profit << endl;
    }

    return 0;
}<file_sep>// https://codeforces.com/contest/501/problem/A
// https://codeforces.com/contest/501/submission/16639055

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int a, b, c, d, m1, m2;
	cin >> a >> b >> c >> d;
	m1 = max(3 * a / 10, a - a / 250 * c);
	m2 = max(3 * b / 10, b - b / 250 * d);
	if (m1 > m2) cout << "Misha";
	else if (m1 == m2) cout << "Tie";
	else cout << "Vasya";
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/525/problem/A
// https://codeforces.com/contest/525/submission/17557255

#include <iostream>
#include <string>
using namespace std;


int main() {

	string s; 
	int n, ABC[27], nr, i;
	memset(ABC, 0, 27 * sizeof(int));
	cin >> n >> s;
	for (i = 0, nr = 0; i < s.size(); i++){
		if (i & 1) {
			if (ABC[s[i] - 'A']) ABC[s[i] - 'A'] -- ;
			else nr++;
		}
		else ABC[s[i] - 'a'] ++;
	}
	cout << nr;


	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/516/problem/A
// https://codeforces.com/contest/516/submission/17291786

#include <iostream>
#include <string>
#include <algorithm>

void ptchar(std::string& s)
{
	char x = getchar();
	if (x == '2' || x == '3' || x == '5' || x == '7') s+=x;
	else if (x == '4') s += "322"; 
	else if (x == '6') s += "53";
	else if (x == '8') s += "2227";
	else if (x == '9') s += "3327"; 
}

int main()
{
	int n;
	std::string s;
	
	std::cin >> n;
	getchar();
	for (; n > 0; n--) ptchar(s);
	std::sort(s.begin(), s.end(), [](const char l, const char r) {return (r < l); });
	std::cout << s;
	return EXIT_SUCCESS;
}

<file_sep>// https://codeforces.com/contest/567/problem/B
// https://codeforces.com/contest/567/submission/17567475

#include <iostream>
using namespace std;


int main() {

	int n, max = 0, curr = 0, numb;
	char x, v[1000001];
	memset(v, '0', 1000001 * sizeof(char));

	cin >> n;
	for (; n > 0; n--) {
		getchar();
		x = getchar();
		cin >> numb;
		if (x == '+') {
			curr++;
			v[numb] = '1';
		}
		else {
			if (v[numb] == '0') max++;
			else curr--, v[numb] = '0';
		}
		if (curr > max) max = curr;
	} 
	cout << max;
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/problemset/problem/1220/A
// https://codeforces.com/contest/1220/submission/67693181

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    string s;
    int z, n;
    
    cin >> z >> s;

    z = 0; n = 0;
    for (const auto& c : s)
    {
        if (c == 'z') z++;
        else if (c == 'n') n++;
    }
    while (n--) cout << "1 ";
    while (z--) cout << "0 ";

    return 0;
}<file_sep>// https://codeforces.com/contest/735/problem/C
// https://codeforces.com/contest/735/submission/22543505

#include<iostream>

using namespace std;

int main() {

   unsigned long long F0, F1;
   unsigned long long n;
   cin >> n;


   F0 = 1;
   F1 = 2;

   unsigned long long aux, nr=0;
   while (n >= F1) {
      aux = F1;
      F1 = F1+F0;
      F0 = aux;
      nr++;
   }
   cout << nr;



}<file_sep># https://codeforces.com/contest/271/problem/A
# https://codeforces.com/contest/271/submission/13478547

def read():

    """
     Read an integer n.
     @restrictions: 1000<=n<=9000
     @output: n - the year number
    """

    return(int(input()))
def distinct_digits(n):

    """
     Check if a number (n) has only distincts digits.
     @input: n - an integer
     @output: True - if n has only distincts digits
              False - otherwise
    """

    v=[] # A list of digits frequency

    #initialize list with 0
    for i in range(10):
        v.append(0)

    ok=True # we assume that n has only distincts digits

    while (n>0 and ok==True):
        v[n%10]+=1
        if v[n%10]>1:
            ok=False
        else:
            n=n//10
    return ok

def find(n):

    """
     Find the smallest value that is strictly larger than n and all it's digits are distincts
     @input: n - a given integer
     @output: the value that we search for
     @restrictions: it is guaranteed that the answer exists
    """

    n+=1
    while distinct_digits(n)!=True:
        n+=1
    return n
    
    
n=read()
print(find(n))
<file_sep># https://codeforces.com/contest/119/problem/A
# https://codeforces.com/contest/119/submission/13478295

def read():

    """
     Read three integers: a,b,n.
     @restrictions: 1<=a,b,n<=100
     @output: a - number that Simon receives
              b - number that Antisimon receives
              n - the number of stones in heap at start.
    """
    
    a,b,n=map(int, input().split())
    return a,b,n
def gcd(x,y):

    """
     Calculate the greatest common divisor of x and y using Euclid's algorithm.
     @input: x,y
     @output: greatest common divisor of x and y.
    """

    while y!=0:
        r=y
        y=x%y
        x=r
    return x

def play(a,b,n):

    """
     The steps of playing the game.
     @input: a - number that Simon receives
             b - number that Antisimon receives
             n - the number of stones in heap at start.
     @output: 0 - if Simon wins
              1 - if Antisimon wins
    """

    #tour variable can have 2 values: 1 if it's Simon turns or -1 if it's Antisimon's
    
    tour=1
    while n>0:
        if tour == 1:
            k=a
        else:
            k=b
        n=n-gcd(k,n)
        tour=-tour
    if tour==1:
        return 1
    else:
        return 0

a,b,n=read()
print(play(a,b,n))
<file_sep>// https://codeforces.com/contest/474/problem/B
// https://codeforces.com/contest/474/submission/15134437

#include <iostream>
using namespace std;

struct entity
{
    int first_in_pile,last_in_pile;
};

entity piles[100001];

int search_bin(int lo, int hi, int x)
{
    int mid = (lo+hi) / 2;
    while (lo <= hi)
    {
        if (piles[mid].first_in_pile > x) hi = mid - 1;
        else if (piles[mid].last_in_pile < x) lo = mid + 1;
        else return mid;
        mid = (lo + hi) / 2;
    }
}

int main()
{
    int m,x,n,worms = 0;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> x;
        piles[i].first_in_pile = worms + 1;
        piles[i].last_in_pile = worms + x;
        worms += x;

    }
    cin >> m;
    for (int i = 1; i <= m; i++)
    {
        cin >> x;
        cout << search_bin(1,n,x)<<"\n";
    }
    return 0;
}
<file_sep># https://codeforces.com/contest/4/problem/A
# https://codeforces.com/contest/4/submission/13404456

w=input()
if (int(w)%2==1 or int(w)==2):
    print("NO")
else:
    print("YES")
<file_sep>// https://codeforces.com/contest/20/problem/C
// https://codeforces.com/contest/20/submission/48035394
#include <map>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;

void BellmanFord(int Edges, map<int, vector<pair<int, int>>> & Graph, int Source, vector<long long>& Distance, vector<int>& Parent)
{
    priority_queue<int> q;

    Distance = vector<long long>(Edges + 1, std::numeric_limits<long long>::max());
    Parent = vector<int>(Edges + 1, 0);

    q.push(Source);
    Distance[Source] = 0;

    while (!q.empty())
    {
        auto current = q.top(); 
        q.pop();

        for (const auto& keyValuePair : Graph[current])
        {
            auto target = keyValuePair.first;
            auto weight = keyValuePair.second;

            if (Distance[current] + weight < Distance[target])
            {
                Parent[target] = current;
                Distance[target] = Distance[current] + weight;
                q.push(target);
            }
        }
    }
}

void PrintPath(vector<int>& Parent, int index)
{
    if (index == 0) return;
    PrintPath(Parent, Parent[index]);
    printf("%d ", index);
}


int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, m, x, y, w;

    cin >> n >> m;
    map<int, vector<pair<int, int>>> graph;
    vector<long long> distance;
    vector<int> parent;

    for (int i = 1; i <= m; ++i)
    {
        cin >> x >> y >> w;

        graph[x].push_back({ y,w });
        graph[y].push_back({ x,w });
    }

    BellmanFord(n, graph, 1, distance, parent);

    if (distance[n] == numeric_limits<long long>::max())
    {
        cout << "-1\n";
    }
    else
    {
        PrintPath(parent, n);
    }

    return 0;

}<file_sep># https://codeforces.com/contest/266/problem/A
# https://codeforces.com/contest/266/submission/13408006

n=int(input())
s=input()
nr=0
for i in range(1,len(s)):
    if s[i]==s[i-1]:
        nr+=1
print(nr)
<file_sep># https://codeforces.com/contest/337/problem/A
# https://codeforces.com/contest/337/submission/13961119

n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
mins=1000
for i in range(0,len(l)-n+1):
    if l[i+n-1]-l[i]<mins:
        mins=l[i+n-1]-l[i]
print(mins)
<file_sep>// https://codeforces.com/contest/679/problem/A
// https://codeforces.com/contest/679/submission/18453358

#include <iostream>
#include <string>
using namespace std;


int main() {

	int lst[] = { 2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71 };
	int i, cnt = 0, nr, tmp = 0;
	string s;
	for (i = 1; i <= 20; i++) {
		cout << lst[i - 1] << "\n";
		fflush(stdout);
		cin >> s;
		fflush(stdin);
		if (s == "yes") nr = lst[i - 1], cnt++;
		if (cnt > 0) break;
	}
	for (; i < 20; i++) {
		(nr*lst[i - 1] <= 100) ? cout << nr*lst[i - 1] << "\n" : cout << lst[i] << " ";
		fflush(stdout);
		cin >> s;
		fflush(stdin);
		if (s == "yes") cnt++;
		if (cnt > 1) break;
	}

	fflush(stdout);
	(cnt > 1) ? puts("composite") : puts("prime");


	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/789/problem/B
// https://codeforces.com/contest/789/submission/25930709

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long 
#define ull unsigned long long

/*------------------------------------------------------------------*/
 
unordered_map < long long , bool > in;
long long b1, q, l, m, x;

int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
   cin >> b1 >> q >> l >> m;
   for(int i = 1; i<=m; ++i)
   {
      cin >> x;
      in[x] = true;
   }

   long long  cnt = 0;
   long long last = b1;

   while (b1 != 0 && abs(b1) <= l)
   {
      if (in.find(b1) == in.end()) cnt++;
      b1 *= q;
      if (abs(b1) == last || b1 == last) break;
      last = b1;
   } 

   if(b1 == 0 )
   {
      if (in.find(b1) == in.end()) cnt = -1;
   }
   else if ( (abs(b1) == last || b1 == last) && abs(b1) <= l)
   {
      if (in.find(b1) == in.end()) cnt = -1;
      if (q == -1)
      {
         if (in.find(b1) == in.end() || in.find(-b1) == in.end()) cnt = -1;
      }
   }

   if (cnt == -1)cout << "inf\n";
   else cout << cnt;

   return 0;
}<file_sep>// https://codeforces.com/gym/100810/problem/G
// https://codeforces.com/gym/100810/submission/18255909

#include <iostream>
#include <vector>
#include <map>
using namespace std;

map<int, vector<int>> frecv;
int cd[200005], ord[200005];

int main() {
	int poz, max, n, m, x;
	bool ok;

	for (cin >> n >> m; n != 0 && m != 0; cin >> n >> m) {

		ok = true;
		frecv.clear();
		for (int i = 0; i <= 200002; i++) cd[i] = -1, ord[i] = -1;
		for (int i = 1; i <= n; i++) {
			cin >> x;
			poz = -1; 
			max = -1;
			for (int j = 1; j <= m; j++) {
				if (cd[j] <= x && cd[j] >= max) {
					max = cd[j];
					poz = j;
				}
			}
			if (poz == -1) ok = false;
			else {
				cd[poz] = x;
				frecv[x].push_back(poz);
			}
			ord[i] = poz;
		}
		if (!ok) cout << "Transportation failed\n";
		else {
			for (int i = 1; i <= n; i++) {
				cout << ord[i]<<" ";
			}
			cout << "\n";
			for (auto it = frecv.begin(); it != frecv.end(); it++) {
				for (int j = 0; j < (int)it->second.size(); j++) {
					cout << it->second[j]<< " ";
				}
			}
			cout << "\n";
		}

	}

	return 0;
}<file_sep>// https://codeforces.com/contest/705/problem/A
// https://codeforces.com/contest/705/submission/21340464

#include <stdio.h>
#include <stdlib.h>

int main()
{
   int n, i = 0;

   scanf("%d", &n);

   for (i = 1; i < n; ++i)
   {
      (i % 2 == 0) ? printf("I love that ") : printf("I hate that ");
   }

   (n % 2 == 0) ? printf("I love it") : printf("I hate it");

   return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/146/problem/A
// https://codeforces.com/contest/146/submission/17291944

#include <iostream>
#include <string>

int main() {

	int n, s1 = 0, s2 = 0;
	std::string nm;
	std::cin >> n >> nm;
	for (int i = 0; i < n / 2; i++)
	{
		if (nm[i] != '4' && nm[i] != '7' || nm[n - i - 1] != '4' && nm[n - i - 1] != '7') { std::cout << "NO"; goto EXIT; }
		else { s1 += nm[i] - '0'; s2 += nm[n - i - 1] - '0';}
	}
	if (s1 != s2) std::cout << "NO";
	else std::cout << "YES";

EXIT:
	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/118/problem/B
# https://codeforces.com/contest/118/submission/14544078

n = int(input())
k = n
for i in range(1,n+n+2):
    for j in range(1,k+1):
        print(' ',end=' ')
    for j in range(n-k+1):
        if n-k==0:
            print(j,sep=' ',end='')
        else:
            print(j,sep=' ',end=' ')
    for j in range(n-k):
        if j==n-k-1:
            print(n-k-j-1,sep=' ',end='')
        else:
            print(n-k-j-1,sep=' ',end=' ')
    if i<=n:
        k-=1
    else:
        k+=1
    print()
<file_sep>// https://codeforces.com/contest/733/problem/A
// https://codeforces.com/contest/733/submission/22040766

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <vector>
#include <string>
#include <iostream>
using namespace std;


#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define ABS(a)   (((a) > 0)   ? (a) : (-(a)))

bool is_vowel(const char& c)
{
   return(c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' || c == 'Y');
}

int main()
{

   string s;
   int start = -1;
   unsigned int ability = 0;

   cin >> s;
   size_t size = s.size();
   for (size_t i = 0; i < size; ++i)
   {
      if (is_vowel(s[i]))
      {
         ability = MAX(ability, i - start);
         start = i;
      }
   }

   ability = MAX(ability, size - start);

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

   return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/263/problem/A
# https://codeforces.com/contest/263/submission/13580409

for i in range(5):
    x=list(map(int, input().split()))
    for j in range(5):
        if x[j]==1:
            ax,ay=i+1,j+1
    x.clear()
print(abs(3-ax)+abs(3-ay))
<file_sep>// https://codeforces.com/contest/675/problem/D
// https://codeforces.com/contest/675/submission/47971947

#include <iostream>
#include <map>
#include <set>
#include <algorithm>
using namespace std;


int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    map<int, int> kinder;
    set<int> bst;

    int n, x;
    cin >> n >> x;

    bst.insert(x);
    for (int i = 1; i < n; ++i)
    {
        cin >> x;

        auto smaller = --bst.lower_bound(x);
        int parent = 0;

        if (smaller != bst.end())
        {
            if (kinder[*smaller] != 0) smaller = bst.upper_bound(*smaller);
            parent = *smaller;
        }
        else
        {
            parent = *bst.upper_bound(x);
        }

        if (parent <= x) kinder[parent] = x;
        bst.insert(x);

        cout << parent << " ";
    }


    return 0;
}<file_sep># https://codeforces.com/contest/472/problem/A
# https://codeforces.com/contest/472/submission/13580206

n = int(input())
from math import sqrt
def e_prim(k):

    if k==1:
        return False
    for d in range(2,int(sqrt(n))+1):
        if k%d==0:
            return False
    return True
if n % 2 == 0:
    print(n-4, 4)
else:
    k=4
    while e_prim(n-k) == True:
        k=k+2
    print(k, n-k)
    
    
<file_sep>// https://www.spoj.com/problems/FARIDA/

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long 
#define ull unsigned long long

/*------------------------------------------------------------------*/

ull sol[10009], ptc[10009];

int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

   int n, t;
   cin >> t;
   for(int j = 1; j<=t; ++j){
      cin >> n;
      for (int i = 1; i <= n; ++i)cin >> ptc[i];
      sol[1] = ptc[1];
      for (int i = 2; i <= n; ++i) sol[i] = max(sol[i - 2] + ptc[i], sol[i - 1]);
      cout <<"Case "<< j<<": "<< sol[n]<<"\n";
   }

   return 0;
}<file_sep>// https://codeforces.com/contest/278/problem/A
// https://codeforces.com/contest/278/submission/17335998

#include <iostream>
#include <algorithm>

void swap(int&x, int&y)
{
	int aux;
	aux = x;
	x = y;
	y = aux;
}

int main()
{
	int n, v[105], x, y;
	v[1] = v[0] = 0;
	std::cin >> n;
	for (int i = 2; i <= n + 1; i++)
	{
		std::cin >> x;
		v[i] = v[i - 1] + x;
	}
	std::cin >> x >> y;
	if (x > y) swap(x, y);
	std::cout << std::min(v[y] - v[x], v[x] + v[n + 1] - v[y]);

    return EXIT_SUCCESS;
}

<file_sep>// https://codeforces.com/contest/630/problem/J
// https://codeforces.com/contest/630/submission/17323407

#include <iostream>


int main()
{
	unsigned long long n;
	std::cin >> n;
	std::cout << n / 2520;

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/754/problem/A
// https://codeforces.com/contest/754/submission/24060119

#include <iostream>
#include <vector>
using namespace std;



int main() {

   int v[105], n;
   vector<pair<int, int>>res;

   cin >> n;
   for (int i = 1; i <= n; ++i) cin >> v[i];

   int zer = 1;
   int st = 1;

   while (v[zer] == 0) zer++;

   while (zer <= n)
   {
      int end = zer;
      for (int i = zer + 1; i <= n && v[i] == 0; end = i, ++i);
      res.push_back(make_pair(st, end));
      st = zer = ++end;
   }

   if (res.size() == 0) cout << "NO";
   else
   {
      cout << "YES\n" << res.size() << "\n";
      for (auto e : res) cout << e.first << " " <<e.second <<"\n";
   }

   return 0;
}<file_sep>// https://codeforces.com/contest/363/problem/B
// https://codeforces.com/contest/363/submission/46625690

/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, k, x;
    long long min = 0;
    int idx = 0;
    vector<long long> v;
    vector<long long> qp;
    
    cin >> n >> k;
    for(int i = 0; i < n; ++i) 
    {
        cin >> x;
        v.push_back(x);
        qp.push_back(x);
    }
    
    for(int i = 1; i < k; ++i)
    {
        qp[i] += qp[i-1];
    }
    
    min = qp[k-1];
    for(int i = k; i < n; ++i)
    {
        qp[i] = qp[i] + qp[i-1] - v[i-k];
        if(qp[i] < min)
        {
            min = qp[i];
            idx = i - k + 1;
        }
    }

    cout << idx + 1;    
    
    return 0;
}<file_sep>// https://codeforces.com/contest/787/problem/A
// https://codeforces.com/contest/787/submission/25738084

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long 
#define ull unsigned long long

/*------------------------------------------------------------------*/
 
int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

   int a, b, c, d;
   cin >> a >> b >> c >> d;
   unordered_map<int, int> mp;
   int ans = -1;

   for(int i = 0; i<= 50000; ++i)
   {
      mp[b + a * i] = 1;
   }

   for(int i = 0; i<=50000; ++i)
   {
      if(mp.find(d + i * c) != mp.end())
      {
         ans = d + i * c;
         break;

      }
   }


   cout << ans;
   return 0;
}<file_sep>// https://codeforces.com/contest/606/problem/B
// https://codeforces.com/contest/606/submission/17916859

#include <iostream>
#include <string>
using namespace std;



int main() {
	int n, m, x, y, sm = 1, i;
	int mat[505][505];
	memset(mat, 0, 505 * 505 * sizeof(int));
	
	string s;
	cin >> n >> m >> x >> y >> s;
	mat[x][y] = 1;
	cout << "1 ";
	for (i = 0; i < (int)s.size() - 1; ++i) {
		if (s[i] == 'D') {
			x++;
			if (mat[x][y] == 0) {
				if (x > n) cout << "0 ", x--;
				else cout << "1 ", sm++, mat[x][y] = 1;
			}
			else {
				cout << "0 ";
			}
		}
		if (s[i] == 'U') {
			x--;
			if (mat[x][y] == 0) {
				if (x < 1) cout << "0 ", x++;
				else cout << "1 ", sm++, mat[x][y] = 1;
			}
			else {
				cout << "0 ";
			}
		}
		if (s[i] == 'R') {
			y++;
			if (mat[x][y] == 0) {
				if (y > m) cout << "0 ", y--;
				else cout << "1 ", sm++, mat[x][y] = 1;
			}
			else {
				cout << "0 ";
			}
		}
		if (s[i] == 'L') {
			y--;
			if (mat[x][y] == 0) {
				if (y < 1) cout << "0 ", y++;
				else cout << "1 ", sm++, mat[x][y] = 1;
			}
			else {
				cout << "0 ";
			}
		}
	}
	cout << m*n - sm;
	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/339/problem/A
# https://codeforces.com/contest/339/submission/13408149

s=input()
v=[0, 0, 0, 0]
for i in range(len(s)):
    if s[i]=="1":
        v[1]+=1
    elif s[i]=="2":
        v[2]+=1
    elif s[i]=="3":
        v[3]+=1
nr=0
i=0
for i in range(4):
    while v[i]>0:
        print(i,end='')
        nr+=1
        if nr<len(s):
            print("+",end='')
            nr+=1
        v[i]-=1
<file_sep>// https://codeforces.com/contest/719/problem/A
// https://codeforces.com/contest/719/submission/22851797

#include <iostream>
using namespace std;

int main()
{
	int n;
	int a,b;
	cin>>n;
	cin>>b;
	for(int i = 2; i<=n; ++i)
	{
		a = b;
		cin>>b;
	}
	if (b == 0) puts("UP");
	else if (b == 15) puts("DOWN");
	else if (n == 1) puts("-1");
	else if (b - a > 0) puts("UP");
	else puts("DOWN");
	return 0;
}<file_sep># https://codeforces.com/contest/379/problem/A
# https://codeforces.com/contest/379/submission/13583372

n,m = map(int,input().split())
nr = n
while n // m > 0:
    notlighted = n % m
    nr += n//m
    n = n//m + notlighted
print(nr)
<file_sep>// https://codeforces.com/contest/43/problem/A
// https://codeforces.com/contest/43/submission/18055085

#include <string>
#include <iostream>
using namespace std;


int main() {

	string read, a, ot;
	int scoreA = 0, scoreB = 0, n;
	
	cin >> n;
	cin >> a;
	scoreA++;
	for (; n > 1; n--) {
		cin >> read;
		if (a == read) scoreA++;
		else scoreB++, ot = read;
	}
	(scoreA > scoreB) ? cout<<a : cout<<ot;

	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/160/problem/A
# https://codeforces.com/contest/160/submission/13419910

n=int(input())
v=list(map(int,input().split()))
v.sort()
sum=0
for i in range(n):
    sum+=v[i]
ok="true"
i=n-1
sumax=v[i]
while (ok=="true"):
    if sumax>sum-sumax:
        ok="false"
    else:
        i-=1
        sumax+=v[i]
print(n-i)
<file_sep>// https://codeforces.com/contest/492/problem/A
// https://codeforces.com/contest/492/submission/13875822

#include <stdio.h>
#include <stdlib.h>



int main()
{
    int n,s,i;
    scanf("%d",&n);
    s = 0;
    i = 0;
    while (s<=n)
    {
        i++;
        s = s+ ((1+i)*i)/2;
    }
    printf("%d",i-1);
    return 0;
}
<file_sep>// https://codeforces.com/contest/908/problem/A
// https://codeforces.com/contest/908/submission/46923986

#include <iostream>
#include <string>
using namespace std;

inline bool ShouldFlip(char c)
{
    switch (c)
    {
    case 'a':
    case 'e':
    case 'i':
    case 'o':
    case 'u':
    case '1':
    case '3':
    case '5':
    case '7':
    case '9':
        return true;
    default:
        return false;
    }
}

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(NULL);
    string s;
    int nr = 0;
    
    cin >> s;
    for (auto& c : s)
    {
        if (ShouldFlip(c)) nr++;
    }

    cout << nr;
    return 0;
}<file_sep>#include <iostream>
#include <fstream>
#include <chrono>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>
using namespace std;

class Node
{
    friend class Trie;
public:
    Node() = default;
    ~Node()
    {
        for (auto& node : Children) delete node.second;
    }

private:
    map<char, Node*> Children;
    size_t Words = 0;
};

class Trie
{
public:
    Trie() { Root = new Node(); }
    ~Trie() { delete Root; }

    bool InsertUnique(const string& String)
    {
        auto current = Root;
        bool ok = false;
        for (auto& c : String)
        {
            if (current->Children.find(c) == current->Children.end())
            {
                current->Children[c] = new Node();
                ok = true;
            }

            current = current->Children[c];
            if (current->Words != 0)
            {
                return false;
            }
        }

        current->Words++;
        return ok;
    }

private:
    Node* Root;
};


int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);

    int t, n;
    cin >> t;

    while (t--)
    {
        cin >> n;
        Trie trie;
        string s; 
        bool ok = true;

        for (int i = 1; i <= n; ++i)
        {
            cin >> s;
            ok = ok && trie.InsertUnique(s);
        }

        (ok) ? cout << "YES\n" : cout << "NO\n";
    }

    return 0;
}<file_sep>// https://codeforces.com/contest/1006/problem/A
// https://codeforces.com/contest/1006/submission/46828520

#include <iostream>
using namespace std;


int main()
{
	ios::sync_with_stdio(false); cin.tie(NULL);

	int n, x;
	cin >> n;
	while (n--)
	{
		cin >> x;
		if ((x & 1) == 0) --x;
		cout << x << " ";
	}

	return 0;
}<file_sep>// https://codeforces.com/contest/672/problem/A
// https://codeforces.com/contest/672/submission/17927943

#include <iostream>
using namespace std;


int main() {

	int n, c, i, k;
	cin >> n;
	for (i = 1, c = 1; i < n && i <= 9; i++, c++);
	for (i = 10, k = 10; i <= n && k<=99; i += 2, k++) {
		if (i == n) c = k / 10;
		else if (i + 1 == n) c = k % 10;
	}
	for (k = 100; i <= n; i += 3, k++) {
		if (i == n) c = k / 100;
		else if (i + 1 == n) c = (k / 10) % 10;
		else if (i + 2 == n) c = k % 10;
	}
	cout << c;

	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/612/problem/A
# https://codeforces.com/contest/612/submission/15041261

def gaseste(a,b,n):
    gasit = False
    k = 0
    while k * a <= n and not gasit:
        p = 0
        while (p * b) + (k*a) <= n and not gasit:
            if (p*b)+(k*a) == n:
                gasit = True
            else:
                p+=1
        if not gasit:
            k+=1
    return (-1,-1) if not gasit else (k,p)
    
    

n,p,q = map(int,input().split())
s = input()
a,b = gaseste(p,q,n)
if (a,b) != (-1,-1):
    i = 0
    print(a+b)
    while a > 0:
        print(s[i:i+p])
        i+=p
        a -=1
    while b>0:
        print(s[i:i+q])
        i+=q
        b-=1
else:
    print(-1)
        
<file_sep># https://codeforces.com/contest/82/problem/A
# https://codeforces.com/contest/82/submission/13476587

n=int(input())
nr=5
i=1
k=1
while nr<n:
    k=k*2 + 1
    nr=5*k
    i=i*2
cont=1
while nr-i+1>n:
    nr=nr-i
    cont+=1
    
    
if cont==1:
    strn='Howard'
elif cont==2:
    strn='Rajesh'
elif cont==3:
    strn='Penny'
elif cont==4:
    strn='Leonard'
else:
    strn='Sheldon'
print(strn)

    
<file_sep>// https://www.spoj.com/problems/TEST/

#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int x;
    cin >> x;
    while(x!=42)
    {
        cout<<x <<endl;
        cin>>x;
    }
    return 0;
}
<file_sep># https://codeforces.com/contest/122/problem/A
# https://codeforces.com/contest/122/submission/13477054

def is_lucky(a):
    
    """
     Check if a given number (a) is lucky.
     @input: an integer a (1<=a<=1000)
     @output: True - if a is lucky
              False - if a is not lucky
    """

    ok=True       # We assume that a is lucky
    
    while (a>0 and ok==True):
        if (int(a%10) == 4 or int(a%10) == 7):
            a=a//10
        else:
            ok=False
    return ok

def almost_lucky(n):

    """
     Check if a given number (n) is almost lucky.
     @input: an integer n (1<=n<=1000)
     @output: True - if n is almost lucky
              False - if n is not almost lucky
    """

    # n is "almost lucky" if n is lucky
    
    if (is_lucky(n)==True): 
        ok=True
    else:
        ok=False

    #If n is not lucky, we check to to see if it is "almost lucky"

    d=2
    while (d<=n//2 and ok==False):
        if (int(n%d)==0 and is_lucky(d)==True):
            ok=True
        else:
            d+=1

    return ok

def citire():

    """
     Read an integer.
     @output: an integer n (1<=n<=1000)
    """

    return int(input())

n=citire() #read n
if (almost_lucky(n)==True):
    print("YES")
else:
    print("NO")

    
    
    
<file_sep>// https://codeforces.com/gym/101020/problem/A
// https://codeforces.com/gym/101020/submission/18653242

#include <iostream>
using namespace std;

int main() {
	long long x, y,t;
	for (cin >> t; t-- > 0; cin >> x >> y, cout << x*y << '\n');
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/581/problem/C
// https://codeforces.com/contest/581/submission/14394891

#include <iostream>
using namespace std;


int main()
{

    long long v[102],n,k,x;

	for (int i = 0; i < 101; i++) v[i] = 0;

	cin >> n >> k;
	for (int i = 0; i < n; i++)
	{
		cin >> x;
		v[x]++;
	}

	long long aux = k;

	while (k > 0)
	{
		for (int p = 1; p <= 10; p++)
		{
			for (int i = 100 - p; i >= 0; i -= 10)
			{
				while (v[i] > 0 && k - p >= 0)
				{
					v[i + p]++;
					v[i]--;
					k -= p;
				}
			} 
		}

		if (k == aux) k = 0;
		aux = k;
	}

	unsigned long long s = 0;
	for (int i = 1; i <= 100; i++)
	{
		s += ((i / 10) * v[i]);
	}
	cout << s;

	return 0;
}
#include <iostream>

using namespace std;

int a[102];

int main()
{
    int n,x;
    long long k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> x;
        a[x]++;
    }
    int poz = 100;
    long long cost =1;
    while (k > 0)
    {
        int  j = 0;
        while (j < 100 && k > 0)
        {
            if (poz-j-cost!=100 && a[poz-j-cost]!=0 ){
            if (a[poz-j-cost]*cost < k)
            {
                k-=a[poz-j-cost]*cost;
                a[poz-j]+=a[poz-j-cost];
                a[poz-j-cost]=0;
            }
            else
            {
                k = k/cost;
                a[poz-j-cost] -= k;
                a[poz-j] +=k;
                k = 0;
            }
            }
            j+=10;
        }
        if (a[100]==n){k=0;}
        if (cost<10)
        {
            cost++;
        }
    }
    cost = 0;
    for (int i=1;i<=100;i++)
    {
        cost += a[i]*(i/10);
    }
    cout<<cost;
    return 0;
}
<file_sep>// https://codeforces.com/contest/474/problem/F
// https://codeforces.com/contest/474/submission/25364936

#include <iostream>
using namespace std;

#define NMAX 100005

int gcd(int a, int b)
{
   if (b == 0) return a;
   return gcd(b, a%b);
}

typedef struct arbore
{
   int cmmdc;
   int nmb;
   arbore() { cmmdc = nmb = 0; }

}arbore;

int n;
arbore arb[4 * NMAX];

void build(int node, int start, int end, int pos, int val)
{
   if (start == end)
   {
      arb[node].cmmdc = val;
      arb[node].nmb = 1;
      return;
   }
   int mid = (start + end) / 2;
   if (pos <= mid) build(node * 2, start, mid, pos, val);
   else build(node * 2 + 1, mid + 1, end, pos, val);
   
   arb[node].cmmdc = gcd(arb[node * 2].cmmdc, arb[node * 2 + 1].cmmdc);
   arb[node].nmb = 0;
   
   if (arb[node].cmmdc == arb[node * 2].cmmdc) arb[node].nmb += arb[node * 2].nmb;
   if (arb[node].cmmdc == arb[node * 2 + 1].cmmdc) arb[node].nmb += arb[node * 2 + 1].nmb;
}

arbore querry(int node, int start, int end, int left, int right)
{
   if (start > end || start > right || left > end) return arbore{};
   if (left <= start && end <= right) return arb[node];

   int mid = (start + end) / 2;
   
   arbore leftAns = querry(node * 2, start, mid, left, right);
   arbore rightAns = querry(node * 2 + 1, mid + 1, end, left, right);
   arbore ans{};
   ans.cmmdc = gcd(leftAns.cmmdc, rightAns.cmmdc);
   if (ans.cmmdc == leftAns.cmmdc) ans.nmb += leftAns.nmb;
   if (ans.cmmdc == rightAns.cmmdc) ans.nmb += rightAns.nmb;
   return ans;
}

int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

   int m, x, i, a, b;   
   
   for(i = 1, cin>>n; i<=n; ++i)
   {
      cin >> x;
      build(1, 1, n, i, x);
   }

   cin >> m;
   for(;m--;)
   {
      cin >> a >> b;
      cout << (b - a + 1) - querry(1, 1, n, a, b).nmb << "\n";
   }

   return 0;
}<file_sep># https://codeforces.com/contest/405/problem/A
# https://codeforces.com/contest/405/submission/14009514

n=int(input())
l=list(map(int,input().split()))
l.sort()
for el in l:
    print(el,sep=' ',end=' ')
<file_sep>// https://codeforces.com/contest/777/problem/C
// https://codeforces.com/contest/777/submission/25124989

#include <stdio.h>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;


int main()
{

   unordered_map<int, vector<int>> mat;
   unordered_map<int, vector<int>> crescator;
   int n, m, x;

   scanf("%d %d", &n, &m);
   vector<int> rows(m + n + 1, 0);
   for (auto i = 1; i <= m; ++i) mat[i].push_back(0), crescator[i].push_back(0);


   for(auto i = 1; i <= n; ++i)
   {
      for(auto j = 1; j <= m; ++j)
      {
         scanf("%d", &x);
         crescator[j].push_back(mat[j].back() <= x ? crescator[j].back() + 1 : 1);
         mat[j].push_back(x);
         rows[i] = max(rows[i], crescator[j].back());
      }
   }

   int q, l, r;
   bool ok;

   for(scanf("%d",&q); q-- ;)
   {
      scanf("%d %d", &l, &r);
      ok = rows[r] >= r - l + 1;
      puts(!ok ? "No" : "Yes");
   }

   
   return 0;
}<file_sep>// https://codeforces.com/contest/404/problem/A
// https://codeforces.com/contest/404/submission/17155021

#include <iostream>
using namespace std;

int main()
{
	int diag[27], nDiag[27], n;
	memset(diag, 0, 27 * sizeof(int));
	memset(nDiag, 0, 27 * sizeof(int));
	char mat[300][300];

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		getchar();
		for (int j = 0; j < n; j++)
		{
			mat[i][j] = getchar();
			if (i == j || (i == n - j - 1)) diag[mat[i][j] - 'a'] = 1;
			else nDiag[mat[i][j] - 'a'] = 1;
		}
	}

	int count = 0 ,  count2 = 0;
	bool notDiag = true;
	for (int i = 0; i < 27; i++)
	{
		count += diag[i];
		count2 += nDiag[i];
		if (diag[i] != 0 && nDiag[i] != 0) notDiag = false;
	}

	if (count == 1 && notDiag && count2 == 1) cout << "YES";
	else cout << "NO";
	
	return EXIT_SUCCESS;

}<file_sep>// https://codeforces.com/contest/835/problem/C
// https://codeforces.com/contest/835/submission/29152450

// Example program
#include <stdio.h>
#include <string>
using namespace std;

int mat[12][102][102];

int main()
{
    int n,q,c,p,x,y,t,x1,y1,x2,y2, sum;
    scanf("%d %d %d", &n, &q, &c);
    
    
    for (int i = 0; i < n; ++ i)
    {
        scanf("%d %d %d", &x, &y, &p);
        mat[p][x][y]++;
    }
    
    for (int k = 0; k <= c; ++ k)
    {
        for (int i = 100; i >= 0; --i)
        {
            for(int j = 100; j >= 0; --j)
            {
                mat[k][i][j] = mat[k][i][j] + mat[k][i+1][j] + mat[k][i][j+1] - mat[k][i+1][j+1];
            }
        }
    }
    
    while(q--)
    {
        scanf("%d %d %d %d %d", &t, &x1, &y1, &x2, &y2);
        sum = 0;
        for (int i = 0; i <= c; ++i)
        {
            sum += (mat[i][x1][y1]  - mat[i][x1][y2+1] - mat[i][x2+1][y1] + mat[i][x2+1][y2+1]) * ((i + t) % (c+1));
        }
        
        printf("%d\n", sum);
    }
    
    

    return 0;    
}

// Example program
#include <iostream>
#include <string>
using namespace std;

int mat[12][102][102];

int GetSum(int x1, int y1, int x2, int y2, int t, int c)
{
    int sum = 0;
    for (int i = 0; i <= c; ++i)
    {
        sum += (mat[i][x1][y1]  - mat[i][x1][y2+1] - mat[i][x2+1][y1] + mat[i][x2+1][y2+1]) * ((i + t) % (c+1));
    }
    return sum;
}

int main()
{
    int n,q,c,p,x,y,t,x1,y1,x2,y2;
    cin >>n >> q >> c;
    
    
    for (int i = 0; i < n; ++ i)
    {
        cin >> x >> y >> p;
        mat[p][x][y]++;
    }
    
    for (int k = 0; k <= c; ++ k)
    {
        for (int i = 100; i >= 0; --i)
        {
            for(int j = 100; j >= 0; --j)
            {
                mat[k][i][j] = mat[k][i][j] + mat[k][i+1][j] + mat[k][i][j+1] - mat[k][i+1][j+1];
            }
        }
    }
    
    while(q--)
    {
        cin >> t >> x1 >> y1 >> x2 >> y2;
        cout << GetSum(x1,y1,x2,y2,t,c) << "\n";
    }
    
    

    return 0;    
}
<file_sep>// https://codeforces.com/contest/741/problem/C
// https://codeforces.com/contest/741/submission/23044412

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;

vector<int> colors(200005, 0);
vector<int> graph[200005];
vector<pair<int, int>> perechi;

inline int oppositeColor(int node)
{
   return (colors[node] == 1) ? 2 : 1;
}

bool color(int nodulet)
{
   bool ok = true;
   for (auto vecin : graph[nodulet])
   {
      if (colors[vecin] == colors[nodulet]) ok = false;
      else if (colors[vecin] == 0)
      {
         colors[vecin] = oppositeColor(nodulet);
         ok = ok & color(vecin);
      }
   }
   return ok;
}

int main()
{
   int n, x, y;
   bool ok = true;
   
   scanf("%d", &n);

   for (int i = 0; i < n; ++i)
   {
      graph[2 * i + 1].push_back(2 * i + 2);
      graph[2 * i + 2].push_back(2 * i + 1);
   }

   for (int i = 1; i <= n; ++i)
   {
      scanf("%d %d", &x, &y);
      graph[x].push_back(y);
      graph[y].push_back(x);
      perechi.push_back(make_pair(x, y));
   }

   for (int i = 1; i <= 2 * n; ++i)
   {
      if (colors[i] == 0)
      {
         colors[i] = 1;
         ok = ok & color(i);
      }
   }

   if (!ok)
   {
      puts("-1");
      return 0;
   }

   pair<int, int> pereche;
   for (int i = 0; i < n; ++i)
   {
      pereche = perechi[i];
      printf("%d %d\n", colors[pereche.first], colors[pereche.second]);
   }


   return 0;
}<file_sep>// https://codeforces.com/contest/832/problem/A
// https://codeforces.com/contest/832/submission/46924171

#include <iostream>
using namespace std;

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);

    unsigned long long n, k;
    cin >> n >> k;

    (n / k) & 1 ? cout << "YES" : cout << "NO";

    return 0;
}<file_sep>// https://codeforces.com/contest/977/problem/B
// https://codeforces.com/contest/977/submission/46637241

#include <iostream>
#include <map>
#include <string>
using namespace std;


int main()
{
    map<pair<char, char>, int> mp;
    std::string str;
    int n, mx = 0;
    pair<char, char> res;

    cin >> n >> str;
    for (int i = 0; i < n - 1; ++i)
    {
        auto c = make_pair(str[i], str[i + 1]);
        if (mx < ++mp[c])
        {
            res = c;
            mx = mp[c];
        }
    }

    cout << res.first << res.second;

    return 0;
}<file_sep>// https://codeforces.com/contest/630/problem/D
// https://codeforces.com/contest/630/submission/17323566

#include <iostream>
using namespace std;


int main()
{
	unsigned long long n;
	cin >> n;
	cout << 1 + 6 * n*(n + 1) / 2;

	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/567/problem/A
# https://codeforces.com/contest/567/submission/14261083

def diferenta(x,y):
    if  x>=0 and y>=0:
        return y-x
    elif x<=0 and y<=0:
        return abs(x)-abs(y)
    else:
        return abs(x)+y

n = int(input())
l = list(map(int,input().split()))
print(diferenta(l[0],l[1]), diferenta(l[0],l[len(l)-1]))
for i in range (1,len(l)-1):
    print(min(diferenta(l[i-1],l[i]),diferenta(l[i],l[i+1])),max(diferenta(l[i],l[len(l)-1]),diferenta(l[0],l[i])))
print(diferenta(l[len(l)-2],l[len(l)-1]), diferenta(l[0],l[len(l)-1]))
<file_sep># https://codeforces.com/contest/69/problem/A
# https://codeforces.com/contest/69/submission/13613715

def check(l):
    for i in range(len(l)):
        if l[i]!=0:
            return ('NO')
    return('YES')
n = int(input())
l = [0, 0, 0]
for _ in range(n):
    m=list(map(int, input().split()))
    for i in range(3):
        l[i]+=m[i]
    m[:]=[]
print(check(l))
<file_sep>// https://codeforces.com/contest/550/problem/A
// https://codeforces.com/contest/550/submission/17522891

#include <iostream>
#include <string>
using namespace std;


int main() {

	int mab, Mab, mba, Mba;
	mab = mba = Mab = Mba = -1;
	string s;
	cin >> s;

	for (int i = 0; i < s.size() - 1; i++) {
		if (s[i] == 'A' && s[i + 1] == 'B') {
			if (mab == -1) mab = i;
			Mab = i;
		}
		else if (s[i] == 'B' && s[i + 1] == 'A') {
			if (mba == -1) mba = i;
			Mba = i;
		}
	}
	if (abs(Mab - mba) < 2 && abs(Mba - mab) < 2 || mba == -1 || mab == -1) puts("NO");
	else puts("YES");

	return EXIT_SUCCESS;
}<file_sep>// https://www.spoj.com/problems/COINS/

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long 
#define ull unsigned long long

/*------------------------------------------------------------------*/
 
unordered_map<int, ull> mp;

ull solve(int n)
{
   if (mp.find(n) != mp.end()) return mp[n];
   return mp[n] = solve(n / 2) + solve(n / 3) + solve(n / 4);
}

int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

   mp[0] = 0;
   mp[1] = 1;
   for (int i = 2; i <= 100000; ++i) mp[i] = max(static_cast<ull>(i), mp[i / 2] + mp[i / 3] + mp[i / 4]);

   int n;
   while(cin>>n)
   {
      cout << solve(n) << "\n";
   }


   return 0;
}<file_sep>// https://codeforces.com/contest/672/problem/B
// https://codeforces.com/contest/672/submission/17927993

#include <iostream>
#include <string>
using namespace std;



int main() {
	int n, v[27];
	string s;
	cin >> n;
	if (n >= 27) puts("-1");
	else {
		cin >> s;
		int i, nr;
		memset(v, 0, 27 * sizeof(int));
		for (i = 0, nr = 0; i < (int)s.size(); i++) {
			v[s[i] - 'a']++;
			if (v[s[i] - 'a'] > 1) nr++;
		}
		cout << nr;
	}
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/984/problem/A
// https://codeforces.com/contest/984/submission/38437486

#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;

int main()
{
    int n, x;
    vector<int> v;
    
    cin>>n;
    
    for(int i = 0; i < n; ++i)
    {
        cin >> x;
        v.push_back(x);
    }
    sort(v.begin(),v.end());
    
    cout << v[(n-1)/2];
    
    return 0;
}<file_sep>// https://codeforces.com/contest/378/problem/A
// https://codeforces.com/contest/378/submission/16639290

#include <stdlib.h>
#include <stdio.h>
int main() {
	int a, b, eq = 0, aWin = 0, bWin = 0;
	scanf_s("%d %d", &a, &b);
	for (int i = 1; i <= 6; i++) {
		if (abs(a - i) < abs(b - i)) aWin++;
		else if (abs(a - i) == abs(b - i)) eq++;
		else bWin++;
	}
	printf("%d %d %d", aWin, eq, bWin);
	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/37/problem/A
# https://codeforces.com/contest/37/submission/14575678

n = int(input())
l = list(map(int,input().split()))
dicts = {}
ma = 0
for i in l:
    if i in dicts.keys():
        dicts[i] += 1
    else:
        dicts[i] = 1
    if dicts[i]>ma:
        ma = dicts[i]
print(ma,len(list(dicts.keys())))
<file_sep>// https://www.spoj.com/problems/ADDREV/

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long 
#define ull unsigned long long

/*------------------------------------------------------------------*/
 
int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
   string a, b;
   int n1, n2, n;

   cin >> n;
   while (n-- )
   {
	   cin >> a >> b;
	   reverse(a.begin(), a.end());
	   reverse(b.begin(), b.end());
	   n1 = stoi(a);
	   n2 = stoi(b);
	   a = to_string(n1 + n2);
	   reverse(a.begin(), a.end());
	   a.erase(0, a.find_first_not_of('0'));
	   cout << a << "\n";
   }


   return 0;
}<file_sep>// https://codeforces.com/contest/189/problem/A
// https://codeforces.com/contest/189/submission/17418226

#include <iostream>
using namespace std;

#define max(a,b) ((a)>(b) ? (a): (b))

int main() {
	int a, n, v[4001];
	memset(v, 0, 4001 * sizeof(int));
	cin >> n;
	while (cin >> a) 
		for (int i = a; i <= n; i++) 
			if (v[i - a] != 0 || (i%a == 0))
				v[i] = max(v[i - a] + 1, v[i]);
	cout << v[n];
	return EXIT_SUCCESS;
}<file_sep>// https://www.spoj.com/problems/MIXTURES/

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long
#define ull unsigned long long

/*------------------------------------------------------------------*/

ull mat[105][105], col[105], smoke[105][105];
int n;

int main()
{
   //ios_base::sync_with_stdio(false) , cin.tie(nullptr) , cout.tie(nullptr);


   while (cin>>n)
   {
      for (int i = 1; i <= n; ++i) cin >> col[i], mat[i][i] = col[i];
      for (int i = 1; i <= n - 1; ++i) smoke[i][i + 1] = col[i] * col[i + 1], mat[i][i + 1] = (col[i] + col[i + 1]) % 100;
      for (int d = 2; d <= n - 1; ++d)
      {
         for (int i = 1; i <= n - d; ++i)
         {
            smoke[i][i + d] = numeric_limits<ull>::max();
            for (int k = i, pr = i +d; k <= pr; ++k)
            {
               if (smoke[i][i + d] > mat[i][k] * mat[k + 1][i + d] + smoke[i][k] + smoke[k + 1][i + d])
               {
                  smoke[i][i + d] = mat[i][k] * mat[k + 1][i + d] + smoke[i][k] + smoke[k + 1][i + d];
                  mat[i][i + d] = (mat[i][k] + mat[k + 1][i + d]) % 100;
               }
            }
         }
      }
      if (n == 1) smoke[1][1] = 0;
      cout << smoke[1][n] << "\n";
   }


   return 0;
}
<file_sep># https://codeforces.com/contest/467/problem/A
# https://codeforces.com/contest/467/submission/13477314

def read():

    """
     Read 2 values p and q, 0<=p<=q<=100.
     @output: p - the number of people who already live in room
              q - room's capacity
    """

    p,q=map(int,input().split())
    return p,q

def room_spec(n):

    """
     Return the number of rooms where George and Alex can move in.
     @input: n - the total number of rooms
     @output: the number of rooms where George and Alex can move in.
    """

    nr=0
    for i in range(n):
        p,q=read()
        if q-p>=2:
            nr+=1
    return nr

n=int(input()) # read an integer n (1<=n<=100) - the number of rooms
print(room_spec(n))
<file_sep># https://codeforces.com/contest/266/problem/B
# https://codeforces.com/contest/266/submission/14007696

import copy
n,k=map(int,input().split())
s=input()
while (k>0):
    p=[];
    i=0;
    while i<=n-1:
        if i<=n-2 and s[i]=='B' and s[i+1] =='G':
            p.append('G')
            p.append('B')
            i+=2
        else:
            p.append(s[i])
            i+=1
    del(s)
    s=copy.deepcopy(p)
    del(p)
    k-=1
for el in s:
    print(el,end='',sep='')
            
<file_sep>// https://codeforces.com/gym/101246/problem/F
// https://codeforces.com/gym/101246/submission/25245739

#include <iostream>
#include<fstream>
#include<string>
#include <queue>
#include <algorithm>
#include <set>
#include <string.h>

#define cin f
#define cout g

using namespace std;




int main()
{

    ifstream f("input.txt");
    ofstream g("output.txt");

    int e[110], viz[110]={0};


    int n, fl, x;
    cin>>n>>fl;
    for(int i=0; i<n; i++){
        cin>>e[i];
        viz[e[i]]=1;
    }

    int curpoz=fl;
    int idx=0;
    while(idx < n){
        if(curpoz < e[idx]){

            for(int i=curpoz+1; i<=e[idx]; i++)
            if(viz[i]==1){
                cout<<i<<" ";
                viz[i]=0;
            }


        }
        else{
            for(int i=curpoz-1; i>=e[idx]; i--)
            if(viz[i]==1){
                cout<<i<<" ";
                viz[i]=0;
            }

        }
        curpoz = e[idx];
        while( idx < n && viz[e[idx]]==0)
            idx++;


    }

    f.close();
    g.close();

    return 0;
}<file_sep>// https://codeforces.com/contest/384/problem/A
// https://codeforces.com/contest/384/submission/16465578

#include <stdio.h>
#include <stdlib.h>

void printC(int);
void printP(int);

int main(){
	int n,i,j,count;
	scanf("%d",&n);
	count = ((n/2)+(n%2))*((n/2)+(n%2))+(n/2)*(n/2);
    printf("%d\n",count);
	for (i = 0; i < n; i++){
		if (i & 1) printC(n);
		else printP(n);
	}
	return EXIT_SUCCESS;
}

void printC(int lg){
	int i;
	for (i = 0; i < lg; i++){
		if (i & 1) putchar('C');
		else putchar('.');
	}
	putchar('\n');
}

void printP(int lg){
	int i;
	for (i = 0; i < lg; i++){
		if (i & 1) putchar('.');
		else putchar('C');
	}
	putchar('\n');
}
<file_sep>// https://codeforces.com/contest/401/problem/A
// https://codeforces.com/contest/401/submission/14899014

#include <iostream>

using namespace std;

int main()
{
    int s = 0, n, x,p;
    cin>>n>>x;
    while (n>0)
    {
        cin>>p;
        s += p;
        n -- ;
    }
    if (s<0) s *= -1;
    if (s % x != 0) cout<< 1 + s/x;
    else cout << s/x;
    return 0;
}
<file_sep>// https://codeforces.com/contest/766/problem/B
// https://codeforces.com/contest/766/submission/46828176

#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;


int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int n, x;
	scanf("%d", &n);
	vector<int> v(n, 0);

	for (int i = 0; i < n; ++i)
	{
		scanf("%d", &x);
		v[i] = x;
	}
	sort(v.begin(), v.end());


	bool ok = false;
	for (size_t i = 2; !ok && i < v.size(); ++i)
	{
		ok = (v[i - 2] + v[i - 1]) > v[i];
	}

	(ok) ? cout << "YES" : cout << "NO";

	return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);

	int n, x;
	cin >> n;
	vector<int> v(n, 0);

	for (int i = 0; i < n; ++i)
	{
		cin >> x;
		v[i] = x;
	}
	sort(v.begin(), v.end());


	bool ok = false;
	for (size_t i = 2; !ok && i < v.size(); ++i)
	{
		ok = (v[i - 2] + v[i - 1]) > v[i];
	}

	(ok) ? cout << "YES" : cout << "NO";

	return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int main()
{
	int n, x;
	cin >> n;
	vector<int> v(n, 0);

	for (int i = 0; i < n; ++i)
	{
		cin >> x;
		v[i] = x;
	}
	sort(v.begin(), v.end());


	bool ok = false;
	for (size_t i = 2; !ok && i < v.size(); ++i)
	{
		ok = (v[i - 2] + v[i - 1]) > v[i];
	}

	(ok) ? cout << "YES" : cout << "NO";

	return 0;
}<file_sep>// https://codeforces.com/contest/723/problem/A
// https://codeforces.com/contest/723/submission/21321216

#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
using namespace std;



int main()
{
   int v[3];
   for (size_t i = 0; i < 3; ++i) scanf("%d", &v[i]);

   sort(v, v + 3);
   printf("%d", v[2] - v[0]);

   return 0;
}<file_sep>// https://codeforces.com/contest/732/problem/C
// https://codeforces.com/contest/732/submission/21665568

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
   unsigned long long a[3], s = 0;
   cin >> a[0] >> a[1] >> a[2];
   sort(a, a + 3);


   if (a[2] - a[0] > 1)
   {
      if (a[2] - a[1] > 1)
      {
         s += (a[2] - a[1] - 1);
      }
      s += (a[2] - a[0] - 1);
   }
   cout << s;
   return 0;
}<file_sep>// https://codeforces.com/contest/352/problem/A
// https://codeforces.com/contest/352/submission/17171732

#include <iostream>
using namespace std;


int main()
{
	int n, n0 = 0, n5 = 0;
	char x;
	char five[] = "555555555";
	cin >> n;
	getchar();
	for (int i = 0; i < n; i++) {
		x = getchar();
		if (x == '0') n0++;
		else n5++;
		getchar();
	}

	if (n0 == 0) cout << -1;
	else
	{
		if (n5 / 9 == 0) n0 = 1;
		for (int i = 1; i <= n5 / 9; i++) cout << five;
		for (int i = 1; i <= n0; i++) putchar('0');
	}

	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/474/problem/A
# https://codeforces.com/contest/474/submission/14042125

keyboard='qwertyuiopasdfghjkl;zxcvbnm,./'
miss=input()
if miss=='R':
    opt=-1
else:
    opt=1
text=input()
for i in range(len(text)):
    print(keyboard[keyboard.index(text[i])+opt],sep='',end='')

<file_sep>// https://codeforces.com/contest/677/problem/A
// https://codeforces.com/contest/677/submission/18234721

#include <iostream>
using namespace std;


int main() {

	int n, t, x, s, i;
	for (cin >> n >> t >> x, i = 1, s = 0; i < n; i++, cin >> x) (x > t) ? s += 2 : s++; (x > t) ? s += 2 : s++;
	cout << s;

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/675/problem/A
// https://codeforces.com/contest/675/submission/18242837

#include <iostream>
using namespace std;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	
	if (c == 0 && a != b) puts("NO");
	else if (c == 0 && a == b) puts("YES");
	else if (c < 0 && a < b || c > 0 && a > b) puts("NO");
	else if ((b - a) % c != 0) puts("NO");
	else puts("YES");
		
	return EXIT_SUCCESS;

}<file_sep>// https://codeforces.com/contest/476/problem/B
// https://codeforces.com/contest/476/submission/46794053

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int output = 0, actual = 0, unknown = 0, need = 0;

void Parse(const string& input, const string& expected)
{
	for (auto& c : input)
	{
		(c == '+') ? output = output + 1
				   : output = output - 1;
	}

	for (auto& c : expected)
	{
		if (c == '+') actual = actual + 1;
		if (c == '-') actual = actual - 1;
		if (c == '?') unknown = unknown + 1;
	}
}

unsigned long long Comb(unsigned long long n, unsigned long k)
{
	unsigned long long fact[12];
	fact[0] = 1;
	for (int i = 1; i < 12; ++i) fact[i] = i * fact[i - 1];

	return fact[n] / (fact[k] * fact[n - k]);
}

double GetSol()
{
	if (need > unknown) return 0;
	if ((unknown - need) % 2 != 0) return 0;
	
	need = need + (unknown - need) / 2;
	auto comb = Comb(unknown, need);

	return static_cast<double>(comb) / static_cast<double>(1 << unknown);
}

int main()
{
	string s1, s2;
	cin >> s1 >> s2;
	Parse(s1, s2);

	need = abs(output - actual);
	cout << setprecision(12) << fixed << GetSol();
	return 0;
}<file_sep>// https://codeforces.com/contest/9/problem/A
// https://codeforces.com/contest/9/submission/46892122

#include <iostream>
#include <algorithm>
using namespace std;

void Reduct(int& a, int& b)
{
    for (int i = 2; i <= 6; ++i)
    {
        while (a % i == 0 && b % i == 0)
        {
            a = a / i;
            b = b / i;
        }
    }
}


int main()
{
    int x, y, p, q;
    cin >> x >> y;

    p = (7 - max(x,y));
    q = 6;
    Reduct(p, q);

    cout << p << "/" << q;
    return 0;
}<file_sep>// https://codeforces.com/contest/462/problem/A
// https://codeforces.com/contest/462/submission/17418438

#include <iostream>
using namespace std;


int main()
{
	char matrix[102][102];
	memset(matrix, 'x', 102 * 102 * sizeof(char));
	int n, count;
	bool ok = true;

	cin >> n; getchar();
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++)
			matrix[i][j] = getchar();
		getchar();
	}

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			count = 0;
			if (matrix[i - 1][j] == 'o') count++;
			if (matrix[i + 1][j] == 'o') count++;
			if (matrix[i][j - 1] == 'o') count++;
			if (matrix[i][j + 1] == 'o') count++;
			if (count & 1) ok = false;
		}
	}
	
	if (ok) cout << "YES";
	else cout << "NO";

    return EXIT_SUCCESS;
}

<file_sep>// https://codeforces.com/contest/689/problem/A
// https://codeforces.com/contest/689/submission/22211157

#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <vector>
#include <string>
#include <iostream>
using namespace std;



int main()
{
   int a[6][5] = { {-1,-1,-1,-1,-1},{-1,1,2,3,-1},{-1,4,5,6,-1},{-1,7,8,9,-1 },{-1,-1,0,-1,-1},{-1,-1,-1,-1,-1} };
   pair<int, int> poz[10];
   poz[0] = make_pair(4, 2);
   poz[7] = make_pair(3, 1);
   poz[8] = make_pair(3, 2);
   poz[9] = make_pair(3, 3);
   poz[4] = make_pair(2, 1);
   poz[5] = make_pair(2, 2);
   poz[6] = make_pair(2, 3);
   poz[1] = make_pair(1, 1);
   poz[2] = make_pair(1, 2);
   poz[3] = make_pair(1, 3);

   vector<int> v;
   int n;
   cin >> n;
   char el;
   int mx[] = { -1,0,1 };
   int my[] = { -1,0,1 };
   for (int i = 0; i < n; i++) {
      cin >> el;
      v.push_back((int)(el - '0'));
   }

   bool sePoate = false;
   for (int i = 0; i <= 2; i++) {
      for (int j = 0; j <= 2; j++) 
      if(i!=1 || j!=1)
      {
         sePoate = true;
         for (auto el : v) {
            auto p = poz[el];
            if (a[p.first + mx[i]][p.second + my[j]] == -1)
               sePoate = false;
         }
         if (sePoate) {
            cout << "NO";
            return 0;
         }
      }
   }
   cout << "YES";
   return 0;
};
   <file_sep>// https://codeforces.com/contest/545/problem/D
// https://codeforces.com/contest/545/submission/17154734

#include <iostream>
#include <algorithm>
using namespace std;



int main()
{
	int v[100001], n, count = 0;
	unsigned long long s = 0;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> v[i];
	sort(v, v + n);
	for (int i = 0; i < n; i++)
	{
		if (v[i] >= s) { s += v[i]; count++;}
	}

	cout << count;

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/115/problem/A
// https://codeforces.com/contest/115/submission/47157726

#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;

void DFS(int node, map<int, vector<int>>& graph, vector<bool>& visited, map<int,int>& sol, int& best)
{
    visited[node] = true;

    for (auto& neighbour : graph[node])
    {
        if (!visited[neighbour])
        {
            DFS(neighbour, graph, visited, sol, best);
        }
        sol[node] = max(sol[node], sol[neighbour] + 1);
    }

    best = max(best, sol[node]);
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);

    int n, best = 1, x;
    cin >> n;
    
    map<int, vector<int>> graph;
    map<int, int> sol;
    for (int i = 1; i <= n; ++i)
    {
        cin >> x;
        sol[x] = 1;
        sol[i] = 1;
        if (x == -1) continue;
        graph[x].push_back(i);
    }

    vector<bool> visited(n + 1, false);
    for (auto& keyValuePair : graph)
    {
        if (!visited[keyValuePair.first])
        {
            DFS(keyValuePair.first, graph, visited, sol, best);
        }
    }

    cout << best;

    return 0;
}<file_sep>// https://codeforces.com/gym/101021/problem/A
// https://codeforces.com/gym/101021/submission/18652939

#include <iostream>
#include <string>
using namespace std;

#define MAX 1000000
#define MIN 1

void cautBin() {
	int mid, lo = MIN, hi = MAX;
	string ans;

	while (hi > lo ) {
		mid = (lo + hi) / 2;
		cout << mid << "\n";
		fflush(stdout);
		cin >> ans;
		if (ans == "<") hi = --mid;
		else (lo = mid);
		if (lo >= hi - 1) {
			cout << mid + 1 <<"\n";
			fflush(stdout);
			cin >> ans;
			if (ans == "<") {
				cout << mid <<"\n";
				fflush(stdout);
				cin >> ans;
				if (ans == "<") cout << "! " << mid - 1 << "\n";
				else cout << "! " << mid << "\n";
			}else cout << "! " << mid + 1 << "\n";
			lo = hi + 1;
		}
	}
}

int main() {

	cautBin();
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/785/problem/A
// https://codeforces.com/contest/785/submission/25504142

#include <iostream>
#include <string>
using namespace std;



int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
   int n;
   long long cnt = 0;
   string s;
   cin >> n;
   for(int i = 0; i < n; ++i)
   {
      cin >> s;
      if (s[0] == 'T') cnt += 4;
      else if (s[0] == 'C') cnt += 6;
      else if (s[0] == 'O') cnt += 8;
      else if (s[0] == 'D') cnt += 12;
      else if (s[0] == 'I') cnt += 20;
   }

   cout << cnt;

   return 0;
}<file_sep># https://codeforces.com/contest/535/problem/A
# https://codeforces.com/contest/535/submission/14926852

numbers = {0:'zero',1:'one',2:'two',3:'three',4:'four',5:'five',6:'six',7:'seven',\
           8:'eight',9:'nine',10:'ten',11:'eleven',12:'twelve',13:'thirteen',14:'fourteen',\
           15:'fifteen',16:'sixteen',17:'seventeen',18:'eighteen',19:'nineteen',20:'twenty',\
           30:'thirty',40:'forty',50:'fifty',60:'sixty',70:'seventy',80:'eighty',90:'ninety'}
a = int(input())
if a <= 20 or a % 10 == 0:
    print(numbers[a])
else:
    print(numbers[a//10 * 10],'-',numbers[a%10],sep='')
    
<file_sep>// https://codeforces.com/contest/616/problem/B
// https://codeforces.com/contest/616/submission/15329996

#include <iostream>

using namespace std;

int main()
{
    short int n,m;
    long long int max = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        long long min = 0x3B9ACA00, x;
        for (int j = 1; j <= m; j++)
        {
            cin >> x;
            if (x < min) min = x;
        }
        if (min > max) max = min;
    }
    cout << max;
    return 0;
}
<file_sep>// https://codeforces.com/contest/1167/problem/A
// https://codeforces.com/contest/1167/submission/68001596

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;


int main()
{
    ios::sync_with_stdio(false); 
    cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);

    int queries = 0, length = 0;
    string s;
    cin >> queries;

    while (queries--)
    {
        cin >> length >> s;

        size_t first8 = s.size();

        for (size_t i = 0; i < s.size(); ++i)
        {
            if (s[i] == '8')
            {
                first8 = i;
                break;
            }
        }
        
        (s.size() - first8 >= 11) ? cout << "YES\n" : cout << "NO\n";
    }

    return 0;
}<file_sep># https://codeforces.com/contest/443/problem/A
# https://codeforces.com/contest/443/submission/13614190

s=input()
l=[]
for i in range(26):
    l.append(0)
for i in range(len(s)):
    if s[i]>='a' and s[i]<='z':
        l[ord(s[i])-97]=1
nr=0
for i in range(26):
    if l[i]==1:
        nr+=1
print(nr)
    
<file_sep>// https://codeforces.com/contest/984/problem/B
// https://codeforces.com/contest/984/submission/38439439

#include <algorithm>
#include <vector>
#include <iostream>
#include <stdio.h>
using namespace std;

bool IsDigit(char x)
{
	return (x >= '0' && x <= '9');
}

int GetDigit(char x)
{
	return x - '0';
}


int main()
{
	int n, m;
	
	vector<int> dX = { -1, -1, 0, 1, 1, 1, 0, -1 };
	vector<int> dY = { 0, 1, 1, 1, 0, -1, -1, -1 }; 
	bool ok = true;
	string line;
	char matrix[102][102] = {0};

	scanf("%d %d", &n,&m);
	for(int i = 1; i<=n; ++i)
	{
	    getchar();
        scanf("%s",&(matrix[i][1]));
		for(int j = 1; j<=m; ++j)
		{
			if (matrix[i][j] == '.')
			{
				matrix[i][j] = '0';
			}
		}
	}
	
	for(int i = 1; i <= n; ++i)
	{
		for(int j = 1; j <= m; ++j)
		{
			if (!IsDigit(matrix[i][j]))
			{
				continue;
			}
			
			int d = GetDigit(matrix[i][j]);
			int matches = 0;
			
			for(int k = 0; k < 8; ++k)
			{
				int ox = i + dX[k];
				int oy = j + dY[k];
				
				if (matrix[ox][oy] == '*')
				{
					matches++;
				}
				
			}
			
			if(matches != d)
			{
				ok = false;
			}
		}
	}
	
	cout << (ok ? "YES" : "NO") << "\n";
	
	return 0;
}<file_sep># https://codeforces.com/contest/431/problem/A
# https://codeforces.com/contest/431/submission/14639640

l = [0] +  list(map(int,input().split()))
s = input()
sm = 0
for i in range(len(s)):
    sm += l[int(s[i])]
print(sm)
<file_sep># https://codeforces.com/contest/514/problem/A
# https://codeforces.com/contest/514/submission/14419432

s = input()
j = 0
if s[0]=='9':
    print(9,sep='',end='')
    j = 1
for i in range(j,len(s)):
    print(min(9-int(s[i]),int(s[i])),sep='',end='')
<file_sep>// https://codeforces.com/contest/463/problem/A
// https://codeforces.com/contest/463/submission/17434138

#include <iostream>
using namespace std;


int main() {

	int $$,c,n, s, max = -1;
	cin >> n >> s;
	for (; n > 0; n--) {
		cin >> $$ >> c;
		if (s - $$ >= 0) {
			if (s - $$ > 0 && c != 0 && 100 - c > max) max = 100 - c;
			else if (c == 0 && max == -1) max = 0;
		}
	}
	cout << max;

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/501/problem/B
// https://codeforces.com/contest/501/submission/48032053

#include <string>
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>
using namespace std;

void Add(map<string, int>& hash, map<int, string>& revHash, int& id, string& handle)
{
    if (hash[handle] == 0)
    {
        hash[handle] = ++id;
        revHash[id] = handle;
    }
}

int find(map<int, int>& parent, int x)
{
    if (x == parent[x]) return x;
    return parent[x] = find(parent, parent[x]);
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int q, id = 0;

    map<string, int> hash;
    map<int, string> revHash;

    map<int, int> parent;
    map<int, bool> visited;

    vector<pair<string, string>> changes;
    string oldH, newH;

    cin >> q;
    for (int i = 1; i <= q; ++i)
    {
        cin >> oldH >> newH;
        Add(hash, revHash, id, oldH);
        Add(hash, revHash, id, newH);

        auto x = hash[oldH]; if (parent[x] == 0) parent[x] = x;
        auto y = hash[newH]; if (parent[y] == 0) parent[y] = y;

        parent[find(parent, x)] = y;
    }

    for (int i = 1; i <= id; ++i)
    {
        auto px = find(parent, i);
        if (visited[px]) continue;

        visited[px] = true;
        changes.push_back(make_pair(revHash[i], revHash[px]));
    }

    cout << changes.size() << "\n";
    for (const auto& value : changes)
    {
        cout << value.first << " " << value.second << "\n";
    }

    return 0;
}<file_sep>// https://codeforces.com/contest/478/problem/A
// https://codeforces.com/contest/478/submission/13753654

#include <stdio.h>
#include <stdlib.h>

int main()
{
   int x,i,sum = 0;
   for (i=1;i<=5;i+=1)
   {
       scanf("%d",&x);
       sum +=x;
   }
   if ((sum%5!=0) || (sum==0)){printf("-1");}
   else{printf("%d",sum/5);}
   return 0;
}
<file_sep>// https://codeforces.com/contest/592/problem/B
// https://codeforces.com/contest/592/submission/13994484

#include <iostream>

using namespace std;

unsigned long long n;

int main()
{
    cin>>n;
    cout<<(n-2)*(n-2);
    return 0;
}
<file_sep>// https://www.spoj.com/problems/BRCKTS/

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

struct Node
{
    Node(char Bracket)
    {
        if (Bracket == ')')
        {
            StartClosed = 1;
        }
        else
        {
            EndOpened = 1;
        }
    }

    Node() = default;
    ~Node() = default;

    int StartClosed = 0;
    int EndOpened = 0;
};

class SegmentTree
{
public:
    SegmentTree(const string& Array) :
        Array{ Array },
        Tree(Array.size() * 4 + 4, Node())
    {
        Build(1, 0, Array.size() - 1);
    };

    bool Query(size_t Low, size_t High)
    {
        auto node = Query(1, 0, Array.size() - 1, Low, High);
        return (node.StartClosed == 0 && node.EndOpened == 0);
    }

    void Update(size_t Low, size_t High)
    {
        Update(1, 0, Array.size() - 1, Low, High);
    }

    ~SegmentTree() = default;

private:

    void Build(size_t Node, size_t Start, size_t End)
    {
        if (Start == End)
        {
            Tree[Node] = ::Node(Array[Start]);
            return;
        }

        size_t mid = (Start + End) / 2;

        Build(Node * 2, Start, mid);
        Build(Node * 2 + 1, mid + 1, End);

        Tree[Node] = Combine(Tree[Node * 2], Tree[Node * 2 + 1]);
    }

    void Update(size_t Node, size_t Start, size_t End, size_t Low, size_t High)
    {
        if (Low > End || High < Start)
        {
            return;
        }

        if (Start == End)
        {
            Array[Start] = (Array[Start] == ')') ? '(' : ')';
            Tree[Node] = ::Node(Array[Start]);
            return;
        }

        size_t mid = (Start + End) / 2;

        Update(Node * 2, Start, mid, Low, High);
        Update(Node * 2 + 1, mid + 1, End, Low, High);

        Tree[Node] = Combine(Tree[Node * 2], Tree[Node * 2 + 1]);
    }

    Node Query(size_t Node, size_t Start, size_t End, size_t Low, size_t High)
    {
        if (Low > End || High < Start)
        {
            return ::Node();
        }

        if (Low >= Start && End <= High)
        {
            return Tree[Node];
        }

        size_t mid = (Start + End) / 2;

        auto left = Query(Node * 2, Start, mid, Low, High);
        auto right = Query(Node * 2 + 1, mid + 1, End, Low, High);
        
        return Combine(left, right);
    }

    Node Combine(const Node& Left, const Node& Right)
    {
        Node node;

        node.StartClosed = Left.StartClosed;
        node.EndOpened = Right.EndOpened;

        node.EndOpened += max(0, Left.EndOpened - Right.StartClosed);
        node.StartClosed += max(0, Right.StartClosed - Left.EndOpened);

        return node;
    }

    string Array;
    vector<Node> Tree;
};


int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, m, k;
    string s;

    for (int i = 1; i <= 10; ++i)
    {
        cin >> n >> s >> m;
        SegmentTree tree(s);

        cout << "Test " << i << ":\n";
        for (int j = 1; j <= m; ++j)
        {
            cin >> k;
            if (k > 0) tree.Update(k - 1, k - 1);
            else tree.Query(0, s.size() - 1) ? cout << "YES\n" : cout << "NO\n";
        }

    }

    return 0;
}<file_sep>// https://codeforces.com/contest/681/problem/A
// https://codeforces.com/contest/681/submission/18456914

#include <iostream>
#include <string>
using namespace std;


int main() {
	int n, b, a;
	string s;
	bool ok = false;
	cin >> n;
	for (; n > 0; n--) {
		cin >> s >> b >> a;
		if (b >= 2400 && a > b) ok = true;
	}
	(ok) ? puts("YES") : puts("NO");


	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/721/problem/A
// https://codeforces.com/contest/721/submission/21808058

#include <iostream>
#include <vector>
#include <string>
using namespace std;


int main()
{
   ios::sync_with_stdio(false);
   vector<int> sol;
   string s;
   int n;
   bool ok = true; 
   int ct = 0;

   cin >> n >> s;
   for (size_t i = 0; i < s.size(); ++i)
   {
      if (s[i] == 'B' && ok) ct++;
      else if (s[i] == 'B' && !ok) ok = true, ct = 1;
      else {
         if (ct > 0) sol.push_back(ct);
         ok = false; 
         ct = 0;
      }
   }

   if (ok > 0) sol.push_back(ct);

   cout << sol.size() << "\n";

   for (size_t i = 0; i < sol.size(); ++i)
   {
      cout << sol[i] << " ";
   }


   return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/19/problem/D
// https://codeforces.com/contest/19/submission/68014305

#include <iostream>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <string>
#include <vector>
using namespace std;

struct Point
{
    Point() = default;
    Point(int x, int y) : x{ x }, y{ y } {};

    bool operator<(const Point& Other) const
    {
        return (this->x != Other.x) ? this->x < Other.x
                                    : this->y < Other.y;
    }

    int x = std::numeric_limits<int>::min();
    int y = std::numeric_limits<int>::min();
};

class SegmentedTree
{
public:
    SegmentedTree(size_t NoPoints)
        : Tree{ NoPoints * 4 + 4, Point() },
        noPoints{NoPoints}
    {};

    void Update(size_t Position, const Point& Point)
    {
        Update(1, 0, noPoints - 1, Position, Position, Point);
    }

    Point Query(const Point& Requested)
    {
        return Query(1, 0, noPoints - 1, Requested);
    }

private:

    Point Query(size_t Node, size_t Start, size_t End, const Point& Requested)
    {
        if (Tree[Node].x <= Requested.x || Tree[Node].y <= Requested.y)
        {
            return Point();
        }
        
        if (Start == End)
        {
            return Tree[Node];
        }

        size_t mid = (Start + End) / 2;

        auto solution = Query(Node * 2, Start, mid, Requested);
        if (solution.x == std::numeric_limits<int>::min() || solution.y == std::numeric_limits<int>::min())
        {
            solution = Query(Node * 2 + 1, mid + 1, End, Requested);
        }

        return solution;
    }

    void Update(size_t Node, size_t Start, size_t End, size_t Low, size_t High, const Point& Point)
    {
        if (Start > High || End < Low)
        {
            return;
        }

        if (Start == End)
        {
            Tree[Node] = ::Point(Point);
            return;
        }

        size_t mid = (Start + End) / 2;

        Update(Node * 2, Start, mid, Low, High, Point);
        Update(Node * 2 + 1, mid + 1, End, Low, High, Point);

        Tree[Node] = Combine(Tree[Node * 2], Tree[Node * 2 + 1]);
    }

    Point Combine(const Point& Left, const Point& Right)
    {
        Point node;
        node.x = max(Left.x, Right.x);
        node.y = max(Left.y, Right.y);

        return node;
    }

private:
    vector<Point> Tree;
    size_t noPoints = 0;
};


int main()
{
    ios::sync_with_stdio(false); 
    cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);

    vector<Point> points;
    vector<pair<int, Point>> queries;

    int n = 0;
    cin >> n;

    while (n--)
    {
        int x = 0, y = 0;
        string s;

        cin >> s >> x >> y;
        Point point{ x,y };

        points.push_back(point);
        
        if (s == "add") queries.push_back({ 'a', point });
        else if (s == "remove") queries.push_back({ 'r',point });
        else queries.push_back({ 'f',point });
    }

    sort(points.begin(), points.end());

    SegmentedTree tree(points.size());

    for (const auto& query : queries)
    {
        auto command = query.first;
        auto point = query.second;

        auto pointMapping = std::lower_bound(points.begin(), points.end(), point);
        
        if (command == 'a') tree.Update(pointMapping - points.begin(), point);
        else if (command == 'r') tree.Update(pointMapping - points.begin(), Point{});
        else if (command == 'f')
        {
            auto p = tree.Query(point);
            if (p.x == std::numeric_limits<int>::min() || p.y == std::numeric_limits<int>::min())
            {
                cout << "-1\n";
            }
            else
            {
                cout << p.x << " " << p.y << "\n";
            }
        }
    }

    return 0;
}<file_sep>// https://codeforces.com/contest/789/problem/A
// https://codeforces.com/contest/789/submission/25902327

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long 
#define ull unsigned long long

/*------------------------------------------------------------------*/
 
int v[100005];
int n, k;

int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
   cin >> n >> k;
   int cnt = 0;
   int buzunare;

   for (int i = 1; i <= n; ++i) cin >> v[i];

   for(int i = 1; i<=n; ++i)
   {
      if (v[i] == 0) continue;
      if (v[i] >= k)
      {
         buzunare = v[i] / k;
         if (v[i] % k != 0) buzunare++;
      }
      else
      {
         buzunare = 1;
      }
      cnt += buzunare / 2;
      if (buzunare % 2 != 0) {
         cnt++;
         v[i + 1] = max(0, v[i + 1] - k);
      }
   }
   cout << cnt;
   

   return 0;
}<file_sep># https://codeforces.com/contest/59/problem/A
# https://codeforces.com/contest/59/submission/14287298

import string
lower = string.ascii_lowercase
upper = string.ascii_uppercase
s = input()
nrl,nru = 0, 0
for i in range (len(s)):
    if s[i] in lower:
        nrl+=1
    else:
        nru+=1
if nrl>=nru:
    print(s.lower())
else:
    print(s.upper())
<file_sep># https://codeforces.com/contest/500/problem/A
# https://codeforces.com/contest/500/submission/14007783

n,m=map(int,input().split())
l=list(map(int,input().split()))
p=[0]+l
rez=1+p[1]
while (rez<m):
    rez=p[rez]+rez
if rez==m:
    print('YES')
else:
    print('NO')
<file_sep>// https://codeforces.com/contest/752/problem/B
// https://codeforces.com/contest/752/submission/23310052

#include <iostream>
#include <string>
#include <map>
using namespace std;


int main()
{
   map<char, char> m;
   string s, t;
   int cnt = 0;

   cin >> s >> t;
   bool ok = true;
   int size = s.size();
   for (int i = 0; i < size; ++i)
   {
      if (s[i] == t[i])
      {
         if (m.find(s[i]) != m.end())
         {
            if (m[s[i]] != t[i]) ok = false;
         }
         else m[s[i]] = t[i], m[t[i]] = s[i];
      }
      else if (m.find(s[i]) == m.end() && m.find(t[i]) == m.end())
      {
         m[s[i]] = t[i];
         m[t[i]] = s[i];
      }
      else
      {
         if (m[s[i]] != t[i]) ok = false;
      }
      if (!ok) break;
   }
   for (auto key : m)
   {
      if (key.second != '-') cnt++, m[key.second] = '-';
      if (key.second == key.first) cnt--;
   }

   if (!ok) puts("-1");
   else
   {
      cout << cnt << "\n";
      for (auto key : m)
      {
         if (key.second != '-') cout << key.first << " " << key.second << "\n";
      }
   }

   return 0;
}<file_sep># https://codeforces.com/contest/208/problem/A
# https://codeforces.com/contest/208/submission/13960065

import string
s=input()
a=s.replace('WUB',' ')
del(s)
s=a.lstrip()
del(a)
a=s.rstrip()
print(a)
<file_sep>// https://codeforces.com/contest/750/problem/A
// https://codeforces.com/contest/750/submission/23458514

#include <iostream>
using namespace std;


int main()
{
   int n, k, s = 240, i = 1, cnt = 0;
   
   cin >> n >> k;
   s -= k;
   while (s - i * 5 >= 0 && i <= n) cnt++, s -= i++ * 5;
   cout << cnt;
   return 0;
}<file_sep># https://codeforces.com/contest/268/problem/B
# https://codeforces.com/contest/268/submission/14056730

n=int(input())
print(int((n*n*n + (5*n))/6))
<file_sep>// https://www.spoj.com/problems/GSS1/

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct Node
{
    Node(int Value)
    {
        this->Sum = Value;
        this->MaxPrefixSum = Value;
        this->MaxSuffixSum = Value;
        this->MaxCombinedSum = Value;
    }

    Node() = default;
    ~Node() = default;

    long long Sum             = numeric_limits<int>::min();
    long long MaxPrefixSum    = numeric_limits<int>::min();
    long long MaxSuffixSum    = numeric_limits<int>::min();
    long long MaxCombinedSum  = numeric_limits<int>::min();
};

class SegmentedTree
{
public:
    SegmentedTree(const vector<int>& Array):
        Array{Array},
        Tree(Array.size() * 4 + 4, Node())
    {
        Build(1, 0, Array.size() - 1);
    }

    long long Query(size_t Low, size_t High)
    {
        std::vector<size_t> path;

        Query(1, 0, Array.size() - 1, Low, High, path);

        Node previous{ numeric_limits<int>::min() };
        previous.Sum = 0;

        for (auto& nodeIdx : path)
        {
            const auto& node = Tree[nodeIdx];
            previous = Combine(previous, node);
        }

        return MaxSum(previous);
    }

private:

    void Build(size_t Node, size_t Start, size_t End)
    {
        if (Start == End)
        {
            Tree[Node] = ::Node(Array[Start]);
            return;
        }

        size_t mid = (Start + End) / 2;

        Build(Node * 2, Start, mid);
        Build(Node * 2 + 1, mid + 1, End);

        Tree[Node] = Combine(Tree[Node * 2], Tree[Node * 2 + 1]);
    }

    void Query(size_t Node, size_t Start, size_t End, size_t Low, size_t High, std::vector<size_t>& Nodes)
    {
        if (Start > High || End < Low)
        {
            return;
        }

        if (Low <= Start && End <= High)
        {
            Nodes.push_back(Node);
            return;
        }

        size_t mid = (Start + End) / 2;
        Query(Node * 2, Start, mid, Low, High, Nodes);
        Query(Node * 2 + 1, mid + 1, End, Low, High, Nodes);
    }

    Node Combine(const Node& Left, const Node& Right)
    {
        Node node;

        node.Sum = Left.Sum + Right.Sum;
        node.MaxPrefixSum = max(Left.MaxPrefixSum, Left.Sum + Right.MaxPrefixSum);
        node.MaxSuffixSum = max(Right.MaxSuffixSum, Left.MaxSuffixSum + Right.Sum);
        node.MaxCombinedSum = max(Left.MaxCombinedSum, Right.MaxCombinedSum);
        node.MaxCombinedSum = max(node.MaxCombinedSum, Left.MaxSuffixSum + Right.MaxPrefixSum);

        return node;
    }

    long long MaxSum(const Node& Node)
    {
        auto res = Node.Sum;
        res = max(res, Node.MaxCombinedSum);
        res = max(res, Node.MaxPrefixSum);
        res = max(res, Node.MaxSuffixSum);
        
        return res;
    }

    vector<int> Array;
    vector<Node> Tree;
};

vector<int> ReadVector()
{
    int n;
    cin >> n;
    vector<int> v(n, 0);

    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    return v;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int q, r, l;

    auto vector = ReadVector();

    SegmentedTree tree(vector);
    
    cin >> q;
    for (int i = 1; i <= q; ++i)
    {
        cin >> r >> l;
        cout << tree.Query(r - 1, l - 1) << '\n';
    }

    return 0;
}<file_sep># https://codeforces.com/contest/149/problem/A
# https://codeforces.com/contest/149/submission/14449996

k  = int(input())
l = sorted(list(map(int,input().split())))
i = 11
nr = 0
while k>0 and i>=0:
    k-=l[i]
    nr+=1
    i-=1
if k>0:
    print(-1)
else:
    print(nr)

<file_sep>// https://codeforces.com/contest/734/problem/A
// https://codeforces.com/contest/734/submission/22307512

#include <iostream>
#include <string>
using namespace std;



int main()
{
   int An,Dn, size;
   string s;
   cin >> An >> s;
   An = Dn = 0; size = s.size();
   for (int i = 0; i < size; ++i)
   {
      (s[i] == 'A') ? An++ : Dn++;
   }
   (An > Dn) ? puts("Anton") : (An == Dn) ? puts("Friendship") : puts("Danik");
   
   return 0;
}<file_sep>// https://codeforces.com/contest/731/problem/C
// https://codeforces.com/contest/731/submission/21641965

#include <iostream>
#include <stdio.h>
#include <vector>
#include <string.h>
#include <map>
using namespace std;

vector<int> colors(200005,0);
vector<int> graph[200005];
bool visited[200005];
map<int, int> cls;
int maxCol = 0;
int maxFrecv = 0;

void dfs(int node)
{
   visited[node] = 1;
   for (auto nd : graph[node])
   {
      if (visited[nd] == 0)
      {
         if (maxCol < ++cls[colors[nd]]) maxCol = cls[colors[nd]];
         ++maxFrecv;
         dfs(nd);
      }
   }
}

int main()
{
   int n, m, k, x, y;
   
   scanf("%d %d %d", &n, &m, &k);
   for (int i = 1; i <= n; ++i) cin >> colors[i];
   for (int i = 0; i < m; ++i)
   {
      scanf("%d %d", &x, &y);
      graph[x].push_back(y);
      graph[y].push_back(x);
   }

   int all = 0;

   for (int i = 1; i <= n; ++i)
   {
      if (visited[i] == 0)
      {
         cls.clear();
         cls[colors[i]] = 1;
         maxCol = 1;
         maxFrecv = 1;
         dfs(i);
         all += (maxFrecv - maxCol);

      }
   }

   printf("%d", all);


   return 0;
}<file_sep>// https://codeforces.com/contest/745/problem/C
// https://codeforces.com/contest/745/submission/23064233

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int parent[1004];
int kids[1004];
int muchii[1004];
map<int, bool> rep;
vector<int>reps;

void swap(int&x, int&y)
{
   int aux = x;
   x = y;
   y = aux;
}

int find(int x)
{
   return (x == parent[x]) ? x : parent[x] = find(parent[x]);
}

int main()
{
   int n, m, k, reprez, x, y, px, py;
   scanf("%d %d %d", &n, &m, &k);

   for (int i = 1; i <= n; i++)
   {
      parent[i] = i;
      kids[i] = 1;
   }

   for (int i = 1; i <= k; ++i)
   {
      scanf("%d", &reprez);
      rep[reprez] = 1;
   }

   for (int i = 1; i <= m; ++i)
   {
      scanf("%d %d", &x, &y);
      px = find(x);
      py = find(y);
      if (rep[px] == 1) swap(px, py);
      if (px != py) parent[px] = py, kids[py] += kids[px], muchii[py] += muchii[px];
      muchii[py]++;
   }

   int contor = 0;
   int freeNodes = 0;
   int freeMuchii = 0;
   for (int i = 1; i <= n; ++i)
   {
      if (find(i) != i) continue;
      contor += ((kids[i] * (kids[i] - 1)) / 2 - muchii[i]);
      if (rep[i] == 1) reps.push_back(kids[i]);
      else
      {
         freeMuchii += freeNodes*kids[i];
         freeNodes += kids[i];
      }
   }
   sort(reps.begin(), reps.end());
   int mx = reps[reps.size() - 1];
   freeMuchii += mx * freeNodes;
   contor += freeMuchii;

   printf("%d", contor);
   return 0;
}<file_sep>// https://codeforces.com/contest/749/problem/B
// https://codeforces.com/contest/749/submission/23148975

#include <iostream>
using namespace std;

int main()
{
   int x1, y1, x2, y2, x3, y3;
   cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

   cout << 3 << "\n";
   cout << x2 - x3 + x1 << " " << y2 - y3 + y1 << "\n";
   cout << x1 - x2 + x3 << " " << y1 - y2 + y3 << "\n";
   cout << x3 - x1 + x2 << " " << y3 - y1 + y2 << "\n";

   return 0;
}<file_sep>// https://codeforces.com/contest/822/problem/A
// https://codeforces.com/contest/822/submission/30913465

#include <iostream>
#include <algorithm>
using namespace std;

typedef unsigned int ui;

ui Fact(const ui& a)
{
	ui res = 1;
	for (ui i = 2; i <= a; ++i)
	{
		res *= i;
	}

	return res;
}

int main()
{
	ui a = 0, b = 0;
	cin >> a >> b;
	cout << Fact(min(a, b));

	cin >> a;
	return 0;
}<file_sep>// https://codeforces.com/contest/615/problem/A
// https://codeforces.com/contest/615/submission/16452036

#include <stdlib.h>
#include <stdio.h>

typedef enum elem{ONE, ZERO} STATE;

int main() {
	int n, m, i, j, x, y;
	scanf_s("%d %d", &n, &m);
	STATE *v, ok = ONE;
	v = (STATE*)malloc((m+1)*sizeof(STATE));
	for (i = 0; i <= m; i++) v[i] = ZERO;
	for (i = 0; i < n; i++) {
		scanf_s("%d", &x);
		for (j = 0; j < x; j++) {
			scanf_s("%d", &y);
			v[y] = ONE;
		}
	}
	i = 1;
	while (i <= m && ok != ZERO) {
		ok = v[i];
		i++;
	}
	if (ok == ONE) printf("YES");
	else printf("NO");
	free(v);
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/gym/101246/problem/D
// https://codeforces.com/gym/101246/submission/25263041

#include <iostream>
#include<fstream>
#include<string>
#include <queue>
#include <algorithm>
#include <set>
#include <string.h>

#define cin f
#define cout g

using namespace std;



vector<int> vecini[100100];
int viz[100100];
int nivel[100100];
int grd[100100];


void bfs(){
    queue<int> q;
    q.push(1);
    viz[1]=1;
    int p;
    while(!q.empty()){
        p=q.front();
        q.pop();

        for(int vec:vecini[p]){
            if(viz[vec]==0){

                q.push(vec );
                viz[vec]=1;
                nivel[vec]=nivel[p]+1;

            }
        }

    }
}


int mex(set<int>& s){

    int m=0;
    while( s.find(m)!=s.end() )m++;
    return m;
}

void dfs(int nod){

    set<int> s;
    viz[nod]=1;
    bool frunza=true;
    for(int vec:vecini[nod]){
        if( nivel[vec]==nivel[nod]+1){
            frunza=false;
            dfs(vec);
            s.insert(grd[vec]);
        }
    }

    if(frunza)
        grd[nod]=0;
    else
        grd[nod]=mex(s);
}



int main()
{

    ifstream f("input.txt");
    ofstream g("output.txt");


    int n, m;
    cin>>n>>m;

    int x, y;
    for(int i=0; i<m; i++)
    {
        cin>>x>>y;
        vecini[x].push_back(y);
        vecini[y].push_back(x);
    }

    bfs();
    memset(viz, 0, sizeof(int)*100100);
    dfs(1);
    if(!grd[1]){
        cout<<"Nikolay\n";

    }
    else
        cout<<"Vladimir\n";
    //cout<<nivel[1]<<" "<<nivel[2]<<" "<<nivel[3]<< " "<<nivel[4]<<"\n";
    //cout<<grd[1]<<" "<<grd[2]<<" "<<grd[3]<< " "<<grd[4];





    f.close();
    g.close();

    return 0;
}<file_sep>// https://codeforces.com/contest/508/problem/B
// https://codeforces.com/contest/508/submission/17535879

#include <string>
#include <iostream>
using namespace std;

int main() {

	int max = -9, poz = -1;
	string s;
	cin >> s;
	for (int i = 0; i < s.size() - 1; i++) {
		if ((s[i] - '0') % 2 == 0) {
				if (s[s.size()-1] > s[i] && max < 0){
					max = 0;
					poz = i;
				}
				else if (max!=0) {
					poz = i;
				}
		}
	}
	if (poz == -1) puts("-1");
	else {
		char c = s[s.size() - 1];
		s[s.size() - 1] = s[poz];
		s[poz] = c;
		cout<<s;
	}


	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/237/problem/A
# https://codeforces.com/contest/237/submission/14397970

n = int(input())
m,h = map(int,input().split())
nr=1;
nr1=1;
while n-1>0:
    x,y=map(int,input().split())
    if x==m and y==h:
        nr1+=1
    else:
        m,h,nr1 = x,y,1
    if nr1>nr:
        nr=nr1
    n-=1
print(nr)
<file_sep>// https://codeforces.com/contest/678/problem/D
// https://codeforces.com/contest/678/submission/18451856

#include <iostream>
using namespace std;

const unsigned long long  MOD=1000000007;

unsigned long long pow(unsigned long long a, unsigned long long b) {
	if (b == 1) return a;
	if (b == 0) return 1;
	if (b % 2 == 0) return pow(((a% MOD)*(a% MOD)) % MOD, b / 2);
	return ((a% MOD)*pow(((a% MOD)*(a% MOD)) % MOD, b / 2)) % MOD;
}

int main() {

	unsigned long long a, b, n, x, rez, td, pt;
	cin >> a >> b >> n >> x;
	
	pt = pow(a, n);
	if (a == 1) td = ((b%MOD) * (n%MOD)) % MOD;
	else td = (b % MOD  * ((pt - 1) % MOD * pow(a-1,MOD-2) % MOD)) % MOD;
	rez = (((pt%MOD) * (x%MOD)) % MOD + td ) % MOD;

	cout << rez;


	return 0;
}<file_sep># https://codeforces.com/contest/124/problem/A
# https://codeforces.com/contest/124/submission/14872673

n, a, b = map(int,input().split())
print(n-max(a+1,n-b)+1)
<file_sep>// https://codeforces.com/contest/712/problem/C
// https://codeforces.com/contest/712/submission/21841423

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))


int main()
{
   int a, b, c, goal, steps = 0;
   bool ok = false;

   scanf("%d %d", &goal, &a);
   b = c = a;

   while (!ok)
   {
      ok = true;
      if (a != goal)
      {
         ok = false;
         a = MIN(b + c - 1, goal);
         steps++;
      }
      if (b != goal)
      {
         ok = false;
         b = MIN(a + c - 1, goal);
         steps++;
      }
      if (c != goal)
      {
         ok = false;
         c = MIN(a + b - 1, goal);
         steps++;
      }
   }

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

   return EXIT_SUCCESS;

}<file_sep># https://codeforces.com/contest/131/problem/A
# https://codeforces.com/contest/131/submission/13407839

s=input()
if s.isupper():
    print(s.lower())
elif len(s)==1 and s.islower():
    print(s.upper())
elif s[1:len(s)].isupper():
    print(s.capitalize())
else:
    print(s)

    
<file_sep>// https://codeforces.com/contest/748/problem/D
// https://codeforces.com/contest/748/submission/23312486

#include <string>
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

string revers(string& s)
{
   string c = s;
   reverse(c.begin(), c.end());
   return c;
}


int main()
{
   ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

   int n, k;
   long long ctt = 0, pr, se, c;
   long long mx = 0;
   long long zero = 0;

   cin >> n >> k;

   map<string, vector<long long>> m;
   string s, rev;

   for (int i = 0; i < n; ++i)
   {
      cin >> s >> c;
      m[s].push_back(c);
   }

   for (auto& key : m)
   {
      sort(key.second.begin(), key.second.end());
   }

   for (auto& key : m)
   {
      s = key.first;
      rev = revers(s);

      if (s == rev)
      {
         while (m[s].size() > 1)
         {
            pr = m[s].back(); m[s].pop_back();
            se = m[s].back(); m[s].pop_back();
            if (pr > 0 && se < 0)
               mx = max(mx, pr - max(pr + se, zero));
            ctt += max(pr + se, zero);
         }
         if (m[s].size() > 0)
         {
            pr = m[s].back(); m[s].pop_back();
            mx = max(mx, pr);
         }
      }
      else
      {
         while (m[s].size() > 0 && m[rev].size() > 0)
         {
            pr = m[s].back();m[s].pop_back();
            se = m[rev].back();m[rev].pop_back();
            ctt += max(pr + se, zero);
         }
      }
      m[s].clear();
      m[rev].clear();
   }

   cout << ctt + mx;

   return 0;
}<file_sep># https://codeforces.com/contest/282/problem/A
# https://codeforces.com/contest/282/submission/13407539

n=int(input())
nr=0
for i in range(n):
    s=input()
    if s[1]=="+":
        nr+=1
    else:
        nr-=1
print(nr)
<file_sep>// https://codeforces.com/contest/701/problem/A
// https://codeforces.com/contest/701/submission/21841936

#include <stdio.h>
#include <algorithm>
#include <vector>
using namespace std;

typedef struct _STR
{
   int idx, value;
   _STR() { idx = 0, value = 0; }
   _STR(int idx, int value) { this->idx = idx, this->value = value; }
}STR;

bool compare(STR l, STR r)
{
   return l.value < r.value;
}

int main()
{
   vector<STR> vct;
   int n, x;

   scanf("%d", &n);
   for (int i = 1; i <= n; ++i)
   {
      scanf("%d", &x);
      vct.push_back(STR(i, x));
   }
   sort(vct.begin(), vct.end(), compare);
   
   int i = 0;
   --n;
   while (i < n)
   {
      printf("%d %d\n", vct[i].idx, vct[n].idx);
      ++i, --n;
   }

   return EXIT_SUCCESS;
}<file_sep>#include <iostream>
#include <fstream>
#include <chrono>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>
using namespace std;

void Play()
{
    unsigned long long start = 0;
    unsigned long long end = 1;
    string result = "y";

    while(result == "y")
    {
        cout << "? " << start << " " << end << endl;
        cin >> result;

        if (result == "y")
        {
            start = end;
            end *= 2;
        }
    }

    while(end - start > 1)
    {
        auto mid = (start + end) / 2;

        cout << "? " << start << " " << mid << endl;
        cin >> result;
        
        (result == "y") ? start = mid : end = mid;
    };

    cout << "! " << start + 1 << endl;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);
    
    string status;

    for (cin >> status; status == "start"; cin >> status)
    {
        Play();
    }

    return 0;
}<file_sep># https://codeforces.com/contest/540/problem/A
# https://codeforces.com/contest/540/submission/14011088

n=int(input())
s=input()
s2=input()
rez=0;
for i in range(n):
    t1=int(s[i])
    t2=int(s2[i])
    if abs(t1-t2)>min(t1,t2)+10-max(t1,t2):
        rez+=min(t1,t2)+10-max(t1,t2)
    else:
        rez+=abs(t1-t2)
print(rez)
<file_sep>// https://codeforces.com/problemset/problem/1017/A
// https://codeforces.com/problemset/submission/1017/49365147
#include <iostream>
#include <fstream>
#include <chrono>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>
using namespace std;

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);
    int a, b, c, d, thomas, n, rank = 1;

    cin >> n >> a >> b >> c >> d;
    thomas = a + b + c + d;

    for (int i = 1; i < n; ++i)
    {
        cin >> a >> b >> c >> d;
        if (a + b + c + d > thomas) rank++;
    }
    cout << rank;

    return 0;
}<file_sep>// https://codeforces.com/contest/369/problem/A
// https://codeforces.com/contest/369/submission/17419130

#include <stdio.h>
#include <stdlib.h>

int main() {

	int n, a, b, x, i, count;
	scanf("%d %d %d", &n, &a, &b);
	for (i = 0, count = 0; i < n; i++) {
		scanf("%d", &x);
		if (x == 1) {
			if (a > 0) a--;
			else count++;
		}
		else {
			if (b > 0) b--;
			else if (a > 0) a--;
			else count++;
		}
	}
	printf("%d", count);

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/731/problem/B
// https://codeforces.com/contest/731/submission/21570145

#include <iostream>
using namespace std;


int main()
{
   int n, x, cup = 0;
   bool ok = true;

   cin >> n;
   for (int i = 0; i < n; ++i)
   {
      cin >> x;
      if (cup == 1) x--;
      if (x < 0) ok = false;
      cup = x % 2;
   }
   ok = ok && (cup == 0);
   (ok) ? puts("YES") : puts("NO");
   return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/1003/problem/A
// https://codeforces.com/contest/1003/submission/46796608

#include <iostream>
#include <algorithm>
using namespace std;


int main()
{
	int v[101] = { 0 };
	int n, x, mx = -1;
	
	cin >> n;
	while (n--)
	{
		cin >> x;
		mx = max(mx, ++v[x]);
	}

	cout << mx;

	return 0;
}<file_sep>// https://codeforces.com/contest/488/problem/A
// https://codeforces.com/contest/488/submission/17418962

#include <iostream>
using namespace std;

bool valid(long long x) {
	while (x != 0) {
		if (x % 10 == 8 || x%10 == -8) return true;
		x /= 10;
	}
	return false;
}

int main() {

	long long n, k = 1;
	cin >> n;
	for (long long i = n+1; !valid(i); k++, i++);
	cout << k;
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/712/problem/A
// https://codeforces.com/contest/712/submission/21814728

#include <stdio.h>
using namespace std;


int main()
{
   
   int ai, bi, n;
   scanf("%d %d", &n, &ai);

   for (; n > 1; n--)
   {
      scanf("%d", &bi);
      printf("%d ", ai + bi);
      ai = bi;
   }
   printf("%d\n", ai);
   return 0;
}
#include <iostream>
using namespace std;


int main()
{
   ios::sync_with_stdio(false);
   
   int ai, bi, n;
   cin >> n;
   cin >> ai;

   for (; n > 1; n--)
   {
      cin >> bi;
      cout << ai + bi << ' ';
      ai = bi;
   }
   cout << ai << '\n';

   return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/problemset/problem/999/A
// https://codeforces.com/contest/999/submission/49378361
#include <iostream>
#include <fstream>
#include <chrono>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>
using namespace std;

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);
    
    int n, k, cnt = 0, idx = 0;
    
    cin >> n >> k;
    vector<int> v(n);

    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    
    for (idx = 0; idx < n; ++idx)
    {
        if (v[idx] > k) break;
        ++cnt;
    }

    for (int i = n - 1; i > idx; --i)
    {
        if (v[i] > k) break;
        ++cnt;
    }

    cout << cnt;
    return 0;
}<file_sep># https://codeforces.com/contest/579/problem/A
# https://codeforces.com/contest/579/submission/14411323

def power(a,b):
    if b==1:
        m = a
    elif b==0:
        m = 1
    elif b%2==0:
        m = power(a*a,b//2)
    else:
        m = a*power(a*a,(b-1)//2)
    return m
def find_bacteria(n):
    ans = power(2,1)
    i = 1
    while ans<n:
        i+=1
        ans = power(2,i)
    if ans>n:
        ans = power(2,i-1)
    return ans
n = int(input())
nr = 0
while n>1:
    p = find_bacteria(n)
    n = n-p
    nr += 1
if n ==1:
    nr += 1
print(nr)
<file_sep>// https://codeforces.com/contest/519/problem/C
// https://codeforces.com/contest/519/submission/17145705

#include <iostream>
#include <algorithm> 
using namespace std;


int main()
{
	int n, m;

	cin >> n >> m;
	cout << min(n, min(m, (n + m) / 3));

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/gym/101191/problem/C
// https://codeforces.com/gym/101191/submission/47897843

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

void init(vector<long long>& v)
{
	v.push_back(0);
	v.push_back(1);
	for (long long i = 2; v.back() <= 1e9; ++i)
	{
		v.push_back(v.back() + i);
	}
}

long long bin_search(vector<long long>& v, long long X)
{
	long long lo = 0;
	long long hi = v.size() - 1;
	long long idx = 0;

	while (lo <= hi)
	{
		long long mi = (lo + hi) / 2;

		if (v[static_cast<size_t>(mi)] > X) hi = mi - 1;
		else idx = mi, lo = mi + 1;
	}

	return idx;
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(nullptr);

	vector<long long> sums;
	string cbs = "";
	long long n = 0;

	cin >> n;
	init(sums);

	while(n > 0)
	{
		cbs = "(" + cbs + ")";
		--n;
		
		string nextCbs = "(";
		auto idx = bin_search(sums, n - 2);
		for (long long i = 0; i < idx; ++i) nextCbs += "()";
		nextCbs += ")";

		long long total = sums[static_cast<size_t>(idx)] + 2;
		if (n - total >= 0) cbs += nextCbs, n -= total;
	}

	
	cout << cbs;
	return 0;
}<file_sep>// https://codeforces.com/contest/839/problem/A
// https://codeforces.com/contest/839/submission/46637035

#include <iostream>
#include <algorithm>
using namespace std;



int main()
{
    int n, k, x, t = 0, d = -1;
   
    cin >> n >> k;
    for (int i = 0; i < n; ++i)
    {
        cin >> x;
        k -= min(8, t + x);
        t = t + x - min(8, t + x);
        if (k <= 0)
        {
            d = i + 1;
            break;
        }
    }

    cout << d;

    return 0;
}<file_sep>// https://codeforces.com/problemset/problem/1191/A
// https://codeforces.com/contest/1191/submission/68001731

#include <iostream>
#include <algorithm>
#include <string>
using namespace std;


int main()
{
    ios::sync_with_stdio(false); 
    cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);


    int x;
    cin >> x;

    if (x % 4 == 0) cout << "1 A";
    else if (x % 4 == 1) cout << "0 A";
    else if (x % 4 == 2) cout << "1 B";
    else cout << "2 A";

    return 0;
}<file_sep>// https://codeforces.com/contest/569/problem/B
// https://codeforces.com/contest/569/submission/17996677

#include <iostream>
#include <string.h>
#include <vector>
using namespace std;


int main(){
    int v[100003],f[100003],n;
    vector<int> ramas;
    cin>>n;
    int contor=0;
    memset(f,0,100003*sizeof(int));
    for(int i = 1; i<=n; i++){
        cin>>v[i];
        f[v[i]]++;
    }
    for(int i=1;i<=n;i++)
        if(f[i]==0)
            ramas.push_back(i);
    for(int i=1;i<=n;i++){
        if(f[v[i]]>1 || v[i]> n || v[i]<=0){//duplicate
            f[v[i]]--;
            cout << ramas[contor++] << " ";
        }
        else{
            cout << v[i] << " ";
        }
    }
    return 0;
}
<file_sep>// https://codeforces.com/contest/595/problem/A
// https://codeforces.com/contest/595/submission/17558105

#include <stdio.h>
#include <stdlib.h>


int main() {

	int n, m, x, y, i, j, nr;
	scanf("%d %d", &n, &m);
	for (i = 0, nr = 0; i < n; i++) {
		for (j = 0; j < 2 * m; j += 2) {
			scanf("%d %d", &x, &y);
			if (x || y) nr++;
		}
	}
	printf("%d", nr);

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/problemset/problem/1108/A
// https://codeforces.com/contest/1108/submission/49355225
#include <iostream>
#include <fstream>
#include <chrono>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <numeric>
#include <bitset>
using namespace std;

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr);

    int q, l1, r1, l2, r2;

    for (cin >> q; q > 0; --q)
    {
        cin >> l1 >> r1 >> l2 >> r2;
        
        if (l1 == r2) l1 = r1;
        cout << l1 << " " << r2 << "\n";
    }

    return 0;
}<file_sep>// https://codeforces.com/contest/913/problem/A
// https://codeforces.com/contest/913/submission/46626161

#include <iostream>
using namespace std;

int minpow()
{
    int i = 1;
    for(int j = 2; j <= 1e8; ++i, j = j<<1);
    return i;
}

int main()
{
    int n,m;
    cin>>n>>m;
    (n >= minpow()) ? cout << m
                    : cout << m % (1 << n);
    return 0;
}<file_sep>// https://codeforces.com/contest/710/problem/A
// https://codeforces.com/contest/710/submission/20566928

#include <stdio.h>
#include <stdlib.h>

int main()
{
    char c = getchar(), r = getchar();

    int rez = 0;

    if (c == 'a' || c == 'h')
    {
        if (r == '1' || r == '8')
        {
           rez = 3;
        }
        else rez = 5;
    }
    else
    {
        if (r == '1' || r == '8')
        {
            rez = 5;
        }
        else rez = 8;
    }

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

    return EXIT_SUCCESS;
}
<file_sep>// https://codeforces.com/problemset/problem/919/A
// https://codeforces.com/contest/919/submission/48049287
#include <iostream>
#include <iomanip>
#include <algorithm>
using namespace std;


int main()
{
    int n, m, a, b;
    double res = numeric_limits<double>::max();

    cin >> n >> m;
    while (n--)
    {
        cin >> a >> b;
        res = min(res, static_cast<double>(m * a) / static_cast<double>(b));
    }

    cout << setprecision(12) << fixed << res;

    return 0;
}<file_sep>// https://codeforces.com/contest/680/problem/A
// https://codeforces.com/contest/680/submission/18452312

#include <iostream>
using namespace std;

int main() {

	int v[102], x, i, s, st = 0;
	memset(v, 0, 102 * sizeof(int));
	for (i = 0; i < 5; i++) cin>>x, v[x]++, st += x;
	s = st;
	for (int i = 100; i > 0; i--) {
		if (v[i] >= 3) {
			if (st - i * 3 < s) s = st - i * 3;
		}
		else if (v[i] == 2) {
			if (st - i * 2 < s) s = st - i * 2;
		}
	}
	cout << s;

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/586/problem/A
// https://codeforces.com/contest/586/submission/17471048

#include <iostream>
using namespace std;

int main() {
	int n, i = 1, count = 0;
	char x, y, ok = '1';
	cin >> n;
	getchar();
	for (; i <= n && count == 0; i++) {
		x = getchar();
		if (x == '1') count++;
		getchar();
	}
	
	y = x;
	for (; i <= n; i++) {
		x = getchar();
		if (x == '1' && ok == '0' ) count+=2, ok = '1';
		else if (x == '1') count++;
		else {
			if (y == '1' && ok == '1') ok = '0';
			else if (y == '0' && ok == '0') ok = '1';
		}
		y = x;
		getchar();
	}
	cout << count;
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/246/problem/A
// https://codeforces.com/contest/246/submission/18055009

#include <iostream>
#include <random>
using namespace std;


int main() {

	int n;
	cin >> n;
	if (n < 3) puts("-1");
	else for (; n > 0; n--)cout << n << " ";

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/gym/101246/problem/E
// https://codeforces.com/gym/101246/submission/25245302

#include <iostream>
#include<fstream>
#include<string>
#include <queue>
#include <algorithm>
#include <set>
#include <string.h>

#define cin f
#define cout g

using namespace std;


int mat[110][110];

int main()
{

    ifstream f("input.txt");
    ofstream g("output.txt");
    int n,k;
    int mat[205][205];
    int vis[205];
    queue<pair<int,int>> v;
    set<int> sol;

    f>> n;

    for(int i = 1; i<= n; ++i)
        for(int j = 1; j<= n; ++j)
            f>>mat[i][j];

    f >> k;
    v.push(make_pair(1,1));
    int niv = 1, road;

    while(k > 0)
    {
        memset(vis,0,205*sizeof(int));
        f >> road;
        if (v.empty()) break;
        while(!v.empty() && v.front().second == niv)
        {
            int el = v.front().first;
            v.pop();
            for(int i = 1; i<=n; ++i) if (vis[i] == 0 && mat[el][i] == road) v.push(make_pair(i,niv+1)), vis[i] = 1;
        }
        niv++;
        k--;
    }

    while(!v.empty())
    {
        sol.insert(v.front().first);
        v.pop();
    }

    g<<sol.size()<<"\n";
    for(int el : sol) g<< el<<" ";


    f.close();
    g.close();

    return 0;
}<file_sep># https://codeforces.com/contest/448/problem/A
# https://codeforces.com/contest/448/submission/14009316

a,b,c=map(int,input().split())
r=int((a+b+c)/5)
if (a+b+c)%5!=0:
    r+=1
a,b,c=map(int,input().split())
r2=int((a+b+c)/10)
if (a+b+c)%10!=0:
    r2+=1
r+=r2
n=int(input())
if r>n:
    print('NO')
else:
    print('YES')
<file_sep>// https://codeforces.com/contest/478/problem/B
// https://codeforces.com/contest/478/submission/28727713

#include <iostream>
#include <string>
using namespace std;

int main() {

    int n, m;
    
    
    cin >> n >> m;
    
    unsigned long long mic = n / m, mic2 = n % m;
    unsigned long long mare = n - m  + 1;
    
    
    cout << mic2 * (mic + 1) * mic / 2 +  (m - mic2) * (mic - 1 ) * mic / 2<< " " << (mare - 1) * mare / 2;
    

    return 0;
    
}
<file_sep>// https://codeforces.com/contest/894/problem/A
// https://codeforces.com/contest/894/submission/46639459

#include <iostream>
#include <string>
#include <vector>
using namespace std;


int Bsearch0(vector<int>& Vec, int X)
{
    int lo = 0;
    int hi = Vec.size() - 1;
    int m;
    int found = -1;

    while (lo <= hi)
    {
        m = (lo + hi) / 2;
        if (Vec[m] > X) hi = m - 1;
        else found = m, lo = m + 1;
    }

    return found;
}

int Bsearch1(vector<int>& Vec, int X)
{
    int lo = 0;
    int hi = Vec.size() - 1;
    int m;
    int found = -1;

    while (lo <= hi)
    {
        m = (lo + hi) / 2;
        if (Vec[m] <= X) lo = m + 1;
        else found = m, hi = m - 1;
    }

    return found == -1 ? 0 : Vec.size() - found;
}

int main()
{
    string s;
    vector<int> q;
    vector<int> a;
    int t = 0;

    cin >> s;
    for (size_t i = 0; i < s.size(); ++i)
    {
        if (s[i] == 'A') a.push_back(i);
        else if (s[i] == 'Q') q.push_back(i);
    }

    for (const auto& pa : a)
    {
        t = t + (Bsearch0(q, pa) + 1) * Bsearch1(q, pa);
    }
    cout << t;
    return 0;
}<file_sep># https://codeforces.com/contest/486/problem/A
# https://codeforces.com/contest/486/submission/13960500

n=int(input())

if n%2==0:
    print(int(n/2))
else:
    print(int(-1-(n/2)))
    
<file_sep>// https://codeforces.com/contest/519/problem/A
// https://codeforces.com/contest/519/submission/14057025

#include <iostream>

using namespace std;

int white['Z'+1],black['z'+1];

void init()
{
    white['Q']=9; black['q']=9;
    white['R']=5; black['r']=5;
    white['B']=3; black['b']=3;
    white['N']=3; black['n']=3;
    white['P']=1; black['p']=1;
    white['K']=0; black['k']=0;
}

int main()
{
  char c;
  int black_points=0, white_points=0;
  init();
  for (int i=0;i<8;i++)
  {
      for (int j=0;j<8;j++)
      {
          cin>>c;
          if (c!='.' && c<'Z')
          {
              white_points+=white[c];
          }
          else if (c!='.')
          {
              black_points+=black[c];
          }
      }
  }
  if (white_points>black_points)
  {
      cout<<"White";
  }
  else if (white_points<black_points)
  {
      cout<<"Black";
  }
  else
  {
      cout<<"Draw";
  }

  return 0;

}
<file_sep># https://codeforces.com/contest/560/problem/A
# https://codeforces.com/contest/560/submission/14575554

n = int(input())
l = list(map(int,input().split()))
if 1 in l:
    print('-1')
else:
    print('1')
<file_sep>// https://codeforces.com/contest/764/problem/A
// https://codeforces.com/contest/764/submission/28727849

#include <iostream>
#include <string>
using namespace std;



int main() {

    int n, m, z;
    cin>>n>>m>>z;
    
    int gcd = 1;
    
    //gcd - zsisku
    for(int i=1; i<=z; i++)
    {
        if(n% i == 0 && m%i == 0) gcd = i;
    }

    int lcm = (n*m)/gcd;
    
    cout << (z/lcm);
    

    return 0;
    
}
<file_sep>// https://codeforces.com/contest/451/problem/B
// https://codeforces.com/contest/451/submission/18724654

#ifndef _CRT_NONSTDC_NO_WARNINGS
#define _CRT_NONSTDC_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
using namespace std;

void swap(int&a, int&b) {int aux = a;a = b;b = aux;}

int main() {

	int n, v[100005], i = 0, j;
	vector<int> rez;
	
	for (scanf("%d", &n); i < n; scanf("%d", &v[i++]));
	
	i = 0;
	while (i < n - 1) {
		if (v[i] > v[i + 1]) {
			rez.push_back(i + 1);
			j = i;
			while (j < n - 1 && v[j] > v[j + 1]) j++;
			rez.push_back(j+1);
			swap(v[i], v[j]);
			if (i > 0 && v[i - 1] > v[i]) i = n, rez.push_back(2);
			else i = j;
		}
		else i++;
	}

	(rez.size() > 2) ? puts("no") : ((rez.size() == 0) ? puts("yes\n1 1\n") : printf("yes\n%d %d\n", rez[0], rez[1]));
	return EXIT_SUCCESS;
}

#endif //_CRT_NONSTDC_NO_WARNINGS<file_sep>// https://codeforces.com/contest/712/problem/B
// https://codeforces.com/contest/712/submission/21840726

#include <string>
#include <iostream>
using namespace std;

#define ABS(x) (((x) > (0)) ? (x) : (-x))


int main()
{
   string s;
   cin >> s;
   int y, x = y = 0;
   if (s.size() % 2 == 1)
   {
      puts("-1");
      return EXIT_SUCCESS;
   }
 
   for (size_t i = 0; i < s.size(); ++i)
   {
      if (s[i] == 'U') y++;
      else if (s[i] == 'D') y--;
      else if (s[i] == 'L') x--;
      else if (s[i] == 'R') x++;
   }

   cout << ABS( ABS(x) / 2 + ABS(y) / 2) + ABS(x) % 2;

   return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/519/problem/B
# https://codeforces.com/contest/519/submission/14419382

n = int(input())
l = list(map(int,input().split()))
dicts = {}
for el in l:
    if el in dicts.keys():
        dicts[el]+=1
    else:
        dicts[el]=1
p = list(map(int,input().split()))
dictssec={}
for el in p:
    if dicts[el]>1:
        dicts[el]-=1
    else:
        del(dicts[el])
    if el in dictssec.keys():
        dictssec[el]+=1
    else:
        dictssec[el]=1
l = list(map(int,input().split()))
h = list(dicts.keys())
print(h[0])
for el in l:
    if dictssec[el]>1:
        dictssec[el]-=1
    else:
        del(dictssec[el])
h = list(dictssec.keys())
print(h[0])
    
<file_sep># https://codeforces.com/contest/136/problem/A
# https://codeforces.com/contest/136/submission/13580602

def find(k,l):
    for i in range(len(l)):
        if l[i]==k:
            return i+1

n = int(input())
l = list(map(int,input().split()))
for i in range(n):
    print(find(i+1,l),end=' ')
    
<file_sep>// https://codeforces.com/contest/456/problem/B
// https://codeforces.com/contest/456/submission/17592868

#include <iostream>
#include <string>
using namespace std;

int main() {
	string s;
	getline(cin, s);
	if (s.size() == 1) {
		if (s[0] == '0' || s[0] == '4' || s[0] == '8') putchar('4');
		else putchar('0');
	} 
	else {
		if (stoi(s.substr(s.size() - 2, 2)) % 4 == 0) putchar('4');
		else putchar('0');
	}
	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/231/problem/A
# https://codeforces.com/contest/231/submission/13406348

n=int(input())
nr=0
for i in range(n):
    a,b,c=map(int, input().split())
    nraux=0
    if a==1:
        nraux+=1
    if b==1:
        nraux+=1
    if c==1:
        nraux+=1
    if nraux>=2:
        nr+=1
print(nr)
<file_sep>// https://codeforces.com/contest/606/problem/C
// https://codeforces.com/contest/606/submission/17916901

#include <iostream>
using namespace std;


int main() {

	int v[100002], n, x, mx = 0;
	memset(v, 0, 100002 * sizeof(int));
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		v[x] = 1 + v[x - 1];
		if (v[x] > mx) mx = v[x];
	}
	cout << n - mx;

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/791/problem/C
// https://codeforces.com/contest/791/submission/25626271

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long 
#define ull unsigned long long

/*------------------------------------------------------------------*/
int n, k, idx;
int nou[60];

string t = "Aa";

string next(int idx)
{
   if (t[t.size() - 1] != 'z')t[t.size() - 1]++;
   else t += 'a';
   return t;
}

int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
   int amAjuns = 1;
   string s, last = next(idx);
   cin >> n >> k;
   vector<string> sol;

   for(int i = 1; i<=n-k+1;++i)
   {
      cin >> s;
      if (s == "YES")
      {
         for (int j = max(i, amAjuns); j <= i + k - 1; ++j)sol.push_back(next(++idx));
         amAjuns = i + k;
      }
      else
      {
         if (i == 1) sol.push_back(next(idx)), amAjuns++;
         sol.push_back(sol[i - 1]);
         amAjuns++;
      }
   }
   while (amAjuns++ <= n) sol.push_back(next(++idx));

   for (string s : sol)cout << s<<" ";
   

   return 0;
}<file_sep>// https://codeforces.com/contest/743/problem/D
// https://codeforces.com/contest/743/submission/22983812

#include <vector>
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

vector<int> graph[200005];
vector<long long> cost(200005, 0);
vector<bool> visited(200005, false);
vector<long long> maxSuma(200005, LLONG_MIN);
int n;
long long ans = LLONG_MIN;

void dfs(int nodulet)
{
   visited[nodulet] = true;
   long long mare  = LLONG_MIN;
   long long mare2 = LLONG_MIN;
   long long sumaFii = 0;

   for (auto vecin : graph[nodulet])
   {
      if (visited[vecin] == true) continue;
      dfs(vecin);
      sumaFii += cost[vecin];
      if (maxSuma[vecin] >= mare)
      {
         mare2 = mare;
         mare = maxSuma[vecin];
      }
      else if (maxSuma[vecin] > mare2)
      {
         mare2 = maxSuma[vecin];
      }
   }
   cost[nodulet] += sumaFii;
   maxSuma[nodulet] = max(mare, cost[nodulet]);
   if (mare != LLONG_MIN && mare2 != LLONG_MIN) ans = max(ans, mare + mare2);
}

int main()
{
   scanf("%d", &n);
   for (int i = 1; i <= n; ++i) scanf("%I64d", &cost[i]);
   int x, y;
   for (int i = 0; i < n - 1; ++i)
   {
      scanf("%d %d", &x, &y);
      graph[x].push_back(y);
      graph[y].push_back(x);
   }
   dfs(1);

   if (ans == LLONG_MIN) puts("Impossible");
   else cout << ans;

   return 0;
}<file_sep># https://codeforces.com/contest/499/problem/B
# https://codeforces.com/contest/499/submission/16472830

n,m = map(int,input().split())
dic = {}
while m > 0 :
    key,value = input().split()
    dic[key] = value;
    m -= 1 
l = list(input().split())
for el in l:
    if len(el) <= len(dic[el]):
        print(el, sep = ' ', end = ' ')
    else:
        print(dic[el], sep = ' ', end = ' ')
<file_sep>// https://codeforces.com/contest/608/problem/A
// https://codeforces.com/contest/608/submission/18043778

#include <iostream>
using namespace std;



int main() {

	int n, s, v[1001], sm = 0, et, arrival;
	memset(v, 0, 1001 * sizeof(int));

	cin >> n >> s;
	for (int i = 0; i < n; i++) {
		cin >> et >> arrival;
		if (v[et] < arrival) v[et] = arrival;
	}

	sm = 0;
	for (int i = s; i > 0; i--, sm++) {
		if (sm < v[i]) sm += v[i] - sm;
	}
	cout << sm;
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/731/problem/A
// https://codeforces.com/contest/731/submission/21480669

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;



int main()
{

   string s;
   cin >> s;
   int sum, ma, mi;
   size_t size = s.size();
 

   sum = min(s[0] - 'a', 27 - (s[0] - 96));

   for (size_t i = 1; i < size; ++i)
   {
      if (s[i] > s[i - 1]) ma = s[i], mi = s[i - 1];
      else ma = s[i - 1], mi = s[i];
      sum += min(ma - mi, 26 - (ma - mi));
  }

   cout << sum;
   return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/621/problem/A
// https://codeforces.com/contest/621/submission/16450717

#include <stdio.h>
#include <stdlib.h>

#define MAX 0x3B9ACA01

int main(){
	int n,i,odds = 0;
	unsigned long long x, oddmin = MAX, s = 0;
	scanf_s("%d", &n);

	for (i = 0; i < n; i++){
		scanf_s("%llu", &x);
		s += x;
		if (x & 1) {
			odds++;
			if (x < oddmin) oddmin = x;
		}
	}

	if (odds & 1) s -= oddmin;
	printf("%llu", s);
	return EXIT_SUCCESS;
}
#include <stdio.h>
#include <stdlib.h>

#define MAX 0x3B9ACA01

int main(){
	int n,i,odds = 0;
	unsigned long long x, oddmin = MAX, s = 0;
	scanf_s("%d", &n);

	for (i = 0; i < n; i++){
		scanf_s("%llu", &x);
		s += x;
		if (x % 2 == 1) {
			odds++;
			if (x < oddmin) oddmin = x;
		}
	}

	if (odds % 2 == 1) s -= oddmin;
	printf("%llu", s);
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/548/problem/A
// https://codeforces.com/contest/548/submission/17433560

#include <iostream>
#include <string>
using namespace std;

bool ispal(const string& p);

int main() {

	string s,p;
	int n,sz;
	cin >> s >> n;
	if (s.size() % n != 0) { puts("NO"); goto Clean; }
	sz = s.size() / n;
	for (int pivot = 0; pivot < n; pivot++) {
		p = s.substr(sz*pivot, sz);
		if (!ispal(p)) { puts("NO"); goto Clean; };
	}
	puts("YES");
Clean:
	return EXIT_SUCCESS;
}
bool ispal(const string& p) {
	int size = p.size();
	for (int i = 0; i < size / 2; i++) {
		if (p[i] != p[size - i - 1]) return false;
	}
	return true;
}<file_sep># https://codeforces.com/contest/270/problem/A
# https://codeforces.com/contest/270/submission/14468305

n = int(input())
while n>0:
    x = int(input())
    if 360 %  (180-x) ==0:
        print('YES')
    else:
        print('NO')
    n-=1
    
<file_sep>// https://codeforces.com/contest/472/problem/C
// https://codeforces.com/contest/472/submission/18054753

#include <iostream>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

class Elev {
public:
	string nume;
	string prenume;
	Elev(const string& nume, const string& prenume) : nume{ nume }, prenume{ prenume } {};
	Elev() :nume{ "" }, prenume{ "" } {};
};

int main() {
	int n, poz;
	bool ok = true;
	Elev first, last;
	string nume, prenume;
	vector <Elev> v;
	cin >> n;

	for (int i = 1; i <= n; i++) {
		cin >> nume >> prenume;
		v.push_back(Elev(nume, prenume));
	}

	cin >> poz;
	nume = min(v[poz - 1].nume, v[poz - 1].prenume);
	int i = 2;
	while (i <= n && ok == true) {
		cin >> poz;
		last = v[poz - 1];
		if (last.nume >= nume && last.prenume < nume) nume = last.nume;
		else if (last.prenume >= nume && last.nume < nume) nume = last.prenume;
		else if (last.nume >= nume && last.prenume >= nume) nume = min(last.nume, last.prenume);
		else { ok = false; }
		i++;
	}

	(ok) ? puts("YES") : puts("NO");

	return EXIT_SUCCESS;
}
<file_sep>// https://codeforces.com/contest/749/problem/D
// https://codeforces.com/contest/749/submission/23162259

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define INT32_MIN (-1)

vector<int> arbore(800005, INT32_MIN);
vector<int> indecsi(800005, INT32_MIN);
vector<int> v[200005];
int maxi = INT32_MIN;
int pos = INT32_MIN;

void update(int node, int left, int right, int value, int pos)
{
   if (left == right)
   {
      arbore[node] = value;
      indecsi[node] = pos;
      return;
   }

   int mid = (left + right) / 2;
   if (pos <= mid) update(2 * node, left, mid, value, pos);
   else update(2 * node + 1, mid + 1, right, value, pos);

   if (arbore[node * 2] > arbore[node * 2 + 1])
   {
      indecsi[node] = indecsi[node * 2];
      arbore[node] = arbore[node * 2];
   }
   else
   {
      indecsi[node] = indecsi[node * 2 + 1];
      arbore[node] = arbore[node * 2 + 1];
   }
}

void Querry(int node, int left, int right, int start, int finish)
{
   if (start <= left && right <= finish)
   {
      if (maxi < arbore[node]) maxi = arbore[node], pos = indecsi[node];
      return;
   }

   int mid = (left + right) / 2;
   if (start <= mid) update(2 * node, left, mid, start, finish);
   if (mid < finish) update(2 * node + 1, mid + 1, right, start, finish);
}

int main()
{
   int n, contestant, bid, x;
   scanf("%d", &n);

   for (int i = 1; i <= n; ++i)
   {
      v[i].push_back(INT32_MIN);
      scanf("%d %d", &contestant, &bid);
      update(1, 1, n, bid, contestant);
      v[contestant].push_back(bid);
   }

   for (int i = 1; i <= n; ++i)
   {
      sort(v[i].begin(), v[i].end());
   }

   int m, sz;
   vector<int>querry;
   scanf("%d", &m);

   for (int i = 0; i < m; ++i)
   {
      querry.clear();
      scanf("%d", &sz);
      pos = INT32_MIN;
      maxi = INT32_MIN;
      for (int j = 0; j < sz; ++j)
      {
         scanf("%d", &x);
         querry.push_back(x);
         update(1, 1, n, INT32_MIN, x);
      }
      Querry(1, 1, n, 1, n);
      if (pos == INT32_MIN) puts("0 0");
      else
      {
         int maximLocal = maxi;
         int posLocal = pos;
         pos = INT32_MIN;
         maxi = INT32_MIN;
         querry.push_back(posLocal);
         update(1, 1, n, INT32_MIN, posLocal);
         Querry(1, 1, n, 1, n);
         if (maxi == maximLocal) printf("0 0\n");
         else
         {
            maximLocal = *(lower_bound(v[posLocal].begin(), v[posLocal].end(), maxi + 1));

            printf("%d %d\n", posLocal, maximLocal);
         }
      }

      for (int p : querry)
      {
         update(1, 1, n, v[p][v[p].size() - 1], p);
      }
   }

   return 0;
}<file_sep>// https://codeforces.com/contest/735/problem/A
// https://codeforces.com/contest/735/submission/22532948

#include <iostream>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;


int main()
{
   int n, k;
   int g, t;
   string s;
   cin >> n >> k >> s;
   bool ok = true;
   for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'G')
         g = i;
      if (s[i] == 'T')
         t = i;
   }

   if ((g - t) % k == 0) {
      int A, B;
      A = min(g, t);
      B = max(g, t);

      while (ok && A != B) {

         if (s[A] == '#')
            ok = false;
         A += k;

      }
   }
   else
      ok = false;

   cout << ((ok) ? ("YES") : ("NO"));

   return 0;
}<file_sep>// https://codeforces.com/contest/230/problem/A
// https://codeforces.com/contest/230/submission/14058507

#include <iostream>
#include <algorithm>
using namespace std;

struct dragon{
    int level,power;
};

bool accompare (dragon lhs, dragon rhs){return lhs.level<rhs.level;}

int main()
{
   dragon list[10000];
   int n,s;
   cin>>s>>n;
   for (int i=0;i<n;i++)
   {
       cin>>list[i].level>>list[i].power;
   }
   sort(list,list+n,accompare);
   bool ok=true;
   int i=0;
   while (i<n && ok==true)
   {
       if (s<=list[i].level)
       {
           ok = false;
       }
       else
       {
           s=s+list[i].power;
           i++;
       }
   }
   if (ok==false)
   {
       cout<<"NO";
   }
   else
   {
       cout<<"YES";
   }
   return 0;
}
<file_sep># https://codeforces.com/contest/50/problem/A
# https://codeforces.com/contest/50/submission/13405987


m,n = map(int, input().split())
c=m*n/2
print(int(c))

<file_sep>// https://codeforces.com/contest/688/problem/B
// https://codeforces.com/contest/688/submission/22867635

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;


int main()
{
   string s;
   cin >> s;
   cout << s;
   reverse(s.begin(), s.end());
   cout << s;
   
   return 0;
}

<file_sep># https://codeforces.com/contest/459/problem/B
# https://codeforces.com/contest/459/submission/14543529

n = int(input())
l = sorted(list(map(int,input().split())))
nr = 0
nr2 = 0
i = 0
if l[0]==l[n-1]:
    nr = (n)*(n-1)//2
    n = n-1
else:
    while i<n-1 and l[0] == l[i]:
        i,nr = i+1, nr+1
    n -= 1
    i = n
    while i>1 and l[n] == l[i]:
        i, nr2 = i-1, nr2+1
    nr = nr*nr2
    if len(l)==2:
        nr+=1
print(l[n]-l[0],nr)
<file_sep>// https://codeforces.com/contest/465/problem/A
// https://codeforces.com/contest/465/submission/17145967

#include <iostream>
using namespace std;


int main()
{

	int n, count = 1;
	char x;
	bool ok = true;

	cin >> n;
	getchar();

	while (ok)
	{
		x = getchar();

		if (x != '1') ok = false;
		else count++;
	}
	if (x != '0') count--;
	cout << count;
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/599/problem/B
// https://codeforces.com/contest/599/submission/14385888

#include <iostream>

using namespace std;

int main()
{
    int a[100001],f[100001],b[100001],n,m;
    for (int i=1;i<=100001;i++)
    {
        a[i]=-1;
    }
    cin>>n>>m;
    for (int i=1;i<=n;i++)
    {
        cin>>f[i];
    }
    for (int i=1;i<=m;i++)
    {
        cin>>b[i];
    }
    for (int i=1;i<=n;i++)
    {
        if (a[f[i]]==-1)
        {
            a[f[i]]=i;
        }
        else
        {
            a[f[i]]=-999;
        }
    }
    bool okimp = true;
    bool okamb = true;
    for (int i=1;i<=m;i++)
    {
        if (a[b[i]]==-1)
        {
            okimp = false;
        }
        else
        {
            if (a[b[i]]==-999)
            {
                okamb = false;
            }
        }
    }

    if (!okimp){cout<<"Impossible";}
    else if (!okamb){cout<<"Ambiguity";}
    else
    {
        cout<<"Possible"<<"\n";
        for (int i=1;i<=m;i++)
        {
            cout<<a[b[i]]<<" ";
        }
    }

    return 0;
}
<file_sep>// https://codeforces.com/contest/570/problem/A
// https://codeforces.com/contest/570/submission/14395674

#include <iostream>

using namespace std;

long long v[102];

int main()
{
    int n,m,x;
    int cand_for_city,cand_index,grand_total=-1,total_index=-1;
    cin>>m>>n;
    for (int i=1;i<=n;i++)
    {
        cand_for_city = -1;

        for (int j=1;j<=m;j++)
        {
            cin>>x;
            if (x>cand_for_city)
            {
                cand_for_city = x;
                cand_index = j;
            }
        }
    v[cand_index]++;
    if (grand_total<v[cand_index]||(grand_total==v[cand_index] && cand_index<total_index))
    {
        grand_total=v[cand_index];
        total_index=cand_index;
    }
    }
    cout<<total_index;
    return 0;
}
<file_sep>// https://codeforces.com/contest/611/problem/A
// https://codeforces.com/contest/611/submission/16614944

#include <iostream>
#include <string.h>
using namespace std;

int main(int argc, char* argv[]) {

	int months[] = { 0,31,29,31,30,31,30,31,31,30,31,30,31 }, days[] = { 0,52,52,52,52,53,53,52 }, n, sum = 0;
	char s[10];
	cin >> n >> s >> s;
	if (!strcmp(s, "week")) cout << days[n];
	else {
		for (int i = 1; i <= 12; i++) if (months[i] >= n) sum++;
		cout << sum;
	}
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/277/problem/A
// https://codeforces.com/contest/277/submission/48031502

#include <map>
#include <algorithm>
#include <set>
#include <iostream>
using namespace std;

int find(map<int, int>& parent, int x)
{
    if (x == parent[x]) return x;
    return parent[x] = find(parent, parent[x]);
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);

    int n, m, k, x, y, ctx = 0;
    map<int, int> languages;
    set<int> masters;

    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    {
        cin >> k;
        if (k == 0)
        {
            ++ctx;
            continue;
        }

        cin >> x;
        if (languages[x] == 0) languages[x] = x;
        auto px = find(languages, x);


        for (int j = 2; j <= k; ++j)
        {
            cin >> y;
            if (languages[y] == 0) languages[y] = y;
            auto py = find(languages, y);
           
            languages[py] = px;
        }
    }

    for (auto& keyValuePair : languages)
    {
        masters.insert(find(languages, keyValuePair.first));
    }

    if (masters.size() == 0) cout << ctx;
    else cout << masters.size() - 1 + ctx;

    return 0;
}<file_sep>// https://codeforces.com/contest/606/problem/D
// https://codeforces.com/contest/606/submission/17913074

#include <iostream>
#include <algorithm>
using namespace std;

typedef struct _DATE {
	int cost, in, poz;
}DATE, *DATEPTR;

typedef struct _MUCHIE {
	int x, y;
}MUCHIE, *MUCHIEPTR;

int main() {
	DATEPTR date;
	MUCHIEPTR muchii;
	int v[100002], n, m, lastNode = 2, currNode = 1;
	for (int i = 1; i < 100002; i++) v[i] = i + 2;
	cin >> n >> m;
	
	date = (DATEPTR)malloc((m+1) * sizeof(DATE));
	muchii = (MUCHIEPTR)malloc((m+1)* sizeof(MUCHIE));

	for (int i = 1; i <= m; i++) {
		cin >> date[i].cost >> date[i].in;
		date[i].poz = i;
	}

	sort(date+1, date + 1 + m, [&](DATE& dataLeft, DATE& dataRight) {
		return (dataLeft.cost < dataRight.cost ||
			dataLeft.cost == dataRight.cost && dataLeft.in > dataRight.in || 
			dataLeft.cost == dataRight.cost && dataLeft.in == dataRight.in && dataLeft.poz < dataRight.poz
			);
	});

	if (date[1].in == 0) {
		puts("-1");
		goto Cleanup;
	}
	muchii[date[1].poz].x = 1;
	muchii[date[1].poz].y = 2;
	for (int i = 2; i <= m; i++) {
		if (date[i].in == 1) {
			muchii[date[i].poz].x = lastNode;
			muchii[date[i].poz].y = lastNode + 1;
			lastNode++;
			currNode = 1;
		}
		else {
			if (v[currNode] <= lastNode) {
				muchii[date[i].poz].x = currNode;
				muchii[date[i].poz].y = v[currNode];
				v[currNode]++;
				if (v[currNode] > lastNode)currNode++;
			}
			else {
				puts("-1");
				goto Cleanup;;
			}
		}
	}
	
	for (int i = 1; i <= m; i++)cout << muchii[i].x << " " << muchii[i].y << "\n";

Cleanup:
	free(muchii);
	free(date);
	return EXIT_SUCCESS;

}<file_sep># https://codeforces.com/contest/61/problem/A
# https://codeforces.com/contest/61/submission/13614120

a=input()
b=input()
c=[]
for i in range(len(a)):
    if a[i]==b[i]:
        c.append(0)
    else:
        c.append(1)
for i in range (len(a)):
    print(c[i],sep='', end='')
<file_sep>// https://codeforces.com/contest/629/problem/A
// https://codeforces.com/contest/629/submission/17462230

#include <iostream>
using namespace std;

int main() {

	int lin[101], col[101], n, s = 0;
	memset(lin, 0, 101 * sizeof(int));
	memset(col, 0, 101 * sizeof(int));
	cin >> n; getchar();

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (getchar() == 'C') lin[i]++, col[j]++;
		}
		getchar();
	}
	for (int i = 1; i <= n; i++) s += (lin[i] - 1)*lin[i] / 2 + (col[i] - 1) * col[i] / 2;
	cout << s;

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/732/problem/B
// https://codeforces.com/contest/732/submission/21650297

#include <stdio.h>
#include <stdlib.h>



int main()
{
   int n, k, v[504], s = 0;

   scanf("%d %d", &n, &k);
   for (int i = 0; i < n; ++i) scanf("%d", &v[i]);

   for (int i = 1; i < n; ++i)
   {
      if (v[i - 1] + v[i] < k)
      {
         s += (k - (v[i - 1] + v[i]));
         v[i] += (k - (v[i - 1] + v[i]));
      }
   }
   printf("%d\n", s);
   for (int i = 0; i < n; ++i) printf("%d ", v[i]);

   return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/217/problem/A
// https://codeforces.com/contest/217/submission/48030693

#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
using namespace std;


int find(map<int, int>& parent, int x)
{
    if (x == parent[x]) return x;
    return parent[x] = find(parent, parent[x]);
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int n, x, y;
    map<int, int> uniX;
    map<int, int> east;

    set<int> newDrifts;
    
    cin >> n;

    for (int i = 1; i <= n; ++i)
    {
        cin >> x >> y;

        if (uniX[x] == 0) uniX[x] = x;
        if (east[y] == 0) east[y] = x;
        
        auto px = find(uniX, x);
        auto py = find(uniX, east[y]);

        uniX[py] = px;
        east[y] = px;
    }

    for (auto& keyValuePair : uniX)
    {
        newDrifts.insert(find(uniX, keyValuePair.first));
    }


    cout << newDrifts.size() - 1;

    return 0;
}<file_sep>// https://codeforces.com/contest/598/problem/A
// https://codeforces.com/contest/598/submission/17154517

#include <iostream>
using namespace std;


int main()
{
	int t;
	unsigned long long n, s1, s2, ratio;
	long long s;
	cin >> t;
	for (; t > 0; t--)
	{
		cin >> n;
		s1 = (1 + n) * n / 2;
		ratio = 1;
		while (ratio <= n) ratio <<= 1;
		s2 = ratio - 1;
		s = (s1 - 2 * s2);
		cout << s << endl;
	}

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/368/problem/B
// https://codeforces.com/contest/368/submission/25721896

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long 
#define ull unsigned long long

/*------------------------------------------------------------------*/
 
int n, m, ct;
unordered_map<int, bool> mp;
int pt[100005], dp[100005];

int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);

   cin >> n >> m;
   for (int i = 1; i <= n; ++i) cin >> pt[i];
   for(int i = n; i > 0; --i)
   {
      if (mp[pt[i]] != true) ct++;
      mp[pt[i]] = true;
      dp[i] = ct;
   }
   for(int x, i = 1; i<=m;++i )
   {
      cin >> x;
      cout << dp[x] << "\n";
   }

   return 0;
}<file_sep>// https://codeforces.com/contest/552/problem/A
// https://codeforces.com/contest/552/submission/17433232

#include <stdio.h>
#include <stdlib.h>


int main() {

	int cnt = 0, n, x1, y1, x2, y2;
	scanf("%d", &n);
	for (; n > 0; n--) {
		scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
		cnt += (x2 - x1 + 1) * (y2 - y1 + 1);
	}
	printf("%d", cnt);

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/758/problem/A
// https://codeforces.com/contest/758/submission/27364470

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int n;
	int mx = numeric_limits<int>::min();
	vector<int> vct(100, 0);
	int s = 0;

	cin >> n;
	for (int i = 0; i < n; ++i)cin >> vct[i] , mx = max(mx, vct[i]);
	for (int i = 0; i < n; ++i) s += mx - vct[i];
	cout << s;


	return 0;
}
<file_sep>// https://codeforces.com/contest/219/problem/A
// https://codeforces.com/contest/219/submission/18041939

#include <iostream>
#include <string>
using namespace std;


int main() {
	int n, v[28], min;
	string s;
	cin >> n >> s;
	min = n;
	memset(v, 0, 28 * sizeof(int));

	for (size_t i = 0; i < s.size(); i++) v[s[i] - 'a']++;
	for (size_t i = 0; i < 28; i++) {
		if (v[i] != 0) {
			if (v[i] % n != 0) {
				cout << -1;
				goto exit;
			}
			else if (min > v[i]) min = v[i];
		}
	}
	for (int i = 0; i < min; i++) {
		for (size_t j = 0; j < 28; j++) {
			for (int k = 0; k < v[j] / n; k++) {
				putchar(j + 'a');
			}
		}
	}

exit:
	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/gym/100810/problem/C
// https://codeforces.com/gym/100810/submission/18234771

#include <iostream>
#include <string.h>
using namespace std;

int vals( const string& str){
    int nr = 0;
    int i = 0;
    int size = str.size();

    while (i < size && str[i] == 'M')nr+=1000,i++;
    if (i < size && i+1 < size && str[i] == 'C' && str[i + 1] == 'M') nr+=900, i+=2;
    if (i < size && str[i] == 'D') nr += 500, i++;
    if (i < size && i+1 < size && str[i] == 'C' && str[i + 1] == 'D') nr+=400, i+=2;
    while (i < size && str[i] == 'C')nr+=100,i++;
    if (i < size && i+1 < size && str[i] == 'X' && str[i + 1] == 'C') nr+=90, i+=2;
    if (i < size && str[i] == 'L') nr += 50, i++;
    if (i < size && i+1 < size && str[i] == 'X' && str[i + 1] == 'L') nr+=40, i+=2;
    while (i < size && str[i] == 'X')nr+=10,i++;
    if (i < size && i+1 < size && str[i] == 'I' && str[i + 1] == 'X') nr+=9, i+=2;
    if (i < size && str[i] == 'V') nr += 5, i++;
    if (i < size && i+1 < size && str[i] == 'I' && str[i + 1] == 'V') nr+=4, i+=2;
    while (i < size && str[i] == 'I')nr+=1,i++;
    if (i < size && str[i] == 'O') nr = 0;

    return nr;
}

string roman(int val){
    string roman = "";

    while (val >= 1000) roman+="M", val-=1000;
    if (val >= 900) roman +="CM", val-=900;
    if (val >= 500) roman+="D", val-=500;
    if (val >= 400) roman+="CD",val-=400;
    while (val >= 100) roman+="C",val-=100;
    if (val >= 90) roman+="XC",val-=90;
    if (val >= 50) roman+="L",val-=50;
    if (val >= 40) roman+="XL",val-=40;
    while (val >= 10)roman+="X",val-=10;
    if (val>=9) roman+="IX", val-=9;
    if (val>=5) roman+="V", val-=5;
    if (val>=4) roman+="IV", val-=4;
    while (val >= 1) roman+="I",val--;
    if (roman == "" && val == 0) roman = "O";
    return roman;
}

bool is_digit(char c){
    return (c == '0' || c=='1' || c =='2' ||c == '3' || c=='4' || c=='5' || c=='6' || c=='7' || c=='8' || c=='9');
}

int main()
{
     string line = "";
     int v[10];
     for (int i = 0; i< 10; i++) v[i] = -1;

     while (line != "QUIT"){
        cin>>line;
        if (line == "RESET"){
            cout<<"Ready\n";
            for (int i = 0; i< 10; i++) v[i] = -1;
        }
        else if (line == "QUIT"){
            cout<<"Bye\n";
        }
        else{
            int registru = line[0] - 48;
            int val = 0;
            char op = '+';
            int i = 2;
            bool ok = true;
            if (line[2] == '-' || line[2] == '+'){
                cout<<"Error\n";
            }else{
                while (i < line.size() && ok){
                    string expr = "";
                    while(i < line.size() && !is_digit(line[i]) && line[i] != '+' && line[i] !='-'){
                            expr+=line[i];
                            i++;
                    }
                    if (expr == ""){
                        if (is_digit(line[i])){
                            int cifra = line[i] - 48;
                            if (v[cifra] == -1){
                                  ok = false;
                            }
                            else{
                                if (op =='+') val+=v[cifra];
                                else val-=v[cifra];
                            }
                        }
                        else op = line[i];
                        i++;
                    } else{
                        if (op =='+') val+=vals(expr);
                        else val-=vals(expr);
                    }
                }
                if (val < 0 || val > 10000) ok = false;
                if (!ok) cout<<"Error\n";
                else{
                     v[registru] = val;
                     cout<<registru<<"="<<roman(val)<<"\n";
                }
            }


        }
     }

    return 0;
}<file_sep>// https://codeforces.com/contest/716/problem/A
// https://codeforces.com/contest/716/submission/21733770

#include <stdio.h>
#include <stdlib.h>


int main()
{

   int c, n, ct = 1, f, cur;
   scanf("%d %d %d", &n, &c, &f);
   for (int i = 1; i < n; ++i)
   {
      scanf("%d", &cur);
      if (cur - f> c)
      {
         ct = 1;
      }
      else ct++;
      f = cur;
   }
   printf("%d", ct);

   return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/432/problem/A
// https://codeforces.com/contest/432/submission/14416498

#include <iostream>

using namespace std;

int main()
{
   int n,k,x,nr=0;
   cin>>n>>k;
   while (n>0)
   {
       cin>>x;
       if (x+k<=5){nr++;}
       n--;
   }
   cout<<nr/3;
   return 0;

}
<file_sep>// https://codeforces.com/contest/651/problem/B
// https://codeforces.com/contest/651/submission/47181097

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;


int main()
{
	int n, x, nr = 0;
	
	map<int, int> frecv;
	set<int> elements;
	cin >> n;

	for (int i = 0; i < n; ++i)
	{
		cin >> x;
		frecv[x]++;
		elements.insert(x);
	}

	for (auto& keyValuePair : frecv)
	{
		while (keyValuePair.second != 0)
		{
			--keyValuePair.second;
			auto current = keyValuePair.first;
			for (auto next = elements.upper_bound(current); next != elements.end(); next = elements.upper_bound(current))
			{
				++nr;
				current = *next;
				if (--frecv[current] == 0)
				{
					elements.erase(current);
				}
			}
		}

	}
	cout << nr;

	return 0;
}<file_sep>// https://codeforces.com/contest/791/problem/B
// https://codeforces.com/contest/791/submission/25625859

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <vector>
#include <cstdio>
#include <string>
using namespace std;

#define ll long long 
#define ull unsigned long long

/*------------------------------------------------------------------*/

const int NMAX = 150006;
int n, m;
vector<int> graph[NMAX];
int vis[NMAX];

ll noduri, muchii;

void dfs(int node)
{
   vis[node] = 1;
   noduri++;

   for(auto g: graph[node])
   {
      muchii++;
      if (vis[g] == 0)
      {
         dfs(g);
      }
   }
}

int main()
{
   ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
   int x, y;
   scanf("%d %d", &n, &m);
   for(int i = 0; i< m; ++i)
   {
      scanf("%d %d", &x, &y);
      graph[x].push_back(y);
      graph[y].push_back(x);
   }
   bool ok = true;
   for(int i = 1; i<=n; ++i)
   {
      if(vis[i] == 0)
      {
         noduri = muchii = 0;
         dfs(i);
         if (muchii != (noduri *(noduri - 1))) ok = false;
      }
   }
   (ok) ? cout << "YES\n" : cout << "NO\n";



   return 0;
}<file_sep>// https://codeforces.com/contest/741/problem/B
// https://codeforces.com/contest/741/submission/23036476

#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <stdio.h>
#include <algorithm>
using namespace std;

typedef struct HOS
{
   int beauty;
   int weight;
   HOS() { beauty = 0, weight = 0; }
}HOS;

int parent[1005], bestDP[1005], usedDP[1005];
HOS basics[1005];
HOS combs[1005];
vector<HOS> groupies[1005];

int find(int x)
{
   return (x == parent[x]) ? x : parent[x] = (find(parent[x]));
}

int main()
{
   int n, m, w;
   int x, y;
   int px, py;
   int ans = 0;
   HOS g;

   scanf("%d %d %d", &n, &m, &w);

   for (int i = 1; i <= n; ++i)
   {
      scanf("%d", &basics[i].weight);
   }

   for (int i = 1; i <= n; ++i)
   {
      scanf("%d", &basics[i].beauty);
   }

   for (int i = 1; i <= n; ++i)
   {
      parent[i] = i;
      combs[i] = basics[i];
   }

   for (int i = 1; i <= m; ++i)
   {
      scanf("%d %d", &x, &y);
      px = find(x);
      py = find(y);
      if (px == py) continue;
      combs[px].beauty += combs[py].beauty;
      combs[px].weight += combs[py].weight;
      parent[py] = px;
   }

   for (int i = 1; i <= n; ++i)
   {
      if (i == find(i)) groupies[i].push_back(combs[i]);
      groupies[find(i)].push_back(basics[i]);
   }

   for (int i = 1; i <= n; ++i)
   {
      if (i != find(i)) continue;
      for (size_t p = 0; p < groupies[i].size(); ++p)
      {
         g = groupies[i][p];
         for (int k = w; k > 0; --k)
         {
            if (k - g.weight >= 0)
            {
               bestDP[k] = max(bestDP[k], usedDP[k - g.weight] + g.beauty);
               ans = max(ans, bestDP[k]);
            }
         }
      }
      for (int i = 0; i <= w; ++i) usedDP[i] = bestDP[i];
   }

   printf("%d", ans);
   return 0;
}
<file_sep>// https://codeforces.com/contest/330/problem/A
// https://codeforces.com/contest/330/submission/14898824

#include <iostream>

using namespace std;


int main()
{
    int n,m;
    bool lin[11],col[11];
    for (int i = 1; i <= 10; i++)
    {
        lin[i] = true;
        col[i] = true;
    }
    cin>>n>>m;
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= m; j++)
        {
            char x;
            cin>>x;
            if (x == 'S')
            {
                lin[i] = false;
                col[j] = false;
            }
        }
    }
    int nrcol = 0, nrlin = 0;
    for (int i = 1; i <= m; i++)
    {
        if (col[i]){nrcol++;}
    }
    for (int i = 1; i <= n; i++)
    {
        if (lin[i]){nrlin++;}
    }
    cout<<(nrcol*(n-nrlin) + (nrlin*m));
    return 0;

}
<file_sep>// https://codeforces.com/contest/151/problem/A
// https://codeforces.com/contest/151/submission/17418748

#include <iostream>
using namespace std;

#define MIN(a,b) (((a)<(b))?(a):(b))

int main() {

	int n, k, l, c, d, p, nl, np;
	cin >> n >> k >> l >> c >> d >> p >> nl >> np;
	cout << MIN(MIN(k*l / nl, c*d), p/np ) / n;

	return EXIT_SUCCESS;
}<file_sep>// https://codeforces.com/contest/673/problem/A
// https://codeforces.com/contest/673/submission/17928098

#include <iostream>
using namespace std;


int main() {
	int n, t1 = 0, t2, s = 0;
	bool ok = true;
	cin >> n;
	for (int i = 0; i < n && ok; i++) {
		cin >> t2;
		if (t2 - t1 <= 15) s = t2;
		else s += 15, ok = false;
		t1 = t2;
	}
	if (ok) s += 15;
	if (s > 90) s = 90;
	cout << s;
	return EXIT_SUCCESS;
}<file_sep># https://codeforces.com/contest/592/problem/C
# https://codeforces.com/contest/592/submission/47395386

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

def reduct(x,y):
    g = gcd(x,y)
    while g != 1:
        while x % g == 0 and y % g == 0:
            x = x // g
            y = y // g
        g =gcd(x,y)
    print(str(x) + "/" + str(y))

(t, w, b) = map(int,input().split())
rest = min(w,b) - 1
s = (w*b) // gcd(w,b)
div = t // s
mod = t % s
ans = div + div * rest + min(mod,rest)
reduct(ans,t)
<file_sep># https://codeforces.com/contest/510/problem/A
# https://codeforces.com/contest/510/submission/14007946

n,m=map(int,input().split())
ok=1
for i in range(1,n+1):
    for j in range(1,m+1):
        if (i%2==1):
            print('#',sep='',end='')
        elif j==m and ok==-1:
            print('#',sep='',end='')
        elif j==1 and ok==1:
            print('#',sep='',end='')
        else:
            print('.',sep='',end='')
    print()
    if i%2==1:
        ok=-ok
<file_sep>// https://codeforces.com/contest/734/problem/D
// https://codeforces.com/contest/734/submission/22308457

#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;

typedef struct _PIECE
{
   unsigned long long dist;
   char c;
}PIECE;

inline bool diagonala(long long x, long long y, long long xr, long long yr)
{
   return (abs(x - xr) == abs(y - yr));
}

inline unsigned long long distance(long long x, long long y, long long xr, long long yr)
{
   return (unsigned long long)((x - xr)*(x - xr) + (y - yr)*(y - yr));
}

int main()
{
   long long xr, yr, n, x, y;
   char c;
   PIECE v[10];
   PIECE aux;
   unsigned long long dist;

   for (int i = 0; i < 10; ++i) v[i].c = '0', v[i].dist = -1;
   scanf("%lld %lld %lld", &n, &xr, &yr);
   
   while (n--)
   {
      getchar();
      scanf("%c %lld %lld",&c, &x, &y);
      dist = distance(x, y, xr, yr);
      aux.c = c;
      aux.dist = dist;
      
      if (x == xr && y > yr && dist < v[1].dist) v[1] = aux;
      else if (x == xr && y < yr && dist < v[2].dist) v[2] = aux;
      else if (x > xr && y == yr && dist < v[3].dist) v[3] = aux;
      else if (x < xr && y == yr && dist < v[4].dist) v[4] = aux;
      else if (diagonala(x, y, xr, yr))
      {
         if (x < xr && y > yr && dist < v[5].dist) v[5] = aux;
         else if (x > xr && y > yr && dist < v[6].dist) v[6] = aux;
         else if (x < xr && y < yr && dist < v[7].dist) v[7] = aux;
         else if (x > xr && y < yr && dist < v[8].dist) v[8] = aux;
      }
   }

   bool won = (v[1].c != 'Q' && v[1].c != 'R' &&
      v[2].c != 'Q' && v[2].c != 'R' &&
      v[3].c != 'Q' && v[3].c != 'R' &&
      v[4].c != 'Q' && v[4].c != 'R' &&
      v[5].c != 'Q' && v[5].c != 'B' &&
      v[6].c != 'Q' && v[6].c != 'B' &&
      v[7].c != 'Q' && v[7].c != 'B' &&
      v[8].c != 'Q' && v[8].c != 'B');
   (won) ? puts("NO") : puts("YES");


   return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;

struct my{
    char tip;
    unsigned long long distanta;
    my(){
        tip = '0';
        distanta = -1;
    }

};

inline bool diagonale(long long xP,long long yP,long long x,long long y){
    return abs(xP - x) == abs(yP - y);
}

unsigned long long distanta(long long xP,long long yP,long long x,long long y){
    return (unsigned long long)((xP - x)*(xP-x) + (yP - y)*(yP - y));
}

int main()
{
    my v[8];
    long long i,n;
    long long xR,yR;
    scanf("%lld %lld %lld",&n,&xR,&yR);
    char pion;
    long long xPion,yPion;
    unsigned long long myDist;
    for(i=0;i<n;i++){
        getchar();
        scanf("%c %lld %lld",&pion,&xPion,&yPion);
        myDist = distanta(xPion,yPion,xR,yR);
        if(diagonale(xPion,yPion,xR,yR)){

            if(xPion < xR && yPion > yR && v[1].distanta > myDist){
                v[1].distanta = myDist;
                v[1].tip = pion;
            }
            else if(xPion > xR && yPion > yR && v[2].distanta > myDist){
                v[2].distanta = myDist;
                v[2].tip = pion;
            }
            else if(xPion < xR && yPion < yR && v[4].distanta > myDist){
                v[4].distanta = myDist;
                v[4].tip = pion;
            }
            else if(xPion > xR && yPion < yR &&v[5].distanta > myDist){
                v[5].distanta = myDist;
                v[5].tip = pion;
            }
        }
        else if(yPion == yR){
            if(xPion < xR && v[7].distanta > myDist){
                v[7].distanta = myDist;
                v[7].tip = pion;
            }
            else if(xPion > xR && v[6].distanta > myDist){
                v[6].distanta = myDist;
                v[6].tip = pion;
            }
        }
        else if(xPion == xR){
            if(yPion > yR && v[0].distanta > myDist){
                v[0].distanta = myDist;
                v[0].tip = pion;
            }
            else if( yPion < yR &&v[3].distanta > myDist){
                v[3].distanta = myDist;
                v[3].tip = pion;
            }
        }
    }
    bool ESah = (v[0].tip == 'R' || v[0].tip == 'Q' ||
                 v[3].tip == 'R' || v[3].tip == 'Q' ||
                 v[6].tip == 'R' || v[6].tip == 'Q' ||
                 v[7].tip == 'R' || v[7].tip == 'Q' ||
                 v[1].tip == 'B' || v[1].tip == 'Q' ||
                 v[2].tip == 'B' || v[2].tip == 'Q' ||
                 v[4].tip == 'B' || v[4].tip == 'Q' ||
                 v[5].tip == 'B' || v[5].tip == 'Q'
                 );
    (ESah) ? puts("YES") : puts("NO");
    return 0;
}<file_sep># https://codeforces.com/contest/144/problem/A
# https://codeforces.com/contest/144/submission/13589412

n=int(input())
l=list(map(int,input().split()))
maxs=-1
mins=102
poz_min, poz_max = -1, -1
for i in range(len(l)):
    if maxs<l[i]:
        maxs=l[i]
        poz_max=i+1
    if mins>=l[i]:
        mins=l[i]
        poz_min=i+1
if poz_max>poz_min:
    poz_max-=1
print(poz_max-1+len(l)-poz_min)
<file_sep>// https://codeforces.com/contest/570/problem/B
// https://codeforces.com/contest/570/submission/28728095

#include <iostream>
using namespace std;



int main() {

    int n, m;
    cin>>n>>m;
    
    if (n == 1){
        
        cout<<"1";
    return                      0;
    }
    
    cout<<( ( m-1 >= n-m)?(m-1):(m+1)); 
     
    return 0;
    
}
<file_sep>// https://codeforces.com/problemset/problem/1114/A
// https://codeforces.com/contest/1114/submission/67692580

#include <iostream>
#include <algorithm>
using namespace std;

bool SolveAndrew(int& Andrew, int& green)
{
    if (green < Andrew)
    {
        return false;
    }

    green -= Andrew;
    return true;
}

bool SolveDimitry(int& Dimitry, int& green, int& purple)
{
    if (green + purple < Dimitry)
    {
        return false;
    }

    if (green < Dimitry)
    {
        Dimitry -= green; 
        green = 0;
        purple -= Dimitry;
    }
    else
    {
        green -= Dimitry;
    }
    return true;
}

bool SolveMichael(int& Michael, int& green, int& purple, int& black)
{
    if (green + purple + black < Michael)
    {
        return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int Andrew, Dimitry, Michael;
    cin >> Andrew >> Dimitry >> Michael;

    int green, purple, black;
    cin >> green >> purple >> black;

    bool ok = SolveAndrew(Andrew, green) && 
              SolveDimitry(Dimitry, green, purple) && 
              SolveMichael(Michael, green, purple, black);

    (ok) ? cout << "YES\n" : cout << "NO\n";
    return 0;
}<file_sep>// https://codeforces.com/gym/101246/problem/B
// https://codeforces.com/gym/101246/submission/25244690

#include <iostream>
#include<fstream>
#include<string>

#define cin f
#define cout g

using namespace std;


int mat[110][110];

int main()
{

    ifstream f("input.txt");
    ofstream g("output.txt");
    int n, m;

    f>>n>>m;
    string s;
    for(int i=1; i<=n; i++)
    {
        f>>s;
        for(int j=1; j<=m; j++)
            mat[i][j] =(s[j-1]-'0') ;
    }

    int sol=0;

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

        for(int j=1; j<=m; j++)
        {
            if(mat[i][j]!=0)sol+=2;
            sol+= (max(0, mat[i][j]-mat[i-1][j])+  max(0, mat[i][j]-mat[i+1][j])+  max(0, mat[i][j]-mat[i][j-1])+  max(0, mat[i][j]-mat[i][j+1]));
        }
    }

    g<<sol<<endl;
    f.close();
    g.close();

    return 0;
}<file_sep># https://codeforces.com/contest/630/problem/C
# https://codeforces.com/contest/630/submission/17323650

n = int(input())
print(2*(1<<n)-2)
<file_sep># https://codeforces.com/contest/318/problem/A
# https://codeforces.com/contest/318/submission/14008127

n,m=map(int,input().split())
if n%2==0:
    k=int(n/2)
else:
    k=int(n/2+1)
if k<m:
    print((m-k)*2)
else:
    print(2*m-1)
    
<file_sep># https://codeforces.com/contest/492/problem/B
# https://codeforces.com/contest/492/submission/14414432

n,m = map(int,input().split())
v = list(map(float,input().split()))
v = sorted(v)
if v[0]!=0:
    maxs = v[0]
    indice = 2
else:
    maxs = -1
    indice = 1
if v[n-1]!=m:
    if m-v[n-1]>maxs:
        maxs=m-v[n-1]
while indice <= n-1:
    if (v[indice]-v[indice-1])/2>maxs:
        maxs=(v[indice]-v[indice-1])/2
    indice+=1
print("%.10f" %maxs)
    
    

    
