akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

using int64 = long long;
using ST = pair<int64, int64>;  // x, diff

int main() {
  int64 a, b, q;
  cin >> a >> b >> q;
  vector<int64> s(a);
  vector<int64> t(b);
  for (int64 i = 0; i < a; ++i)
    cin >> s[i];
  for (int64 i = 0; i < b; ++i)
    cin >> t[i];

  vector<ST> st;
  for (int64 i = 0; i < a; ++i) {
    int64 j = lower_bound(t.begin(), t.end(), s[i]) - t.begin();
    int64 c0 = 1e+18;
    int64 c1 = 1e+18;

    if (j < b)
      c0 = abs(t[j] - s[i]);
    if (j > 0)
      c1 = abs(t[j - 1] - s[i]);
    st.emplace_back(s[i], min(c0, c1));
  }
  for (int64 i = 0; i < b; ++i) {
    int64 j = lower_bound(s.begin(), s.end(), t[i]) - s.begin();
    int64 c0 = 1e+18;
    int64 c1 = 1e+18;

    if (j < a)
      c0 = abs(s[j] - t[i]);
    if (j > 0)
      c1 = abs(s[j - 1] - t[i]);
    st.emplace_back(t[i], min(c0, c1));
  }
  sort(st.begin(), st.end());

  for (int64 i = 0; i < q; ++i) {
    int64 x;
    cin >> x;
    int64 id = lower_bound(st.begin(), st.end(), ST {x, 0}) - st.begin();
    int64 c0 = 1e+18;
    int64 c1 = 1e+18;

    if (id < st.size())
      c0 = abs(st[id].first - x) + st[id].second;
    if (id > 0)
      c1 = abs(st[id - 1].first - x) + st[id - 1].second;
    cout << min(c0, c1) << "\n";
  }

  return 0;
}


Measured memory_bytes: 8048
#include <iostream>
using namespace std;

int main() {
  int a, b, c, x;
  cin >> a; cin >> b; cin >> c; cin >> x;

  int ans = 0;
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
        if ((500*i) + (100*j) + (50*k) == x)
          ans++;
      }
    }
  }

  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 504
#include <bits/stdc++.h>

using namespace std;

int a[500009];

string s;

int main()
{
    int mn = 0;
    int n;
    cin >> s;

    n = s.size();

    a[0] = 0;
    for(int i = 0; i < n; )
    {
        if(s[i] == '<')
            a[i + 1] = a[i] + 1, i ++;

        else
        {
            int cr = i;
            int cnt = 0;
            while(cr < n && s[cr] == '>')
                cr++, cnt ++;

            a[i] = max(a[i], cnt);
            int val = min(cnt, a[i]) - 1;
            for(int x = i + 1; x <= cr; x ++)
                a[x] = val, val --;

            i = cr;
        }
    }

  /*  for(int i = 0; i <= n; i ++)
        cout << a[i] << " ";
    cout << "\n";*/

    long long sum = 0;
    for(int i = 0; i <= n; i ++)
        sum += mn + a[i];

    cout << sum << "\n";

    return 0;
}


Measured memory_bytes: 2820
#include <bits/stdc++.h>

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;

