akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
   /* #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,s=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        if(i%3==0&&i%5==0)
            continue;
        else if(i%3==0)
            continue;
        else if(i%5==0)
            continue;
        else
        {
          s+=i;
        }
    }
    cout<<s<<endl;
}
return 0;
}

Measured memory_bytes: 3600
'use strict';
process.stdin.on('data', function(chunk) {
    var inputs = chunk.toString().trim().split('\n').map(Number);
    for (var i = 0; i < inputs.length; i++) {
        if (inputs[i] === 0) {
            break;
        }
        console.log('Case ' + (i + 1) + ': ' + inputs[i]);
    }
});
process.stdin.resume();
process.stdin.setEncoding('utf8');

Measured memory_bytes: 20632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
const int N = 200005;
int n;
vector<pair<ll, ll> > v;
ll memo[2000][2000];
ll solve(int *arr, int i, int l, int r) {
if (i==n) {
return 0LL;
}
if (memo[l][r] != -1) {
return memo[l][r];
}
ll ans1 = solve(arr, i + 1, l + 1, r) + (1LL * v[i].first * abs(v[i].second - l));
ll ans2 = solve(arr, i + 1, l, r - 1) + (1LL * v[i].first * abs(v[i].second - r));
return memo[l][r] = max(ans1, ans2);
 
}
 
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
cin >> n;
int arr[2005];
for (int i = 0; i < n; i++)
cin >> arr[i];
for (int i = 0; i < n; i++) {
v.push_back({arr[i], i});
}
memset(memo, -1, sizeof memo);
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
// for (int i = 0; i < n; i++) {
// cout << v[i].first << " " << v[i].second << endl;
// }
ll ans = solve(arr, 0, 0, n - 1);
cout<<ans<<endl;
return 0;
 
}

Measured memory_bytes: 35112
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();

    final int MAX = 55_555;
    final boolean[] isPrimse = new boolean[MAX + 1];
    for (int i = 2; i <= MAX; i++) isPrimse[i] = true;
    for (int i = 2; i < Math.sqrt(MAX); i++) {
      if (isPrimse[i]) {
        for (int j = 2; i * j <= MAX; j++) {
          isPrimse[i * j] = false;
        }
      }
    }
    int count = 0;
    for (int i = 2; i <= MAX && count < N; i++) {
      if (isPrimse[i] && i % 5 == 1) {
        System.out.printf("%d ", i);
        count++;
      }
    }
    System.out.println();
  }
}


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

int main(){
  string s, t;
  int ans=0;
  cin>>s>>t;

  REP(i,3){
    if(s.at(i) == t.at(i)) ans++;
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
   	int a, b;
   	int val, i, count;
   	count = 0;
   	scanf("%d %d %d", &a, &b, &val);
   	for(i = a; i <= b; i++)
   	{
   		if(val % i == 0) count++;
   	}
   	printf("%d\n", count);
    return 0;
}

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

// #include "debug.h"
// #define debug(...) 42

using ll = long long;

void solve() {
   ll n, k;
   cin >> n >> k;
   vector <pair <int, int>> v(n);
   for(int i = 0; i < n; i++) {
      cin >> v[i].first >> v[i].second;
   }
   sort(v.begin(), v.end());
   ll cur = 0;
   for(int i = 0; i < n; i++) {
      cur += v[i].second;
      if(cur >= k) {
         cout << v[i].first << endl;
         return;
      }
   }
} 

int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   int testcase = 1;
   // cin >> testcase;

   for(int i = 0; i < testcase; i++) {
      solve();
   } 
   return 0;
}


Measured memory_bytes: 3960
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

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

typedef struct {
    int number;       //
    int parent_num;
    int depth;
    char var[20];
    int child_num;    //
    int *children;    //
} Node;

void dfs_set_var_depth(Node array[], int depth, int index){
    
    array[index].depth = depth;
    int cn = array[index].child_num;
    
    if(array[index].parent_num == -1){
        strncpy(array[index].var, "root", sizeof("root") + 1);
    }
    else if(cn == 0){
        strncpy(array[index].var, "leaf", sizeof("leaf") + 1);
    }
    else{
        strncpy(array[index].var, "internal node", sizeof("internal node") + 1);
    }
    
    if(cn == 0) return;
    
    REP(i,cn){
        int child_index = array[index].children[i];
        dfs_set_var_depth(array, depth + 1, child_index);
    }
    
}


int main(int argc, const char * argv[]) {
    //Input
    int n,id,k, c, root_num;
    
    scanf("%d", &n);
    
    Node * node_array = NULL;
    node_array = (Node *)malloc(sizeof(Node) * n);
    
    
    //set value into Node struct
    REP(i,n){
        scanf("%d", &id);
        scanf("%d", &k);
        node_array[id].number = id;
        node_array[id].parent_num = -1;
        node_array[id].depth = 0;
        node_array[id].child_num  = k;
        if(k > 0){
            node_array[id].children = (int *)malloc( sizeof(int) * k );
            REP(j,k){
                scanf("%d", &c);
                node_array[id].children[j] = c;
            }
        }
    }
    
    //set parent_num
    int cn;
    REP(i,n){
        cn = node_array[i].child_num;
        int parent_index = node_array[i].number;
        
        REP(j,cn){
            int child_index = node_array[i].children[j];
            node_array[child_index].parent_num = parent_index;
        }
    }
    
    //choose parent node
    REP(i,n){
        if(node_array[i].parent_num == -1){
            root_num = i;
            break;
        }
    }
    
    //set depth, var
    dfs_set_var_depth(node_array, 0, root_num);
    
    //print answer
    REP(i,n){
        printf("node %d: parent = %d, depth = %d, %s, [", node_array[i].number, node_array[i].parent_num, node_array[i].depth, node_array[i].var);
        
        int cn = node_array[i].child_num;
        REP(j,cn){
            printf("%d", node_array[i].children[j]);
            if(j != cn - 1){
                printf(", ");
            }
        }
        printf("]\n");
    }

    //free memory
    REP(i,n){
        if(node_array[i].child_num > 0){
            free(node_array[i].children);
        }
    }
    free(node_array);
    
    return 0;
}

Measured memory_bytes: 6176
// Why am I so dumb? :c
#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair

#define all(x) (x).begin(), (x).end()

#define fi first
#define se second

using namespace std;

typedef long long ll;

int mn[2005][2005];

int arr[4005];

int n, x;

ll ans;

void solve() {                   
	scanf("%d %d", &n, &x);

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

    for (int r = 1; r <= n; ++r) {
    	mn[r][1] = arr[r];

    	for (int len = 2; len <= n; ++len) {
			mn[r][len] = min(mn[r][len - 1], arr[r + n - len + 1]);			    	
    	}
    }     

    ans = (ll)1e18;

    for (int len = 1; len <= n; ++len) {
    	ll cur = x * (len - 1ll);

		for (int i = 1; i <= n; ++i) {
			cur += mn[i][len];
		}				

		ans = min(ans, cur);
    }

    printf("%lld\n", ans);
}

int main() {    
    int tt = 1;

    while (tt--) {
        solve();
    }

    return 0;
}

Measured memory_bytes: 15872
#include<stdio.h>


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

 scanf("%d", &a);
 scanf("%d", &b);
 
 if(a<-1000||b>1000)
printf("Too Large\n");

 if(a>b)
 printf("a > b\n");

 if(a<b)
 printf("a < b\n");

  if(a==b)
 printf("a == b\n");
}

Measured memory_bytes: 1804
N = int(input())
S = input()

flag = 0
count = 0

for i in S:
  if i == "A":
    flag = 1
  elif i == "B" and flag == 1:
    flag = 2
  elif i == "C" and flag == 2:
    flag = 0
    count += 1
  else:
    flag = 0
print(count)
  

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
#define ll long long
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define rrep(i,a,b) for(ll i=a;i>b;i-=1)
#define vi vector<ll>
#define vii vector<vector<ll> >
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define sz(a) int((a).size())
#define tr(c,i) for( typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define mp make_pair
#define hell 1000000007
#define F first
#define S second
//debug
#define trace(x)                 cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
ll t=1;
map<int,vector<int> > adj;
vector<bool> vis(100000,0);
int n,m;
void dfs(int i)
{
    cout<<i<<endl;
    vis[i]=true;
    for(int j=1;j<=n;j++)
    {
        if(!vis[j])
        dfs(j);
    }
}
void solve()
{
    int n,m;
    cin>>n>>m;
    int dp[n][m];
    char a[n][m];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>a[i][j];
        }
    }
    int flag=0;
    for(int i=0;i<m;i++)
    {
        if(a[0][i]!='#' && !flag)
        {
            dp[0][i]=1;
        }
        else
        {
            dp[0][i]=0;
            flag=1;
        }
    }
    flag=0;
    for(int j=0;j<n;j++)
    {
        if(a[j][0]!='#' && !flag)
        {
            dp[j][0]=1;
        }
        else
        {
            dp[j][0]=0;
            flag=1;
        }
    }
    for(int i=1;i<n;i++)
    {
        for(int j=1;j<m;j++)
        {
            if(a[i][j]!='#')
            dp[i][j]=(dp[i-1][j]+dp[i][j-1])%hell;
            else dp[i][j]=0;
        }
    }
    cout<<dp[n-1][m-1];
}
int main()
{
    int i;
  	ios_base::sync_with_stdio(false);
	cin.tie(0);
    cout.tie(0);
  	//cin>>t;
  	while(t--)
	solve();
	return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define setbits(x) __builtin_popcount(x)
#define zerobits(x) __builtin_ctz(x)
#define setbitsll(x) __builtin_popcountll(x)
#define zerobitsll(x) __builtin_ctzll(x)
#define inf 1e18
#define ps(x,y) fixed<<setprecision(y)<<x

typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef map<int,int> mii;

const int MOD = 1e9+7;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	vi arr(n);
	for (int i = 0;i < n;++i) {
		cin >> arr[i];
	}
	sort(all(arr));
	for (int i = 1;i < n;++i) {
		if (arr[i] == arr[i-1]) {
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";

	return 0;
}



Measured memory_bytes: 3920
#include <stdio.h>
#include <algorithm>
using namespace std;
const int N=1e2+10;
int main(){
    int n,a[N],now,ans;
    while(scanf("%d",&n)!=EOF){
        for(int i=0;i<n;i++)scanf("%d",&a[i]);
        sort(a,a+n);
        now=ans=0;
        for(int i=0;i<n;i++){
            now+=a[i];
            ans+=now;
        }
        printf("%d\n",ans);
    }
}


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

int main() {
  int H, W, A, B, N;
  int y=0;
  long int x=0;
  string S;
  cin >> A >> B;
  vector<int> vec(N);

  if (A<=9 && B<=9) cout << A*B << endl;
  else cout << "-1" << endl;

    
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];
    sort(all(p));
    ll ans = 0;
    rep(i, k){
        ans += p[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
import java.util.*;

class Main {
	Scanner sc;
	int N;
	long K;
	long[] A, F;
	
	Main() {
		sc = new Scanner(System.in);
	}
	
	private void calc() {
		N = sc.nextInt();
		A = new long[N];
		F = new long[N];
		K = sc.nextLong();
		for (int i = 0; i < N; i++) A[i] = sc.nextLong();
		for (int i = 0; i < N; i++) F[i] = sc.nextLong();
		Arrays.sort(A);
		Arrays.sort(F);
		for (int i = 0; i < N/2; i++) {
			F[i] ^= F[N-1-i];
			F[N-1-i] ^= F[i];
			F[i] ^= F[N-1-i];
		}
		
		long ans = 0x7fffffffffffffffL;
		for (long bit = 1L<<62; bit > 0L; bit >>>= 1) {
			if (requiredK(ans & ~bit) > K) continue;
			ans &= ~bit;
		}
		System.out.println(ans);
	}
	
	private long requiredK(long minVal) {
		long s = 0L;
		for (int i = 0; i < N; i++) {
			long x = minVal/F[i];
			if (A[i] > x) s += (A[i]-x);
		}
		return s;
	}
	
	public static void main(String[] args) throws Exception {
		new Main().calc();
	}
}


Measured memory_bytes: 102688
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ls x<<1
#define rs x<<1|1
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-6;
const ull hashp=131;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=998244353;
const int maxn=2e5+100;

void solve(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<c<<" "<<a<<" "<<b<<endl;
}
int main(){
    //IOS;
    //freopen("D://data.txt","r",stdin);
    solve();
    
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;;                                             ;;
	;;         ;;            ;;;;;;;;;       ;;    ;;
	;;        ;; ;;        ;;                ;;    ;;
	;;       ;;   ;;       ;;                ;;    ;;
	;;      ;;;;;;;;;      ;;                ;;    ;;
	;;     ;;       ;;     ;;                      ;;
    ;;    ;;         ;;      ;;;;;;;;;       ;;    ;;
    ;;                                             ;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int a = 0, z = 0;
  for (int j = 0; j < 2; j++) {
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'A' && j == 0) {
        a = i;
        break;
      }
      if (s[i] == 'Z' && j == 1) {
        z = s.size() - i;
        break;
      }
    }
    reverse(s.begin(), s.end());
  }
  cout << z - a << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;

typedef long long ll;
typedef long double db;
typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vii;
typedef pair<int, int> pi;
typedef tuple<int, int, int> t3;
typedef map<int, int> mi;
#define fi first
#define se second
#define be begin()
#define ed end()
#define sz size()
#define cl clear()
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define lb(v, x) lower_bound(v.begin(), v.end(), x)
#define lbi(v, x) (lb(v, x) - v.begin())
#define tp(t, x, y) t x, y; tie(x, y)
#define tp3(t, x, y, z) t x, y, z; tie(x, y, z)
#define mp make_pair
#define mt make_tuple
#define co const
#define fc(x) for(int x = 1, _end = ri(); x <= _end; x++)
void uni(vi &v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); }

db rd() { db x; cin >> x; return x; }
ll ri() { ll x; cin >> x; return x; }
string rs() { string s; cin >> s; return s; }
pi rpi() { pi x; cin >> x.fi >> x.se; return x; }
vi rvi(int n, int f = 0) { vi v(n + f); for (int i = f; i < v.size(); i++) cin >> v[i]; return v; }
vii rvii(int n, int m, int f = 0) { vii v(n + f, vi(n + f)); for (int i = f; i < v.size(); i++) for (int j = f; j < v[0].size(); j++) cin >> v[i][j]; return v; }
void pr() {}; template <class T, class ...U> void pr(T x, U ...y) { cout << x << ' ', pr(y...); }
void prl() { cout << '\n'; }; template <class T, class ...U> void prl(T x, U ...y) { cout << x << ' ', prl(y...); }
void pr(const vi &v, int f = 0) { for (int i = f; i < v.size(); i++) cout << v[i] << ' '; }
void prl(const vi &v, int f = 0) { pr(v, f); cout << '\n'; }
void pr(const pi &x) { cout << x.fi << ' ' << x.se; };
void prl(const pi &x) { pr(x); cout << '\n'; }

#define rep(i, l, r) for (int i = l; i < r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)

const int N = 2e5 + 5, M = 1e9 + 7;

ll sqr(ll x) { return x * x; }

ll dis2(co pi &a, co pi &b) {
  return sqr(a.fi - b.fi) + sqr(a.se - b.se);
}

db dis(co t3 &t, co pi &p) {
  tp3(ll, x, y, r) = t;
  db d = sqrt(dis2(mp(x, y), p));
  return max(d - r, db(0));
}
db dis(co t3 &a, co t3 &b) {
  tp3(ll, x, y, r) = a;
  tp3(ll, u, v, w) = b;
  db d = sqrt(dis2(mp(x, y), mp(u, v)));
  return max(d - r - w, db(0));
}

vector<pair<db, int>> g[N];

int main() {
  cout << setprecision(10) << fixed;
  pi a = rpi(), b = rpi();
  int n = ri();
  vector<t3> vp(n);
  rep(i, 0, n) {
    vp[i] = {ri(), ri(), ri()};
    g[i].eb(dis(vp[i], a), n);
    g[n].eb(dis(vp[i], a), i);
    g[i].eb(dis(vp[i], b), n + 1);
    g[n + 1].eb(dis(vp[i], b), i);
  }
  rep(i, 0, n) {
    rep(j, i + 1, n) {
      g[i].eb(dis(vp[i], vp[j]), j);
      g[j].eb(dis(vp[i], vp[j]), i);
    }
  }
  g[n].eb(sqrt(dis2(a, b)), n+1);
  g[n+1].eb(sqrt(dis2(a, b)), n);
  set<pair<db, int>> s = {{0, n}};
  vector<db> d(n + 2, 1e15);
  d[n] = 0;
  while (s.size()) {
    auto p = *s.begin(); s.erase(s.begin());
    for (auto &e : g[p.se])
      if (p.fi + e.fi < d[e.se])
        s.erase({d[e.se], e.se}),
        d[e.se] = p.fi + e.fi,
        s.insert({d[e.se], e.se});
  }
  pr(d[n+1]);
}


Measured memory_bytes: 40688
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let ab = Array.to_list @@ Array.init n @@ fun _ -> Scanf.sscanf (read_line ()) "%d %d" @@ fun a b -> (b, a)
let cd = Array.to_list @@ Array.init n @@ fun _ -> Scanf.sscanf (read_line ()) "%d %d" @@ fun c d -> (c, d)

let rec loop ans reds = function
  | [] -> ans
  | (c, d) :: bs ->
      let ts = List.filter (fun (b, a)-> a < c && b < d) reds in
      if List.length ts > 0 then
        let red = ts |> List.sort compare |> List.rev |> List.hd in
        loop (ans + 1) (List.filter ((<>) red) reds) bs
      else 
        loop ans reds bs

let () = Printf.printf "%d\n" @@ loop 0 ab (cd |> List.sort compare)

Measured memory_bytes: 4472
import Control.Applicative
import Control.Monad

main :: IO ()
main = do
  [n] <- getInts
  ns <- replicateM n getInts
  mapM_ (putStrLn.solve) ns

getInts :: IO [Int]
getInts = map read . words <$> getLine

solve :: [Int] -> String
solve (x:y:z:_) = if c1 || c2 || c3
                then "YES"
                else "NO"
  where
    c1 = x*x +  y*y == z*z
    c2 = y*y + z*z == x*x
    c3 = z*z + x*x == y*y
solve _ = ""

Measured memory_bytes: 4608
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

using namespace std;

struct edge { int to, cost; };

class S{
public:
  int p, d, z;
  S(){}
  S(int p, int d, int z): p(p), d(d), z(z){}
  bool operator < (const S s) const{ return s.d < d; }
};

const int N = 100;
const int INF = (1<<28);

int n, m, c;
vector<edge> G[N];

int dijkstra(int s, int t){
  int dist[N][N];
  fill(dist[0], dist[n], INF);
  priority_queue<S> que;
  dist[0][0] = 0;
  que.push(S(0, 0, 0));
  while(!que.empty()){
    S u = que.top(); que.pop();
    //printf("%d %d %d\n", u.p, u.d, u.z);
    if(dist[u.p][u.z] < u.d) continue;
    for(int i=0;i<G[u.p].size();i++){
      S v = S(G[u.p][i].to, u.d, u.z + 1);
      if(v.z < n && dist[v.p][v.z] > v.d){
        dist[v.p][v.z] = v.d;
        que.push(v);
      }
      v.d += G[u.p][i].cost;
      v.z--;
      if(dist[v.p][v.z] > v.d){
        dist[v.p][v.z] = v.d;
        que.push(v);
      }
    }
  }
  for(int i=0;i<n;i++) if(dist[n-1][i] <= c) return i;
}

main(){
  while(cin >> n >> m >> c && (n|m|c)){
    for(int i=0;i<N;i++) G[i].clear();
    for(int i=0;i<m;i++){
      int a, b, cost;
      cin >> a >> b >> cost;
      G[a-1].push_back((edge){b-1, cost});
    }
    cout << dijkstra(0, n-1) << endl;
  }
}

Measured memory_bytes: 1532
// Tax Rate Changed
#include <iostream>
using namespace std;
int X, Y, S;
int tax(int rate, int price_without_tax){
  return price_without_tax*(100+rate)/100;
}
int solve(){
  int maximum = 0;
  for (int i=1; i<S; ++i)
    for (int j=i; j<S; ++j)
      if (tax(X,i)+tax(X,j) == S)
        maximum = max(maximum, tax(Y,i)+tax(Y,j));
  return maximum;
}
int main(){
  while (cin >> X >> Y >> S && X > 0){
    cout << solve() << endl;
  }
}

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

#define int long long 
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vpii vector<pi> 
#define vvpii vector<vpii>
#define all(V) V.begin(),V.end()
#define mpii map<int,int> 
#define mpci map<char,int> 
#define fi first
#define si second
#define pb(V) push_back(V)
#define mp(a,b) make_pair(a,b)
#define mt(a,b,c) make_tuple(a,b,c)
#define forn(i,n) for (int i = 0; i < int(n); ++i)


const int N = 1e5+10;
const int mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	
	int ans = 0;
	for(int  i = 1; i < n-1; ++i)
	{
		if((a[i]>a[i+1] && a[i] < a[i-1]) || (a[i]<a[i+1] && a[i]>a[i-1]))
		{
			ans++;
		}
	}
	cout << ans;
}



Measured memory_bytes: 256
#include<stdio.h>

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

int main(){
  int i,j,h,w;
  char A[1010][1010];
  int c[1010][1010];
  scanf("%d %d",&h,&w);
  for(i=0;i<h;i++)
    scanf("%s",A[i]);


  int cnt1=0,cnt2=0,ans=0;
  black B[1000010];
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(A[i][j]=='#'){
        B[cnt1].x=j;
        B[cnt1++].y=i;
        c[i][j]=0;
      }else
        c[i][j]=-1;
    }
  }
  int dx[4] = {1,0,-1,0};
  int dy[4] = {0,1,0,-1};
  int bx,by,tx,ty;
  while(cnt1 < h*w){
    bx = B[cnt2].x;
    by = B[cnt2++].y;
    for(i=0;i<4;i++){
      tx = bx + dx[i];
      ty = by + dy[i];
      if(tx>=0 && tx<w && ty>=0 && ty<h){
        if(c[ty][tx]==-1){
          c[ty][tx] = c[by][bx] + 1;
          ans = c[ty][tx];
          B[cnt1].x = tx;
          B[cnt1++].y = ty;
        }
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 12928
n, l = [int(i) for i in input().split()]

if l >= 0:
    res = (n - 1) * (l + n / 2)
elif l + n - 1 <= 0:
    res = (n - 1) * (l + (n - 2) / 2)
else:
    res = n * l + n * (n - 1) / 2

print(int(res))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<double> vd;
typedef set<int> si;
typedef set<string> ss;
typedef map<int,int> mii;
typedef map<string,int>msi;
typedef map<string,string>mss;
void solve(){
    string inp,res="";
    int n;
    cin>>n;
    cin>>inp;
    for(int i=0;i<inp.size();i++){
        char ch = inp[i];
        ch+=n;
        if(ch>'Z'){
            ch-=26;
        }
        res+=ch;
    }
    cout<<res<<endl;
}
int main(){
    int t;
    t=1;
    while(t--){
       solve();
    }
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int a[105];
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    int ans=1e9;
    for(int i=-100;i<=100;i++)
    {
        int num=0;
        for(int j=1;j<=n;j++)
            num+=(a[j]-i)*(a[j]-i);
        ans=min(ans,num);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner

func init() {
	// 100MB
	bufsize := 100 * 1024 * 1024
	sc = bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, bufio.MaxScanTokenSize), bufsize)
	sc.Split(bufio.ScanWords)
}
func readInt() int              { return readIntArray(1)[0] }
func readInt2() (int, int)      { a := readIntArray(2); return a[0], a[1] }
func readInt3() (int, int, int) { a := readIntArray(3); return a[0], a[1], a[2] }
func readIntArray(n int) []int {
	s := readStringArray(n)
	a := make([]int, n)
	for i := range a {
		a[i], _ = strconv.Atoi(s[i])
	}
	return a
}
func readString() string            { return readStringArray(1)[0] }
func readString2() (string, string) { a := readStringArray(2); return a[0], a[1] }
func readStringArray(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		a[i] = sc.Text()
	}
	return a
}
func max(ns ...int) int {
	max := ns[0]
	for _, n := range ns {
		if n > max {
			max = n
		}
	}
	return max
}
func min(ns ...int) int {
	min := ns[0]
	for _, n := range ns {
		if n < min {
			min = n
		}
	}
	return min
}
func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	N, M := readInt2()
	A := readIntArray(N)
	var total int
	for _, v := range A {
		total += v
	}
	threshold := float64(total) / float64(4*M)
	//fmt.Printf("total: %d, threshold: %.5f\n", total, threshold)
	sort.Ints(A)
	//fmt.Printf("sorted: %#v, target: %d\n", A, A[len(A)-M])
	if float64(A[len(A)-M]) < threshold {
		fmt.Println("No")
		return
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 640
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    token.parse().ok().unwrap()
}

fn main() {
    let hh = input::<i32>();
    let ww = input::<i32>();
    let h = input::<i32>();
    let w = input::<i32>();

    let ans = (hh - h) * (ww - w);
    println!("{}", ans);
}


Measured memory_bytes: 4352
/*
 * 2438.cc: YAML
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef vector<int> vi;
typedef vector<string> vs;

enum { T_OBJ, T_STR };

struct Obj {
  int t;
  string v;
  map<string,struct Obj> props;
  Obj() {}
  Obj(string &s): t(T_STR), v(s) {}

  void print(int ind = 0) {
    if (t == T_STR) {
      cout << v << endl;
      return;
    }
    for (map<string,struct Obj>::iterator mit = props.begin();
	 mit != props.end(); mit++) {
      for (int i = 0; i < ind; i++) putchar(' ');
      cout << mit->first << ':';
      if (mit->second.t == T_STR) cout << ' ' << mit->second.v << endl;
      else {
	cout << endl;
	mit->second.print(ind + 1);
      }
    }
  }
};

typedef map<string,struct Obj> mso;

/* global variables */

