akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2 + 2], R[MAX/2 + 2];
int cnt;

void merge(int A[], int n, int left, int mid, int right){
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; ++i) L[i] = A[left + i];
    for (int i = 0; i < n2; i++) R[i] = A[mid + i];
    L[n1] = R[n2] = SENTINEL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++)
    {
        cnt++;
        if (L[i] <= R[j])
        {
            A[k] = L[i]; i++;
        }
        else{
            A[k] = R[j]; j++;
        }
    }
}

void mergeSort(int A[], int n, int left, int right){
    if(left+1 < right){
        int mid = (left + right)/2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int main(){
    int A[MAX], n, i;
    cnt = 0;

    cin >> n;
    for(i = 0; i<n; i++) cin >> A[i];

    mergeSort(A, n, 0, n);

    for (int i = 0; i < n; ++i)
    {
        if(i) cout << " ";
        cout << A[i];

    }
    cout << endl;
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 6964
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define M1 1000000007
#define M2 998244353

#define fl(i,a,b)  for(ll i=a;i<b;i++)
#define bfl(i,a,b) for(ll i=b-1;i>=a;i--)
#define f(i,n)     for(int i=0;i<n;i++)
#define bf(i,n)    for(int i=n-1;i>=0;i--)


#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define bn "\n"

//------------------------------------------------------------------------ 
// #define V(a) vector<a>
// #define vt() vector< tuple < int ,int ,int > > ;
// #define vector< int ,int > pv;
// vector< pair <int,int> > vect;


//------------------------------------------------------------------------

ll modI(ll a,ll m);
ll gcd(ll a,ll b);
ll powM(ll x,ll y,ll m);
ll swap(ll a,ll b);

void swap(ll& a,ll& b)
{
    ll tp=a;
    a=b;
    b=tp;
}

ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}

ll powM(ll x,ll y,ll m)
{
    ll ans=1,r=1;
    x%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            ans*=x;
            ans%=m;
        }
        r<<=1;
        x*=x;
        x%=m;
    }
    return ans;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}

//---------------------------------------------------------------------------

// variable = Expression1 ? Expression2 : Expression3
// max = (n1 > n2) ? n1 : n2; 
// (n>m) ? cout<<"True"<<endl:cout<<"false"<<endl ;

// ---------------------------------------------------------------------------	

// int n;cin>>n;int a[n];for(int i=0;i<n;i++)cin>>a[i];    
// for(int i=0;i<n;i++)cout<<a[i];
// int a,b;cin>>a>>b;   

//----------------------------------------------------------------------------

// vector< tuple < int ,int ,int > > tv;
// vector< int ,int > pv;


//----------------------------------------------------------------------------


int main() {
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
	int tt=1;
   // cin>>tt;
	while(tt--)
	{	    double a,b,h,m;
	    cin>>a>>b>>h>>m;

    double pi=acos(-1.0);
	   double tp=(double)m*(6.0); double hr=(double)h*(30.0) +(double)(m/2);
	   double value=min(abs(tp-hr),(360.0-abs(tp-hr)));
	   double ans=(double)sqrt((double)a*a +(double)b*b -2.0*(double)a*(double)b*cos(pi/180.0 * value));
	  // cout.precision(25);

	  // cout<<ans<<bn;
	  	cout<<fixed<<setprecision(15)<<ans<<bn;

	
	    
	}
	
	return 0;
}


Measured memory_bytes: 4228
MAX_G = 40 * 10
N, Ma, Mb, *rest = $stdin.read.split.map(&:to_i)
CHEMICALS = rest.each_slice(3).to_a

dp = Array.new(N+1){ Array.new(MAX_G+1){ Array.new(MAX_G+1, Float::INFINITY) }}
dp[0][0][0] = 0

for i in 0...N
  for ca in 0..MAX_G
    for cb in 0..MAX_G
      next if dp[i][ca][cb] == Float::INFINITY
      # iを使わない場合
      dp[i+1][ca][cb] = [ dp[i+1][ca][cb],
                          dp[i][ca][cb] ].min
      # iを使う場合
      ga, gb, gc = CHEMICALS[i]
      dp[i+1][ca + ga][cb + gb] = [ dp[i+1][ca + ga][cb + gb],
                                    dp[i][ca][cb] + gc ].min
    end
  end
end

ans = Float::INFINITY
for ca in 1..MAX_G
  for cb in 1..MAX_G
    if ca*Mb == cb*Ma
      ans = [ans, dp[N][ca][cb]].min
    end
  end
end

p(ans == Float::INFINITY ? -1 : ans)


Measured memory_bytes: 56700
#include <iostream>
#include <vector>
#include <algorithm>
 
long calcNumOfCombination(long n, long r){
        long num = 1;
        for(long i = 1; i <= r; i++){
            num = num * (n - i + 1) / i;
        }
        return num;
    }
 
