akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

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

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int k;
  string s;
  cin>>k>>s;
  int n=s.size();
  if(n<=k){
    cout<<s<<'\n';
  }
  else{
    cout<<s.substr(0, k)<<"..."<<'\n';
  }
  return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    int d[n];
    rep(i, n) { cin >> d[i]; }
    ll ans = 0;
    rep(i, n) {
        repd(j, i + 1, n) { ans += d[i] * d[j]; }
    }
    cout << ans << endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


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

using namespace std;

int main() {
	while (true) {
		int t, n, s, f;
		int sum = 0;
		
		cin >> t;
		if (t == 0) break;

		cin >> n;

		for (int i = 0; i < n; i++) {
			cin >> s >> f;
			sum += (f - s);
		}

		if (sum >= t) {
			cout << "OK" << endl;
		} else {
			cout << t - sum << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define inf 1<<30
using namespace std;

int mv[9][4]={{1,8,6,3},
              {2,0,7,4},
              {3,1,8,5},
              {4,2,0,6},
              {5,3,1,7},
              {6,4,2,8},
              {7,5,3,0},
              {8,6,4,1},
              {0,7,5,2}};

int main()
{
  int a,b,c,d;

  while(1){
    cin>>a>>b;
    if(a+b==0)break;
    long long s=0,g=0,n=1e8;
    for(int i=0;i<9;i++){
      cin>>c;
      if(c==0)d=i;
      c++;
      c*=n;
      s+=c;
      n/=10;
    }
    n=1e8;
    for(int i=0;i<9;i++){
      cin>>c;
      c++;
      c*=n;
      g+=c;
      n/=10;
    }

    priority_queue<pair<int,pair<int,int> > > pq;
    map<int,int> m;
    pq.push(mp(0,mp(s,d)));
    m[s]=0;

    while(!pq.empty()){
      pair<int,pair<int,int> > u=pq.top();
      int x=u.f*(-1);
      pq.pop();
      if(m[u.s.f]<x)continue;
      if(u.s.f==g)break;

      for(int k=0;k<4;k++){
        int y=u.s.f,e=u.s.s,f,h,t,z;
	h=(y/(pow(10,8-mv[e][k])));
	t=h%10;
	for(int j=0;j<9;j++){
	  int A=(y/pow(10,j));
	  if(A%10==t){
	    y-=t*pow(10,j);
	    y+=pow(10,j);
	    z=j;
	    break;
	  }
	}
	y-=pow(10,8-e);
	y+=t*pow(10,8-e);
	if(k<2)f=x+a;
	else f=x+b;
        if(m.find(y)!=m.end() && m[y]<=f)continue;
	m[y]=f;
	pq.push(mp(f*(-1),mp(y,8-z)));
      }
    }
    cout<<m[g]<<endl;
  }
  return 0;
}

Measured memory_bytes: 19312
const lines=readlines(open("/dev/fd/0"))
let
    state=0
    global input
    input()=lines[state+=1]
end
int(s::String)=parse(Int32,s)
intSub(s::SubString{String})=parse(Int32,s)
intLine()=map(intSub,split(input()))
function main()
    n=int(input())
    println(sum((x->x>0 ? x : 0).(intLine()-intLine())))
end
main()

Measured memory_bytes: 130832
#include <iostream>
#include <vector>
#include <queue>
#include <list>

using namespace std;
#define ll long long

queue<ll> Q;
int debug=0;

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

    for(ll i=1;i<10;++i){
        Q.push(i);
    }

    /*
    while(!Q.empty()){
        cout << Q.front() << endl;
        Q.pop();
    }
    */

    ll ans;
    ll r;
    for(int i=1;i<K+1;++i){
        ans = Q.front();
        Q.pop();
        if(i==K)break;
        r = ans % 10;

        if(debug) cout << "pick..." << ans << endl;

        if(r != 0){
            Q.push(10*ans+r-1);
            if(debug) cout << "push..." << 10*ans+r-1 << endl;
        } 
        Q.push(10*ans+r);
        if(debug) cout << "push..." << 10*ans+r << endl;

        if(r != 9){
            Q.push(10*ans+r+1);    
            if(debug) cout << "push..." << 10*ans+r+1 << endl;
        }

    }

    cout << ans << endl;

}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
int h1,m1,h2,m2,k;
int main(){
	cin>>h1>>m1>>h2>>m2>>k;
	cout<<h2*60+m2-h1*60-m1-k<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

struct flowGraph{
	struct edge{ int to, cap, rev; };
	
	int n, *level, *iter;
	vector<vector<edge> > G;
	
	flowGraph(int sz) : n(sz){
		G.resize(n);
		iter = new int[n]; level = new int[n];
	}
	~flowGraph(){
		delete iter; delete level;
	}
	
	void add(int s, int t, int cap){
		G[s].pb((edge){t, cap, G[t].size()});
		G[t].pb((edge){s, 0, G[s].size() - 1});
	}
	void bfs(int s){
		rep(i, n) level[i] = -1;
		queue<int> q;
		level[s] = 0;
		q.push(s);
		while(!q.empty()){	
			int v = q.front();
			q.pop();
			rep(i, G[v].size()){
				edge &e = G[v][i];
				if(e.cap > 0 && level[e.to] < 0){
					level[e.to] = level[v] + 1;
					q.push(e.to);
				}
			}
		}
	}
	int dfs(int v, int t, int f){
		if(v == t) return f;
		for(int &i = iter[v]; i < (int)G[v].size(); i++){
			edge &e = G[v][i];
			if(e.cap > 0 && level[v] < level[e.to]){
				int d = dfs(e.to, t, min(f, e.cap));
				if(d > 0){
					e.cap -= d;
					G[e.to][e.rev].cap += d;
					return d;
				}
			}
		}
		return 0;
	}
	int max_flow(int s, int t){
		int flow = 0;
		while(1){
			bfs(s);
			if(level[t] < 0) return flow;
			rep(i, n) iter[i] = 0;
			int f;
			while((f = dfs(s, t, inf)) > 0) flow += f;
		}
	}
};
int h, w, c, m, nw, nc, nm;

int main(){
	while(cin >> h >> w >> c >> m >> nw >> nc >> nm, h >= 0){
		int p = (h + w + c + m) * 2, s = p + 6, t = p + 7;
		int W = 2 * h, C = 2 * (h + w), M = 2 * (h + w + c);
		
		flowGraph g(t + 1);
		rep(i, h) g.add(s, 2 * i, 1), g.add(2 * i, p, 1), g.add(2 * i, 2 * i + 1, 1);
		rep(i, w){
			int k, l;
			cin >> k;
			rep(j, k){
				cin >> l;
				g.add(2 * (l - 1) + 1, W + 2 * i, 1);
			}
			g.add(W + 2 * i, W + 2 * i + 1, 1);
			g.add(W + 2 * i + 1, p + 2, 1);
		}
		rep(i, c){
			int k, l;
			cin >> k;
			rep(j, k){
				cin >> l;
				g.add(2 * (l - 1) + 1 + W, C + 2 * i, 1);
			}
			g.add(C + 2 * i, C + 2 * i + 1, 1);
			g.add(C + 2 * i + 1, p + 4, 1);
			g.add(p + 1, C + 2 * i, 1);
		}
		rep(i, m){
			int k, l;
			cin >> k;
			rep(j, k){
				cin >> l;
				g.add(C + 2 * (l - 1) + 1, M + 2 * i, 1);
			}
			g.add(M + 2 * i, M + 2 * i + 1, 1);
			g.add(p + 3, M + 2 * i, 1);
			g.add(M + 2 * i + 1, t, 1);
		}
		g.add(p, p + 1, nw);
		g.add(p + 2, p + 3, nc);
		g.add(p + 4, t, nm);
		cout << g.max_flow(s, t) << endl;
	}
	return 0;
}

Measured memory_bytes: 1488
/*

                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                    prayer
*/

// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
// #define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

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

	int n;
  cin>>n;
  	vi a(n),b(n),c(n-1);
  cin>>a>>b>>c;
  int t=0;
  rep(i,n)t+=b[i];
  rep(i,n-1)if(a[i]+1==a[i+1])t+=c[a[i]-1];
  cout<<t<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int A,B,K,p;
    scanf("%d%d",&A,&B);
    p=A+B;
    if(p%2==0)
    {
    K=p/2;
    printf("%d",K);
    }
    else
        printf("IMPOSSIBLE");
    return 0;
}


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

int main(void){
    int N, M, Abuf, Asum;
    cin >> N >> M;
    Asum = 0;
    for(int i=0; i<M; i++){
        cin >> Abuf;
        Asum += Abuf;
    }
    cout << (N - Asum < 0 ? -1 : N - Asum) << endl;
    return 0;
}

Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>   
#include <stdio.h>    
 
using namespace std;
     
#define F first
#define S second
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)2e5 + 123;
const ll inf = (ll)3e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
                             
int n, m, dp[2001], ans, s[2001], t[2001], pref[2001];

inline int add (int a, int b) {
   a += b;
   if (a >= mod) a -= mod;
   return a;
}

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   dp[0] = pref[0] = 1;
   cin >> n >> m;
   for (int i = 1; i <= n; i ++) cin >> s[i];
   for (int i = 1; i <= m; i ++) cin >> t[i], pref[i] = 1;
   for (int i = 1; i <= n; i ++) {
      for (int j = 1; j <= m; j ++) {
         if (s[i] == t[j]) {            
            dp[j] = add (dp[j], pref[j - 1]);
         }
      }
      for (int j = 1; j <= m; j ++) pref[j] = add (pref[j - 1], dp[j]);
   }
   cout << pref[m];
}                                     

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
// cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}


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