vs lines, keys;
vi idts;

/* subroutines */

void parse(Obj &o, int &k, int idt) {
  o.t = T_OBJ;

  while (k < lines.size() && idts[k] == idt) {
    string &s = lines[k];
    int pos = idt;
    string key;
    while (s[pos] != ':') key += s[pos++];
    pos++; // ':'

    if (pos >= s.size()) {
      k++;
      Obj co;
      parse(co, k, idts[k]);
      o.props[key] = co;
    }
    else {
      pos++; // ' '
      string val;
      while (pos < s.size()) val += s[pos++];
      o.props[key] = Obj(val);
      k++;
    }
  }
}

/* main */

int main() {
  string keystr;
  getline(cin, keystr);

  for (int pos = 0; pos < keystr.size();) {
    string key;
    pos++; // '.'
    while (pos < keystr.size() && keystr[pos] != '.')
      key += keystr[pos++];
    keys.push_back(key);
  }
  
  for (;;) {
    string line;
    getline(cin, line);
    if (cin.eof()) break;

    lines.push_back(line);

    int idt = 0;
    while (line[idt] == ' ') idt++;
    idts.push_back(idt);
    //printf("idt=%d\n", idt);
  }

  Obj yaml;
  int k = 0;
  parse(yaml, k, 0);
  //yaml.print();

  Obj *opt = &yaml;
  for (int k = 0; k < keys.size(); k++) {
    mso::iterator mit = opt->props.find(keys[k]);
    if (mit == opt->props.end()) {
      opt = NULL;
      break;
    }

    Obj *copt = &(mit->second);
    if (k < keys.size() - 1 && copt->t == T_STR) {
      opt = NULL;
      break;
    }

    opt = copt;
  }

  if (opt == NULL) cout << "no such property" << endl;
  else if (opt->t == T_OBJ) cout << "object" << endl;
  else cout << "string \"" << opt->v << "\"" << endl;
  return 0;
}

