akhauriyash/Code-Regression huggingface dataset:
<?php namespace Track;

function main($lines) {
  foreach ($lines as $index=>$value) {
    if($value[0] == "0" && $value[1] == "0"){
        break;
    }
    asort($value);
    echo implode(" ", $value),PHP_EOL;
  }
}

$array = array();
while (true) {
  $stdin = fgets(STDIN);
  if ($stdin == "") {
    break;
  }
  $array[] = explode(" ",rtrim($stdin));
}
main($array);



Measured memory_bytes: 10724
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  for(int j=0;j<W+2;j++){
    cout<< "#";
  }
  cout << endl;
  for(int i=0;i<H;i++){
    string a;
    cin >> a;
    cout << "#" << a << "#" << endl;
  }
  for(int k=0;k<W+2;k++){
    cout<<"#";
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

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

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/


int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N)cin >> A[i];
    sort(all(A));
    vector<l_l> v;
    rep(i,N)rep(j,N){
        if(i == j)continue;
        v.emplace_back(i,j);
    }
    ll ans = 0;
    for(auto [i, j] : v){
        ll l = abs(A[i]-A[j]);
        ll r = abs(A[i]+A[j]);
        dump(i, j);
        dump(l+1, r);
        ll cnt = lower_bound(all(A), r) - lower_bound(all(A), l+1);
        if(l < A[i] && A[i] < r)cnt--;
        if(l < A[j] && A[j] < r)cnt--;
        dump(cnt);
        ans += cnt;
    }
    cout << ans/6 << endl;
}


Measured memory_bytes: 68980
N = int(input())
d = list(map(int, input().split()))

dic = {}

for e in d :
    if e not in dic :
        dic[e] = 1
    else :
        dic[e] += 1

dic = sorted(dic.items(), key=lambda x:x[0])

#print(dic)

sum = 0
ancker = 0
tmp = 0
ans = True

for i in range(len(dic)):
    sum += dic[i][1]
    if sum == N / 2 :
        ancker = i
        break;
    if sum > N / 2 :
        ans = False
        break
#print(ancker)

if not ans :
    print(0)
else :
    print(dic[ancker+1][0] - dic[ancker][0])


Measured memory_bytes: 15712
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long int ll;
int main()
{
  int n;
  cin>>n;
  string s="ACL";
  string a="";
  for(int i=0;i<n;i++)
  {
    a+=s;
  }
  cout<<a;
}

Measured memory_bytes: 3628
using System;
using System.Linq;

class Solution
{
    static int GCD(int m, int n)
    {
        if (m < n)
        {
            return GCD(n, m);
        }

        while (n != 0)
        {
            var t = n;
            n = m % n;
            m = t;
        }
        return m;
    }

    static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        int n = vals[0];
        int k = vals[1];
        var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        if (k <= a.Max())
        {
            // 全ての最大公約数
            var gcd = a.Aggregate((g, next) => GCD(g, next));
            if (k % gcd == 0)
            {
                Console.WriteLine("POSSIBLE");
                return;
            }
        }

        Console.WriteLine("IMPOSSIBLE");
    }
}

Measured memory_bytes: 19936
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan =new java.util.Scanner(System.in);
		String  n = scan.next();
		String week[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
		int ans = 0;

		for(int i=0;i<7;i++) {
		 if(n.equals(week[i])) {
			ans = 7-i;
			break;
		 }
		}

		System.out.println(ans);
	}

}


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

int main() {
  int n, m, l;
  cin >> n >> m >> l;
  vector<int64_t> a(n * m), b(m * l), c(n * l, 0);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a.at(i * m + j);
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < l; j++) {
      cin >> b.at(i * l + j);
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      for (int k = 0; k < m; k++) {
        c.at(i * l + j) += a.at(i * m + k) * b.at(k * l + j);
      }
    }
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {
      if (j != l - 1)
        cout << c.at(i * l + j) << " ";
      else
        cout << c.at(i * l + j);
    }
    cout << endl;
  }
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll int64_t
#define all(v) v.begin(), v.end()
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)

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

  int D=B/A;

  if(D>=C) cout << C << endl;

  else cout << D << endl;
  
  return 0;
}

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

typedef long long int ll;
#define INF 1<<20

struct Node {
	public:
		vector <int> edge_to; //接続されているノードID
		vector <int> edge_cost; //エッジのコスト
		bool done;
		int id, cost;
};

bool operator < (const Node &a, const Node &b){
	return (a.cost < b.cost);
}
bool operator > (const Node &a, const Node &b){
	return (a.cost > b.cost);
}


vector<Node> node;
vector<int> ans;
void dijkstra() {
	priority_queue<Node, vector<Node>, greater<Node> > pq;
	node[1].cost = 0;
	pq.push(node[1]);
	while(!pq.empty()){
		Node n = pq.top(); pq.pop();
		for (int i = 0; i < n.edge_to.size(); i++) {
			if (!node[n.edge_to[i]].done) {
				if (node[n.edge_to[i]].cost > n.cost + n.edge_cost[i]) {
					node[n.edge_to[i]].cost = n.cost + n.edge_cost[i];
				}
				pq.push(node[n.edge_to[i]]);
			}
		}
		node[n.id].done = true;
		ans.push_back(n.id);
	}
}

