akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N,x;
    cin>>N>>x;
    if(N==2){
        if(x==2){
            cout <<"Yes"<<"\n";
            rep(i,0,3){
                cout <<i+1<<"\n";
            }
        }
        else cout <<"No"<<"\n";
    }
    else if(x>=2&&x<=2*N-2){
        cout <<"Yes"<<"\n";
        vector<int> ans(2*N-1,0);
        set<int> s;
        if(x!=2*N-2){
            ans[N-3]=x+1;
            ans[N-2]=1;
            ans[N-1]=x;
            ans[N]=x+2;
            rep(i,1,2*N){
                if(i!=1&&i!=x&&i!=x+1&&i!=x+2) s.insert(i);
            }
            int cnt=0;
            for(auto d: s){
                if(cnt<N-3) ans[cnt]=d;
                else ans[cnt+4]=d;
                cnt++;
            }
        }
        else{
            ans[N-3]=x-1;
            ans[N-2]=2*N-1;
            ans[N-1]=x;
            ans[N]=x-2;
            rep(i,1,2*N){
                if(i!=2*N-1&&i!=x&&i!=x-1&&i!=x-2) s.insert(i);
            }
            int cnt=0;
            for(auto d: s){
                if(cnt<N-3) ans[cnt]=d;
                else ans[cnt+4]=d;
                cnt++;
            }
        }
        rep(i,0,2*N-1){
            cout <<ans[i]<<"\n";
        }
    }
    else{
        cout <<"No"<<"\n";
    }
}

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