Measured memory_bytes: 1516
#include<bits/stdc++.h>
using namespace std;
const int N = 110;
#define x first
#define y second
typedef pair<int,int> pii;
pii g[N];
int main()
{
    
    int n;
    cin>>n;
    int cnt=0;
    bool st=false;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        if(a==b) cnt++;
        else cnt=0;
        if(cnt>=3)
        {
            st=true;
            break;
        }
    }
    
    if(st) puts("Yes");
    else puts("No");
     
 
    
}

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

int main(){
    int n,m=0;
    cin >>n;
    map<string, int> mp;
    vector<string> ans;
    string s;
    for(int i=0;i<n;i++){
        cin >>s;
        mp[s]++;
        if(mp[s]>m){
            m=mp[s];
            vector<string> temp;
            temp.push_back(s);
            swap(ans,temp);
        }else if(mp[s]==m){
            ans.push_back(s);
        }
    }
    sort(ans.begin(),ans.end());
    for(string x:ans) cout <<x<<endl;
    return 0;
}

Measured memory_bytes: 26736
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(){    
  ll X;
  cin >> X;
  ll a = 100;
  int i = 0;
  while(i < 1000000000000000000){
   	a += a/100;
   	if(a >= X) break;
    i++;
   }
  
  cout << i + 1 << endl;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N, K;
    cin >> N >> K;
    vector<ll> H;
    rep(i, N){ll h; cin >> h; H.push_back(h);}
    sort(H.begin(), H.end());
    rep(i, K){if (H.size() > 0){H.pop_back();}}
    ll sum = 0;
    if (H.size() == 0){
        cout << 0 << endl;
    } else {
        for (auto h : H){
            sum += h;
        }
        cout << sum << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

int main() {
    int m;
    cin >> m;
    vector<P> v(m);
    for (P &p:v)cin >> p.first >> p.second;

    ll n = 0, s = 0;
    for (P p : v) n += p.second;
    for (P p : v) s += (p.first * p.second);


    ll start = 9 * n + s;
    ll fin = s % 9;
    if (fin == 0) fin += 9;

    ll ans = (start - fin) / 9 - 1;
    cout << ans << endl;

}


Measured memory_bytes: 6416
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int main(){
  fio();
  int a,b,c; cin>>a>>b>>c;
  cout<<c<<" "<<a<<" "<<b<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;

int main(void) {
  ll n,a,b,c,d,e;
  cin >> n >> a >> b >> c >> d >> e;
  ll p = min({a,b,c,d,e});
  cout << (n+p-1)/p+4 << endl;
}






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

int main() {
  int k,n,x,y;
  x=0;
  cin>>k>>n;
  vector<int>pos(n);
  for(int i=0;i<n;i++){
      cin>>pos.at(i);
  }
  for(int i=1;i<n;i++){
      if(x<pos.at(i)-pos.at(i-1)){
          x=pos.at(i)-pos.at(i-1);
      }
  }
  y=k-pos.at(n-1)+pos.at(0);
  x=max(y,x);
  cout<<k-x<<endl;
}



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

#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<30)
#define INFLL (1LL<<62LL)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

bool consume(map<int, int> &cnt, int pn, int pl) {
  bool selected;
  while (pn) {
    selected = false;
    rep(i, 26) {
      if (cnt[i] < pl) continue;
      pn--;
      cnt[i] -= pl;
      selected = true;
    }
    if (!selected)
      break;
  }
  return pn == 0;
}

void dump(map<int, int> cnt) {
  rep(i, 26) {
    if (cnt[i] == 0) continue;
    cout << (char)(i + 'a') << ": " << cnt[i] << ", ";
  }
  cout << endl;
}

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int H, W;
  vector<string> a;

  cin >> H >> W;
  a.resize(H);

  rep(i, H) cin >> a[i];

  map<int, int> cnt;
  rep(i, H) rep(j, W) {
    cnt[a[i][j] - 'a']++;
  }

  if (!consume(cnt, (H / 2) * (W / 2), 4)) {
    cout << "No" << endl;
    return 0;
  }

  if (!consume(cnt, W / 2 * (H % 2) + H / 2 * (W % 2), 2)) {
    cout << "No" << endl;
    return 0;
  }

  if (!consume(cnt, H % 2 && W % 2, 1)) {
    cout << "No" << endl;
    return 0;
  }

  cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll INFL = 1e18;
const ll mod = 1e9 + 7;
 
int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}
 
ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

bool is_prime(long long N){
    if (N == 1) return false;
    for (long long i = 2;i * i <= N;i++){
        if (N % i == 0) return false;
    }
    return true;
}
 
ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}
 
double DegreeToRadian(double degree){
    return degree * M_PI / 180.0;
}
 
 
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};
 
 
///////////////////////////////////////////////////////////////////////////////////

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

    long long ans = INFL;

    for (int i = 1;i < n;i++){
        long long x = sum[i];
        long long y = sum[n] - sum[i];
        ans = min(ans, abs(y - x));
    }

    cout << ans << endl;
}

