akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stack>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;


int main(){
    char ch;
    stack<int> S1;
    stack<pair<int, int> > S2;

    int sum;
    for (int i = 0; cin >> ch; i++){
        if (ch == '\\') S1.push(i);
        else if (ch == '/' && S1.size() > 0){
            int j = S1.top(); S1.pop();
            int a = i - j;
            sum += i - j;
            while (S2.size() > 0 && S2.top().first > j){
                a += S2.top().second; S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }

    vector<int> ans;
    while (S2.size() > 0) {
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(), ans.end());

    cout << sum << endl;
    cout << ans.size();
    for (int i = 0; i < ans.size(); i++){
        cout << " " << ans[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n,i,j,t;
  long d,ans=0;
  string s;
  cin >> s;
  n=s.size()-1;
  for (i=0;i<(1<<n);i++){
    t=i*2+1;
    for (j=n;j>=0;j--){
      if (t%2){
        d=1;
        ans+=s[j]-'0';
      }else{
        d*=10;
        ans+=(s[j]-'0')*d;
      }
      t/=2;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    int N;
    cin>>N;
    vector<int> A(N),B(N),D;
    long long lose=0,win=0;
    int c=0;
    for(int i=0;i<N;i++)cin>>A[i];
    for(int i=0;i<N;i++){
        cin>>B[i];
        int d=A[i]-B[i];
        if(d<0){
            lose+=d;
            c+=1;
        }else if(d>0){
            win+=d;
            D.push_back(d);
        }
    }
    if(-lose>win){
        cout<<-1<<endl;
        return 0;
    }
    if(lose==0){
        cout<<0<<endl;
        return 0;
    }
    sort(D.begin(),D.end());
    for(int i=D.size()-1;i>=0;i--){
        lose+=D[i];
        c+=1;
        if(lose>=0){
            cout<<c<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

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

ll calc(ll a, ll c, ll d) {
  return a - (a / c) - (a / d) + (a / lcm(c, d));
}

int main() {
  ll a, b, c, d;
  while (cin >> a >> b >> c >> d) {
    cout << calc(b, c, d) - calc(a - 1, c, d) << endl;
  }
}


Measured memory_bytes: 888
N ,M = map(int,input().split())
array = []
if N % 2 == 1:
    for i in range(1,(N-1)//2 + 1):
        array.append([i,N-i])
    for i in range(M):
        print(*array[i])
else:
    for i in range(1,N//2):
        if i <= N//4:
            array.append([i,N+1-i])
        else:
            array.append([i,N-i])
    for i in range(M):
        print(*array[i])

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

using namespace std;

int main()
{
  int N;
  cin >> N;
  int C[101][101];

  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      cin >> C[i][j];
    }
  }
  long long ans = 0;
  for(int i = 0; i < N; i++){
    for(int j = i+1; j < N; j++){
      ans += min(C[i][j], C[j][i]);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1196
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

ll L, A, B, M;
vector<ll> carry_over(20, 1LL<<60);

vector< vector<ll> > product(vector< vector<ll> > A, vector< vector<ll> > B){
	int height = A.size(), width = B[0].size(), n = B.size();
	
	vector< vector<ll> > C(height, vector<ll>(width, 0));
	
	for(int i=0;i<height;++i){
		for(int j=0;j<width;++j){
			for(int k=0;k<n;++k){
				C[i][j] += (A[i][k] * B[k][j]) % M;
                C[i][j] %= M;
			}
		}
	}
	
	return C;
}

vector< vector<ll> > matrix_pow(vector< vector<ll> > A, ll t) {
    int n = A.size();
    vector< vector<ll> > B(n, vector<ll>(n, 0));
    for(int i=0;i<n;++i) B[i][i] = 1;
    while(t){
        if(t & 1){
            B = product(B, A);
        }
        A = product(A, A);
        t >>= 1;
    }
    return B;
}

ll modpow(ll a, ll t) {
    ll ret = 1LL;
    while(t){
        if(t & 1LL){
            ret *= a;
            ret %= M;
        }
        a *= a;
        a %= M;
        t >>= 1;
    }
    return ret;
}

int main() {
    cin >> L >> A >> B >> M;
    carry_over[0] = 0;
    ll con_9 = 9LL;
    for(int i=1;i<19;++i) {
        if(A + B * L <= con_9) {
            carry_over[i] = L;
            break;
        }
        ll ng = -1, ok = L;
        while(ok-ng > 1) {
            ll mid = (ng+ok)/2;
            if(A+B*mid <= con_9) {
                ng = mid;
            } else {
                ok = mid;
            }
        }
        carry_over[i] = ok;

        con_9 = (con_9+1) * 10 - 1;
    }

    ll ans = 0LL;
    ll pow10 = 10LL;
    A %= M;
    B %= M;
    for(int d=0;d<19&&carry_over[d]<L;) {
        int dd = d;
        while(carry_over[dd] == carry_over[d]) {
            ++d;
        }
        --d;
        for(int i=0;i<d-dd;++i) {
            pow10 *= 10LL;
            pow10 %= M;
        }

        vector<vector<ll>> matrixA(3, vector<ll>(3, 0)), matrixB(3, vector<ll>(1, 0LL));
        matrixA[0][0] = pow10;
        matrixA[0][1] = 1LL;
        matrixA[1][1] = 1LL;
        matrixA[1][2] = B;
        matrixA[2][2] = 1LL;
        matrixB[0][0] = 0;
        matrixB[1][0] = (A + B * carry_over[d]) % M;
        matrixB[2][0] = 1LL;

        vector<vector<ll>> matrixC = product(matrix_pow(matrixA, carry_over[d+1]-carry_over[d]), matrixB);
        ans *= modpow(pow10, carry_over[d+1]-carry_over[d]);
        ans %= M;
        ans += matrixC[0][0];
        ans %= M;

        dd = ++d;
        while(carry_over[dd] == carry_over[d]) {
            ++d;
        }
        --d;
        for(int i=0;i<d-dd+1;++i) {
            pow10 *= 10LL;
            pow10 %= M;
        }
    }

    cout << ans << endl;
}


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

int main(){
	/*input*/
	int n, x;	cin >> n >> x;
	vector<int>m(n);
	for(int i = 0; i < n; i++){
		cin >> m[i];
	}
	/*calculation*/
	int ans = 0;
	for(int i = 0; i < n; i++){
		x -= m[i];
		ans++;
	}
	sort(m.begin(), m.end());
	int min = m[0];
	ans += x/min;
	/*output*/
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int N, t[55], ans;
string s[55], X;

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> s[i] >> t[i];
  }
  cin >> X;
  for (int i = N - 1; i >= 0; i--) {
    if (s[i] == X) break;
    ans += t[i];
  }
  cout << ans << endl;
}

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

int main(){
    int k;
    cin >> k;
    long long int amarisum = 0;
    long long int amari = 7;
    long long int ans = 0;
    do{
        ans++;
        if(ans > 50000000){
            ans = -1;
            break;
        }
        amarisum += amari;
        amarisum %= k;
        amari *= 10;
        amari = amari % k;
    }while(amarisum % k != 0);
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n; cin>>n;
  vector<int> a(n);
  vector<int> b(n);
  for (int i=0; i<n+1; i++) cin>>a[i];
  for (int j=0; j<n; j++) cin>>b[j];
  
  long long ans=0;
  for (int k=0; k<n; k++){
    if (a[k]<b[k]){
      ans+=a[k];
      if (a[k+1]>=b[k]-a[k]){
        ans+=b[k]-a[k];
        a[k+1]-=b[k]-a[k];
      }
      else{
        ans+=a[k+1];
        a[k+1]=0;
      }
    }
    else{
      ans+=b[k];
    }
  }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>

using namespace std;

int main() {

    int64_t H;
    cin >> H;

    int count = 0;
    while(H) {
        H /= 2;
        count++;
    }

    int64_t ans = 0, num = 1;
    for(int i = 1; i <= count; i++) {
        ans += num;
        num *= 2;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
typedef long long int ll;

int main()
{
	ll a, b, c,ans=0;
	string s;
	cin >> a;
	for (ll i = 1; i <= sqrt(a); i++)
	{
		if (a%i == 0)ans = i + a/i - 2;
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void){
    int i,j; 
    char n[3]={0};
    int ans = 0;
   
    scanf("%d %d",&i,&j);
    if((i+j)%2 == 0){
        printf("%d\n",(i+j)/2);
    }else{
        printf("%.d\n",((i+j)/2+1));
    }
    
    

    
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
using namespace std;
int main()
{
	int n,x;
	cin>>n>>x;
	if(x==1||x==2*n-1)
	{
		cout<<"No"<<endl;
		return 0;
	}
	cout<<"Yes"<<endl;
	int now=1;
	for(int i=0;i<n-2;i++)
	{
		if(now==x-1)now=x+2;
		cout<<now<<endl;
		now++;
	}
	cout<<x-1<<endl<<x<<endl<<x+1<<endl;
	for(int i=0;i<n-2;i++)
	{
		if(now==x-1)now=x+2;
		cout<<now<<endl;
		now++;
	}
	return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<stack>

using namespace std;

int check(char c){
  if(c == '[' || c == '(') return 2;
  if(c == ']' || c == ')') return 1;
  return 0;
}

int isOK(char c, char in){
  if(in == ']' && c == '[') return 1;
  if(in == ')' && c == '(') return 1;
  // cout << " " << c << " " << in << endl;
  return 0;
}

int main(){

  string in;
  while(getline(cin,in)){
    if(in == ".") break;
    stack<char> S;
    int status = 1;
    for(int i = 0; i < in.size(); i++){
      int j = check(in[i]);
      if(j == 2){
	S.push(in[i]);
	//	cout << " " << in[i] << endl;
      }
      if(j == 1) {
	if(S.size() == 0){
	  status = 0;
	  break;
	}
	if(!isOK(S.top(),in[i])){
	  status = 0;
	  break;
	}
	S.pop();
      }
    }
    if(status && S.size() == 0) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

const int    INF = 1000000000;
const ll     MOD = 1000000007LL;
const double EPS = 1E-12;

inline int nextCombination(int comb)
{
  int x = comb & -comb, y = comb + x;
  return (((comb & ~y) / x) >> 1) | y;
}

const int MAX_N = 10;
const int MAX_S = 100000;
const int N = MAX_N;
int n, s;
int dp[MAX_N+1][MAX_S+1];

template<typename T> ostream& operator <<(ostream& r, const vector<T> t){vrep(v,t)r<<*v<<(v+1==t.end()?"":" ");return r;}
template<typename T> ostream& operator <<(ostream& r, const pair<vector<T>, int> p){int n=p.second;minup(n,p.first.size());rep(i,n-1)r<<p.first[i]<<' ';r<<p.first[n-1];return r;}
template<typename T> ostream& operator <<(ostream& r, const pair<T*, int> p){int n=p.second-1;rep(i,n)r<<p.first[i]<<' ';return r<<p.first[n];}
template<typename T, size_t S> ostream& operator <<(ostream& r, const T (&a)[S]){rep(i,S-1)r<<a[i]<<' ';return r<<a[S-1];}

int main()
{
  erep(m, 1, N){
    for(int comb = (1 << (m)) - 1; comb < (1 << N); comb = nextCombination(comb)){
      int d = 1;
      int sum = 0;
      vi c;
      rep(i, N) if(comb & (1 << i)) c.pb(i);
      do{
        int sum = 0;
        rep(i, m) sum += (i + 1) * c[i];
        dp[m][sum] += 1;
      }while(next_permutation(ALL(c)));
    }
  }

  while(cin >> n >> s) cout << dp[n][s] << endl;

  return 0;
}

Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s; cin >> s;
    int k; cin >> k;
    if(s.size() < k){
        rep(i,s.size()){
        if(s[i] != '1') {
            OUT(s[i]);
            return 0;
        }
    }
    OUT(1);
    }
    rep(i,k){
        if(s[i] != '1') {
            OUT(s[i]);
            return 0;
        }
    }
    OUT(1);

    return 0;
}



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

int main() {
  double x1, x2, y1, y2;
  std::cin >> x1 >> y1 >> x2 >> y2;
  std::cout << std::fixed << sqrt(pow((x2 - x1), 2) + pow(y2 - y1, 2))
            << std::endl;
}



Measured memory_bytes: 3272
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <utility>
#include <vector>

using namespace std;

typedef long long Long;
#define whole(xs) xs.begin(), xs.end()
#define uniq(xs) (xs.erase(unique(xs.begin(), xs.end()), xs.end()))

template<class T>
ostream& operator<<(ostream& os, const vector<T>& vs) {
    if (vs.empty()) return os << "[]";
    os << "[" << vs[0];
    for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
    return os << "]";
}

const int IINF = 1<<28;
const Long LINF = 1LL<<56;
#define INF IINF

int V, E;

struct Edge {
    int s, t, w;
    Edge(int s, int t, int w) : s(s), t(t), w(w) {}
    bool operator<(const Edge& e) const {
        return w < e.w;
    }
};

vector<Edge> G;

void Input() {
    cin >> V >> E;
    for (int i = 0; i < E; i++) {
        int s, t, w; cin >> s >> t >> w;
        G.push_back(Edge(s, t, w));
    }
}

struct UnionFind {
    int N;
    vector<int> P;
    UnionFind(int N) : N(N) {
        P.clear(); P.resize(N, -1);
    }
    int query(int x) {
        if (P[x] == -1) return x;
        return P[x] = query(P[x]);
    }
    void merge(int x, int y) {
        x = query(x); y = query(y);
        if (x == y) return;
        P[y] = x;
    }
};

void Solve() {
    sort(whole(G));
    UnionFind uf(V);
    int Ans = 0;
    for (int i = 0; i < E; i++) {
        Edge& e = G[i];
        if (uf.query(e.s) == uf.query(e.t)) continue;
        Ans += e.w;
        uf.merge(e.s, e.t);
    }
    cout << Ans << endl;
}

int main() {
    Input(); Solve();
    return 0;
}



Measured memory_bytes: 4528
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    sort(A.rbegin(), A.rend());
    ll ans = A[0];
    priority_queue<ll> que;
    que.emplace(A[1]);
    que.emplace(A[1]);

    for(int i=2; i<N; i++) {
        ll t = que.top(); que.pop();
        ans += t;
        que.emplace(A[i]);
        que.emplace(A[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6144
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <map>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <stack>
#include <queue>
#include <utility>
#include <bitset>
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define per(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,a,b) for (int i=(a);i<=(b);i++)
#define PER(i,a,b) for (int i=(b);i>=(a);i--)
#define de(x) cout<<">> "<<#x<<" = "<<x<<endl;
using namespace std;
typedef long long LL;

const int INF = 0x3f3f3f3f;
const int MAXN = 2005; // 1e6;
int n,w,z,a[MAXN],f[MAXN][MAXN][2];
int abs(int x)
{
	if (x<0) return -x;
	else return x;
}
int main()
{
	// freopen("in.txt","r",stdin);
	scanf("%d%d%d",&n,&z,&w);
	rep(i, 1, n+1) scanf("%d",a+i);
	f[0][n][1]=abs(w-a[n]);
	rep(i, 1, n+1)
	{
		f[i][n][0]=abs(a[i]-a[n]);
		f[i][n][1]=abs(a[i]-a[n]);
	}
	per(i, 0, n)
	per(j, i+1, n)
	{
		if (j == n-1) f[i][j][0]=f[i][j][1]=f[n-1][n][0];
		else 
		{
			f[i][j][0]=max(f[j][j+1][0],f[j][n][0]);
			f[i][j][1]=min(f[j][j+1][1],f[j][n][1]);
		}

	}
	f[0][0][0]=0;
	rep(i ,1 ,n+1)
	{
		f[0][0][0]=max(f[0][i][1],f[0][0][0]);
	}
	// rep(i, 0, n+1) rep(j, 0, n+1) printf("%d%c",f[i][j][0]," \n"[j==n]); 
	// de("===")
	// rep(i, 0, n+1) rep(j, 0, n+1) printf("%d%c",f[i][j][1]," \n"[j==n]); 
	printf("%d\n",f[0][0][0]);
	return 0;
}


Measured memory_bytes: 31104
#include<bits/stdc++.h>
using namespace std;
long long sum[4000][10000];
bool used[4000][5000];
int main(){
    int a[10000];
    long long int n, b, c;
    for(int m=0; ; m++){
        scanf("%lld", &n);
        if(n==0)break;
        bool na = true;
        for(int i = 0; i < n; i++){
            scanf("%d%lld%lld", &a[i], &b, &c);
            sum[m][a[i]] += b*c;
            /*if(b*c>=1000000){
                na = false;
                printf("%lld\n", a);
            }*/
        }
        for(int i = 0; i < n; i++){
            if(used[m][a[i]]==false&&sum[m][a[i]] >= 1000000){
                na = false;
              used[m][a[i]]=true;
                printf("%d\n", a[i]);
            }
        }
        
        if(na) puts("NA");
    }
}


Measured memory_bytes: 3276
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
long long int V[200010];
long long int C[200010];




int main(void){
    // Your code here!
    long long int N,H,W,i,j,k,ans,count,cost,tmp;
    
    
    string T;
    bool flag;
    count=0;
    ans=0;
    flag=false;
    cin >>N;
    
    
    for (i=0;i<N;i++){
        cin>>V[i];
    } 
    for (i=0;i<N;i++){
        cin>>C[i];
        if (V[i]-C[i]>0){
            ans+=V[i]-C[i];
        }
    } 
    
    
    
    
    cout<< ans <<endl;
    

    return 0;
    
}



Measured memory_bytes: 3548
#include<iostream>
using namespace std;
#define int long long
signed main()
{
    int a;cin>>a;
    int key=a/4+1;
    for(int i=key;i<3505;i++){
        for(int j=key;j<3505;j++){
            int e=(4*i*j)-(a*i)-(a*j);
            int m=a*i*j;
            if(e!=0&&m%e==0&&m/e>0){
                cout<<i<<" "<<j<<" "<<m/e<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
INF = float("inf")
import sys
sys.setrecursionlimit(10000)


def solve(N, t, v):
    memo = [0]
    for i in range(len(t)):
        memo += ([v[i]] * (t[i]) * 2)
    memo += [0]

    for i in range(len(memo) - 1):
        memo[i] = min(memo[i], memo[i + 1])

    memo[0] = 0
    for i in range(0, len(memo) - 1):
        memo[i + 1] = min(memo[i + 1], memo[i] + 0.5)

    memo[-1] = 0
    for i in range(len(memo) - 1, 0, -1):
        memo[i - 1] = min(memo[i - 1], memo[i] + 0.5)

    ans = 0
    for i in range(len(memo) - 1):
        ans += (memo[i] + memo[i + 1]) / 4
    return ans


def main():
    N = int(input())
    t = list(map(int, input().split()))
    v = list(map(int, input().split()))
    print("{0:4f}".format(solve(N, t, v)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 4348
#include<bits/stdc++.h>
#define endl '\n'
#define fo(i,n)        for(int i=0; i<n; i++)
#define foa(i,k,n)     for(int i=k; i<=n; i++)
#define fod(i,k,n)     for(int i=n; i>=k; i--)
#define clr(arr)       memset(arr, 0, sizeof arr)
#define hi(x)          cout<<" -> "<<#x<<" : "<<x<<endl;
using namespace std;
const int mod = 1e9 + 7;


void solve()
{
// #define T
	char a;
	cin>>a;
	if(isupper(a))
		cout<<'A';
	else
		cout<<'a';
}

int32_t main()
{
///////////////////////////////////////////////////////
#ifdef FIN
	freopen("in.txt", "r", stdin);
#endif
	ios_base::sync_with_stdio(false); cin.tie(nullptr);
///////////////////////////////////////////////////////

	int t = 1;
#ifdef T
	cin >> t;
#endif
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;
public class Main {
    static boolean prime(int s) {
        if(s == 1) return false;
        for(int i=2; i*i<=s; i++) {
            if(s%i == 0)
                return false;
        }
        return true;
    }
     
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()) {
            int a = sc.nextInt();
            int d = sc.nextInt();
            int n = sc.nextInt();
            if(a+d+n == 0)break;
            int b = a;
            if(prime(a))n--;
            int ans = a;
            if(n != 0) {
                for(int i=0;;i++) {
                    b += d;
                    if(prime(b)) n--;
                    if(n == 0) {
                        ans = b;
                        break;
                    }
                }
            }
            System.out.println(ans);
        }
    }
}


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

ll solve(vector<int> &xs) {
    const int sz = xs.size();
    ll ans = 0;

    for (int i = 1; i < sz; ++i) {
        if (xs[i] < xs[i - 1]) {
            ans += xs[i - 1] - xs[i];
            xs[i] = xs[i - 1];
        }
    }

    return ans;
}

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

    int sz;
    cin >> sz;
    vector<int> xs(sz, 0);
    for (auto &x : xs) cin >> x;

    cout << solve(xs) << '\n';

    return 0;
}


Measured memory_bytes: 3988
h,n=map(int,input().split())
A=[list(map(int,input().split())) for i in range(n)]
ma=max(a for a,b in A)
dp=[0]*(h+ma)
for i in range(1,h+ma):
  dp[i]=min(dp[i-a]+b for a,b in A)
print(min(dp[h:]))

Measured memory_bytes: 3668
mod = 10**9+7

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

DP = [0]*(1<<n)
DP[0] = 1

pow2 = [1<<i for i in range(n)]
cnt = [0]*(1<<n)
for i in range(1<<(n-1)):
    cnt[2*i] = cnt[i]
    cnt[2*i+1] = cnt[i]+1

for state in range(1, 1<<n):
    k = cnt[state]
    for j in range(n):
        if a[k-1][j] and (state>>j)&1:
            DP[state] += DP[state^pow2[j]]
    DP[state] %= mod
print(DP[-1])

Measured memory_bytes: 73564
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(0)
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
typedef long long ll;
#define pri(n) printf("%d\n",n)
#define lpri(n) printf("%lld\n",n);
#define rep(i,st,ed) for(int i=st;i<ed;i++)
#define var(n) int n; scn(n)
#define F first
#define S second 
#define pb(n) push_back(n)
#define pii pair<int,int> 
const int N=2e6+5;
const ll M=1e9+7;
const ll inf=1e18+5;

int main()
{
	var(n);var(k);
	int a[n];
	int pos= -1;
	rep(i,0,n)
	{
		scn(a[i]);
		if(a[i]==1)
			pos = i;
	}
	int ans = (n-1 + k-2)/(k-1);
	pri(ans);
}

Measured memory_bytes: 640
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma warning(disable:4786)
#pragma warning(disable:4996)

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=10005;
int n,m,len;
int a[12];
int dp_len[M];
int cost[]={0,2,5,5,4,5,6,3,7,6};
int solve(int rem)
{
    if(rem<0)return -inf;
    if(rem==0)return 0;
    int &ret=dp_len[rem];
    if(ret!=(-1))return ret;
    ret=0;
    for(int i=1;i<=m;i++)
    {
        ret=max(ret,1+solve(rem-cost[a[i]]));
    }
    return ret;
}
vector<int>dp[M];
int yo(int baki,int pos)
{
    if(baki<0)return 0;
    if(pos>len)
    {
        if(baki==0)return 1;
        else return 0;
    }
    int &ret=dp[baki][pos];
    if(ret!=(-1))return ret;
    ret=0;
    for(int i=1;i<=m;i++)
    {
        int x=yo(baki-cost[a[i]],pos+1);
        if(x==1)ret=1;
    }
    return ret;
}
 main()

{
    fast
    cin>>n>>m;
    f(i,1,m)
    {
        cin>>a[i];
    }
    sort(a+1,a+m+1);
    reverse(a+1,a+m+1);
    memset(dp_len,-1,sizeof dp_len);
    len=solve(n);
    f(i,0,n+2)dp[i].assign(len+5,-1);
    string ses="";
    int has=n;
    for(int i=1;i<=len;i++)
    {
        for(int j=1;j<=m;j++)
        {
            if(yo(has-cost[a[j]],i+1))
            {
                has=has-cost[a[j]];
                ses+=(a[j]+'0');
                break;
            }
        }
    }
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 395428
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>

#define mod 1000000007

using namespace std;
using ll = long long;

void solve() {
    string s;
    int x = 0;
    cin >> s;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == '1'){
            x++;
        }
    }
    cout << x << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
// H - Grid 1
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rep(i,n) for(int i=0;i<(n);++i)
#define MOD 1000000007

int main(){
	int H,W; cin>>H>>W;

	vector<string> grid(H);
	rep(h, H) cin>>grid[h];

	vvi dp(H, vi(W, 0));
	dp[0][0] = 1;

	rep(h, H){
		rep(w, W){
			if(grid[h][w] == '#') continue;

			// right (h,w+1)=(h,w)+(h-1,w+1)
			if(w+1 < W && grid[h][w+1] == '.'){
				dp[h][w+1] = dp[h][w];
				if(0 <= h-1) dp[h][w+1] += dp[h-1][w+1];
				dp[h][w+1] %= MOD;
			}

			// down (h+1,w)=(h,w)+(h+1,w-1)
			if(h+1 < H && grid[h+1][w] == '.'){
				dp[h+1][w] = dp[h][w];
				if(0 <= w-1) dp[h+1][w] += dp[h+1][w-1];
				dp[h+1][w] %= MOD;
			}

		}
	}
	cout<< dp[H-1][W-1] <<endl;

	// // print ==========================
	// puts("===");//
	// cout<<"H "<<H<<" W "<<W<<"\n";//
	// rep(h,H) cout<<grid[h]<<"\n";//
	// for(auto v:dp){
	// 	for(auto x:v)printf(" %2d",x);
	// 	puts("");
	// }
	// // =================================

}


Measured memory_bytes: 5248
// ABC173A2
//#include "pch.h"
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
	int n;
	cin >> n;
	int pay = 0; // 支払い金額
	while (pay < n) {
		pay += 1000;
	}
	cout << pay-n << endl;
	return 0;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



i64 x,y;
//コンビネーション
//けんちょんさんありがとう
const int MAX = 1010101, MOD = INF;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long C(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
////
void solve(){
	cin >> x >> y;
	if(x < y) swap(x,y);
	
	int cnt = x-y;
	x -= cnt*2; y -= cnt;
	if(x % 3){
		cout << 0 << endl;
		return;
	}
	COMinit();
	cout << C(cnt+x/3*2, x/3) << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 23936
n = int(input())
m = 10**9 + 7

L = [-1 for _ in range(n+10)]
L[0] = 0
L[1] = 0
L[2] = 1
L[3] = 1
L[4] = 1
def f(m):
    if m <= 5:
        return L[m-1]
    a = 1
    for i in range(3, m-2):
        if L[i-1] == -1:
            L[i-1] = f(i)
        a += L[i-1]
    return a

print(f(n) % m)

Measured memory_bytes: 9180
#include <iostream>

bool judge(int x) {
    for (int i = 2; i < x; ++i) {
        if (x % i == 0) return false;
    }
    return true;
}

int main() {
    long int N;
    long int now_point[2];
    std::cin >> N;
    long int count = 0;

    now_point[0] = 1;
    now_point[1] = 1;

    while (now_point[0] * now_point[1] < N) {
        now_point[0]++;
        now_point[1]++;
    }

    while (true) {
        if (now_point[0] * now_point[1] == N) {
            std::cout << now_point[0] + now_point[1] - 2 << '\n';
            break;
        } else {
            if (now_point[0] * now_point[1] > N) {
                now_point[1]--;
                count = 0;
            }
            if (now_point[0] * now_point[1] < N) {
                now_point[0]++;
                count++;
                if (count > 2) {
                    now_point[0] = N / now_point[1];
                    count = 0;
                }
            }
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__;
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k; cin >> k;
    cout << a[k-1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
    #include<cstdlib>
    #include<math.h>
    #include<set>
    #include<string>
    #include<stdlib.h>
    using namespace std ;
    int main(){
      int A,P;
      cin>>A>>P;
      cout<<(3*A+P)/2<<endl;
      return 0;
    }

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

using namespace std;

typedef long long LL;
#define N 6000

const LL mod=1000000007;
LL n,a,b,ans,f[N],g[N],pre[N];

void upd(LL &x,LL y){
	x=(x+y)%mod;
}

int main(){
	scanf("%lld%lld%lld",&n,&a,&b);
	if (a<b) swap(a,b);
	g[0]=1;
	for (LL i=1;i<=n;++i){
		g[i]=g[i-1];
		if (i>=b){
			++g[i];
			for (LL j=b;i-j-1>=0;++j){
				upd(g[i],g[i-j-1]);
			}
		}
	}
	ans=1; for (LL i=1;i<=n;++i) ans=ans*2%mod;
	pre[0]=g[0]; for (LL i=1;i<=n;++i) pre[i]=(pre[i-1]+g[i])%mod;
	for (LL i=1;i<=n;++i){
		for (LL j=1;j<i-1;++j){
			LL l=max(i-j-2-b+1,0LL),r=min(a-2,i-j-2)-1;
			if (l<=r){
				upd(f[i],f[j]*(pre[r]-(l?pre[l-1]:0)));
			}
			if (a>1&&i-j-1<b){
				upd(f[i],f[j]);
			}
		}
		LL l=max(i-1-b+1,0LL),r=min(a-1,i-1)-1;
		if (l<=r) upd(f[i],pre[r]-(l?pre[l-1]:0));
		if (i<b) upd(f[i],1);
		if (i<n&&n-i<a) upd(ans,-f[i]*g[n-i-1]);
		if (i==n) upd(ans,-f[i]);
	}
	upd(ans,mod);
	printf("%lld\n",ans);
	
	return 0;
}
			

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

int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i,n) cin >> a[i];
  sort(a.rbegin(),a.rend());
  int len = a[0]+1;
  vi cnt(len);
  for(int x : a) for(int i=x; i<=len; i+=x) cnt[i]++;
  int ans=0;
  for(int x : a){
    if(cnt[x] == 1) ans++;
  }
  cout << ans << endl;
}


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

int main()
{
  char s[101],t[101];
  char u;
  int n,m;
  int i,j;
  int a=0;
  scanf("%s",s);
  scanf("%s",t);
  n=strlen(s);
  m=strlen(t);
  for (i=0;i<n;i++){
    for (j=i+1;j<n;j++){
      if(s[i]>s[j]){
        u=s[i];
        s[i]=s[j];
        s[j]=u;
      }
    }
  }
  for (i=0;i<m;i++){
    for (j=i+1;j<m;j++){
      if(t[i]<t[j]){
        u=t[i];
        t[i]=t[j];
        t[j]=u;
      }
    }
  }
  for(i=0;i<n;i++){
    if(s[i]<t[i]){
      a=1;
      break;
    }
    if(s[i]>t[i]){
      a=2;
      break;
    }
  }
  if(a==0 && n<m) a=1;
  if(a==0 && n>=m) a=2;
  if(a==1) printf("Yes");
  if(a==2) printf("No");
  return 0;
}






Measured memory_bytes: 1700
#include <bits/stdc++.h>
#define mem(a,b) memset(a,b,sizeof(a))
#define pb push_back
using namespace std;
const int maxn = 1e5+50;
typedef long long ll;
int cnt[maxn];
int n;
int main(){
//    freopen("input.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    int t, mx = 0;
    for(int i = 0; i < n; i++){
        cin >> t;
        cnt[t]++;
        mx=max(mx, t);
    }
    int ans = 0;
    for(int i = 0; i <= mx; i++){
        if(i == 0){
            t = cnt[0] + cnt[1];
        }
        else{
            t = cnt[i]+cnt[i-1]+cnt[i+1];
        }
        ans = max(ans, t);
    }
    cout << ans << "\n";
    return 0; 
}

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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

struct List {
    List() {
        first = new Node();
        last = new Node();

        first->nxt = last;
        last->prev = first;
    }

    ~List() {
        Node *nodePtr = first;
        while (nodePtr != nullptr) {
            Node *nxt = nodePtr->nxt;
            delete (nodePtr);
            nodePtr = nxt;
        }
    }

    void insert(ll x) {
        Node *newNodePtr = new Node();
        newNodePtr->value = x;
        Node *prevPtr = last->prev;
        newNodePtr->nxt = last;
        newNodePtr->prev = prevPtr;
        prevPtr->nxt = newNodePtr;
        last->prev = newNodePtr;
    }

    void dump() {
        Node *nodePtr = first->nxt;
        while (nodePtr != last) {
            cout << nodePtr->value;
            nodePtr = nodePtr->nxt;
            if (nodePtr == last)
                break;
            cout << " ";
        }
        cout << endl;
    }

    void splice(List &list) {
        Node *nodePtr = last->prev;

        nodePtr->nxt = list.first->nxt;
        last->prev = list.last->prev;
        list.first->nxt->prev = first;
        list.last->prev->nxt = last;

        list.first->nxt = list.last;
        list.last->prev = list.first;
    }

    struct Node {
        Node *prev = nullptr;
        Node *nxt = nullptr;
        ll value;
    };

    Node *first;
    Node *last;
};

List L[1005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, Q;
    cin >> N >> Q;
    REP(_, Q) {
        ll q;
        cin >> q;
        if (q == 0) {
            ll t, x;
            cin >> t >> x;
            L[t].insert(x);
        }
        else if (q == 1) {
            ll t;
            cin >> t;
            L[t].dump();
        }
        else {
            ll s, t;
            cin >> s >> t;
            L[t].splice(L[s]);
        }
    }
    return 0;
}


Measured memory_bytes: 18828
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> D(N);
  map<ll, ll> m_D;
  for (int i = 0; i < N; i++) {
    cin >> D[i];
    if (m_D.find(D[i]) != m_D.end()) {
      m_D[D[i]]++;
    } else {
      m_D[D[i]] = 1;
    }
  }
  ll M;
  cin >> M;
  vector<ll> T(N);
  bool can = true;
  for (int i = 0; i < M; i++) {
    cin >> T[i];
    if (m_D.find(T[i]) != m_D.end() && m_D[T[i]] > 0) {
      m_D[T[i]]--;
    } else {
      can = false;
      break;
    }
  }
  string ans = (can) ? "YES" : "NO";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 15872
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

int main(){

  // read problem
  long long int N, K, S;
  scanf("%lld%lld%lld", &N, &K, &S);

  // construction
  std::vector<long long int> A;
  for(long long int i = 0; i < K; i++){
    A.push_back(S);
  }
  long long int tmp = S+1;
  if(S == 1e9){
    tmp = 1e9-1;
  }
  for(long long int i = K; i < N; i++){
    A.push_back(tmp);
  }

  std::cerr << "Answer: " << std::endl;
  for(long long int i = 0; i < N; i++){
    printf("%lld ", A[i]);
  }std::cerr << std::endl;

  return 0;
  
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

bool yymm(int x) {
    int y = x / 100, m = x % 100;
    return m >= 1 && m <= 12;
}

bool mmyy(int x) {
    int y = x % 100, m = x / 100;
    return m >= 1 && m <= 12;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int x;
    cin >> x;
    if(yymm(x) && mmyy(x)) {
        cout << "AMBIGUOUS" << endl;
    } else if(yymm(x)) {
        cout << "YYMM" << endl;
    } else if(mmyy(x)) {
        cout << "MMYY" << endl;
    } else {
        cout << "NA" << endl;
    }
    return 0;
}


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

count_A = 0
count_B = 0
count_C = 0
count = 0
if A >= K:
    count_A += K
else:   # A < K
    K -= A
    count_A += A
    if B >= K:
        count_B += K
    else:
        K -= B
        count_B += B
        count_C += K

print(count_A - count_C)


Measured memory_bytes: 9116
#include <iostream>
#include <sstream>
#include <iomanip>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int n,m;
    cin >> n >> m;
    map<int, vector<int>> mv;    
    int p[m] = {};
    int y[m] = {};
    for(int i = 0; i<m; i++){
        cin >> p[i] >> y[i];
        auto& v = mv[p[i]];
        v.push_back(y[i]);
    }
    
    for(auto& v: mv){
        sort(v.second.begin(), v.second.end());
    }
    
    for(int i=0; i<m; i++){
        stringstream s;
        s << std::setw(6) << std::setfill('0') << p[i];
        auto &v = mv[p[i]];
        auto loc = lower_bound(v.begin(), v.end(), y[i]) - v.begin() +1;
        s << std::setw(6) << std::setfill('0') << loc;
        cout << s.str() << endl;
    }
    
    return 0;
}

Measured memory_bytes: 13184
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int32_t main()
{
    IOS
    int n;
    cin>>n;
    string arr[n];
    int brr[n];
    int sum=0;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i]>>brr[i];    
        sum+=brr[i];
    }
    string c;cin>>c;
    for(int i=0;i<n;i++)
    {
        sum-=brr[i];
        if(arr[i]==c)
            break;
    }
    cout<<sum;
}


Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

q = []
for i in range(N):
    q.extend([i+1] * A[i])

ans = [['' for _ in range(W)] for _ in range(H)]
for h in range(H):
    if h % 2 == 0:
        X = range(W)
    else:
        X = reversed(range(W))
    for w in X:
        ans[h][w] = str(q.pop())

for line in ans:
    print(' '.join(line))


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;
typedef vector<int> vi;

signed main(){
    int ans = 0;
    string s;
    cin >> s;
    rep(i, 1, s.size()){
        if(s[i] != s[i - 1]) ans ++;
    }
    o(ans);
}

Measured memory_bytes: 1020
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int n, s, max=0, min=1000, sum=0;
	while(true){
	    n = sc.nextInt();
	    if(n == 0) break;
	    for(int i=0;i<n;i++){
		s = sc.nextInt();
		sum+=s;
		if(s>max) max = s;
		if(s<min) min = s;
	    }
	    sum = sum-max-min;
	    System.out.println(sum/(n-2));
	    sum=0;
	    max=0;
	    min=1000;
	}
    }
}

Measured memory_bytes: 29004
from sys import stdin
import numpy as np
mod = 10**9+7
X,Y = [int(x) for x in stdin.readline().rstrip().split()]

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod
 
def power(x, n):
    """
    O(log n)
    """
    if n == 0:
        return 1
 
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x % mod
        x *= x % mod
        n //= 2
 
    return K * x % mod
 
def div(a, b):
    return mul(a, power(b, mod-2))
 
def fact(n):
    f = 1
    for i in range(1,n+1):
        f *= i
        f %= mod
    return f

if (X+Y) % 3 != 0:
    print(0)

else:
    A = np.matrix([[2, 1],[1, 2]])
    Y = np.matrix([[X],[Y]])
    x,y = np.linalg.solve(A,Y)
    x = int(x)
    y = int(y)
    ans = fact(x+y)
    ans = div(ans,fact(x))
    ans = div(ans,fact(y))
    if x < 0 or y <0:
        print(0)
    else:
        print(ans%mod)

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

using namespace std;

int main()
{
  string S; cin >> S;

  for (int i = S.size()-1; i >= 0; --i) {
    if (i % 2 == 1) continue;

    string left = S.substr(0, i/2);
    string right = S.substr(i/2, i/2);

    if (left == right) {
      cout << i;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>

#define REP(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;

int main() {
    int n;
    scanf("%d", &n);
    vector<int> t(n+1), x(n+1), y(n+1);
    
    t[0] = 0; x[0] = 0; y[0] = 0;
    REP(i, 1, n+1) {
       cin >> t[i] >> x[i] >> y[i];
    }

    bool ans = true;
    REP(i,1, n+1) {
        int time = t[i] - t[i-1];
        int dist = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]);
        if ((time - dist) >= 0 && (time - dist) % 2 == 0) {
            ans = true;
        } else {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 1408