akhauriyash/Code-Regression huggingface dataset:
import heapq

n=int(input())
pts=[list(map(int,input().split())) for _ in range(n)]

x=sorted([(i,pts[i][0]) for i in range(n)],key=lambda x:x[1])
y=sorted([(i,pts[i][1]) for i in range(n)],key=lambda x:x[1])

invx=[0]*n
invy=[0]*n

for i in range(n):
    cx,_=x[i]
    invx[cx]=i
    cy,_=y[i]
    invy[cy]=i

xi=invx[0]
yi=invy[0]

q=[(0,0)]


visit=[0]*n
ans=0

while q:
    cnt,i=heapq.heappop(q)

    if visit[i]==1:
        continue

    visit[i]=1
    ans+=cnt

    xi=invx[i]
    yi=invy[i]

    if xi>0 and visit[x[xi-1][0]]==0:
        heapq.heappush(q,(x[xi][1]-x[xi-1][1],x[xi-1][0]))
    if xi<n-1 and visit[x[xi+1][0]]==0:
        heapq.heappush(q,(x[xi+1][1]-x[xi][1],x[xi+1][0]))

    if yi>0 and visit[y[yi-1][0]]==0:
        heapq.heappush(q,(y[yi][1]-y[yi-1][1],y[yi-1][0]))
    if yi<n-1 and visit[y[yi+1][0]]==0:
        heapq.heappush(q,(y[yi+1][1]-y[yi][1],y[yi+1][0]))
    
print(ans)

