akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

map<int, int> mp;

void addMp(int tmp) {
  auto itr = mp.find(tmp);
  if (itr != mp.end()) mp[tmp]++;
  else mp[tmp] = 1;
}

int main() {
  int h, w;
  cin >> h >> w;
  string s[h];
  rep (i, h) {
    cin >> s[i];
  }

  int ans[h][w];

  rep (i, h) {
    rep (j, w) {
      ans[i][j] = 0;

      for (int aa = -1; aa <= 1; aa++) {
        for (int bb = -1; bb <= 1; bb++) {
          if (aa == 0 && bb == 0) continue;
          if (i + aa < 0 || i + aa >= h) continue;
          if (j + bb < 0 || j + bb >= w) continue;

          if (s[i + aa][j + bb] == '#') {
            ans[i][j]++;
          }
        }
      }

      if (s[i][j] == '#') ans[i][j] = -1;
    }
  }

  rep (i, h) {
    rep (j, w) {
      if (ans[i][j] == -1) cout << "#";
      else cout << ans[i][j];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <string>
#include <math.h>

using namespace std;

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

const ll mod = 1000000007;
const ll INF = 1000000000000;

ll K, X;
vector<ll> ans;
vector<P> G[2510];

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

	for (int i = -1000000; i <= 1000000; i++)
	{
		if (abs(i - X) + 1 <= K)
		{
			ans.push_back(i);
		}
	}

	for (int i = 0; i < ans.size(); i++)
	{
		cout << ans[i];
		if (i == ans.size() - 1)
		{
			cout << endl;
		}
		else
		{
			cout << ' ';
		}
	}

	int www;
	cin >> www;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy

# スペース区切りの整数の入力
A,B = map(int, input().split())

num = B-A+1

if A%2==0:
  if num%4==0:
    print("0")
  elif num%4==1:
    print(B)
  elif num%4==2:
    print("1")
  else: #num%4==3:
    print(B^1)
else:
  if num%4==0:
    print(A^B^1)
  elif num%4==1:
    print(A)
  elif num%4==2:
    print(A^B)
  else: #num%4==3:
    print(A^1)

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

ifstream in ( "test.in"  );
ofstream out( "test.out" );

string str;
vector<int> lst[26];

int main( void ) {
    
    for( int i = 0; i <= 25; i ++ )
        lst[i].push_back( 0 );
    
    cin >> str;
    
    for( int i = 0; i < str.length(); i ++ )
        lst[str[i] - 'a'].push_back( i + 1 );
    
    for( int i = 0; i <= 25; i ++ )
        lst[i].push_back( (int) str.length() + 1 );
    
    int ans = 1e9;
    for( int i = 0; i <= 25; i ++ ) {
        int dst = 0;
        for( int j = 1; j < lst[i].size(); j ++ )
            dst = max( dst, lst[i][j] - lst[i][j - 1] - 1 );
        
        ans = min( ans, dst );
    }
    
    cout << ans;
    return 0;
}

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

int main(){
    ll n;
    cin >> n;
    vector<ll> f(n);
    ll pp;
    ll ans = 0;
    rep(i,n){
        pp = (i+1);
        while(1){
            f[pp-1]++;
            pp += (i+1);
            if(pp > n) break;
        }
    }
    rep(i,n){
        //cout << f[i] << " ";
        ans += (f[i]*(i+1));
    }
    //cout << endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 81364
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

template <class T>
void chmax(T &a, T b) {
    if (b > a) a = b;
}

constexpr int W = (int)1e+5, K = 11;

int dp[1 << K][W + 1];

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

    int n;
    cin >> n;
    n++;

    vector<int> v(n), w(n);
    for (int i = 1; i < n; i++) {
        cin >> v[i] >> w[i];
    }

    int n1 = min(1 << K, n);
    for (int i = 1; i < n1; i++) {
        int i0 = i / 2;
        for (int j = 0; j < w[i]; j++) {
            dp[i][j] = dp[i0][j];
        }
        for (int j = w[i]; j <= W; j++) {
            dp[i][j] = max(dp[i0][j], dp[i0][j - w[i]] + v[i]);
        }
    }

    vector<ll> s(1 << K);
    s[0] = 0;

    int q;
    cin >> q;

    while (q--) {
        int i, j;
        cin >> i >> j;

        int r;

        if (i < 1 << K) {
            r = dp[i][j];

        } else {
            ll p[K];
            int h0;
            for (int h = 0;;) {
                p[h++] = (ll)v[i] << 32 | w[i];
                i /= 2;
                if (i < 1 << K) {
                    h0 = h;
                    break;
                }
            }

            r = dp[i][j];
            for (int h = 0; h < h0; h++) {
                int m = 1 << h;
                for (int l = m; l < m << 1; l++) {
                    s[l] = s[l & ~m] + p[h];
                    int v1 = s[l] >> 32, w1 = s[l];
                    if (w1 > j) continue;
                    chmax(r, dp[i][j - w1] + v1);
                }
            }
        }

        cout << r << '\n';
    }

    return 0;
}

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

using namespace std;

int n, m;
pair<int, int> res[(1 << 18)][2];

int main()
{
    cin >> n;
    m = (1 << n) - 1;
    for (int i = 0; i <= m; i++) cin >> res[m - i][0].first, res[m - i][0].second = m - i, res[m - i][1].second = m - i;
    int ans = 0;
    for (int i = m; i >= 0; i--)
    {
        vector<pair<int, int> > v;
        for (int j = 0; j < n; j++)
        {
            if (!((1 << j) & i)) v.push_back(res[(1 << j) | i][0]);
            if (!((1 << j) & i)) v.push_back(res[(1 << j) | i][1]);
        }
        v.push_back(res[i][0]);
        v.push_back(res[i][1]);
        sort(v.begin(), v.end());
        v.resize(unique(v.begin(), v.end()) - v.begin());
        reverse(v.begin(), v.end());
        res[i][0] = v[0];
        res[i][1] = v[1];
        if (m - i)
            ans = max(ans, res[i][0].first + res[i][1].first), cout << ans << "\n";
    }
}


Measured memory_bytes: 7168
def resolve():
    n, m = map(int, input().split())
    sc = []
    for _ in range(m):
        sc.append(list(map(int, input().split())))

    # 先にs,cの重複チェックをする。sが同じでcが異なる場合は実現できない
    s_reserve = []
    c_reserve = []
    for sc_one in sc:
        in_reserve = False
        for k in range(len(s_reserve)):
            if sc_one[0] == s_reserve[k]:
                in_reserve = True
                if not sc_one[1] == c_reserve[k]:
                    print('-1')
                    return
                else:
                    break
        if not in_reserve:
            s_reserve.append(sc_one[0])
            c_reserve.append(sc_one[1])

    if n == 1:
        ans = '0'
    elif n == 2:
        ans = '10'
    elif n == 3:
        ans = '100'
    ans = list(ans)

    for i in range(len(s_reserve)):
        # 1桁目が0はだめ。ただし答えが1桁の場合は'0'があり得るのでOK
        if not n == 1 and s_reserve[i] == 1 and c_reserve[i] == 0:
            print('-1')
            return
        ans[s_reserve[i] - 1] = str(c_reserve[i])

    print(''.join(ans))

resolve()

Measured memory_bytes: 3064
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <numeric>
#include <bitset>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;
// const ll mod =  998244353 ;
const ll mod =  1000000007 ;
const ll inf = 1e18;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP_FROM(i, j, n) for (ll i = (j); i < (n); ++i)
#define REP_REV(i, n) for (ll i = n-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())

template<typename T> void print_vec(vector<T> a) {int n = a.size();REP(i, n) {cout >> a[i]; if(i!=n-1) cout << " "; else cout << endl;}}
ll power(ll base, ll exponent){ if(exponent % 2){ return power(base, exponent - 1) * base % mod; }else if(exponent){ ll root_ans = power(base, exponent / 2); return root_ans * root_ans % mod; }else{ return 1; }}
ll inverse(ll x){ return power(x, mod - 2);}
ll gcd(ll a, ll b) {if(a < b) gcd(b, a);ll r;while(r=a%b) {a=b;b=r;}return b;}
template<typename T> ll sum(T begin, T end) {return accumulate(begin, end, 0ll);}
struct combination{ vector<ll> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } ll C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };

using Pair = pair<ll, ll>;
map<ll, ll> m;

ll dfs(ll h) {
  if(h == 1) return 1;
  return dfs(h / 2) * 2 + 1;
}

signed main() {
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll h;
  cin >> h;
  ll ans = dfs(h);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define io std :: ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define M 1000000007
#define int long long
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define nl "\n"
#define yy "YES\n"
#define nn "NO\n"
using namespace std;
bool ispalin(string s)
{
    int n=s.length();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
            return false;
    }
    return true;
}
signed main()
{
    io;
    string s;
    cin>>s;
    int i;
    int n=s.length();
    if(ispalin(s)){
    if(((n-1)/2)%2==0)
    {
        string tmp="",tmp1="";
        for(int i=0;i<n/2;i++)
            tmp+=s[i];
        for(int i=n/2+1;i<n;i++)
            tmp1+=s[i];
        if(ispalin(tmp1) && ispalin(tmp))
            cout<<"Yes";
        else
            cout<<"No";
    }
    else{
        string t1="",t2="";
        for(int i=0;i<n/2;i++)
            t1+=s[i];
        for(int i=n/2+1;i<n;i++)
            t2+=s[i];
        if(ispalin(t1) && ispalin(t2))
            cout<<"Yes";
        else
            cout<<"No";
    }
    }
    else
        cout<<"No";
}



Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext())
        {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int d = sc.nextInt();
            int e = sc.nextInt();
            int f = sc.nextInt();
            double y=(double)(c*d-a*f)/(b*d-a*e);
            double x=(double)(c-b*y)/a;
            System.out.printf("%.3f %.3f\n",x,y);
        }
    }
}


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