Measured memory_bytes: 4760
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a + 2), t(b + 2), x(q), invs(a + 2), invt(b + 2);
    s[0] = t[0] = invs[0] = invt[0] = -infl;
    s[a + 1] = t[b + 1] = invs[a + 1] = invt[b + 1] = infl;
    for (int i = 1; i <= a; ++i) {
        cin >> s[i];
        invs[a - i + 1] = -s[i];
    }
    for (int i = 1; i <= b; ++i) {
        cin >> t[i];
        invt[b - i + 1] = -t[i];
    }
    for (int i = 0; i < q; ++i) {
        cin >> x[i];
    }

    for (ll query : x) {
        ll ans = inf;
        auto slb = lower_bound(s.begin(), s.end(), query);
        auto tlb = lower_bound(t.begin(), t.end(), query);
        auto sub = s.end() - 1 - (int)(lower_bound(invs.begin(), invs.end(), -query) - invs.begin());
        auto tub = t.end() - 1 - (int)(lower_bound(invt.begin(), invt.end(), -query) - invt.begin());

        ans = min({abs(*slb - query) + min(abs(*tlb - *slb), abs(*tub - *slb)),
                   abs(*sub - query) + min(abs(*tlb - *sub), abs(*tub - *sub)),
                   abs(*tlb - query) + min(abs(*slb - *tlb), abs(*sub - *tlb)),
                   abs(*tub - query) + min(abs(*slb - *tub), abs(*sub - *tub))});

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

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

const int MAX_V = 1e5;
const int MAX_LOG_V = 20;

int N, Q;

struct edge {
  int dest, color, distance;
};

vector<edge> G[MAX_V];
const int root = 0;

int parent[MAX_LOG_V][MAX_V];
int depth[MAX_V];
set<int> relevantColor[MAX_V];

void dfs(int v, int p, int d) {
  parent[0][v] = p;
  depth[v] = d;
  for(auto &e: G[v]) {
    if (e.dest != p) dfs(e.dest, v, d+1);
  }
}

void initLCA(int V) {
  dfs(root, -1, 0);
  for(int k = 0; k + 1 < MAX_LOG_V; k++) {
    for(int v = 0; v < V; v++) {
      if(parent[k][v] < 0) {
        parent[k+1][v] = -1;
      } else {
        parent[k+1][v] = parent[k][parent[k][v]];
      }
    }
  }
}

int lca(int u, int v) {
  if(depth[u] > depth[v]) swap(u, v);
  for(int k = 0; k < MAX_LOG_V; k++) {
    if((depth[v] - depth[u]) >> k & 1) {
      v = parent[k][v];
    }
  }
  if(u == v) return u;
  for(int k = MAX_LOG_V - 1; k >= 0; k--) {
    if(parent[k][u] != parent[k][v]) {
      u = parent[k][u];
      v = parent[k][v];
    }
  }
  return parent[0][u];
}

struct query {
  int x, y, u, v, lca;
};

map<int, map<int, int>> colorDistance;
map<int, map<int, int>> colorNum;
int monochroDistance[MAX_V];
int tmpColorDist[MAX_V-1];
int tmpColorNum[MAX_V-1];

void collectDistances(int u, int p) {
  for(int c: relevantColor[u]) {
    colorDistance[c][u] = tmpColorDist[c];
    colorNum[c][u] = tmpColorNum[c];
  }

  for(auto &e: G[u]) {
    if(e.dest != p) {
      tmpColorDist[e.color] += e.distance;
      tmpColorNum[e.color]++;
      monochroDistance[e.dest] = monochroDistance[u] + e.distance;
      collectDistances(e.dest, u);
      tmpColorDist[e.color] -= e.distance;
      tmpColorNum[e.color]--;
    }
  }
}

int distanceBetweenNodes(auto &d, query &q) {
  return d[q.u] + d[q.v] - 2 * d[q.lca];
};

int main () {
  cin >> N >> Q;

  rep(i,N-1) {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    a--;b--;c--;
    G[a].push_back(edge{b, c, d});
    G[b].push_back(edge{a, c, d});
  }

  initLCA(N);

  vector<query> queries(Q);
  rep(i,Q) {
    int x, y, u, v;
    cin >> x >> y >> u >> v;
    x--;u--;v--;
    int l = lca(u,v);
    queries[i] = query{x, y, u, v, l};
    relevantColor[u].insert(x);
    relevantColor[v].insert(x);
    relevantColor[l].insert(x);
  }

  collectDistances(root, -1);

  for(auto &q: queries) {
    int d = distanceBetweenNodes(monochroDistance, q);
    int cd = distanceBetweenNodes(colorDistance[q.x], q);
    int n = distanceBetweenNodes(colorNum[q.x], q);
    cout << d - cd + n*q.y << endl;
  }

  return 0;
}


Measured memory_bytes: 67384
def abc063_d():
    n, a, b = map(int, input().split())
    H = [int(input()) for _ in range(n)]
    lower, upper = 0, 10**16
    d = a - b
    while upper - lower > 1:
        x = (upper + lower) // 2
        v = 0
        for hi in H:
            v += (max(0, hi - x*b) + d - 1) // d
        if v <= x: upper = x
        else: lower = x
    print(upper)

if __name__ == '__main__':
    abc063_d()

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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, m, k, u, v;
string s, t;

// <------------- Implement Functions Here ----------> //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>s;
	ll c0 = count(all(s),'0');
	ll c1 = count(all(s),'1');
	cout<<2*min(c0,c1);
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 3720
num=int(input())

def cal(num):
    return num*num*num*num*num

A=0
while(1):
    B=0
    while(cal(A)-cal(B)>num):
        B+=1
    if cal(A)-cal(B)==num:
        print(str(A)+" "+str(B))
        break
    B=0
    while(cal(A)-cal(B)<num):
        B-=1
    if cal(A)-cal(B)==num:
        print(str(A)+" "+str(B))
        break
    A+=1

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

int d[MAX];

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1;i <= n;++i)
		scanf("%d", &d[i]);
	sort(d + 1, d + n + 1);
	if (n % 2)
		printf("0\n");
	else
		printf("%d\n", d[n / 2 + 1] - d[n / 2]);
	//system("pause");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
