akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
string maze[50];
int fx[]= {-1,1,0,0};
int fy[]= {0,0,-1,1};
int h,w;
int visit[50][50],cost[50][50];
int bfs(int tx,int ty)
{
    int i,j,x,y,temp=0;
    queue<pair<int,int>>q;
    visit[tx][ty]=-1;
    cost[tx][ty]=0;
    q.push(make_pair(tx,ty));
    while(!q.empty())
    {
        pair<int,int>p;
        p=q.front();
        q.pop();
        for(int k=0; k<4; k++)
        {
            x=p.first+fx[k];
            y=p.second+fy[k];
            if(x>=0 && x<h && y>=0 && y<w && visit[x][y]!=-1 && maze[x][y]=='.')
            {
                visit[x][y]=-1;
                cost[x][y]=cost[p.first][p.second]+1;
                q.push(make_pair(x,y));
                temp=max(temp,cost[x][y]);
            }
        }
    }
    return temp;
}
int main()
{
    int i,j;
    int ans=0;
    cin>>h>>w;
    for(i=0; i<h; i++)
    {
        cin>>maze[i];
    }
    for(i=0; i<h; i++)
    {
        for(j=0; j<w; j++)
        {
            if(maze[i][j]=='.')
            {
                memset(visit,0,sizeof(visit));
                memset(cost,0,sizeof(cost));
                ans=max(ans,bfs(i,j));
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main(){
    int N;
    cin >> N;
    vector<char> c(N);
    int r_num = 0, w_num = 0;
    for (int i = 0; i < N; i++) {
        cin >> c.at(i);
        if (c.at(i) == 'R') r_num++;
        else w_num++;
    }
    if (r_num == 0 || w_num == 0) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    for (int i = 0; i < r_num; i++) {
        if (c.at(i) == 'W') ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	int T[110][110], r, c;
	cin >> r >> c;
	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> T[i][j];
		}
	}

	for (int i = 0; i <= r; i++) T[i][c] = 0;
	for (int i = 0; i <= c; i++) T[r][i] = 0;

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			T[i][c] += T[i][j];
			T[r][j] += T[i][j];
			T[r][c] += T[i][j];
		}
	}

	for (int i = 0; i <= r; i++) {
		for (int j = 0; j <= c; j++) {
			if (j) cout << " ";
			cout << T[i][j];
		}
		cout << endl;
	}

	return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC() ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);


int main()
{
    int i = 0, j = 0, cs = 0, in;
    char a; cin>>a;
    if(a >= 97) cout << "a" << endl;
    else cout << "A" << endl;
    return 0;
}


Measured memory_bytes: 3632
using System;
using System.Linq;

class A
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		var s = Console.ReadLine();
		int a = h[1] - 1, b = h[2] - 1, c = h[3] - 1, d = h[4] - 1;
		Console.WriteLine(s.IndexOf("##", a, Math.Max(c, d) - a) == -1 && (c < d || s.IndexOf("...", b - 1, d - b + 3) != -1) ? "Yes" : "No");
	}
}


Measured memory_bytes: 14176
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define FOR(i, m, n) for(ll i = m; i < (n); i++)
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vll = vector<vl>;
using pll = pair<ll, ll>; 

string P = "";
string Q = "";
ll Pnum = 0, Qnum = 0;
ll Pcount = 0, Qcount = 0;

void dfs(string now, ll n, ll m){
    if(n == 0){
        if(now == P){
            Pnum = Pcount;
        }if(now == Q){
            Qnum = Qcount;
        }
        Pcount++;
        Qcount++;
        return;
    }
    for(char c = '1'; c < '1'+m; c++){
        bool con = false;
        for(char nowc : now){
            if(nowc == c) con = true; 
        }
        if(con) continue;
        string next = now;
        next += c;
        dfs(next, n-1, m);
    }
}

int main() {
    ll N;
    cin >> N;
    rep(i, N){
        char c;
        cin >> c;
        P += c;
    }
    rep(i, N){
        char c;
        cin >> c;
        Q += c;
    }
    dfs("", N, N);
    cout << abs(Pnum - Qnum);
}


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

int main(){

 rep(i,3){
  string S; cin>>S;
  cout<<S[0];
 } cout<<endl;

 return 0;
}




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