using ll=long long;
int main()
{
  int n;
  ll k;
  cin>>n>>k;
  vector<int> a(n);
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
  }
  
  vector<int> root(n,0);
  int n_start=1;
  ll n_behind=0;
  while(root[n_start-1]==0)
  {
    root[n_start-1]++;
    n_start=a[n_start-1];
    n_behind++;
  }
  
  ll n_loop=0;
  vector<int> loop;
  int m=n_start;
  do
  {
    loop.push_back(m);
    m=a[m-1];
    n_loop++;
  }while(m!=n_start);
  
  if(k<n_behind)
  {
    int result=1;
    for(int i=0;i<k;i++)
    {
      result=a[result-1];
      if(i==k-1)
      {
        cout<<result<<endl;
        return 0;
      }
    }
  }
  else
  {
    k-=n_behind;
    cout<<loop[k%n_loop]<<endl;
  }
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)
#define deg_to_rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad_to_deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)

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 MAX 1400

struct Rect { int height; int pos; };

// ヒストグラムから最大長方形面積を取得
int getLargestRect(int size, int buffer[]) {
  stack<Rect> S;
  int maxv = 0;
  buffer[size] = 0;

  rep(i, 0, size+1) {
    Rect rect;
    rect.height = buffer[i];
    rect.pos = i;
    if (S.empty()) {
      S.push(rect);
    } else {
      if (S.top().height < rect.height) {
        S.push(rect);
      } else if (S.top().height > rect.height) {
        int target = i;
        while (!S.empty() && S.top().height >= rect.height) {
          Rect pre = S.top(); S.pop();
          int area = pre.height * (i - pre.pos);
          maxv = max(maxv, area);
          target = pre.pos;
        }

        rect.pos = target;
        S.push(rect);
      }
    }
  }

  return maxv;
};