int main() {
	int n, m;
	scanf("%d %d",&n ,&m);
	n++;
	node.resize(n);
	for (int i = 1; i < n; i++) {
		node[i].id = i;
		node[i].done = false;
		node[i].cost = INF;
	}
	for (int i = 0; i < m; i++) {
		int a, b;
		scanf("%d %d",&a, &b);
		node[a].edge_to.push_back(b);
		node[a].edge_cost.push_back(1);
	}

	dijkstra();
	if (node[n-1].cost == 2) {
		printf("POSSIBLE\n");
	} else {
		printf("IMPOSSIBLE\n");
	}
}


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

int N;
const int MAX_N = 2.0e5 + 100;
int X[MAX_N];

int main() {
    cin >> N;
    int X_sorted[N];
    for (int i = 0; i < N; i++) {
        cin >> X[i];
        X_sorted[i] = X[i];
    }    
    
    sort(X_sorted, X_sorted+N);

    int median_l = X_sorted[(N-1)/2];
    int median_r = X_sorted[N/2];

    for (int i = 0; i < N; i++) {
        if (X[i] <= median_l) {
            cout << median_r << endl;
        }
        else {
            cout << median_l << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3712
// Doubly Linked List
#include <stdio.h>
#include <stdlib.h>

#define MAX 2000000

struct Node{
  int key;
  struct Node *prev;
  struct Node *next;
};
struct Node *nil; // 双方向リストの先頭のノードを指す番兵

// 双方向リストの初期化 //
void init(){
  nil = (struct Node *)malloc(sizeof(struct Node));
  nil->next = nil;
  nil->prev = nil;
}

// 与えられたkeyを持つノードを探し、そのポインタを返す //
struct Node* listSearch(int key){
  struct Node *x;
  x = nil->next; // 番兵の次の要素からたどる
  while(x != nil && x->key != key){
    x = x->next;
  }
  return x;
}

// 双方向リストへの要素の挿入 //
void insert(int key){
  struct Node *x = (struct Node *)malloc(sizeof(struct Node)); // xを持つノードを生成
  x->key = key;
   // 番兵の直後に要素を追加 //
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

// 双方向リストの要素の削除 //
void delete(struct Node *x){
  if(x == nil)return; // xが番兵の場合
  x->prev->next = x->next;
  x->next->prev = x->prev;
  free(x);
}

// 先頭のノードを削除 //
void deleteFirst(){
  delete(nil->next);
}

// 双方向リストの末尾の要素を削除 //
void deleteLast(){
  delete(nil->prev);
}

int main(){
  int i, n, key;
  char com[20];
  struct Node *x;
  
  init(); // リストの初期化
  
  scanf("%d", &n);
  for(i=0; i < n; i++){
    //printf("%d\n", i);
    scanf("%s", com);
    if(com[0] == 'i'){
      scanf("%d", &key);
      insert(key);
    }
    else if(com[0] == 'd' && com[6] == 'F')deleteFirst();
    else if(com[0] == 'd' && com[6] == 'L')deleteLast();
    else{
      scanf("%d", &key);
      delete(listSearch(key));
    }
  }
  x = nil->next;
  while(x != nil){
    if(x->prev != nil)printf(" ");
    printf("%d", x->key);
    x = x->next;
  }
  printf("\n");
  return 0;
}




Measured memory_bytes: 32932
#!/usr/bin/env python3
import sys


def ilog(b: int, x: int):
    if b == 1:
        return 0
    lb = 0
    rb = x.bit_length()
    while lb + 1 < rb:
        m = (lb + rb) // 2
        if b ** m <= x:
            lb = m
        else:
            rb = m
    return lb


def solve(X: int):
    print(max(
        b ** ilog(b, X)
        for b in range(1, X + 1)
        if b ** 2 <= X
    ))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=9e18;
typedef pair<ll,ll> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll N,W,w[105]={},v[105]={},dp[105][100005]={};
  cin >> N >> W;
  for(int i=1; i<=N; i++) {
    cin >> w[i] >> v[i];
  }
  for(int i=1; i<=N; i++) {
    for(int j=0; j<=W; j++) {
      if(j-w[i]>=0) {
        dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
      }
      else {
        dp[i][j]=dp[i-1][j];
      }
    }
  }
  cout << dp[N][W] << endl;
}

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

int main()
{
    int n,x;
    cin>>n>>x;
    int i,j,k,v,b,sum=0;
    int a[105];
    for(i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(j=0;j<n;j++)
           sum=sum+a[j];
           if(sum>x)
           {
               for(k=0;k<n;k++)
               {
                   sum=sum+a[k];
                   if(sum>x)
                    break;
               }
           }
          else
          {
                v=x-sum;
                b=v/a[0];
                k=n+b;
          }
          cout<<k<<endl;

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &e : a) {
    cin >> e;
  }
  vector<int> v = {1};
  for (int i = 1; i < n; i++) {
    if (a[i - 1] == a[i]) {
      v[v.size() - 1]++;
    } else {
      v.push_back(1);
    }
  }
  int m = 0;
  for (auto e : v) {
    m += e / 2;
  }
  cout << m << endl;
  return 0;
}


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

class union_find {
private:
    vector<int> parent;
public:
    union_find(int n) : parent(n, -1) {}
    ~union_find() {}
    void link(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (parent[x] > parent[y])
            swap(x, y);
        parent[x] += parent[y];
        parent[y] = x;
    }
    int find(int x) {
        if (parent[x] < 0)
            return x;
        return parent[x] = find(parent[x]);
    }
    int count(int x) {
        return -parent[find(x)];
    }
    bool linked(int x, int y) {
        return find(x) == find(y);
    }
};

int main()
{
    int N, M; cin >> N >> M;
    union_find uf(N+1);
    for (int i = 0; i < M; i++) {
        int x, y, z; cin >> x >> y >> z;
        uf.link(x, y);
    }
    set<int> s;
    for (int i = 1; i <= N; i++) {
        s.insert(uf.find(i));
    }

    cout << s.size() << endl;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;
const int DV = 998244353;

int N, M;
string S;
vi va, vb;
int nmx = -INF;
void input() {
  ;
  cin >> N;
  va.resize(N);
  rep(i, 0, N - 1) {
    cin >> va[i];
    chmax(nmx, va[i]);
  }

  ;
}

long long pow_mod(long long a, long long b) {
  long long ans = 1;
  long long mul = a;
  //
  for (; b; mul = (mul * mul) % DV) {
    if ((b & 1) == 1) ans = (ans * mul) % DV;
    b >>= 1;
  }
  return ans;
}
void solve() {
  int ans = 1;
  map<int, int> mp;
  // rep(i, 0, N - 1) { debug2(i, mp[i]); }
  rep(i, 0, N - 1) { mp[va[i]]++; }

  if (va[0] != 0) {
    cout << 0 << endl;
    return;
  }
  if (mp[0] != 1) {
    cout << 0 << endl;
    return;
  }
  rep(i, 1, nmx) {
    if (mp[i] == 0) {
      cout << 0 << endl;
      return;
    }
  }

  rep(i, 1, nmx) {
    // debug(mp[va[i - 1]]);
    // debug(mp[va[i]]);
    // debug(pow_mod(mp[va[i - 1]], mp[va[i]]));
    ans *= pow_mod(mp[i - 1], mp[i]);
    //    debug2(i, ans);
    ans %= DV;
  }
  // debug(pow_mod(2, 3));
  // debug(pow_mod(2, 1));
  // debug(pow_mod(3, 4));
  // debug(pow_mod(3, 2));
  cout << ans << endl;

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

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define inf1 INT_MAX
#define inf2 LLONG_MAX
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define sbit __builtin_popcount
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define rit(it,x) for(auto it=x.begin();it!=x.end();it++)
#define cases(t) int t; cin>>t; rep(casn,1,t+1)
#define fill(a,b) memset(a,b,sizeof(a))
#define dbg(x) cerr<<#x<<" "<<x<<endl;
#define dbga(arr,n) cerr<<#arr<<": "; rep(tt,0,n)cerr<<arr[tt]<<" "; cerr<<endl;
#define infile ifstream fin; fin.open("input.txt")
#define outfile ofstream fout; fout.open("output.txt")
#define vec vector<int>
#define pii pair<int,int>
#define plii pair<ll,int>
#define pll pair<ll,ll>
#define p_queue priority_queue< plii,vector< plii >,greater< plii > > 
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define sp(x) setprecision(x)
#define si(x) scanf("%d",&x)
#define sc(x) scanf("%c",&x)
#define sl(x) scanf("%lld",&x)
#define sst(x) scanf("%s",x)
#define pl(x) printf("%lld\n",x)
#define pi(x) printf("%d\n",x)
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

inline ll binex(ll a,ll b)
{
    ll ans=1,temp=a%mod;
    while(b!=0){
        if(b&1) ans=(ans*temp)%mod;
        temp=(temp*temp)%mod;
        b=b>>1;
    }
    return ans;
}

inline string solve(string a,string b)
{
    int n=sz(a),m=sz(b),dp[n+1][m+1];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i-1]==b[j-1]) dp[i][j]=1+dp[i-1][j-1];
            else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
    }
    if(dp[n][m]==0) return " ";
    string s;
    int i=n,j=m;
    while(sz(s)!=dp[n][m]){
        if(a[i-1]==b[j-1]){
            s.pb(a[i-1]); 
            i--; j--;
        }
        else if(dp[i-1][j]>dp[i][j-1]) i--;
        else j--;
    }
    reverse(all(s));
    return s;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a,b; cin>>a>>b;
    cout<<solve(a,b)<<endl;
}

Measured memory_bytes: 35584
//B - i18n: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    string s, ans = "";
    int sz;
    cin >> s;
    sz = s.size() - 2;
    ans += s[0];
    ans += to_string(sz);
    ans += s[s.size()-1];
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N,M;
    cin >> N >> M;
    vector<string> A(N);
    vector<string> B(M);
    REP(i,N) cin >> A[i];
    REP(i,M) cin >> B[i];
    for(int i = 0; i <= N-M; i++) {
        for(int j = 0; j <= N-M; j++) {
            bool ok = true;
            for(int k = 0; k < M; k++) {
                for(int l = 0; l < M; l++) {
                    if(B[k][l] != A[i+k][j+l]) ok = false;
                }
            }
            if(ok) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
from string import ascii_lowercase
# ----------

INF = float("inf")
MOD = 10 ** 9 + 7
# ----------


n = int(input())
S = []
for i in range(n):
    S.append(input().strip())

cmap = defaultdict(lambda :INF)

for s in S:
    for alpha in ascii_lowercase:
        cnt = s.count(alpha)
        cmap[alpha] = min(cnt, cmap[alpha])

ans = ''
for alpha in ascii_lowercase:
    ans += alpha * cmap[alpha]

print(ans)


Measured memory_bytes: 3768
#include <stdio.h>

int main(){
	int i,j,n,a[1000],v;
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++) scanf("%d",&a[i]);
	for(i=0;i<n-1;i++) printf("%d ",a[i]);

	printf("%d\n",a[n-1]);
	
	for(i=1;i<=n-1;i++){
		v=a[i];
		j=i-1;
		while(j>=0 && a[j]>v){
			a[j+1]=a[j];
			j--;
		}
		a[j+1]=v;
		
		for(j=0;j<n-1;j++) printf("%d ",a[j]);

		printf("%d\n",a[n-1]);
	}
	
	return 0;
}


Measured memory_bytes: 2124
import fractions
A, B, K = map(int, input().split())

answer = []
ans = 1
max_ans = fractions.gcd(A, B)
while ans <= max_ans:
    if A % ans == 0 and B % ans == 0:
        answer.append(ans)
        ans += 1
    else:
        ans += 1
answer = sorted(answer, reverse=True)

print(answer[K-1])


Measured memory_bytes: 5304
#![allow(unused_imports)]

use std::{i32, i64, u32, u64, usize, f64};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::io::{stdout, Write, BufWriter};
use std::mem::{swap};
use maplit::*;
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!{
        n: usize,
        ss: [Chars; n],
    }
    let march = ['M', 'A', 'R', 'C', 'H'];
    let mut map = hashmap!{
        'M' => 0,
        'A' => 0,
        'R' => 0,
        'C' => 0,
        'H' => 0,
    };
    for s in ss {
        let ini = s.first().unwrap();
        if march.contains(&ini) { *map.get_mut(ini).unwrap() += 1u64; }
    }
    let m = map[&'M'];
    let a = map[&'A'];
    let r = map[&'R'];
    let c = map[&'C'];
    let h = map[&'H'];
    println!("{}", m*(a*(r+c+h)+r*(c+h)+c*h) + a*(r*(c+h)+c*h) + r*c*h);
}


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

using namespace std;

template<typename T>
void fill_all(T& a, const T& b)
{
	a = b;
}
template<typename T, size_t N, typename U>
void fill_all(T(& a)[N], const U& b)
{
	for (auto& i : a)
	{
		fill_all(i, b);
	}
}


int64_t dp[51];
int64_t func(int i)
{
	if (i == 0) {
		return 1;
	}
	if (dp[i] != -1) {
		return dp[i]
			;
	}
	auto a = func(i - 1);
	return dp[i] = 1 + a * 2;
}
int64_t numdp[51];
int64_t numfunc(int i)
{
	if (i == 0) {
		return 1;
	}
	if (numdp[i] != -1) {
		return numdp[i]
			;
	}
	auto a = numfunc(i - 1);
	return numdp[i] = 3 + a * 2;
}
int64_t func2(int i, int64_t x)
{
	if (x == 0) {
		return 0;
	}
	if (i == 0) {
		return 1;
	}
	auto num2 = numfunc(i);
	if (num2 == x) {
		return func(i);
	}

	int64_t res = 0;
	auto num = numfunc(i - 1);
	if (num+2 <= x) {
		res += func(i - 1) + 1 + func2(i - 1, x - (num + 2));
	}
	else if (num + 1 == x) {
		res += func(i - 1);
	}
	else {
		res += func2(i - 1, x-1);
	}
	return res;
}
int main() {
	fill_all(dp, (int64_t)-1);
	fill_all(numdp, (int64_t)-1);
	int64_t N, X;
	cin >> N >> X;
	cout << func2(N, X) << endl;
}

#if 0
int P, R, Q;
int r_num[300];
std::vector<int> resolved[300][101];

int main()
{
	cin >> P >> R >> Q;
	for (int i = 0; i < R; i++)
	{
		cin >> r_num[i];
	}



}
#endif

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

using namespace std;

#define ll long long
#define endl '\n'
#define pb push_back
#define inf 1e9

int main ()
{
    int n, h; cin >> h >> n;
    for (int i = 0; i < n; i++)
    {
        int x; cin >> x;
        h -= x;
    }

    cout << (h <= 0 ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)

	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	var A = make([]int, num)

	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " ") {
		A[i], _ = strconv.Atoi(v)
	}

	sc.Scan()

	for sc.Scan() {
		inputs := strings.Split(sc.Text(), " ")
		start, _ := strconv.Atoi(inputs[0])
		end, _ := strconv.Atoi(inputs[1])
		k, _ := strconv.Atoi(inputs[2])

		result := 0
		for _, v := range A[start:end] {
			if v == k {
				result++
			}
		}
		fmt.Println(result)
	}
}



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

typedef long long ll;
const ll MOD = 1e9+7;
const ll INF = 1e18;
const int N = 2e5+5;
const ll M = 1e6+5;

template<int SZ>
struct LiChao_min{
    struct Line{
        ll k,m;
        Line(){k=0,m=0;}
        Line(ll _k,ll _m){k=_k,m=_m;}
        ll Get(ll x){return k*x+m;}
    };

    struct node{
        node *l, *r;
        Line p;

        node(){p=Line(),l=nullptr,r=nullptr;}
        node(ll k,ll m){p=Line(k,m),l=nullptr,r=nullptr;}
        node(Line _p){p=_p,l=nullptr,r=nullptr;}
    };
    typedef node* pnode;

    pnode root = nullptr;

    void Reset(){root=nullptr;}
    void Set(ll k,ll m){
        Line p = Line(k,m);
        Set(root,-SZ,SZ,p);
    }
    void Set(Line p){
        Set(root,-SZ,SZ,p);
    }
    ll Get(ll x){return Get(root,-SZ,SZ,x);}

    void Set(pnode &v,ll ss,ll se,Line t){
        if(!v){
            v = new node(t);
            return;
        }

        ll vss=v->p.Get(ss),vse=v->p.Get(se);
        ll tss=t.Get(ss),tse=t.Get(se);

        if(t.Get(ss)<v->p.Get(ss)&&t.Get(se)<v->p.Get(se)){v->p=t;return;}
        if(t.Get(ss)>=v->p.Get(ss)&&t.Get(se)>=v->p.Get(se))return;

        ll mid=(ss+se)>>1LL;
        /*
        int64_t trl = nd->f.eval(l), trr = nd->f.eval(r);
		int64_t vl = v.eval(l), vr = v.eval(r);

		if(trl <= vl && trr <= vr) return;
		if(trl > vl && trr > vr) { nd->f = v; return; }

		int mid = (l + r) >> 1;
		if(trl > vl) swap(nd->f, v);
		if(nd->f.eval(mid) < v.eval(mid)) insert(v, mid + 1, r, nd->r);
        else swap(nd->f, v), insert(v, l, mid, nd->l);
        */
        if(vss>tss)swap(v->p,t);
        if(v->p.Get(mid)<t.Get(mid))Set(v->r,mid+1,se,t);
        else {
            swap(v->p,t);
            Set(v->l,ss,mid,t);
        }

        /*
        if(t.Get(ss)>v->p.Get(ss)&&t.Get(mid)<v->p.Get(mid)){
            swap(t,v->p);
            Set(v->l,ss,mid,t);
        }else if(t.Get(ss)>v->p.Get(ss)&&t.Get(mid)>v->p.Get(mid)){
            Set(v->r,mid+1,se,t);
        }else if(t.Get(ss)<v->p.Get(ss)&&t.Get(mid)>v->p.Get(mid)){
            Set(v->l,ss,mid,t);
        }else{
            swap(t,v->p);
            Set(v->r,mid+1,se,t);
        }
        */
    }

    ll Get(pnode &v,ll ss,ll se,ll x){
        if(v==nullptr)return INF;
        if(ss==se)return v->p.Get(x);

        ll mid=(ss+se)>>1LL;
        if(x<=mid)return min(v->p.Get(x),Get(v->l,ss,mid,x));
        return min(v->p.Get(x),Get(v->r,mid+1,se,x));
    }
};


LiChao_min<M> tree;
int n;
ll c,h[N],dp[N];

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>c;

    for(int i=1;i<=n;i++)cin>>h[i];

    dp[1]=0LL;
    //tree.init(M);
    //tree.add_line(-2LL*h[1],1LL*h[1]*h[1]);
    tree.Set(-2LL*h[1],1LL*h[1]*h[1]);

    for(int i=2;i<=n;i++){
        dp[i]=tree.Get(h[i])+h[i]*h[i]+c;
        //dp[i]=tree.query(h[i])+h[i]*h[i]+c;
        tree.Set(-2LL*h[i],dp[i]+1LL*h[i]*h[i]);
        //tree.add_line(-2LL*h[i],dp[i]+1LL*h[i]*h[i]);
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 12800
S = raw_input()
M = 10**9+7

def count(W):
  N = len(S)
  T1 = [0]*N
  for i in range(N):
    T1[i] = (0 if i==0 else T1[i-1]) + int(S[i]==W[0])
  T2 = [0]*N
  for i in range(N)[::-1]:
    T2[i] = (0 if i==N-1 else T2[i+1]) + int(S[i]==W[2])
  ans = 0
  for i in range(1,N-1):
    if S[i]==W[1]:
      ans += T1[i-1]*T2[i+1]
      ans %= M
  return ans

Q = S.count("?")
print (
  count("ABC")*pow(3,Q,M) +
  count("AB?")*pow(3,max(Q-1,0),M) +
  count("A?C")*pow(3,max(Q-1,0),M) +
  count("A??")*pow(3,max(Q-2,0),M) +
  count("?BC")*pow(3,max(Q-1,0),M) +
  count("?B?")*pow(3,max(Q-2,0),M) +
  count("??C")*pow(3,max(Q-2,0),M) +
  count("???")*pow(3,max(Q-3,0),M))%M


Measured memory_bytes: 13800
package main

import "fmt"

func main() {
	var a, b, c, x int
	fmt.Scanln(&a)
	fmt.Scanln(&b)
	fmt.Scanln(&c)
	fmt.Scanln(&x)

	// fmt.Println(a, b, c, x)

	result := moneySum(a, b, c, x)
	fmt.Println(result)
}

func moneySum(a, b, c, x int) int {
	// fmt.Printf("a=%d, b=%d, c=%d, x=%d\n", a, b, c, x)
	if x == 0 {
		return 1
	} else if x < 0 {
		return 0
	}

	result := 0
	if a > 0 {
		result += moneySum(a-1, b, c, x-500)
	}
	if b > 0 {
		result += moneySum(0, b-1, c, x-100)
	}
	if c > 0 {
		result += moneySum(0, 0, c-1, x-50)
	}
	return result
}


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

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

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  long long D;
  cin >> N >> D;
  
  long long x,y;
  int count=0;
  for(int i=0;i<N;i++){
    cin >> x >> y;
    if(x*x+y*y<=D*D) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
const int P = 1000000007;
int n, i, a[200005];
i64 tot, ans;
int main() {
    scanf("%d", &n);
    for (i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (i = n; i > 0; --i) {
        ans = (ans + tot * a[i]) % P;
        tot = (tot + a[i]) % P;
    }
    printf("%lld", ans);
}

Measured memory_bytes: 4588
function main()
	lines=readlines()
	N,M=map(x->parse(Int,x),split(shift!(lines)))
	A=Array{Pair{Int,Int}}(0)
	for s=lines
		a,b=map(x->parse(Int,x),split(s))
		push!(A,a=>b)
	end
	reverse!(A)
	size=ones(Int,N)
	parent=collect(1:N)
	function find(u)
		if u==parent[u]
			u
		else
			parent[u]=find(parent[u])
		end
	end
	ans=[]
	now=div(N*(N-1),2)
	for (a,b)=A
		push!(ans,now)
		a=find(a)
		b=find(b)
		if a!=b
			now-=size[a]*size[b]
			if size[a]>size[b]
				size[a]+=size[b]
				parent[b]=a
			else
				size[b]+=size[a]
				parent[a]=b
			end
		end
	end
	for c=reverse(ans)
		println(c)
	end
end
main()


Measured memory_bytes: 178500
q = gets.to_i
q.times{
	hash = {}
	n = gets.to_i
	loop {
		if hash[n] 
			puts -1
			break
		end
		hash[n] = 0
		
		a = n.to_s.split("")
		if a.size == 1
			puts hash.size - 1
			break 
		else
			n = (0..a.size-2).map{|i|
				a[0..i].join.to_i * a[i+1..-1].join.to_i	
			}.max
		end
	}
}

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

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

    string s, t;
    cin >> s >> t;

    vector<vector<int>> chars(26);
    int n = s.size();
    int m = t.size();
    for (int i = 0; i < n; i++) {
        chars[s[i] - 'a'].push_back(i);
    }
    for (int i = 0; i < n; i++) {
        chars[s[i] - 'a'].push_back(i + n);
    }
    int64_t ret = 0;
    int p = 0;
    for (int i = 0; i < m; i++) {
        int ti = t[i] - 'a';
        if (chars[ti].empty()) {
            cout << -1 << endl;
            return 0;
        }
        p = *lower_bound(chars[ti].begin(), chars[ti].end(), p) + 1;
        if (p >= n) {
            p -= n;
            ret += n;
        }
    }
    ret += p;

    cout << ret << endl;

    return 0;
}


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

using namespace std;


const int N = 30;


int a[N], b[N], c[N];


int main()
{
	int n;
	cin >> n;
	
	for (int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++)
		scanf("%d", &b[i]);
	for (int i = 1; i < n; i++)
		scanf("%d", &c[i]);
	
	long long Ans = 0;
	for (int i = 1; i <= n; i++)
		Ans += b[a[i]];
	for (int i = 1; i <= n; i++)
		if (a[i] + 1 == a[i+1])
			Ans += c[a[i]];
	
	printf("%lld\n", Ans);
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  std::string s,t;
  std::cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(),t.rend());

  std::cout << (s < t ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  string str;
  cin >> str;
  int q;
  cin >> q;
  string comm;
  int v1, v2;
  for (int i = 0; i < q; i++) {
    cin >> comm;
    if (comm == "replace") {
      string re;
      cin >> v1 >> v2 >> re;
      str.replace(v1, v2 - v1 + 1, re);
    } else if (comm == "reverse") {
      cin >> v1 >> v2;
      string sub = str.substr(v1, v2 - v1 + 1);
      reverse(sub.begin(), sub.end());
      str.replace(v1, v2 - v1 + 1, sub);
    } else if (comm == "print") {
      cin >> v1 >> v2;
      cout << str.substr(v1, v2 - v1 + 1) << endl;
    }
  }
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define pp pair<ll,ll>
#define mp make_pair
#define PI acos(-1.0)
#define all(v) v.begin(),v.end()
#define pb push_back
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FREV(i,a,b) for(i=a;i>=b;i--)
#define FORI(a) for(auto it=a.begin();it!=a.end();it++)
#define READ(a,i,n) FOR(i,0,n) { sll(a[i]);}
#define DEBUG(x) cerr<<"In file "<< __FILE__ <<" at line "<< __LINE__ <<" :: "<< #x <<" = "<<x<<endl
#define sll(n) scanf("%lld", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define INF 1e18
#define MOD 1000000007

using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t,d;
    cin>>t>>d;
    int count=0;
    while(t--)
    {
      double x,y;
      cin>>x>>y;
      if(sqrt((x*x)+(y*y))<=d)
        count++;
    }
  cout<<count;
}


Measured memory_bytes: 3816
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>

using namespace std;
int main() {
    unsigned  long long n; cin>>n;
    string ans{};
    while (n) {
        n--;
        unsigned long long r = n % 26;
        ans.push_back(r + 'a');
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3604
fun main(args: Array<String>) {
  val X = readLong()

  var now = 100L
  for (i in 1 until Int.MAX_VALUE) {
    now += now / 100
    if (X <= now) {
      println(i)
      return
    }
  }
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 34492
n,k=map(int,input().split())
d={i+1:0 for i in range(n)}

for i in range(k):
    n=input()
    q=list(map(int,input().split()))
    for j in q:
        d[j]+=1
ans=0
for i in d.values():
    if i==0:
        ans+=1
print(ans)

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

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n,a,b;
	cin >> n >> a >> b;
	ll x,y;
	x=min(a,b);
	y=max(0LL,a+b-n);
	cout << x << " " << y;
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * overflow (ll vs int?)
 * * array bounds
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


Measured memory_bytes: 256
// vim: foldmethod=marker
#include <iostream> // cout, endl, cin{{{
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
typedef long long ll;/*}}}*/

int main(int argc, char *argv[])
{
  int a, b;
  cin >> a;
  cin >> b;

  int ans;
  ans = 6 - a - b;

  cout << ans << endl;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int MOD = 1e9 + 7;

void add(int &a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
}

int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}

int dp[4017][2017][2];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,m,kk; cin>>n>>m>>kk;
	dp[0][0][0] = 1;
	for(int i = 0; i < (n+m-1)/(kk-1); i++)
	{
		for(int j = 0; j <= n; j++)
		{
			for(int k = 0; k < 2; k++)
			{
				int v = dp[i][j][k];
				if(v==0) continue;
				for(int z=0;z<kk;z++)
				{
					int newk=(z!=0);
					int newi=i+1;
					int newj=j+z;
					if(newj>n) continue;
					add(dp[newi][newj][newk],v);
				}
			}
		}
	}
	int ans=0;
	for(int i=1;i<=(n+m-1)/(kk-1);i++)
	{
		for(int j = n; j >= 0; j-=(kk-1))
		{
			int sj = (kk-1)*i - j;
			if(sj>=0&&sj<=m-1&&(m-1-sj)%(kk-1)==0)
			{
				add(ans,dp[i][j][1]);
			}
		}
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 61824
#include"bits/stdc++.h"
using namespace std;
 
#define MAX 502
#define ull unsigned long long int 
int n;
int ty_r[MAX];
ull val_r[MAX];
int ty_c[MAX];
ull val_c[MAX];
bool tmp[MAX][MAX];
int emp[MAX];
ull ans[MAX][MAX];
void transpose(){
	for(int i=0;i<n;i++){
		for(int j=0;j<i;j++)swap(tmp[i][j],tmp[j][i]);
		swap(val_r[i],val_c[i]);
		swap(ty_r[i],ty_c[i]);
	}
}
void fi(long long int pos){
	memset(emp, 0, sizeof(emp));
	for (int j = 0; j < n; j++) {
		if (ty_c[j] == false) {
			emp[j] = n - 1;
			for (int k = 0; k < n; k++) emp[j]-=tmp[k][j];
		}
	}
	for (int i = 0; i < n; i++) {
		if (ty_r[i]) {
			if (((val_r[i]) >> pos) & 1ULL) {
				bool valid = false;
				for (int j = 0; j < n; j++) valid|=tmp[i][j];
				if (valid == false) {
					for (int j = 0; j < n; j++) {
						if (emp[j]>0) { 
							emp[j]--;
							tmp[i][j] = true;
							break;
						}
					}
				}
			}
		}
	}
}
void solve(ull pos) {
	memset(tmp, false, sizeof(tmp));
	for (int i = 0; i < n; i++) {
		if (ty_r[i]==false&&((val_r[i]) >> pos) & 1ULL) for (int j = 0; j < n; j++) tmp[i][j] = 1;
		if(ty_c[i]==false&&((val_c[i]) >> pos) & 1ULL) for (int j = 0; j < n; j++) tmp[j][i] = 1;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (ty_r[i] == ty_c[j]) {
				if (ty_r[i] == false) tmp[i][j] = ((val_r[i] >> pos) & 1ULL)| ((val_c[j] >> pos) & 1ULL);
				else tmp[i][j] = ((val_r[i] >> pos) & 1ULL)& ((val_c[j] >> pos) & 1ULL);
			}
		}
	}
	fi(pos);
	transpose();
	fi(pos);
	transpose();
	for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) ans[i][j] += ((ull)(tmp[i][j]) << pos);
}
void fo(){
	puts("-1");
	exit(0);
}
void check() {
	for (int i = 0; i < n; i++) {
		ull AN = -1; ull O = 0; ull AN2 = -1; ull O2 = 0;
		for (int j = 0; j < n; j++) {
			AN &= ans[i][j];
			O |= ans[i][j];
			AN2&=ans[j][i];
			O2|=ans[j][i];
		}
		if (ty_r[i] == false&&AN != val_r[i]) fo();
		else if(ty_r[i] == true&&O!=val_r[i]) fo();
		if (ty_c[i] == false&&AN2 != val_c[i]) fo();
		else if (ty_c[i] && O2 != val_c[i]) fo();
	}
}
int main() {
		cin>>n;
		for (int i = 0; i < n; i++) scanf("%d", &ty_r[i]);
		for (int j = 0; j < n; j++) scanf("%d", &ty_c[j]);
		for (int i = 0; i < n; i++) scanf("%llu", &val_r[i]);
		for (int j = 0; j < n; j++) scanf("%llu", &val_c[j]);
		for (int i = 0; i < 64; i++) solve(i);
		check();
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (j)printf(" ");
				printf("%llu", ans[i][j]);
			}
			puts("");
		}
	return 0;
}


Measured memory_bytes: 7784
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

ans = 0
bonus = n
for a in A:
	a -= 1
	ans += B[a]
	if a-1 == bonus:
		ans += C[a-1]
	bonus = a
print(ans)

Measured memory_bytes: 3064
n = int(input())

dishes = []
for _ in range(n):
    a, b = map(int, input().split())
    dishes.append((a+b, a, b))
dishes.sort(reverse=True)

T = A = 0
for i, (_, a, b) in enumerate(dishes):
    if not i & 1:
        T += a
    else:
        A += b
print(T-A)


Measured memory_bytes: 26104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var nums = Console.ReadLine().Split(' ').Select(int.Parse);
            var ret = nums.Aggregate(new { Cnt = 0, Height = 0 }, (n, p) => (n.Height <= p) ? new { Cnt = n.Cnt + 1, Height = p } : n).Cnt;
            Console.WriteLine(ret);
        }
    }
}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e16;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)

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