int main() {
  
  string A, B, C;
  cin >> A >> B >> C;
  
  if(A.at(A.size() - 1) == B.at(0) && B.at(B.size() - 1) == C.at(0)){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  
}



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

int main()
{
	int n;
	cin >> n;
	int a[n];
	loop(i,n)
		cin >> a[i];
	int dp[n];
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for(int i=2;i<n;i++)
	{
		dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, m; string s;
    cin >> n >> m >> s;

    // 逆順から貪欲に最短手数を求める
    vi backGreedyPath = {n};
    ll now = n;
    while(now > 0){
        // 次の手でゴール地点にたどり着ける場合
        if(now - m <= 0){
            backGreedyPath.push_back(0);
            now = 0; break;
        }
        bool moveChk = false;
        // 移動距離が大きい順から見ていく
        for(ll i = m; i>0; i--){
            if(s[now-i] == '0'){
                now -= i;
                backGreedyPath.push_back(now);
                moveChk = true;
                break;
            }
        }
        // 移動不可な場所がある場合
        if(!moveChk){
            cout << -1 << endl;
            return 0;
        }
    }
    for(ll i=backGreedyPath.size()-1; i>0; i--){
        cout << backGreedyPath[i-1]-backGreedyPath[i] << (i == 1 ? endl : " ");
    }
    return 0;
}

Measured memory_bytes: 4412
// 2020-07-15 23:41:12
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  using Work = tuple<int, int, int>; // (x, s, t)
  using P = pair<int, int>;
  int n, q;
  cin >> n >> q;
  vector<Work> works(n);
  rep(i, n) {
    int s, t, x;
    cin >> s >> t >> x;
    works[i] = { x, s-x, t-x };
  }
  sort(ALL(works));
  set<P> ds;
  rep(i, q) {
    int d;
    cin >> d;
    ds.emplace(d, i);
  }
  vector<int> ans(q, -1);
  for(const auto& w : works) {
    int x, s, t;
    tie(x, s, t) = w;
    auto it = ds.lower_bound({ s, -1 });
    while(it != ds.end() && (*it).first < t) {
      int d, qi;
      tie(d, qi) = *it;
      ans[qi] = x;
      it++;
      ds.erase(prev(it));
    }
  }
  for(const auto x : ans) cout << x << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 15492
ans = 0
s = input().replace("BC","D")
l1 = list(s.split("B"))
l2 = []
for x in l1:
  l2 += list(x.split("C"))
for x in l2:
  if x == "":
    continue
  d = 0
  t = 0
  for i in range(len(x)):
    if x[i] == "D":
      d += 1
      t += i
  ans += t - d*(d-1)//2
print(ans)

Measured memory_bytes: 6836
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define crap ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define assign(x,val) memset(x,val,sizeof(x))
vector<int>pre(71,0);
bool isprime(ll n){
    if(n==2) return true;
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0) return false;
    }
    return true;
}
void solve(){
    vector<int>pre(71,0);
    pre[0]=0;
    for(int i=1;i<=11;i++)
    pre[i*(i+1)/2]=1;
    for(int i=2;i<=70;i++){
        pre[i]=pre[i-1]+pre[i];
    }
    ll n;ll ans=0;
    cin>>n;
    if(n==1) {cout<<0;return;}
    if(isprime(n)) {cout<<1;return;}
    int c=0;
    while(n%2==0){
        n/=2;c++;
    }
    //cout<<pre[6];
    ans+=pre[c];
    for(ll i=3;i*i<=n;i+=2){
        c=0;
        while(n%i==0){
            n/=i;c++;
        }
        ans+=pre[c];
    }
    if(n>1) ans+=pre[1];
    cout<<ans;
}
int main() {
    crap;
	int t=1;
	//cin>>t;
	while(t--){
	    solve();
	}
	return 0;
}

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

int a[100][100], b[100], c[100];

#define REP(i, n) for ( int i = 0; i < (n); i++ )

