akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  Scanner sc;

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  class Disk {
    byte x;
    byte y;
    byte c;
    byte r;

    boolean isIn(Disk disk) {
      return (this.r + disk.r) * (this.r + disk.r) > (this.x - disk.x) * (this.x - disk.x) + (this.y - disk.y) * (this.y - disk.y);
    }
  }

  void run() {
    for (; ; ) {
      int n = ni();
      if (n == 0) {
        break;
      }
      Disk[] list = new Disk[n];
      for (int i = 0; i < n; ++i) {
        Disk d = new Disk();
        d.x = (byte) ni();
        d.y = (byte) ni();
        d.r = (byte) ni();
        d.c = (byte) ni();
        list[i] = d;
      }

      byte[] dp = new byte[1 << n];
      Arrays.fill(dp, (byte) -1);
      dp[0] = 0;
      for (int i = 0; i < 1 << n; ++i) {
        if (dp[i] < 0) {
          continue;
        }
        for (int j = 0; j < n; ++j) {
          if (((i >> j) & 1) == 1) {
            continue;
          }
          boolean flag = true;
          for (int a = 0; a < j; ++a) {
            if (((i >> a) & 1) == 1) {
              continue;
            }
            flag &= !list[j].isIn(list[a]);
          }
          if (!flag) {
            continue;
          }
          for (int k = j + 1; k < n; ++k) {
            if (((i >> k) & 1) == 1) {
              continue;
            }
            boolean glag = true;
            for (int a = 0; a < k; ++a) {
              if (((i >> a) & 1) == 1) {
                continue;
              }
              glag &= !list[k].isIn(list[a]);
            }
            if (!glag) {
              continue;
            }
            if (list[j].c != list[k].c) {
              continue;
            }

//            debug(j, k);

            dp[i | (1 << j) | (1 << k)] = (byte) Math.max(dp[i] + 1, dp[i | (1 << j) | (1 << k)]);
          }
        }
      }
      int max = 0;
      for (int i = 0; i < 1 << n; ++i) {
        max = Math.max(max, dp[i]);
      }

      System.out.println(max * 2);
    }
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 227164
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N;

int main() {

	scanf("%d", &N);

	rep(A, 9) {
		rep(B, 9) {
			if ((A + 1) * (B + 1) == N) {
				printf("Yes\n");
				return 0;
			}
		}
	}


	printf("No\n");

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int mod = 1e9 + 7;
const int IMAX = 300000;
constexpr ll modpow(ll A, ll B) {
	ll kotae = 1;
	while (B > 0) {
		if (B & 1) kotae = kotae * A % mod;
		A = A * A % mod;
		B >>= 1;
	}
	return kotae;
}
class unko {
public:
	int fac[IMAX + 1], ifac[IMAX + 1], inv[IMAX + 1];
	constexpr unko() : fac(), ifac(), inv() {
		fac[0] = 1;
		rep1(i, IMAX) fac[i] = ll(fac[i - 1]) * i % mod;
		ifac[IMAX] = modpow(fac[IMAX], mod - 2);
		for (int i = IMAX; i > 0; i--) ifac[i - 1] = ll(ifac[i]) * i % mod;
		inv[0] = 1;
		rep1(i, IMAX) inv[i] = ll(ifac[i]) * fac[i - 1] % mod;
	}
	int comb(int A, int B) {
		return ll(fac[A]) * ifac[B] % mod * ifac[A - B] % mod;
	}
} f;

const int VN = 200000;
int to[VN * 2 + 2], ne[VN * 2 + 2], he[VN + 1], num[VN * 2 + 2];
int dame[VN + 1], K[VN + 1];

ll S1[VN * 2 + 2];
int S2[VN * 2 + 2];

pair<ll, int> dfs(int v, int prev) {
	auto s1 = S1 + K[v - 1];
	auto s2 = S2 + K[v - 1];
	int en = K[v] - K[v - 1];

	//まだその頂点から探索したことが無くてデータが空っぽのとき
	if (!dame[v]) {
		dame[v] = prev;
		ll ret1 = 1;
		int ret2 = 0;
		int k = 0;
		for (int i = he[v]; i; i = ne[i]) {
			if (i != prev) {
				auto tmp = dfs(to[i], i ^ 1);
				ret1 = ret1 * f.ifac[tmp.second] % mod * tmp.first % mod;
				ret2 += tmp.second;
			}
			s1[k] = ret1;
			s2[k++] = ret2;
		}
	}

	//前回この頂点から探索した時も今回と同じ辺から来てたとき
	if (dame[v] == prev) return mp(s1[en - 1] * f.fac[s2[en - 1]] % mod, s2[en - 1] + 1);

	//まだその頂点からのデータが完璧じゃなかったとき
	if (dame[v] != -1) {
		auto tmp = dfs(to[dame[v]], dame[v] ^ 1);
		int k = en - num[dame[v]];
		ll tmp1 = f.ifac[tmp.second] * tmp.first % mod;
		for (int i = k; i < en; i++) {
			s1[i] = s1[i] * tmp1 % mod;
			s2[i] += tmp.second;
		}
		dame[v] = -1;
	}

	//例外なく全方向へのデータが欲しい時
	if (prev == -1) return mp(s1[en - 1] * f.fac[s2[en - 1]] % mod, s2[en - 1] + 1);

	//その他の時
	int k = en - num[prev];
	ll ret1 = s1[en - 1] * modpow(s1[k], mod - 2) % mod;
	if (k >= 1) ret1 = ret1 * s1[k - 1] % mod;

	int ret2 = s2[en - 1] - s2[k];
	if (k >= 1) ret2 += s2[k - 1];

	return mp(ret1 * f.fac[ret2] % mod, ret2 + 1);
}

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


	int N;
	cin >> N;
	int k = 2;
	rep1(i, N - 1) {
		int a, b;
		cin >> a >> b;

		num[k] = ++K[a];
		to[k] = b;
		ne[k] = he[a];
		he[a] = k++;
		num[k] = ++K[b];
		to[k] = a;
		ne[k] = he[b];
		he[b] = k++;
	}
	rep1(i, N) K[i] += K[i - 1];

	rep1(i, N) co(dfs(i, -1).first);

	Would you please return 0;
}

Measured memory_bytes: 14848
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#define ld long double
#define ll long long int
#define ull unsigned long long int
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const long long INF=1LL<<60;


int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int i,n,left,right;
	string s;
	cin>>s;
	for(i=0;i<s.length();i++){
		if(s[i]=='A'){
			left=i;
			break;
		}
	}
	for(i=s.length();i>=0;i--){
		if(s[i]=='Z'){
			right=i;
			break;
		}
	}
	cout<<right-left+1<<endl;
	
	return 0;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    double tmp = 0;
    rep(i, 0, n) {
        double a;
        cin >> a;
        tmp += (double)(1 / a);
    }
    cout << fixed;
    cout << setprecision(10) << (double)(1 / tmp)<< endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

	vll v(3);
	cin >> v[0] >> v[1] >> v[2];
	sort(all(v));
	ll ans = 0;
	while (v[1] < v[2]) {
		v[0]++;
		v[1]++;
		ans++;
	}
	while (v[0] < v[1]) {
		v[0] += 2;
		ans++;
	}
	if (v[0] > v[1]) ans++;
	cout << ans << endl;
}


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

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using int128 = __int128;
using cint = cpp_int;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ull MAX = ULONG_MAX;
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define each(i, a) for (auto &&i : a)
#define rep(i, n) inc(i, 0, n - 1)