typedef long long LL;
typedef long double ldouble;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

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

    }

    sort(all(v));
    if(s % 10 == 0) {
        int pos = 0;
        while(pos < n && v[pos] % 10 == 0) {
            ++pos;

        }
        if(pos == n) cout << 0 << endl;
        else {
            int ss = 0;
            for(int i = 0; i < n; ++i) {
                if(v[i] % 10 == 0) ss += v[i];

            }
            cout << max(s - ss, s - v[pos]) << endl;
        }
    } else {
        cout << s << endl;

    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
    int N,K;cin >> N >> K;
    vector<ll> D(N);
    for (int i = 0;i < N;i++) cin >> D[i];
    ll res = 0;
    for (int a = 0;a <= min(N,K);a++){
        for (int b = 0;a + b <= min(N,K);b++){
            vector<ll> v;
            ll cur = 0;
            for (int i = 0;i < a;i++) v.push_back(D[i]),cur += D[i];
            for (int i = 0;i < b;i++) v.push_back(D[N - 1 - i]),cur += D[N - 1 - i];
            sort(v.begin(),v.end());
            for (int i = 0;i < min((K - a - b),(int)v.size());i++){
                if (v[i] < 0) cur -= v[i];
            }
            res = max(res,cur);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define bg begin()
#define ed end()
#define rbg rbegin()
#define red rend()
#define all(x) x.bg,x.ed
#define rall(x) x.rbg,x.red
#define pb push_back
#define pf push_front
#define eb emplace_back
using namespace std;
typedef long long ll;
template<class t,class u> bool chmax(t&a,u b){if(a<b){a=b; return true;} return false;}
template<class t,class u> bool chmin(t&a,u b){if(a>b){a=b; return true;} return false;}
template<class t,class u> t MAX(t a,u b){if(a>=b) return a; return b;}
template<class t,class u> t MIN(t a,u b){if(a<=b) return a; return b;}
template<class t> int SIZE(t s){return (int)s.size();}
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
using vvi=vc<vc<int>>;
using pi=pair<int,int>;
using vi=vc<int>;
void yes(){ cout << "Yes" << endl; }
void no(){ cout << "No" << endl; }
const long long INF = 1LL << 60;

int main(){
    cout << fixed << setprecision(20);
    int a,b,c; cin >> a >> b>>c;
    cout << a+b+c-max(a,max(b,c)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
long long X, Y;
using namespace std;

int main(){
    int cnt = 0;
    cin >> X >> Y;
    while(true){
        if(X > Y) {
            break;
        }else if(X <= Y){
            cnt++;
        }
        X *= 2;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
mod = 10 ** 9 + 7

fact = [1] * (n + 1)
revfact = [1] * (n + 1)
for i in range(n):
    fact[i + 1] = ((i + 1) * fact[i]) % mod
revfact[n] = pow(fact[n], mod - 2, mod)
for i in reversed(range(n)):
    revfact[i] = ((i + 1) * revfact[i + 1]) % mod
def combination(n, k, p):
    return (fact[n] * revfact[k] * revfact[n - k]) % p

for i in range(1, k + 1):
    if n - k + 1 < i:
        ans  = 0
    else:
        ans = combination(n - k + 1, i, mod) * combination(k - 1, i - 1, mod)
    print(ans % mod)

Measured memory_bytes: 9296
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n,m;
  cin >> n >> m;
  if(n >= 3 && m >= 3){
    cout << (n-2)*(m-2) << endl;
    return 0;
  }
  else if(n == 2 || m == 2){
    cout << 0 << endl;
    return 0;
  }
  else if(n == 1 && m == 1){
    cout << 1 << endl;
    return 0;
  }
  else{
    if(n == 1){
      cout << m-2 << endl;
      return 0;
    }
    if(m == 1){
      cout << n-2 << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000000 + 7
#define MAX 51000
#define all(x) (x).begin(), (x).end()
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))

using namespace std;
int main(void)
{
    int a;
    string s;
    cin >> a >> s;
    if (a >= 3200)
        cout << s << endl;
    else
        cout << "red" << endl;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

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

    int ans=0;
    while(s.size()>1){
        char f=s.front(),b=s.back();
        if(f==b){
            s=s.substr(1,s.size()-2);
        }else if(f=='x' || b=='x'){
            if(f=='x') s=s.substr(1,s.size()-1);
            else s=s.substr(0,s.size()-1);
            ans++;
        }else{
            ans=-1;
            break;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B == C + D){
    cout << "Balanced" << endl;
  }
  
  else if (A + B <= C + D){
      cout << "Right" << endl;
    }
  
  else if (A + B >= C + D){
    cout << "Left" << endl;
  }
  
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

struct UnionFind
{
	vector<int> par;
	UnionFind(int n) :par(n, -1) {}
	int find(int x) { return par[x] < 0 ? x : par[x] = find(par[x]); }
	void unite(int x, int y)
	{
		x = find(x); y = find(y);
		if (x == y) return;
		if (par[y] < par[x]) swap(x, y);
		if (par[x] == par[y]) par[x]--;
		par[y] = x;
		if (find(x) != find(y)) par[find(y)] = x;
	}
	int count()
	{
		int cnt = 0;
		REP(i, par.size()) if (par[i] < 0) cnt++;
		return cnt;
	}
	bool same(int x, int y)
	{
		return find(x) == find(y);
	}
};

typedef ld Weight;
struct Edge
{
	int from, to; Weight cost; char c;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;

const ld INF = 1e9;
const ld EPS = 1e-9;

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, m, k;
	while (cin >> n >> m >> k, n)
	{
		Edges es;
		REP(i, m)
		{
			int a, b; ld c; char d;
			cin >> a >> b >> c >> d;
			a--; b--;
			es.emplace_back(Edge{ a, b, c, d });
		}
		int mn = INF, mx = -1;
		ld lb = -INF, ub = INF;
		REP(lp, 300)
		{
			ld mid = (ub + lb) / 2;
			Edges tmp;
			for (auto e : es)
			{
				if (e.c == 'A') e.cost += mid;
				tmp.push_back(e);
			}
			sort(ALL(tmp));
			UnionFind uf(n);
			ld cost = 0;
			int cnta = 0;
			for (auto e : tmp)
			{
				if (uf.same(e.from, e.to)) continue;
				if (e.c == 'A')
				{
					cnta++;
				}
				cost += e.cost;
				uf.unite(e.from, e.to);
			}

			chmax(mx, cnta);
			chmin(mn, cnta);
			if (lp == 299)
			{
				if (uf.count() != 1 || (mx < k || mn > k))
				{
					cout << -1 << endl;
				}
				else
				{
					cout << ll(cost - k * mid + EPS) << endl;
				}
			}
			else if (cnta > k)
			{
				lb = mid;
			}
			else
			{
				ub = mid;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3424
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 1000000007
#define INF (ll)1e18+9
#define N 2000006

using namespace std;

ll n, p[2001], a[2001], d[2001], f;
vector <ll> v[2001];
ll dp[1001][5005][2];
void dfs(int x) {
    if (v[x].size() == 0 || f) return;

    for (int i = 0; i <= 5000; i++)
        dp[x][i][1] = 1 << 30;
    for (int i = 0; i < v[x].size(); i++) {
        int u = v[x][i];
        dfs(u);
        for (int i = 5000 - a[u]; i >= 0; i--)
            dp[x][i + a[u]][1] = min(dp[x][i + a[u]][1], dp[x][i][0] + d[u]);
        for (int i = 5000 - d[u]; i >= 0; i--)
            dp[x][i + d[u]][1] = min(dp[x][i + d[u]][1], dp[x][i][0] + a[u]);
        for (int i = 0; i <= 5000; i++)
            dp[x][i][0] = dp[x][i][1], dp[x][i][1] = 1 << 30;
    }
    d[x] = dp[x][a[x]][0];
    if (d[x] >= 1e9) f = 1;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 2; i <= n; i++)
        cin >> p[i], v[p[i]].pb(i);
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    dfs(1);
    if (!f)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;

	return 0;
}


Measured memory_bytes: 78208
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <queue>
#include <list>
using namespace std;

int main(){
    int n, k, a;
    cin >> n >> k;
    double arr[n];
    for(int i = 0; i < n; i++){
        cin >> a;
        arr[i] = a;
        arr[i] /= 2;
        arr[i] += 0.5;
    }
    double ans = 0, t = 0;
    for(int i = 0; i < k-1; i++){
        t += arr[i];
    }
    for(int i = k-1; i < n; i++){
        t += arr[i];
        ans = max(ans, t);
        t -= arr[i+1-k];
    }
    printf("%.10f\n", ans);
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)

int abc[3];

int main() {
    string S; cin >> S;
    int N = (int)S.size();
    if(N==1){cout << "YES" << '\n'; return 0;}
    REP(i,N) ++abc[S[i]-'a'];
  
    if(abs(abc[0]-abc[1])>1 || abs(abc[1]-abc[2])>1 || abs(abc[2]-abc[0])>1) cout << "NO" << '\n';
    else cout << "YES" << '\n';
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;

void trace(vector<int> vec) {
    for(int i = 0; i < vec.size(); i++) {
        if(i > 0) cout << " ";
        cout << vec.at(i);
    }
    cout << endl;
}

int bubbleSort(vector<int> &A, int N) {
    int count = 0;
    bool flag = true;
    int i = 0;
    while(flag) {
        flag = false;
        for(int j = N - 1; j > i; j--) {
            if(A.at(j) < A.at(j - 1)) {
                swap(A.at(j), A.at(j - 1));
                count++;
                flag = true;
            }
        }
        i++;
    }
    return count;
}

int main() {
    int N, ans;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    ans = bubbleSort(A, N);
    trace(A);
    cout << ans << endl;
}


Measured memory_bytes: 3136
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b) //最大公約数
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}

ll lcm(ll a, ll b) //最小公倍数
{
	return a * b / gcd(a, b);
}

ll box(double a) //doubleの切り捨て
{
	ll b = a;
	return b;
}

ll fff(double a) //doubleの四捨五入
{
	ll b = a + 0.5;
	return b;
}

ll sum(ll n) { //整数sまでの合計
	if (n == 0) {
		return 0;
	}

	int s = sum(n - 1);
	return s + n;
}

bool prime(ll num)//素数判定、primeならtrue,違うならfalse
{
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}

// ===============================================================

int main() {
	ll a, b; cin >> a >> b;
	if (a * 500 >= b) {
		cout << "Yes" << endl;
	}
	else cout << "No" << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<float.h>
#include<math.h>
#include<algorithm>
using namespace std;


double Manhattan(int *x, int *y, int n){
	double d=0;
	for(int i=0; i<n; i++){
		d+=abs(x[i]-y[i]);
	}
	return d;
}

double Euclidean(int *x, int *y, int n){
	double d, tmp=0.0;
	for(int i =0; i<n; i++){
		tmp+=pow((double)abs(x[i]-y[i]),2.0);		//d+=abs(x[i]-y[i])*abs(x[i]-y[i])
	}
	d=pow(tmp, 1.0/2.0);
	//cout<<pow((double)abs(x[1]-y[1]),1.0/2.0)<<endl;
	return d;
}	

double Minkowski3(int *x, int *y, int n){
	double d, tmp=0.0;
	for(int i =0; i<n; i++){
		tmp+=pow((double)abs(x[i]-y[i]),3.0);
	}
	d=pow(tmp,1.0/3.0);
	return d;
}

double Chebyshev(int *x, int *y, int n){
	double d=0;
	int sub[100]={0};
	for(int i=0; i<n; i++){
		sub[i]=abs(x[i]-y[i]);
		if(sub[i]>d)d=sub[i];
	}
	return d;
}


int main(){
	int n, x[100]={0},y[100]={0};
	double a1, a2, a3, a4;

	cin>>n;

	for(int i=0; i<n; i++){
		cin>>x[i];
	}
	for(int i=0; i<n; i++){
		cin>>y[i];
	}
	a1=Manhattan(x,y,n);
	a2=Euclidean(x,y,n);
	a3=Minkowski3(x,y,n);
	a4=Chebyshev(x,y,n);

	printf("%7.6lf\n%7.6lf\n%7.6lf\n%7.6lf\n", a1, a2, a3, a4);

	//cout<<a1<<endl<<a2<<endl<<a3<<endl<<a4<<endl;
	return 0;
}


Measured memory_bytes: 3348
#include<bits/stdc++.h>
using namespace std;

int main(){
    int a, b, k;
    int m, c;
    int ans;
    m=0;
    c=0;
    ans=0;
    cin >> a >> b >> k;
    m = min(a, b);
    for(; m>=1; m--){
        if((a%m)==0 && (b%m)==0){
            c++;
        }
        if(c==k){
            ans = m;
            break;
        } 
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static const int INF = (1<<30)-1;

int main(){
  int N,T;
  cin >> N >> T;

  vector<int> town(N);
  for(int i=0;i<N;i++) cin >> town[i];

  int min_price = town[0], max_benefit = -INF, cost = 0;
  for(int i=1;i<N;i++){
    if(town[i]-min_price>max_benefit){
      max_benefit = town[i]-min_price;
      cost = 1;
    }else if(town[i]-min_price==max_benefit) cost ++;
    
    if(town[i] < min_price) min_price = town[i];
  }
  cout << cost << endl;
  return 0;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

int n;
string s;
int q;
int k[75];
LL d,m,dm;

int main(){
  cin>>n;
  cin>>s;
  cin>>q;
  REP(i,q)
    cin>>k[i];
  LL ret;
  REP(i,q){
    ret=0;
    d=0;
    m=0;
    dm=0;
    REP(j,n){
      if(j-k[i]>=0){
	if(s[j-k[i]]=='D'){
	  dm-=m;
	  d--;
	}else if(s[j-k[i]]=='M'){
	  m--;
	}
      }
      
      if(s[j]=='D'){
	d++;
      }else if(s[j]=='M'){
	m++;
	dm+=d;
      }else if(s[j]=='C'){
	ret+=dm;
      }
      //cerr<<j<<" "<<d<<" "<<m<<" "<<dm<<endl;
    }
    cout<<ret<<endl;
  }
  return 0;
}


Measured memory_bytes: 1412
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;


int main() {
    int s[2], t[2];
    cin >> s[0] >> s[1] >> t[0] >> t[1];
    rep(i, t[1]-s[1]) {
        cout << 'U';
    }
    rep(i, t[0] - s[0]) {
        cout << 'R';
    }
    rep(i, t[1]-s[1]) {
        cout << 'D';
    }
    rep(i, t[0] - s[0]) {
        cout << 'L';
    }
    cout << 'D';
    rep(i, t[0]-s[0]+1) {
        cout << 'R';
    }
    rep(i, t[1]-s[1]+1) {
        cout << 'U';
    }
    cout << 'L';
    cout << 'U';
    rep(i, t[0]-s[0]+1) {
        cout << 'L';
    }
    rep(i, t[1]-s[1]+1) {
        cout << 'D';
    }
    cout << 'R' << '\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main() {
	int a = 0;
	int edita = 0;
	int b = 0;
	int n = 0;
	int sum = 0;
	std::vector<int> x(5, 0);

	std::cin >> a;
	std::cin >> b;

	edita = a;
	n = b - a + 1;

	for (int i = 0; i < n; i++) {
		edita = a;
		for (int j = 0; j < 5; j++) {
			x.at(j) = edita % 10;
			edita = edita / 10;
		}
		if (x.at(0) == x.at(4)) {
			if (x.at(1) == x.at(3)) {
				sum += 1;
			}
		}
		a += 1;
	}

	std::cout << sum;

	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <cassert>
#include <functional>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template<typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template<typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int P, Q, R;

  cin >> P >> Q >> R;

  cout << P + Q + R - max({P, Q, R}) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
struct S {
    int l, r, num;
};
int a[N], c[N], ans[N], fl[N];
S ak[N];
int n;

int lowbit(int x) {
    return x & (-x);
}

void add(int x, int k) {
    while (x <= n) {
        c[x] += k;
        x += lowbit(x);
    }
}

int getsum(int x) {
    int ret = 0;
    while (x) {
        ret += c[x];
        x -= lowbit(x);
    }
    return ret;
}

bool cmp(S x, S y) {
    return x.r < y.r;
}

int main()
{
    int m;
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < m; i++) {
        scanf("%d%d", &ak[i].l, &ak[i].r);
        ak[i].num = i;
    }
    sort(ak, ak + m, cmp);
    int pos = 1;
    for (int i = 0; i < m; i++) {
        for (int j = pos; j <= ak[i].r; j++) {
            if (fl[a[j]])
                add(fl[a[j]], -1);
            add(j, 1);
            fl[a[j]] = j;
        }
        pos = ak[i].r + 1;
        ans[ak[i].num] = getsum(ak[i].r) - getsum(ak[i].l - 1);
    }
    for (int i = 0; i < m; i++) {
        printf("%d\n", ans[i]);
    }
    return 0;
}

Measured memory_bytes: 17364
#include <bits/stdc++.h>
using namespace std;

int main() {
  long long H,W;
  cin >> H >> W;
  
  if(H == 1 || W == 1){
    cout << 1 << endl;
  }else{
    cout << (H * W + 1) / 2 << endl;
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;

#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv)vprint(v);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20);

    ll N, K;
    cin >> N >> K;

    ll total = 0;
    REP(k, K, N+2){
        ll minimum = k*(k-1)/2;
        ll maximum = k*(N-k+1) + k*(k-1)/2;
        total = (total+maximum-minimum+1) % 1000000007;
    }
    cout << total << endl;
}


Measured memory_bytes: 3600
import math
mode=1000000007


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

if n==m:
    ans=math.factorial(n) % mode
    print(2*ans*ans % mode)
elif abs(n-m)==1:
    ans_n=math.factorial(n) % mode
    ans_m=math.factorial(m) % mode
    print(ans_n*ans_m % mode)
else:
    print(0)


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;

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

  vector<string> words{"dream", "dreamer", "erase", "eraser"};

  for(int i = 0; i < 4; i ++){
    reverse(words.at(i).begin(), words.at(i).end());
  }
  reverse(s.begin(), s.end());

  while(1){
    bool flag = false;
    for(int i = 0; i < 4; i ++){
      if(equal(words.at(i).begin(), words.at(i).end(), s.begin())){
        auto pos = s.find(words.at(i));
        auto len = words.at(i).length();
        s.replace(pos, len, "");
        flag = true;
      }
    }
    if(flag == false){
      if(s == "") break;

      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
  
  return 0;
}


Measured memory_bytes: 512
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	s := next()
	if s[2] == s[3] && s[4] == s[5] {
		puts("Yes")
	} else {
		puts("No")
	}
}

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func nextFloat64s(n int) []float64 {
	slice := make([]float64, n)
	for i := 0; i < n; i++ {
		slice[i] = nextFloat64()
	}
	return slice
}

func putf(format string, a ...interface{}) {
	fmt.Fprintf(wt, format, a...)
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int N;
const int MAX_N = 10000;
int a[MAX_N];  

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) cin >> a[i];
    
    int ans = 0;
    for (int i = 0; i < N; i++) {
        while (a[i] % 2 == 0) {
            a[i] /= 2;
            ans++;
        }
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 764
s=input()

t=input()

s=list(s)

t=list(t)

memo = -1

for i in range(len(s)-len(t)+1):
    count = 0
    for k, j in enumerate(range(i, i+len(t))):
        if s[j] == t[k] or '?' == s[j]:
            count += 1
    if count == len(t):
        memo = i

if memo == -1:
    print('UNRESTORABLE')
else:
    for k,l in enumerate(range(memo,memo+len(t))):
        s[l] = t[k]
    for g in range(len(s)):
        if s[g] == '?':
            s[g] = 'a'
    print(''.join(map(str,s)))

Measured memory_bytes: 38256
fun main(s: Array<String>) {
  readLine()!!
  val t = readLine()!!.split(' ').map { it.toInt() }
  val q = (1.0 * t.sum() / t.size).toInt()
  println((q-1..q+1).map { cost(t, it) }.min())
}

fun cost(nums: List<Int>, pt: Int) = nums.sumBy { (it - pt) * (it - pt) }

Measured memory_bytes: 38092
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

int main(){
  int N, M;
  cin >> N >> M;
  if(N == M) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(r) r.begin(),r.end()
using namespace std;
typedef int64_t ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll n;
        in >> n;
        vvll a(3, vll(n));
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < n; j++) {
                in >> a[i][j];
            }
            sort(all(a[i]));
        }
        ll ans = 0;
        for (int i = 0; i < n; i++) {
            ll ud = lower_bound(all(a[0]), a[1][i]) - a[0].begin();
            ll dd = a[2].end() - upper_bound(all(a[2]), a[1][i]);
            ans += ud * dd;
        }
        out << ans << '\n';
    }
};
void solve(std::istream& in, std::ostream& out) {
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}

Measured memory_bytes: 3456
#include <bits/stdc++.h>

#define int long long

using namespace std;



int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int N;
    cin >> N;

    vector<pair<int,int>> vect;

    vector<pair<int,int>> v1, v2;

    for(int i = 0 ; i < N ; i++)
    {
    	int x, y;
    	cin >> x >> y;
    	
    	vect.push_back({x,y});

    	v1.push_back({x+y,i});

    	v2.push_back({x-y,i});
    }

    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());

    int d1 = abs(vect[v1[0].second].first-vect[v1.back().second].first) + abs(vect[v1[0].second].second-vect[v1.back().second].second);
    int d2 = abs(vect[v2[0].second].first-vect[v2.back().second].first) + abs(vect[v2[0].second].second-vect[v2.back().second].second);

    int res = max(d1,d2);

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 12816
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(ReadLine());
        string S = ReadLine();

        int result = 0;

        for (int i = 1; i < N; i++) 
        {
            var X = S.Substring(0, i).ToCharArray().Distinct();
            var Y = S.Substring(i, N - i).ToCharArray().Distinct();

            if (result < X.Intersect(Y).Count()) {
                result = X.Intersect(Y).Count();
            }
        }

        WriteLine(result.ToString());
    }
}


Measured memory_bytes: 13280
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] like = new int[m+1];
        int ans = 0;
        for(int i = 0;i < n;i++){
            int kind = sc.nextInt();
            for(int j = 0;j < kind;j++){
                like[sc.nextInt()]++;
            }
        }

        for(int i : like){
            if(i == n)
            ans++;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;


int main(){
  int n,x;
  cin >> n >> x;
  int mi=10000;
  int su=0;
  for(int i=0;i<n;++i){
    int m;
    cin >> m;
    su+=m;
    mi=min(mi,m);
  }
  int ans=n;
  x-=su;
  ans+=x/mi;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3592
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
 
		String s = sc.next();
		int ans =753;
		
		for(int i=0; i<s.length()-2; i++){
		    String a = s.substring(i,i+3);
		    int b = Integer.parseInt(a) - 753;
		    int sa = Math.abs(b);
		    if(sa<ans){
		        ans =sa;
		    }
		}
 
		System.out.println(ans);
    }
}


Measured memory_bytes: 35596
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N;
  cin >> N;
  int ans = 0;
  vector<int> dish(N);
  vector<int> add(N);
  for(int i = 0; i < N; i++) {
    int a;
    cin >> a;
    dish.at(i) = a - 1;
  }
  for(int i = 0; i < N; i++) {
    int b;
    cin >> b;
    ans += b;
  }
  for(int i = 0; i < N; i++) {
    cin >> add.at(i);
  }
  for(int i = 0; i < N - 1; i++) {
    if(dish.at(i) + 1 == dish.at(i + 1)) {
      ans += add.at(dish.at(i));
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n,m,X,Y;
    cin >>n>>m>>X>>Y;

    vector<int>x(n+1);
    x[0]=X;
    vector<int>y(m+1);
    y[0]=Y;

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

    sort(x.begin(),x.end());
    sort(y.begin(),y.end());

    if(x.back()<y.front()){
        cout<<"No War"<<endl;
    }
    else {
        cout<<"War"<<endl;
    }
}


Measured memory_bytes: 256
N, M = map(int, input().split())

cities = [[] for _ in range(N)]

for i in range(M) :
    p, y = map(int, input().split())
    cities[p - 1].append((i, y))

id = [0] * M

for p, city in enumerate(cities) :
    city.sort(key = lambda A : A[1])
    for index, (i, year) in enumerate(city) :
        id[i] = '{pre:06}{i:06}'.format(pre = p + 1, i = index + 1)

for i in range(M) :
    print(id[i])

Measured memory_bytes: 35940
#include<stdio.h>

int main(void)
{
  int n,k,l[51],i,ans=0,temp,frag=1;
  scanf("%d %d",&n,&k);
  for(i=0;i<n;i++)
    {
      scanf("%d",&l[i]);
    }
  while(frag == 1)
    {
      frag = 0;
      for(i=0;i<n-1;i++)
	{
	  if(l[i] < l[i+1])
	    {
	      temp = l[i];
	      l[i] = l[i+1];
	      l[i+1] = temp;
	      frag = 1;
	    }
	}
    }
  for(i=0;i<k;i++)
    {
      ans += l[i];
    }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 128
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;

const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int H,W;
char board[520][520];
int dp[520][520];//最大の縦、最大の横
int main(){
	while(cin>>H>>W,H||W){
		for(int i =1;i <=H;i++){
			for(int j =1;j <=W;j++){
				dp[i][j]=0;
			}
		}
		for(int i =1;i <=H;i++){
			int x = 1;
			for(int j =W;j >=1;j--){
				cin>>board[i][j];
				if(board[i][j]=='.'){
					dp[i][j]=x;
					x++;
				}else{
					dp[i][j]=0;
					x = 1;
				}
			}
		}
		int ans = 0;
		for(int i = 1;i <=H;i++){
			for(int j =1;j <= W;j++){
				if(dp[i][j]==0)continue;
				int m =INF;
				for(int k =i;k <=H;k++){
					m =min(m,dp[k][j]);
					if(m==0)break;
					ans =max(ans,(k-i+1)*m);
				}
			}
		}
		cout <<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 2436
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

vector<int> eT;
vector<ll> uF;
ll ans = 0;

void es( int n ){
	for( int i = 0; i < n; ++i ){
		eT.push_back(i);
		uF.push_back(1ll);
	}
}

int wurzel( int x ){
	if( eT.at(x) == x ){
		return x;
	} else {
		return eT.at(x) = wurzel( eT.at(x) );
	}
}

void verbinden( int x, int y ){
	x = wurzel(x);
	y = wurzel(y);
	if( x == y ) return;
	eT.at(x) = y;
	ll nx = uF[x];
	ll ny = uF[y];
	ll n = uF[x] = uF[y] = nx + ny;
	// cout << "n: " << n << ", nx: " << nx << ", ny:" << ny << endl;
	ans += n*(n-1)/2 - nx*(nx-1)/2 - ny*(ny-1)/2;
	// cout << "ans: " << ans << endl;
}

bool gleich( int x, int y ){
	return wurzel(x) == wurzel(y);
}

int main(){
	ll n, m;
	cin >> n >> m;
	es(n);
	ll bq = n*(n-1)/2;
	vector<pair<int, int>> vp;
	for( int i = 0; i < m; ++i ){
		int a, b;
		cin >> a >> b;
		--a; --b;
		vp.emplace_back(a, b);
	}
	vector<ll> ansbox;
	ansbox.push_back(bq);
	for( int i = m-1; i > 0; --i ){
		int a = vp.at(i).first;
		int b = vp.at(i).second;
		verbinden(a, b);
		ansbox.push_back(bq - ans);
	}
	reverse( ansbox.begin(), ansbox.end() );
	for( int i = 0; i < m; ++i ){
		cout << ansbox.at(i) << endl;
	}
	return 0;
}

Measured memory_bytes: 4208
var
 a,b:ansistring;
 x,k:longint;
begin
 readln(b);
 k:=pos(' ',b);
 a:=copy(b,1,k-1);
 delete(b,1,k);
 val(a+b,x);
 if trunc(sqrt(x))*trunc(sqrt(x))=x then writeln('Yes')
                                                     else writeln('No');
end.


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int W, H, N;
    cin >> W >> H >> N;
    int left = 0, right = W, under = 0, over = H;
    for(int i = 0; i < N; i++) {
        int x, y, a;
        cin >> x >> y >> a;
        if(a == 1)
            left = max(left, x);
        else if(a == 2)
            right = min(right, x);
        else if(a == 3)
            under = max(under, y);
        else
            over = min(over, y);
    }
    cout << max(0, right - left) * max(0, over - under) << "\n";
    return 0;
}

Measured memory_bytes: 256
/*
	written by Pankaj Kumar.
	country:-INDIA
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
typedef set<pair<int,int>> spi;
typedef set<pair<ll,ll>> spl;
typedef vector<pair<int,int>> vpi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vpl;
typedef vector<string> vs;
typedef map<int,int>m;
typedef set<string> ss;
typedef set<int> si;
typedef set<ll> sl;
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
// define values.
#define mod 1000000007;
#define phi 1.618
/* Bit-Stuff */
#define get_set_bits(a) (__builtin_popcount(a))
#define get_set_bitsll(a) ( __builtin_popcountll(a))
#define get_trail_zero(a) (__builtin_ctz(a))
#define get_lead_zero(a) (__builtin_clz(a))
#define get_parity(a) (__builtin_parity(a))
/*  Abbrevations  */
#define ff first
#define ss second
#define mp make_pair
#define line cout<<endl;
#define pb push_back
// function
ll power(ll x,ll y)
{
	ll res=1;
	while(y>0)
	{
		if(y%2==1)res*=x;
		y/=2; x*=x;
	}
	return res;
}
/* ascii value 
A=65,Z=90,a=97,z=122
*/
/*  ---------------------------------MAIN-------------------------------------------*/

int main()
{
	ll a,b,n;
	cin>>a>>b>>n;
	cout<<(a*(min(b-1,n)))/b<<endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

ll vis[100005];

int main()
{
    ll n,x=0,a=0;
    cin>>n;
    ll l1[n+1];
    for(int i=1;i<=n;i++){
        cin>>l1[i];
        if(l1[i]==2)a++;
    }
    if(a==0){
        cout<<-1;return 0;
    }
    ll b=l1[1];//x++;vis[b]=1;
    while(1){
        if(vis[b]){
            cout<<-1;return 0;
        }
        else{
            vis[b]=1;
            x++;
            if(b==2){
                cout<<x;return 0;
            }
            b=l1[b];
        }
    }

    return 0;
}


Measured memory_bytes: 1792
use std::io;
use std::str;
use std::usize;
use std::cmp;
use std::collections::BTreeSet;

fn main() {
    let (n, k) = {
        let v = read_values::<usize>();
        (v[0], v[1] as u64)
    };

    let mut v = read_values::<u64>();
    let set: BTreeSet<_> = v.drain(..).collect();
    v.extend(set.into_iter());
    if v.len() == 1 {
        if k == v[0] {
            println!("POSSIBLE");
        } else {
            println!("IMPOSSIBLE");
        }
        return;
    }

    v.sort();
    let mut g = v[1] - v[0];
    for i in 0..(v.len() - 1) {
        g = gcd(g, v[i + 1] - v[i]);
    }

    if k <= v[v.len() - 1] && (v[v.len() - 1] - k) % g == 0 {
        println!("POSSIBLE");
    } else {
        println!("IMPOSSIBLE");
    }
}

fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn read_line() -> String {
    let stdin = io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf
}

fn read_values<T>() -> Vec<T>
    where T: std::str::FromStr,
          T::Err: std::fmt::Debug
{
    read_line()
        .split(' ')
        .map(|a| a.trim().parse().unwrap())
        .collect()
}

Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main() {
	string s;
	cin >> s;
	int k;
	cin >> k;
	int n = s.size();
	bool b = true;
	rep(i,n-1) if (s[i] != s[i+1]) b = false;
	if (b) {
		cout << (ll) n * k / 2 << endl;
	} else {
		int t = 1;
		ll tot = 0;
		rep(i,n-1) {
			if (s[i] == s[i+1]) t++;
			else {
				tot += t / 2;
				t = 1;
			}
		}
		if (t != 1) tot += t / 2;
		tot *= k;

		if (s[0] != s[n-1]) {
			cout << tot << endl;
		} else {
			ll l = 1;
			ll r = 1;
			rep(i,n-1) {
				if (s[i] == s[i+1]) l++;
				else break;
			}
			for (int i = n-1; i >= 1; i--) {
				if (s[i] == s[i-1]) r++;
				else break;
			}

			cout << tot - l/2*(k-1)- r/2*(k-1) + (l+r)/2*(k-1) << endl;
		}
	}
}

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll n;
	cin>>n;
	ll a[n],sum=0;
	unordered_map<ll,ll> mp;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		mp[a[i]]++;
		sum+=a[i];
	}
	ll q;
	cin>>q;
	while(q--)
	{
		ll b,c;
		cin>>b>>c;
		sum+=mp[b]*(c-b);
		mp[c]+=mp[b];
		mp[b]=0;
		cout<<sum<<endl;
	}
	return 0;
	
}

Measured memory_bytes: 7912
#include<vector>
#include<iostream>
using namespace std;

int main(){
    int N, b;
    int ans = 0;

    std::cin >> N;
    vector<int> A(N), C(N-1);

    for(int i = 0; i < N; i++){
        std::cin >> A[i];
    }

    for(int i=0; i < N; i++){
        std::cin >> b;
        ans = ans + b;
    }

    for(int i=0; i < N-1; i++){
        std::cin >> C[i];
    }

    int a_prev = A[0];
    for(int i = 1; i < N; i++){
        if(A[i] == a_prev + 1){
            ans = ans + C[a_prev-1];
        }
        a_prev = A[i];
    }

    std::cout << ans;

}


Measured memory_bytes: 3608
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = 998244353;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;


template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


ll dfs(Graph& g, ll v,Array& c) {
	bool flag = true;
	for (auto e : g[v]) {
		if (c[e.to] == -1) {
			c[e.to] = !c[v];
			if (!dfs(g, e.to, c)) flag = false;
		}
		else {
			if (c[e.to] == c[v]) flag = false;
		}
	}
	return flag;
}

void solve() {
	ll aa, bb, m;
	cin >> aa >> bb >> m;
	Array a(aa, 0), b(bb, 0);
	REP(i, aa) cin >> a[i];
	REP(i, bb) cin >> b[i];
	ll ans = INF;
	REP(i, m) {
		ll x, y, c;
		cin >> x >> y >> c;
		x--; y--;
		chmin(ans, a[x] + b[y] - c);
	}
	sort(all(a));
	sort(all(b));
	chmin(ans, a[0] + b[0]);
	cout << ans << en;
}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}


Measured memory_bytes: 1792
// https://beta.atcoder.jp/contests/abc065

#include <bits/stdc++.h>
using namespace std;
using ui64 = uint64_t;

const ui64 MOD =  1000000007;
// 階乗と階乗の逆元 mod
const ui64 SIZE = 100001;
ui64 f[SIZE];
ui64 f_inv[SIZE];

// 二分累乗法
// x^n % mod
ui64 power(ui64 x, ui64 n, ui64 mod) {
    ui64 res = 1;
    while (n != 0) {
        if (n % 2 == 1) res = (res * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return res;
}

// 逆元
ui64 inverse_element(ui64 x, ui64 mod) {
    return power(x, mod - 2, mod);
}

void init() {
    auto size = SIZE;
    f[0] = f[1] = 1;
    for (ui64 i = 2; i < size; ++i) f[i] = i * f[i - 1] % MOD;

    f_inv[0] = f_inv[1] = 1;
    for (ui64 i = 2; i < size; ++i) f_inv[i] = inverse_element(f[i], MOD) % MOD;
}

int main() {
    init();

    int n, m;
    cin >> n >> m;
    if (1 < abs(n - m)) {
        cout << "0" << endl;
        exit(0);
    }

    if (abs(n - m) == 1) {
        ui64 ans = f[n] * f[m] % MOD;
        cout << ans  << endl;
        exit(0);
    }

    if (abs(n - m) == 0) {
        ui64 ans = f[n] * f[m] % MOD * 2 % MOD;
        cout << ans  << endl;
        exit(0);
    }

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    string s;
    ll k;
    cin >> s >> k;
    rep(i, 0, s.size()){
        if(s[i] != '1' && k > i){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;


/*
void renketsu(string &r,int n,int m){
    for(int i=m-1;i<r.size()-n;i++){
        r.at(i)=r.at(i+n);
    }
}
*/
//こんなことしなくてもsubstrで解決する

//n番目の文字とn+1番目の文字が違うとき文字列を短くする関数を作成する。
void shorten(string &s,int n){
    if(s.size()-1<n){
        return;
    }
    else if(s.at(n-1)==s.at(n)){
        return;
    }
    else{
        s=s.substr(0,n-1)+s.substr(n+1,s.size()-n-1);
        return;
    }
}

//違うかの判定は他の関数に任せるパターン
void shortcut(string &s,int n){
    if(s.size()-1<n){
        return;
    }
    else{
        s=s.substr(0,n-1)+s.substr(n+1,s.size()-n-1);
        return;
    }
}

//n番目とn+1番目の数が一緒か否かを判定する(違ったらtrue一緒ならfalse)
bool sameornot(string s, int n){
    
    if(s.at(n)!=s.at(n-1)){
        return true;
    }
    else {
        return false;
    }
    
}




//n番目でカット出来たらn==0ならもう一回n番目でカット出来ないか考え、n!=0ならn-1番目でもう一回カット出来ないか考える。
//n番目でカット出来なかったらn+1番目でカット出来ないか考える。
//終了条件はs.size()-1番目でカット出来ないときカットするか考えるのがs.size()番目になったとき

int main(){
    string S;
    cin>>S;
    int kiroku;
    kiroku=S.size();

    int counter=0;
    //int &ccc=S.size();
    while(counter+1<S.size()){
        if(sameornot(S,counter+1)){
            shortcut(S,counter+1);
            if(counter!=0){
                counter--;
            }
        }
        else{
            //shortcut(S,counter+1);
            counter++;
        }
    }
    cout<<kiroku-S.size()<<endl;
}

Measured memory_bytes: 724
#include <stdio.h>
 
int main(){
   int n,a,b,c,k,l[8],aa,bb,cc;
   long i,j,m,p,mp;
    
   scanf("%d %d %d %d",&n,&a,&b,&c);
   m=1;
   for (i=0;i<n;i++) {
      scanf("%d",&l[i]);
      m*=4;
   }
   mp=-1;
   for (i=0;i<m;i++) {
      p=aa=bb=cc=0;
      for (j=i,k=0;k<n;k++) {
         if (j%4==0) {
            if (aa>0) p+=10;
            aa+=l[k];
         } else if (j%4==1) {
            if (bb>0) p+=10;
            bb+=l[k];
         } else if (j%4==2) {
            if (cc>0) p+=10;
            cc+=l[k];
         }
         j=j/4;
      }
      if (aa==0 || bb==0 || cc==0) continue;
      if (aa>a) p+=aa-a;
      else      p+=a-aa;
      if (bb>b) p+=bb-b;
      else      p+=b-bb;
      if (cc>c) p+=cc-c;
      else      p+=c-cc;
      if (mp<0) mp=p;
      else if (p<mp) mp=p;
   }
   printf("%ld\n",mp);
   return 0;
}



Measured memory_bytes: 128