akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
//template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) {os << p.first << " " << p.second;return os;}

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T, class U>bool chmin(T& a, U b) { if (a > b) { a = b; return true; }return false; }
template <class T, class U>bool chmax(T& a, U b) { if (a < b) { a = b; return true; }return false; }
struct UnionFind {
	vector<int> parent;
	int size;
	UnionFind(int n) :parent(n, -1), size(n) {}
	bool unite(int x, int y) {
		x = root(x); y = root(y);
		if (x == y)return false;
		if (size_of(x) < size_of(y))swap(x, y);
		parent[x] += parent[y]; parent[y] = x; size--;
		return true;
	}
	bool same(int x, int y) { return root(x) == root(y); }
	int root(int x) { return parent[x] < 0 ? x : parent[x] = root(parent[x]); }
	int size_of(int x) { return -parent[root(x)]; }
};

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	vector<int>x(N), y(N); rep(i, 0, N) { cin >> x[i] >> y[i]; }

	vector<pair<pii, int>>v(N);
	rep(i, 0, N) {
		v[i].first = pii(x[i], y[i]);
		v[i].second = i;
	}
	sort(all(v));
	UnionFind uf(N);
	rep(i, 1, N) {
		if (v[i - 1].first.first == v[i].first.first) {
			uf.unite(v[i - 1].second, v[i].second);
		}
	}
	rep(i, 0, N) {
		swap(v[i].first.first, v[i].first.second);
	}
	sort(all(v));
	rep(i, 1, N) {
		if (v[i - 1].first.first == v[i].first.first) {
			uf.unite(v[i - 1].second, v[i].second);
		}
	}

	vector<vector<int>>u(N);
	rep(i, 0, N) {
		u[uf.root(i)].eb(i);
	}
	dump(u);

	int sum = 0;
	rep(i, 0, u.size()) {
		set<int>a, b;
		for (auto w : u[i]) {
			a.insert(x[w]);
			b.insert(y[w]);
		}
		sum += a.size()*b.size();
	}
	cout << sum - N << endl;



	return 0;
}


Measured memory_bytes: 12788
n, m = map(int, input().split())
graph = [[False for i in range(60)] for _ in range(60)]
A, B = [], []
ans = 0

def dfs(v):
    if vis[v]:
        return
    vis[v] = True
    for i in range(n):
        if graph[v][i]:
            dfs(i)

for i in range(m):
    a, b = map(lambda x: int(x)-1, input().split())
    A.append(a)
    B.append(b)
    graph[a][b] = graph[b][a] = True

for i in range(m): #どれが橋か
    graph[A[i]][B[i]] = graph[B[i]][A[i]] = False
    vis = [False] * n
    
    dfs(0)

    f = 0
    for j in range(n):
        if not vis[j]: f = 1
    if f: ans += 1
    
    graph[A[i]][B[i]] = graph[B[i]][A[i]] = True

print(ans)

Measured memory_bytes: 3064
<?php
$input = fgets(STDIN);
$array = explode(' ', $input);

$A = (int)$array[0];
$B = (int)$array[1];
$C = (int)$array[2];
$K = (int)$array[3];

$sum = 0;

if ($A >= $K) {
   echo $K;
} else {
   $sum += $A;
   if ($B < $K - $A) {
      if ($C >= $K - $A - $B) {
          $sum += ($K - $A - $B) * -1;
      } else {
          $sum += $C * -1;
      }
   }

   echo $sum;
}

Measured memory_bytes: 16336
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  int n;cin >> n;
  map<int,int> m;
  vi c(n);

  rep(i,n) cin >> c[i];

  int i = 0;
  int pos = 0;
  for(i = 0;i < n;i++)
  {
    if(pos == 1)
    {
      cout << i << endl;
      return 0;
    }
    else
    {
      if(m[c[pos]] != 0)
      {
        cout << -1 << endl;
        return 0;
      }
      else
      {
        m[c[pos]]++;
        pos = c[pos] - 1;
      }
    }
  }

  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 5376
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

int h,w;
vector<string>field(h);
bool seen[100][100];
int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
int cnt = 0;

int dfs(int y,int x,int &cnt){
    cnt++;
    seen[y][x] = true;
    rep(i,4){
        int ny = y+dy[i],nx = x+dx[i];
        if(ny<0 || ny>=h || nx<0 || nx>=w)continue;
        if(field[ny][nx] != '#')continue;
        if(seen[ny][nx])continue;
        cnt++;
        dfs(ny,nx,cnt);
    }
    return cnt;
}

int main(){
    cin>>h>>w;
    field.resize(h);
    rep(i,h)cin>>field[i];
    rep(i,h)rep(j,w)seen[i][j] = false;
    rep(i,h){
        rep(j,w){
            if(field[i][j] != '#')continue;
            if(seen[i][j])continue;
            cnt = 0;
            int r = dfs(i,j,cnt);
            if(r <= 1){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
}



Measured memory_bytes: 512
N = int(input())
A = input()
B = input()
C = input()

ans = 0
for i in range(N):
  if A[i] != B[i] and A[i] == C[i]: # AとCが同じ
    ans += 1
  elif A[i] == B[i] and A[i] != C[i]: # AとBが同じ
    ans += 1
  elif A[i] != B[i] and B[i] == C[i]: # BとCが同じ
    ans += 1
  elif A[i] != B[i] and B[i] != C[i]: # 3つとも異なる
    ans += 2

print(ans)


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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second

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

    char ch;
    cin >> ch;
    if (ch >= 'a' && ch <= 'z') cout << "a\n";
    else cout << "A\n";


    return 0;
}

Measured memory_bytes: 3632
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		// input
		final int NUM = scan.nextInt();
		List<Integer> scores = new ArrayList<>();
		int delicious = scan.nextInt();
		for (int i = 0; i < NUM; i++) {
			scores.add(delicious + i);
		}

		// search
		int sum = 0;
		Collections.sort(
				scores, 
	            new Comparator<Integer>() {
	                @Override
	                public int compare(Integer a, Integer b) {
	                    return Math.abs(a) - Math.abs(b);
	                }
	            }
	        );
		scores.remove(0);
		for (Integer integer : scores) {
			sum += integer;
		}

		// answer
		System.out.println(sum);

	}
}