// Stream
#define input(a) scanf("%lld", &(a))
#define output(a) printf("%lld\n", (a))
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

// Math
func gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
func lcm(ll a, ll b) { return a * b / gcd(a, b); }


ll N, not_prime[55548];
signed main() {
    not_prime[1] = 0;
    inc(i, 2, 55547) {
        if(not_prime[i] == 0) {
            for(ll p = 2; p * i < 55548; p++) {
                not_prime[p * i] = 1;
            }
        }
    }
    cin >> N;
    ll i = 31;
    cout << 11;
    while(N - 1) {
        if(!not_prime[i]) {
            cout << ' ' << i;
            N--;
        }
        i += 5;
    }
    cout << endl;
}

// for compilation: g++ -O3 -o _ _.cpp -std=c++17

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <cmath>
#include <bitset>
#include <random>
#include <regex>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;


signed main(void){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int x, y, z;
    cin >> x >> y >> z;

    cout << z << ' ' << x << ' ' << y << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll mod = 1e9 + 7;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> to[100005];
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  queue<int> q;
  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  dist[0] = 0;
  q.push(0);
  while (!q.empty()) {
    int v = q.front(); q.pop();
    for (int u : to[v]) {
      if (dist[u] != INF) continue;
      dist[u] = dist[v] + 1;
      pre[u] = v;
      q.push(u);
    }
  }

  cout << "Yes" << endl;
  rep(i,n) {
    if (i == 0) continue;
    int ans = pre[i];
    ++ans;
    cout << ans << endl;
  }
  return 0;
}


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