int main(){
  int n,k,x,y,ans;
  cin >> n >> k >> x >> y;
 	
  if(n > k){
	ans = k*x+(n-k)*y;
  }
  else{
    ans = n*x;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n, m;
int t[15][15];
vector<int> v[15];

void vrotate(int r, int c, int size, int angle) {
	if(angle == 0 || angle == 360) return;

	memset(t, 0, sizeof(t));

	rep(i, angle/90) {
		int col = c;
		for(int i = r + size - 1; i >= r; i--, col++) {
			REP(j, c, c + size) {
				t[r+j-c][col] = v[i][j];
			}
		}

		REP(i, r, r + size) {
			REP(j, c, c + size) {
				v[i][j] = t[i][j];
			}
		}
	}
}

void reversal(int r, int c, int size) {
	REP(i, r, min(n, r + size)) {
		REP(j, c, min(n, c + size)) {
			v[i][j] = !v[i][j];
		}
	}
}

void leftshift(int r) {
	int t = v[r][0];
	rep(i, n) {
		v[r][i] = v[r][i+1];
	}
	v[r][n-1] = t;
}

void rightshift(int r) {
	int t = v[r][n-1];
	for(int i = n-1; i >= 1; i--) {
		v[r][i] = v[r][i-1];
	}
	v[r][0] = t;
}

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};
bool used[15][15];

bool can(int y, int x) {
	if(0 <= y && y < n && 0 <= x && x < n) return true;
	return false;
}

void islandreversal(int r, int c) {
	queue<P> que;
	que.push(mp(r, c));

	memset(used, 0, sizeof(used));
	used[r][c] = true;
	int t = v[r][c];
	while(que.size()) {
		P p = que.front(); que.pop();
		int y = p.first;
		int x = p.second;

		if(v[y][x] == t) {
			v[y][x] = !v[y][x];
		}

		rep(i, 4) {
			int ny = y + dy[i];
			int nx = x + dx[i];

			if(can(ny, nx) && !used[ny][nx] && v[ny][nx] == t) {
				que.push(mp(ny, nx));
				used[ny][nx] = true;
			}
		}
	}
}

int main() {
	cin >> n >> m;

	memset(v, 0, sizeof(v));
	rep(i, n) {
		v[i].resize(n);
		rep(j, n) cin >> v[i][j];
	}

	rep(i, m) {
		int o;
		cin >> o;

		int r, c, size, angle;

		if(o == 0) { // rotate
			cin >> r >> c >> size >> angle;
			r--; c--;

			vrotate(r, c, size, angle);
		} else if(o == 1) { // reversal
			cin >> r >> c >> size;
			r--; c--;

			reversal(r, c, size);
		} else if(o == 2) { // left shift
			cin >> r;
			r--;

			leftshift(r);
		} else if(o == 3) { // right shift
			cin >> r;
			r--;
			rightshift(r);
		} else if(o == 4) { // Island reversal
			cin >> r >> c;
			r--; c--;
			islandreversal(r, c);
		}
	}

	rep(i, n) {
		rep(j, n) {
			cout << v[i][j];

			if(j == n-1) cout << endl;
			else cout << " ";
		}
	}

	return 0;
}

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

typedef long long ll;


int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a, b;
  cin >> a >> b;
  int ans1 = a / 0.08;
  int ans2 = (b + 1) / 0.1;
  for (int i = ans1; i < ans2; i++) {
    if ((int)(i * 0.08) == a && (int)(i * 0.1) == b) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << "-1\n";
    
  return 0;
}

Measured memory_bytes: 256
/*
 * Author       : YangDavid
 * Created Time : 2019年09月27日 星期五 09时32分30秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

struct Graph {
    ull adj[55];
    Graph() { clear(); }
    void clear() {
        for(int i = 0; i < 51; ++i)
            adj[i] = 1ULL << i;
    }
    void addType(int x) {
        for(int i = 0; i < 51; ++i)
            adj[i] |= 1ULL << (i % x);
    }
    void topo() {
        for(int i = 0; i < 51; ++i)
            for(int j = 0; j < i; ++j) if(adj[i] >> j & 1)
                adj[i] |= adj[j];
    }
} g1, g2;

int a[55], b[55], n;
bool reach(const Graph& g) {
    rep(i, n) if(~g.adj[a[i]] >> b[i] & 1) return false;
    return true;
}

int main() {
    scanf("%d", &n);
    rep(i, n) scanf("%d", &a[i]);
    rep(i, n) scanf("%d", &b[i]);
    rep(i, 50) g2.addType(i);
    g2.topo();
    rep(i, n) if(!reach(g2)) { puts("-1"); return 0; }
    ull ans = 0;
    for(int i = 50; i > 0; --i) {
        g2 = g1;
        for(int k = i - 1; k > 0; --k) g2.addType(k);
        g2.topo();
        if(!reach(g2)) g1.addType(i), ans += 1ULL << i;
    }
    printf("%llu\n", ans);
    
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }
        private const long MOD = 1000000007;
        
        static void Solve()
        {
            string s = Console.ReadLine();
            s = s.Replace(',', ' ');
            Console.WriteLine(s);
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 13140
import java.util.*;

class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int[] arr=new int[n];
    int sum=0;
    for(int i=0;i<n;i++)
      arr[i]=sc.nextInt();
    Arrays.sort(arr);
    for(int i=0;i<k;i++)
      sum+=arr[i];
    System.out.println(sum);
  }
}

Measured memory_bytes: 39212
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int r, c, n; cin >> r >> c >> n;
  vector<pair<int, int> > us, ds, ls, rs;
  REP(i, n) {
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    swap(x1, y1);
    swap(x2, y2);
    if ((x1 == 0 || x1 == c || y1 == 0 || y1 == r) && (x2 == 0 || x2 == c || y2 == 0 || y2 == r)) {
      if (y1 == 0) {
        ds.emplace_back(x1, i);
      } else if (y1 == r) {
        us.emplace_back(x1, i);
      } else if (x1 == 0) {
        ls.emplace_back(y1, i);
      } else if (x1 == c) {
        rs.emplace_back(y1, i);
      }
      if (y2 == 0) {
        ds.emplace_back(x2, i);
      } else if (y2 == r) {
        us.emplace_back(x2, i);
      } else if (x2 == 0) {
        ls.emplace_back(y2, i);
      } else if (x2 == c) {
        rs.emplace_back(y2, i);
      }
    }
  }
  vector<bool> in(n, false);
  vector<int> sta;
  sort(ALL(ds));
  for (auto pr : ds) {
    int e = pr.second;
    if (in[e] && sta.back() != e) {
      cout << "NO\n";
      return 0;
    }
    if (in[e]) {
      sta.pop_back();
    } else {
      sta.emplace_back(e);
    }
    in[e] = !in[e];
  }
  sort(ALL(rs));
  for (auto pr : rs) {
    int e = pr.second;
    if (in[e] && sta.back() != e) {
      cout << "NO\n";
      return 0;
    }
    if (in[e]) {
      sta.pop_back();
    } else {
      sta.emplace_back(e);
    }
    in[e] = !in[e];
  }
  sort(ALL(us));
  reverse(ALL(us));
  for (auto pr : us) {
    int e = pr.second;
    if (in[e] && sta.back() != e) {
      cout << "NO\n";
      return 0;
    }
    if (in[e]) {
      sta.pop_back();
    } else {
      sta.emplace_back(e);
    }
    in[e] = !in[e];
  }
  sort(ALL(ls));
  reverse(ALL(ls));
  for (auto pr : ls) {
    int e = pr.second;
    if (in[e] && sta.back() != e) {
      cout << "NO\n";
      return 0;
    }
    if (in[e]) {
      sta.pop_back();
    } else {
      sta.emplace_back(e);
    }
    in[e] = !in[e];
  }
  cout << "YES\n";
  return 0;
}


Measured memory_bytes: 2520
#include <iostream>
#include <vector>
#include <set>
using namespace std;
typedef pair<int, int> Pii;
int main() {
  int N, Q;
  cin >> N >> Q;
  
  vector<int> memo(N+1);
  set<Pii> st;
  
  for(int q=0; q<Q; q++) {
    int a, v; cin >> a >> v;
    st.erase(Pii(-memo[a], a));
    memo[a] += v;
    st.insert(Pii(-memo[a], a));
    cout << st.begin()->second << ' ' << -st.begin()->first << endl;
  }
  
  return 0;
}

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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define rep(i, N) for (ll i = 0; i < (N); i++)
#define For(i, a, b) for (ll i = (a); i < (b); i++)
#define all(A) (A).begin(), (A).end()

int main(){
    int X;
    cin >> X;
    rep(i, X + 1) {
        if (0 <= (X - 100 * i) and (X - 100 * i) <= 5 * i) {
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
typedef pair<int,int> pii;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define inf 1000000000

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

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


void solve(){
    int n;
  cin >> n;
  //n/=2;
  int f = 0, t = 0;

  int count = 0;

    if(n%2==0){
        n/=2;
        for (int i = 5; n / i >= 1; i *= 5){
        //f++;
        count += n / i; 
        }
        cout << count << endl;
    }
    else{
        int tmp = n/2;
        for( int i = 2; n/i>=1; i*=2){
            t+=n/i;
        }

        for(int i = 2;tmp/i>=1; i*=2){
            t-=tmp/i;
        }
        t-=tmp;

        for(int i = 5; n/i>=1; i*=5)f+=n/i;
        for(int  i =5;tmp/i>=1; i*=5)f-=tmp/i;
            cout << min(f,t) << endl;
    }
     
//cout << f << endl;
  //cout << count << endl;
  
}

signed main() 
{   
    IOS;
    int t = 1;
    //cin >> t;

    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int3(n, a, b);
    vector<int> cnt(3, 0);
    for (int i = 0; i < n; i++) {
        Int(tmp);
        if (tmp <= a) {
            cnt[0]++;
        } else if (tmp <= b) {
            cnt[1]++;
        } else {
            cnt[2]++;
        }
    }


    cout << min({cnt[0], cnt[1], cnt[2]}) << endl;
    

    return 0;
}


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

typedef long long ll;




int main() {
    int N;
    long long K;
    cin >> N >> K;
    vector<int> A(200001);
    for(int i=1;i<N+1;i++){
        cin >> A[i];
    }
    
    map<int, int> mp;
    
    mp[1] = 0;
    int town = 1;
    int loop;
    int i = 1;
    while(1){
        if(A[town] == 1 || mp[A[town]] != 0 || i == K) {
            loop = i - mp[A[town]];
            K = K - mp[A[town]];
            town = A[town];
            break;
        }else{
            mp[A[town]] = i;
            town = A[town];
        }
        i++;
    }
    K = K % loop;
    for(int i=0;i<K;i++){
        town = A[town];
    }
    cout << town << endl;
	return 0;
}

Measured memory_bytes: 11212
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf =1 << 28;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int n;
vector<vi> graph;
vi dp;

void dfs(int v){
    dp[v] = 0;

    vi nums;
    for(auto& nv : graph[v]){
        dfs(nv);
        nums.push_back(dp[nv]);
    }

    sort(_all(nums));
    for(auto& e : nums){
        dp[v] = max(dp[v], e) + 1;
    }
}

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

    cin >> n;
    vi a(n); for(auto& e : a) cin >> e, e--;

    graph = vector<vi>(n);
    rep(i, 1, n){
        graph[a[i - 1]].push_back(i);
    }

    dp = vi(n, inf);
    dfs(0);

    cout << dp[0] << endl;

    return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};

const int MAX=510000;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  string s;
  cin >> s;
  if(s[2]==s[3] && s[4]==s[5])cout<<"Yes"<<endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3668
use std::io;


// https://atcoder.jp/contests/abc170/tasks/abc170_d
fn main() {
    let _n = read_one::<usize>();
    let an = read::<usize>();
    let max = an.iter().max().unwrap();

    // whether dp[i] has any factors in dp
    let mut dp = vec![0usize; max + 1];
    for &a in an.iter() {
        let mut j = a;
        while j <= *max {
            dp[j] += 1;
            j += a;
        }
    }

    let ans = an.into_iter()
        .filter(|&a| dp[a] == 1)
        .count();

    println!("{}", ans);
}


#[allow(unused)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}


#[allow(unused)]
fn read_one<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 11392
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_066_A.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 INP    PIC X(17).
    01 a      PIC 9(5).
    01 b      PIC 9(5).
    01 c      PIC 9(5).
    01 ans    PIC X(5).

    01 tmp    PIC 9(5).

    01 ZS     PIC Z(6).
    01 DUMMY  PIC X(1).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT INP.

    UNSTRING INP
    DELIMITED BY SPACE
    INTO a b c.

    ADD a b TO c GIVING tmp.

    COMPUTE c = FUNCTION MAX(a, b, c).

    SUBTRACT tmp FROM c.

    MOVE c TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


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

using namespace std;

int dp[100005];

int main()
{
	dp[0] = 1;
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); i++) {
	 	if(dp[i] != 0 && (s.size() - i >= 7) && s.substr(i, 7) == "dreamer")	dp[i + 7] = 1;
	 	if(dp[i] != 0 && (s.size() - i >= 6) && s.substr(i, 6) == "eraser")	dp[i + 6] = 1;
	 	if(dp[i] != 0 && (s.size() - i >= 5) && (s.substr(i, 5) == "dream" || s.substr(i, 5) == "erase"))	dp[i + 5] = 1;

	}
	if(dp[s.size()] == 1)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}	

Measured memory_bytes: 896
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		int A,B,C,D;
		Scanner scan = new Scanner(System.in);
		A = scan.nextInt();
		B = scan.nextInt();
		C = scan.nextInt();
		D = scan.nextInt();
		
		while(true) {
			if(A <= 0 || C <= 0) break;
			C -= B;
			if(A <= 0 || C <= 0) break;
			A -= D; 
		}
		if(C <= 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


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

int main()
{
  int h,w,n;cin>>h>>w>>n;
  int i;
  int ans;
  if(h<w)
  {
    ans=n/w;
    if(n%w!=0)ans++;
  }
  else
  {
    ans=n/h;
    if(n%h!=0)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <memory>
#include <memory.h>
#include <cmath>
#include <fstream>
#include <cmath>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>
#define USE_MATH_DEFINES
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)
using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

int table[][7] = {
	{0, 300, 500, 600, 700, 1350, 1650},
	{6, 0, 350, 450, 600, 1150, 1500},
	{13, 7, 0, 250, 400, 1000, 1350},
	{13, 12, 5, 0, 250, 850, 1300},
	{23, 17, 10, 5, 0, 600, 1150},
	{43, 37, 30, 25, 20, 0, 500},
	{58, 52, 45, 40, 35, 15, 0}
};

int main(){
	int s, t;
	int h1, m1, h2, m2;
	int t1, t2;
	while(cin >> s && s){
		cin >>h1 >> m1;
		cin >> t;
		cin >> h2 >> m2;
		t1 = h1 * 60 + m1;
		t2 = h2 * 60 + m2;
		s--, t--;
		int cost = table[min(s, t)][max(s, t)];
		int dis = table[max(s, t)][min(s, t)];
		if(dis <= 40 && (1050 <= t1 && t1 <= 1170 || 1050 <= t2 && t2 <= 1170)){
			cost = (cost / 2 + 49) / 50 * 50;
		}
		cout << cost << endl;
	}
	return 0;
}

Measured memory_bytes: 0
n, m = map(int, input().split())
x = [int(x) for x in input().split()]
y = [int(x) for x in input().split()]

mod = 10 ** 9 + 7
a = 0
for k in range(n):
    a += k * x[k] - (n - (k + 1)) * x[k]
b = 0
for k in range(m):
    b += k * y[k] - (m - (k + 1)) * y[k]

print(a * b % mod)

Measured memory_bytes: 19472
#include <iostream>
#include <cmath>
using namespace std;
int tem[201],G[201][3],D,N,DP[201][201]={0};
int absn(int value){
	if(value>0)
		return value;
	return -value;
}
int main() {
	cin >> D >> N ;
	for (int i=1;i<=D;i++){
		cin>>tem[i];
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<3;j++){
			cin >> G[i][j];

		}
		if(!(G[i][0]<=tem[1] && tem[1]<=G[i][1]))
			DP[i][1]=-9999;
	}

	for(int i=2;i<=D;i++){
		for(int j=0;j<N;j++){
			if(G[j][0]<=tem[i] && tem[i]<=G[j][1]){
			for(int k=0;k<N;k++){
			DP[j][i]=max(DP[j][i],DP[k][i-1]+absn(G[k][2]-G[j][2]));
			}
			}
		}
	}
	int maxer=-1;
	for (int i=0;i<N;i++){
		maxer=max(maxer,DP[i][D]);
	}
	cout << maxer << endl; 
}

Measured memory_bytes: 1320
#include<iostream>
#include<complex>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define fs first
#define sc second
#define pb push_back
#define sz size()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)

using namespace std;

typedef complex<double> P;
typedef pair<P,P> L;
typedef vector<P> Poly;
typedef pair<P,double> C;

const double PI = acos(-1);

namespace std{
  bool operator<(const P &a,const P &b){
    return real(a)==real(b)?imag(a)<imag(b):real(a)<real(b);
  }
}

//for vector

double dot(P x,P y){return real(conj(x)*y);}

double cross(P x,P y){return imag(conj(x)*y);}

//for line(segment)
int ccw(P a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 1;   //counter clockwise
  if (cross(b,c)<-EPS) return -1; //clockwise
  if (dot(b, c)<-EPS) return 2;   //c--a--b on line
  if (abs(b)<abs(c)) return -2;   //a--b--c on line
  return 0;                       //on segment
}

bool orth(L a,L b){return abs(dot(a.fs-a.sc,b.fs-b.sc))<EPS;}

bool para(L a,L b){return abs(cross(a.fs-a.sc,b.fs-b.sc))<EPS;}

double seg_dis(L a,P x){
  if(dot(a.sc-a.fs,x-a.fs)<EPS)return abs(x-a.fs);
  if(dot(a.fs-a.sc,x-a.sc)<EPS)return abs(x-a.sc);
  return abs(cross(a.sc-a.fs,x-a.fs))/abs(a.sc-a.fs);
}

bool is_cp(L a,L b){
  if(ccw(a.fs,a.sc,b.fs)*ccw(a.fs,a.sc,b.sc)<=0)
    if(ccw(b.fs,b.sc,a.fs)*ccw(b.fs,b.sc,a.sc)<=0)return true;
  return false;
}

P seg_cp(L a,L b){
  double d = abs(cross(b.sc-b.fs,a.fs-b.fs));
  return a.fs + (a.sc-a.fs)*( d /(d + abs(cross(b.sc-b.fs,a.sc-b.fs))) );
}

double seg_close(L a, L b){
  double res = 1e10;
  res = min(res, seg_dis(a,b.first));
  res = min(res, seg_dis(a,b.second));
  res = min(res, seg_dis(b,a.first));
  res = min(res, seg_dis(b,a.second));
  return res;
}

int main(){
  int n,sx,sy,ex,ey;
  int x1,y1,x2,y2,h;

  while(cin >> n ,n){
    cin >> sx >> sy >> ex >> ey;
    L l = L(P(sx,sy),P(ex,ey));

    double r = 100000.0;
    for(int i=0;i<n;i++){
      cin >> x1 >> y1 >> x2 >> y2 >> h;
      if(x1>x2)swap(x1,x2);
      if(y1>y2)swap(y1,y2);
      if(r<EPS)continue;
      P a = P(x1,y1);
      P b = P(x1,y2);
      P c = P(x2,y2);
      P d = P(x2,y1);
      L A = L(a,b);
      L B = L(b,c);
      L C = L(c,d);
      L D = L(d,a);

      if(is_cp(l,A))r = 0.0;
      else if(is_cp(l,B))r = 0.0;
      else if(is_cp(l,C))r = 0.0;
      else if(is_cp(l,D))r = 0.0;
      else if(x1<=sx && sx<=x2 && y1<=sy && sy<=y2)r = 0.0;
      else{
	double dis = min(min(seg_close(l,A),seg_close(l,B)),
			 min(seg_close(l,C),seg_close(l,D)));
	if(dis<h)r = min(r,dis);
	else r = min(r,(h*h+dis*dis)/(2*h));
      }
    }
    cout << r << endl;
  }
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	private void solve() throws IOException {
		int n = ni();

		out.println(n >= 1000 ? "ABD" : "ABC");
		out.close();
	}

	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tok;

	private int[][] na(int n) throws IOException {
		int[][] a = new int[n][2];
		for (int i = 0; i < n; i++) {
			a[i][0] = ni();
			a[i][1] = i;
		}
		return a;
	}

	String ns() throws IOException {
		while (!tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine(), " ");
		}
		return tok.nextToken();
	}

	int ni() throws IOException {
		return Integer.parseInt(ns());
	}

	long nl() throws IOException {
		return Long.parseLong(ns());
	}

	double nd() throws IOException {
		return Double.parseDouble(ns());
	}

	String[] nsa(int n) throws IOException {
		String[] res = new String[n];
		for (int i = 0; i < n; i++) {
			res[i] = ns();
		}
		return res;
	}

	int[] nia(int n) throws IOException {
		int[] res = new int[n];
		for (int i = 0; i < n; i++) {
			res[i] = ni();
		}
		return res;
	}

	long[] nla(int n) throws IOException {
		long[] res = new long[n];
		for (int i = 0; i < n; i++) {
			res[i] = nl();
		}
		return res;
	}

	public static void main(String[] args) throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		tok = new StringTokenizer("");
		Main main = new Main();
		main.solve();
		out.close();
	}
}

Measured memory_bytes: 21204
#include<stdio.h>
#include<iostream>
#include<math.h>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<cmath>
#include <algorithm>
using namespace std;
using ll = long long int;
 
typedef pair<int,int> P;
 
int main(void){
 int N;
 cin >>N;
 vector<int> L(N);
 for(int a=0;a<N;a++){
     cin >> L[a];
 }
    sort(L.begin(),L.end());
    ll ans=0;
    int nagasa;
    for(int k=0;k<N;k++){
        for(int m=k+1;m<N;m++){
            nagasa=L[k]+L[m];
            int c = m+1;
            if(c==N)break;
            while(nagasa>L[c]){
                //if(nagasa)
                if(L[k]==L[m]||L[k]==L[c]||L[m]==L[c]){
                    c++;
                }else{
                    ans++;c++;
                }
                if(c==N)break;
            }
        }
    }
    cout << ans<<endl;;

}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define  ll long long
ll s;
ll dp[2001];
ll mod=1000000007;
ll rec(ll sm)
{
	if(sm==s)
	{
		return 1;
	}
	if(sm>s)
	{
		return 0;
	}
	if(dp[sm]!=-1)return dp[sm];
	ll ans=0;
	for(int i=3;i<=s;i++)
	{
		ans=(ans%mod + rec(sm+i)%mod)%mod;
	//	ans%=mod;
	}
return dp[sm]=ans;

}
int main()
{
	
	 memset(dp,-1,sizeof(dp));
	 cin>>s;
	 cout<<rec(0);
	
}

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

struct node{
  int key;
  node *l,*r,*p;
};

node* root;

node* make_node(int a){
  node* ret = new node();
  ret->key = a;
  ret->p = ret->l = ret->r = NULL;
  return ret;
}

void insert(node *z){
  node *y = NULL;
  node *x = root;
  while( x != NULL ){
    y = x;
    if( z->key < x->key )
      x = x->l;
    else
      x = x->r;
  }
  z->p = y;
  if( y == NULL )
    root = z;
  else if( z->key < y->key )
    y->l = z;
  else
    y->r = z;
}

bool find(int k){
  node* x = root;
  while( x != NULL ){
    if( k < x->key )
      x = x->l;
    else if( k > x->key )
      x = x->r;
    else
      return true;
  }
  return false;
}

void delete_node(node *x){
  if( x->l == NULL && x->r == NULL ){
    if( x->p != NULL ){
      if( x->p->l == x ) x->p->l = NULL;
      else x->p->r = NULL;
    }
    delete x;
  } else if( x->l == NULL ){
    x->r->p = x->p;
    if( x->p != NULL ){
      if( x->p->l == x ) x->p->l = x->r;
      else x->p->r = x->r;
    }
    delete x;
  } else if( x->r == NULL ){
    x->l->p = x->p;
    if( x->p != NULL ){
      if( x->p->l == x ) x->p->l = x->l;
      else x->p->r = x->l;
    }
    delete x;
  }
}

void del(int key){
  node* x = root;
  while( x != NULL ){
    if( key < x->key )
      x = x->l;
    else if( key > x->key )
      x = x->r;
    else
      break;
  }

  if( x->l && x->r ){
    node* y = x->r;
    while( y->l && y->r )
      y = y->l;
    x->key = y->key;
    delete_node(y);
  } else {
    delete_node(x);
  }
}

void inorder(node* n){
  if( n == NULL) return;
  inorder(n->l);
  cout << " " << n->key;
  inorder(n->r);
}

void preorder(node* n){
  if( n == NULL ) return;
  cout << " " << n->key;
  preorder(n->l);
  preorder(n->r);
}

int main(){
  int N;
  cin >> N;
  for(int i=0;i<N;i++){
    string s; int k;
    cin >> s;
    if( s[0] == 'i' ) {
      cin >> k;
      insert(make_node(k));
    } else if( s[0] == 'f' ){
      cin >> k;
      if( find(k) ) cout << "yes" << endl;
      else cout << "no" << endl;
    } else if( s[0] == 'p' ){
      inorder(root); cout << endl;
      preorder(root); cout << endl;
    } else {
      cin >> k;
      del(k);
    }
  }
}

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

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

    long long x,y;
    cin >> x >> y;
    y /= x;
    int ans = 1;
    while(y != 1){
        y >>= 1;
        ans ++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1000000007;

int main(){
  ll N,K;
  cin>>N>>K;
  vector<ll> h(N);
  for (int i=0;i<N;i++) cin>>h[i];
  sort(h.begin(),h.end());
  ll min=mod;

  for (int i=0;i<=N-K;i++){
    ll x=h[i+K-1]-h[i];
    if (min>x) min=x;

  }
  cout<<min<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
    int a[1];
    int C;
    int ans;

    if(scanf("%d", &a[0])==1){}

    C = (int)((double)a[0]/100);
    if(100*C <= a[0] && a[0]<=105*C){
        ans = 1;
    }else{
        ans = 0;
    }

    printf("%d\n", ans);

}

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

const int N = 3e5 + 10;
int n, v, u, c, ce = -1, r = -1, le = 1e9, cnt[N];
long long ans;
vector<pair<int, int> > g[N];

void dfs(int v, int p){
	cnt[v]++;
	bool f = true;
	for (auto q : g[v]){
		int u = q.first, 
			c = q.second;
		if(u != p){
			dfs(u, v);
			ans += (1LL * 2 * min(cnt[u], n - cnt[u]) * c);
			if(2 * min(cnt[u], n - cnt[u]) == n)
				ce = c;
			f &= ((2 * cnt[u]) <= n);
			cnt[v] += cnt[u];
		}
	}
	f &= ((2 * (n - cnt[v])) <= n);
	if(f)
		r = v;	
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin >> n;
	for (int i = 0; i + 1 < n; i++){
		cin >> v >> u >> c;
		v--;u--;
		
		g[v].push_back({u, c});
		g[u].push_back({v, c});
	}
	
	dfs(0, 0);
	
	if(r != -1)
		for (auto u : g[r])
			le = min(le, u.second);
					
	if(ce != -1)
		cout << ans - ce;
	else
		cout << ans - le;
}


Measured memory_bytes: 18304
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        boolean flag = true;
        List<Integer> list = new ArrayList<Integer>();
        while(flag){
            int sum = 0;
            String s = sc.next();
            if(s.equals("0")){
                flag = false;
            }else{
                StringBuffer sb = new StringBuffer(s);
                for(int i=0;i<s.length();i++){                
                    sum = sum + Integer.parseInt(sb.substring(i, i+1));
                }
                list.add(sum);
            }
        }
        for(int i = 0;i<list.size();i++){
            System.out.println(list.get(i));
        }

    }
}




Measured memory_bytes: 26912
#include<bits/stdc++.h>
#define maxn 100000
#define inf 0x3f3f3f3f
#define LL long long
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define mm(a,b) memset(a,b,sizeof(a))
#define mp(a,b) make_pair(a,b)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const LL mod=1e9+7;
const LL INF=(LL)1e18;
using namespace std;
LL gcd(LL a,LL b){return b==0?a:gcd(b,a%b);}
LL qpow(LL x,LL y){LL re=1,base=x%mod;while(y){if(y&1)re=(re*base)%mod;base=(base*base)%mod;y>>=1;}return re;}
int main(){
//	freopen("input.txt","r",stdin);
//	freopen("ouput.txt","w",sdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int a,b;
	cin>>a>>b;
	if(a%3==0 || b%3==0 || (a+b)%3==0) cout<<"Possible"<<endl;
	else cout<<"Impossible"<<endl;
	return 0;
}

Measured memory_bytes: 256
import scala.collection.mutable._
import io.StdIn.readInt
import io.StdIn.readLine

object Main extends App {
  val out = new java.io.PrintWriter(System.out)

  def calculate(q:Array[Int],d:Array[Array[Int]]):Int = {
    val ts = q(0)
    val te = q(1)
    val st = q(2)

    val a = d.filter(_(2) == st)
    val map = new HashMap[Int,Array[Int]]
    val log = new ListBuffer[Tuple2[Int,Int]]
    a.foreach(l => {
      if(l(3) == 1) map.put(l(1),l)
      else {
        val e = map(l(1))
        log += {( e(0), l(0) )}
        }
    })
    // println(log.mkString)

    val time = Array.ofDim[Boolean](721)
    log.foreach(t => {
      val s = math.max(ts, t._1) -540
      val e = math.min(te, t._2) -540
      (s until e).foreach(time(_) = true)
    })
    time.count(_ == true)
  }

  def solve(s:String):Unit = {
    // val Array(n, m) = s.split(" ").map(_.toInt)
    val r = readInt
    val d = Iterator.continually(readLine)
      .take(r)
      .map(_.split(" ").map(_.toInt))
      .toArray
    val q = readInt
    Iterator.continually(readLine)
      .take(q)
      .map(_.split(" ").map(_.toInt))
      .foreach(qd => out.println(calculate(qd,d)))
  }

  Iterator.continually(readLine)
    .takeWhile(_ != "0 0")
    .foreach(solve(_))
  
  out.flush
}


Measured memory_bytes: 58408
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        long ans = 0;
        for (long i = 1; i <= K; i++) {
            for (long j = 1; j <=K; j++) {
                for (long k = 1; k <=K; k++) {
                    ans += gcd(i,gcd(j, k));
                }
            }
        }
        System.out.println(ans);
    }

    public static final long gcd(long a, long b) {
        if( b == 0 ) return a;
        return gcd(b, a % b);
    }
}

Measured memory_bytes: 35684
#include "bits/stdc++.h"

using namespace std;

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))
#define OUT(P) cout << (P) << endl
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)

int sum_digits(int num);
template <class T>
vector<T> copy_vector(vector<T> vec);

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; i++) {
        cin >> a[i];
    }
    vector<int> b(n,0);

    bool is_front = true;
    int front_i = 0, back_i = n-1;
    for(int i=n-1; i>=0; i--) {
        if(is_front) {
            b[front_i] = a[i];
            front_i++;
        } else {
            b[back_i] = a[i];
            back_i--;

        }
        is_front = !is_front;
    }

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

    return 0;
}

/******************************/
/***** DECRARED FUNCTIONS *****/
/******************************/

// integerの各桁を足す
int sum_digits(int num) {
    int rtn = 0;
    string num_str = to_string(num);
    for(int i=0; i<num_str.size(); i++) {
        rtn += num_str[i] - '0';
    }   
    return rtn;
}

// vectorのコピー
template <class T>
vector<T> copy_vector(vector<T> vec) {
    vector<T> rtn;
    rtn.reserve(vec.size());
    copy(vec.begin(), vec.end(), back_inserter(rtn));
    return rtn;
}



Measured memory_bytes: 3712
N, K = map(int, input().split())
A = list(map(lambda x:int(x)-1, input().split()))

cnts = [None] * N

pos = 0
cnt = 0

while cnt < K:
    if cnts[pos] != None:
        loop_size = cnt - cnts[pos]
        cnt += ((K-cnt-1) // loop_size) * loop_size
        cnts = [None] * N
    cnts[pos] = cnt
    pos = A[pos]
    cnt += 1

print(pos+1)



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

int main() {
    vector<map<char, int>> m(50);
    int n; cin >> n;
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, s.size()) {
            m[i][s[j]]++;
        }
    }

    string t="";
    for (char c='a'; c<='z'; ++c) {
        int mi=1e8;
        rep(i, n) {
            mi = min(mi, m[i][c]);
        }
        rep(i, mi) {
            t+=c;
        }
    }
    sort(t.begin(), t.end());

    cout << t << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <stdlib.h>
#include <time.h>
#include <random>
#include <string>
#include<algorithm>


using namespace std;


int main(){
	string s;
	cin >>s;
	
	string ss = "";
	for(int i=0; i<s.length(); i++){
		if(s[i] != 'x'){
			ss+= s[i];
		}
	}
	string ssrev=ss;
	reverse(ssrev.begin(), ssrev.end());
	if(ssrev != ss){
		cout<< "-1" << endl;
	}
	else{
		int n=0;
		while(s.length()>1){
			if(s[0]==s[s.length()-1]){
				s = s.substr(1,s.length()-2);
			}
			else if(s[0] == 'x'){
				s = s.substr(1,s.length()-1);
				n++;
			}
			else{
				s = s.substr(0,s.length()-1);
				n++;
			}
		}
		cout << n << endl;
	}

    return 0;
}

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

int main() {
	vector<int> a;
	while(1) {
		int x = 0;
		scanf("%d", &x);
		a.push_back(x);
		if(x==0)break;
	}
	
	int l = a.size()-1;
	int b[l][10];
	
	for(int i=0;i<l;i++) {
		int a1 = a[i];
		for(int j=0;j<10;j++) {
			if(a1<1) {
				b[i][j] = -1;
			}else {
				int t = a1%8;
				if(t>3) {
					t++;
				}
				if(t>5) {
					t++;
				}
				b[i][j] = t;
				a1 /= 8;
			}
		}
	}
	
	for(int i=0;i<l;i++) {
		for(int j=9;j>=0;j--) {
			if(0<=b[i][j])printf("%d", b[i][j]);
		}
		printf("\n");
	}
	
	return 0;
}

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

using namespace std;

bool double_rock(uint64_t N, const string &S, uint64_t src, uint64_t dst)
{
  for (uint64_t n = src; (n + 1) <= dst; ++n) {
    if ((S[n] == '#') && (S[n + 1] == '#')) {
      return true;
    }
  }
  return false;
}

bool swapable(uint64_t N, uint64_t A, uint64_t B, uint64_t C, uint64_t D, const string &S)
{
  for (uint64_t n = B; n <= D; ++n) {
    if ((A <= (n - 1)) && ((n + 1) <= C)) {
      if ((S[n - 1] == '.') && (S[n] == '.') && (S[n + 1] == '.')) {
        return true;
      }
    }
  }
  return false;
}

int main()
{
  uint64_t N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  
  string S;
  cin >> S;
  
  S.insert(S.begin(), '?');
  S.insert(S.end(),   '?');
  
  if (double_rock(N, S, A, C) || double_rock(N, S, B, D)) {
    cout << "No" << endl;
    return 0;
  }
  
  if ((C < B) || (C < D)) {
    cout << "Yes" << endl;
    return 0;
  }
  
  cout << (swapable(N, A, B, C, D, S) ? "Yes" : "No") << endl;
  
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define N int(1e5 + 5)
#define MOD 1000003
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
vector<int>v;
int n, m;
int main(){
    IO
    cin >> n >> m;
    priority_queue<int>pq;
    for(int i=0 ; i < n ; i++){
        int x; cin >> x;
        pq.push(x);
    }
    while(m--){
        int cur = pq.top();
        pq.pop();
        cur >>= 1;
        pq.push(cur);
    }
    ll ans = 0;
    while(pq.size())
        ans += pq.top(), pq.pop();
    cout << ans;
}


Measured memory_bytes: 892
h, w = gets.split.map(&:to_i)
ss = h.times.map { gets.chomp.chars }
dx = [1, 0, -1, 0, 1, 1, -1, -1]
dy = [0, -1, 0, 1, 1, -1, -1, 1]
h.times do |i|
  w.times do |j|
    next if ss[i][j] == '#'
    num = 0
    8.times do |k|
      ni = i + dy[k]
      nj = j + dx[k]
      next if ni < 0 || h <= ni
      next if nj < 0 || w <= nj
      num += 1 if ss[ni][nj] == '#'
    end
    ss[i][j] = num.to_s
  end
end

h.times { |i| puts ss[i].join }

Measured memory_bytes: 2044
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        
        for(int i=0; i<M; i++){
            
            int A = scanner.nextInt();
            N -= A;
            }
        
        if(N>=0){
            System.out.println(N);
        }else{
            System.out.println(-1);
        }
        
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 100000000000

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

	ll N;
	cin >> N;

	multiset<ll> A;
	ll tmp;
	rep(i, N) {
		cin >> tmp;
		A.insert(tmp);
	}

	ll min = *A.begin();
	bool is_continue = true;
	while (is_continue) {
		is_continue = false;
		for (auto itr = A.begin(); itr != A.end(); itr++) {
			if (*itr % min != 0) {
				min = *itr % min;
				is_continue = true;
			}
		}
	}

	cout << min << "\n";

	return 0;
}

Measured memory_bytes: 4992
N, M = map(int, input().split())

path_matrix = []

#無向行列の初期化
for n in range(N):
    path_matrix.append([False] * N)

#まず無向グラフを表す行列を作る
for m in range(M):
    a,b = map(int, input().split())
    path_matrix[a-1][b-1] = True
    path_matrix[b-1][a-1] = True
#無向グラフを表す行列はpath_matrix[i][j]iの部分が各頂点でjが他の頂点との繋がりを意味する
#最初はvisited、つまり訪問したことのあるノードはひとつもないので、Falseにする
visited = [False] * N #この問題は各頂点をすべて通る方法を調べること
def dfs(now,depth):
    if visited[now]:#もし現在位置が訪問済みなら
        return 0
    if depth == N-1:#もし深さが最大までいったらすべての頂点を探索し終えたので１を返す
        return 1
    
    visited[now] = True#現在位置を訪問済みにする(これをしないとループし続ける)
    total_path = 0
    for i in range(N):
        if path_matrix[now][i]:#もし飛べる先があるのなら、その飛んだ先のノードで今いる位置と深さを更新した上で、もっと掘り下げてみる
            total_path += dfs(i,depth+1)#もし深さが最大まで行ったらすべての頂点について探索が終了したので1加える

    visited[now] = False

    return total_path


print(dfs(0,0))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
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 (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll X, N; cin >> X >> N;
    if (N==0) {
        cout << X;
        return 0;
    }
    vector<ll> p(N);
    REP(i, N) cin >> p[i];
    ll dist = 0;
    while (true) {
        if (find(ALL(p), X-dist) == p.end()) {
            cout << X-dist << "\n";
            break;
        } else if (find(ALL(p), X+dist) == p.end()) {
            cout << X+dist << "\n";
            break;
        }
        dist++;
    }
}


Measured memory_bytes: 3652
def main():
    K, T = map(int, input().split())
    A = list(map(int, input().split()))
    max_a = max(A)
    limit = (K + 1)//2
    if max_a <= limit:
        print(0)
    else:
        remain = K - max_a
        print(max_a - remain - 1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
n,u,v=map(int,input().split())
u-=1
v-=1
edge=[[]for _ in range(n)]
for _ in range(n-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
aoki=[10**10]*n
taka=[10**10]*n
aoki[v]=0
taka[u]=0
Q=[v]
visited={v}
co=1
while Q:
  P=[]
  for i in Q:
    for j in edge[i]:
      if j in visited:continue
      aoki[j]=co
      visited.add(j)
      P.append(j)
  Q=P
  co+=1
Q=[u]
visited={u}
co=1
while Q:
  P=[]
  for i in Q:
    for j in edge[i]:
      if j in visited:continue
      taka[j]=co
      visited.add(j)
      P.append(j)
  Q=P
  co+=1
ans=0
for i in range(n):
  if taka[i]<aoki[i]:ans=max(ans,aoki[i]-1)
print(ans)

Measured memory_bytes: 77088