int main() {

    int n, m;

    std::cin >> n >> m;

    REP(i, n) REP(j, m) std::cin >> a[i][j];
              REP(j, m) std::cin >>    b[j];

    REP(i, n) REP(j, m) c[i] += a[i][j] * b[j];

    REP(i, n) std::cout << c[i] << std::endl;

    return 0;
}



Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	register int number_read=0,if_ok_read=1;
	char ch_read=getchar();
	while(ch_read<'0'||ch_read>'9')
	{
		if(ch_read=='-')
			if_ok_read=-1;
		ch_read=getchar();
	}
	while(ch_read>='0'&&ch_read<='9')
	{
		number_read=number_read*10+ch_read-'0';
		ch_read=getchar();
	}
	return number_read*if_ok_read;
}
inline void write(register int x_write)
{
    if(x_write<0)
	{
    	putchar('-');
		x_write=-x_write;
	}
    if(x_write>9)
		write(x_write/10);
    putchar(x_write%10+'0');
    return ;
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int a=read(),b=read(),c=read(),x=read(),total=0;
	for(int i=0;i<=a;i++)
		for(int j=0;j<=b;j++)
			for(int k=0;k<=c;k++)
				if(i*500+j*100+k*50==x)
					total++;
	write(total);
	putchar('\n');
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int fib(int);
int f[50];
int main(void){

  int n, sum;
  
  scanf("%d", &n);

  if(n >= 0 && n <=44){
    sum = fib(n);
  }

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

  return 0;
}

int fib(int n){
  if (n == 0|| n==1){
    return f[n]=1;
  }

  if(f[n])
    return f[n];

  return f[n] = fib(n-1)+fib(n-2);
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    ll N, A, B;
    cin >> N >> A >> B;

    if (A > B)
    {
        cout << 0 << endl;
        return;
    }
    else if (N == 1)
    {
        if (A == B)
        {
            cout << 1 << endl;
            return;
        }
        else
        {
            cout << 0 << endl;
            return;
        }
    }

    const ll min = A + B + A * (N - 2);
    const ll max = A + B + B * (N - 2);
    cout << max - min + 1 << endl;
}


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

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

vector<vector<int> > v(100010);
vector<int> deg(100010);
int dp[100010];

int main(){
	int n, m, x, y;
	scanf("%d%d", &n, &m);
	for(int i=0; i < m; i++) {
		scanf("%d%d", &x, &y);
		v.at(x-1).push_back(y-1);
		deg.at(y-1)++;
	}
	queue<int> que;
	for(int i=0; i < n; i++) if(deg.at(i) == 0) que.push(i);
	while(!que.empty()) {
		int ver = que.front();  que.pop();
		for(auto next: v[ver]) {
			if(--deg.at(next) == 0) {
				que.push(next);
				chmax(dp[next], dp[ver]+1);
			}
		}
	}

	int ans = 0;
	for(int i=0; i < n; i++)
		chmax(ans, dp[i]);
	printf("%d\n", ans);
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<ll,ll> P;

int main(){

	ll a , b;cin >> a >> b;
	if(b % a == 0)cout << a + b << endl;
	else cout << b - a << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string input;
	int n,d=0;
	int counter = 0;
	cin>>n>>input;
	for(int i=0;i<n;i++){
		if(input[i]=='('){
			counter++;
		}
		else{
			counter--;
		}	
		d=min(d,counter);
	}

	for(int i=0;i<-d;i++){
		cout<<"(";
	}
	cout<<input;
	for(int i=0;i<counter-d;i++){
		cout<<")";
	}
	return 0;
}

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

const long double PI = acos(-1);
constexpr long double EPS = 1e-15;
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;

//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair


void solve() {
  int n;
  cin >> n;
  int a[n+1];
  a[0] = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i+1];
    a[i+1] += a[i];
  }
  int ans = inf;
  for (int i = 0; i < n-1; i++) {
    ans = min(ans, abs(a[n] - a[i+1] * 2));
  }
  cout << ans << endl;
}

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

  /*Regular*/
  int case_num = 1;
  if (argc > 1 && stoi(argv[1])) cin >> case_num;
  REP(case_no, case_num) {
    cerr << endl << "case " << case_no + 1 << endl;
    solve();
  }

  // /*ICPC*/
  // while (cin >> t >> d >> l, t) {
  //   solve();
  // }

  //solve();
  return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep2(i,s,n) for(int i = (s); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    string s; cin>>s;
    ll ans=0;
    while(1){
        string t; cin>>t;
        if(t=="END_OF_TEXT") break;
        rep(i,t.size()) t[i]=tolower(t[i]);
        if(t==s) ++ans;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {

	ll n; cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll updown = 0;
	ll cash = 1000;
	ll stock = 0;
	for (ll i = 1; i <= n - 1; i++) {
		ll e = a[i] - a[i - 1];
		if (0 < e) {
			if (updown == 1) {}
			else if (updown == -1 || updown == 0) {
				stock += cash / a[i - 1];
				cash -= a[i - 1] * stock;				
			}
			updown = 1;
		}
		else if (e == 0) {}
		else if (e < 0) {
			if (updown == 1 || updown == 0) {
				cash += a[i - 1] * stock;
				stock = 0;
			}
			else if (updown == -1) {}
			updown = -1;
		}
	}
	if (0 < stock) {
		cash += a[n - 1] * stock;
		stock = 0;
	}
	cout << cash << endl;
	return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 5;

bool vis[N];
int X[N], Y[N];
ll get(int n) {
	vector<int> v(n);
	for (int i = 0; i < n; i++)
		v[i] = i;
	ll ans = 0;
	do {
		int point = 0;
		ll temp = 0;
		for (int i = 0; i < v.size(); i++) {
			int l = X[v[i]];
			int r = Y[v[i]];
			if (point >= l && point <= r) continue;
			if (point < l) {
				temp += abs(point - l);
				point = l;
			} else if (point > r) {
				temp += abs(point - r);
				point = r;
			}
		}
		ans = max(ans, temp + abs(point));
	} while (next_permutation(v.begin(), v.end()));
	return ans;
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
//	srand(time(0));
//	int t = 50;
	int n;
	cin >> n;
	set<pair<int, int> > l, r;
	for (int i = 0, a, b; i < n; i++) {
		cin >> a >> b;
		X[i] = a, Y[i] = b;
		l.insert(make_pair(a, i));
		r.insert(make_pair(b, i));
	}
	int point = 0;
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		while (l.size() && vis[l.rbegin()->second])
			l.erase(*l.rbegin());
		while (r.size() && vis[r.begin()->second])
			r.erase(*r.begin());

		if (l.size()) {
			int x = l.rbegin()->first;
			int ind = l.rbegin()->second;
			if (point < x) {
				ans += x - point;
				vis[ind] = 1;
				point = x;
				continue;
			}
		}
		if (r.size()) {
			int x = r.begin()->first;
			int ind = r.begin()->second;
			if (point > x) {
				ans += point - x;
				point = x;
				vis[ind] = 1;
				continue;
			}
		}
		ans += abs(point);
		point = 0;
		break;
	}
	ans += abs(point);
	ll ans2 = ans;
	ans = 0;
	memset(vis, 0, sizeof vis);
	for (int i = 0, a, b; i < n; i++) {
		a = X[i], b = Y[i];
		l.insert(make_pair(a, i));
		r.insert(make_pair(b, i));
	}
	point = 0;
	ans = 0;
	for (int i = 0; i < n; i++) {
		while (l.size() && vis[l.rbegin()->second])
			l.erase(*l.rbegin());
		while (r.size() && vis[r.begin()->second])
			r.erase(*r.begin());
		if (r.size()) {
			int x = r.begin()->first;
			int ind = r.begin()->second;
			if (point > x) {
				ans += point - x;
				point = x;
				vis[ind] = 1;
				continue;
			}
		}
		if (l.size()) {
			int x = l.rbegin()->first;
			int ind = l.rbegin()->second;
			if (point < x) {
				ans += x - point;
				vis[ind] = 1;
				point = x;
				continue;
			}
		}
		ans += abs(point);
		point = 0;
		break;
	}
	cout << max(ans + abs(point), ans2) << endl;
	return 0;
}



Measured memory_bytes: 12544
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
using ll = long long;

int main(){
        int N,K,i,j,k,r,l,n,surp;
        ll ans=0;
        cin >> N >> K;
        vector<ll> v(N);
        for(i=0;i<N;++i) cin >> v.at(i);
        n = min(N,K);
        for(i=0;i<=n;++i){
                for(r=0;r<=i;++r){
                        vector<ll> lis;
                        l = i - r;
                        for(j=0;j<r;++j) lis.push_back(*(v.end()-1-j));
                        for(k=0;k<l;++k) lis.push_back(v.at(k));
                        sort(lis.begin(),lis.end());
                        surp = K - i;
                        while(surp){
                                if(lis.size()==0) break;
                                if(lis.at(0)<0) lis.erase(lis.begin());
                                else break;
                                --surp;
                        }
                        ans = max(ans, accumulate(lis.begin(), lis.end(), 0LL));
                }
        }
        cout << ans << endl;
        return 0;
}

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

using namespace std;

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

long long dp[110][100010]; //main関数内で宣言すると以降sigsev

int main(){
  for(int i=0;i<110;i++){
    for(int j=0;j<100010;j++){
      dp[i][j] = 0;
    }
  }
  int N;
  long long W, weight[110], value[110];

  cin >> N >> W;
  for(int i=0;i<N;i++){
    cin >> weight[i] >> value[i];
  }
  for(int i=0;i<N;i++){
    for(int sum_w = 0;sum_w<=W; sum_w++){
      //select i'th object
      if(sum_w + weight[i] <= W){
        chmax(dp[i+1][sum_w+weight[i]], dp[i][sum_w] + value[i]);
      }
      //doesn't select i'th object
      chmax(dp[i+1][sum_w], dp[i][sum_w]);
    }
  }
  long long ans;
  for(int i=0;i<=W;i++){
    chmax(ans,dp[N][i]);
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 86144
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

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

    int ans = -1;
    for (int i=0; i<10000; i++) {
        if ((int)(i*0.08) == a && (int)(i*0.1) == b) ans = i;
        if (ans > 0) break;
    }

    cout << ans << endl;
}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

int main() {
  ll r;
  cin >> r;
  cout << r * r << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long
#define ld long double
#define MAX 1000000000
#define MOD 1000000007
#define MOD2 998244353
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
    //cin>>t;
    for(int cc=1;cc<=t;cc++){
        //cout<<"Case #"<<cc<<": ";
        int s,w;
        cin>>s>>w;
        if(w>=s)
            cout<<"unsafe\n";
        else
            cout<<"safe\n";
    }
}


Measured memory_bytes: 3636
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#include <iomanip>
#include<set>
#include <numeric>
#pragma region Macros
#define int long long
#define double long double
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define LAST(x) x[x.size()-1]
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define DIVCEIL(a,b) ((a+b-1)/b)
//int CHMAX

int FACT(int a) {
	if (a == 0)
		return 1;
	else
		return a * FACT(a - 1);
}
int MODFACT(int a, int mod) {
	if (a == 0)
		return 1;
	else
		return (a * FACT(a - 1))%mod;
}
int nPr(int n, int r) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++)
		sum *= i;
	return sum;
}
int MODnPr(int n, int r, int mod) {
	int s = n - r + 1;
	int sum = 1;
	for (int i = s; i <= n; i++) {
		sum *= i;
		sum = sum % MOD;
	}
	return sum;
}
//int nCr(int n, int r)
int nCr2(int n, int r) {
	return FACT(n) / (FACT(r) * FACT(n - r));
}
int GCD(int a, int b)
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b)
{
	return  a * b / GCD(a, b);
}
int NUMOFDIV(int n) {
	//約数の数（だっけ？）
	int ans = 0;
	REP(i, n) {
		if (n % i == 0)
			ans++;
	}
	return ans;
}
int CEIL1(int n) {
	//1桁目切り上げ
	return (n + 9) / 10 * 10;
}
int DIGIT(int n,int k) {
	//nのk桁目
	rep(i, k-1)
		n /= 10;
	return n % 10;
}
int DIGITSUM(int n) {
	int sum = 0, dig;
	while (n) {
		dig = n % 10;
		sum += dig;
		n /= 10;
	}
	return sum;
}
int DIVTIME(int n, int k) {
	//nをkで何回割れるか的な
	int div = 0;
	while (n % k == 0) {
		div++;
		n /= k;
	}
	return div;
}
int MODPOW(int a, int n, int mod) {
	// a^n mod
	int ans = 1;
	while (n > 0) {
		if (n & 1)
			ans = ans * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return ans;
}
double LOG(int a, int b) {
	return log(b) / log(a);
}
inline bool BETWEEN(int x, int min, int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}
inline bool between(int x, int min, int max) {
	if (min < x && x < max)
		return true;
	else
		return false;
}
inline bool PRIMEOR(int x) {
	if (x == 1)
		return false;
	if (x == 2)
		return true;
	if (x % 2 == 0)
		return false;
	double sqrtx = sqrt(x);
	for (int i = 3; i <= sqrtx; i += 2) {
		if (x % i == 0)
			return false;
	}
	return true;
}
bool SQRTOR(int n) {
	if (sqrt(n) == (int)sqrt(n))
		return true;
	else
		return false;
}
// 順位付け
using namespace std;
#pragma endregion
signed main() {
	int N,x,SUM=0;
	cin >> N;
	vector <int> Sum(N+1);
	vector <int> A(N+1);
	vector <int> nC2(N + 1);
	rep(i, N) {
		cin >> x;
		Sum[x]++;
		A[i] = x;
	}
	REP(i, N) {
		SUM += Sum[i] * (Sum[i] - 1) / 2;
		nC2[i] = Sum[i] * (Sum[i] - 1) / 2;
	}
	REP(i, N) {
		cout << SUM - nC2[A[i-1]] + (Sum[A[i-1]] - 1) * (Sum[A[i-1]] - 2) / 2 << endl;
	}
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	long long N,S;
	cin >> N >> S;
	for(int b =2; b <= 1000000; b++) {
		long long x =N, s =0;
		while(x > 0) {
			s +=x%b;
			x /=b;}
		if(s == S) {cout << b << "\n"; return 0;}
		}
	long long minb =-1;
	for(long long x =1; x <= 1000000; x++) {
		long long r =S-x;
		if(r < 0) continue;
		long long y =N-r;
		if(y < 0) continue;
		if(y%x != 0) continue;
		long long b =y/x;
		if(b <= r || b == 0) continue;
		long long z =N, s =0;
		while(z > 0) {
			s +=z%b;
			z /=b;}
		if(s == S) minb =(minb == -1)?b:min(minb,b);
		}
	if(minb != -1) {cout << minb << "\n"; return 0;}
	if(S == N) {cout << N+1 << "\n"; return 0;}
	cout << "-1\n";
	return 0;}

// look at my code
// my code is amazing


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

 int N;
vector<int> v;
vector<int> p,q;
 
int main(){
    int t;
    cin >> N;
    for(int i=1;i<=N;i++) v.push_back(i);
    for(int i=0;i<N;i++){
        cin >> t;
        p.push_back(t);
    }
    for(int i=0;i<N;i++){
        cin >> t;
        q.push_back(t);
    }
    int a,b,i;
    i=0;
    do{
        if(p == v) a = i;
        if(q == v) b = i;
        i++;
    }while(next_permutation(v.begin(),v.end()));
    cout << abs(a-b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
 
int n, k;
const int MAX_N = 20000;
vector<int> bit;
 
int bit_sum(int i) {
  int s = 0;
  while(i > 0) {
    s += bit[i];
    i -= i & (-i);
  }
  return s;
}
 
void bit_add(int i, int val) {
  while(i <= n) {
    bit[i] += val;
    i += i & (-i);
  }
}
 
int main () {
  scanf("%d%d", &n, &k);
 
  vector<ll> s(n+1);
 
  s[0] = 0;
  rep(i,n) {
    int a;
    scanf("%d", &a);
    s[i+1] = s[i] + (a - k);
  }
 
  vector<ll> ss(s);
  sort(ss.begin(), ss.end());
 
  for(int i = 0; i <= n; i++) {
    s[i] = distance(ss.begin(), lower_bound(ss.begin(), ss.end(), s[i])) + 1;
  }
 
  bit = vector<int>(n+2, 0);
  ll c = 0;
  for(int i = n; i >= 0; i--) {
    c += bit_sum(s[i] - 1);
    bit_add(s[i], 1);
  }
 
  printf("%lld\n", ll(n)*(n+1)/2 - c);
 
  return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>

using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
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);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    int n;
    cin >>n;
    vector <ll> a(n);
    rep(i,0,n) {
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    cout << a[a.size()-1] - a[0] << endl;
}

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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	string s;
	cin>>s;
	int ans=0,c=0;
	for(int i=0;i<3;i++){
		if(s[i]=='R'){
			c++;
			ans=max(ans,c);
		}
		else{
			c=0;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

const int MAX_B = 104;
bool p[MAX_B];

int main() 
{
    int A, B, C;
    cin >> A >> B >> C;
    int x = 0;
    p[0] = true;
    while(true) {
        x += A; x %= B;
        if(p[x]) break;
        p[x] = true;
    }
    if(p[C]) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

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

  int add = a + b;
  int sub = a - b;
  int mult = a * b;
  int MAX = max(add, max(sub, mult)); 

  cout << MAX << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x)     (x).begin() , (x).end()
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
typedef long long int ll;
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}


const ll mod = 1e9+7;
const double eps = 1e-9;



int n;
void solve(){
    cin >> n;
    if(n>=400 && n<=599)
        cout << 8 ;
    if(n>=600 && n<=799)
        cout << 7 ;
    if(n>=800 && n<=999)
        cout << 6 ;
    if(n>=1000 && n<=1199)
        cout << 5 ;
    if(n>=1200&& n<=1399)
        cout << 4 ;
    if(n>=1400 && n<=1599)
        cout << 3 ;
    if(n>=1600&& n<=1799)
        cout << 2 ;
    if(n>=1800 && n<=1999)
        cout << 1 ;
    cout << "\n";
}





int main(){
    fastio 
    int test=1;
    while(test--)
        solve();
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

vector< vector<int> > G;
ll dfs(int v, int prev, int depth, int th) {
    ll res = 0;
    if (depth >= th) ++res;
    EACH(to, G[v]) {
        if (to == prev) continue;
        res += dfs(to, v, depth+1, th);
    }
    return res;
}
int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n, k; cin >> n >> k;
    G.resize(n);
    REP(i, n-1) {
        int a, b; cin >> a >> b; --a, --b;
        G[a].pb(b);
        G[b].pb(a);
    }
    ll ans = inf;
    REP(i, n) {
        ll sum = 0;
        ll M = 0;
        EACH(to, G[i]) {
            ll cnt1 = dfs(to, i, 0, k/2);
            ll cnt2 = dfs(to, i, 0, (k+1)/2);
            M = max(M, cnt1-cnt2);
            sum += cnt1;
        }
        sum -= M;
        ans = min(ans, sum);
    }
    cout << ans << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        
        if(a < b && b < c && a < c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 26352
//
// Created by munaiyi on 2020/3/8.
//

#include<bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 5;
char shit[maxn];

long long fast(int num, int mod) {
    int ci = mod - 2;
    long long ans = 1;
    while (ci) {
        if (ci & 1) ans = ans * num % mod;
        num = num * num % mod;
        ci = ci >> 1;
    }
    return ans;
}

int main() {
    int n, p;
    scanf("%d%d", &n, &p);
    scanf("%s", shit);
    if (p == 2 || p == 5) {
        long long ans = 0;
        for (int i = 0; i < n; i++) {
            int num = shit[i] - '0';
            if (num % p == 0) {
                ans += i + 1;
            }
        }
        printf("%lld\n", ans);
        return 0;
    }
    vector<int> cnt(p + 1, 0);
    cnt[0]++;
    long long inv = fast(10, p);
    long long invten = 1;
    long long now = 0;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        int num = shit[i] - '0';
        now = (now * 10 + num) % p;

        // if we want it mod p equal to b  ten tmp = (now - b + p) * invten % p; ans+=cnt[tmp]
        //  then tmp = now * invten % p;  cnt[tmp]++;
        long long tmp = now * invten % p;
        //printf("%lld %d %lld %d\n", now, i, tmp, cnt[tmp]);
        ans += cnt[tmp];
        cnt[tmp]++;
        invten = invten * inv % p;
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int N,K;
vector<int> G[2001];
int d[2001];
int visited[2001];

void print(int n){
  for(int i=1;i<=n;i++) printf("%d ",d[i]);
  printf("\n");
}
void dfs(int s,int D,int x){
  visited[s]=1;
  d[s]=D+1;
  for(int i=0;i<G[s].size();i++){
    int v=G[s][i];
    if(visited[v]==0 && v!=x){dfs(v,d[s],x);}
  }
}

void e_dfs(int a,int b,int D){
  //printf("edge %d - %d\n",a,b);
  dfs(a,D,b);
  //print(N);
  dfs(b,D,a);
  //print(N);
  //printf("\n");
}
int min(int a,int b){
  return a<b?a:b;
}

int main(){
  int count,ans=3000;
  scanf("%d %d",&N,&K);
  for(int i=0;i<N-1;i++){
    int a,b;
    scanf("%d %d",&a,&b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
 
  if(K%2==0){
    for(int i=1;i<=N;i++){
      fill(d,d+N+1,0);
      fill(visited,visited+N+1,0);
      dfs(i,-1,3000);
      count=0;
      for(int j=1;j<=N;j++){
	if(d[j]>K/2)count++;
      }
      ans=min(ans,count);
    }
  }
  else{
    for(int i=1;i<=N;i++){
      for(int j=0;j<G[i].size();j++){
	count=0;
	int v=G[i][j];
	fill(d,d+N+1,0);
	fill(visited,visited+N+1,0);
	e_dfs(i,v,-1);
	for(int k=1;k<=N;k++){
	  if(d[k]>(K-1)/2)count++;
	}
	ans=min(ans,count);
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

x,a,b=MI()
l1=abs(x-a)
l2=abs(x-b)
if l1<l2:
    print("A")
else:
    print("B")

Measured memory_bytes: 3316
import std.stdio;
import std.string;
import std.algorithm;
import std.array;
import std.conv;

int solve(int[] list) {
  while (list.length > 1) {
    int[] res = new int[](list.length - 1);
    for(int i = 0; i < list.length - 1; i++) {
      res[i] = (list[i] + list[i + 1]) % 10;
    }
    list = res;
  }
  return list[0];
}

void main() {
  string line;
  while ((line = readln.chomp).length != 0) {
    line.array.map!((x) => x.to!(int) - '0').array.solve.writeln;
  }
}

Measured memory_bytes: 1096
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

#define ll long long
#define ldb long double
#define db double
#define str string

#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair

#define pi pair<int,int>
#define pll pair<ll,ll>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vll vector<ll>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >
#define vpll vector< pll >

#define mi map<int,int>
#define mll map<ll,ll>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(i,a,b) for (int i = (a); i < (b); ++i)
#define rrof(i,a,b) for (int i = (b)-1; i >= (a); --i)


const int MOD = 1e9+7;
const ldb PI = 4*atan((ldb)1);

ll power(ll a,ll n){
	ll res=1;

	while(n){
		if(n%2)
		res*=a;
		a*=a;
		n/=2;
	}
	
	return res;
}

ll int dp[10001];

ll int solve(ll int h,ll int*a,ll int*b,int n){
	if(h<=0)
	return 0;
	
	if(dp[h]!=-1)
	return dp[h];
	
	ll int ans=INT_MAX;
	forr(i,0,n)
	ans=min(ans,solve(h-a[i],a,b,n)+b[i]);	
	
	dp[h]=ans;
	return ans;
}

int main(){
	fast;
	
	ll int h,n;
	cin>>h>>n;
	
	forr(i,0,10001)
	dp[i]=-1;
	
	ll int a[n],b[n];
	forr(i,0,n)
	cin>>a[i]>>b[i];
	
	ll int ans=solve(h,a,b,n);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1152
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);

		String a = sc.next();
		String b = sc.next();
		String c = sc.next();



		if (a.substring(a.length() - 1).equals(b.substring(0, 1))
				&& b.substring(b.length() - 1).equals(c.substring(0, 1)))

		{

			System.out.println("YES");

		} else {
			System.out.println("NO");

		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

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

    int n;
    cin >> n;

    int mx = 0;
    ll sum = 0;
    rep(i, n) {
        int a;
        cin >> a;
        chmax(mx, a);
        sum += mx - a;
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3652
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        abc135_c solver = new abc135_c();
        solver.solve(1, in, out);
        out.close();
    }

    static class abc135_c {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.Int();
            int[] A = in.Int(N + 1);
            int[] B = in.Int(N);

            long ans = 0;
            for (int i = 0; i < N; i++) {
                if (A[i] <= B[i]) {
                    ans += A[i];
                    B[i] -= A[i];
                } else {
                    ans += B[i];
                    B[i] = 0;
                }
                int min = Math.min(A[i + 1], B[i]);
                ans += min;
                A[i + 1] -= min;

            }
            out.println(ans);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

        public int[] Int(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = Int();
            }
            return a;
        }

    }
}



Measured memory_bytes: 42820
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define ssll(x,y)    scanf("%lld %lld", &x ,&y)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


const int maxx = 21;
char s[maxx];

int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		scanf("%s",s);
		for (int i=0 ; i<3 ; i++)
		printf("%c",s[i]);
		return 0;
}  


Measured memory_bytes: 3712
class Factorial:
    def __init__(self, n, mod):
        self.f = [1]
        self.mod = mod
        for j in range(1, n + 1):
            self.f.append(self.f[-1] * j % mod)
        self.i = [pow(self.f[-1], mod - 2, mod)]
        for j in range(n, 0, -1):
            self.i.append(self.i[-1] * j % mod)
        self.i.reverse()
    def factorial(self, j):
        return self.f[j]
    def ifactorial(self, j):
        return self.i[j]
    def comb(self, n, k):
        return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod if n >= k else 0


N, A, B, K = map(int, input().split())
MOD = 998244353

c = Factorial(N + 1, MOD).comb

def calc(a, b):
    return (c(N, a) * c(N, b)) % MOD

ans = 0
for a in range(N + 1):
    b = (K - (A * a)) // B
    if A * a + B * b == K and 0 <= b <= N:
        ans += calc(a, b)
        ans %= MOD

print (ans)


Measured memory_bytes: 26796
N, X = map(int, input().split())

gram = 0
first_flag = True
for i in range(N):
    x = int(input())
    gram += x
    if first_flag:
        min = x
        first_flag = False
    else:
        if min > x:
            min = x

print(N + int((X - gram)/min))


Measured memory_bytes: 2940
N = int(input())
A = list(map(int, input().split()))
def isOdd(n):
    return n % 2 == 1
def div2(n):
    return n // 2

res = 0
while True:
    if sum(map(isOdd, A)) > 0 or sum(A) == 0:
        print(res)
        exit()
    else:
        res += 1
        A = list(map(div2, A))



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define ALL(n) begin(n),end(n)

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    
    REP(i,n){
        cin>>a[i];
    }
    
    for(int i=n-1; i>0; i--){
        cout<<a[i]<<" ";
    }
    
    cout<<a[0]<<endl;
}


Measured memory_bytes: 3080