Measured memory_bytes: 22868
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>

int main(){
	int *A, n,i,j,cnt=0,tmp;

	scanf("%d", &n);
	A = (int *)malloc(sizeof(int)*n);
	for (i = 0; i < n; ++i) scanf("%d", A+i);

	for (i = 0; i < n ; i++) {
		for (j = 1; j < n;j++) {
			if (*(A + j - 1) > *(A + j)) {
				tmp = *(A + j); *(A + j) = *(A + j - 1); *(A + j - 1) = tmp;
				cnt++;
			}
		}
	}
	for (i = 0; i < n; i++) printf("%d%c", A[i], i < n - 1 ? ' ' : '\n');
	printf("%d\n", cnt);
	free(A);
	return 0;
}

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

// ただの辺
struct edge {
    int to;
    long long cost;
    // 引数一つの時は距離1
    edge(int t, long long c = 1) : to(t), cost(c) {}
};

int l;
vector<vector<edge>> g;

//二進数の桁数
int width(int x) {
    int res = 0;
    while (x) {
        x /= 2;
        res++;
    }
    return res;
}

bool ispow_2(int x) {
    return x == (1 << (width(x) - 1));
}

int main() {
    cin >> l;
    int num_edge = 0;
    int w = width(l);
    if (ispow_2(l)) {
        g.resize(w);
        for (int i = 0; i < w - 1; i++) {
            g[i].push_back(edge(i + 1, 0));
            g[i].push_back(edge(i + 1, 1 << (w - i - 2)));
            num_edge += 2;
        }
    } else {
        l--;
        g.resize(w);
        for (int i = 0; i < w - 1; i++) {
            g[i].push_back(edge(i + 1, 0));
            g[i].push_back(edge(i + 1, 1 << (w - i - 2)));
            num_edge += 2;
        }
        bitset<20> b(l + 1);
        int now = 1 << (w - 1);
        for (int i = w - 2; i >= 0; i--) {
            if (b[i]) {
                g[0].push_back(edge(w - i - 1, now));
                num_edge++;
                now += 1 << i;
            }
        }
    }

    cout << g.size() << " " << num_edge << endl;
    for (int i = 0; i < g.size(); i++) {
        for (auto e : g[i]) {
            cout << i + 1 << " " << e.to + 1 << " " << e.cost << endl;
        }
    }
}

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