void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll L;
    cin>>L;
    ld x = L / (ld)3;
    cout << x * x * x << endl;
}

Measured memory_bytes: 256
/*  
    tanuj_johal :: gla_clg_sync_with_CSE(true);
    bonding.tie(true);
    hardwork.tie(true);
    
    ::::::::--------------------::::::::
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ll          long long
#define fio         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define vi          vector<ll>
#define pp          push_pop
#define pll         pair<ll,ll>
#define in          insert
#define f(i,a,b)    for(ll i=a;i<b;i++)
#define f0(i,n)     f(i,0,n)
#define arr(a,n)    int a[n];f0(i, n) cin >> a[i];
#define ini(a,n)    memset(a,n,sizeof(a))
#define ff          first
#define ss          second
#define inf         10000000000000000
#define all(p)      p.begin(), p.end()
#define que_max     priority_queue <int>
#define que_min     priority_queue <int, vi, greater<int>>
#define print(a)    for(auto i:a){cout<<i<<" ";}
#define print1(a)   for(auto i:a){cout<<i.ff<<" "<<i.ss<<endl;}

typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> Set;


const ll mod = 1e9+7;

ll power(ll x,ll y,ll p){ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;}
bool imp = false;

void solve()
{
    ll a,b,c;cin>>a>>b>>c;
    ll k;cin>>k;
    ll sum=0;
    if(k > a){
        k-=a;
        sum+=a;
    }
    else{
        sum += k;
        k=0;
    }
    
    if(k > b){
        k -= b;
    }
    else{
        k=0;
    }
    
    sum -= k;
    cout<<sum<<endl;

}

int main()
{
    fio
    int t=1;
    if(imp) cin>>t;
    while(t--)
    {
        // cout<<"Case #"<<tc<<": ";
        solve();
        // tc++;
    }
    
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <math.h>
using namespace std;
int main ()
{
	int n;
	scanf("%i",&n);
	int a[n+1];
	for(int i=1;i<=n;i++)
	{
		scanf("%i",&a[i]);
	}
	int mn=a[1],r=1;
	for(int i=2;i<=n;i++)
	{
		if(a[i]<=mn)
		{
			r++;
			mn=a[i];
		}
	}
	printf("%i",r);
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int di(int x){
  int count=0;
  while(x>0){
    if(x%2==0)  count++;
    else  break;
    x/=2;
  }
  return count;
}

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++)  cin >> A.at(i);

  int ans=0;
  for(int i=0;i<N;i++){
    int x=A.at(i);
    ans+=di(x);
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main() {
    int n; scanf("%d", &n);
    
    for(int i = 0; i < n; ++i) {
    	int s[3]; scanf("%d %d %d", &s[0], &s[1], &s[2]);
    	
    	sort(s, s + 3);
    	
    	int a=s[0], b=s[1], c=s[2];
    	
    	if (c*c == (a*a)+(b*b)) puts("YES");
    	else puts("NO");
    }
}

Measured memory_bytes: 1020
import sys
input = sys.stdin.readline
from collections import deque
 
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n-1)]
 
graph = [[] for _ in range(n)]
for a, b in ab:
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

stack = deque([0])
parent = [None]*n
colors = [0]*n
while stack:
    node = stack.popleft()
    color = 1
    for child in graph[node]:
        if child == parent[node]:
            continue
        parent[child] = node
        if color == colors[node]:
            color += 1
        colors[child] = color
        color += 1
        stack.append(child)

 
k = max(colors)
print(k)
for a, b in ab:
    if (a-1) == parent[b-1]:
        print(colors[b-1])
    else:
        print(colors[a-1])


Measured memory_bytes: 44104