akhauriyash/Code-Regression huggingface dataset:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>


int main()
{
  int A, B, C, K;
  scanf("%d %d %d %d", &A, &B, &C, &K);

  int sum = 0;
  
  int A1=A-K;
  if (A1<0)A1=0;
  K-=A;
  if (K<0)K=0;

  int B1=B-K;

  if (B1<0)B1=0;
  K-=B;
  if (K<0)K=0;

  int C1=C-K;

  if (C1<0)C1=0;
  K-=B;
  if (K<0)K=0;

  if (A1 != A)sum+=abs(A1-A);
  if (C1 != C)sum+=abs(C1-C)*-1;

  printf("%d",sum);   

  return 0;
}


Measured memory_bytes: 1724
# ####################################################################
# import io
# import sys

# _INPUT = """\
# 5
# 86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
# 19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
# 6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
# 6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
# 8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
# 19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192
# 1
# 17
# 13
# 14
# 13
# """
# sys.stdin = io.StringIO(_INPUT)
# ####################################################################
D = int(input())
C = [int(i) for i in input().split()]

SS = [[int(i) for i in input().split()] for _ in range(D)]
T = [int(input()) for _ in range(D)]

L = [0]*26

v = 0
for d, t in enumerate(T):
  t -= 1
  L[t] = d+1

  v += SS[d][t]
  for c, l in zip(C, L):
    v -= c * (d+1 - l)
  # v += C[t]

  print(v)







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

vector<vector<pair<int, int>>> to;
vector<int> ans;

void dfs(int P, int C, int parent){
  int c = 1;
  for (auto i: to[P]){
    if (i.first == parent) continue;
    if (c == C) c++;
    ans[i.second] = c;
    dfs(i.first, c, P);
    c++;
  }
}