int H, W;
int buffer[MAX][MAX];
int T[MAX][MAX];

int solve() {
  rep(j, 0, W) {
    rep(i, 0, H) {
      if (buffer[i][j]) {
        T[i][j] = 0;
      } else {
        T[i][j] = (i > 0) ? T[i - 1][j] + 1 : 1;
      }
    }
  }

  int ret = 0;

  rep(i, 0, H) {
    ret = max(ret, getLargestRect(W, T[i]));
  }

  return ret;
};

int main() {
  scanf("%d %d", &H, &W);

  rep(i, 0, H) {
    rep(j, 0, W) {
      scanf("%d", &buffer[i][j]);
    }
  }
  int ans = solve();
  cout << ans << endl;
};



Measured memory_bytes: 18484
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNextInt()){
			int cnt=0;
			int n=sc.nextInt();
			if(n>50) break;
			for(int i1=0;i1<=n;i1++){
				if(i1>9) continue;
				for(int i2=0;i2<=n-i1;i2++){
					if(i2>9) continue;
					for(int i3=0;i3<=n-i1-i2;i3++){
						if(i3>9) continue;
						if(n-i1-i2-i3>9) continue;
						cnt++;
					}
				}
			}
			System.out.println(cnt);
		}
		sc.close();
	}
}

Measured memory_bytes: 19092
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int DP[400][400];