int main(){
  int A,B,C,D,t,a;
  cin >> A >> B >> C >> D;
  t=A/D;
  a=C/B;
  if(A%D!=0){
    t++;
  }
  if(C%B!=0){
    a++;
  }
  if(t<a){
    cout << "No";
  }else{
    cout << "Yes";
  }
  cout << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
int n,a[222222],flag[1111111],flag2[222222],ans;
signed main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	sort(a,a+n);
	rep(i,n-1){
		if(a[i]==a[i+1]){
			flag2[i]=1;
			flag2[i+1]=1;
		}
	}
	rep(i,n){
		if(!flag[a[i]] && !flag2[i])ans++;
		for(int j=a[i];j<=a[n-1];j+=a[i]){
			flag[j]=1;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 14580
#include <stdio.h>
#include <algorithm>

using namespace std;

struct so {
	int a , b , i;
} s[120000];
int n;
int a[120000];
int vis[120000] , cnt;
bool cmp ( so x1 , so x2 ) {
	return x1.b < x2.b;
}
bool cmp2 ( so x1 , so x2 ) {
	return x1.a < x2.a;
}
void work () {
	int i;
	scanf ( "%d" , &n );
	for ( i = 1 ; i <= n ; i++ ) {
		scanf ( "%d" , &s[i].a );
		a[i] = s[i].a;
	}
	for ( i = 1 ; i <= n ; i++ ) {
		scanf ( "%d" , &s[i].b );
	}
	sort ( s + 1 , s + 1 + n , cmp );
	sort ( a + 1 , a + 1 + n );
	for ( i = 1 ; i <= n ; i++ ) {
		//printf ( "%d %d\n" , a[i] , s[i].b );
		if ( a[i] > s[i].b ) {
			printf ( "No\n" );
			return ;
		}
	}
	for ( i = 1 ; i < n ; i++ ) {
		if ( a[i+1] <= s[i].b ) {
			printf ( "Yes\n" );
			return ;
		}
	}
	for ( i = 1 ; i <= n ; i++ ) {
		s[i].i = i;
	}
	sort ( s + 1 , s + 1 + n , cmp2 );
	cnt = 0;
	for ( i = 1 ; !vis[i] ; i = s[i].i ) {
		vis[i] = 1;
		cnt++;
	}
	if ( cnt != n ) printf ( "Yes\n" );
	else printf ( "No\n");
}
int main () {
	work ();
	return 0;
}


Measured memory_bytes: 2048
import sys


t = input()
answerCount = 0
stringList = []
while True:
    line = input()
    if line == "END_OF_TEXT":
        break
    for i in range(len(str(line).lower().split())):
        stringList.append(str(line).lower().split()[i])

        if str(line).lower().split()[i] == t:
            answerCount += 1



print(answerCount)


Measured memory_bytes: 5564
#![allow(unused)]

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        n: u64,
        m: u64,
    }

    let r = if n == 0 { 0 } else { n * (n - 1) / 2 };
    let l = if m == 0 { 0 } else { m * (m - 1) / 2 };

    println!("{}", r + l);
}


Measured memory_bytes: 4352
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int w = scan.nextInt(), h = scan.nextInt();

		while (w != 0 || h != 0){
			int grid[][] = new int[h + 2][w + 2];
			int count = 0;

			for (int i = 0; i < h + 2; i++){
				for (int j = 0; j < w + 2; j++){
					if (i == 0 || i == h + 1 || j == 0 || j == w + 1){
						grid[i][j] = -1;
					} else {
						grid[i][j] = scan.nextInt();
					}
				}
			}


			for (int i = 1; i <= h; i++){
				for (int j = 1; j <= w; j++){
					if (grid[i][j] == 1){
						search(grid, i, j);
						count++;
					}
				}
			}

			System.out.println(count);

			w = scan.nextInt();
			h = scan.nextInt();
		}
	}

	public static void search(int[][] grid, int i, int j) {
		grid[i][j] = -1;

		if (grid[i + 1][j] == 1){
			search(grid, i + 1, j);
		}
		if (grid[i - 1][j] == 1){
			search(grid, i - 1, j);
		}
		if (grid[i][j + 1] == 1){
			search(grid, i, j + 1);
		}
		if (grid[i][j - 1] == 1){
			search(grid, i, j - 1);
		}
		if (grid[i + 1][j + 1] == 1){
			search(grid, i + 1, j + 1);
		}
		if (grid[i - 1][j + 1] == 1){
			search(grid, i - 1, j + 1);
		}
		if (grid[i + 1][j - 1] == 1){
			search(grid, i + 1, j - 1);
		}
		if (grid[i - 1][j - 1] == 1){
			search(grid, i - 1, j - 1);
		}
	}
}

Measured memory_bytes: 46100
//
// Created by kash on 16/05/20.
//

#include <bits/stdc++.h>

using namespace std;
#define mod 1e9+7
#define ll long long
#define rev_rep(it, last, first) for(int it=last-1;it>=first;--it)
#define out(x) cout << x;
#define pln(x) cout << x << "\n";
#define debug(x) cout << "Debug: " << x << "\n";
#define in(x) cin >> x;
#define rep(it, start, end) for(int it=start;it<end;++it)
#define x first
#define y second