void solve(int N, std::vector<std::string> s) 
{
  for(auto& i: s)
  {
    std::sort(i.begin(), i.end());
  }
  std::sort(s.begin(), s.end());
  long count = 0;
  long result = 0;
  for (int i = 1; i < N; i++)
  {
    if(s[i-1]==s[i])
    {
      count++;
      result += count;
    }
    else
    {
      count=0;
    }
  }
  std::cout << result << std::endl;
}
int main(void) {
  int N;
  std::cin >> N;
  std::vector<std::string> s(N);
  for(auto i0 = 0; i0 < N; ++i0)
  {
    std::cin >> s[i0];
  }
  solve(N,s);
  return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <set>
#include <map>
#include <list>
#include <cstdlib>

using namespace std;

#define mod (1e9 + 7)
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()

typedef long long ll;

void solve1()
{
    int n, x; cin >> n >> x;
    vector<int> l(n);
    rep(i, n) {
        cin >> l[i];
    }

    int d[2*n];
    d[0] = 0;
    int ans = 1;
    for(int i = 1; i <= n; i++) {
        d[i] = d[i-1] + l[i-1];
        if(d[i] <= x) {
            ans ++;
        }
    }

    cout << ans << endl;

 
}

int main()
{
    solve1();
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    string s, t, u;
    cin >> s >> t >> u;
    cout << "A" << t[0] << "C\n";
}


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

int main(){
    int a, b;
    cin >> a >> b;
    vector<vector<int>>mp(a, vector<int>(b));
    for(int i=0; i < a; i++){
        for(int j=0; j < b; j++){
            cin >> mp[i][j];
        }
    }
    vector<int>t(b);
    for(int i=0; i < b; i++)cin >> t[i];
    for(int i=0; i < a; i++){
        int sum = 0;
        for(int j=0; j < b; j++){
            sum += t[j] * mp[i][j];
        }
        cout << sum << endl;
    }
}


Measured memory_bytes: 3172
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int n,k;
    cin >> n >> k;
    int ans =0;
    for(int i=0;i<n;i++){
        int x;
        cin >> x;
        ans+=min(abs(0-x)*2,abs(k-x)*2);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    
    Scanner scan = new Scanner(System.in);
    int X = scan.nextInt();
    int Y = scan.nextInt();
        
    if ((Y-2*X) >= 0 && (Y-2*X)%2 == 0 && (4*X-Y) >= 0) {
      System.out.println("Yes");
      return;
    }
    System.out.println("No");
  }
}


Measured memory_bytes: 35644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (ll i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (500000)
#define pii pair<int, int>

/////////////////////////////////////////////////////////

class XY{
public:
  ll x, y;
  XY() {x = y = 0;}
  XY(ll u, ll v) {x = u; y = v;}
};

class e{
public:
  ll a, b;
  e() {a = b = -1;}
  e(ll u, ll v) {a = u; b = v;}
};

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

template<typename T>
int BS(vector<T> &V, int left, int right, T key){
  int mid = (left + right) / 2;
  if(V[mid] <= key) left = mid;
  else right = mid;
  if(right - mid == 1) return left;
  else return BS(V, left, right, key);
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

template<typename T>
T euclid(T a, T b){
  if(b == 0) return a;
  else return euclid(b, a % b);
}

vector<ll> fact(MAX, 0), fact_inv(MAX, 0);

ll pow_mod(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b & 1) res = res * a % MOD;
		a = a * a % MOD;
		b >>= 1;
	}
	return res;
}

void prepare_comb_mod(ll n){
	fact[0] = 1LL;
	for(ll i = 0; i < n; i++) fact[i+1] = fact[i] * (i + 1) % MOD;
	fact_inv[n] = pow_mod(fact[n], MOD - 2);
	for(ll i = n - 1; i >= 0; i--) fact_inv[i] = fact_inv[i + 1] * (i + 1) % MOD;
}

ll comb_mod(ll n, ll r){
	return (fact[n] * fact_inv[r]) % MOD * fact_inv[n - r] % MOD;
}

/////////////////////////////////////////////////////////


void Main() {
  int N; cin >> N;
  vector<int> L(N);
  rep(i, 0, N) cin >> L[i];
  sort(all(L));
  ll res = 0;
  rep(i, 2, N){
    rep(j, 0, i - 1){
      rep(k, j + 1, i){
        if(L[i] < L[j] + L[k]) res++;
      }
    }
  }
  cout << res << endl;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();
}


Measured memory_bytes: 8192
#include <iostream>

int main()
{
	int i, r, c, k = 0;
	std::cin >> r >> c;
	int a[10000];
	for (i = 0;i < r*c;i++) {
		std::cin >> a[i];
	}
	int C = c;
	for (int j = 0;j < r;j++) {
		int nSum = 0;
		for (;k < C; k++) {
			std::cout << a[k] << " " ;
			nSum += a[k];
		}
		std::cout << nSum << std::endl;
		C = C + c;
	}
	for (int l = 0;l < c ;l++) {
		int nSum = 0;
		for (int m = 0;l+m < r*c;m=m + c) {
			nSum += a[l + m];
		}
		std::cout << nSum << " ";
	}
	int nSum = 0;
	for (i = 0;i < r*c;i++) {
		nSum += a[i];
	}
	std::cout << nSum << std::endl;
    return 0;
}

Measured memory_bytes: 3132
N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

h = Hash.new(0)

A.each do |a|
  h[a] += 1
end

M.times do
  b, c = gets.split.map(&:to_i)
  h[c] += b
end

remain = N
ans = 0
h.sort_by { |k, _| -k }.each do |key, _|
  count = [remain, h[key]].min
  remain -= count
  ans += key * count
  break if remain <= 0
end

puts ans


Measured memory_bytes: 30848
#include "bits/stdc++.h"

#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++)

using namespace std;
const long long INF = 1LL << 61;

int main() {
	int N; cin >> N;
	vector<int> a(N);
	rep(i, N)cin >> a[i];

	vector<int> box(N, 0);
	rep(i, N) {
		int num = N / (N - i);
		int total = 0;
		rep(j, num - 1)total += box[(j + 2) * (N - i) - 1];
		if (total % 2 == 0) {
			if (a[N - i - 1] == 0)box[N - i - 1] = 0;
			else box[N - i - 1] = 1;
		}
		else {
			if (a[N - i - 1] == 0)box[N - i - 1] = 1;
			else box[N - i - 1] = 0;
		}
	}
	int M = accumulate(box.begin(), box.end(), 0);
	if (M%2==a[0]) {
		cout << M << endl;
		rep(i, N) {
			if (box[i] == 1)cout << i + 1 << " ";
			}
		}
	else cout << -1;
}

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