int main() {
    int N;
    cin>>N;
    int s[N], l[N], p[N];
    for(int i=0;i<N;++i){
        cin>>s[i]>>l[i]>>p[i];
    }
    int M;
    cin>>M;
    int w[M];
    for(int i=0;i<M;++i){
        cin>>w[i];
    }
    bool can = true;
    int ans[M];
    for(int i=0;i<M;++i){
        for(int j=0;j<N;++j){
            for(int k=0;k<=w[i];++k){
                if(k==0) DP[j][k] = 0;
                else DP[j][k] = -1;
            }
        }
        for(int j=0;j<=w[i];++j){
            if(DP[0][j]>-1){
                for(int k=s[0];(k<=l[0])&&(j+k<=w[i]);++k){
                    DP[0][j+k] = DP[0][j] + p[0];
                }
            }
        }
        for(int j=1;j<N;++j){
            for(int k=0;k<=w[i];++k){
                if(k>=s[j]){
                    for(int a=s[j];(a<=l[j])&&(k-a>=0);++a){
                        if(DP[j][k-a]>-1) {
                            DP[j][k] = max(DP[j-1][k], max(DP[j][k], DP[j][k-a] + p[j]));
                            break;
                        }
                        else DP[j][k] = DP[j-1][k];
                    }
                }
                else{
                    DP[j][k] = DP[j-1][k];
                }
            }
        }
        if(DP[N-1][w[i]]==-1) can = false;
        else ans[i] = DP[N-1][w[i]];
    }
    if(can){
        for(int i=0;i<M;++i){
            cout<<ans[i]<<endl;
        }
    }
    else cout<<-1<<endl;
}




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

#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define repm(i, a, b) for (int i = (a); i > (b); i--)

using namespace std;
using ll = long long;


int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  rep(i,0,n) cin >> a[i]; sort(a.begin(), a.end());
  rep(i,0,n) cin >> b[i]; sort(b.begin(), b.end());
  rep(i,0,n) cin >> c[i]; sort(c.begin(), c.end());
 
  ll ans = 0;
  
 
  vector<ll> larger_b_pos_than_a(n);
  vector<ll> larger_c_pos_than_b_sum(n);
  rep (i,0,n) {
    larger_b_pos_than_a[i] = n - distance(b.begin(), lower_bound(b.begin(), b.end(), a[i]+1));
  }
  repm (i,n-1,-1) {
    if (i==n-1) {
      larger_c_pos_than_b_sum[i] = n - distance(c.begin(), lower_bound(c.begin(), c.end(), b[i]+1));
    } else {
      larger_c_pos_than_b_sum[i] = larger_c_pos_than_b_sum[i+1] + n - distance(c.begin(), lower_bound(c.begin(), c.end(), b[i]+1));
    }
  }
 
  rep (i,0,n) {
    ans += larger_c_pos_than_b_sum[n-larger_b_pos_than_a[i]];
  }
 
  cout << ans << endl;
 

  return 0;
}

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

#define N_MAX 100000
#define W_MAX 10000

typedef long long ll;

int ws[N_MAX];
int n;
int k;

int check(const ll P) {
	ll sum = 0;
	int count = 0;
	for (int i = 0; i < n; ++i) {
		sum += ws[i];
		while (sum > P) {
			sum = ws[i];
			++count;
			if (count == k) {
				return i;
			}
		}
	}
	return n;
}

ll solve() {
	ll begin = 0;
	ll end = N_MAX * W_MAX;

	while (begin < end) {
		ll mid = (begin + end) / 2;
		if (check(mid) < n) {
			begin = mid + 1;
		} else {
			end = mid;
		}
	}
	return begin;
}

int main() {
	std::cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		std::cin >> ws[i];
	}

	std::cout << solve() << std::endl;

	return 0;
}