void set_io(int inp) {
#ifndef ONLINE_JUDGE
    string folder = string(getenv("HOME")) + "/CLionProjects/CompetitiveProgramming/inputs/";
    string input_file = folder + "input-" + to_string(inp) + ".txt";
    string output_file = folder + "output-" + to_string(inp) + ".txt";
    freopen(input_file.c_str(), "r", stdin);
    freopen(output_file.c_str(), "w", stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

}


int main() {
    set_io(1);
    int n;
    in(n);
    int arr[n];
    rep(i, 0, n)in(arr[i]);
    ll sol = 0;
    sort(arr, arr+n);
    priority_queue<int> pq;
    pq.push(arr[n-1]);
    rev_rep(i, n-1, 0){
        sol+=pq.top();
        pq.pop();
        pq.push(arr[i]);
        pq.push(arr[i]);
    }
    out(sol);

    return 0;
}


Measured memory_bytes: 5068
#include<stdio.h>


int main(){
  int i;
  int j = 0;
  scanf("%d",&i);
  // printf("%dツ嘉アツ禿シツ療債つオツづつュツつセツつウツつ「\n",i);
   while(j < i){
    int x,y,z;
    scanf("%d",&x);
    scanf(" %d",&y);
    scanf(" %d/n",&z);
    int X = x * x;
    int Y = y * y;
    int Z = z * z;
    if(X == 0 || Y == 0 || Z == 0){
      printf("NO\n");
    }else if(X == Y + Z){
      printf("YES\n");
    }else if(Y == X + Z){
      printf("YES\n");
    }else if(Z == X + Y){
      printf("YES\n");
    }else{
      printf("NO\n");
    }
    j++;
    // printf("%d %d %d\n",x,y,z);
   }
  return 0;
}

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

int main() {
  int x,a,b,A,B;
  cin >> x >> a >> b;
  A = max(a-x,x-a);
  B = max(b-x,x-b);
  if(A>B){
    cout << 'B' << endl;
  }
  else {
    cout << 'A' << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
#define ll long long

int main(){
  ll H, W, K;
  cin >> H >> W >> K;
  
  vector<ll> row(W, 0);
  vector<vector<ll>> S(H, row);
  for(ll h=0; h<H; ++h) {
    string s;
    cin >> s;
    for(ll w=0; w<W; ++w) S[h][w] = (s[w]=='1' ? 1 : 0);
  }
  
  //for(ll h=0; h<H; ++h){ for(ll w=0; w<W; ++w) cout << S[h][w]; cout<<endl;}
  
  ll ans = 10000000;
  vector<ll> tgt(H, 0);
  for(ll c=0; c<(1<<H-1); ++c) {
    //cout << c << endl;
    
    ll ncut=0;
    ll t=0;
    for(ll h=0; h<H-1; ++h) {
      if((c>>h)&1){ t=h+1; ++ncut; }
      tgt[h+1]=t;
    }
    
    //for(ll i=0; i<H; ++i) cout << tgt[i];
    //cout<<endl;
    
    vector<ll> sum(H, 0);
    bool skip=false;
    for(ll w=0; w<W && !skip; ++w){
      vector<ll> add(H, 0);
      for(ll h=0; h<H; ++h) add[tgt[h]] += S[h][w];
      
      bool cut = false;
      for(ll h=0; h<H; ++h) {
      	if(add[h]>K){ skip=true; break; }
        else if(sum[h]+add[h]>K){ cut=true; break; }
      }
      
      if(cut){
        //cout << "cut:" << w << endl;
        ++ncut;
        for(ll h=0; h<H; ++h) sum[h]= add[h];
      }else{
        for(ll h=0; h<H; ++h) sum[h]+=add[h];
      }
      
    }
    
    if(!skip) { ans = min(ans, ncut); }
    //cout << skip << ":" << ncut << endl;
    
    //cout << endl;
  }
  
  cout << ans << endl;
  
  return 0; 
}

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

int main() {
    int n;
    cin >> n;
    int min_count = 0;
    for (int i=0; i<n; i++) {
        int count = 0;
        int a;
        cin >> a;
        while (a % 2 ==0) {
            a /= 2;
            count++;
        }
        if (count <= min_count || i == 0) {
            min_count = count;
        }
    }
    cout << min_count;
}

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

int main()
{
	int n = 0, x = 0;

	cin >> n;

	for (int i = 1; i <= n; i++) {
		if ((i % 3) == 0)
			cout << " " << i;
		else {
			x = i;
			while (x) {
				if ((x % 10) == 3) {
					cout << " " << i;
					break;
				}
				x /= 10;
			}
		}
	}

	cout << endl;

    return 0;
}

Measured memory_bytes: 3088
#include<iostream>
#include<string>
using namespace std;
int main() {
  	string s; cin >> s;
  	if (s.size() % 2 != 0) {
    	cout << "No";
      	return 0;
    }
  	char curr = 'h';
  	for (int i = 0; i < s.size(); i ++) {
    	if (s[i] != curr) {
        	cout << "No";
          	return 0;
        }
      	if (i == 0 || i % 2 == 0) curr = 'i';
      	else curr = 'h';
    }
  	cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

K=gets.to_i
A=get_i.reverse
if A[0]!=2
    puts "-1"
    exit
elsif K==1 and A[0]==2
    puts "2 3"
    exit
end
min=2
1.upto(K-1) do|i|
  if A[i]<min
      min=((min+A[i]-1)/A[i])*A[i]
  else
      min=A[i]
  end
end
max=2
1.upto(K-1) do|i|
   if A[i]>max
    max=A[i]*2-1
   else
    max=(max/A[i])*A[i]+A[i]-1
   end
end
v1=min
v2=max
A.reverse.each do|a|
  v1=(v1/a)*a
  v2=(v2/a)*a
end
if v1!=2 or v2!=2
    puts "-1"
else
  puts [min,max].join(" ")
end

Measured memory_bytes: 23080
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);


    static long n;
    static long m;


    public static void main(String[] args) {
        n = sc.nextLong();
        m = sc.nextLong();

        long result = solve(n, m);
        System.out.println(result);
    }

    private static long solve(long n, long m) {
        long num = m / n;
        while (num > 0) {
            if (m % num == 0 && m / num >= n) {
                return num;
            }
            num--;
        }
        return 0;
    }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define int long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;

bool matrix[200][200];
int n;

int colour[200];
vector<int> cmp;

void dfs(int vertex, int c){
	colour[vertex] = c;
	cmp.push_back(vertex);
	for (int to=0;to<n;++to){
		if (!matrix[vertex][to]) continue;
		if (colour[to] == -1){
			dfs(to, 1-c);
		}
		if (colour[to] == c){
			cout << -1;
			exit(0);
		}
		continue;
	}
}

/*

void bfs(int vertex){
	vector<int> d(n, 1e9);
	d[vertex] = 0;
	queue<int> q;
	q.push(vertex);
	while (q.size()){
		int V = q.pop();
		q.front();
		if (d[V] != 1 && matrix[V][vertex]) return (d[V]+1)/2;
		for (int i=0; i < n; ++i){
			if (!matrix[vertex][i]) continue;
			if (d[i] <= d[vertex]+1) continue;
			d[i] = d[vertex]+1;
			q.push(i);
		}
	}

	return -1;




}

*/

int f[200][200];

main(){
#ifdef LOCAL
	freopen("A_input.txt", "r", stdin);
	//freopen("A_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin >> n;
	for (int i=0;i<n;++i) for (int j=0;j<n;++j){
		char ch;
		cin >> ch;
		if (ch=='1'){
			matrix[i][j] = true;
			f[i][j] = 1;
		}
		else if (i != j){
			f[i][j] = 1e9;
		}
	}

	int ans=0;

	for (int i=0;i<n;++i) colour[i] = -1;

	for (int k=0; k<n; ++k)
	for (int i=0; i<n; ++i)
		for (int j=0; j<n; ++j)
			f[i][j] = min (f[i][j], f[i][k] + f[k][j]);



	for (int i=0;i<n;++i){
		if (colour[i] != -1) continue;
		cmp.clear();
		dfs(i, 0);
		int tut = 0;
		for (int j=0; j < cmp.size(); ++j) for (int e=0; e < cmp.size(); ++e){
			tut = max(tut, f[cmp[j]][cmp[e]]);
		}
		ans += tut+1;
	}

	cout << ans;
	

}


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

int main(){
    int q;
    cin>>q;
    string s1,s2;
    
    rep(i,q){
        cin>>s1>>s2;
        vector< vector< int > > c(1010, vector< int >(1010, 0));
        c[0][0]=0;
        rep(j,s1.length()+1)c[j][0]=0;
        rep(k,s2.length()+1)c[0][k]=0;
        for(int n=1;n<=s1.length();n++){
            for(int m=1;m<=s2.length();m++){
                if(s1[n-1]==s2[m-1])c[n][m]=c[n-1][m-1]+1;
                else {
                    c[n][m]=max(c[n-1][m],c[n][m-1]);
                }
            }
        }
        cout<<c[s1.length()][s2.length()]<<endl;
    }
}


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

typedef long long ll;
typedef tuple<ll, ll, ll> mytuple;
const ll INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589793238;

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) { if (b == 0) {return a;} else {return GCD(b, a % b);} }
// a と b の最小公倍数を返す関数
long long LCM(long long a, long long b) { return a/GCD(a,b)*b; }

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

int main() {
  int64_t X; cin >> X;

  int64_t m = 100;
  int cnt = 0;
  while(X > m) {
    m *= 1.01;
    cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define INF 2000000000
#define int long long int
#define MOD 1000000007
#define pb push_back
#define cin1(n) (cin >> n)
#define cin2(a,b) (cin >> a >> b)
#define cin3(a,b,c) (cin >> a >> b >> c)
#define cout(n) (cout << n << endl)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define fr first 
#define sc second 
#define EPS (1e-10)

using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<pair<int,int>> vpii;
typedef vector<string> vs;
typedef vector<vector<string>> vss;
typedef pair<int,int> pii;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int n,m;
int a,b;
int p,q;


signed main() {
	int M,N; cin2(N,M);

	vi trg(M,0);
	rep(i,0,M) {
		cin1(trg[i]);
	}

	vi P(N,0);
	rep(i,0,M) {
		rep(j,0,N) {
			cin1(a);
			if (a == trg[i]) {
				P[j]++;
			}else {
				P[trg[i]-1]++;
			}
		}
	}

	rep(i,0,N) {
		cout(P[i]);
	}

	return 0;
}

Measured memory_bytes: 3124
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  string s,t;
  int ans=0;
  cin >> s;
  for(int i=0; i>s.size(); i++) {
      if(s[i]>='A'&&s[i]<='Z') {
        s[i]=s[i]+'a'-'A';  
      }
  }
  while(cin >> t, t!="END_OF_TEXT") {
      for(int i=0; i<t.size(); i++) {
          if(t[i]>='A'&&t[i]<='Z') {
              t[i]=t[i]+'a'-'A';
          }
      }
      if(s==t) {
          ans++;
      }
  }
  cout << ans << endl;
}


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

#define F(i, a, b) for(int i=a; i<b; i++)
#define mem(arr, val) memset(arr, val, sizeof(arr))
#define rev(str) reverse(str.begin(), str.end())
#define UPPER(str) transform(str.begin(), str.end(), str.begin(), ::toupper)
#define LOWER(str) transform(str.begin(), str.end(), str.begin(), ::tolower)

#define MOD 1000000007
#define INF 1000000000000001
#define epsilon 1e-15

typedef long long int ll;
typedef unsigned long long int ull;

const int MAX = 100;

int gcd(int a, int b){
	if(b==0) return a;

	return gcd(b, a%b);
}



int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int N;
    cin >> N;
    string S;
    cin >> S;

    int white[N+1];
    white[0] = 0;
    for(int i=1; i<=N; i++){
    	if(S[i-1]=='W') white[i] = white[i-1] + 1;
    	else white[i] = white[i-1];
    }

    int ans = INT_MAX;

    for(int r=0; r<=N; r++){
    	ans = min(ans, max(white[r], N - r - (white[N] - white[r])));
    }

    cout << ans ;

    return 0;
   
}

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

typedef long long ll;
ll k, a = 1;

ll f(ll p) {
	ll re = 0;
	while (p) {
		re += p % 10;
		p /= 10;
	}
	return re;
}

int main()
{
	ll i = 1, t;
	cin >> k;
	while (k--) {
		t = i + a;
        if (t * f(i) < i * f(t)) i -= a, a *= 10, i += a;
		printf("%lld\n", i);
		i += a;
	}
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <numeric>
#include <complex>

using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const int INF = (1<<30);
const ll INFL = (1LL<<62);
const ll MOD = 1000000007;
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<class T> ll mod_pow(ll a, ll n, T mod) { mod=(ll)mod; ll res=1, p=a%mod; while(n){ if(n&1) res=res*p%mod; p=p*p%mod; n>>=1; } return res; }
template<int mod>
struct ModInt {
    using ll = long long; ll x;
    ModInt() : x(0) {}
    ModInt(int y) : x(y >= 0 ? ll(y % mod) : (ll)((mod - (-y) % mod))) {}
    ModInt(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod)) {}
    ModInt &operator+=(const ModInt &rhs) { if((x += rhs.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &rhs) { if((x += mod - rhs.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &rhs) { x = x * rhs.x % mod; return *this; }
    ModInt &operator/=(const ModInt &rhs) { *this *= rhs.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(const ModInt &rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(const ModInt &rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(const ModInt &rhs) const { return ModInt(*this) /= rhs; }
    ModInt operator==(const ModInt &rhs) const { return x == rhs.x; }
    ModInt operator!=(const ModInt &rhs) const { return x != rhs.x; }
    friend ostream &operator<<(ostream &os, const ModInt &rhs) { return os << rhs.x; }
    friend istream &operator>>(istream &is, ModInt &rhs) { ll t; is >> t; rhs = ModInt<mod> (t); return (is); }
private:
    ModInt inverse() const { ll a = x, u = 1LL, v = 0LL, t, b = (ll)mod; while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); } return  ModInt(u); }
};
using mint = ModInt<MOD>;

int main() {
    int N, Q;
    string S;
    cin >> N >> Q >> S;
    vector<int> sum(N+1, 0);
    rep(i, N){
        sum[i+1] = sum[i];
        if(S[i]=='A' && S[i+1] == 'C') sum[i+1] += 1;
    }
    // rep(i, N+1) cout << i << " ";
    // cout << "\n";
    // rep(i, N+1) cout << sum[i] << " ";
    // cout << "\n";
    while(Q--){
        int l, r;
        cin >> l >> r;
        l--, r--;
        cout << sum[r] - sum[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
p=list(map(int,input().split()))

ans=0
for i in range(2**n):
  num=0
  #ある電球
  for j in range(m):
    cnt=0
    #ある電球に接続されている各スイッチ
    for k in range(1,l[j][0]+1):
      if (i>>l[j][k]-1) & 1:
        cnt+=1
    if cnt%2==p[j]:
      num+=1
  if num==m:
    ans+=1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

int main() {
  string num;
  cin >> num;
  rep (i,3) {
    if(num.at(i) == '1') num.at(i)='9';
    else if (num.at(i) == '9') num.at(i)='1';
  }
  cout << num << endl;
  return 0;
}

Measured memory_bytes: 256
from math import cos
from math import pi

A, B, H, M = [int(i) for i in input().split()]

H_R = (H * 60 + M) / 720 * (pi * 2)
M_R = M / 60 * (pi * 2)

ans = (A ** 2 + B ** 2 - 2 * A * B * cos(H_R - M_R)) ** 0.5

print(ans)

Measured memory_bytes: 9488
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = 3.141592653589;
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}

signed main(){
    cout << fixed << setprecision(10);
    string s,t;
    cin >> s;
    if( s == "ABC")cout << "ARC";
    else cout << "ABC";
    return 0;
}

Measured memory_bytes: 3628
KN = list(map(int, input().split()))
K, N = KN[0], KN[1]
A = list(map(int, input().split()))

L = [K-A[N-1]+A[0]]
for i in range(N-1):
    L.append(A[i+1]-A[i])

print(K-max(L))


Measured memory_bytes: 26444
#include <iostream>
#include <stdio.h>
#include<string>
using namespace std;
int main(void) {
  int a,b,c;
  char op;
  //input

  while(true){
    cin >> a >> op >> b;

    if (op == '?'){
      break;
    }
    if (op == '+'){
      c = a + b;
    }else if (op == '-'){
      c = a - b;
    }else if (op == '*'){
      c = a * b;
    }else if (op == '/'){
      c = a / b;
    }
    cout << c << endl;
  }

  return 0;
}



Measured memory_bytes: 3104
a,b = map(int,input().split())
#lis = list(map(int,input().split()))
count = 0
if a>b:
    count += a
    a -= 1
else:
    count += b
    b -= 1
if a>b:
    count += a
    a -= 1
else:
    count += b
    b -= 1
print(count)

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

using namespace std;

int main(){
    int h,w,i,j,k;
    vector<int> vx,vy;
    while(1){
        cin>>h>>w;
        if(h==0 && w==0){
            break;
        }
        else{
            vx.push_back(h);
            vy.push_back(w);
        }
    }
    for(k=0; k<vx.size(); k++){
        for(i=0; i<vx[k]; i++){
            for(j=0; j<vy[k]; j++){
                cout<<"#";
            }
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 3068
#include<iostream>
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>

using namespace std;

class Counting {
	unsigned long long p, n;
	vector<long long> invMemo, facMemo, facInvMemo;
public:
	Counting(unsigned long long nn, unsigned long long np) {
		p = np;
		n = nn;
		invMemo.resize(n + 1);
		facMemo.resize(n + 1);
		facInvMemo.resize(n + 1);
		facMemo[0] = 1;
		facMemo[1] = 1;
		facInvMemo[0] = 1;
		facInvMemo[1] = 1;
		invMemo[0] = 0;
		invMemo[1] = 1;
		for (unsigned long long i = 2; i <= n; i++) {
			invMemo[i] = p - (p / i)*invMemo[p%i] % p;
			facMemo[i] = (facMemo[i - 1] * i) % p;
			facInvMemo[i] = (facInvMemo[i - 1] * invMemo[i]) % p;
		}
	}
	unsigned long long fac(unsigned long long k) {
		return facMemo[k];
	}
	unsigned long long facInv(unsigned long long k) {
		return facInvMemo[k];
	}
	unsigned long long choose(unsigned long long n, unsigned long long k) {
		if (!(0 <= k && k <= n))
			return 0;
		return (((facMemo[n] * facInvMemo[k]) % p)*facMemo[n - k]) % p;
	}
	unsigned long long divide(unsigned long long a, unsigned long long b) {
		return (a * invMemo[b]) % p;
	}
	unsigned long long mod(unsigned long long a) {
		a %= p;
		if (a < 0) a += p;
		return a;
	}
	unsigned long long power(unsigned long long a, unsigned long long e) {
		unsigned long long ans = 1;
		for (; e > 0; e /= 2) {
			if (e % 2 != 0)
				ans = ans * a % p;
			a = a*a%p;
		}
		return ans;
	}
};

int main() {
	long long n, m, ans = 0;
	cin >> n >> m;
	if (n * 2 < m) {
		m -= n * 2;
		ans = n;
		ans += m / 4;
	}
	else {
		ans = m / 2;
	}
	cout << ans << endl;
//	cin >> n;
	return 0;
}

Measured memory_bytes: 768
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>

using namespace std;

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

vector<string> split(string delim,string str){
	vector<string> res;
	str += delim;
	for(int i=0;i<str.size();i++){
		for(int j=1;i+j<=str.size();j++){
			if(str.substr(i,j).find_first_of(delim) != string::npos){
				//cout << str.substr(i,j) << endl;
				if(str.substr(i,j-1).size() > 0 ){
					//int num;
					//sscanf(str.substr(i,j-1).c_str(),"%d",&num);
					//res.push_back(num);
					res.push_back(str.substr(i,j-1));

				}
				i+=j-1;
				break;
			}
		}
	}

	return res;
}

string calc(string a,string b){
	string res;
	reverse(a.begin(),a.end());
	reverse(b.begin(),b.end());
	int carry = 0;
	int idx;
	for(int j=0;j<min(a.size(),b.size());j++){
		int lhs = a[j] - '0';
		int rhs = b[j] - '0';
		res.push_back((carry + lhs + rhs) % 10 + '0');
		carry = (carry + lhs + rhs) / 10 ? 1 : 0;
		idx =j;
	}

	for(int j=idx+1;j<max(a.size(),b.size());j++){
		if(a.size() > b.size()){
			int lhs = a[j] - '0';
			res.push_back((carry + lhs) % 10 + '0');
			carry = (carry + lhs) / 10 ? 1 : 0;
		}
		else{
			int rhs = b[j] - '0';
			res.push_back((carry + rhs) % 10 + '0');
			carry = (carry + rhs) / 10 ? 1 : 0;
		}
	}
	if(carry) res.push_back(carry+'0');
	reverse(res.begin(),res.end());

	return res;
}

int main(){
	string str;
	while(getline(cin,str)){
		vector<string> data = split("+=",str);

		for(int i=0;i<=9;i++){
			vector<string> tmp = data;
			for(int j=0;j<3;j++){
				replace(tmp[j].begin(),tmp[j].end(),'X',(char)('0'+i));
			}

			if(calc(tmp[0],tmp[1]) == tmp[2]){
				cout << i << endl;
				goto next;
			}
		}
		cout << "NA" << endl;
next:;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n; cin>>n;
    if(n<=9) {cout<<n<<endl; return 0;}
    if(n==10||n==100||n==1000||n==10000||n==100000){
        cout<<10<<endl; return 0;
    }
    int digsum=0;
    while(n!=0){
        digsum+=n%10;
        n/=10;
    }
    cout<<digsum<<endl;
}

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

using namespace std;

int main() {
	vector <int> list;
	int swaps = 0;
	int size = 0;
	int num = 0;

	scanf("%d", &size);
	for (int i = 0; i < size; i++) {
		scanf("%d", &num);
		list.push_back(num);
	}
	size = size-1;
	for (int i = 0; i <= size; i++) {
		for (int j = size; j > i; j--) {
			if (list[j] < list[j-1]) {
				num = list[j];
				list[j] = list[j-1];
				list[j-1] = num;
				swaps++;
			}
		}
	}
	for (int i = 0; i < size; i++) {
		printf("%d ", list[i]);
	}
	printf("%d\n%d\n", list.back(), swaps);
}



Measured memory_bytes: 2776
#include <algorithm>
#include<cfenv>
#include <cmath>
#include <complex>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <list>
#include <map>
#include<numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>
#define itn int
#define retrun return
using namespace std;
typedef long long llong;
vector<llong> AllDivisors(llong N) {
	vector<llong> ANS;
	for (llong i = 1; i * i <= N; i++) {
		if (N % i == 0) {
			ANS.push_back(i);
			if (N / i != i)ANS.push_back(N / i);
		}
	}
	sort(ANS.begin(), ANS.end());
	return ANS;
}
bool IsPrime(llong N) {
	for (llong i = 2; i * i <= N; i++) {
		if (N % i == 0) return false;
	}
	return true;
}
//ここまで共通
int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	while (A > 0 && C > 0) {
		C -= B;
		if (!(A > 0 && C > 0)) {
			break;
		}
		A -= D;
	}
	if (A <= 0) {
		cout << "No";
	}
	else {
		cout << "Yes";
	}
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct Node{
  int key;
  struct Node *right,*left,*parent;
};

typedef struct Node node;

node *NIL;
node *root;

void insert(int k);
void inorder(node *p);
void preorder(node *p);
node * find(node *p,int k);



int main(void)
{
  int m,k;
  int i;
  char com[100];

  scanf("%d",&m);

  for(i = 0;i < m;i++){
    scanf("%s",com);

    if(com[0] == 'f'){
      scanf("%d",&k);
      node *n = find(root,k);
      if(n == NIL){
	puts("no");
      } else {
	puts("yes");
      }
      
    } else if(strcmp(com,"insert") == 0){
      scanf("%d",&k);
      insert(k);
      
    } else if(strcmp(com,"print") == 0){
      inorder(root);
      puts("");
      preorder(root);
      puts("");
    }
  }
  return 0;
}



node * find(node *p,int k){
  while(p != NIL && k != p->key){
    p = (p->key  >  k) ? p->left : p->right;
  }

  return p;
}





void insert(int k){
  node *x = root;
  node *y = NIL;
  node *z;

  z = (node *)malloc(sizeof(node));
  
  z->left = NIL;
  z->right = NIL;
  z->key = k;

  while(x != NIL){
    y = x;
    
    if(z->key  <   x->key){
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;

  if(y == NIL){
    root = z;
  }
  if (y != NIL){
    if(y->key  >  z->key){
      y->left = z;
    } else {
      y->right = z;
    }
  }
  
}


void inorder(node *p){
  if(p != NIL){
    inorder(p->left);
    printf(" %d",p->key);
    inorder(p->right);
  } else {
    return;
  }
}


void preorder(node *p){
  if(p != NIL){
    printf(" %d",p->key);
    preorder(p->left);
    preorder(p->right);
  } else {
    return;
  }
}


   




Measured memory_bytes: 20440
#include <stdio.h>
#include <string.h>

const int PMAX = 180;
const int OMAX = 45;

#define MAX 1000000
int tp[MAX];
int to[MAX];

int main(void)
{
    int i, j, n;
    int p[PMAX], o[OMAX];

    for (i = j = 1; (n = i * (i + 1) * (i + 2) / 6) < MAX; ++i) {
        p[i] = n;
        if (n % 2 == 1)
            o[j++] = n;
    }

    memset(tp, MAX, sizeof(tp));
    memset(to, MAX, sizeof(to));
    tp[0] = to[0] = 0;
    for (i = 0; i < MAX; ++i)
        for (j = 1; j < PMAX; ++j)
            if (i + p[j] < MAX && tp[i + p[j]] > tp[i] + 1)
                tp[i + p[j]] = tp[i] + 1;
    for (i = 0; i < MAX; ++i)
        for (j = 1; j < OMAX; ++j)
            if (i + o[j] < MAX && to[i + o[j]] > to[i] + 1)
                to[i + o[j]] = to[i] + 1;

    for (;;) {
        int n;

        scanf("%d", &n);
        if (n == 0)
            break;

        printf("%d %d\n", tp[n], to[n]);
    }

    return 0;
}

Measured memory_bytes: 8416
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val S = in.tail.head
  //val N = S.size
  val al = ('a' to 'z').map(_ => 0).toArray
  S.foreach(c => al(c - 'a') += 1)
  /*
  private def func(ex:Char):Long = {
	val excnt = S.count(_ != ex)
    //TODO mod
    Math.pow(2, excnt).toLong - 1
  }
  */
  val ret = (0 to ('z' - 'a')).foldLeft(1L){ (a,e) =>
    if(al(e) < 1) a else {
      a * (al(e) + 1) % 1000000007
    }
  }
  println(ret - 1)
}


Measured memory_bytes: 27324