int main(){
  int n; cin >> n;
  to.resize(n);
  ans.resize(n-1);
  rep(i,n-1){
    int a, b; cin >> a >> b;
    a--; b--;
    to[a].push_back(make_pair(b,i));
    to[b].push_back(make_pair(a,i));
  }
  int K = 0;
  rep(i,n){
    K = max(K, (int)to[i].size());
  }
  cout << K << endl;

  dfs(0,0,-1);
  rep(i, n-1){
    printf("%d\n", ans[i]);
  }
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> A(N + 1);
	for (int i = 0; i < N + 1; ++i) { cin >> A[i]; }
	vector<int> B(N);
	for (int i = 0; i < N; ++i) { cin >> B[i]; }

	Int res = 0;
	for (int i = 0; i < N; ++i) {
		int x = min(A[i], B[i]);
		res += x;
		B[i] -= x;
		x = min(A[i + 1], B[i]);
		res += x;
		A[i + 1] -= x;
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
#define out(a) printf("%d",a)
using namespace std;
int n;
char c1,c2,c3;
int read()
{
	int s=0,t=1; char c;
	while (c<'0'||c>'9') {if (c=='-') t=-1; c=getchar();}
	while (c>='0'&&c<='9') {s=s*10+c-'0'; c=getchar();}
	return s*t;
}
int main()
{
	c1=getchar();c3=getchar(); c2=getchar();
	if (c1-'A'>c2-'A') puts(">");
	if (c1==c2) puts("=");
	if (c1-'A'<c2-'A') puts("<");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

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

int main() {
    ll n;
    cin >> n;
    vector<ll> A(n);
    rep(i, n) cin >> A[i];
    vector<ll> B(n + 1, 0);
    rrep(i, n) {
        B[i] += B[i - 1] + A[i - 1];
    }
    ll ans = LINF;

    rrep(i, n - 1) {
        ll cnt = abs(2 * B[i] - B[n]);
        ans = min(ans, cnt);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N,K,S;
  cin>>N>>K>>S;
  for(int X=0;X<K;X++){
    if(X==K-1){
      cout<<S<<endl;
    }
    else{
      cout<<S<<" ";
    }
  }
  for(int X=K;X<N;X++){
    if(X==N-1){
      cout<<94541<<endl;
    }
    else{
      cout<<87693<<" ";
    }
  }
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


int main() {
  auto st = clock();
  int N;
  cin >> N;
  auto A = make_v< int >(N, N - 1);
  cin >> A;
  for(auto &vs : A) for(auto &p : vs) --p;

  vector< int > deg(N);
  bool update = true;
  int add = 0;
  auto to = make_v< int >(N, N);
  fill_v(to, -1);
  vector< int > alive(N);
  iota(begin(alive), end(alive), 0);

  while(update) {
    while((clock() - st) >= 1.95 * CLOCKS_PER_SEC) {
      cout << N * (N - 1) / 2 << endl;
      return 0;
    }
    update = false;
    for(int i : alive) {
      if(to[i][A[i][deg[i]]] == add) {
        ++deg[A[i][deg[i]]];
        ++deg[i];
        update = true;
      } else {
        to[A[i][deg[i]]][i] = add;
      }
    }
    vector< int > nxt;
    for(auto &p : alive) {
      if(deg[p] == N - 1) continue;
      nxt.emplace_back(p);
    }
    alive.swap(nxt);
    ++add;
  }

  if(*min_element(begin(deg), end(deg)) == N - 1) cout << add - 1 << endl;
  else cout << -1 << endl;
}




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

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

long long MOD = 1000000000 + 7;


ll H,W,N;
bool check(ll x, ll y, ll i, ll j){

  if(!(x - i >= 0 && x + (2-i) < H)) return false;
  if(!(y - j >= 0 && y + (2-j) < W)) return false;

  return true;

}

int main(){
  cout << setprecision(10);
  cin >> H >> W >> N;

  map<pll, int> m;

  vector<pll> v(N);
  for(int k = 0; k < N; k++){
    ll x,y;
    cin >> x >> y;
    x--; y--;

    for(ll i = 0; i < 3; i++){
      for(ll j = 0; j < 3; j++){
        if(check(x,y,i,j)){
          pll tmp = make_pair(x-i,y-j);
          if(m.count(tmp) == 0){
            m[tmp] = 1;
          } else { 
            m[tmp] += 1;
          }
        }
      }
    }
  }

  map<int,ll> ans;
  for(int i = 0; i <= 9; i++){
    ans[i] = 0;
  }

  ll sum = 0;
  for(auto x: m){
    ans[x.second] += 1;
    sum += x.second;
  }

  ans[0] = (H-2) * (W-2) - (ll)m.size();
  for(auto x: ans){
    cout << x.second << endl;
  }


}


Measured memory_bytes: 58112
#include <bits//stdc++.h>
using namespace std;
int main(void){
    int a,b,c,i,j,ans;
    ans=0;
    int rc,lc;
    rc=1;
    lc=0;
    
    string s;
    cin>>s;
    a=s.size();
    int box[s.size()];
    for(i=0;i<a;i++)
    box[i]=0;
    for(i=0;i<a;i++){
        if(i==0)
        continue;
        if(rc){
            if(s[i]=='R')
            rc++;
            else{
                box[i]=box[i]+rc/2;
                box[i-1]=box[i-1]+(rc+1)/2;
                rc=0;
                lc=1;
            }
        }
        else{
            if(s[i]=='L')
            lc++;
            else{
                box[i-lc]=box[i-lc]+(lc+1)/2;
                box[i-lc-1]=box[i-lc-1]+lc/2;
                lc=0;
                rc=1;
            }
            
        }
        if(i==a-1){
            box[i-lc+1]=box[i-lc+1]+(lc+1)/2;
            box[i-lc]=box[i-lc]+lc/2;
            lc=0;
            rc=1;
        }
    }
    for(i=0;i<a;i++){
        cout<<box[i];
        if(i!=a-1)
        cout<<" ";
        else
        cout<<endl;
    }
}


Measured memory_bytes: 1024
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =2e5+10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
typedef long long ll;
int k;
int n;
int a[MAXN];
int check(int x)
{
	int sum=0;
	for(int i=1;i<=n;i++)
	{
		sum+=(a[i]+x-1)/x-1;
	}
	//printf("x: %lld sum:%lld \n",x,sum);
	if(sum<=k) return 1;
	else return 0;
}
int main()
{
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++) 
	{
	    scanf("%d",&a[i]);
	} 
	int l=1,r=1e9;
	while(r>l)
	{
		int mid=(l+r)>>1;
		if(check(mid))
		{
			r=mid;
		}
		else l=mid+1;
	}
	printf("%d\n",l);
	return 0;
}

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

using namespace std;

int n, m, s[5], c[5];
int ans[3];

int digits[3][10];

int main(){
	cin >> n >> m;
	for(int i = 0; i < m; ++i){
		cin >> s[i] >> c[i];
		digits[s[i]-1][c[i]] = 1;
	}
	if(n != 1) ans[0] = 1;	
	
	for(int i = 0; i < 3; ++i){
		int sum = 0;
		for(int j = 0; j < 10; ++j) sum += digits[i][j];
		if(sum > 1){
			cout << -1 << endl;
			return 0;
		}
	}
	if(n != 1 && digits[0][0] == 1){
		cout << -1 << endl;
		return 0;
	}
	
	for(int i = 0; i < 3; ++i){
		ans[s[i]-1] = c[i];
	}
	for(int i = 0; i < n; ++i) cout << ans[i];
	cout << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
using ll = long long;
#define MAX_N 1010
#define MAX_M 100010
const long long mod = pow(10,9)+7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep1(n) for(ll i = 0; i < (n); ++i)
#define rep2(i, n) for(ll i = 0; i < (n); ++i)
#define rep3(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep4(i, a, b, c) for(ll i = (a); i < (b); i += (c))
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; }
#define INF 1e+9
#define print(x) cout<<x<<endl;
using P = pair<int, int>;
#define PLL pair<ll, ll>;
#define MAX_V 10010
#define PI 3.141592653589793
#define vecP vector<P>
 //cout << setprecision(15) << std::fixed;


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && a != c) {
        print("Yes");
    }
    else if (a == c && a != b) {
        print("Yes");
    }
    else if (b == c && a != b) {
        print("Yes");
    }
    else {
        print("No");
    }
}




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

int main(void) {
    int n;
    cin >> n;
    int x[n], sorted[n];
    int sum = 0;
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        sorted[i] = x[i];
    }
    sort(sorted, sorted + n);
    for (int i = 0; i < n; i++) {
        int med_min = sorted[(n-1)/2];
        int med_max = sorted[(n+1)/2];
        if (x[i] < med_max) cout << med_max << endl;
        else cout << med_min << endl;
    }

    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}
 
struct Edge {
    int u, v, c;
};
 
int main() {
    FAST_IO();
    int N, M, P; cin >> N >> M >> P;
    vector<Edge> edges;
    vector<vector<int>> adj(N);
    rep(i, M) {
        Edge e;
        cin >> e.u >> e.v >> e.c;
        e.u--; e.v--; e.c = P - e.c;
        edges.push_back(e);
        adj[e.u].push_back(e.v);
    }
    // Bellman-Ford Algorithm
    int src = 0, dst = N - 1;
    vector<int> dist(N, INT_MAX);
    dist[src] = 0;
    rep(i, N - 1) {
        for(auto &e : edges) {
            if(dist[e.u] != INT_MAX && dist[e.v] > dist[e.u] + e.c) {
                dist[e.v] = dist[e.u] + e.c;
            }
        }
    }
    vector<int> neg_cycle;
    for(auto &e : edges) {
        if(dist[e.u] != INT_MAX && dist[e.v] > dist[e.u] + e.c) {
            dist[e.v] = dist[e.u] + e.c;
            neg_cycle.push_back(e.u);
        }
    }
    
    if(sz(neg_cycle) == 0) {
        cout << max(0, -dist[dst]) << "\n";
    } else {
        // reachable
        vector<vector<int>> reachable(N, vector<int>(N, -1));
        rep(u, N) {
            queue<int> Q;
            Q.push(u);
            reachable[u][u] = 1;
            while(!Q.empty()) {
                int here = Q.front(); Q.pop();
                for(auto &next : adj[here]) {
                    if(reachable[u][next] == -1) {
                        reachable[u][next] = 1;
                        Q.push(next);
                    }
                }
            }
        }
        for(auto &x : neg_cycle) {
            if(reachable[src][x] == 1 && reachable[x][dst] == 1) {
                cout << -1 << "\n";
                return 0;
            }
        }
        cout << max(0, -dist[dst]) << "\n";
    }
}

Measured memory_bytes: 24960
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N, k;
	cin >> N >> k;

	vector<Int> x(N);
	Int flag = 1;
	for (Int i = 0; i < N; i++) {
		cin >> x[i];
		if (x[i] == 0) k--;
	}
	
	Int ans = INF;
	Int temp = 0;
	if (k) {
		for (Int i = 0; i <= N-k; i++) {
			temp = abs(0 - x[i]) + abs(x[k + i - 1] - x[i]);
			ans = min(ans, temp);
			//if (k + i - 1 == N - 1)break;
		}

		for (Int i = 0; i <= N-k; i++) {
			temp = abs(0 - x[k+i-1]) + abs(x[k + i - 1] - x[i]);
			ans = min(ans, temp);
			//if (k + i - 1 == N - 1)break;
		}
	}
	else {
		ans = 0;
	}
	

	cout << ans << endl;


}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    string s;
    cin >> s;
    string ans = "";
    for(auto c:s){
        if(c == 'B'){
            if(ans.size())
                ans.erase(ans.end()-1);
        }else{
            ans += c;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
 int kosu,capa,time,ans,R;
  R=0;
  scanf("%d %d %d",&kosu,&capa,&time);
  
  if(kosu%capa>0)
  {
    R++;
  }
  ans=kosu/capa + R;
  printf("%d",ans*time);
  return 0;
  
}

Measured memory_bytes: 1700
n = gets.to_i
x = Array.new(n).map{ Array.new(2) }
n.times do |i|
    x[i][0], x[i][1] = gets.split.map(&:to_i)
end

d = Array.new(n).map{ Array.new(n) }
n.times do |i|
    n.times do |j|
        d[i][j] = Math.sqrt((x[i][0] - x[j][0]) ** 2 + (x[i][1] - x[j][1]) ** 2)
    end
end

puts d.map{ |e| e.inject(:+)}.inject(:+)/n

Measured memory_bytes: 1916
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

int main (void) {
  int A, B, C; std::cin >> A >> B >> C;

  int maxK = std::max( { A, B, C } );

  int ans = 0;
  ans += std::floor((double)(maxK - A)/2); A = maxK - A - std::floor((double)(maxK - A)/2)*2 ;
  ans += std::floor((double)(maxK - B)/2); B = maxK - B - std::floor((double)(maxK - B)/2)*2 ;
  ans += std::floor((double)(maxK - C)/2); C = maxK - C - std::floor((double)(maxK - C)/2)*2 ;

  if ( A + B + C == 1 ) ans += 2;
  else if ( A + B + C == 2 ) ans += 1;
  std::cout << ans << std::endl;


  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// Useful constants
#define INF  (int)1e9
#define EPS   1e-9
#define MOD 1000000007ll
#define PI 3.14159
// for input-output
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
// iteration macros: have advantage of auto-casting and not recomputing arguments
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
// input macro
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}
//output macro
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
// shortcut for data type
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define uset unordered_set
#define umap unordered_map
//--namespace
using namespace std;
//--useful function
ll gcd(ll a, ll b){ll temp;while (b > 0){temp = a%b;a = b;b = temp;} return a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
// --clock funtion
clock_t time_p=clock();
void TimeTaken()
{
    time_p=clock()-time_p;
    cerr<<"Completion time : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
// --solve function
void solve() {

}
//--main function
int main(){
	int n,mox=0;cin>>n;
	string s;cin>>s;int b=0;
	for(auto x:s){
		if(x=='I')b++;
		else if(x=='D')b--;
		mox=max(b,mox);
		
	}
	cout<<mox;
	return 0;

//   TimeTaken();
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  ui N; cin >> N;
  vector<int> res(N);
  for (ui i = 0; i < N; i++)
  {
    ui a; cin >> a;
    res[a - 1] = i + 1;
  }
  cout << res << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


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

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

struct Node *root,*NIL;

void insert(int);
void inorder(struct Node *);
void preorder(struct Node *);
struct Node* find(struct Node *,int);

int main(){
  int n,i,x;
  char s[20];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",s);
    if(strcmp(s,"find")==0){
      scanf("%d",&x);
      struct Node *t = find(root,x);
      if(t != NIL)printf("yes\n");
      else printf("no\n");
    }
    else if(strcmp(s,"insert")==0){
      scanf("%d",&x);
      insert(x);
    }
    else if(strcmp(s,"print")==0){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

void insert(int k){
  struct Node *y = NIL,*x = root,*z;

  z = malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  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;
  else {
    if(z->key < y->key)y->left = z;
    else y->right = z;
  }
}

void inorder(struct Node *u){

  if(u == NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(struct Node *u){

  if(u == NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

struct Node* find(struct Node *u,int k){

  while(u != NIL && k != u->key){
    if(k < u->key)u = u->left;
    else u = u->right;
  }
  return u;
}

Measured memory_bytes: 19360
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

constexpr int64 MOD = 1000000007;

const string ALICE = "Alice";
const string BROWN = "Brown";

int64 X, Y;

int main() {
    cin >> X >> Y;
    if (abs(X - Y) <= 1) {
        cout << BROWN << endl;
    } else {
        cout << ALICE << endl;
    }
    return 0;
}


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

int main() {
    ll n; cin >> n;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin >> a[i];
    ll ans = 0;
    for(int i=0; i<n; i++) {
        ans ^= a[i];
    }
    for(int i=0; i<n; i++) {
        cout << (ans ^ a[i]) << " ";
    }
}

Measured memory_bytes: 4832
#include<stdio.h>
#include<stdlib.h>

#define constraints 101

int n, i, u, k, v_k, time, Adj[constraints][constraints], discovery[constraints], finish[constraints];


void dfs(int i) {
	time++;
	discovery[i] = time;
	for (int j = 0; j < n; j++) {
		if (Adj[i][j] != 0 && discovery[j] == 0) {
			dfs(j);
		}
	}
	time++;
	finish[i] = time;
}

int main() {
	time = 0;
	scanf("%d", &n);

	//scanning / make graph
	for (i = 0; i < n; i++) {
		scanf("%d %d", &u, &k);
		for (int j = 0; j < k; j++) {
			scanf("%d", &v_k);
			Adj[u - 1][v_k - 1] = 1;
		}
	}

	//dfs
	for (i = 0; i < n; i++) {
		if (discovery[i] == 0) {
			dfs(i);
		}
	}

	//printing
	for (i = 0; i < n; i++) {
		printf("%d %d %d\n", i + 1, discovery[i], finish[i]);
	}

	return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
using namespace std;
# define M_PI 3.14159265358979323846
using ll = long long int;
const int MOD = 1e9 + 7;
int main()
{
    ll x;
    cin>>x;
    bool found=false;
    for(ll i=-200;i<=200;i++)
    {
        for(ll j=-200;j<=200;j++)
        {
            ll a=i*i*i*i*i;
            ll b=j*j*j*j*j;
            if((a-b)==x)
            {
                cout<<i<<" "<<j;
                found=true;
                break;
            }
        }
        if(found)
        {
            break;
        }
    }
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<int> s(n),t(n),r(n);
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    for (int i = 0; i < n; i++) {
        r[i] = i + 1;
    }
    int a = -1, b = -1;
    int cnt = 1;
    do {
        if (a == -1) {
            for (int i = 0; i < n; i++) {
                if (s[i] != r[i]) {
                    break;
                }
                else if (i == n - 1) {
                    a = cnt;
                }
            }
        }
        if (b == -1) {
            for (int i = 0; i < n; i++) {
                if (t[i] != r[i]) {
                    break;
                }
                else if (i == n - 1) {
                    b = cnt;
                }
            }
        }
        cnt++;
    } while (next_permutation(r.begin(), r.end()));
    //cout << a << " " << b << endl;
    cout << abs(a - b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,i,x=0;
    scanf("%d %d",&a,&b);
    c=b-a;
    for(i=1;i<=c;i++){
	x+=i;
    }
    x-=b;
    printf("%d",x);
    return 0;
}

Measured memory_bytes: 128
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 30000

int n;
char s[MAXN+1];

int input() {
        if (scanf("%d %s", &n, s) < 0) return 0;
        return 1;
}

void init() {
}

int solve() {
        char t[4]={0};
        int r = 0;
        for (int i=0; i<10; i++) {
                t[0] = i+'0';
                for (int j=0; j<10; j++) {
                        t[1] = j+'0';
                        for (int k=0; k<10; k++) {
                                t[2] = k+'0';
                                int ok = 0;
                                for (int pi=0; pi<n; pi++) if(s[pi]==t[0]) {
                                        for (int pj=pi+1; pj<n; pj++) if(s[pj]==t[1]) {
                                                for (int pk=pj+1; pk<n; pk++) if(s[pk]==t[2]) {
                                                        ok = 1;
                                                        goto done;
                                                }
                                                break;
                                        }
                                        break;
                                }
                                done:
                                r += ok;
                        }
                }
        }
        return r;
}

void output(int ans) {
        printf("%d\n", ans);
}

void cleanup() {
}

int main() {
        //int ca; scanf("%d", &ca);
        while (input()) {
                init();
                output(solve());
                cleanup();
                //break;
        }
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int N, T;
  cin >> N >> T;

  vector<int> A(N);
  rep (i, N) cin >> A[i];

  int maxv = 0;
  int tmp = INF;
  rep (i, N) {
    tmp = min(tmp, A[i]);
    maxv = max(maxv, A[i] - tmp);
  }

  int ans = 0;
  map<int, int> cnt;
  rep (i, N) {
    if (cnt.find(A[i] - maxv) != cnt.end()) {
      ans += cnt[A[i] - maxv];
    }
    cnt[A[i]]++;
  }

  cout << ans <<endl;
}


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

int main() {
	int n; scanf("%d", &n);
	int i;
	for (i = 0; n > 1; i++) {
		n = min(n / 2, n / 3 + (n % 3 > 0));
	}
	cout << i << endl;
}

Measured memory_bytes: 3232
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {
	private static final int MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		sc.fill(A);

		debug(gcd(0, 8));

		int[] left = new int[N];
		int prev = 0;
		for (int i = 0; i < N; i++) {
			prev = left[i] = gcd(prev, A[i]);
		}

		int[] right = new int[N];
		prev = 0;
		for (int i = N - 1; i >= 0; i--) {
			prev = right[i] = gcd(prev, A[i]);
		}

		int max = 0;
		for (int i = 0; i < N; i++) {
			int a = i == 0 ? 0 : left[i - 1];
			int b = i == N - 1 ? 0 : right[i + 1];
			int current = gcd(a, b);
			max = Math.max(max, current);
		}

		System.out.println(max);
	}

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

		return gcd(b, a % b);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public char nextChar() throws IOException {
			return (char) skip();
		}

		public int nextInt() throws IOException {
			int num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}

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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    int w, h; cin >> w >> h;
    vector<vector<bool>> g(h, vector<bool>(w));
    for(int i=0;i<n;++i) {
      int x, y; cin >> x >> y;
      x--; y--;
      g[y][x] = true;
    }
    int s, t; cin >> s >> t;

    int ans = 0;
    for(int i=0;i<h-t+1;++i) {
      for(int j=0;j<w-s+1;++j) {
        int su = 0;
        for(int k=0;k<t;++k) {
          for(int l=0;l<s;++l) {
            su += g[i+k][j+l];
          }
        }
        ans = max(ans, su);
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3124
import math
import sys

m=10**9 + 7 
N  = int(input())

if ( N ) % 2 != 0:
    print(0)
    exit(0)

x = 10 
fives = 0 
for i in range(1,27):
    fives = fives + ( N // x )
    x = x * 5

print(fives)

Measured memory_bytes: 3060
#include <iostream>

int main(int argc, const char * argv[]) {
    
    int a[3];
    std::cin >> a[0] >> a[1] >> a[2];
    
    int tmp;
    for (int j=2; j>0; j--) {
        for (int i=0; i<j; i++) {
            if (a[i]>a[i+1]) {
                tmp = a[i];
                a[i] = a[i+1];
                a[i+1] = tmp;
            }
        }
    }
    std::cout << a[0] << " " << a[1] << " " << a[2] << std::endl;
}

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

int main(){
    int R , G , B , n;
    cin >> R >> G >> B;
    cin >> n;
    for (int i = 0 ; i < n ; i++){
        if(G <= R){
            G *= 2;
        }else if(B <= G){
            B *= 2;
        }
    }
    if(B > G && G > R){
        cout << "Yes";
    }else{
        cout << "No";
    }

    return 0;
}



Measured memory_bytes: 3540
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 100000
using namespace std;
int n,a[N+5],s[N+5];
class FastIO
{
	private:
		#define FS 100000
		#define tc() (A==B&&(B=(A=FI)+fread(FI,1,FS,stdin),A==B)?EOF:*A++)
		#define tn (x<<3)+(x<<1)
		#define D isdigit(c=tc())
		char c,*A,*B,FI[FS];
	public:
		I FastIO() {A=B=FI;}
		Tp I void read(Ty& x) {x=0;W(!D);W(x=tn+(c&15),D);}
		Ts I void read(Ty& x,Ar&... y) {read(x),read(y...);}
}F;
int main()
{
	RI i,t=0;for(F.read(n),i=1;i<=n;++i) F.read(a[i]);
	for(sort(a+1,a+n+1),i=1;i<=n;++i) s[i]=a[i];t=unique(s+1,s+n+1)-s-1;
	if(!a[1]&&t==1) return puts("Yes"),0;if(n%3||t>3) return puts("No"),0;
	for(i=1;i<n/3;++i) if(a[i]^a[i+1]) return puts("No"),0;
	for(i=n/3+1;i<n/3*2;++i) if(a[i]^a[i+1]) return puts("No"),0;
	for(i=n/3*2+1;i<n;++i) if(a[i]^a[i+1]) return puts("No"),0;
	return puts((a[1]^a[n/3+1])==a[n]?"Yes":"No"),0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
  
int main()
{
  int N;
  cin >> N;

  vector<int> A(N+1);
  REP(i, N+1) cin >> A[i];
  vector<int> B(N);
  REP(i, N) cin >> B[i];
  
  ll cnt = 0;
  REPR(i,N-1){
    if(B.at(i)>=A.at(i+1)){
      B.at(i)-=A.at(i+1);
      cnt+=A.at(i+1);
      cnt+=min(B.at(i),A.at(i));
      A.at(i)-=min(B.at(i),A.at(i));
    }else{
      cnt+=B.at(i);
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 3996
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;

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

		while (true) {
			final int n = Integer.parseInt(sc.nextLine());
			
			if(n == 0){
				break;
			}
			
			int score = 0;
			int prev_suc_state = 0;
			int cur_state = 0;
			
			StringTokenizer token = new StringTokenizer(sc.nextLine());
			while(token.hasMoreTokens()){
				char[] input = token.nextToken().toCharArray();
				//System.out.println(Arrays.toString(input));
				
				boolean is_left = input[0] == 'l';
				boolean is_up = input[1] == 'u';
				
				cur_state += (is_up ? 1 : -1) * (is_left ? 10 : 1);
				
				if(cur_state == 10 || cur_state == 01){
					continue;
				}else if(cur_state == prev_suc_state){
					continue;
				}else{
					prev_suc_state = cur_state;
					score++;
				}
			}
			
			System.out.println(score);
		}
	}
}

Measured memory_bytes: 24280
#  入力
N = int(input())
A = [int(x) for x in input().split()]

# 初期化
dp = [[0] * (N+1) for _ in range(N+1)]
dp[0][0] = 0

for i in range(0,N):

    # 最も嬉しさの高い子供から場所を選択していく
    a = max(A)
    id = A.index(a)
    
    for x in range(0,i+1):
        y = i - x

        d = dp[x][y]
        tmp = d + a * (id - x)
        if dp[x+1][y] < tmp:
        	dp[x+1][y] = tmp
        tmp = d + a * (((N-1)-y) - id)            
        if dp[x][y+1] < tmp:
        	dp[x][y+1] = tmp
        
    A[id] = 0

ans = 0
for i in range(N+1):
    ans = max(ans, dp[i][N-i])
print(ans)

Measured memory_bytes: 100068
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define pb push_back

int main(){

	string S;
	cin >> S;
	for(int i = 0; i < S.size(); i ++){
		if(S[i] == '1')S[i] = '9';
		else if(S[i] == '9')S[i] = '1';
	}
	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,W;
long long dp[100001];
int weigth[101];
int value[101];

long long solve2() {
    for(int i=0;i<n;++i)
        dp[i] = -1;
    dp[0] = 0;
    for(int i=0;i<n;++i)
        for(int w = W;w>=0;--w)
            if(w - weigth[i] >=0)
                dp[w] = max(dp[w], dp[w - weigth[i]] + value[i]);
    return *max_element(dp,dp+W+1);
}
int main(int argc, char const *argv[]) {
    scanf("%d %d", &n, &W);
    for(int i=0;i<n;++i)
        scanf("%d %d", &weigth[i], &value[i]);
    printf("%lld\n", solve2());

    return 0;
}

Measured memory_bytes: 4448
A = list(input())
n = len(A)
B = list(range(1,n))
m = len(B)
# v: +を入れる場所
v = []
for bit in range(1<<m):
    tmp = []
    for i in range(m):
        if 1 & (bit>>i):
            tmp.append(B[i])
    v.append(tmp)
v.sort(key=len)

res = 0
for b in v:
    tmp_index = 0
    if b==[]:
        res += int(''.join(A))
        continue
    # 末尾まで足したいのでAの長さを追加する
    b = b + [n]
    for i in b:
        res += int(''.join(A[tmp_index:i]))
        tmp_index = i
print(res)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
using namespace std;
 
int main(void){
  int count = 0;
  char S[4], T[4];
  cin >> S >> T;
  
  for (int i = 0; i < 3; i++){
    if(S[i] == T[i]){
      count++;
    }
  }
  
  cout << count << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
int mod=1e9+7;

signed main(){
  int n;
  cin>>n;
  double ans1=0;
  double ans2=0;
  double ans3=0;
  double ans4=0;
  vector<double> a(n);
  vector<double> b(n);

  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  for(int i=0;i<n;i++){
    ans1+=abs(a[i]-b[i]);
    ans2+=(a[i]-b[i])*(a[i]-b[i]);
    ans3=max(ans3,abs(a[i]-b[i]));
    ans4+=abs(a[i]-b[i])*abs(a[i]-b[i])*abs(a[i]-b[i]);
  }
  cout<<fixed<<setprecision(20)<<ans1<<endl;
  cout<<sqrt(ans2)<<endl;
  cout<<pow(ans4,1.0/3.0)<<endl;
  cout<<ans3<<endl;
}



Measured memory_bytes: 3484
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <iostream>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int vs[100000+10];
int main(void) {
  int n, k;
  scanf("%d%d", &n, &k);
  REP(i, n) {
    scanf("%d", &vs[i]);
  }
  int res = 2e9;
  REP(i, n) {
    if(i+k-1 >= n) {
      break;
    }
    int cur = abs(vs[i]-vs[i+k-1]) + min(abs(vs[i]), abs(vs[i+k-1]));
    res = min(cur, res);
  }
  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 640
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	nab := strings.Fields(nextLine())
	n, _ := strconv.Atoi(nab[0])
	a, _ := strconv.Atoi(nab[1])
	b, _ := strconv.Atoi(nab[2])
	if n*a < b {
		fmt.Println(n * a)
	} else {
		fmt.Println(b)
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;

bool solve(vector<int> &a, vector<int> &b, vector<vector<int>> &c) {
    int n = c.size();
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == 0) {
                b[j] = c[i][j] - a[i];
            } else {
                if (j == 0) continue;
                if (c[i][j] - b[j] != c[i][j-1] - b[j-1]) return false;
            }
        }
    }
    return true;
}

int main() {
    int n = 3;
    vector<int> a(n);
    vector<int> b(n);
    vector<vector<int>> c(n, vector<int>(n));
    rep(i, n) {
        rep(j, n) {
            cin >> c[i][j];
        }
    }
    bool flag;
    for (int i = -100; i <= 100; i++) {
        a[0] = i;
        flag = solve(a, b, c);
        if (flag) break;
    }
    if (flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

using namespace std;
int main(){
    vector<int> v;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++){
        // char ch=s[i];
        // if(ch>='0'&&ch<='9')cout<<ch<<endl;
        if(s[i]=='0')v.push_back(0);
        if(s[i]=='1')v.push_back(1);
        if(s[i]=='B'&&v.size()>0)v.pop_back();
    }
    // string ans="";
    for(int i=0;i<v.size()-1;i++){
        // ans+=v.at(i);
        cout<<v.at(i);
    }
    cout<<v.at(v.size()-1)<<endl;;
    // cout<<ans<<endl;
    // stack<int> s;
    // cout<<s.top()<<endl;
    // s.pop();
    // cout<<s.top()<<endl;
}

Measured memory_bytes: 256
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
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)*}
    };
}

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")
    };
}

fn main() {
    input! {
        N: usize,
        K: usize,
        ls: [usize; N],
    }
    let mut ls = ls;
    ls.sort();
    ls.reverse();
    println!("{}", ls.into_iter().take(K).sum::<usize>());
}


Measured memory_bytes: 4352
import java.util.*; 

class Main{
public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
       
  		int[] a=new int[n];
		for(int c=0;c<n;c++){
    		a[c]=sc.nextInt();
    	}
  		String ans="YES";
  		Arrays.sort(a);
  		for(int d=0;d<n-1;d++){
        	if(a[d]==a[d+1]){
              	ans="NO";
            	break;
            }
        }
    
 	

    	System.out.println(ans);
    }
}

Measured memory_bytes: 68200