Measured memory_bytes: 1548
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	long long int L, r,i,j;
	cin >> L >> r;
	int x=0;
	int min=2020;
	for (i = L; i <= r; i++) {
		if (i % 2019 == 0) {
			min = 0;
			break;
		}
		for (j = i + 1; j <= r; j++) {
			if (j % 2019 == 0 ) {
				min = 0;
				break;
			}
			x = (i % 2019 * j % 2019) % 2019;
			if (min > x) {
				min = x;
			}
			
			x = 0;
		}
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
 
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
 

#define    int                   long long int 
#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    pll                      pair <long long int , long long int>
#define    ppl                      pair <long long int , pll>              //pair of ll and pair ll 
#define    sp(x)                    setprecision(x)
 

int32_t main()
{
    speed upp
    int n,m;
    cin>>n>>m;
    char s[n+1][m+1];
    f(i,1,n)
        f(j,1,m)
            cin>>s[i][j];
    int dp[n+1][m+1];
    
    f(i,0,n)
        f(j,0,m)
        dp[i][j]=0;
    dp[0][1]=1;
    f(i,1,n)
        f(j,1,m)
        {
            if(s[i][j]=='#')
                continue;
            dp[i][j]=(dp[i-1][j]+ dp[i][j-1])%mod;
        }
    cout<<dp[n][m];
}

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

using namespace std;

const int N = 1e3 + 3 , M = 1e4 + 4;
int memo[N][M];
int A[N] , B[N] , n;

int solve (int i , int rem) {
    if (rem <= 0)
        return 0;

    if (i == n)
        return 1e9;

    int &ret = memo[i][rem];
    if (~ret)
        return ret;

    return ret = min(solve(i + 1 , rem) , solve(i , rem - A[i]) + B[i]);
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    int h;
    cin >> h >> n;
    for (int i = 0 ;i < n ;i++)
        cin >> A[i] >> B[i];

    memset(memo , -1 , sizeof memo);
    cout << solve(0 , h);
}


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

int main(){
    int N, X;
    cin >> N >> X;
    vector<int> L(N + 1, 0);
    for(int i = 1; i < N + 1; i++)
        cin >> L[i];
    

    int dist = 0, cnt = 1;
    for(int i = 1; i < N + 1; i++){
        dist += L[i];
        if(dist > X)
            break;
        else
            cnt++;
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };



int main() {

	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;


	if (s1.at(s1.size() - 1) == s2.at(0) && s2.at(s2.size() - 1) == s3.at(0)) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

import math
from decimal import Decimal

A, B = input().split()

# A=int(A)
# B=float(B)

temp = Decimal(A)*Decimal(B)
print(int(math.floor(temp)))

Measured memory_bytes: 10072
(n,m,x),*z=$<.map{|s|s.split.map &:to_i}
s=nil
(1<<n).times{|b|
r=[0]*m
d=0
n.times{|i|
c,*a=z[i]
if b[i]==1
d+=c
m.times{|j|r[j]+=a[j]}
end
}
if r.all?{|y|y>=x}
s ? s=[s,d].min : s=d
end
}
p s||-1

Measured memory_bytes: 14928
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;

inline bool check(ll x, ll y, ll xMax, ll yMax) { return x >= 0 && y >= 0 && xMax > x && yMax > y; }
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string tostring(T x) { ostringstream sout; sout << x; return sout.str(); }
template<class T> inline T sqr(T x) { return x*x; }
template<class T> inline T mypow(T x, ll n) { T res = 1; while (n > 0) { if (n & 1)res = res * x;	x = x * x;	n >>= 1; }return res; }
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

#define For(i,a,b)	for(ll (i) = (a);i < (b);(i)++)
#define rep(i,n)	For(i,0,n)
#define rFor(i,a,b)	for(ll (i) = (a-1);i >= (b);(i)--)
#define rrep(i,n)	rFor(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define sz(a)		(sizeof(a))
#define tostr(a)	tostring(a)
#define dump(val) 	cerr << #val " = " << val << endl;
#define Fill(a,v)	fill((int*)a,(int*)(a+(sz(a)/sz(*(a)))),v)

const ll dx[8] = { 1, 0, -1, 0, 1, 1, -1, -1 }, dy[8] = { 0, -1, 0, 1, -1, 1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = 1e17 + 9;

#define int ll
#define double ld

map<ll, int> primeFactor(ll n) {
	map<ll, int> res;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1)res[n] = 1;
	return res;
}

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

	int n;
	cin >> n;

	map<int, int> mp;

	for (int i = 1; i <= n; i++) {
		auto t = primeFactor(i);
		each(j, t) {
			mp[j.first] += j.second;
		}
	}
	int ans = 1;
	each(i, mp) {
		ans = ans * (i.second + 1);
		ans %= mod;
	}

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

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (c == 0) {
    cout << "YES\n";
    return 0;
  }
  const int res = a%b;
  int sum = res;
  while (sum != 0) {
    if (sum == c) {
      cout << "YES\n";
      return 0;
    }
    sum += res;
    sum %= b;
  }
  cout << "NO\n";
  return 0;
}

Measured memory_bytes: 256
<?php

function input() {
    return trim(fgets(STDIN));
}
function input_array() {
    return explode(' ', input());
}

function search($A, $key) {
    $i = 0;
    $count = count($A);
    $A[$count] = $key;
    while ($A[$i] !== $key) $i++;
    return $i !== $count;
}

input();
$A = array_map(function($numeric_string) {
    return (int)$numeric_string;
}, input_array());

input();

echo array_sum(array_map(function($key) use ($A) {
    return (int)search($A, (int)$key);
}, input_array())) . "\n";


Measured memory_bytes: 12420
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { 
  INIT(){cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int sx, sy, tx, ty; 
  cin >> sx >> sy >> tx >> ty;

  REP(i, tx-sx) cout << 'R';
  REP(i, ty-sy) cout << 'U';
  REP(i, tx-sx) cout << 'L';
  REP(i, ty-sy+1) cout << 'D';
  REP(i, tx-sx+1) cout << 'R';
  REP(i, ty-sy+1) cout << 'U';
  cout << "LU";
  REP(i, tx-sx+1) cout << 'L';
  REP(i, ty-sy+1) cout << 'D';
  cout << 'R' << "\n";

  return 0;
}

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

using namespace std;

using VI = vector<int>;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IN(v) int v;cin>>v;
#define OUT(v) cout<<v<<endl

int pos = 0;
VI pre_order, in_order, post_order;

template <typename T> void print(T v) {
  cout << *(v.begin());
  for (auto it = v.begin() + 1; it != v.end(); ++it)
    cout << " " << *it;
  cout << endl;
}
void make_tree(VI::iterator s, VI::iterator t) {
  if (s == t)
    return;
  auto root = pre_order[pos++];
  auto it = find(s, t, root);
  make_tree(s, it);
  make_tree(it + 1, t);
  post_order.push_back(root);
}
int main() {
  IN(N);

  REP(i, N) {
    IN(a); pre_order.push_back(a);
  }
  REP(i, N) {
    IN(a); in_order.push_back(a);
  }
  make_tree(in_order.begin(), in_order.end());

  print(post_order);
  return 0;
}



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

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

    string s;
    cin >> s;

    for(int i = 0; i < s.length(); i += 2) {
        cout << s[i];
    }

    cout << endl;
}

Measured memory_bytes: 592
import java.util.*;
class Main
{
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt() ;int b = s.nextInt() ;int  c = s.nextInt() ;int 	x = s.nextInt();
		long count  =0 ;
		for(int i=0;i<=a;i++)
		{
			for(int j =0 ;j<=b;j++)
			{
				for(int k =0;k<=c;k++)
				{
					long sum = 500*i+100*j+50*k;
					if(sum == x)
					{
						// System.out.println(i+"  "+j+"   "+k +"  "+sum+"  "+x);
						count++;
					}
				}
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

struct UnionFind{
    vector<int> par;
    vector<int> rank;
    vector<ll> connection;

    UnionFind(int N):par(N),rank(N),connection(N){
        rep(i,N){
          par[i] = i;
          rank[i] = 0;
          connection[i] = 1;
        }
    }

    int root(int x){
       while(x != par[x]){
        x =  par[x] = par[par[x]];
       }
       return x;
    }
    
    bool same(int x,int y){
      return root(x) == root(y);
    }

    void unite(int x,int y){
        int rx = root(x);
        int ry = root(y);
        if(!same(x,y)){
            connection[root(x)] += connection[root(y)];
            connection[root(y)] = connection[root(x)];
        }else{
          return ;
        }
        if(rx == ry)return;
        if(rank[x] > rank[y]){
          par[y] = rx;
        }
        if(rank[x] < rank[y]){
          par[rx] = ry;
        }else{
          par[ry] = rx;
          if(rank[x] == rank[y]){
            rank[rx]++;
          }
        }
    }

    ll SIZE(int x){
        return connection[root(x)];
    }
};

ll N,K,L;
UnionFind R(200010),T(200010);

int main(){
    cin >> N >> K >> L;
    rep(i,K){
        ll a,b;
        cin >> a >> b;
        a--;b--;
        R.unite(a,b);
    }
    rep(i,L){
        ll a,b;
        cin >> a >> b;
        a--;b--;
        T.unite(a,b);
    }
    map<pair<ll,ll>,ll> mp;
    rep(i,N){
      mp[make_pair(R.root(i),T.root(i))]++;
    }
    rep(i,N) cout << mp[make_pair(R.root(i),T.root(i))] << ' ';
    cout << endl;
}


Measured memory_bytes: 18304
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ms(a,b) memset(a,b,sizeof(a))
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const int maxn=1e6+10;
const int mod=1e9+7;
const int maxm=1e3+10;
using namespace std;
struct wzy
{
    int day,money;
}p[maxn];
bool cmp(wzy u,wzy v)
{
    return u.day<v.day;
}
int main(int argc, char const *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++)
    	cin>>p[i].day>>p[i].money;
    sort(p,p+n,cmp);
    int ans=0;
    int cnt=0;
    priority_queue<int>que;
    for(int i=1;i<=m;i++)
    {
        while(p[cnt].day<=i && cnt<n)
        {
            que.push(p[cnt].money);
            cnt++;
        }
        if(que.empty()) 
        	continue;
        ans+=que.top();
        que.pop();
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
int main(){
    int n,y;
    cin >> n >> y;
    if(n*1000>y||n*10000<y){
        cout << -1 << " " << -1 << " " << -1 << endl;
        return 0;
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=n-i;j++){
            if(i*1000+j*5000+(n-i-j)*10000==y){
                cout << n-i-j << " " << j << " " << i << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define RNG(i,from,to) for(ll i=(from); i<(ll)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;

int main(int argc, char const *argv[])
{
  ll N; cin >> N;
  vecll V(N), OR(N);
  REP(i, N) {
    cin >> V[i];
    OR[i] = V[i];
  }
  sort(V.begin(), V.end());
  ll m1 = V[(N/2) - 1];
  ll m2 = V[N/2];
  REP(i, N) {
    ll res = 0;
    if (OR[i] <= m1) {
      res = m2;
    } else {
      res = m1;
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 6432
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		long a = sc.nextLong();
		long b = sc.nextLong();
		if(a<b/2){
			System.out.println(a+(b/2-a)/2);
		}else{
			System.out.println(b/2);
		}
	}
}

Measured memory_bytes: 21844
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N;

    print(N % 1000 == 0 ? 0 : 1000 - N % 1000);
    
}


Measured memory_bytes: 3688
map$q[$_]+=$q[$N]/@$N,@{/ /,push@
$`,$' for<>;$N=$_}for++$q[1]..<>;${$b=1;$e[$N]=$b+=$_/@@for@@=sort@e[@$N];a}<($~=$q[$N]*=$#@&&($b-1-$@[-1])/$#@)or$a=$~while--$N;print$a+$b

Measured memory_bytes: 42368
// abc154_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    string S;
    cin >> S;
    
    string ans;
    REP(i, S.size()){
        ans += 'x';
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 256
<?php
  fscanf(STDIN, "%d", $H);
  fscanf(STDIN, "%d", $W);
  fscanf(STDIN, "%d", $N);

  $max = max($H, $W);
  $ans = 0;

  if($N % $max === 0){
    $ans = (int)$N / $max; 
  }else{
   	for($i=0;$i<$max;$i++){
     	if($i * $max > $N){
         	 $ans = $i;
          break;
        }
    }
  }

echo $ans;
?>

  

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

#define ll long long
#define mod 1000000007

ll dp[2005];

ll solve(int s)
{
    if(s==0) return 1;
    if(s<3) return 0;
    if(dp[s]!=-1) return dp[s];
    dp[s]=0LL;
    for(int i=3;i<=s;i++)
        dp[s] = (dp[s]%mod+ solve(s-i)%mod)%mod;
    return dp[s];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int s;
    cin >> s;
    if(s<3)
    {
        cout << 0 << endl;
        return 0;
    }
    for(int i=0;i<=s;i++) dp[i]=-1LL;
    cout << solve(s) << endl;

}


Measured memory_bytes: 3660
def read_input():
    s = input()
    former = s[:2]
    latter = s[2:]
    return int(former), int(latter)


def can_month(x):
    return 1 <= x <= 12


def submit():
    f, l = read_input()

    if can_month(f) and can_month(l):
        print('AMBIGUOUS')
        return

    if can_month(f):
        print('MMYY')
        return

    if can_month(l):
        print('YYMM')
        return

    print('NA')

if __name__ == '__main__':
    submit()


Measured memory_bytes: 38256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<cstring>
#define M 1000000007
using namespace std;
int n,pre,pos;
queue<int> q;
string s1,s2;
long long res;
int main(){
	std::ios::sync_with_stdio(false);
	cin>>n>>s1>>s2;s1+='*';
	for (int i=0;i<n;i++)
		if (s1[i]==s1[i+1])	q.push(2),i++;else q.push(1);
	pos=q.front();q.pop();
	if (pos==1) res=3;else res=6;
	while (!q.empty()){
		pre=pos;pos=q.front();q.pop();
		if (pre==pos) {if (pre==1) res=(res*2)%M;else res=(res*3)%M;}
		else	if (pre==1) res=(res*2)%M;
	}
	cout<<res;
	return 0;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] S = new String[n];
        for(int i = 0; i < n ; i++) S[i] = sc.next();
        String res = "";
        Arrays.sort(S);
        for(char c : S[0].toCharArray()) {
            boolean flag = true;
            for(int i = 1; i < n; i++) {
                if(!S[i].contains(String.valueOf(c))) {
                    flag = false;
                    break;
                }
                int idx = S[i].indexOf(c);
                char[] t = S[i].toCharArray();
                t[S[i].indexOf(c)] = '.';
                S[i] = String.valueOf(t);
            }
            if(flag) res += c;
        }
        if(n == 1) res = S[0];
        char[] t = res.toCharArray();
        Arrays.sort(t);
        res = String.copyValueOf(t);
        System.out.println(res);
    }
}


Measured memory_bytes: 23376
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        sc.nextLine();
        String B = sc.next();
        sc.nextLine();
        int C = sc.nextInt(); 
        String cha = B.substring(C-1,C);
        String ans = "";
        
        int n = B.length();
        //System.out.println(n);
        //System.out.println(cha);
               
        for(int i=1;  i <= n ; i++ ){
            if ( B.substring(i-1,i).equals(cha)){
               ans = ans + cha;
            }
            else {
               ans = ans + "*";
            }
            //System.out.println(ans);
        }
        System.out.println(ans);
    }
}

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

int main(){
  int64_t a,b;
  cin>>a>>b;
  if(a*b<=0)
    cout<<"Zero"<<endl;
  else if(a>0)
    cout<<"Positive"<<endl;
  else if((b-a)%2==1)
    cout<<"Positive"<<endl;
  else
    cout<<"Negative"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
template<class T> inline void YES(T condition) { 
    if(condition) cout << "YES" << endl;
    else cout << "NO" << endl;
}
template<class T> inline void Yes(T condition) {
    if(condition) cout << "Yes" << endl;
    else cout << "No" << endl;
}
template<class T> T gcd(T a, T b) {
    if(a && b) { return gcd(min(a, b), max(a, b) % min(a, b)); }
    else { return a; }
}
template<class T> T lcm(T a, T b){
    return a / gcd(a, b) * b;
}
const int MOD = 2019;
long long qpow(long long a, long long b) {
    if (b == 0) return 1;
    long long res = 1;
    while (b) {
        if (b & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}

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

    string s;
    cin >> s;
    int n = s.size();
    bool ok = (s.front() == s.back()) ^ (n & 1);
    cout << (ok ? "First" : "Second") << '\n';

    return 0;
}


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

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> h(n);
    vector<bool> low(n);
    for(int i = 0;i < n;i++){
        low.at(i) = false;
        cin >> h.at(i);
    }
    for(int i = 0;i < m;i++){
        int a,b;
        cin >> a >> b;
        if(h.at(a - 1) > h.at(b - 1)){
            low.at(b - 1)= true;
        } else if(h.at(a - 1) < h.at(b - 1)){
            low.at(a - 1)= true;
        } else {
            low.at(a-1) = true;
            low.at(b-1) = true;
        }
    }
    int cnt = 0;
    for(int i = 0;i < n;i++){
        if(low.at(i) == false){cnt++;}
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
   char a,b;
   cin >> a >> b;
   if (a=='H'){
      if (b=='H') cout << "H" << endl;
      else cout << "D" << endl;
   }
   else {
      if (b=='H') cout << "D" << endl;
      else cout << "H" << endl;
   }
  

   return 0;
}



Measured memory_bytes: 256
#  =========     /\       /|    |====/|
#      |        /  \       |    |   / |
#      |       /____\      |    |  /  |
#      |      /      \     |    | /   |
#  ========= /        \  =====  |/====|  
#  code

def main():
    x = int(input())
    ans = 0
    ans += (x // 500) * 1000
    x -= (x // 500) * 500
    ans += (x // 5) * 5
    print(ans)
    return

if __name__ == "__main__":
    main()

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

// #undef DEBUG
// #define DEBUG
/// {{{ DEBUG --- ///
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { if(&o == &cerr) { o << '{'; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; } else { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); } return o; }
#ifdef DEBUG
#ifdef USE_COUT
#define dump(...) (cout<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n")
#else
#define dump(...) (cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<make_tuple(__VA_ARGS__)<<"\n")
#endif
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream &o, tuple<T...> const &t){ o << "("; _ot<0>(o, t); o << ")"; return o; }
template<class T, class U> ostream & operator<<(ostream &o, pair<T, U> const &p) { o << "(" << p.first << ", " << p.second << ")"; return o; }
#else
#define dump(...) (0)
#endif
/// }}}--- ///

const int N = 1002;
int n, m;
ll x[3][N];
vector<vector<ll>> d(8, vector<ll>(N));
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  for(int i = 1; i <= n; i++) cin >> x[0][i] >> x[1][i] >> x[2][i];
  for(int i = 1; i <= n; i++) {
    for(int j = 0; j < 8; j++) {
      ll res = 0;
      for(int k = 0; k < 3; k++) {
        res += ((j & (1 << k)) ? 1 : -1) * x[k][i];
      }
      dump(j, i, res);
      d[j][i] = res;
    }
  }
  
  ll ans = 0;
  for(int j = 0; j < 8; j++) {
    ll res = 0;
    sort(begin(d[j]) + 1, begin(d[j]) + 1 + n);
    reverse(begin(d[j]) + 1, begin(d[j]) + 1 + n);
    for(int i = 1; i <= m; i++) res += d[j][i];
    ans = max(ans, res);
  }
  cout << ans << endl;
}



Measured memory_bytes: 384