akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

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

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

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

    string s;
    cin >> s;
    string a = "Good";
    rep(i, 3) if (s[i] == s[i + 1]) a = "Bad";
    cout << a << endl;

    return 0;
}

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

int main()
{
	string str;
	map<string,bool> memo;
	printf("?aa\n"); fflush(stdout);
	memo["aa"] = true;
	cin >> str;
		if(str[0] != 'a'){
			cout << "!OUT" << endl;
			goto END;
		}
		if(memo.find(str) != memo.end()){
			cout << "!OUT" << endl;
			goto END;
		}
		else
			memo[str] = true;
	for(int i=0;i<26;i++){
		string my = "aaa";
		my[0] = str[str.size()-1];
		my[1] = static_cast<char>(static_cast<int>(my[1])+i);
		cout << "?" << my << endl; fflush(stdout);
		cin >> str;
		if(str[0] != 'a'){
			cout << "!OUT" << endl;
			goto END;
		}
		if(memo.find(str) != memo.end()){
			cout << "!OUT" << endl;
			goto END;
		}
		else
			memo[str] = true;
	}
END:;
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class UnionFind {
public:
    explicit UnionFind(int N) : root(N, -1), size(N, 1), edge(N, 0) {}
    int getRoot(int u){ return root[u] == -1 ? u : root[u] = getRoot(root[u]); }
    int getSize(int u){ return size[getRoot(u)]; }
    int same(int a, int b){
        return getRoot(a) == getRoot(b);
    }
    bool merge(int a, int b){
        int u = getRoot(a);
        int v = getRoot(b);
        if(u != v){
            if(edge[u] + edge[v] + 1 > size[u] + size[v]) return false;
            root[u] = v;
            size[v] += size[u];
            edge[v] += edge[u] + 1;
        } else {
            if(edge[u] + 1 > size[u]) return false;
            edge[u]++;
        }
        return true;
    }
private:
    vector<int> root;
    vector<int> size;
    vector<int> edge;
};

int main(){
    int N, H, W;
    while(cin >> N >> H >> W){
        UnionFind uf(H+W);
        long long res = 0;
        vector<pair<int, pair<int, int>>> vp;
        for(int i=0;i<N;i++){
            int r, c, a; cin >> r >> c >> a;
            vp.emplace_back(a, make_pair(r-1, c-1+H));
        }
        sort(vp.rbegin(), vp.rend());
        for(auto& p : vp){
            if(uf.merge(p.second.first, p.second.second)){
                res += p.first;
            }
        }
        cout << res << endl;
    }
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define MOD 1000000007
static const ll INF = 1000000000000000ll;

int n;
int cnt[26][26];

struct dinic{
  struct edge{int to;ll cost;};
  int n;
  vector< vector<edge> > G;
  vector<vl> flow, capacity;
#define RESIDUE(s,t) (capacity[s][t]-flow[s][t])
  vi level;
  vector<bool> finished;
  dinic(int _n){
    n = _n;
    G.assign(n,vector<edge>());
    flow.assign(n,vl(n,0));
    capacity.assign(n,vl(n,0));
    level.assign(n,0);
    finished.assign(n,false);
  }
  void add_edge(int from,int to,ll cost){
    assert(0<=from && from<n);
    assert(0<=to && to<n);
    G[from].push_back((edge){to,cost});
    G[to].push_back((edge){from,0ll});  // 逆に流すフローのためのダミー辺
  }
  ll dfs(int u, int t, ll cur){
    if(u==t || cur==0) return cur;
    if(finished[u]) return 0;
    finished[u] = true;
    REP(i,G[u].size()){
      edge e = G[u][i];
      if(level[e.to] > level[u]){
        ll f = dfs(e.to, t, min(cur, RESIDUE(u,e.to)));
        if(f>0){
          flow[u][e.to] += f;
          flow[e.to][u] -= f;
          finished[u] = false;
          return f;
        }
      }
    }
    return 0;
  }
  ll calc(int s, int t){
    REP(i,n)REP(j,n)flow[i][j]=capacity[i][j]=0;
    REP(u,n)REP(j,G[u].size()){
      edge e = G[u][j];
      capacity[u][e.to] += e.cost;
    }
    ll total = 0;
    while(true){
      REP(i,n)level[i] = -1;
      level[s] = 0;
      queue<int> Q; Q.push(s);
      int d = n;
      while(!Q.empty()){
        int u = Q.front(); Q.pop();
        REP(i,G[u].size()){
          edge e = G[u][i];
          if(RESIDUE(u,e.to) > 0 && level[e.to] == -1){
            Q.push(e.to);
            level[e.to] = level[u] + 1;
          }
        }
      }
      REP(i,n)finished[i]=false;
      bool flag = false;
      while(true){
        ll f = dfs(s,t,INF);
        if(f==0)break;
        total += f;
        flag = true;
      }
      if(!flag)break;
    }
    return total;
  }
};

char buf[1252];

int main(){
  scanf("%d",&n);
  REP(i,n){
    scanf("%s",buf);
    int ln = strlen(buf);
    int a = buf[0]-'a';
    int b = buf[ln-1]-'a';
    cnt[a][b]++;
    REP(i,ln)buf[i]='\0';
  }
  REP(i,26){
    // can end at i?
    int indeg = 0, outdeg = 0;
    REP(j,26){
      indeg += cnt[j][i];
      outdeg += cnt[i][j];
    }
    if(indeg == 0)continue;
    indeg -= cnt[i][i];
    outdeg -= cnt[i][i];
    dinic D(28);
    REP(a,26)REP(b,26){
      if(a==i || b==i)continue;
      D.add_edge(a,b,cnt[a][b]);
    }
    REP(a,26)if(a!=i){
      D.add_edge(26,a,cnt[i][a]);
      D.add_edge(a,27,cnt[a][i]);
    }
    if(D.calc(26,27)==outdeg){
      putchar('a'+i);putchar('\n');
    }
  }
  return 0;
}



Measured memory_bytes: 3304
#include<bits/stdc++.h>
using namespace std;
int a[200001],sum,n;
int main()
{
	cin >> n;
	for (int i=1;i<=n;i++)
	{
		cin >> a[i];
		sum^=a[i];
	}
	for (int i=1;i<=n;i++)
	{
		cout << (sum^a[i]) << " ";
	}
	return 0;
}

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;




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

	int n;
	string s;cin>>s;
	n = s.size();

	vector<int> ans(n);

	for(int i=0; i<2; i++){
		int cnt =0;

		for(int i=0; i<n; i++){
			if(s[i] =='R')cnt++;
			else{
				ans[i] += cnt/2;
				ans[i-1] +=(cnt+1)/2;
				cnt=0;
			}
		}
		reverse(ans.begin(),ans.end());
		reverse(s.begin(),s.end());

		for(int i=0; i<n; i++){
			if(s[i] == 'L')s[i] ='R';
			else {
				s[i] ='L';
			}
		}

	}

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

}




Measured memory_bytes: 1104
#include <stdio.h>
int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    if(1<=a,b,c && a,b,c<=100){
        if(a<b && b<c){
            printf("Yes\n");
        }
        else {
            printf("No\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2044
package main

import (
	"bufio"
	"fmt"
	"math/bits"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() uint64 {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return uint64(n)
}

func printOneOrZero(ok bool) {
	if ok {
		fmt.Println(1)
	} else {
		fmt.Println(0)
	}
}

func main() {
	scanner.Split(bufio.ScanWords)

	nQueries := int(nextInt())
	n := uint64(0)
	for i := 0; i < nQueries; i++ {
		queryType := nextInt()
		// fmt.Printf("%v %b\n", queryType, n)
		if queryType == 0 { // test
			qi := nextInt()
			mask := uint64(1) << qi
			// fmt.Printf("qi=%v, n & mask = %v", qi, n&mask)
			printOneOrZero(n&mask != 0)
		} else if queryType == 1 { // set
			qi := nextInt()
			n |= (uint64(1) << qi)
		} else if queryType == 2 { // clear
			qi := nextInt()
			// https://stackoverflow.com/questions/23192262/how-would-you-set-and-clear-a-single-bit-in-go
			n &= ^(uint64(1) << qi)
		} else if queryType == 3 { // flip
			qi := nextInt()
			n ^= uint64(1) << qi
		} else if queryType == 4 { // all
			printOneOrZero(bits.OnesCount64(n) == 64)
		} else if queryType == 5 { // any
			printOneOrZero(n != 0)
		} else if queryType == 6 { // none
			printOneOrZero(n == 0)
		} else if queryType == 7 { // count
			fmt.Println(bits.OnesCount64(n))
		} else if queryType == 8 { // val
			fmt.Println(n)
		}
	}
}



Measured memory_bytes: 3204
N=int(input())
xyh=[list(map(int,input().split())) for i in range(N)]
MAX=100
for PosY in range(MAX+1):
    for PosX in range(MAX+1):
        needH=-1
        for i in range(N):
             if xyh[i][2]>0:
                tmp=xyh[i][2]+abs(PosX-xyh[i][0])+abs(PosY-xyh[i][1])
                if needH==-1:
                    needH=tmp
                else:
                    if needH!=tmp:
                        needH=-2
                        break
        if needH==-2:
            continue
        for i in range(N):
            if xyh[i][2]==0:
                dist=abs(PosX-xyh[i][0])+abs(PosY-xyh[i][1])
                if needH>dist:
                    needH=-2
                    break
        if needH==-2:
            continue
        print(PosX,PosY,needH)


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<vector<pll>> A(N);
    REP(i, N) {
        ll a;
        cin >> a;
        REP(j, a) {
            ll x, y;
            cin >> x >> y;
            x--;
            A[i].push_back(pll(x, y));
        }
    }

    ll ans = 0;
    REP(i, pow(2LL, N)) {
        bool f = true;
        REP(j, N) {
            if ((i >> j) & 1) {
                REP(k, A[j].size()) {
                    if (((i >> A[j][k].first) & 1) != A[j][k].second)
                        f = false;
                }
            }
        }

        if (f) {
            ll s = 0;
            REP(j, N) {
                if ((i >> j) & 1)
                    s++;
            }
            ans = std::max(s, ans);
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int n,k;
    cin>>n>>k;
    int arr[n];

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

    sort(arr,arr+n);
    int ans=0;
    for(int i=0;i<k;i++)
    {
        ans += arr[i];
    }

    cout<<ans;
    return 0;
}


Measured memory_bytes: 3628
# 参考: https://atcoder.jp/contests/abc077/submissions/5869524
N = gets.to_i
A = gets.chomp.split.map(&:to_i).sort
B = gets.chomp.split.map(&:to_i).sort
C = gets.chomp.split.map(&:to_i).sort

s = 0
B.each do |b|
  i = A.bsearch_index { |a| a >= b } || N
  k = N - (C.bsearch_index { |c| c > b } || N)
  s += i * k
end
puts s


Measured memory_bytes: 26804
N, M = map(int, input().split())
listx = sorted(list(map(int, input().split())))
listgap =[0]*(M-1)
for n in range(M-1):
    listgap[n] = listx[n+1]-listx[n]
listgap.sort()    
if N>=M:
    print('0')
    exit
else:
    a = M-N
    anslist = listgap[0:a]
    b = sum(anslist)
    print(b)

Measured memory_bytes: 13960
using System;

namespace AOJ0019
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine(Factorize(int.Parse(Console.ReadLine() ?? "")));
        }

        public static long Factorize(int n)
        {
            if(n < 0) throw new ArgumentException();
            if (n <= 1) return 1;
            return n*Factorize(n - 1);
        }
    }
}

Measured memory_bytes: 5612
#include<bits/stdc++.h>
using namespace std;
const int SIZE = 2000+50;
int arr[SIZE];
#define ll long long
#define MOD 1000000007
int li[SIZE],ri[SIZE];

int main(){
    int n;ll k;scanf("%d%lld",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%d",&arr[i]);
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i-1;j++){
            if(arr[j]>arr[i])li[i]++;
        }
        for(int j=i+1;j<=n;j++){
            if(arr[j]>arr[i])ri[i]++;
        }
    }

    ll inv2 = (MOD+1)/2;
    ll k1=((k%MOD)*((k+1)%MOD))%MOD*inv2%MOD;
    ll k2=((k%MOD)*((k-1)%MOD))%MOD*inv2%MOD;
    ll sum=0;
    for(int i=1;i<=n;i++){
        //printf("%d %")
        sum += ((k1%MOD)*(li[i]%MOD))%MOD;
        sum += ((k2%MOD)*(ri[i]%MOD))%MOD;
    }
    sum%=MOD;
    printf("%lld",sum);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast", "unroll-loops")
#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(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=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define debug(x) cerr<<#x<<" is "<<x<<endl
using namespace std;

#define int ll

const int maxn = 2e5+5;
const int iinf = 1<<29;
const ll inf = 1ll<<60;
const ll mod = 1e9+7;


void GG(){cout<<"No\n"; exit(0);}




main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, a, b, c, d;
    cin>>n>>a>>b>>c>>d;
    string s; cin>>s;
    a--; b--; c--; d--;
    REP(i,n){
    	if (i&&s[i]=='#'&&s[i]==s[i-1]){
    		if ((i>a&&i<c) || (i>b&&i<d)){
    			// cout<<"WHOP";
    			GG();
    		}
    	}	
    }

    if (d>c) {
    	cout<<"Yes\n"; return 0;
    }
	FOR(i,b,d+1) { 
    	if (s[i]=='.'){
    		if (i && s[i-1]=='.' && i<n && s[i+1] == '.'){
    			cout<<"Yes\n"; return 0;
    		}
    	}

    }

    GG();
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long int n,m;
	cin>>n>>m;
	long int i,j,k[n],s=0,a[m+1]={0};
	for(i=0;i<n;i++)
	{
		
		cin>>k[i];
		long int x,y,b[k[i]];
		for(j=0;j<k[i];j++)
		{
		cin>>b[j];
		x=b[j];
		a[x]++;
		}
	}
	for(i=0;i<m+1;i++)
	{
	if(a[i]==n)
	{
		s++;
	}
	}
	cout<<s<<endl;
	
}

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

typedef long long ll;
const int maxn = 1e5 + 10;
int a[maxn];

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int x = 0, y = 1, c = 1, d = 0, c1 = 0, c2 = 0;
	bool addx = false, addy = false, addc = false, addd = false;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] % 4 == 0) {
			if (addx) {
				x += 2;
			}
			addx = true;
			if (addc) {
				c += 2;
			}
			addc = true;
			c1++;
		} else if (a[i] % 4 != 2) {
			if (addy) {
				y += 2;
			}
			addy = true;
			if (addd) {
				d += 2;
			}
			addd = true;
			c2++;
		}
	}
	if (n == 1 && a[1] == 2) {
		cout << "No" << endl;
		return 0;
	}
	if (c1 == 0 && c2 == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	if (addx && !addy) {
		cout << "Yes" << endl;
		return 0;
	}
	if (c1 > c2) {
		cout << "Yes" << endl;
		return 0;
	}
	if (y == x + 1 && !addx || d == c + 1 && !addc) {
		cout << "No" << endl;
		return 0;
	}
	if (x != y + 1 && y != x + 1 && c != d + 1 && d != c + 1) {
		cout << "No" << endl;
	} else {
		if (c == d + 1) {
			cout << "Yes" << endl;
		} else {
			int tmp = 0;
			for (int i = 1; i <= n; i++) {
				if (a[i] % 4 == 2) {
					tmp++;
				}
			}
			if (tmp == 0) {
				cout << "Yes" << endl;
			} else {
				cout << "No" << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 640
x,n = map(int,input().split())
p = input().split()
q = p[::-1]
a = x
b = x
c = 1
if p.count(str(x)) == 1:
  while c == 1:
    a -= 1
    c = p.count(str(a))
c = 1
if p.count(str(x)) == 1:
  while c == 1:
    b += 1
    c = p.count(str(b))
if x - a <= b - x:
  print(a)
else:
  print(b)

Measured memory_bytes: 9024
#include <iostream>
#include <cmath>
#include <string>

int main(int argc, char *argv[])
{
    int x, y;
    while(1){
        std::cin >> x >> y;
        if(x == 0 && y == 0)break;
        if(x > y)std::swap(x,y);

        std::cout << x << " " << y << std::endl;
    }
    return 0;
}

Measured memory_bytes: 3036
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

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

    long long ans = 0;
    for (int i = 0; i <= N; i++) {
        if(i % 3 == 0)
            continue;
        if (i % 5 == 0)
            continue;

        ans += i;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
// template version 1.13
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define infile "../test/sample-1.in"
#define int long long //{{{
const int INF=1e18;
const int MOD=1e9+7; //}}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_pair(a, b, c)
#define ceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

int solve(){
  string s;cin>>s;
  int n=sz(s)+1;

  vi p(n);
  vi q(n);
  rep(i, 1, n){
    if (s[i-1]=='<'){
      p[i] = p[i-1]+1;
    }
    else{
      p[i] = 0;
    }
  }
  dump(p);

  rrep(i, n-1){
    if (s[i]=='>'){
      q[i] = q[i+1]+1;
    }
    else{
      q[i] = 0;
    }
  }
  dump(q);

  int ans = 0;
  rep(i, n){
    ans += max(p[i], q[i]);
  }
  cout << ans << endl;

  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 8732
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	v := make([]int, n)
	for i := range v {
		fmt.Scan(&v[i])
	}

	p, c := selectionSort(v)
	for i, e := range p {
		fmt.Print(e)
		if i < len(p)-1 {
			fmt.Print(" ")
		} else {
			fmt.Println()
		}
	}
	fmt.Println(c)
}

func selectionSort(v []int) ([]int, int) {
	if len(v) == 0 {
		return []int{}, 0
	}

	a, p, c := step(v, v[0])
	pp, cc := selectionSort(p[1:])
	return append([]int{a}, pp...), c + cc
}

func step(v []int, s int) (int, []int, int) {
	if len(v) == 0 {
		return s, v, 0
	}

	a, p, _ := step(v[1:], s)
	if v[0] > a {
		return a, append([]int{v[0]}, p...), 1
	}
	return v[0], append([]int{s}, v[1:]...), 0
}



Measured memory_bytes: 2768
#include<iostream>

using namespace std;

int main(){
    int N;cin>>N;
    int a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    int fst =0;
    int snd = 0;
    for(int i=0;i<N;i++){
        if(a[i]>=fst){
            snd = fst;
            fst = a[i];
        } else if(a[i]>=snd){
            snd = a[i];
        }
    }
    for(int i=0;i<N;i++){
        if(a[i]==fst){
            cout << snd << endl;
        } else {
            cout << fst << endl;
        }
    }
}

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

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> S(H);
  for(int i=0;i<H;i++){
    cin >> S.at(i);
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(S.at(i).at(j)=='.'){
        int count=0;
        for(int k=-1;k<=1;k++){
          if((i+k<0)||(i+k>=H)){
            continue;
          }
          for(int l=-1;l<=1;l++){
            if((j+l<0)||(j+l>=W)){
              continue;
            }
            if(S.at(i+k).at(j+l)=='#'){
              count++;
            }
          }
        }
        cout << count;
      }else{
        cout << "#";
      }
      if(j==W-1){
        cout << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
a=[int(input()) for _ in range(m)]

INF=1000000007
dp=[1]*(n+1)

for item in a:
    dp[item]=0
for i in range(2,n+1):
    if dp[i]==0:
        continue
    dp[i]=dp[i-2]+dp[i-1]

print(dp[-1]%INF)


Measured memory_bytes: 460020
s = input()

head = int(s[:2])
tail = int(s[2:])

if 0 < head <= 12 and 0 < tail <= 12:
  print("AMBIGUOUS")

elif 0 < head <= 12:
  print("MMYY")

elif 0 < tail <= 12:
  print("YYMM")

else :
  print("NA")


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int n; cin >> n;
	vector<ll> L;
	for (int i=0; i<n; i++) {
		int l; cin >> l;
		L.push_back(l);
	}
	int ret = 0;
	for (int i=0; i<n; i++) {
		for (int j=i+1; j<n; j++) {
			for (int k= j+1; k<n; k++) {
				ll l1, l2, l3;
				l1 = L[i];
				l2 = L[j];
				l3 = L[k];
				if (l1==l2 || l2==l3 || l3==l1) continue;
				else if (l1 >= l2 + l3) continue;
				else if (l2 >= l3 + l1) continue;
				else if (l3 >= l1 + l2) continue;
				else ret++;
			}
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <stdlib.h>
#include <functional>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <set>
#include <queue>
#include <map>
using namespace std;
int main(){
	string s;
	cin>>s;
	int len=s.size(),cs=0;
	for(int i=0;i<len;i++){
		if(s[i]=='S'){
			cs++;
		}
		else{
			cs=max(0,cs-1);
		}
	}
	cout<<cs*2<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;

    return 0;
}





Measured memory_bytes: 256
//#pragma GCC optimize "trapv"
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand rng
#define fios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define M_PI 3.14159265358979323846
typedef long long ll;



int main() {
	//fios;
	int n, x, t;
	cin >> n >> x >> t;
	cout << (n + x - 1) / x * t << endl;

}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;
long long int a = 0, b = 0, c = 0,d=0, x = 0, y = 0, z = 0,n=0,m=0, maxy = 0, mini = 9999, counter = 0, s = 0, endp = 0, checker = 0;
long long int one = 0, two = 0, four = 0;
std::vector <char> vec{}, vecsec{}, vecth{};
long long int iremono[100001],sec[100001],pointx[100001],pointy[100001];
long long int iremono2[100001],check[100001];
std::vector<long long int>kinds{}, ans{}, kaku{};
char moji, moji2;
bool okada = false, okada2 = false;
std::string output, output2, input,input2;
char rev[100001];
unsigned long long int kakunou2[101][101] = {};
unsigned long long int M, A, R, C, H;

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int kaizyo(int k) {
	int sum = 1;
	for (int i = 1; i <= k; ++i)
	{
		sum *= i;
	}
	return sum;
}
int main()
{
	cin >> a;
	rep(i, a) {
		cin >> sec[i+1] >> pointx[i+1] >> pointy[i+1];
	}
	sec[0] = 0; pointx[0] = 0; pointy[0] = 0;
	okada = true;
	for (int i = 1; i <= a; i++) {
		if (std::abs(sec[i - 1] - sec[i]) < (std::abs(pointx[i - 1] - pointx[i]) + std::abs(pointy[i - 1] - pointy[i]))) {
			okada=false;
		}
		else if ((std::abs(pointx[i - 1] - pointx[i]) + std::abs(pointy[i - 1] - pointy[i])- std::abs(sec[i - 1] - sec[i]))%2!=0) {
            okada=false;			
		}
    }
	if (okada) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 2560
n = input()
s = ""
for i in range(1, n + 1):
    x = i
    if(x % 3 == 0):
        s += " " + str(i)
        continue
    while(x):
        if(x % 10 == 3):
            s += " " + str(i)
            break
        x /= 10
print(s)

Measured memory_bytes: 6632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.next();
		int[] count = new int[26];
		for (int i = 0; i < s.length(); i++) {
			count[s.charAt(i) - 'a']++;
		}
		for (int i = 0; i < count.length; i++) {
			if (count[i] == 0) {
				char ans = 'a';
				ans += i;
				System.out.println(ans);
				return;
			}
		}
		System.out.println("None");
		in.close();
	}
}

Measured memory_bytes: 24020
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const inputs = input.trim().split('\n');
const n = Number(inputs.shift());
const adj = inputs.map((s) => s.split(' ').map(Number));

class Node {
  constructor(id) {
    this.id = id;
    this.calculated = false;
    this.children = [];
  }
  add(node) {
    node.parent = this;
    this.children.push(node);
  }
  hasParent() {
    return !!this.parent;
  }
  hasChild() {
    return !!this.children.length;
  }
  getType() {
    return !this.hasParent() ? 'root' : (this.hasChild() ? 'internal node' : 'leaf');
  }
  calc(parent) {
    this.depth = parent ? (parent.depth + 1) : 0;
    this.calculated = true;
  }
  // 深さ優先探索
  dfsChild() {
    this.children.forEach(child => {
      child.calc(this);
      child.dfsChild()
    });
  }
  // 幅優先探索
  bfsChild() {
    this.children.forEach(child => child.calc(this));
    this.children.forEach(child => child.bfsChild());
  }
  toString() {
    return 'node ' + this.id + ': ' + [
      'parent = ' + (this.hasParent() ? this.parent.id : -1),
      'depth = ' + this.depth,
      this.getType(),
      '[' + this.children.map(child => child.id).join(', ') + ']',
    ].join(', ');
  }
}

class Tree {
  constructor() {
    this.map = new Map();
  }
  getNode(id) {
    this.map.has(id) || this.map.set(id, new Node(id));
    return this.map.get(id);
  }
  getRoot() {
    return Array.from(this.map.values()).find(node => !node.hasParent());
  }
  dfs() {
    const root = this.getRoot();
    root.calc();
    root.dfsChild();
  }
  bfs() {
    const root = this.getRoot();
    root.calc();
    root.bfsChild();
  }
  print() {
    for (let i = 0; i < this.map.size; i++) {
      const node = this.map.get(i);
      console.log(node.toString());
    }
  }
}

const tree = new Tree();
adj.forEach(([u, k, ...vk]) => {
  const parent = tree.getNode(u);
  vk.forEach(v => {
    const child = tree.getNode(v);
    parent.add(child);
  });
});

tree.bfs();
tree.print();



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



int main() {
  string s;
  cin >> s;

  int a,b,c;
  a=0;
  b=0;
  c=0;

  for(int i=0; i<3; i++) {
    if (s[i] == 'a') {
      a++;
    } else if (s[i] == 'b') {
      b++;
    } else if (s[i] == 'c') {
      c++;
    }
  }

  if (a == 1 && b == 1 && c == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>
#include <iomanip>
#include <functional>
#include <array>

using namespace std;
using ll = long long;
const ll MOD = (ll)1e9 + 7;

int main()
{
    ll d;
    cin >> d;
    cout << "Christmas";
    for (d = 25 - d; d > 0; d--)
    {
        cout << " Eve";
    }
    cout << endl;
    return 0;
}



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

ll X,Y;

int main(void){
    cin >> X >> Y ;
    int i=0;
    while(X<=Y){X*=2;i++;}
    cout << i << endl;
}


Measured memory_bytes: 256
import Data.List -- sort
import Control.Monad -- replicateM

readInt = read <$> getLine :: IO Integer
arrayInt = map read . words <$> getLine :: IO [Integer]
writeln x = putStrLn $ unwords x :: IO ()

main = do
    n <- readInt
    hs <- arrayInt
    print $ solve hs 0 0


solve [] m s = s
solve (h:hs) m s
    | m <= h = solve hs h (s+1)
    | otherwise = solve hs m s

Measured memory_bytes: 508
import qualified Data.List.Split as S

main :: IO()
main = do
    d <- readDatas
    case d of
        ("0","0") -> return ()
        otherwise -> (tuplePrint $ sort d) >> main
    
tuplePrint :: (String,String) -> IO()
tuplePrint (a,b) = putStrLn $ a ++ ' ':b

readDatas :: IO ((String,String))
readDatas = do
    l <- getLine
    let (a:b:_) = S.splitOn " " l
    return $ (a,b)

sort :: (String,String) ->  (String,String) 
sort (a,b)
    | an > bn = (b,a)
    | otherwise = (a,b)
    where
        an = read a :: Integer
        bn = read b :: Integer


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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll N;
  cin>>N;
  vector<ll> v(N);
  rep(i,N) cin>>v[i];
  sort(v.begin(),v.end());
  vector<ll> s(N);
  rep(i,N) {
    if(i==0) s[i] = v[i];
    else s[i] = s[i-1]+v[i];
  }
  ll ans = 0;
  reverse(s.begin(),s.end());
  reverse(v.begin(),v.end());
  rep(i,N){
    if(i==0) ans++;
    else{
      if(v[i-1]<=s[i]*2LL) ans++;
      else break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4768
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
void fastIO(){
  ios_base::sync_with_stdio(0); cin.tie(0);
}


int main(){
  fastIO();
  string s,t,comp="";
  cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  for(int i=t.length()-1;i>=0;i--){
  	comp+=t[i];
  }
  if(s<comp){
  	cout<<"Yes"<<endl;
  }else{
  	cout<<"No"<<endl;
  }
}








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

int main(void){
    string so,se;
    cin>>so>>se;
    rep(i,se.size()){
        cout<<so[i]<<se[i];
    }
    if(se.size()<so.size())cout<<so.back();
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

int k;
long long n = 1;
long long best = -1;
long long bestSum = 0;

int getSum(long long x) {
  int res = 0;
  while (x > 0) {
    res += x % 10;
    x /= 10;
  }
  return res;
}

int main() { 

  cin >> k;

  while (k) {
    printf("%lld\n", n);
    k--;

    long long cur = n;
    long long p = 1;
    best = -1;
    for (int i = 0; i <= 17; i++) {
      int digit = cur % 10;
      for (int j = digit + 1; j <= 10; j++) {
        long long go = cur - digit + j;
        go = go * p + (p - 1);
        long long sum = getSum(go);
        if (best == -1 || (go * bestSum < sum * best || (go < best && go * bestSum == best * sum))) {
          best = go;
          bestSum = sum;
        }
      }
      p *= 10;
      if (cur == 0) {
        break;
      }
      cur /= 10;
    }

    n = best;
  }

  return 0;
}


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

signed main(){
    string S;
    cin >>S;
    if(S[0]==S[1]||S[1]==S[2]||S[2]==S[3]) cout<<"Bad"<<endl;
    else cout<<"Good"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

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

template<int mod>
struct ModInt{
    int x;

    ModInt() : x(0) {}
    
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    
    ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod)   x -= mod;
        return *this;
    }
    
    ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    
    ModInt operator-() const {return ModInt(-x);}

    ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}

    ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}

    ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}

    ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

    bool operator==(const ModInt &p) const {return x == p.x;}

    bool operator!=(const ModInt &p) const {return x != p.x;}

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const{
        ModInt ret(1), mul(x);
        while(n > 0){
            if(n & 1)   ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a){
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() {return mod;}
};

using modint = ModInt<mod>;

modint dp[3005][3005];

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

    int A, B, C, D;
    cin >> A >> B >> C >> D;
    dp[A][B] = 1;
    for(int i = A; i <= C; ++i){
        for(int j = B; j <= D; ++j){
            dp[i + 1][j] += dp[i][j] * j;
            dp[i][j + 1] += dp[i][j] * i;
            dp[i + 1][j + 1] -= dp[i][j] * i * j;
        }
    }
    cout << dp[C][D] << endl;
}

Measured memory_bytes: 38852
import java.util.Arrays;
import java.util.Scanner;

public 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 i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		int alice = 0;
		int bob = 0;
		Arrays.sort(a);
		for (int i = n - 1; i >= 0; i--) {
			if (i % 2 == (n - 1) % 2) {
				alice = alice + a[i];
			} else {
				bob += a[i];
			}
		}

		System.out.println(alice-bob);
	}
}

Measured memory_bytes: 21840
s=input()
n=len(s)

ans=0

for b in range(1<<(n-1)):
  f=s[0]
  for i in range(n-1):
    if b&(1<<i):
      f+='+'
    f+=s[i+1]
  ans+=sum(map(int,f.split('+')))
print(ans)

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

int main(void)
{
	int a, b, c, d, e, f;
	int min, max;
	int an1, an2, an3, z;
	int flag = 0;
	char str[100000];
	char str2[100000];
	char str3[100000];
	char str4[100000];
	char str5[100000];
	
	scanf("%d", &a);
	
	for (b = 0; b < a; b++) {
		scanf("%s", str);
		scanf("%s", str2);
		flag = 0;
		c = 0;
		d = strlen(str);
		e = strlen(str2);
		memset(str4, '0', 100000);
		if (d > e) {
			min = e;
			max = d;
			strcpy(str4, str);
		}
		else {
			min = d;
			max = e;
			strcpy(str4, str2);
		}
		if (min >= 81 || max >= 81) {
			flag = 1;
		}		
		d--;
		e--;
		an2 = 0;
		an3 = 0;
		for (f = min - 1; f >= 0; f--) {
			an1 = (str[d] - '0') + (str2[e] - '0') + an2;
			if (an1 >= 10) {
				str3[c] = (an1 % 10) + '0';
				an2 = an1 / 10;
			}
			else {
				str3[c] = an1 + '0';
				an2 = 0;
			}
			d--;
			e--;
			c++;
			max--;
			an3++;
		}
		max -= 1;
		while (1) {
			if (max == -1 && an2 == 0) {
				break;
			}
			if (max > -1) {
				an1 = (str4[max] - '0') + an2;
				max--;
			}
			else {
				an1 = an2;
			}
			if (an1 >= 10) {
				str3[c] = (an1 % 10) + '0';
				an2 = an1 / 10;
			}
			else {
				str3[c] = an1 + '0';
				an2 = 0;
			}
			c++;
		}
		an3--;
		str3[c] = '\0';
		z = 0;
		if (strlen(str3) >= 81) {
			flag = 1;
		}
		if (flag == 1) {
			printf("overflow\n");
		}
		
		else {
			for (f = strlen(str3) - 1; f >= 0; f--) {
				printf("%c", str3[f]);
			}
			printf("\n");
		}
		str3[0] = '\0';
	}
	
	return (0);
}

Measured memory_bytes: 708
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <sstream>
#include <numeric>
#include <string>
#include <vector>
#include <cstdio>
#include <bitset>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it++)
#define np(v) next_permutation(v.begin(), v.end())
#define pll pair < long long, long long>
#define all(a) a.begin(), a.end()
#define ull unsigned long long
#define pii pair < int, int >
#define sz(a) (int)a.size()
#define sqr(x) ((x) * (x))
#define y1 stupid_cmath
#define vi vector <int>
#define pb push_back
#define mp make_pair
#define ll long long
#define f first
#define s second

const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);

string s, ans;

int main(){
    ios_base::sync_with_stdio(0), cin.tie(0);
    cin >> s;
    int cur = 0;
    for(int i = 0; i < s.length(); ++i){
        if(s[i] == 'S') cur++;
        if(s[i] == 'T'){
            if(cur != 0) cur--;
            else{
                ans += 'T';
            }
        }
    }
    cout << 2 * ans.length() << endl;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
vector<ll> A;
void input(){
    fast_io();
    cin >> N;
    A = fetch_vec<ll>(N);
}

int solve(){
    sort(A.begin(),A.end());
    ll ans = 0;
    if(N%2){
        ll tmp = 0;
        for (int i = (N+1)/2; i < N; i++)
        {
            tmp += 2*A[i];
        }
        for (int i = 0; i < (N+1)/2; i++)
        {
            tmp -= 2*A[i];
        }
        tmp += A[(N-3)/2];
        tmp += A[(N-1)/2];
        ans = max(ans,tmp);

        tmp = 0;
        for (int i = (N-1)/2; i < N; i++)
        {
            tmp += 2*A[i];
        }
        for (int i = 0; i < (N-1)/2; i++)
        {
            tmp -= 2*A[i];
        }
        tmp -= A[(N+1)/2];
        tmp -= A[(N-1)/2];
        ans = max(ans,tmp);
    }
    else{
        ll tmp = 0;
        for (int i = N/2; i < N; i++)
        {
            tmp += 2*A[i];
        }
        for (int i = 0; i < N/2; i++)
        {
            tmp -= 2*A[i];
        }
        tmp -= A[N/2];
        tmp += A[N/2-1];
        ans = max(ans,tmp);
    }

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

int main()
{
    input();
    solve();
    return 0;
}

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

using namespace std;

int main()
{
    
    vector<int> A, B;
    vector<int> Ans;
    
    int N, M, Num;
    
    cin >> N;
    A.resize(N);
    for(int i = 0; i < N; ++i)
        cin >> A[i];
        
    cin >> M;
    B.resize(M);
    for(int i = 0; i < M; ++i)
        cin >> B[i];
        
    set_union(A.begin(), A.end(), B.begin(), B.end(), inserter(Ans, end(Ans)));
    
    for(const int &x : Ans)
      cout << x << endl;
    
    return 0;
}


Measured memory_bytes: 6560
#include <cstdio>
#include <cstring>

int main() {
    char s[110],ss[110];
    scanf("%s", s);
    int n = strlen(s), flag = 0;
    for(int i = 0; i < n / 2; i++) {
        if(s[i] != s[n-i-1]) {
            flag = 1;
            break;
        }
    }
    if(flag) printf("No\n");
    else {
        int m = (n - 1) / 2;
        for(int i = 0; i < m / 2; i++) {
            if(s[i] != s[m-i-1]) {
                flag = 1;
                break;
            }
        }
        if(flag) printf("No\n");
        else {
            m = (n + 3) / 2 - 1;
            for(int i = n - 1, j = 0; i >= m; i--, j++) ss[j] = s[i];
            for(int i = m, j = 0; i < n; i++, j++) {
                if(ss[j] != s[i]) {
                    flag = 1;
                    break;
                }
            }
            if(flag) printf("No\n");
            else printf("Yes\n");
        }
    }
    return 0;
}


Measured memory_bytes: 128
import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val (a, b) = listOfInt()
    println(Math.max(Math.max(a + b, a - b), a * b))
}

fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

fun println(value : Any) {
    pw.println(value)
}

Measured memory_bytes: 37864
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

	public class Main {
		public static void main(String[] args) {
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));


			  try{


				  String ab;
				  String[] strAry;
				  int a;
				  int b;
				  int c;
				  int yaku;
				  int count=0;

			
				  ab = input.readLine();
			      strAry = ab.split(" ");
			      a=Integer.parseInt(strAry[0]);
		          b=Integer.parseInt(strAry[1]);
		          c=Integer.parseInt(strAry[2]);

				  for(int i=a; i<=b; i++){
					     yaku=c%i;
					     
					     if(yaku==0){
					    	count++;
					    	
					     }


				   }
				  System.out.println(count);


			    }catch(IOException e) {   System.out.println("Exception : " + e);
			    }

		}
	}

Measured memory_bytes: 24436
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int n,a[200005];
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;a[i]-=(i+1),i++)
		scanf("%d",&a[i]);
	sort(a,a+n);
	int b=a[n/2];
	long long ans=0;
	for(int i=0;i<n;i++)
		ans+=abs(a[i]-b);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 896