Measured memory_bytes: 133468
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> segs;
    for(int i = 1; i <= m; i++) {
        int a, b;
        cin >> a >> b;
        segs.push_back({a, b});
    }
    sort(segs.begin(), segs.end(), [](auto& p1, auto& p2) {
        return p1.second < p2.second;
    });
    int last_cut = 0;
    int ans = 0;
    for(auto& seg : segs) {
        if(seg.first >= last_cut) {
            last_cut = seg.second;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1528
def divisors(N):
    U = int(N ** 0.5) + 1
    L = [i for i in range(1, U) if N % i == 0]
    return L + [N // i for i in reversed(L) if N != i * i]

def main():
    N, K, *A = map(int, open(0).read().split())

    for d in reversed(divisors(sum(A))):
        R = sorted(a % d for a in A)
        if sum(R[:-sum(R) // d]) <= K:
            print(d)
            quit()

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std ;
template< class T > inl T read() {
	T x = 0 ; int f = 1 ; char k = getchar() ;
	for( ; k > '9' || k < '0'; k = getchar() ) if( k == '-' ) f = -1 ;
	for( ; k >= '0' && k <= '9'; k = getchar() ) x = x * 10 + k - '0' ;
	return x * f ;
}
template< class T > inl T read( T &x ) { return x = read<T>() ; }
int _num, _buf[20];
template< class T > il print( T x ) {
   	if( x == 0 ) return putchar( '0' ) ,void() ;
	if( x < 0 ) putchar( '-' ), x = -x ;
	while( x ) _buf[++_num] = x % 10, x /= 10 ;
	while( _num ) putchar( _buf[_num--] + '0' ) ;
}
ll mul( ll a, ll b, ll mod ) { long double c = 1. ; return ( a * b - (ll)( c * a * b / mod ) * mod ) % mod ; }
it qpow( int x, int m, int mod ) {
	int res = 1, bas = x ;
	while(m) {
		if( m & 1 ) res = ( 1ll * res * bas ) % mod ;
		bas = ( 1ll * bas * bas ) % mod, m >>= 1 ;
	}
	return res ;
}
const double pi = acos( -1. ) ;
int A, B, H, M;
int main() {
//	freopen( ".in", "r", stdin ) ;
//	freopen( ".out", "w", stdout ) ;
	A = read<int>(), B = read<int>(), H = read<int>(), M = read<int>() ;
	double x = 2 * pi / 60, y = 2 * pi / 60 / 12 ;
	double ang1 = x * M ;
	double ang2 = y * ( 60 * H + M ) ;
	double ang = fabs( ang1 - ang2 ) ;
	double res = A * A + B * B - 2 * A * B * cos( ang ) ;
	res = sqrt( res ) ;
	printf( "%.12f\n", res ) ;
	cerr << 1. * clock() / CLOCKS_PER_SEC << "\n" ;
	return 0;
}

Measured memory_bytes: 4176
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

int main(void){
	int a, b;
	char s;
	cin >> a >> s >>b;
		
	if(s == '+') cout << a+b << endl;
	else cout << a-b << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int	main(void)
{
	int h;
	int a;
	int count;
	count = 0;
	scanf("%d%d", &h, &a);
	while (h > 0)
	{
		h -= a;
		count++;
	}
	printf("%d",count);
	return (0);
}


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

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

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const ll INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");

    int n,k; cin >> n >> k;
    vl A(n), H(n);
    rep(i,n) cin >> A[i];
    H[0] = A[0];
    REP(i,1,n) H[i] = max(H[i-1], H[i]);

    ll ans = INFL;
    rep(i,1<<n){
        if(__builtin_popcountll(i) < k) continue;
        ll res = 0, mh = 0;
        rep(j,n){
            ll h = A[j];
            if(i>>j & 1){
                h = max(mh + 1, A[j]);
                res += h - A[j];
            }
            mh = max(mh, h);
        }
        ans = min(ans, res);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>

using namespace std;

int CalHp(int x,int p)
{
  int Hp=(x-p)*(x-p);
  return Hp;
}

int main()
{
  int n;
  cin>>n;
  int sMax=0;
  int HpSum=0;
  int res=10000000;
  
  int *s=new int[n];
  for(int i=0;i<n;i++)
  {
   	cin>>s[i];
    if(s[i]>sMax)
      sMax=s[i];
  }
  for(int i=1;i<sMax+1;i++)
  {
  	for(int j=0;j<n;j++)
    {
      HpSum+=CalHp(s[j],i);
    }
    if(HpSum<res)
      res=HpSum;
    HpSum=0;
  }
  cout<<res<<endl;
}

Measured memory_bytes: 384
#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 bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

// 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 K, A, B;
  cin >> K >> A >> B;

  bool ans = false;
  FOR(i, A, B+1){
    if(i%K == 0) ans = true;
  }

  if(ans) cout << "OK" << "\n";
  else cout << "NG" << "\n";

  return 0;
}

Measured memory_bytes: 3608
import std.stdio;
import std.conv, std.array, std.algorithm, std.string;
import std.math, std.random, std.range, std.datetime;
import std.bigint;

const long MOD = 1_000_000_007;

void main(){
	int n = readln.chomp.to!int;
	
	int[] ps; // primes
	int[int] cs; // prime -> count
	for(int i = 2; i < 1000; i ++){
		int f = 1;
		for(int j = 2; j <= i / 2; j ++){
			if(i % j == 0) f = 0;
			}
		if(f){
			ps ~= i;
			cs[i] = 0;
			}
		}
	
	
	for(int i = 2; i <= n; i ++){
		int x = i;
		foreach(p; ps){
			while(x % p == 0){
				cs[p] += 1;
				x /= p;
				}
			}
		}
	
	BigInt ans;
	ans = 1;
	foreach(p; ps){
		ans *= cs[p] + 1;
		ans %= MOD;
		}
	
	ans.writeln;
	
	}

Measured memory_bytes: 380
#include <iostream>
#include <queue>
#include <map>

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

#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0;i<(n);++i)

int main() {
  int in(N);

  map<int, int> m;
  m[-1] = 0;
  m[N] = N;
  priority_queue<pii> q;
  rep(i, N) {
    int in(a);
    q.emplace(-a, i);
  }
  ll ans = 0;
  while (!q.empty()) {
    auto p = q.top(); q.pop();
    m[p.second] = p.second;
    auto l = (--m.lower_bound(p.second))->first;
    auto r = m.upper_bound(p.second)->first;
    ans += 1LL * (p.second - l) * (r - p.second) * (-p.first);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11248
#include <iostream>
#include <string>
#define REP(i,n) for(int i=0;i<(n);++i)
#define MOD 1000000007
using namespace std;
typedef long long int LL;


int main(){
  LL N;
  cin >> N;
  LL ret = 0;
  if(N % 2 == 0) {
    N /= 10;
    ret = N;
    while(N != 0) {
      N /= 5;
      ret += N;
    }
  }
  cout << ret << endl;
}

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

using namespace std;

#define count __mycount

int H, W;
int count(int rx, int ry, const vector<string>& grid){
    int res = 1;
    int curr = 0;
    bool state = false;
    for(int x = 0; x < W; x++){
        int next = ry * (x + 1) / rx;
        for(int y = curr; y <= min(next, H - 1); y++){
            char c = grid[y][x];
            // printf("x = %d y = %d c = %c state = %d\n", x, y, c, state);
            if(c == '#' && !state){
                state = true;
                res ++;
            }else if(c == '.' && state){
                state = false;
            }
        }
        if(next >= H) break;
        curr = next;
    }
    return res;
}

int main(){
    while(cin >> H >> W){
        vector<string> grid(H);
        REP(y, H) cin >> grid[H - 1 - y];

        int ans = 0;
        for(int y = 1; y <= H + 1; y++){
            for(int x = 1; x <= W + 1; x++){
                ans = max(ans, count(x, y, grid));
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1840
#include <map>
#include <cstdio>

using std::map;

int n, m, x, m1, m2;

map <int, int> p;

int main() {
	scanf("%d", &n);
	for(int i = 0;i < n;i ++) {
		scanf("%d", &x);
		p[x] = 1;
	}
	m = p.size();
	
	for(map<int, int>::iterator iter1 = p.begin();iter1 != p.end();iter1 ++)
		m1 ++;
	for(auto iter2 : p) 
		m2 ++;
	if(m1 != m || m2 != m)
		puts("ERROR");
	
	m -= !(m & 1);
	printf("%d", m);
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
using namespace std;

const double PI=acos(-1);

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

    vector<int> a(n, 0), b(n, 0);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    b = a;
    sort(b.begin(), b.end(), greater<int>());
    for(int i = 0; i < n; i++){
        if(a[i] == b[0]) cout << b[1] << endl;
        else cout << b[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 3200
#include<iostream>
using namespace std;
#define MAX 500000

void max_heapify(int T[], int s, int i) {
	int left, right, largest;
	left = 2 * i;
	right = ( 2 * i ) + 1;
	if (left <= s && T[left] > T[i]) {
		largest = left;
	}
	else largest = i;
	if (right <= s && T[right] > T[largest]) {
		largest = right;
	}
	if (largest != i) {
		swap(T[i], T[largest]);
		max_heapify(T,s,largest);
	}
}

int main() {
	int s, T[MAX];
	cin >> s;
	for (int i = 1; i <= s; i++) {
		cin >> T[i];
	}
	for (int i = s / 2; i >= 1; i--) {
		max_heapify(T, s, i);
	}
	for (int i = 1; i <= s; i++) {
		cout << " " << T[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3112
#include<stdio.h>
int x[100001],f[100001],su[100001];
int main(void)
{
	int n,m,i,j,y,a,b,c;
	long long sum,nn,mm;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++)	scanf("%d",&x[i]);
	for(i=1;i<=n;i++) f[i]=0;
	for(i=1;i<m;i++){
		if(x[i-1]<x[i]){
			f[x[i-1]]++;	f[x[i]]--;
		}
		else{
			f[x[i]]++;	f[x[i-1]]--;
		}
	}
	y=0;
	for(i=1;i<=n;i++){
		y+=f[i];	su[i]=y;
	}
	sum=0;
	for(i=1;i<n;i++){
		scanf("%d %d %d",&a,&b,&c);
		nn=(long long)a*su[i];
		mm=(long long)b*su[i]+c;
		if(nn<mm) sum+=nn;
		else sum+=mm;
	}	
	printf("%lld\n",sum);	
	return 0;
}

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

int main()
{
	int a, b;
	int i;
	int sum;
	int digits[200];
	int roop = 0;
	char buf[16];
	
	while ( scanf( "%d %d", &a, &b ) != EOF ) 
	{
		sum = a + b;
		sprintf( buf, "%d", sum );
		digits[roop] = strlen( buf );
		roop = roop + 1;
	}

	for ( i = 0 ; i < roop ; i++ )
	{
		fprintf( stdout, "%d\n", digits[i] );
	}

	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#include <time.h>
#include <stdlib.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(a) a.begin(),a.end()
#define ign cin.ignore();

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

using namespace std;
using namespace __gnu_pbds;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef MY_PROJECT
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main()
{
    IOS
    int x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vpii vec;
    for(int i=0;i<a;i++)
    {
        int temp;
        cin>>temp;
        vec.pb(mp(temp,2));
    }
    for(int j=0;j<b;j++)
    {
        int temp;
        cin>>temp;
        vec.pb(mp(temp,1));
    }
    for(int i=0;i<c;i++)
    {
        int temp;
        cin>>temp;
        vec.pb(mp(temp,0));
    }
    sort(all(vec),greater<>());
    ll res=0;
    int red=0,green=0,colorless=0;
    int cur=0;
    while(red+green+colorless<x+y&&cur<vec.size()){
        if(vec[cur].second==2){
            if(red<x){
                red++;
                res=res+(ll)vec[cur].first;
            }
            cur++;
        }
        else if(vec[cur].second==1){
            if(green<y){
                green++;
                res=res+(ll)vec[cur].first;
            }
            cur++;
        }
        else{
            colorless++;
            res=res+(ll)vec[cur].first;
            cur++;
        }
    }
    cout<<res;
    return 0;
}


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

int main(){
  int n;
  char moji[1024];
  char m1[5]={'.',',','!','?',' '};
  char m2[3]={'a','b','c'};
  char m3[3]={'d','e','f'};
  char m4[3]={'g','h','i'};
  char m5[3]={'j','k','l'};
  char m6[3]={'m','n','o'};
  char m7[4]={'p','q','r','s'};
  char m8[3]={'t','u','v'};
  char m9[4]={'w','x','y','z'};
  
  cin >> n;

  for(int i=0;i < n;i++){
    char write;
    int cnt=0;
    int flag=0;
    
    scanf("%s",moji);
    
    for(int j=0;moji[j] != '\0';j++){
      
      if(moji[j] == '1'){
	if(cnt == 5) cnt=0;
	write = m1[cnt];
	flag=1;
	cnt++;
      }
      else if(moji[j] == '2'){
	if(cnt == 3) cnt=0;
	write = m2[cnt];
	flag=1;
	cnt++;
      }
      else if(moji[j] == '3'){
	if(cnt == 3) cnt=0;
	write = m3[cnt];
	flag=1;
	cnt++;
      }
      else if(moji[j] == '4'){
	if(cnt == 3) cnt=0;
	write = m4[cnt];
	flag=1;
	cnt++;
      }
      else if(moji[j] == '5'){
	if(cnt == 3) cnt=0;
	write = m5[cnt];
	flag=1;
	cnt++;
      }
      else if(moji[j] == '6'){
	if(cnt == 3) cnt=0;
	write = m6[cnt];
	flag=1;
	cnt++;
      }
      else if(moji[j] == '7'){
	if(cnt == 4) cnt=0;
	write = m7[cnt];
	flag=1;
	cnt++;
      }
      else if(moji[j] == '8'){
	if(cnt == 3) cnt=0;
	write = m8[cnt];
	flag=1;
	cnt++;
      }
      else if(moji[j] == '9'){
	if(cnt == 4) cnt=0;
	write = m9[cnt];
	flag=1;
	cnt++;
      }
      else if(moji[j] == '0' && flag ==1){
	cout << write;
	flag=0;
	cnt=0;
      }
    }
    cout << endl;
  }
  return 0;
}
    



Measured memory_bytes: 3112
s = int(input())
count=0
flag=0
n = s
fourflag=0
if n == 2:
    fourflag=1
if n == 1:
    fourflag=1
while flag<2:
    if n ==4:
        flag+=1
    count+=1
    if n%2 ==0:
        n/=2
    else:
        n=3*n+1


    if flag==2:
        break
        
    
    
if fourflag==0:
    print(count)
else:
    print(4)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,l;
  cin >> n >> l;
  vector<string> list(n);
  for (int i=0; i<n; i++) {
    cin >> list.at(i);
  }
  sort(list.begin(),list.end());
  for (int i=0; i<n; i++) {
    cout << list.at(i);
  }
  cout << endl;
}

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

using namespace std;

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

  int c = 0;
  for (int i=1; i<=n; i+=2) {
    int cc = 0;
    for (int j=1; j<=i; j++) {
      if (i%j == 0) cc++;
    }

    if (cc == 8) c++;
  }

  cout << c << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
    ll n; cin>>n;
    vector<pair<ll,ll>> v;
    ll a,b;
    rep(i,n) cin>>a>>b, v.push_back(make_pair(b,a));
    sort(all(v));
    ll sum=0;
    for(auto p:v){
        sum+=p.second;
        if(sum>p.first){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}

Measured memory_bytes: 6256
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, T, *AB = map(int, read().split())
    A = AB[::2]
    B = AB[1::2]

    dp1 = [[0] * T for _ in range(N + 1)]
    for i in range(N):
        for t in range(T):
            if 0 <= t - A[i]:
                dp1[i + 1][t] = dp1[i][t - A[i]] + B[i]
            if dp1[i + 1][t] < dp1[i][t]:
                dp1[i + 1][t] = dp1[i][t]

    dp2 = [[0] * T for _ in range(N + 1)]
    for i in range(N - 1, -1, -1):
        for t in range(T):
            if 0 <= t - A[i]:
                dp2[i][t] = dp2[i + 1][t - A[i]] + B[i]
            if dp2[i][t] < dp2[i + 1][t]:
                dp2[i][t] = dp2[i + 1][t]

    ans = 0
    for i in range(N):
        tmp = max(dp1[i][t] + dp2[i + 1][T - t - 1] for t in range(T)) + B[i]
        if ans < tmp:
            ans = tmp

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 215852
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1000 + 5;
string s;
set<char> st;

int main() {
    cin >> s;
    for(char c : s) st.insert(c);
    if(st.size() == 26) {
        string tmp = s;
        if(next_permutation(s.begin(), s.end())) {
            for(int i = 0; i < s.size(); i++) {
                cout << s[i];
                if(s[i] != tmp[i]) break;
            }
            cout << '\n';
        }else puts("-1");
    }else {
        for(char c = 'a'; c <= 'z'; c++) {
            if(!st.count(c)) {
                s += c;
                break;
            }
        }
        cout << s << '\n';
    }
    return 0;
}


Measured memory_bytes: 764
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define gridif(a,x,b) if((a)<=(x)&&(x)<(b))

using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;

int digitsum(int n,int b){
	if(b<2) return -1;
	if(n<b) return n;
	return digitsum(n/b,b)+n%b;
}
int mpow(int a,int x);
int m_inv(int n);
vector<int> split(int n,int a);
string xal_number(int n,int x);
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
class Factorial{
private:
	vector<int> fac;
public:
	Factorial(int N){
		fac.push_back(1);
		rep(i,N) fac.push_back(fac[i]*(i+1)%mod);
	}
	int fact(int a){return fac[a];}
	int ifac(int a){return m_inv(fac[a]);}
	int cmb(int n,int r);
};
struct UnionFind {
    vector<int> par; // 親ノード
    UnionFind(int n = 1) { init(n);}
    void init(int n = 1) {
        par.resize(n);
        rep(i,n) par[i] = -1;
    }
    int root(int x) {
        if (par[x] <0) return x;
        else return par[x] = root(par[x]);      
    }
    int size(int x){ return -par[root(x)];}
    bool issame(int x, int y) {return root(x)==root(y);}
    bool connect(int x, int y);
};

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<<'L'<<'U';
	rep(i,tx-sx+1) cout<<'L';
	rep(i,ty-sy+1) cout<<'D';
	cout<<'R'<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
  string s, t;
  cin >> s >> t;
  int m = s.size(), n = t.size();

  vvi dp(3010, vi(3010, 0));
  
  for(int i = 0; i < m; i++){
    for(int j = 0; j < n; j++){
      if(s.at(i) == t.at(j)) dp.at(i+1).at(j+1) = dp.at(i).at(j) + 1;
      else{
        chmax(dp.at(i+1).at(j+1), dp.at(i+1).at(j));
        chmax(dp.at(i+1).at(j+1), dp.at(i).at(j+1));
      }
    }
  }
  
  //復元
  string res = "";
  int i = m, j = n;
  while(i > 0 && j > 0){
    if (dp.at(i).at(j) == dp.at(i-1).at(j)) i--;
    else if (dp.at(i).at(j) == dp.at(i).at(j-1)) j--;
    else{
      res = s.at(i-1) + res;
      i--; j--;
    }
  }
  cout << res << endl;

}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v[n];
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    bool ok = false;
    for (auto k : v[0]) {
        if (k == n - 1) ok = true;
        for (auto l : v[k])
            if (l == n - 1) ok = true;
    }

    if (ok)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 15016
use std::io;
use std::str::FromStr;
use std::collections::HashMap;

fn read() -> i32 {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let x: i32 = s.trim().parse().unwrap();
    x
}
fn read_char() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let x: String = s.trim().parse().unwrap();
    x
}

 fn main(){
    loop{
        let mut rules : HashMap<String,String> = HashMap::new();
    
        let n = read();
        if n == 0{
            break;
        }
        for i in 0..n{
            let mut buf = String::new();
            io::stdin().read_line(&mut buf).unwrap();
            let mut it = buf.split_whitespace().map(|n| String::from_str(n).unwrap());
            let a = it.next().unwrap();
            let b = it.next().unwrap();

            rules.insert(a,b);
        }

        let m = read();
        for i in 0..m{
            let mut a = read_char();
            match rules.get(&a){
                Some(e) =>{
                    print!("{}",e);
                },
                None => print!("{}",&a),
            }
        }
        println!();
    }
 }
 


Measured memory_bytes: 5052
#include <vector>
#include <sstream>
#include <algorithm>
#include <fstream>
#include <list>
#include <map>
#include <istream>
#include <bitset>
#include <sstream>
#include <unordered_map>
#include <stack>
#include <set>
#include <cmath>
#include <random>
#include <iostream>
#include <bitset>
#include <iomanip>
#include <queue>
#include <string>

#define int long
#define endl "\n"
#define all(x) x.begin(),x.end()
#define rr return 0
#define xx first
#define yy second
#define pii pair<int,int>

using namespace std;

typedef long long ll;
typedef long double ld;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    int ans = n * (n - 1) / 2;
    cout << ans;
    rr;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	cout << (a + b) / 2 << endl;
}


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

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

struct edge {
  int to; ll cost;
  edge(int t, ll c): to(t), cost(c) {}
};

int n;
vector<edge> G[100001];
ll mincost[100001];
bool used[100001];

ll prim(void) {
  priority_queue<P, vector<P>, greater<P> > que;
  fill(mincost, mincost + n, 1e18);
  mincost[0] = 0;
  que.push(P(0, 0));

  ll res = 0;
  while (!que.empty()) {
    P p = que.top(); que.pop();
    int v = p.second;
    if (used[v] || mincost[v] < p.first) continue;

    used[v] = true;
    res += mincost[v];

    for (int i = 0; i < G[v].size(); i++) {
      edge e = G[v][i];
      if (!used[e.to] && mincost[e.to] > e.cost) {
        mincost[e.to] = e.cost;
        que.push(P(mincost[e.to], e.to));
      }
    }
  }
  return res;
}

int main(void) {
  cin >> n;

  vector<P> x(n), y(n);
  for (int i = 0; i < n; i++) {
    cin >> x[i].first >> y[i].first;
    x[i].second = y[i].second = i;
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  
  for (int i = 0; i < n - 1; i++) {
    G[x[i].second].push_back(edge(x[i + 1].second, x[i + 1].first - x[i].first));
    G[x[i + 1].second].push_back(edge(x[i].second, x[i + 1].first - x[i].first));
    G[y[i].second].push_back(edge(y[i + 1].second, y[i + 1].first - y[i].first));
    G[y[i + 1].second].push_back(edge(y[i].second, y[i + 1].first - y[i].first));
  }

  cout << prim() << endl;
  
  return 0;
}

Measured memory_bytes: 18420
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

string s;

int main(){
    ios_base::sync_with_stdio(false);

    cin >> s;

    long long ans = 0;
    long long cnt = 0;
    
    for(int i = 0; i < s.size(); i++) {
        if(s[s.size() - i - 1] == 'B') {
            ans += i - cnt;
            cnt++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

int main()
{


  char s[200];
  char p[100];
  char smake[100];

  scanf("%s %s",s,p);

   strcpy(smake,s);
   strcat(s,smake);


  if(strstr(s,p)==NULL)printf("No\n");
  else printf("Yes\n");








return(0);

}

Measured memory_bytes: 540
#include <iostream>
//#include <iomanip>
#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
//using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	bool n,s,e,w ;
	n = s = e = w = false ;
	string str ; cin >> str ;
	for(int i=0;i<str.size();i++){
		if(str.at(i)=='N') n = true ;
		if(str.at(i)=='S') s = true ;
		if(str.at(i)=='E') e = true ;
		if(str.at(i)=='W') w = true ;
	}
	cout << yorn((n==s)&&(e==w)) << endl ;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


class UnionFind {
public:
	vector<int> s, p, es;
	map<int, int>sizemp;

	UnionFind() {}
	UnionFind(int size) {
		s.resize(size, 0);
		p.resize(size, 0);
		es.resize(size, 0);
		sizemp[1] = size;
		rep(i, 0, size)makeSet(i);
	}

	void makeSet(int x) {
		p[x] = x;
		s[x] = 0;
		es[x] = 0;
	}

	void givesize(int x){
		s[x] = 1;
	}

	bool same(int x, int y) {
		return findSet(x) == findSet(y);
	}

	void unite(int x, int y) {
		x = findSet(x);
		y = findSet(y);
		es[x]++;
		if (x == y)return;
		if (s[x] < s[y])swap(x, y);
		int szx = size(x);
		int szy = size(y);
		sizemp[szx]--;
		sizemp[szy]--;
		sizemp[szx + szy]++;
		if (sizemp[szx] == 0)sizemp.erase(szx);
		if (sizemp[szy] == 0)sizemp.erase(szy);
		p[y] = x;
		s[x] += s[y];
		es[x] += es[y];
	}


	int findSet(int x) {
		if (x == p[x]) {
			return x;
		}
		else {
			return p[x] = findSet(p[x]);
		}
	}

	int size(int x) {
		return s[findSet(x)];
	}
	int esize(int x) {
		return es[findSet(x)];
	}
	int minsz() {
		auto beg = sizemp.begin();
		return beg->first;
	}
};


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

	int N;
	cin >> N;
	map<ll, ll>mp;
	for (int i = 0; i < N; i++) {
		ll a;
		cin >> a;
		mp[a] = i;
	}
	vector<ll>li(N, -1);

	UnionFind un = UnionFind(N);
	
	ll ans = 0;
	for (ll i = N; i >= 1; i--) {
		ll idx = mp[i];
		ll cntr = 0;
		ll cntl = 0;
		li[idx] = i;
		un.givesize(idx);
		if (idx < N-1) {
			if (li[idx + 1] != -1) {
				cntr += un.size(idx+1);
				un.unite(idx, idx + 1);
			}
		}
		if (idx > 0) {
			if (li[idx - 1] != -1) {
				cntl += un.size(idx - 1);
				un.unite(idx, idx - 1);
			}
		}
		ans += i * (cntr*cntl + cntr + cntl + 1);
	}
	puts(ans);

	return 0;
}

Measured memory_bytes: 16640
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	     //  #ifndef ONLINE_JUDGE
      //  // for getting input from input.txt
      //  freopen("input.txt", "r", stdin);
      //  // for writing output to output.txt
      //  freopen("output.txt", "w", stdout);
      // #endif
		int n,a,b;
		cin>>n>>a>>b;
		n*a < b? cout<<n*a<<"\n" : cout<<b<<"\n";
	return 0;
}

Measured memory_bytes: 256
A, B = map(int,input().split())

def euclid(a0, b0):
    a = max(a0, b0)
    b = min(a0, b0)
    while(a%b != 0):
        a = a%b
        if a<b: # 入れ替え
          a = a^b
          b = a^b
          a = a^b
        #print(a,end=" ")
        #print(b)
    return b

print(A*B//euclid(A,B))  

Measured memory_bytes: 3060
<?php
fscanf(STDIN, "%d %d",$n,$m);
$x=explode(" ",rtrim(fgets(STDIN)));
$result=0;
sort($x);
for($i=0; $i < $m-1; $i++)
	$dis[$i]=$x[$i+1]-$x[$i];
sort($dis);
for ($i=0; $i < $m-$n; $i++)
	$result+=$dis[$i];
printf("%d",$result);

Measured memory_bytes: 18932
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <math.h>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 100000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main()
{
    ll x;
    cin >> x;

    for (ll a = -2000; a <= 2000; a++) {
        for (ll b = -2000; b <= 2000; b++) {
            if (a*a*a*a*a - b*b*b*b*b == x) {
                cout << a << " " << b << endl; 
                return 0;
            }
        }
    }
    return 0;
}

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

int GetCeilIndex(vector<int> &arr, vector<int> &tailIndices, int l, int r, int key){ //Use &x for Quick Reference
    while ((r-l) > 1){ //Perform Binary Search
        int m = l+(r-l)/2;
        if (arr[tailIndices[m]] >= key){
            r = m;
        } else {
            l = m;
        }
    }
    return r; //Return the Valid Index
}
 
int LongestIncreasingSubsequence(vector<int> &arr, int n) {
    vector<int> tailIndices(n, 0); //Generate a vector, of size n, filled with 0s
    int len = 1; //Default the Len to 1, since the Smallest Possible Increasing Subsequence will be 1
    for (int i = 1; i < n; i++) { //Iterate Through arr[]
        if (arr[i] < arr[tailIndices[0]]){
            tailIndices[0] = i;
        } else if (arr[i] > arr[tailIndices[len-1]]){
            tailIndices[len++] = i; //Incriment len by 1 as a Longer Increasing Subsequence has been Found
        } else {
            int pos = GetCeilIndex(arr, tailIndices, -1, len-1, arr[i]); //Possible New Longest Increasing Subsequence
            tailIndices[pos] = i;
        }
    }
    return len; //Return the Final Length of the Longest Increasing Subsequence
}
 
int main(){
    int n;
    cin >> n;
    vector<int> x(n); //Although vector<int>s will Fail the Test Cases, Performing Referencing Makes it Pass Test Cases
    for(int i = 0; i < n; i++){
        cin >> x[i];
    } //Finished Resolving Inputs
    cout << LongestIncreasingSubsequence(x, n) << endl; //Perform Solve Function
    return 0;
}



Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/





int N[3], K;
ll A[3][1010];
//---------------------------------------------------------------------------------------------------
vector<ll> B;
int BN;
int check(ll x) {
	ll cnt = 0;
	rep(i, 0, N[0]) {
		int id = lower_bound(all(B), x - A[0][i]) - B.begin();
		cnt += BN - id;
	}
	return K <= cnt;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	rep(i, 0, 3) cin >> N[i];
	cin >> K;
	rep(i, 0, 3) rep(j, 0, N[i]) cin >> A[i][j];

	rep(a, 0, N[1]) rep(b, 0, N[2]) B.push_back(A[1][a] + A[2][b]);
	sort(all(B));
	BN = B.size();

	ll ok = 0, ng = infl;
	while (ok + 1 != ng) {
		ll md = (ng + ok) / 2;
		if (check(md)) ok = md;
		else ng = md;
	}

	reverse(all(B));
	vector<ll> ans;
	rep(i, 0, N[0]) {
		fore(b, B) {
			if (ok < A[0][i] + b) ans.push_back(A[0][i] + b);
			else break;
		}
	}
	while (ans.size() < K) ans.push_back(ok);

	sort(all(ans), greater<ll>());
	rep(i, 0, K) printf("%lld\n", ans[i]);
}

Measured memory_bytes: 10604
#include<stdio.h>
#include<string.h>
int main(){
  int n,f[30]={},cnt=0;
  char s[100010];
  scanf("%s",s);
  n=strlen(s);
  for(int i=0;i<n;i++)
    f[s[i]-'a']=1;
  for(int i=0;i<30;i++)
    cnt+=f[i];
  if((n%2==1&&s[0]==s[n-1])||(n%2==0&&s[0]!=s[n-1])||cnt==2)
    printf("Second\n");
  else
    printf("First\n");
}

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

int comp(const void * a, const void * b){
    return (*(int*)a - *(int*)b);
}


int main(){
    int n,k,p[1010],i,j,w,soma=0;

    scanf("%d %d",&n,&k);

    for(j=0;j<n;j++){
        scanf("%d",&p[j]);
    }





// preciso de um for p percorrer ate o k


qsort(p,n,sizeof(int),comp);

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

    for(w=0;w<k;++w){
            soma +=p[w];// to com problema em fzr ele pegar a lista e somar o p[k]


    }
    printf("%d\n",soma);
    return 0;
}


Measured memory_bytes: 1736
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 = ListBuffer.empty[Tuple2[Int,Int]]
    a.foreach(l => {
      if(l(3) == 1) map.put(l(1),l)
      else {
        val e = map.remove(l(1)).get
        log += {( e(0), l(0) )}
        }
    })
    // println(log.mkString)

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

  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: 65712
def kyori(a, b, x, y):
    if a > b:
        a, b = b, a
    return min(abs(b - a), abs(x - a) + abs(b - y) + 1)


n, x, y = map(int, input().split())
ans = [0] * (n)

for i in range(1, n + 1):
    for j in range(i + 1, n + 1):
        # print(i, j, kyori(i, j, x, y))
        ans[kyori(i, j, x, y)] += 1
# print(ans)
for i in range(1, n):
    print(ans[i])


Measured memory_bytes: 47836
import sys
s = input()[::-1]

s_list = ['dream'[::-1], 'dreamer'[::-1], 'erase'[::-1], 'eraser'[::-1]]

while True:
  flag = False
  for l in s_list:
    if s[0:len(l)] == l:
      s = s[len(l):]
      flag = True
  if s == '':
    print('YES')
    sys.exit()
  if flag == False:
    print('NO')
    sys.exit()

Measured memory_bytes: 3188
def notfound(s):

    ans = ""
    for code in range(ord('a'), ord('z') + 1):
        if s.count(chr(code)) == 0:
            return chr(code)
    return "None"

def main():
    s = str(input())
    print(notfound(s))

if __name__ == '__main__':
    main()

Measured memory_bytes: 39024
#include <iostream>

using namespace std;

const int KMAX = 100000 + 5;
typedef long long int lint;

int K;
int A[KMAX];

int main()
{
    ios_base :: sync_with_stdio(false);
    cin >> K;
    for (int i = K; i; -- i)
        cin >> A[i];
    lint l = 2, r = 2;
    for (int i = 1; i <= K; ++ i) {
        lint l2 = ((l - 1) / A[i] + 1) * A[i];
        lint r2 = r - r % A[i];
        if (r2 < l2) {
            cout << "-1\n";
            return 0;
        }
        r2 += A[i] - 1;
        l = l2, r = r2;
    }

    cout << l << ' ' << r << '\n';
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main() {
	uint64_t N;
	cin >> N;
	vector<string>S(N);
	for (uint64_t i = 0; i <N ; ++i)
	{
		cin >> S[i];
	}
	sort(S.begin(), S.end());
	S.erase(unique(S.begin(), S.end()), S.end());

	cout << S.size() << endl;
	return 0;
}



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

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

	double sum = 0;
	for( int i = 0; i < N; i++ ) {
		sum += 1.0 / A[i];
	}
	double ans = 1.0 /sum;

	cout << fixed << setprecision(12) << ans <<  endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int status[5000][5000];

int main(void) {
	int kugi_num;
	int wagom_num;
	int A,B,X;
	int i,j;
	int count;
	int max;
	scanf("%d %d",&kugi_num,&wagom_num);
	for(i=0;i<wagom_num;i++) {
		scanf("%d %d %d",&A,&B,&X);
		status[A-1][B-1]=X+1;
	}
	count=0;
	if(status[0][0]>0)count++;
	for(i=1;i<kugi_num;i++) {
		max=status[i-1][0]-1;
		if(status[i][0]>max)max=status[i][0];
		status[i][0]=max;
		if(status[i][0]>0)count++;
		for(j=1;j<=i;j++) {
			max=status[i-1][j-1]-1;
			if(status[i-1][j]-1>max)max=status[i-1][j]-1;
			if(status[i][j]>max)max=status[i][j];
			status[i][j]=max;
			if(status[i][j]>0)count++;
		}
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")  
#include<bits/stdc++.h>
using namespace std;

#define ll 				long long
#define eb 				emplace_back
const long long 		MOD = 1e9 + 7;
#define rep(i,n) 		for (int (i) = 0; (i) < (n); (i)++) 
#define REP(i,k,n)  	for (int (i) = (k); (i) <= (n); (i)++) 
#define REPR(i,k,n) 	for (int (i) = (k); (i) >= (n); (i)--)
#define watch(x) 		cout << (#x) << " = " << (x) << endl
#define t(x)			int x; cin >> x; while(x--)

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
	
	/*---- continue Coding ;----*/

	ll int n, ans = 0;
    cin >> n;
    n--;
    REP(i, 1, n){
        ans += n/i;
    }
    cout << ans << "\n";
	
	/*---- break ;----*/

	cerr<<"Execution time: "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
	return 0;
}

Measured memory_bytes: 3816
import itertools
N = int(input())
nums = {}
for _ in range(N):
  s = input()[0]
  if s in nums.keys():
    nums[s] += 1
  else:
    nums[s] = 1
ans = 0
for C in itertools.combinations(list("MARCH"),3):
  tmp = 1
  for c in C:
    if c in nums.keys():
      tmp *= nums[c]
    else:
      tmp = 0
  ans += tmp
print(ans)



Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		System.out.println(solve());
	}

	static long solve() {
		long K = sc.nextInt();
		long A = sc.nextInt();
		long B = sc.nextInt();
		if (B - A < 2) {
			return 1 + K;
		} else {
			if (K <= A) {
				return 1 + K;
			}
			long exchange = (K - (A - 1)) / 2;
			return 1 + (K - exchange * 2) + exchange * (B - A);
		}
	}

}

Measured memory_bytes: 21844
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int sw[111]; FOR(i,0,111) sw[i] = 0;
  sw[a]++;sw[b]--;sw[c]++;sw[d]--;
  FOR(i,1,111) sw[i] += sw[i-1];
  int ans = 0;
  FOR(i,0,111) if(sw[i] == 2) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384