int main() {
    int N, K, S;
    cin >> N >> K >> S;

    vector<int> res(N);
    for (int i = 0; i < K; i++) res[i] = S;
    if (S == 1000000000) {
        for (int i = K; i < N; i++) res[i] = 1;
    } else {
        for (int i = K; i < N; i++) res[i] = 1000000000;
    }
    

    for (int i = 0; i < N; i++) {
        cout << res[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<map>
#include<queue>
#include<set>
#include<bitset>
#include<stdio.h>
#include<deque>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long ll;

int main()
{
    int a[3][3];
    rep(i, 3){
        rep(j, 3){
            cin >> a[i][j];
        }
    }
    int x[3], y[3];
    x[0] = 0;
    rep(i, 3) y[i] = a[0][i] -x[0];
    rep(i, 3) x[i] = a[i][0] -y[0];
    bool ans = true;
    rep(i, 3){
        rep(j, 3){
            if(a[i][j] != x[i] + y[j]){
                ans = false;
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i = 0; i < n; i++){
    cin >> d.at(i);
  }
  
  n /= 2;
  sort(d.begin(), d.end());
  int a = d.at(n-1);
  int b = d.at(n);
  
  int counta = 0;
  int countb = 0;
  
  for(int i = 0; i < 2 * n; i++){
    if(d.at(i) < a + 1){
      counta++;
    }
    if(d.at(i) >= b){
      countb++;
    }
  }
  
  if(counta == countb){
    cout << b-a << endl;
  }
  else{
    cout << 0 << endl;
  }
}


Measured memory_bytes: 3772
/* This code is written by Nemlit */
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define rep(i, a, b) for(re int i = (a); i <= (b); ++ i)
#define drep(i, a, b) for(re int i = (b); i >= (a); -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define int long long
#define D double
#define inf 1023456789
#define mod 1000000007
#define lb(x) (x)&(-(x))
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
#define maxn 200005
namespace Graph {
	int head[maxn], cnt;
	struct edge { int v, next; }e[maxn << 1];
	il void add(int u, int v) { e[++ cnt] = (edge){v, head[u]}, head[u] = cnt; }
}
//using namespace Graph;
int n, m, sum[maxn * 44], rt, a[maxn], cnt, L = -200000, R = (1e9) + 200000, ls[maxn * 44], rs[maxn * 44];
il void insert(int &k, int l, int r, int ll) {
	if(!k) k = ++ cnt; ++ sum[k];
	if(l == r) return;
	int mid = (l + r) >> 1;
	if(ll <= mid) insert(ls[k], l, mid, ll);
	else insert(rs[k], mid + 1, r, ll);
}
il int query(int k, int l, int r, int ll) {
	if(l == r) return sum[k];
	int mid = (l + r) >> 1;
	if(ll <= mid) return query(ls[k], l, mid, ll);
	else return query(rs[k], mid + 1, r, ll);
}
signed main() {
	n = read();
	rep(i, 1, n) a[i] = read();
	rep(i, 1, n) {
		m += query(1, L, R, i - a[i]);
		insert(rt, L, R, i + a[i]);
	}
	cout << m;
	return 0;
}


Measured memory_bytes: 46036
import java.util.Scanner;

public class Main {
	char[][] map;
	int h, w;
	char c;
	
	void run() {
		Scanner scan = new Scanner(System.in);
		while (true) {
			h = scan.nextInt();
			w = scan.nextInt();
			if (w == 0 && h == 0) break;
			map = new char[h][];
			int section = 0;
			for (int i = 0; i < h; i++)
				map[i] = new char[w];
			for (int y = 0; y < h; y++) {
				String str = scan.next();
				for (int x = 0; x < w; x++) {
					map[y][x] = str.charAt(x);
				}
			}
			for (int y = 0; y < h; y++) {
				for (int x = 0; x < w; x++) {
					if (map[y][x] != 'x') {
						c = map[y][x];
						solve(y, x);
						section++;
					}
				}
			}
			System.out.println(section);
		}
	}
	
	void solve(int y, int x) {
		if (y < 0 || x < 0 || y >= h || x >= w || map[y][x] != c) return;
		map[y][x] = 'x';
		solve(y + 1, x);
		solve(y - 1, x);
		solve(y, x + 1);
		solve(y, x - 1);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 28652
mod=10**9+7

n=int(input())

a=list(map(int,input().split()))

def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

def lcm(a,b):
    return a//gcd(a,b)*b

lcma=1

for i in range(n):
    lcma=lcm(lcma,a[i])

ans=0

for i in range(n):
    ans=(ans+lcma//a[i])

print(ans%mod)



Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  long long x=-1,y=-1;
  int a[100009];
  cin>>n;
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a,a+n);
  reverse(a,a+n);
  for(int i=0;i<n-1;i++){
    if(a[i]==a[i+1]){
      if(x==-1){
	x=a[i];
      }
      else if(y==-1){
	y=a[i];
      }
      i++;
    }
  }
  if(x==-1&&y==-1)cout<<0<<endl;
  else cout<<x*y<<endl;
  return(0);
}


Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <numeric>
#include <vector>
#include <unordered_map>

using namespace std;
using ll = long long;
template<typename T> void print(T t) {cout << t << endl;}


int main() {
	int N, ans=0, AMAX; 
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end());

	AMAX = A.back();
	vector<bool> furui(AMAX + 1, true);
	for (int i = 0; i < N; i++) {
		if (furui[A[i]]) {
			for (int n = 1; A[i] * n <= AMAX; n++) {
				furui[A[i] * n] = false;
			}
			if(i==N-1 || A[i]!=A[i+1])ans++;
		}
	}
	print(ans);
}

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

long N, M, K, ans;
vector<long> A, B;

int main(void) {

    cin >> N >> M >> K;
    A.resize(N+1); B.resize(M+1);
    for (long i = 0; i < N; i++) cin >> A[i+1];
    for (long i = 0; i < M; i++) cin >> B[i+1];

    for (long i = 1; i <= N; i++) A[i] += A[i-1];
    for (long i = 1; i <= M; i++) B[i] += B[i-1];

    long j = M;
    for (long i = 0; i <= N && A[i] <= K; i++) {
        while (A[i] + B[j] > K) j--;
        ans = max(ans, i+j);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6376
import itertools
lst=[]
for i in range(5):
  lst.append(int(input()))
k=int(input())
l=list(itertools.combinations(lst,2))
flg=True
for i in l:
  if (i[1]-i[0]) > k:
    flg = False
print("Yay!" if flg else ":(")   

Measured memory_bytes: 3060
from bisect import bisect_left
a, b, q = map(int, input().split())
s = []
for _ in range(a):
    s.append(int(input()))
t = []
for _ in range(b):
    t.append(int(input()))
INF = 10**12
for _ in range(q):
    x = int(input())
    s_l = t_l = -INF
    s_r = t_r = INF
    tmp = bisect_left(s, x)
    if tmp>0:
        s_l = s[tmp-1]
    if tmp<a:
        s_r = s[tmp]
    tmp = bisect_left(t, x)
    if tmp>0:
        t_l = t[tmp-1]
    if tmp<b:
        t_r = t[tmp]
    ans = min(
        x-min(s_l, t_l),
        max(s_r, t_r)-x,
        s_r-t_l+min(s_r-x, x-t_l),
        t_r-s_l+min(t_r-x, x-s_l)
    )
    print(ans)

Measured memory_bytes: 99100
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define itn int
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const ll lnf=1ll<<60;

ll rui(ll a,ll n){
  ll ans=1;
  while(n>0){
    if(n&1) ans=ans*a%mod;
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

ll rui2(ll x){
  ll ans=0;
  while(x%2==0){
    x/=2;
    ans++;
  }
  return ans;
}

ll rui5(ll x){
  ll ans=0;
  while(x%5==0){
    x/=5;
    ans++;
  }
  return ans;
}

int main(){
  itn n; cin >> n;
  vector<string> a(n);
  rep(i,n) cin >> a[i];
  ll ints=0;
  set<pii> st25;
  map<pll,ll> mp;
  rep(i,n){
    ll cnt10=0;
    int p=0;
    rep(j,a[i].size()){
      if(a[i][j]=='.'){
        p=j;
        cnt10=a[i].size()-j-1;
      }
    }
    ll x=0;
    if(p){
      reverse(all(a[i]));
      int j=0;
      while(a[i][j]=='0'){
        j++;
      }
      cnt10-=j;
      reverse(all(a[i]));
      rep(j,p+cnt10+1){
        if(j==p) continue;
        x*=10;
        x+=a[i][j]-'0';
      }
    }
    else{
      rep(j,a[i].size()){
        x*=10;
        x+=a[i][j]-'0';
      }
    }
    ll cnt5=rui5(x);
    ll cnt2=rui2(x);
    if(cnt10==0) ints++;
    st25.insert(pii(cnt2-cnt10,cnt5-cnt10));
    mp[pll(cnt2-cnt10,cnt5-cnt10)]++;
  }
  ll ans=0;
  for(auto a:st25){
    for(auto b:st25){
      if(a.first+b.first>=0&&a.second+b.second>=0) ans+=mp[a]*mp[b];
    }
  }
  ans=(ans-ints)/2;
  cout << ans << endl;
}

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

using namespace std;

typedef tuple<int,int,int> trinca;
typedef long long ll;

const int MAXW = 2*1e4 + 10;

vector<trinca> guloso;
ll dp[MAXW];
int N;

int main(){

	cin >> N;
	for(int i = 1; i <= N; i++){
		int w,s,v;
		cin >> w >> s >> v;
		guloso.push_back(make_tuple(s+w,w,v));
	}

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

	for(trinca davez : guloso){
		int solid = get<0>(davez), w = get<1>(davez);
		ll v = get<2>(davez);
		for(int i = MAXW-1; i >= 0; i--){
			if(i + w <= solid){
				dp[i+w] = max(dp[i+w], dp[i] + v);
			}
		}
	}

	ll best = 0;
	for(int i = 0; i < MAXW; i++) best = max(best, dp[i]);
	cout << best << endl;

	return 0;

}

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

using namespace std;
int main() {
    int n;
    int c[500];
    int s[500];
    int f[500];

    cin >> n;
    for (int i = 0; i < n-1; i++) {
        cin >> c[i] >> s[i] >> f[i];
    }

    for (int i = 0; i < n; i++) {
        int time = 0;
        for (int j = i; j < n-1; j++) {
            if (time < s[j]) {
                time = s[j];
            }
            if (time % f[j]) {
                time += f[j] - (time % f[j]);
            }
            time += c[j];
        }
        cout << time << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int n;
    cin >> n;
    vec<int> x(n);
    for (auto &&e : x)
    {
        cin >> e;
    }
    int sum = accumulate(x.begin(),x.end(),0);
    int square_sum = accumulate(x.begin(),x.end(),0,[](auto &a,auto &b)
    {
        return a+b*b;
    });
    int ans = 100'100'100;
    for (int p = 0; p < 101; p++)
    {
        ans = min(ans,p*p*n  -2*p*sum + square_sum);
    }
    //cout << sum << " " <<  square_sum << endl;
    cout << ans << endl;
}

Measured memory_bytes: 256
// Different Strokes

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>
#include <map>

using namespace std;

int n;

int main() {
    cin >> n;
    vector<long long> a(n);
    vector<long long> b(n);

    vector<long long> sum(n);

    long long a_i, b_i;

    for (int i = 0; i < n; i++) {
        cin >> a_i >> b_i;
        a[i] = a_i;
        b[i] = b_i;
        sum[i] = a_i + b_i;
    }

    sort(sum.begin(), sum.end());
    reverse(sum.begin(), sum.end());

    long long res = 0;

    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            res += sum[i];
        }
        res -= b[i];
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int mod = 1e9+7;
const int MAX = 510000;
const int V = 100005;
ll dy[8] = {1,0,-1,0,1,-1,1,-1};
ll dx[8] = {0,1,0,-1,1,-1,-1,1};
const double pi = acos(-1);
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << endl;}
#define INT_MAX 1e9+7

ll modpow(ll x, ll n){
    ll res = 1;
    while(n > 0){
        if(n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

vector<ll> fac(MAX), finv(MAX), inv(MAX);

void comInit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(ll i=2; i<MAX; i++){
        fac[i] = fac[i-1]*i % mod;
        inv[i] = mod - inv[mod%i] * (mod/i) % mod;
        finv[i] = finv[i-1] * inv[i] % mod;
    }
}


ll com(ll n, ll k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main(){
    ll n,a,b,c; cin >> n >> a >> b >> c;
    ll ans = 0;
    comInit();
    REP(i,n,2*n){
        ll tmp = com(i-1,n-1)*i%mod;
        tmp *= (modpow(a,n)*modpow(b,i-n)%mod+modpow(a,i-n)*modpow(b,n)%mod);
        tmp %= mod;
        tmp *= (100*inv[100-c]%mod*modpow(inv[a+b],i))%mod;
        tmp %= mod;
        ans += tmp;
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 12160
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  string s;
  int ac=0,wa=0,tle=0,re=0;
  while(n--)
  {
      cin>>s;
      if(s=="AC")
        ac++;
      else if(s=="WA")
        wa++;
      else if(s=="TLE")
        tle++;
      else
        re++;
  }
  cout<<"AC x "<<ac<<endl<<"WA x "<<wa<<endl<<"TLE x "<<tle<<endl<<"RE x "<<re;
}


Measured memory_bytes: 3640
/*
 * @Date         : 2020-08-10 15:01:59
 * @Author       : ssyze
 * @Description  :
 */
#include <bits/stdc++.h>
using namespace std;
char g[10][10];
int h, w, k;
int r[10], c[10];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> h >> w >> k;
    int tot = 0, ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> g[i][j];
            if (g[i][j] == '#') tot++;
        }
    }
    for (int i = 0; i < h; i++) {
        int sum = 0;
        for (int j = 0; j < w; j++) {
            if (g[i][j] == '#') sum++;
        }
        r[i] = sum;
    }
    for (int i = 0; i < w; i++) {
        int sum = 0;
        for (int j = 0; j < h; j++) {
            if (g[j][i] == '#') sum++;
        }
        c[i] = sum;
    }
    for (int i = 0; i < 1 << h; i++) {
        for (int j = 0; j < 1 << w; j++) {
            vector<int> row, col;
            int tmp1 = j, tmp2 = i, tt1 = 0, tt2 = 0;
            while (tmp1) {
                if (tmp1 & 1) col.push_back(tt1);
                tt1++;
                tmp1 >>= 1;
            }
            while (tmp2) {
                if (tmp2 & 1) row.push_back(tt2);
                tt2++;
                tmp2 >>= 1;
            }
            int res = tot;
            for (auto& x : col) res -= c[x];
            for (auto& x : row) res -= r[x];
            for (auto& x : row) {
                for (auto& y : col) {
                    if (g[x][y] == '#') res++;
                }
            }
            if (res == k) ans++;
        }
    }
    cout << ans << endl;
}

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

using ll = long long;

const int mod = 1000000007;
// const int INF = 1000000000;
const ll INF = (ll)1e18 + 2;
const double EPS = 1e-9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(), A.end());
    ll l = -INF, r = INF;
    while (l + 1 < r) {
        ll x = (l + r) / 2;
        bool ok = [&]() {
            ll total = 0;
            for (int i = 0; i < N; ++i) {
                int l = -1, r = N;
                if (A[i] > 0) {
                    while (l + 1 < r) {
                        int c = (l + r) / 2;
                        if (A[i] * A[c] < x) l = c;
                        else r = c;
                    }
                    total += l + 1;
                } else {
                    while (l + 1 < r) {
                        int c = (l + r) / 2;
                        if (A[i] * A[c] < x) r = c;
                        else l = c;
                    }
                    total += N - r;
                }
                if (A[i] * A[i] < x) total--;
            }
            total /= 2;
            return total < K;
        }();
        if (ok) l = x;
        else r = x;
    }
    cout << l << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
// int d[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  int ans = 1000-n%1000;
  if(ans!=1000)cout << ans << endl;
  else cout << 0 << endl;
  
  return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,x,n) for(int i=x; i<(int)(n); i++)
#define rep_eq(i,x,n) for(int i=x; i<=(int)(n); i++)
using namespace std;

int main() {
  int W,H,N; cin >>W >>H >>N;

  vector<vector<bool>> vec(W, vector<bool>(H));

  rep(i,0,N) {
    int x,y,a; cin >>x >>y >>a;
    if (a==1) {
      rep(i,0,x) {
        rep(j,0,H) {
          vec[i][j]=true;
        }
      }
    } else if (a==2) {
      rep(i,x,W) {
        rep(j,0,H) {
          vec[i][j]=true;
        }
      }
    } else if (a==3) {
      rep(i,0,W) {
        rep(j,0,y) {
          vec[i][j]=true;
        }
      }
    } else {
      rep(i,0,W) {
        rep(j,y,H) {
          vec[i][j]=true;
        }
      }
    }
  }

  int ans=0;

  rep(i,0,W) {
    rep(j,0,H) {
      if (vec[i][j]==false) ans++;
    }
  }

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


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int peo,que,ans,max=0;
    cin>>peo>>que;
    for(int i=0;i<peo;i++){
        int sum=0;
        for(int j=0;j<que;j++){
            cin>>ans;
            if(ans==1)sum++;
        }
        if(sum>max)max=sum;
    }
    cout<<max<<endl;
    return 0;
}

Measured memory_bytes: 1164
s = input()
pos = 0
str_len = len(s)
count = 0
seq_a = 0
seq_bc = 0

while pos < str_len:
    if s[pos] == "A":
        while pos < str_len and s[pos] == "A":
            seq_a += 1
            pos += 1
        if pos + 1 < str_len and s[pos] == "B" and s[pos+1] == "C":
            while pos < str_len and s[pos] == "B" and pos + 1 < str_len and s[pos+1] == "C":
                seq_bc += 1
                pos += 2
            count += seq_a * seq_bc
            if pos < str_len and s[pos] != "A":
                seq_a = 0
            seq_bc = 0
        else:
            pos += 1
            seq_a = 0
    else:
        pos += 1
        seq_a = 0

print(count)

Measured memory_bytes: 3500
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import qualified Data.Graph as G

dfs :: G.Forest Int -> G.Vertex -> Maybe Int
dfs gs v = iter 0 gs
  where
    iter _ []     = Nothing
    iter d ((G.Node r sf):ks)
        = if r == v then Just d else iter (d + 1) sf <|> iter d ks

main :: IO ()
main = do
    n <- readLn
    as <- replicateM n readLn :: IO [Int]

    let g = G.buildG (1, n) (zip [1..] as)

    case dfs (G.dfs g [1]) 2 of
        Nothing -> print (-1)
        Just n  -> print n

Measured memory_bytes: 48508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000 + 10;
int main(){
    int T; cin>>T;
    while(T--){
        ll A,B,C,D; cin>>A>>B>>C>>D;
        if(A<B) cout<<"No"<<endl;
        else if(D<B) cout<<"No"<<endl;
        else{
            if(C>=B-1) cout<<"Yes"<<endl;
            else{
                D %= B;
                if(D==0){
                    A %= B;
                    if(A<=C) cout<<"Yes"<<endl;
                    else cout<<"No"<<endl;
                }
                else{
                    ll d = __gcd(D,B);
                    if(B-(d-A%d)<=C) cout<<"Yes"<<endl;
                    else cout<<"No"<<endl;
                }
            }
        }
    }
}


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

using namespace std;
const int maxn = 2e5 + 10;
const int inf = (1LL << 55LL);
typedef long long ll;
ll  h[maxn], a[maxn];
int n;
ll dp[maxn];
class node{
public:
    ll val;
    int lb, rb;
    node *left, *right;
    node(int levo, int desno){
        lb = levo;
        rb = desno;
        if(levo == desno){
            val = 0;
        }
        else{
            int mid = (levo + desno) >> 1;
            left = new node(levo, mid);
            right = new node(mid + 1, desno);
            val = max(left->val, right->val);
        }
    }
    void update(int _node, ll new_val){
        if(lb == rb){
            val = new_val;
            return;
        }
        if(_node >= right -> lb){
            right -> update(_node, new_val);
        }
        else{
            left -> update(_node, new_val);
        }
        val = max(left->val, right->val);
    }
    ll query(int i, int j){
        if(i <= lb and rb <= j) return val;
        /// i j l r i j
        if(j < lb or rb < i) return -inf;
        return max(left->query(i, j), right->query(i, j));
    }
};
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    for(int i = 0; i < n; i ++){
        cin >> h[i];
    }
    for(int i = 0; i < n; i ++){
        cin >> a[i];
        dp[i] = 0;
    }
    node *tree = new node(0, n + 1);
    for(int at = 0; at < n; at ++){
        ll tmp = tree->query(0, h[at]);
        tree->update(h[at], tmp + a[at]);
    }
    cout << tree->query(0, n) << endl;
    return 0;
}


Measured memory_bytes: 23680
def ints():
  return [int(x) for x in input().split()]
def readi():
  return int(input())

n = readi()
s = input()
for i in range(len(s)):
  w = ord(s[i])+n
  if w>ord('Z'):
    w = w-ord('Z')+ord('A')-1
  print(chr(w), end='')
print()


Measured memory_bytes: 43624
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n, k;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> k;
    if(k <= (n + 1) / 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int nb[] = new int[32];
		
		int nn = n<0 ? -n:n;
		for(int i=0;nn>0;i++){
			nb[i] = nn & 1;
			nn >>= 1;
		}
		
		int maxlen = 512;
		int ans[] = new int[maxlen];
		for(int i = 0;i<32;i+=2){
			if(n>=0){
				if(nb[i] == 1 && nb[i+1] == 0)
					ans[i]++;
				else if(nb[i] == 0 && nb[i+1] == 1){
					ans[i+1]++;
					ans[i+2]++;
				}
				else if(nb[i] == 1 && nb[i+1] == 1){
					ans[i]++;
					ans[i+1]++;
					ans[i+2]++;
				}
			}
			else{
				if(nb[i] == 1 && nb[i+1] == 0){
					ans[i]++;
					ans[i+1]++;
				}
				else if(nb[i] == 0 && nb[i+1] == 1){
					ans[i+1]++;
				}
				else if(nb[i] == 1 && nb[i+1] == 1){
					ans[i]++;
					ans[i+2]++;
					ans[i+3]++;
				}
			}
		}
		
		for(int i=0;i<maxlen-3;i++){
			int d = Math.min(ans[i] / 2, ans[i+1]);
			ans[i] -= 2*d;
			ans[i+1] -= d;
			
			while(ans[i] >= 2){
				ans[i]-=2;
				ans[i+1]++;
				ans[i+2]++;
			}
		}
		int p = maxlen-1;
		
		while(p >0 && ans[p] == 0){
			p--;
		}
	
		for(int i=p;i>=0;i--){
			System.out.print(ans[i]);
		}
	}

}


Measured memory_bytes: 23764
import java.util.Scanner;
public 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();
		int D = sc.nextInt();
		
		System.out.println(Math.min(A, B) + Math.min(C, D));
	}
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T = int> void print(vector<T> v){for(auto a:v)cout<<a<<" ";cout<<endl;}

/*
*/

double a,b,x,l=0,r=90,eps=1e-8;

bool f(double arg){
	double V=0;
	if(a*tan(arg/180*M_PI)<=b){
		V = a*(a*b - a*a*tan(arg/180*M_PI)/2);
	}else{
		V = a*(b*b*tan((90-arg)/180*M_PI)/2);
	}
	// cerr<<arg<<","<<V<<endl;
	return V>=x;
}

int main(void){
	cin>>a>>b>>x;
	while(r-l>eps){
		double mid = (r+l)/2;
		if(f(mid)){
			l=mid;
		}else{
			r=mid;
		}
	}
	cout<<fixed<<setprecision(15)<<l<<endl;
	return 0;
}

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

int main() {
  int X;
  int count=0;
  cin >> X; //X＝３５
  if(X==2)
    cout << X;
  else{
     for(int i=0; i<100004; i++){
      for(int j=2; j<X; j++){
        if(X%j==0){
          X++;
          count=0;
          break;
        }
        if(X%j!=0)
          count++;
      }
      if(count==X-2){
          cout << X;
          break;
      }
     }
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
	int a,b,c,max=0,half=0,min=0;
	cin>>a>>b>>c;
	if(a<=b && a<=c) min=a;
	else if(b<=a && b<=c) min=b;
	else min=c;
	if(b<=a && c<=a) max=a;
	else if(a<=b && c<=b) max=b;
	else max=c;
	if((b<=a && a<=c) || (c<=a && a<=b)) half=a;
	else if((a<=b && b<=c) || (c<=b && b<=a)) half=b;
	else half=c;
	cout<<min<<' '<<half<<' '<<max<<endl;
	return 0;
}


Measured memory_bytes: 3088
#include <cstdio>

int calc(int a, int b, int c){
    if(a == b && b == c){
        return 0;
    }
    int num[3];
    num[0] = a;
    num[1] = b;
    num[2] = c;
    int max = 0;
    int min = 10000;
    int maxnum = 0;
    int minnum = 0;
    for(int i = 0; i < 3; i++){
        if(num[i] < min){
            min = num[i];
            minnum = i;
        }
        if(num[i] > max){
            max = num[i];
            maxnum = i;
        }
    }
    for(int i = 0; i < 3; i++){
        num[i] = num[i] - min;
    }
    if(max - min >= 2){
        num[minnum] += 2;
        return calc(num[0], num[1], num[2]) + 1;
    }else{
        for(int i = 0; i < 3; i++){
            if(i != maxnum){
                num[i] += 1;
            }
        }
        return calc(num[0], num[1], num[2]) + 1;
    }

}

int main(void){
    int A, B, C;
    scanf("%d %d %d", &A, &B, &C);
    printf("%d\n", calc(A, B, C));
    return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const N = 100

const (
	WHITE = iota
	GRAY
	BLACK
)

type Graph struct {
	M               [N][N]int
	color, d, f, nt [N]int
	tt              int
}

func (g *Graph) next(u, n int) int {
	for v := g.nt[u]; v < n; v++ {
		g.nt[u] = v + 1
		if g.M[u][v] != 0 {
			return v
		}
	}
	return -1
}

func (g *Graph) dfsVisit(r, n int) {
	var S []int
	S = append([]int{r}, S...)
	g.color[r] = GRAY
	g.tt++
	g.d[r] = g.tt

	for len(S) != 0 {
		u := S[0]
		v := g.next(u, n)
		if v == -1 {
			S = S[1:]
			g.color[u] = BLACK
			g.tt++
			g.f[u] = g.tt
			continue
		}

		if g.color[v] != WHITE {
			continue
		}

		g.color[v] = GRAY
		g.tt++
		g.d[v] = g.tt
		S = append([]int{v}, S...)
	}
}

func (g *Graph) dfs(n int) string {
	for i := 0; i < n; i++ {
		g.color[i] = WHITE
	}
	g.tt = 0

	for u := 0; u < n; u++ {
		if g.color[u] == WHITE {
			g.dfsVisit(u, n)
		}
	}

	var out bytes.Buffer
	for i := 0; i < n; i++ {
		out.WriteString(fmt.Sprintf("%d %d %d\n", i+1, g.d[i], g.f[i]))
	}

	return strings.TrimRight(out.String(), "\n")
}

func answer(reader io.Reader) string {
	sc := bufio.NewScanner(reader)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var g Graph
	for i := 0; i < n; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		k, _ := strconv.Atoi(sc.Text())
		u--
		for j := 0; j < k; j++ {
			sc.Scan()
			v, _ := strconv.Atoi(sc.Text())
			v--
			g.M[u][v] = 1
		}
	}

	return g.dfs(n)
}

func main() {
	fmt.Println(answer(os.Stdin))
}



Measured memory_bytes: 1364
#include <bits/stdc++.h>
using namespace std;
int main() {
  string ch;
  int result[26] = {0};
  while(getline(cin, ch)) {
    for (int i = 0; i < ch.size(); i++) {
      if (isalpha(ch[i])) {
        ch[i] = tolower(ch[i]);
        result[ch[i] - 'a']++;
      }
    }
  }
  for (int i = 0; i < 26; i++) {
    cout << (char)('a' + i) << " : " << result[i] << endl;
  }
}


Measured memory_bytes: 3140
#include <iostream>
#include <vector>
#include <numeric>
#include <iomanip>

using namespace std;

int main(int argc, char const *argv[])
{
    int n, k; cin >> n >> k;
    int z = max(k+1, n+1);
    vector<double> p(z, 1.0);
    p[0] = 0;
    for(int i=z-1;i>0;--i) {
        if (i>=k) p[i] = 1.0;
        else if(2*i>z-1) p[i] = 0.5;
        else p[i] = p[2*i] * 0.5;
    }
    cout << fixed << setprecision(10) 
        << accumulate(p.begin(), p.begin()+n+1, 0.0) / n << endl;
    return 0;
}


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

int main() {
	int n, as = 0, bs = 0;
	vector<int> a;
	cin >> n;
	rep(i, n) {
		int ai;
		cin >> ai;
		a.push_back(ai);
	}
	sort(a.begin(), a.end());
	rep(i, n) {
		if (i % 2 == 0) as += a[a.size() - 1];
		else bs += a[a.size() - 1];
		a.pop_back();
	}
	cout << as - bs << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int search(int* S, int n, int t){
	int i = 0;
	S[n] = t;
	while (S[i] != t) i++;
	return i != n;
}


int main(int argc, char const *argv[]) {
	int i, n, S[10001], q, t, c = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &S[i]);

	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &t);
		if(search(S, n, t)) c++;
	}

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

	return 0;
}



Measured memory_bytes: 2072
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
#define    mod      1000000007
#define    speed    ios_base::sync_with_stdio(false);
#define    up       cin.tie(NULL);
#define    pb       push_back
#define    mp       make_pair
#define    T        int t; cin >> t; while(t--)
ll dp[100005] , arr[100005];
int n , k;
 
ll solve(int i){
    if(i > n){
        return 100000;
    }
    if(i==n){
        return 0;
    }
    if(dp[i]!=-1){
        return dp[i];
    }
    ll temp = 1000000000;
    for(int j = i+1; j <= min(i+k , n); j++){
        temp = min(temp , abs(arr[j]-arr[i]) + solve(j));
    }
    return (dp[i] = temp);
}
 
int main(){
  for(int i = 0; i <= 100000; i++){
      dp[i] = -1;
  }
  cin >> n >> k;
  for(int i = 1; i <= n; i++){
      cin >> arr[i];
  }
  cout << solve(1) << '\n';
}

Measured memory_bytes: 6528
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int H, W, Dist[55][55], ans;
char C[55][55];
int di[4] = {-1, 0, 1, 0}, dj[4] = {0, -1, 0, 1};

int main(){
  scanf("%d%d", &H, &W);
  for (int i = 0; i < H; i++) scanf("%s", &C[i]);

  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (C[i][j] == '.') ans++;
    }
  }
  
  Dist[0][0] = 1;
  queue <Pii> que; que.push(mp(0, 0));
  while (!que.empty()){
    Pii Q = que.front(); que.pop();
    for (int k = 0; k < 4; k++){
      int i = Q.fi + di[k], j = Q.se + dj[k];
      if (0 <= i && i < H && 0 <= j && j < W){
        if (Dist[i][j] == 0 && C[i][j] != '#'){
          Dist[i][j] = Dist[Q.fi][Q.se] + 1;
          que.push(mp(i, j));
        }
      }
    }
  }
  
  if (Dist[H - 1][W - 1] == 0){
    cout << -1 << endl;
  }else{
    cout << ans - Dist[H - 1][W - 1] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin >> s;
    if(s=="abc" || s=="acb" || s == "bac" || s=="bca" || s== "cab" || s == "cba"){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
N=int(input())
works=[]
for i in range(N):
    [a,b]=[int(_) for _ in input().split()]
    works.append([b,a])
works.sort()
works2=works[:1]
for work in works[1:]:
    if work[0]==works2[-1][0]:
        works2[-1][1]+=work[1]
    else:
        works2.append([work[0],works2[-1][1]])
        works2[-1][1]+=work[1]

if all([work[0]>=work[1] for work in works2]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 63296
#include <iostream>
#include <string>

using namespace std;

int main() {
	int num;

	cin >> num;

	int *d;
	d = new int[num];

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

	int sum = 0;

	for (int i = 0; i < num; i++) {
		for (int j = i + 1; j < num; j++) {
			sum += (d[i] * d[j]);
		}
	}

	cout << sum << endl;

	system("pause");
	return 0;
}



Measured memory_bytes: 504
import numpy as np

N = int(input())
A = np.array(list(map(int, input().split())))
abs_A = abs(A)

min_A = min(abs_A)

if (A < 0).sum() % 2:
    print(sum(abs_A) - min_A * 2)
else:
    print(sum(abs_A))

Measured memory_bytes: 38120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		char[] s = scn.nextLine().toCharArray();

		String ans = "Sunny";
		if(s[0] == 'S') {
			ans = "Cloudy";
		}else if(s[0] == 'C') {
			ans = "Rainy";
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 21844