int main() {
  int n, k;
  while (cin >> n >> k && n && k) {
    int card[100010];
    for (auto i=0; i<k; i++) {
      cin >> card[i];
    }
    sort(card, card+k);
    bool zero = (card[0] == 0);
    vector< pair<int, bool> > V;
    int tnow = 1;
    for (int i=(zero ? 1 : 0); i<k; i++) {
      if (i == k-1) {
        V.push_back(make_pair(tnow, false));
        break;
      }
      // cerr << "card[" << i << "] = " << card[i] << ", card[" << i+1 << "] = " << card[i+1] << endl;
      if (card[i] == card[i+1] - 1) {
        tnow++;
      } else {
        if (zero && card[i] == card[i+1] - 2) {
          V.push_back(make_pair(tnow, true));
        } else {
          V.push_back(make_pair(tnow, false));
        }
        tnow = 1;
      }
    }
    int ans = 0;
    for (auto it = V.begin(); it != V.end(); it++) {
      if ((*it).second) {
        ans = max(ans, (*it).first + (*(it+1)).first + 1);
      } else if (zero) {
        ans = max(ans, (*it).first + 1);
      } else {
        ans = max(ans, (*it).first);
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1656
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 x = sc.nextInt();
		int y = sc.nextInt();
		int min = Math.min(x, y);
		long ans = 0;
		if(a + b < 2 * c) {
			ans += min * (a + b);
		} else {
			ans += min * 2 * c;
		}
		if(x > y) {
			if(a < 2 * c) {
				ans += (x - min) * a;
			} else {
				ans += (x - min) * 2 * c;
			}
		} else {
			if(b < 2 * c) {
				ans += (y - min) * b;
			} else {
				ans += (y - min) * 2 * c;
			}
		}
		System.out.println(ans);
	}

}


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

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;

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

	int ans = 0;
	int i = 0;
	for (; i < n; i += k)
	{
		if (i != 0)
			i--;

		ans++;
	}

	if (i < n)
	{
		ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 640
n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i)
a = a.sort
a = a.reverse
sa, sb = 0, 0
for i in 1..n
  if i % 2 == 1
    sa += a[i-1]
  else
    sb += a[i-1]
  end
end
puts sa - sb

Measured memory_bytes: 14368
#include<cstdio>
#include<algorithm>
#include<utility>
typedef long long ll;
using namespace std;
int n,f;
ll x,y,rl,rh,ans;
pair<ll,ll> p[200000];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%lld %lld",&x,&y);
        p[i]=make_pair(min(x,y),max(x,y));
    }
    sort(p,p+n);
    rh=rl=p[0].second;
    for(int i=1;i<n;i++){
        rh=max(rh,p[i].second);
        rl=min(rl,p[i].second);
    }
    ans=(p[n-1].first-p[0].first)*(rh-rl);
    f=0;
    for(int i=1;i<n;i++){
        if(rh==p[i].second){
            f=1;
            break;
        }
    }
    if(f){
        x=rh-p[0].first;
        rl=1000000000;
        rh=p[n-1].first;
        for(int i=0;i<n-1;i++){
            rl=min(rl,p[i].second);
            rh=max(rh,p[i].second);
            ans=min(ans,x*(rh-min(rl,p[i+1].first)));
        }
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <string>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <queue>
#include <climits>
#include <set>
#include <complex>
#include <cmath>
#include <cstring>
#include <map>
using namespace std;
using ll = long long;
#define MOD 1000000007
#define INF 1LL << 59

int main()
{
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    //cout << fixed << setprecision(7);

    string s;
    cin >> s;
    ll ans = 0;
    int n = s.size();
    int r = 0, b = 0;

    for (int i = 0; i < n; ++i)
    {
        if (s[i] == '1')
            r++;
        else
            b++;
    }

    cout << min(r, b) * 2 << endl;
    return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;


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

    a -= c;
    b -= d;
    cout << a * b << endl;
    

    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int x[100],y[100];
ll h[100];

int main()
{
	int n;
	cin>>n;
	for( int i=0; i<n; i++ )
	{
		cin>>x[i]>>y[i]>>h[i];
	}
	for( int cx=0;cx<=100;cx++)
	{
		for( int cy=0;cy<=100;cy++)
		{
			ll H;
			for( int i=0; i<n; i++)
			{
				if( h[i] != 0 )
				{
					H = abs(cx-x[i])+abs(cy-y[i])+h[i];
					break;
				}
			}
			bool ok = true;
			for( int i=0; i<n; i++)
			{
				if( ( h[i]!=0 && abs(cx-x[i])+abs(cy-y[i])+h[i] != H )
				    ||( h[i]==0 && abs(cx-x[i])+abs(cy-y[i])+h[i] < H ) )
				{
					ok = false;
					break;
				}
			}
			if(ok)
			{
				cout << cx <<" "<< cy<<" " << H << endl;
				return 0;
			}
		}
	} 
	
		
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;

int main()
{
  long r, d, x, x0;
  scanf("%ld %ld %ld", &r, &d, &x);
  x0 = x;

  for (int i = 1; i <= 10; i++)
  {
    x0 = x;
    x = r * x0 - d;
    printf("%ld\n", x);
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,MAX = 0;
  cin >> N;
  int A = 0;
  vector<int> v(N);
  for (int i = 0; i < N; i++){
     cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());
  for (int i = 0; i < N; i++){
    MAX = v.at(i);
   if (MAX != -1){
     A++;
     for (int i = 0; i < N; i++){
       if (MAX == v.at(i)){
         v.at(i) = -1;
       }
     }
   }
  }

  cout << A << endl;
}

Measured memory_bytes: 256
n = int(raw_input())
a = map(int, raw_input().split())
a.sort()
s = [0] * (n + 1)
for i in xrange(n):
    s[i + 1] += s[i] + a[i]
for i in xrange(n, 0, -1):
    if 2 * s[i - 1]  < a[i - 1]:break
print n - (i - 1)


Measured memory_bytes: 11316
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
using namespace std;
int main() {
	int a = 0, b = 0, c = 0, d[100000], e[100000], f = 0, g = 0, h = 0, count = 0;
	char rikka, toka[100000];
	string saya, homu, kyok, mami,mado[100];
	int manji, nk[26] = {false};
	cin >> a;
	for (int i = 0; i < a; i++) {
		cin >> b >> c;
		count += (c - b) + 1;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
macro_rules! fn_memo{
    ($fun:ident : $memo:ident ( $($param:ident : usize),* ; $($ex_param:ident : $ep_ty:ty),* ) -> $out:ty $body:block) => {
        fn $fun($memo:&mut memo_inner!(type $out; $($param),*), $($param : usize),* , $($ex_param : $ep_ty),*) -> $out $body
    };
}
macro_rules! memo{
    ($fun:ident : $memo:ident ( $($inf_arg:expr),* ) -> $out:ty) => {
        let mut $memo = &mut memo_inner!(vec $out; $($inf_arg),*);
    };
}
macro_rules! memo_inner {
    (type $out:ty ; $param:ident) => {
        Vec<Option<$out>>
    };
    (type $out:ty ; $param:ident, $($p:ident),*) => {
        Vec<fn_vec!($out; $($p),*)>
    };
    (vec $out:ty; $inf_arg:expr) => {
        vec![None as Option<$out>; $inf_arg]
    };
    (vec $out:ty; $inf_arg:expr, $(ia:expr),*) => {
        vec![memo!($out; $($ia),*); $inf_arg]
    };
}
macro_rules! get{
    ($fun:ident : $memo:ident ( $($arg:expr),* ;  $($ex_arg:expr),* )) => {{
        if $memo$([$arg])*.is_none() {
            $memo$([$arg])* = Some($fun($memo, $($arg),* , $($ex_arg),*));
        }
        $memo$([$arg])*.unwrap()
    }};
}

fn main(){
    let mut buf = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut sw = buf.split_whitespace();
    
    let n: usize = sw.next().unwrap().parse().ok().unwrap();
    let m: usize = sw.next().unwrap().parse().ok().unwrap();
    let mut broken = vec![false; n+1];
    for _ in 0..m {
        let a:usize = sw.next().unwrap().parse().ok().unwrap();
        broken[a] = true;
    }
    let broken = broken;
    
    memo!{ solve:sm(100_001) -> u64 };
    println!("{}", get!{ solve:sm( n; &broken ) });
}

fn_memo!{ solve:sm( n:usize; broken: &Vec<bool> ) -> u64 {
    if broken[n] {
        0
    } else if n <= 1 { 
        1
    } else {
        (get!{solve:sm( n-1; broken )} + get!{solve:sm( n-2; broken )}) % 1_000_000_007
    }
}}



Measured memory_bytes: 11004
import java.util.Scanner;

public class Main {

    static int n, A, B, C, l[];

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        l = new int[n];

        for (int i = 0; i < n; i++) {
            l[i] = sc.nextInt();
        }

        System.out.println(dfs(0, 0, 0, 0));
    }

    static int dfs(int cur, int a, int  b, int c) {
        if (cur == n) {
            if (a <= 0 || b <= 0 || c <= 0)
                return 99999;
            return Math.abs(a-A) + Math.abs(b-B) + Math.abs(c-C)-30;
        }

        int ret0 = dfs(cur+1, a, b, c);
        int ret1 = dfs(cur+1, a+l[cur], b, c)+10;
        int ret2 = dfs(cur+1, a, b+l[cur], c)+10;
        int ret3 = dfs(cur+1, a, b, c+l[cur])+10;

        int min = Math.min(Math.min(ret0, ret1), Math.min(ret2, ret3));
        return min;
    }
}


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

int main()
{
  int N, M;
  int A[5005], B[5005];
  int maxv = 0;
  
  cin >> N >> M;
  Rep(i,N) cin >> A[i];
  Rep(i,M) cin >> B[i];
  
  Rep(i,M) {
    int now = i, cnt = 0;
    Rep(j,N) {
      if(A[j] == B[now])cnt++, now++;
    }
    maxv = max(maxv,cnt);
  }

  cout << maxv << endl;
  return 0;
}

Measured memory_bytes: 3136
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <functional>
#include <deque>
typedef long long ll;

using namespace std;

class Edge
{
	public:
	int cost;
	int next;

	Edge(int n,int c)
	{
		next=n;
		cost=c;
	}
};

vector<Edge> g[100000];
int used[100000];
deque<int> keiro;

int main()
{
	int n,m;
	int l,r;//端
	cin>>n>>m;
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(Edge(b,1));
		g[b].push_back(Edge(a,1));
	}
	fill(used,used+100000,0);
	l=0;
	r=g[l][0].next;
	used[l]=1;
	used[r]=1;
	keiro.push_back(l);
	keiro.push_back(r);
	while(g[r].size()!=0)
	{
		bool f=true;
		for(int i=0;i<g[r].size();i++)
		{
			int n=g[r][i].next;
			if(used[n]!=1)
			{
				r=n;
				used[r]=1;
				keiro.push_back(r);
				f=false;
				break;
			}
		}
		if(f)
			break;
	}
	while(g[l].size()!=0)
	{
		bool f=true;
		for(int i=0;i<g[l].size();i++)
		{
			int n=g[l][i].next;
			if(used[n]!=1)
			{
				l=n;
				used[l]=1;
				keiro.push_front(l);
				f=false;
				break;
			}
		}
		if(f)
			break;
	}
	cout<<keiro.size()<<endl;
	for(int i=0;i<keiro.size();i++)
		cout<<keiro[i]+1<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 7040
#include <stdio.h>
typedef struct{
  char c;
  int number;
}donald;
void Bub(donald *a,int n);
void Sel(donald *a, int n);
void PP(donald *a,int n);
int stablecheck(donald *a,int n,donald *b);
int judge(donald *a,int n,donald *b);
int main(){

  int n,i,stable=0;
  donald trump[36],trump1[36],trump2[36];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf(" %c%d",&trump[i].c,&trump[i].number);
    trump1[i].c=trump[i].c;
    trump1[i].number=trump[i].number;
    trump2[i].c=trump[i].c;
    trump2[i].number=trump[i].number;
  }
  /*bubblr sort */
  Bub(trump1,n);
  PP(trump1,n);

  printf("Stable\n");

  /*selection sort*/

  Sel(trump2,n);
  PP(trump2,n);
  stable=judge(trump1,n,trump2);
  if(stable==1){
    printf("Stable\n");
  }
  else{
    printf("Not stable\n");
  }

  return 0;
}

void PP(donald *a,int n){
  int i;
  for(i=0;i<n;i++){
    if(i==(n-1)){
      printf("%c%d\n",a[i].c,a[i].number);
    }
    else {
      printf("%c%d ",a[i].c,a[i].number);
    }
  }
}



void Bub(donald *a,int n){
  int j,flag=1,sub,i;
  char subc;
  while(flag){
    flag=0;
    for(j=n-1;j>=1;j--){
      if(a[j].number<a[j-1].number){
	sub=a[j].number;
	a[j].number=a[j-1].number;
	a[j-1].number=sub;
	subc=a[j].c;
	a[j].c=a[j-1].c;
	a[j-1].c=subc;
	flag=1;
      }
    }
  }
}



void Sel(donald *a,int n){
  int i,min,sub,j;
  char subc;
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(a[j].number<a[min].number){
	min=j;
      }
    }
    if(a[i].number>a[min].number){
      sub=a[i].number;
      a[i].number=a[min].number;
      a[min].number=sub;
      subc=a[i].c;
      a[i].c=a[min].c;
      a[min].c=subc;
    }
  }
}




int stablecheck(donald *in, int n,donald *out){
  int i,j,a,b;
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      for(a=0;a<n;a++){
	for(b=a+1;b<n;b++){
	  if(in[i].number==in[j].number && in[i].number==out[a].number && in[j].number==out[b].number){
	    return 0;
	  }
	}
      }
    }
  }
  return 1;
}

int judge(donald *a,int n,donald *b){
    int i,cnt=0;

    for(i=0;i<n;i++){
      if(a[i].number==b[i].number && a[i].c==b[i].c){
          cnt++;
        }
      }
    if(cnt==n){
        return 1;
      }
    else {
      return 0;
    }
}

Measured memory_bytes: 608
h,w,k=map(int,input().split())
dp=[[0 for _ in range(w)]for _ in range(h+1)]
dp[0][0]=1
mod=10**9+7
for i in range(h):
    for bit in range(2**(w-1)):
        bit=bin(bit)[2:].zfill(w-1)
        f=0
        for j in range(w-2):
            if bit[j]=='1' and bit[j+1]=='1':
                f=1
                break
        if f:
            continue
        for j in range(w):
            if j==0:
                dp[i+1][j]+=dp[i][j+1] if bit[0]=='1' else dp[i][j]
            elif j==w-1:
                dp[i+1][j]+=dp[i][j-1] if bit[-1]=='1' else dp[i][j]
            else:
                dp[i+1][j]+=dp[i][j]*(bit[j-1]=='0' and bit[j]=='0')
                dp[i+1][j]+=dp[i][j-1]*(bit[j-1]=='1')
                dp[i+1][j]+=dp[i][j+1]*(bit[j]=='1')
            dp[i+1][j]%=mod
print(dp[-1][k-1])

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n;
  cin >> n;
  ll ans = 9e18;
  for (ll i = 1; i * i <= n; ++i)
    if (n % i == 0) ans = min(ans, n / i + i - 2);

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int gcd(int a, int b) {
	int temp;

	//比较两个数的大小，值大的数为a，值小的数为b
	if (a < b) {
		temp = a;
		a = b;
		b = temp;
	}

	//求余
	while (b != 0) {
		temp = a % b;
		a = b;
		b = temp;
	}
	return a;
}
int main()
{
    ll a,sum=0;
    cin>>a;
    for(int i=1;i<=a;i++)
    for(int j=1;j<=a;j++)
    for(int k=1;k<=a;k++)
    {
    	sum+=gcd(gcd(i,j),k);
	}
    printf("%lld",sum);
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

const ll mod = 1e9 + 7;

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

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

ll dp[2][100009], ans;

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

    int N, W, w[100], v[100];
    cin >> N >> W;
    rep(i, N) cin >> w[i] >> v[i];
    rep(j, N) rep(i, W + 1) {
        chmax(dp[j + 1 & 1][i], dp[j & 1][i]);
        if(i + w[j] <= W) chmax(dp[j + 1 & 1][i + w[j]], dp[j & 1][i] + v[j]);
    }
    rep(i, 2) rep(j, W + 1) chmax(ans, dp[i][j]);
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

int main(){
    int M, D;
    cin >> M >> D;

    ll ans = 0;
    for(int m = 1; m <= M; m++){
        for(int d = 1; d <= D; d++){
            int d10, d1;
            d10 = d/10;
            d1 = d%10;
            if(d1 >= 2 && d10 >= 2 && d1 * d10 == m){
                ans++;
            }
        }
    }

    cout << ans << endl;
    return 0;

}


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string N; cin >> N;
    int ok=0;
    for (int i=0;i<3;++i) if (N[i]=='7') ok=1;
    cout << (ok?"Yes":"No") << '\n';
}

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

int main(){
  int N, a, b, c, d;
  cin >> N;
  
  a = N / 1000;
  b = (N / 100) % 10;
  c = (N / 10) % 10;
  d = N % 10;
  
  if ((a==b && b==c) || (b==c && c==d)){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
}
  
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef int q;
typedef double w;
typedef string s;
typedef long long ll;
int main(){
    q r; w c=M_PI,k; cin>>r;
    k=c*pow(r,2);
    cout<<k/c;
return 0;}
// HAY MY NAME IS MOHAMMED FNNOUN MOHD


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  if(a.at(0)==a.at(1)||a.at(1)==a.at(2)||a.at(3)==a.at(2))
     cout << "Bad" << endl;
  else
    cout << "Good" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)
#define lli long long int
#define llu unsigned long long int
#define fr(va, beg, end) for (lli va = beg; va < end; va++)
#define pb push_back
#define rt return 0
#define endln "\n"
#define all(x) x.begin(), x.end()
// cout << fixed << setprecision(0) << pi <<" "<<npi<<endl;
// gcd function
// __gcd(a, b)
// for max of n elements
// cout<<max({a,b,c,d})<<endl;

lli input(lli n, vector<lli> &ve);
lli input(lli n, vector<lli> &ve) {
    lli val;
    for (lli i = 0; i < n; i++) {
        cin >> val;
        ve.pb(val);
    }
    return 0;
}

int main(void) {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s, t, ans;
    cin >> s >> t;
    lli n = s.length(), m = t.length();
    vector<lli> ve(m + 2, 0);
    vector<vector<lli>> dp(n + 2, ve);

    for (lli i = 1; i <= n; i++) {
        for (lli j = 1; j <= m; j++) {
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] =
                    max({dp[i][j - 1], dp[i - 1][j], dp[i - 1][j - 1] + 1});
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    lli a = n, b = m;
    while (a > 0 && b > 0) {
        if (dp[a][b] == dp[a - 1][b]) {
            a--;
        } else if (dp[a][b] == dp[a][b - 1]) {
            b--;
        } else {
            a--;
            b--;
            ans.pb(s[a]);
        }
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    rt;
}


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

int main()
{
  int a, b, W;
  int A, B;
  int d;
  cin >> W >> a >> b;

  // 小さい方を A
  // 大きい方を B
  if (a < b) {
    A = a; B = b;
  } else {
    A = b; B = a;
  }

  if (B <= A + W) d = 0;
  else d = B - (A + W);

  cout << d << endl;

  return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn.{readLine,readInt}
import scala.language.postfixOps

object Main {
  var cnt = 0
  val l = new Array[Int](250001)
  val r = new Array[Int](250001)

  def merge(a:Array[Int],left:Int,mid:Int,right:Int) = {
    val n1 = mid-left
    val n2 = right-mid
    Array.copy(a,left,l,0,n1)
    l(n1) = Int.MaxValue
    Array.copy(a,mid,r,0,n2)
    r(n2) = Int.MaxValue
    var i=0
    var j=0
    for(k<-left until right) {
      if(l(i)<=r(j)){
        a(k) = l(i)
        i += 1
      } else  {
        a(k)=r(j)
        j += 1
      }
      cnt += 1
    }
  }

  def getSortIndex(n:Int):Iterator[IndexedSeq[(Int,Int)]] = {
    var w = n
    var h = 0
    while(w>1) {
      h += 1
      w /= 2
    }

    def scan(h:Int,l:List[IndexedSeq[(Int,Int)]]):List[IndexedSeq[(Int,Int)]] = {
      if(h==0) l
      else
        scan(h-1,(for(i<-l.head;j<-List((i._1,(i._2+i._1)/2),((i._2+i._1)/2,i._2))) yield j)::l)
    }
    scan(h-1,List(IndexedSeq((0,n/2),(n/2,n)))).to[Iterator]
  }

  def main(args:Array[String]) = {
    val n = readInt
    val l = getSortIndex(n)
    val a = readLine.split(" ").map(_.toInt)

    for(e2<-l) {
      for(e<-e2) {
        val mid = (e._2+e._1)/2
        if(e._2-e._1>1)
          merge(a,e._1,mid,e._2)
      }
    }
    merge(a,0,n/2,n)
    println(a.mkString(" "))
    println(cnt)
  }
}

Measured memory_bytes: 314864
#include <iostream>
using namespace std;
//快速排序，快排
void qsort(int left,int right,int a[])
{
	int i,j,key;
	i=left;
	j=right;
	key=a[left];
	while(i<=j)
	{
		while(a[i]<key)
			i++;
		while(a[j]>key)
			j--; 
		if(i<=j)
		{
			swap(a[i],a[j]);
			i++;
			j--;
		}
	} 
	if(i<right) qsort(i,right,a);
	if(left<j) qsort(left,j,a);
}
int main(){
	int arr[3] ;
	cin >> arr[0] >> arr[1] >> arr[2];
	qsort ( 0 , 2 , arr ) ; 
	cout << arr[0] + arr[1] ;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
using namespace std;


int main() {

	int size;
	int a[100];
	int count = 0;

	cin >> size;

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


	int min;
	int index;
	int temp;
	for (int i = 0; i < size - 1; i++) {
		min = a[i];
		index = i;
		for (int j = i; j < size; j++) {
			if (min > a[j]) {
				index = j;
				min = a[j];
			}
		}
		if (i != index) {
			count++;
			temp = a[i];
			a[i] = a[index];
			a[index] = temp;
		}
	}

	for (int i = 0; i < size; i++) {
		printf("%d", a[i]);
		if (i + 1 != size)printf(" ");
	}
	printf("\n%d\n", count);


//	system("pause");
	return 0;
}


Measured memory_bytes: 3208
#include <cstdio>
#include <cctype>
#include <algorithm>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 5e2+5;
int n, c[N], pos[N], ans[N*N];
pair<int, int> p[N];
int main()
{
    n = read();
    for(int i = 1, x; i <= n; ++i) pos[i] = read(), p[i] = make_pair(pos[i], i);
    sort(p+1, p+1+n);
    for(int i = 1; i <= n; ++i) c[i] = p[i].second-1, pos[p[i].second] = i;
    for(int i = 1, j = 1; i <= n; ++i)
    {
        int l = p[i-1].first+1, r = p[i].first;
        for(int k = l; k < r; ++k) 
        {
            while(!c[j]&&j <= n) ++j; if(j == n+1) break;
            ans[k] = p[j].second; --c[j];
        }
        ans[r] = p[i].second;
    }
    for(int i = 1; i <= n*n; ++i) ++c[pos[ans[i]]];
    for(int i = 1, j = 1; i <= n; ++i)
    {
        int l = p[i-1].first+1, r = p[i].first;
        for(int k = l; k <= r; ++k) 
        {
            if(ans[k]) continue;
            while(c[j] == n&&j <= n) ++j; if(j == n+1) break;
            ans[k] = p[j].second; ++c[j];
        }
        if(i < n) continue;
        for(int k = p[n].first+1; k <= n*n; ++k)
        {
            if(ans[k]) continue;
            while(c[j] == n&&j <= n) ++j; if(j == n+1) break;
            ans[k] = p[j].second; ++c[j];
        }
    }
    for(int i = 1; i <= n; ++i)
    {
        int cnt = 0;
        for(int j = 1; j <= p[i].first; ++j) cnt += p[i].second == ans[j];
        if(cnt != p[i].second) return puts("No"), 0;
    }       
    puts("Yes");
    for(int i = 1; i <= n*n; ++i) printf("%d ", ans[i]);
    return 0;
}

/* 
1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 0 0 0 0 0 0 0 0 0 0
*/

Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {

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

		long a = s.nextLong();
		
		String b_s = s.next();
		
		long b = 0;
		int base = 1;
		for ( int i = b_s.length()-1; i >= 0; i-- ) {
		    char c = b_s.charAt(i);
		    if (c != '.') {
		        b += Character.getNumericValue(b_s.charAt(i)) * base;
		        base *= 10;
		    }
		}
		
		long mul = (long)(a * b);
		

		System.out.println(mul/100);

		

	}

}


Measured memory_bytes: 35736
import math
def solve():
    A,B,H,M = map(int,input().split())
    minute = H * 60 + M
    hour_angle = 360 * 1/720 * minute
    minute_angle = 360 * 1/60 * M

    angle = 0
    if hour_angle > minute_angle:
        angle = hour_angle - minute_angle
    else:
        angle = minute_angle - hour_angle
    
    print(geta(A,B,min(angle,360-angle)))

def geta(b,c,A):
    a2 = b**2 + c**2 - (2*b*c*math.cos(math.radians(A)))
    return math.sqrt(a2)
if __name__ == '__main__':
    solve()

Measured memory_bytes: 62680
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(int, n, a);
    
    int k = 0;
    For(i, n){
        if(a[i] != i+1) k ++;
    }
    CoutYN(k == 2 || k == 0);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
static const int MAX = 36;
static const int LEN = 3;

void swap(char A[][LEN], int i, int j)
{
	char temp[LEN];
	
	strcpy(temp, A[i]);
	strcpy(A[i], A[j]);
	strcpy(A[j], temp);
}

void print(char A[][LEN], int n)
{
	for (int i = 0; i < n; i++) {
		if (i > 0) {
			cout << " ";
		}
		cout << A[i];
	}		
	cout << endl;
}

void BubbleSort(char A[][LEN], int n)
{
	for (int i = 0; i < n; i++) {
		for (int j = n-1; j > i; j--) {
			if (A[j-1][1] > A[j][1]) {
				swap(A, j-1, j);
			}
		}
	}
	
	//test-def
//	for (int i = 0; i < n; i++){
//		cout << A[i] << " ";
//	}
//	cout << endl;
	//test-end;
}

void SelectionSort(char A[][LEN], int n)
{
	for (int i = 0; i < n; i++) {
		int minIndex = i;
		for (int j = i; j < n; j++) {
			if (A[j][1] < A[minIndex][1]) {
				minIndex = j;
			}
		}
		if (minIndex != i) {
			swap(A, minIndex, i);
		}
	}
	
	//test-def
//	for (int i = 0; i < n; i++){
//		cout << A[i] << " ";
//	}
//	cout << endl;
	//test-end
}

bool isStable(char B[][LEN], char S[][LEN], int n)
{
	for (int i = 0; i < n; i++) {
		if (B[i][0] != S[i][0]) {
			return false;
		}
	}
	
	return true;
}

int main()
{
	char B[MAX][LEN];
	char S[MAX][LEN];
	int n;
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> B[i];
		strcpy(S[i], B[i]);
	}
	
	BubbleSort(B, n);
	SelectionSort(S, n);
	
	print(B, n);
	cout << "Stable" << endl;
	print(S, n);
	if (isStable(B, S, n) == true) {
		cout << "Stable" << endl;
	}
	else {
		cout << "Not stable" << endl;
	}
	
	//test-def
//	for (int i = 0; i < n; i++)
//	{
//		cout << S[i] << " ";
//	}
	//test-end
	
	return 0;
}


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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n;
    string s[11234];

    cin >> n;
    REP(i, n)
    cin >> s[i];

    int oa = 0;
    int bo = 0;
    int ba = 0;

    int res = 0;
    REP(i, n)
    {
        REP(j, s[i].size() - 1)
        {
            if (s[i][j] == 'A' && s[i][j + 1] == 'B')
                res++;
        }
        if (s[i][0] == 'B' && s[i][s[i].size() - 1] == 'A')
            ba++;
        else if (s[i][0] == 'B')
            bo++;
        else if (s[i][s[i].size() - 1] == 'A')
            oa++;
    }

    if (ba)
    {
        res += ba - 1;
        if (oa)
        {
            res++;
            oa--;
        }
        if (bo)
        {
            res++;
            bo--;
        }
    }

    res += min(oa, bo);

    cout << res << endl;

    return 0;
}

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

#define fi first
#define se second
#define pb push_back

typedef long long LL;
typedef long double LD;

const LL INF = (1LL << 60);

struct Edge {
  int u, v; LL w;

  Edge(int u, int v, LL w) : u(u), v(v), w(w) {}

  // order edges by weight
  bool operator <(const Edge& x) const {
      return w < x.w;
  }
};

LL edmonds(vector<Edge>& edgeList, int n, int source);

int main() {

  ios_base::sync_with_stdio(0); cin.tie(0);

  vector<Edge> edgeList;

  int n, m, source;
  cin >> n >> m >> source;

  for (int i = 0; i < m; i++) {
    int u, v; LL w;
    cin >> u >> v >> w;

    edgeList.push_back(Edge(u, v, w));
  }

  LL result = edmonds(edgeList, n, source);

  cout << result << endl;

  return 0;
}

LL edmonds(vector<Edge>& edgeList, int n, int source) {
     
  // determine min cost of edge entering each vertex
  vector<Edge> minInEdge(n, Edge(-1, -1, INF));
  for (Edge e : edgeList) {
    minInEdge[e.v] = min(minInEdge[e.v], e);
  } minInEdge[source] = Edge(-1, source, 0);

  // assign vertices to their cyclic group
  vector<int> group(n, 0);
  vector<bool> visited(n, false), isCycleGroup(n, false); int cnt = 0;
  for (int i = 0; i < n; i++) {
    if (visited[i])
      continue;

    int node = i; vector<int> path;
    while (node != -1 && !visited[node]) {
      visited[node] = true;
      path.push_back(node);
      node = minInEdge[node].u;
    }

    bool isCycle = false;
    for (int v : path) {
      group[v] = cnt;
      if (v == node)
        isCycleGroup[cnt] = isCycle = true;
      if (!isCycle)
        cnt++;
    }

    if (isCycle)
      cnt++;
  }

  // when there are no cycles
  if (cnt == n) {
    int result = 0;
    for (Edge e : minInEdge)
      result += e.w;
    return result;
  }

  LL result = 0;
  for (Edge e : minInEdge)
    if (isCycleGroup[group[e.v]])
      result += e.w;

  // form new graph with groups
  vector<Edge> n_edgeList;
  for (Edge e : edgeList) {
    int u = group[e.u], v = group[e.v], w = e.w;
    if (u == v)
      continue;
    else
      n_edgeList.push_back(Edge(u, v, w - (isCycleGroup[v] ? minInEdge[e.v].w : 0)));
  }

  return result + edmonds(n_edgeList, cnt, group[source]);
}


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

int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(b<c||d<a) cout<<"0"<<endl;
	else
	{
		a=max(a,c);
		c=min(b,d);
		a=c-a;
		cout<<a<<endl;
	}
	return 0;
}

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

int field[128][128];
bool visited[128][128];
int w, h;
int dx[2][6] = {{-1,  0,  1, 1, 1, 0}, {-1, -1,  0, 1, 0, -1}};
int dy[6] = {0, -1, -1, 0, 1, 1};
long long ret = 0;

void rec(int y, int x)
{
	if (visited[y][x] == true){
		return;
	}
	if (y < 0 || x < 0 || h+1 < y || w+1 < x){
		return;
	}
	
	visited[y][x] = true;
	for (int i = 0; i < 6; i++){
		int ny = y + dy[i];
		int nx = x + dx[(y + 1) % 2][i];
		if (field[ny][nx] == 1){
			ret++;
		}
		else {
			rec(ny, nx);
		}
	}
	
	return;
}

int main(void)
{
	for (int i = 0; i < 128; i++){
		for (int j = 0; j < 128; j++){
			field[i][j] = 0;
			visited[i][j] = false;
		}
	}
	
	cin >> w >> h;
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++){
			cin >> field[i][j];
		}
	}
	
	rec(0, 0);
	
	cout << ret << endl;
	
	return 0;
}

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

#define ll long long
#define ull unsigned long long
#define mod 1e9+7
#define INF 1 << 30
#define MAX (1 << 20)
#define NINF (-(1 << 30))
#define Point pair<int, int>
#define triplet pair<pair<int, int>, int>

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

    string s;

    cin >> s;

    if(s[s.size() - 1] == 's') {
        s.push_back('e');
    }
    s.push_back('s');

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3664
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args)
	{
		Scanner input = new Scanner(System.in);
		String s = input.nextLine();
		if(s.equals("Sunny")) {
			System.out.println("Cloudy");
		}else if(s.equals("Cloudy")) {
			System.out.println("Rainy");
		}else if(s.equals("Rainy")) {
			System.out.println("Sunny");
		}
	}
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    if ( a > b )swap(a,b);
    if ( b > c )swap(b,c);
    if ( a > b )swap(a,b);
    cout << a <<" "<< b << " " << c << endl;
}


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

int main(void) {
	int A, B;
	scanf("%d %d", &A, &B);
	int ans = A - 2*B;
	if (ans > 0) {
		printf("%d", ans);
	} else {
		printf("%d", 0);
	}

	return 0;
}


Measured memory_bytes: 256