bool X1[17000], X2[17000];
bool Y1[17000], Y2[17000];
const int offset = 8500;

int main() {
    string s;
    int x, y;
    cin >> s >> x >> y;

    bool *x_prev = X1, *x_nxt = X2;
    bool *y_prev = Y1, *y_nxt = Y2;
    x_prev[offset + 0] = true;
    y_prev[offset + 0] = true;

    vector<int> xdir(1, 0), ydir;
    bool flg = true;
    for (char ch : s) {
        if (ch == 'T') {
            flg = !flg;
            if (flg)
                xdir.push_back(0);
            else
                ydir.push_back(0);
        } else {
            if (flg)
                xdir.back()++;
            else
                ydir.back()++;
        }
    }

    // cout << "xdir: " << endl;
    // for (int dx : xdir) cout << dx << " ";
    // cout << endl;
    // cout << "ydir: " << endl;
    // for (int dy : ydir) cout << dy << " ";
    // cout << endl;

    x_prev[0 + offset] = true;
    y_prev[0 + offset] = true;
    if (xdir.size() >= 1) {
        x_nxt[0 + offset + xdir[0]] = true;
        swap(x_nxt, x_prev);
        for (int i = 0; i < 17000; ++i) x_nxt[i] = false;
    }
    // cout << "initialize done" << endl;

    // for (int i = -10; i < 10; ++i) cout << x_prev[offset + i] << " ";
    // cout << endl;

    for (int i = 1; i < xdir.size(); ++i) {
        int dx = xdir[i];
        for (int j = 0; j < 17000; ++j) {
            x_nxt[j] = (j - dx >= 0 ? x_prev[j - dx] : false) | (j + dx < 17000 ? x_prev[j + dx] : false);
        }
        swap(x_nxt, x_prev);
        for (int i = 0; i < 17000; ++i) x_nxt[i] = false;
        // for (int i = -10; i < 10; ++i) cout << x_prev[offset + i] << " ";
        // cout << endl;
    }
    // cout << "dp for xdir done" << endl;

    // for (int i = -10; i < 10; ++i) cout << y_prev[offset + i] << " ";
    // cout << endl;
    for (int dy : ydir) {
        for (int i = 0; i < 17000; ++i) {
            y_nxt[i] = (i - dy >= 0 ? y_prev[i - dy] : false) | (i + dy < 17000 ? y_prev[i + dy] : false);
        }
        swap(y_nxt, y_prev);
        for (int i = 0; i < 17000; ++i) y_nxt[i] = false;
        // for (int i = -10; i < 10; ++i) cout << y_prev[offset + i] << " ";
        // cout << endl;
    }
    //cout << "dp for ydir done" << endl;

    if (x_prev[x + offset] && y_prev[y + offset]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3672
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

import collections

c = collections.Counter(A)

lis = list()
for i in c.most_common():
    lis.append(i[:][1])

lis.sort()

ans = 0
if len(c.most_common()) > K:
    ans += sum(lis[:(len(c.most_common())- K)])
print(ans)

Measured memory_bytes: 44512
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<map>
#include<queue>
#include<vector>
#include<utility>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int , int> PII;
const int MaxN = 1e5;
int a[MaxN + 5];
int n, k;

int main(){
	while(~scanf("%d %d", &n, &k)){
		for(int i = 1;  i<= n; i++) scanf("%d", &a[i]);
		sort(a + 1, a + 1 + n);
		int ABS = 1 << 30;
		for(int i = 1;  i < n; i++){
			if(a[i + 1] - a[i] != 0) ABS = min(ABS, a[i + 1] - a[i]);
		}
		bool flag = false;
		for(int i = 1; i <= n; i++)
			if(abs(a[i] - k) % ABS == 0) flag = true;
		if(k > a[n]) flag = false;
		if(flag) printf("POSSIBLE\n");
		else printf("IMPOSSIBLE\n");
	}
	return 0;
}

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

int main(){
  int d,g;
  cin >> d >> g;
  int p[d];
  int c[d];
  for(int i=0;i<d;++i){
    cin >> p[i] >> c[i];
  }
  
  int ans=1000;
  int toita=0;
  int score=0;
  
  for(int i=0;i<(1<<d);++i){
    bitset<10> b=i;
    for(int j=0;j<d;++j){
      if(b[j]){
        score+=(100*(j+1)*p[j]);
        toita+=p[j];
        score+=c[j];
      }
    }
    if(score>=g){
      if(toita<ans){
        ans=toita;
      }
    }else{
      int gap=g-score;
      for(int k=d-1;k>=0;--k){
        if(!b[k]){
          if(gap<=100*(k+1)*(p[k]-1)){
            int l=(gap+(100*(k+1))-1)/(100*(k+1));
            if((toita+l)<ans){
              ans=toita+l;
            }
          }
        }
      }
    }
    toita=0;
    score=0;
  }
  
  cout << ans;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

const LL inf = 112345;
LL N, Ma, Mb;
std::vector<LL>a, b, c;
std::vector<std::vector<std::vector<LL>>>memo;

LL dp(LL i, LL j, LL k)
{
	if (j != 0 && k != 0 && j*Mb == k * Ma) return 0;
	if (i == N) return inf;
	if (memo[i][j][k] != -1) return memo[i][j][k];
	LL res1 = dp(i + 1, j + a[i], k + b[i]) + c[i];
	LL res2 = dp(i + 1, j, k);
	return memo[i][j][k] = std::min(res1, res2);
}

int main()
{
	in >> N >> Ma >> Mb;
	a.resize(N); b.resize(N); c.resize(N);
	rep(i, N) in >> a[i] >> b[i] >> c[i];

	memo.resize(N);
	rep(i, memo.size())
	{
		memo[i].resize(412);
		rep(j, memo[i].size()) memo[i][j].resize(412, -1);
	}
	out << (dp(0, 0, 0) >= inf ? -1 : dp(0, 0, 0)) << std::endl;
	return 0;
}


Measured memory_bytes: 53888
#include<stdio.h>
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include <random>
#include <chrono>

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

using namespace std;
int main() {
	string s;
	int ans = 0;
	cin >> s;
	if (s == "SUN") {
		ans = 7;
	}
	else if (s.at(0) == 'M') { ans = 6; }
	else if (s == "TUE") { ans = 5; }
	else if (s.at(0) == 'W') { ans = 4; }
	else if (s.at(0) == 'T') { ans = 3; }
	else if (s.at(0) == 'F') { ans = 2; }
	else if (s.at(0) == 'S') { ans = 1; }
	cout << ans;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

struct edge {
    int from, to; ll cost;
    edge(int s, int t, ll w = 0) : from(s), to(t), cost(w) {}
};

int main() {
    init();

    int n; cin >> n;
    string s; cin >> s;

    string a = "SSWWSWWS";
    FOR(k, 0, 4) {
        vector<char> ans(n, ' ');
        ans[0] = a[2 * k];
        ans[1] = a[2 * k + 1];
        map<char, char> mir = { {'S','W'},{'W','S'} };
        FOR(i, 1, n - 1) {
            if (s[i] == 'o') {
                if (ans[i] == 'S')ans[i + 1] = ans[i - 1];
                else ans[i + 1] = mir[ans[i - 1]];
            }
            else {
                if (ans[i] == 'S')ans[i + 1] = mir[ans[i - 1]];
                else ans[i + 1] = ans[i - 1];
            }
        }

        bool ng = false;
        FOR(i, 0, n) {
            if (ans[i] == 'S') {
                if (s[i] == 'o')ng |= (ans[(i - 1 + n) % n] != ans[(i + 1) % n]);
                if (s[i] == 'x')ng |= (ans[(i - 1 + n) % n] == ans[(i + 1) % n]);
            }
            else {
                if (s[i] == 'o')ng |= (ans[(i - 1 + n) % n] == ans[(i + 1) % n]);
                if (s[i] == 'x')ng |= (ans[(i - 1 + n) % n] != ans[(i + 1) % n]);
            }
        }
        if (ng)continue;

        FOR(i, 0, n)cout << ans[i];
        cout << "\n";
        return 0;
    }
    cout << "-1\n";
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int l;
    string s;
    set<char>st;
    cin>>s;
    l= s.size();
    for(int i=0;i<l;i++)
        st.insert(s[i]);
    if(l==st.size())
        cout<<"yes"<<endl;
    else
        cout<<"no"<<endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using static System.Math;
using System.Linq;
 
class DandA {
    static void Main(string[] args) {
        string[] st = ReadLineStrArray();
        Console.WriteLine(st[1] + st[0]);
    }
  
    static private string ReadLineStr() {return Console.ReadLine();}
    static private int ReadLineInt() {return int.Parse(Console.ReadLine());}
    static private string[] ReadLineStrArray() {return Console.ReadLine().Trim().Split();}
    static private int[] ReadLineIntArray() {return Console.ReadLine().Trim().Split().Select(a => int.Parse(a)).ToArray();}
    static private string[][] ReadMLineStrArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split()).ToArray();}
    static private int[][] ReadMLineIntArray(int arg) { return new int[arg].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();}
}

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, x;
    cin >> n >> x;

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

    int total = 0, i = 0;
    
    while (total <= x) {
        total += arr[i];
        i++;
    }

    cout << i << '\n';
}


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

int cnt[100010],a[100010];
int main() {
    int n;
    cin >> n;
    rep(i, 0, n) {
        cin >> a[i];
    }
    int ans = 0;
    rep(i, 0, n) {
        if (a[i] > n) {
            ans++;
        } else {
            cnt[a[i]]++;
        }
    }
    rep(i, 1, n + 1) {
        if (cnt[i] < i) {
            ans += cnt[i];
        } else {
            ans += cnt[i] - i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;
long long solve(vector <int> a,int b){
    long long ans = 0;
    for(int i=0;i<a.size();i++){
        ans += abs(a[i]-b);
    }
    return ans;
}

int main(){
    int n;
    cin >> n;
    vector <int> in(n);
    for(int i=0;i<n;i++){
        cin >> in[i];
        in[i] -=i+1;
    }
    sort(in.begin(),in.end());
    int b = in[n/2];
    long long ans=solve(in,b);
    cout << ans <<endl;
    return 0;
}

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

int main()
{
    string st[200];
    int n,l;
    cin>>n>>l;
    //getchar();
    for(int k=0;k<n;k++)
        cin>>st[k];
    sort(st,st+n);
    for(int k=0;k<n;k++)
        cout<<st[k];
    cout<<endl;
}


Measured memory_bytes: 3640
#include <algorithm>

namespace rika
{
  template <typename T>
  class edge
  {
  public:
    int to;
    T cost;
    
    edge() = default;
    edge(const edge<T>&) = default;
    edge(edge<T>&&) = default;
    edge& operator =(const edge<T>&) = default;
    edge& operator =(edge<T>&&) = default;

    ~edge() = default;

    edge(int _to, T _cost) : to(_to), cost(_cost) {}
  };
}

#include<bits/stdc++.h>
using namespace std;
using namespace rika;
namespace rika
{
  namespace internal
  {
    template <typename TValue, typename TGraph>
    std::pair<TValue, int> visit(int from, int v, const TGraph &g)
    {
      auto r = std::make_pair(TValue(), v);
      try
      {
        for(auto it = g[v].begin(); it != g[v].end(); ++it)
        {
          if(it->to == from)
            continue;
          auto r2 = visit<TValue>(v, it->to, g);
          if(r2.first + it->cost >= r.first)
            r = std::make_pair(r2.first + it->cost, r2.second);
        }
      }
      catch (const std::out_of_range& e)
      {
        exit(0);
      }
      return r;
    }
  }

  template <typename TValue, typename TGraph>
  TValue tree_diameter(const TGraph &g)
  {
    using namespace internal;
    auto r1 = visit<TValue>(-1, 0, g);
    auto r2 = visit<TValue>(-1, r1.second, g);
    return r2.first;
  }
}

int main()
{
  int N;
  cin >> N;
  vector<vector<edge<int>>> g(N * 10);
  for(int i = 0; i < N - 1; i++)
  {
    int s, t, w;
    cin >> s >> t >> w;
    g[s].push_back(edge<int>(t, w));
    g[t].push_back(edge<int>(s, w));
  }
  cout << tree_diameter<int>(g) << endl;
}

Measured memory_bytes: 35360
/*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define int long long
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define reads(s) string s; cin >> s;
#define readarr(a, n) int a[(n) + 1] = {}; fori (i, 1, n) {cin >> a[i];}
#define readmat(a, n, m) int a[(n) + 1][(m) + 1] = {}; fori (i, 1, n) {fori (j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) fori (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) fori (i, 1, n) {fori (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(s) (int)(s.size())
#define pb push_back
#define fi first
#define se second
#define rz resize
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
#define setprec(x) cout << fixed << setprecision(x);
 
using namespace std;
using namespace __gnu_pbds; 
 
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair <int, int>> vpi;
typedef vector < vector <int> > vvi;
 
const int INF = 4e18;
const int mod = 1e9+7; 

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

    #ifndef ONLINE_JUDGE 
        freopen ("INPUT.txt" , "r" , stdin);
        freopen ("OUTPUT.txt" , "w" , stdout);
        freopen ("OUTPUT_ERROR.txt" , "w" , stderr);
    #endif

    //start from here

    readb(n, W)
    int v[n+1], w[n+1];

    fori (i, 1, n) cin >> w[i] >> v[i];

    int dp[W + 1] = {};

    fori (i, 1, n)
    {
        ford(j, W, 0)
            if(j - w[i] >= 0) dp[j] = max(dp[j], v[i] + dp[j - w[i]]);
    }

    print(dp[W])

    return 0;
}


Measured memory_bytes: 4456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
ll N, Q;
vector<vector<ll>> G;
vector<bool> grid;
vector<ll> ans, coins;
int dfs(ll x, ll cnt){
    cnt+=coins[x];
    ans[x] = cnt;
    for(auto v : G[x]){
        if(!grid[v]) {
            grid[v] = true;
            dfs(v, cnt);
        }
    }
    return 0;
}
 
 
int main(){
    cin >> N >> Q;
    G.resize(N);
    grid.resize(N);
    ans.resize(N);
    coins.resize(N);
    for(int i = 0; i < N-1; i++){
        ll a, b; cin >> a >> b; a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i = 0; i < Q; i++){
        ll p, x; cin >> p >> x;
        coins[p-1] += x;
    }
    grid[0] = true;
    dfs(0, 0);
    for(int i = 0; i < N; i++) cout << ans[i] << " ";
    cout << endl;
}

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

#define INF (1 << 30)
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define out(x) cout << x << endl;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if(a <= 9 && b <= 9){
        out(a*b);
    }else{
        out(-1);
    }
    return 0;
}

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

int main() {
    int N; cin >> N;
    vector<int> A(N);
    bitset<2000001> b;
    b.set(0);
    int s=0;
    REP(i,N) {
        int a;
        cin >> a;
        s += a;
        b |= (b<<a);
    }
    int ans = 0;
    REP(i,s/2+1) {
        if(b[i]) ans = s - i;
    }
    cout << ans << endl;
}

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

int main(){
  long long L, R;
  cin >> L >> R;
  int ans = 2020;
  bool tf = true;
  for (long long i=L;i<R;i++){
    for (long long j=i+1;j<=R;j++){
      if ((i*j)%2019==0){
        ans = 0;
        tf = false;
        break;
      }
      else{
        if ((i*j)%2019<ans){
          ans = (i*j)%2019;
        }
      }
    }
    if (tf == false){
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;
static const ll LOGN=55;



int main(void) {
  ll N;
  cin >> N;
  deque<ll> b;
  ll i;
  
  ll r=0;
  for(i=0; i<N; i++) {
    ll a;
    cin >> a;
    
    if(r) b.push_front(a);
    else  b.push_back(a);
    r=1-r;
  }
  
  if(N&1) reverse(b.begin(), b.end());
  
  for(i=0; i<N; i++) pt(b[i]);
  
}






Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,cnt=0,i;
	cin>>n;
	string s;
	cin>>s;
	int ans=0,j;
	for(i=1;i<n;i++)
	{
		cnt=0;
		for(char c='a';c<='z';c++)
		{
			bool sl=false,sr=false;
			for(j=i;j<n;j++)
			  if(s[j]==c)
			    sr=true;
			for(j=0;j<i;j++)
			  if(s[j]==c)
			    sl=true;
			if(sl&&sr) cnt++;
		}
		if(ans<cnt) ans=cnt;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int A, B;
    cin >> A >> B;
    cout << A * B << endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main()
{
  int x, y, a, b;
  cin >> x >> y;
  b = (y - 2 * x);
  if (b % 2 == 1)
  {
    cout << "No";
    return 0;
  }
  b /= 2;
  a = x - b;
  if (a >= 0 && b >= 0)
    cout << "Yes";
  else
    cout << "No";
}


Measured memory_bytes: 3636
module IntTripleSet = Set.Make (struct
  type t = int * int * int
  let compare = compare
end)

let rec solve acc history a b c =
  if IntTripleSet.mem (a, b, c) history then -1
  else if a mod 2 = 1 || b mod 2 = 1 || c mod 2 = 1 then acc
  else
    solve
      (1 + acc)
      (IntTripleSet.add (a, b, c) history)
      (b / 2 + c / 2)
      (a / 2 + c / 2)
      (a / 2 + b / 2)
let solve = solve 0 IntTripleSet.empty

let () =
  let a, b, c = Scanf.scanf "%d %d %d" (fun a b c -> a, b, c) in
  Printf.printf "%d\n" @@ solve a b c

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,sx,sy,ex,ey;
    cin>>n>>m>>sx>>sy>>ex>>ey;
    sx--;sy--;ex--;ey--;
    deque<int> dx,dy;
    dx.push_front(sx);
    dy.push_front(sy);
    char ** a = new char * [n];
    int ** dist = new int * [n];
    for(int i=0;i<n;i++){
        a[i] = new char [m];
        dist[i] = new int [m];
        for(int j=0;j<m;j++){
            cin>>a[i][j];
            dist[i][j] = 10e8;
        }
    }
    int pos[][2] =  {{-1,0},{1,0},{0,-1},{0,1}};
    dist[sx][sy] = 0;
    while(!dx.empty()){
        int curx = dx.front();
        int cury = dy.front();
        
        dx.pop_front();dy.pop_front();
        int nx,ny;
        for(int i=0;i<4;i++){
            nx = curx + pos[i][0];
            ny = cury + pos[i][1];
            if(nx <0 || ny <0 || nx>=n || ny>=m || a[nx][ny] == '#'){
                continue;
            }
            if(dist[nx][ny] > dist[curx][cury]){
                dist[nx][ny] = dist[curx][cury];
                dx.push_front(nx);
                dy.push_front(ny);
            }
        }
        for(int i=curx-2;i<=curx+2;i++){
            for(int j= cury-2;j<=cury+2;j++){
                if(i <0 || j <0 || i>=n || j>=m || a[i][j] == '#'){
                    continue;
                }
                if(dist[i][j] > dist[curx][cury] + 1){
                    dist[i][j] = dist[curx][cury]+1;
                    dx.push_back(i);
                    dy.push_back(j);
                }
            }
        }
    }
    (dist[ex][ey] >= 10e6)? cout<<"-1" : cout<<dist[ex][ey]; 
    return 0;
}

Measured memory_bytes: 8632
open Scanf
let id x = x
let read_int _ = scanf " %d" id
let () =
  let n = scanf " %d" id in
  let a = Array.init n read_int in
  let b = Array.init n read_int in
  let c = Array.init n read_int in
  Array.sort (-) a; Array.sort (-) b; Array.sort (-) c;
  let f u v =
    let res = Array.make n 0 in
    let rec g a i =
      if i >= n then ()
      else if a = n then (
        res.(i) <- n; g n (i+1)
      ) else if v.(i) <= u.(a) then (
        res.(i) <- a; g a (i+1)
      ) else g (a+1) i in
    g 0 0; res in
  let ab = f a b in
  let bc = f b c in
  Array.iteri (fun i e -> if i > 0 then ab.(i) <- e + ab.(i-1)) ab;
  Array.map (fun e -> if e = 0 then 0 else ab.(e-1)) bc
  |> Array.fold_left (+) 0 |> Printf.printf "%d\n"




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

using namespace std;

typedef long long LL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<LL> vl;
typedef vector<vector<LL>> vvl;
typedef vector<vector<vector<LL>>> vvvl;


const int inf = 1e9+7;
const LL INF = 1e18+5;
const int mod = 1e9+7;
const int mxN = 1e5+5;
const int mxM = 1e5+5;

int main(){
    #ifndef ONLINE_JUDGE
    freopen("E:\\Coding\\Programming\\input.txt", "r", stdin);
    freopen("E:\\Coding\\Programming\\output.txt", "w", stdout);
    #endif
    int n;
    cin>>n;
    vi a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    LL ans = 0;
    for(int i=1;i<n;i++){
        if(a[i]<a[i-1]){
            ans += a[i-1]-a[i];
            a[i]+=a[i-1]-a[i];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4040
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String a = scan.next();
		if (Character.isUpperCase(a.charAt(0))) {
			System.out.println("A");
		} else {
			System.out.println("a");
		}

		scan.close();

	}

}


Measured memory_bytes: 35660
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
ll bg = 20000001;
#define ff(i,n) for(i=0;i<n;i++) 
ll countone(ll n)
{
	ll d = 0;
	while(n!=0)
    {
    	d+=n%2;
    	n = n / 2;
	}
	return d;
}
ll fun(ll n)
{
	ll s = 0;
	while(n!=0)
	{
		s++;
		n = n%countone(n);
	}
	return s;
}
int main()
{
	ll test,t;
	t=1;
	for(test=1;test<=t;test++)
	{
		ll n,i;
		cin>>n;
		string s;
		cin>>s;
		ll x = 0;
		ff(i,n)
		  x += (s[i]-'0');
		ll dp1[n],dp2[n];
		dp1[0] = 1;
		for(i=1;i<n;i++)
			dp1[i] = (dp1[i-1]*2)%(x+1);
		dp2[0] = 1;	
		if(x>1)	 			
		 for(i=1;i<n;i++)
			dp2[i] = (dp2[i-1]*2)%(x-1);
		ll a=0,b=0;
		ff(i,n)
			if(s[i]=='1')
				a = (a + dp1[n-1-i])%(x+1);
		if(x>1)
			ff(i,n)
				if(s[i]=='1')
					b = (b + dp2[n-1-i])%(x-1);
		ll ans[n];					
        ff(i,n)	
	    {
	    	if(s[i]=='1')
	    	{
	    		if(x==1)
	    		   ans[i] = 0;
	    		else
				   ans[i] = 1 + fun(((b-dp2[n-1-i])%(x-1)+(x-1))%(x-1));   
			}
			else
			{
				if(x==0)
				    ans[i] = 1;
				 else
				    ans[i] = 1 + fun(((a+dp1[n-1-i])%(x+1)));
			}
		}
		ff(i,n)
		    cout<<ans[i]<<endl;
	}
	return 0;
} 

Measured memory_bytes: 8440
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;}
using ll = long long;
using P = pair<int,int>;

ll n,m,sum;
string s,t;

int main() {
  cin >> n;
  rep(i,n)if((i+1)%3!=0 && (i+1)%5!=0) sum+=i+1;
  cout << sum << endl;
}

Measured memory_bytes: 3632
n = int(input())
line = ""
for i in range(n):
    x= i+1
    if x % 3 == 0:
        line += " " + str(i+1)
    else:
        while x > 1:
            if x % 10 == 3:
                line += " " + str(i+1)
                break
            else:
                x = x // 10
print(line)


Measured memory_bytes: 5624
N = input()
d = list(map(int, input().split()))
d.sort()
n = int(len(d) / 2)
d_1 = d[:n]
d_2 = d[n:]
#print(d_1, d_2)
if d_1[n - 1] == d_2[0]:
    print(0)
else:
    print(d_2[0] - d_1[n - 1])

Measured memory_bytes: 14396
#include<cstdio>
using namespace std;
int n,m,cnt,a[100005],fa[100005];
bool b[100005];
int find(int x)
{
	if(fa[x]!=x)fa[x]=find(fa[x]);
	return fa[x];
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=0,a,b;i<m;i++)
	{
		scanf("%d%d",&a,&b);
		a=find(a);b=find(b);
		fa[a]=b;
	}
	for(int i=1;i<=n;i++)
	  if(fa[fa[i]]!=fa[i])
		find(i);
	for(int i=1;i<=n;i++)
	{
		if(find(i)==find(a[i]))cnt++;
	}
	printf("%d",cnt);
}

Measured memory_bytes: 896
macro_rules! scan {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };

    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
}

fn main() {
    let (n, t) = scan!(usize, usize);
    let mut vs = scan!(usize;;);
    vs.push(1 << 60);

    let mut total = 0;
    for (&v0, &v1) in vs.iter().zip(vs[1..].iter()) {
        if v1 < v0 + t {
            total += v1 - v0;
        } else {
            total += t
        }
    }

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


Measured memory_bytes: 10492
#include<bits/stdc++.h>
using namespace std;
int main(){
    char a,b;
    cin>>a>>b;
    if(a=='H' && b=='H'){
        cout<<"H"<<endl;
    }
     if(a=='H' && b=='D'){
        cout<<"D"<<endl;
    }
     if(a=='D' && b=='H'){
        cout<<"D"<<endl;
    }
     if(a=='D' && b=='D'){
        cout<<"H"<<endl;
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int stack = 0;
  bool underflow = false;
  REP(i, N) {
    string S;
    cin >> S;
    if (S == "A") {
      stack++;
    } else if (S == "Un") {
      if (stack <= 0) { underflow = true;}
      else { stack--; }
    }
  }
  cout << (((!underflow) && (stack == 0)) ? "YES" : "NO")  << endl;
  return 0;
}

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

int main()
{
  int n, a[5000], ca;
  long long ans, sum;
  while(cin >> n, n){
    for (int i = 0; i < n; i++){
      cin >> a[i];
    }

    ans = -1e5;
    for (int i = 0; i < n; i++){
      sum = 0;
      for (int j = i; j < n; j++){
        sum += a[j];
        ans = max(sum, ans);
      }
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1172
N = int(input())
T,A = map(int, input().split())
H = [int(i) for i in input().split()]

min = (A-(T-0.006*H[0]))**2
ans = 0

for i in range(1,N):
    if min > (A-(T-0.006*H[i]))**2:
        min = (A-(T-0.006*H[i]))**2
        ans = i

print(ans+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    int n; cin >> n;
    priority_queue<ll> que;
    rep(i,n) {
        ll a; cin >> a;
        que.push(a);
    }
    ll ans = que.top(); que.pop();
    ll rec;
    rep(i,n-2) {
        ans += que.top()*2; 
        rec = que.top();
        que.pop();
        i++;
    }
    if (n%2!=0) ans -= rec;
    cout << ans << endl;
}

Measured memory_bytes: 5332
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

vector<string> ans;

void dfs(int n){
    string a = "a";
    queue<string> que;
    que.push("a");
    if(n == 1){
        ans.push_back(a);
        return;
    }
    while(!que.empty()){
        string tmp = que.front(); que.pop();
        int can = 0;
        for(int i = 0; i < tmp.size(); i++){
            if(can < tmp[i]) can = tmp[i];
        }
        for(int i = 'a'; i <= can+1; i++){
            tmp.push_back(i);
            if(tmp.size() == n) ans.push_back(tmp);
            else que.push(tmp);
            tmp.pop_back();
        }
    }
}

int main(){
    int n;
    cin >> n;
    dfs(n);
    for(auto p:ans){
        cout << p << endl;
    }
    return 0;
}

Measured memory_bytes: 9588
import numpy as np
import scipy as sp
import scipy.sparse.csgraph as sg

H, W = [int(a) for a in input().split()]
ss = []
for _ in range(H):
    ss.append(input())

g = np.zeros((H*W,H*W))

v_edges = [((i,j), (i,j+1)) for i in range(H) for j in range(W-1) if ss[i][j] == "." and ss[i][j+1] == "."]
h_edges = [((i,j), (i+1,j)) for i in range(H-1) for j in range(W) if ss[i][j] == "." and ss[i+1][j] == "."]

for (si,sj), (di,dj) in v_edges + h_edges:
    g[si*W+sj][di*W+dj] = 1
    g[di*W+dj][si*W+sj] = 1

r = sg.dijkstra(g, indices=[0,H*W-1])
score = r[0,H*W-1]

if sp.isinf(score):
    print(-1)
    exit(0)
else:
    #print(r)
    #print(ss) 

    ss_ = "".join(ss)
    num = len([0 for c in ss_ if c == '.'])
    #print(num)
    #print(score)
    print("%d" % (num - (score+1)))




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

int main(){
  int n, k;
  cin >> n >> k;
  std::vector<int> h(n);
  rep(i, n){
    std::cin >> h.at(i);
  }
  int ans = 0;
  rep(i, n){
    if(h.at(i) >= k){
      ans++;
    }
  }
  std::cout << ans << '\n';
  
  return 0;
}

Measured memory_bytes: 640
import itertools
import math
N = int(input())
XY = [list(map(int, input().split())) for i in range(N)]
n = [i for i in range(N)]

dist = 0
cnt = 0
for target_list in list(itertools.permutations(n)):
    for i in range(len(target_list)):
        if i == 0:
            continue
        dist += math.sqrt((XY[target_list[i]][0] - XY[target_list[i-1]][0]) ** 2 + (XY[target_list[i]][1] - XY[target_list[i-1]][1]) ** 2)
    cnt += 1
print(dist / cnt)

Measured memory_bytes: 13724