int main()
{
    int N;
    string S1, S2;
    cin >> N >> S1 >> S2;

    int kind = 0;
    ll ans = 1;
    rep(i, N) {
        if (S1[i] == S2[i]) {
            if (kind == 0) {
                ans *= 3;
            }
            else if (kind == 1) {
                ans *= 2;
            }
            else if (kind == 2) {
                ans *= 1;
            }
            kind = 1;
        }
        else {
            i++;
            if (kind == 0) {
                ans *= 6;
            }
            else if (kind == 1) {
                ans *= 2;
            }
            else if (kind == 2) {
                ans *= 3;
            }
            kind = 2;
        }
        ans %= MOD;
    }

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

Measured memory_bytes: 256
from itertools import accumulate

n,k = map(int, input().split())
a = list(map(int, input().split()))
keta = len(bin(sum(a)))-3
sumlist = []
cumsum = [0]+list(accumulate(a))
for key,v1 in enumerate(cumsum):
  for v2 in cumsum[key+1:]:
    sumlist.append(v2-v1)
ans = 0
for i in range(keta,-1,-1):
  tmp = []
  for j in sumlist:
    if (j >> i) & 1:
      tmp.append(j)
  if len(tmp) >= k:
    ans += 2 ** i
    sumlist = tmp
print(ans)
  

Measured memory_bytes: 65916
#include <bits/stdc++.h>
using namespace std;
 typedef long long ll;
 
int main() {
int n;
cin>>n;
int c[200];
for(int i=0;i<n;i++)cin>>c[i];
bool d[11];
for(int i=0;i<9;i++)d[i]=0;
int red = 0;

for(int i=0;i<n;i++){
if(c[i]>=3200)red++;
else if(c[i]>=2800)d[0]=1;
else if(c[i]>=2400)d[1]=1;
else if(c[i]>=2000)d[2]=1;
else if(c[i]>=1600)d[3]=1;
else if(c[i]>=1200)d[4]=1;
else if(c[i]>=800)d[5]=1;
else if(c[i]>=400)d[6]=1;
else d[7]=1;
}
int ans=0;

for(int i=0;i<9;i++){
    if(d[i]==1) ans++;
}
cout<<max(ans,1)<<" "<<ans+red<<endl;


}


Measured memory_bytes: 256