akhauriyash/Code-Regression huggingface dataset:
from itertools import combinations
N = int(input())
s = input()
ans = 0
for a2 in range(10):
    for b2 in range(10):
        for c2 in range(10):
            a = str(a2)
            b = str(b2)
            c = str(c2)
            count = 0
            for i in s:
                if a == i:
                    count += 1
                    if count == 1:
                        a = b
                    if count == 2:
                        a = c
            if count >= 3:
                ans += 1
print(ans)

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

bool isMatch(int x) {
  if (x % 3 == 0) return true;

  do {
    if (x % 10 == 3) return true;
  } while (x /= 10);

  return false;
}

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (isMatch(i)) cout << ' ' << i;
  }
  cout << endl;
  return 0;
}




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

using ll = long long;
#define ALL(c) (c).begin(), (c).end()
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    vector<int> a(n + 1);

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

    int t = 0;
    for (int i = 1; i <= n; i++) {
        if (i == a[a[i]]) {
            t++;
            a[a[i]] = -1;
        }
    }

    cout << t << endl;
}


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

int main(){
    int n; cin >> n; 
    vector<int>  a(n); rep(i,n) cin >> a[i];
    int q; cin >> q;
    vector<bool> ans(q);
    vector<int>  m(q); rep(i,q) cin >> m[i];
    for (int bit = 0; bit < (1<<n); ++bit) {
        vector<int> S;
        for (int i = 0; i < n; ++i) {
            if (bit & (1<<i)) { 
                S.push_back(i);
            }
        }
        rep(i,q){
            int res = 0;
            rep(j,S.size()){
                res += a[S[j]];
            }
            if(res == m[i]){
                ans[i] = 1;
            }
        }
    }
    rep(i,q){
        cout <<((ans[i]) ?"yes" :"no") << endl;
    }
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,m,sum = 0;
  cin >> n >> m;
  vector<int> data(m);
  for ( int i = 0 ; i < m ; i++ ) {
    cin >> data.at(i);
    sum += data.at(i);
  }
  
  if ( n >= sum ) {
    cout << n-sum << endl;
  }
  else {
    cout << -1 << endl;
  }
  
}

Measured memory_bytes: 3648
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	int i=0;
	int k=0;
	
	cin>>s;
	k=s.size();
	
	for(i=0;i<k;i=i+2){
		cout<<s[i];
	}
        return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  char b; cin >> b;
  map<char, char> m = {
    {'A', 'T'},
    {'T', 'A'},
    {'C', 'G'},
    {'G', 'C'},
  };
  COUT(m[b]);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ll> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> vec;
vi adj[111111];
ll ans=0;
int lab[111111];

void dfs(int u, int p=-1)
{
	for(int v:adj[u])
	{
		if(v==p) continue;
		dfs(v,u);
	}
	lab[u]=vec.back(); 
	if(p!=-1) ans+=lab[u];
	vec.pop_back();
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int n; cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int u,v; cin>>u>>v; u--; v--;
		adj[u].pb(v); adj[v].pb(u);
	}
	for(int i=0;i<n;i++)
	{
		int x; cin>>x; vec.pb(x);
	}
	sort(vec.rbegin(),vec.rend());
	dfs(0);
	cout<<ans<<'\n';
	for(int i=0;i<n;i++)
	{
		cout<<lab[i];
		if(i+1<n) cout<<' ';
	}
	cout<<'\n';
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const ll MOD2=998244353;
const double PI=acos(-1);
const ll INF=1e15;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

const ll MAXN=100000;
vl G[MAXN];

int main() {
  ll n,m;
  cin >> n >> m;
  vl a(m),b(m);
  cout << "Yes" << endl;
  rep(i,m){
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }
  vl X(n,INF);
  queue<ll> q;
  q.push(0);
  while(!q.empty()){
    ll x=q.front();
    q.pop();
    ll k=G[x].size();
    rep(i,k){
      if(X[G[x][i]]==INF){
        X[G[x][i]]=x;
        q.push(G[x][i]);
      }
    }
  }
  rep(i,n-1){
    cout << X[i+1]+1 << endl;
  }
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  int left = 0, right = 1 << 29;
  for (int i = 0; i < M; i++) {
    int l, r;
    cin >> l >> r;
    left = max(left, l);
    right = min(right, r);
  }
  cout << max(0, right - left + 1) << '\n';
  return 0;
}


Measured memory_bytes: 256
/*
	Author: zhaodeyin
	Time: 2018.4.7
*/
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long LL;
const int MaxN = 1e5 + 4;
int vis[400];
char s[4];
int main(){
	/*cin>>s;
	for(int i = 0; i < strlen(s); i++){
		vis[s[i]] = 1;
	}
	int flag = 0;
	if(vis['a'] == 1 && vis['b'] == 1 && vis['c'] == 1) flag = 1;
	if(flag == 1) cout<<"Yes"<<endl;
	else cout<<"NO"<<endl;
	*/
	char a,b,c;
	cin>>a>>b>>c;
	vis[a]++;vis[b]++;vis[c]++;
	if(vis['a'] > 1 || vis['b'] > 1 || vis['c'] > 1) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll mod = 1000000007;
#define SIZE 262144
class BIT
{
public:
	ll bit[SIZE + 1];
	void add(int a, ll b)
	{
		a++;
		for (;;)
		{
			bit[a] += b;
			bit[a] %= mod;
			a += a&-a;
			if (a > SIZE)return;
		}
	}
	ll get(int a)
	{
		a++;
		ll ret = 0;
		for (;;)
		{
			ret += bit[a];
			a -= a&-a;
			if (a == 0)return ret%mod;
		}
	}
};
BIT bi;
ll d1[101010], d2[101010];
typedef pair<ll, ll>pii;
int main()
{
	int num, way;
	scanf("%d%d", &num, &way);
	for (int i = 0; i < num; i++)scanf("%lld", &d1[i]);
	d2[0] = -10101010101010LL, d2[way + 1] = 1010101010101010LL;
	for (int i = 1; i <= way; i++)scanf("%lld", &d2[i]);
	vector<pii>v;
	vector<ll>zat;
	for (int i = 0; i < num; i++)
	{
		int a = lower_bound(d2, d2 + way + 2, d1[i]) - d2;
		if (a == 1 || a == way + 1)continue;
		v.push_back(make_pair(d1[i] - d2[a - 1], d1[i] - d2[a]));
		zat.push_back(d2[a] - d1[i]);
	}
	zat.push_back(0);
	sort(v.begin(), v.end()), sort(zat.begin(), zat.end());
	bi.add(0, 1);
	for (int i = 0; i < v.size(); i++)
	{
		if (i != 0 && v[i] == v[i - 1])continue;
		int a = lower_bound(zat.begin(), zat.end(), -v[i].second) - zat.begin();
		ll t = bi.get(a - 1);
		bi.add(a, t);
	}
	printf("%lld\n", bi.get(num + 10));
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> ga(n);
  vector<vector<int>> gb(n);
  string col;
  cin >> col;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    if (col[a] == col[b]) {
      ga[a].push_back(b);
      ga[b].push_back(a);
    } else {
      gb[a].push_back(b);
      gb[b].push_back(a);
    }
  }
  vector<vector<int>> g(n);
  vector<pair<int, int>> ed;
  for (int i = 0; i < n; i++) {
    for (int x : ga[i]) {
      for (int y : gb[i]) {
        g[x].push_back(y);
        ed.emplace_back(x, y);
      }
    }
  }
  vector<int> ord;
  vector<int> id(n);
  vector<bool> mark(n);
  function<void(int)> Dfs = [&](int v) {
    mark[v] = 1;
    for (int to : g[v]) {
      if (!mark[to]) {
        Dfs(to);
      }
    }
    id[v] = (int) ord.size();
    ord.push_back(v);
  };
  for (int i = 0; i < n; i++) {
    if (!mark[i]) {
      Dfs(i);
    }
  }
  bool found = false;
  for (auto e : ed) {
    found |= (id[e.second] > id[e.first]);
  }
  cout << (found ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 709936
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>

#define BR "\n"
#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a, b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it, cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it, cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define is insert
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)

#define DumpArray(cont, from, to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

/*
 * ***_bound(6)
 * 5 6 6 6 6 6 7 7 7
 *   ^lower    ^upper
 * void reverse(c.begin(), c.end())
 *
 * graph
 * seg tree
 * dp
 * brute force
 */
struct Comparator{
    int operator()(int l, int r) const {
        return r<l;
    }
};
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
//set<int, Comparator> S;
const int MAX_N = 100000;
ll facTable[MAX_N+10];
ll invTable[MAX_N+10];

void generate(int n, ll p) { // p must be prime number. O(n) O(log2P)
    memset(facTable, 0, sizeof(facTable));
    memset(invTable, 0, sizeof(invTable));
    facTable[0]=1;
    for(int i=1;i<=n;++i) {
        facTable[i] = (facTable[i-1] * i) % p;
    }

    ll power = facTable[n];
    ll res = 1;
    ll index = p-2;

    for(int i=0;(index>>i) != 0;++i) {
        if( ((index >> i) & 1) == 1) {
            res = (res * power) % p;
        }
        power = (power*power) %p;
    }

    invTable[n] = res;
    for(int i=n;i>=1;--i) {
        invTable[i-1] = (invTable[i] * i) % p;
        if((invTable[i] * facTable[i]) %p != 1) printf("Error");
    }

}

ll factorial(int n) {
    return facTable[n];
}

ll inverseFactorial(int n) {
    return invTable[n];
}


ll N,K;
vector<ll> A;
ll mod=1000*1000*1000+7;

ll nCk(ll n, ll k) {
    ll ret=factorial(n);
    ret*=inverseFactorial(k);
    ret=AS_MOD(ret,mod);
    ret*=inverseFactorial(n-k);
    ret=AS_MOD(ret,mod);
    return ret;
}
int main() {
    cin >> N>> K;
    generate(N,mod);
    A.resize(N);
    REP(i,N)
        cin>>A[i];
    sort(ALL(A));
    ll ans=0;
    for(ll i=N-1;i>=K-1;--i) {
        ans += A[i]*nCk(i,K-1);
        ans=AS_MOD(ans,mod);
    }
    for(ll i=0;i<N-K+1;++i) {
        ans -= A[i]*nCk(N-i-1,K-1);
        ans=AS_MOD(ans,mod);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int K,X;
  cin>>K>>X;
  for(long int i=(X-K+1);i<(X+K);i++){
    cout<<i;
    if(i==X+K-1){
      cout<<endl;
    }
    else{
      cout<<" ";
    }
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define EPS 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

/**
 * Usage:
 * 
 * chmin(old, new);
 * chmax(old, new);
 * 
 */ 
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



int H, W;
char maze[1010][1010];
ll dp[1010][1010];

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

  rep(i, H) {
    rep(j, W) {
      cin >> maze[i][j];
    }
  }

  rep(i, H) {
    rep(j, W) {
      if (i == 1 && j == 1) {
        dp[i][j] = 1LL;
      } else {
        if (maze[i][j] == '#') continue;

        dp[i][j] += dp[i-1][j];
        dp[i][j] %= MOD;
        dp[i][j] += dp[i][j-1];
        dp[i][j] %= MOD;
      }
    }
  }

  cout << dp[H][W] << "\n";

}

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

void _DEBUG() {
    #ifndef _DEBUG
    freopen("input.in", "r", stdin);
    #endif
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // _DEBUG();

    int h {}, w {}, k {};
    cin >> h >> w >> k;

    vector<vector<char>> mat (h, vector<char> (w));
    for (int i {}; i < h; ++i) {
        for (int j {}; j < w; ++j) {
            cin >> mat.at(i).at(j);
        }
    }

    int ans {};

    for (int r {}; r < (1 << h); ++r) {
        for (int c {}; c < (1 << w); ++c) {
            int curr {};
            for (int i {}; i < h; ++i) {
                for (int j {}; j < w; ++j) {
                    if (!(r & (1 << i)) && !(c & (1 << j)) && mat.at(i).at(j) == '#')
                        ++curr;
                }
            }
            if (curr == k)
                ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n;
  long long max, plus=0;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  max = a[0];
  rep(i,n){
    if(max>a[i]) plus += (max-a[i]);
    if(a[i]>max) max=a[i];
  }
  cout << plus << endl;
  return 0;
}

Measured memory_bytes: 3964
#include <iostream>

using namespace std;

int main(void) {
    int w;
    while (true) {
        cin >> w;
        if (cin.eof()) break;
        for (int x = 1; x <= 512; x *= 2) {
            if (w % (x * 2) != 0) {
                cout << x;
                w -= x;
                if (w == 0) {
                    cout << endl;
                    break;
                }
                cout << " ";
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1164
check[30], c, n, a, xor_sum, ans, bit, i;
int main() {
  while (1) {
    c = getchar_unlocked();
    if (48 <= c && c <= 57)
      n = n * 10 + c - 48;
    else
      break;
  }

  for (i = 0; i < n; i++) {
    a = 0;
    while (1) {
      c = getchar_unlocked();
      if (48 <= c && c <= 57)
        a = a * 10 + c - 48;
      else
        break;
    }
    xor_sum ^= a;
    a = a ^ (a - 1);

    check[__builtin_popcount(a) - 1] = 1;
  }

  for (bit = 29; bit >= 0; bit--) {
    if (check[bit] && ((1 << bit) & xor_sum)) {
      xor_sum ^= (1 << (bit + 1)) - 1;
      ans += 1;
    }
  }

  printf("%d\n", xor_sum ? -1 : ans);
}

Measured memory_bytes: 128
#include <stdio.h>
main()
{
    long long int n,k,l=0,m;
	scanf("%lld",&n);
	m=n;
	
    while(n>10)
   	{
	    	k=n%10;
	    	l=l+k;
	    	n=n/10;
   	}
	if(m%(l+n)==0)
	      printf("Yes\n");
   	else
	      printf("No\n");

}

Measured memory_bytes: 128
Red  = []
Blue = []

def match_and_remove(x,y):
    maxy  = -1
    index = -1
    for i in range(len(Red)):
        rx,ry = Red[i]
        if rx < x and ry < y:
            if maxy < ry:
                maxy = ry
                index = i
    if index != -1:
        a = Red.pop(index)
        #print(a,[x,y])
        return True
    else:
        return False

N = int(input())
for _ in range(N):
    a,b = map(int,input().split())
    Red.append([a,b])
for _ in range(N):
    c,d = map(int,input().split())
    Blue.append([c,d])

Red.sort(key=lambda x:x[0])
Blue.sort(key=lambda x:x[0])

ans = 0
for blue in Blue:
    x = blue[0]
    y = blue[1]
    ret = match_and_remove(x,y) 
    if ret:
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>

using namespace std;
static const int MAX = 200000;

int main() {
 
int R[MAX],n;
cin>>n;

for( int i =0; i<n;i++) cin>>R[i];

int maxv = -2000000000;
int minv = R[0];

for( int i=1; i<n; i++){

maxv = max( maxv, R[i]-minv);
minv = min(minv, R[i]);

}
cout << maxv<<endl;
return 0;
}



Measured memory_bytes: 3896
#include <bits/stdc++.h>
#define nl "\n"
#define pb push_back
#define sp " "
typedef long long ll;
#define len(x) x.length()
#define vsort(x) sort(x.begin(), x.end();
using namespace std;
int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    #ifndef ONLINE_JUDGE
   // freopen("bruh.txt","r",stdin);
    #endif
     int n;
     cin >>n;
     ll sum=0;
     for(int i=1;i<=n;i++){
        if(i%3!=0 and i%5!=0)sum+=i;
     }
     cout<<sum;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vpii vector<pair<int,int>> 
#define vl vector<ll> 
#define vvl vector<vector<ll>> 
#define vb vector<bool> 
#define vvb vector<vector<bool>>
#define vs vector<string> 
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a * b / g; }
bool is_prime(ll x) { for (ll i = 2; i * i <= x; i++) { if (x % i == 0)return false; } return true; }

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

	int n;
	cin >> n;
	vvi a(n, vi(3));
	rep(i, n)rep(j,3) cin >> a[i][j];
	vvi dp(n, vi(3));
	rep(j, 3)dp[0][j] = a[0][j];
	reps(i, n - 1)rep(j, 3)rep(k, 3)
	{
		if (j != k)
		{
			chmax(dp[i][j], dp[i - 1][k] + a[i][j]);
		}
	}
	int ans = 0;
	rep(i, 3)chmax(ans, dp[n - 1][i]);
	co(ans);
	return 0;
}


Measured memory_bytes: 11264
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int y = 700;

		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == 'o') y += 100;
		}

		System.out.println(y);
	}

}

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

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
priority_queue<llint,vector<llint>,greater<llint> > que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve(){
	llint n,m;
	cin >> n >> m;
	int v[n][m];
	int v1[m];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)cin >> v[i][j];
	}
	for(int i=0;i<m;i++)cin >> v1[i];
	llint ans;
	for(int i=0;i<n;i++){
		ans=0;
		for(int j=0;j<m;j++){
			ans+=v[i][j]*v1[j];
		}
		cout << ans << endl;
	}
}

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



Measured memory_bytes: 3140
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		
		int tate, yoko;
		tate = scan.nextInt();
		yoko = scan.nextInt();
		
		System.out.print(tate * yoko + " ");
		System.out.println((tate + yoko) * 2);
	}
}

Measured memory_bytes: 26060
# -*- coding: utf-8 -*-
"""
Created on Thu May 14 16:15:19 2020

@author: shinba
"""

n,t = map(int,input().split())

T = list(map(int,input().split()))
T.append(10**10)
R = []
for i in range(n):
    R.append(T[i+1]-T[i])

ans = 0
start = T[0]

for i in range(n):
    if R[i] <= t:
        continue
    ans += t+(T[i]-start)
    start = T[i+1]
    
print(ans)

Measured memory_bytes: 26708
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] H = new int[N];
		for (int i = 0; i < H.length; i++) {
			H[i] = sc.nextInt();
		}

		PrintWriter out = new PrintWriter(System.out);

		for (int i = H.length - 1; i > 0; i--) {
			if (H[i - 1] <= H[i]) {
				continue;
			} else if (H[i - 1] - 1 == H[i]) {
				H[i - 1]--;
			} else {
				out.println("No");
				out.flush();
				return;
			}
		}

		out.println("Yes");
		out.flush();
	}

	public static int gcd(int a, int b) {
	    if (b == 0) return Math.abs(a);
	    return gcd(b, a % b);
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 23892
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<set>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	int n,a;
	cin >> n>>a;
	if (n%500 <= a) cout << "Yes"<<endl;
	else cout <<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
/*input
3 3
1 7 11
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 100900
#define INF 0x3f3f3f3f

int n , x[MAX] , a;

int32_t main(){
	IOS;
	cin >> n >> a;
	REP(i , 1 , n + 1) cin >> x[i] , x[i] -= a , x[i] = abs(x[i]);
	REP(i , 1 , n + 1) x[1] = __gcd(x[i] , x[1]);
	cout << x[1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>
#include <bitset>
#include <list>
#include <iomanip>
#include <cctype>

#define for0(i, N)    for (long long i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (long long i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (long long i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (long long i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (long long i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (long long i = (x), a = 0; a < (N);    \
                              i = (i + 1) % (N), ++a)
#define int long long

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b + 1;
}

template<size_t i>
std::bitset<i> operator++(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b++;
    return temp;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b, signed){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    return b = (unsigned long long)b - 1;
}

template<size_t i>
std::bitset<i> operator--(std::bitset<i> b){
    static_assert(i <= 64, "Cannot cast 64bit int.");
    auto temp = b;
    b--;
    return temp;
}

long long constexpr inf = std::numeric_limits<long long>::max();

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vector<ll>> vvll;


signed main(void){
    cin.tie(0); ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);
    ll k;
    cin >> k;

    pql q;

    for1n(i, 9) q.push(i);

    ll now = 0;
    for0(i, k){
        now = q.top();
        q.pop();

        if (now % 10 - 1 >= 0) {
            q.push(now * 10 + now % 10 - 1);
        }
        q.push(now * 10 + now % 10);
        if (now % 10 + 1 < 10) {
            q.push(now * 10 + now % 10 + 1);
        }
    }

    cout << now;

    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
int main(){
    set<int> st;
    int a, b, c;
    cin >> a >> b >> c;
    st.insert(a);
    st.insert(b);
    st.insert(c);
    if(st.size() == 2){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }

ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

template<class T> ostream& operator<<(ostream& os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template <typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
	const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x)	x.begin(),x.end()

const int mod=1e9+7;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

struct compare{
	bool operator() (const int &a,const int &b) const{
		return a>b;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int n, m;
	cin >> n >> m;
	vi poss(n, 1), h(n);
	for(int i = 0; i < n; i++)
		cin >> h[i];
	for(int i = 0; i < m; i++){
		int a, b;
		cin >> a >> b;
		--a, --b;
		if(h[a] <= h[b])
			poss[a] = 0;
		if(h[b] <= h[a])
			poss[b] = 0;
	}
	int ans = 0;
	for(int i = 0; i < n; i++)
		ans += poss[i];
	cout << ans << endl;
}

Measured memory_bytes: 3988
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>
#include <map>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int n, m;
    cin >> n >> m;

    std::map<int,int> mp;
    for (int i=0; i<n; i++) {
        int k;
        cin >> k;
        for(int j=0; j<k; j++) {
            int t;
            cin >> t;
            mp[t]++;
        }
    }

    int c=0;
    for (int i=0; i<=m; i++) {
        if (mp[i] == n) c++;
    }

    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = []
a.append(10 ** 5)
b = input().split()
x = 0 #答え

for i in range(n-1):
  b[i] = int(b[i])
  if a[i] > b[i]:
    a[i] = b[i]
  a.append(b[i])

for i in range(n):
  x += a[i]

print(x)


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

int main(){
  string S;
  int K;
  cin>>K>>S;
  if(S.size()<=K){
    cout<<S<<endl;
  }
  else{
    for(int i=0; i<K; i++){
      cout<<S.at(i);
    }
    cout<<"..."<<endl;
  }
}

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

int main(){
    int n;
    cin >> n;
    vector<long long> in(5,0);
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        if(s[0] == 'M'){
            
            in[0]++;
        }

        if(s[0] == 'A'){

            in[1]++;
        }

        if(s[0] == 'R'){

            in[2]++;
        }

        if(s[0] == 'C'){
            in[3]++;
        }

        if(s[0] == 'H'){
            in[4]++;
        }
    }
    sort(in.begin(),in.end());
    /*for(int i=0;i<5;i++){
        cout <<in[i] <<endl;
    }*/
    long long ans = 0;
    if(in[0]!=0){
        for(int i=0;i<5;i++){
            for(int j=i+1;j<5;j++){
                for(int k=j+1;k<5;k++){
                    ans += in[i]*in[j]*in[k];
                }
            }
        }
    }
    else if(in[0]==0){
        ans += in[1]*in[2]*in[3] + in[1]*in[2]*in[4] +in[1]*in[3]*in[4]+in[2]*in[3]*in[4]; 
    }
    else if(in[1] == 0){
        ans += in[2]*in[3]*in[4];
    }
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
S = [int(i) for i in input()]
#array = []
#for i in S:
#  array.append(int(i))

N = len(S) #+,-の入りうる場所はN-1か所 

for i in range(2**(N-1)):
  ans = S[0]
  plmi=["-"]*(N-1)
  for j in range(N-1):
    if (i >> j) & 1:
      ans -= S[j+1]
    else:
      ans += S[j+1]
      plmi[j] = "+"
      
  if ans == 7:
    print(S[0],plmi[0],S[1],plmi[1],S[2],plmi[2],S[3],"=7", sep="")
    break

Measured memory_bytes: 3064
/*
 _    _    _______   _    _
| |  / /  |  _____| | |  / /
| | / /   | |       | | / /
| |/ /    | |_____  | |/ /
| |\ \    |  _____| | |\ \
| | \ \   | |       | | \ \
| |  \ \  | |_____  | |  \ \
|_|   \_\ |_______| |_|   \_\

*/
#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;


#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define right(x) x << 1 | 1
#define left(x) x << 1
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
#define mkp make_pair
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define y1 kekekek

#define fname ""

const ll ool = 1e18 + 9;
const int oo = 1e9 + 9, base = 1e9 + 7;
const ld eps = 1e-7;
const int N = 2e3 + 6;

int n, a[N], d[N][N * 10 * 2];

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

    #ifdef krauch
        freopen("input.txt", "r", stdin);
    #else
        //freopen(fname".in", "r", stdin);
        //freopen(fname".out", "w", stdout);
    #endif

    srand(time(0));

    cin >> n;
    int sum = 0;
    forn(i, 1, n) {
        cin >> a[i];
        sum += a[i];
    }

    d[0][0] = 1;
    int mn = oo;
    forn(kek, 1, 8) {
        random_shuffle(a + 1, a + n + 1);
        forn(i, 1, n) {
            forn(j, 0, 40000) {
                d[i][j] = 0;
                if (j + a[i] <= 40000) d[i][j] |= d[i - 1][j + a[i]];
                d[i][j] |= d[i - 1][max(j, a[i]) - min(j, a[i])];
            }
        }
        int ptr = 0;
        while (ptr <= 40000 && !d[n][ptr]) ++ptr;
        mn = min(mn, ptr);
    }

    cout << (sum - mn) / 2 + mn << "\n";

	return 0;
}


Measured memory_bytes: 313856
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin>>x;
  
  string s=to_string(x);
  int split=0;
  
  for(int i=0;i<s.size();i++) {
    int num= s.at(i)-'0';
    split+=num;
  }
  
  if(x%split==0) {
    cout<<"Yes"<<endl;
  }
  
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}
ll get(ll n, ll s){
    return 5001 * n + s;
}
vector<lpair> tree[300010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M,S;
    cin >> N >> M >> S;
    ll U[110], V[110], A[110], B[110];
    ll C[55], D[55];
    rep(i,0,M){
        cin >> U[i] >> V[i] >> A[i] >> B[i];
        U[i]--; V[i]--;
    }
    rep(i,0,N){
        cin >> C[i] >> D[i];
    }

    rep(i,0,N){
        rep(j,0,5001){
            if(j - C[i] >= 0) tree[get(i, j-C[i])].push_back({get(i, j), D[i]});
        }
        rep(j,0,5001){
            if(j+C[i] > 5000){
                tree[get(i, j)].push_back({get(i, 5000), D[i]});
            }
        }
    }
    rep(i,0,M){
        rep(j,0,5001){
            if(j - A[i] >= 0) tree[get(U[i], j)].push_back({get(V[i], j-A[i]), B[i]});
            if(j - A[i] >= 0) tree[get(V[i], j)].push_back({get(U[i], j-A[i]), B[i]});
        }
    }

    ll dist[300010] = {};
    rep(i,0,300000) dist[i] = INF;
    priority_queue pq([](lpair l1, lpair l2){return l1 > l2;}, vector<lpair>());
    if(S >= 5000){
        dist[get(0,5000)] = 0;
        pq.push({0, get(0,5000)});
    }else{
        dist[get(0,S)] = 0;
        pq.push({0, get(0,S)});
    }
    while(!pq.empty()){
        lpair l1 = pq.top();
        pq.pop();
        if(dist[l1.second] < l1.first) continue;
        for(auto &e: tree[l1.second]){
            if(dist[e.first] > dist[l1.second] + e.second){
                dist[e.first] = dist[l1.second] + e.second;
                pq.push(make_pair(dist[e.first], e.first));
            }
        }
    }

    rep(i,1,N){
        ll ans = INF;
        rep(j,0,5001){
            ans = min(ans, dist[get(i, j)]);
        }
        print(ans);
    }

    

}


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

int main()
{
  	string s;
  	cin >> s;
  	int i, j;
  	int result = 0;
    vector<char> sig(3);
  	for(i = 0; i < 16; i++)
  	{
    	if(i%8<4)
    	{
      		result += s.at(0)-'0'+s.at(1)-'0';
          	sig.at(0) = '+';
    	}
    	else
    	{
			result += s.at(0)-'0'-s.at(1)+'0';
          	sig.at(0) = '-';
    	}
    	if(i%4<2)
    	{
			result += s.at(2)-'0';
          	sig.at(1) = '+';
    	}
    	else
    	{
			result -= s.at(2)-'0';
          	sig.at(1) = '-';
    	}
    	if(i%2<1)
    	{
			result += s.at(3)-'0';
          	sig.at(2) = '+';
    	}
		else
		{
			result -= s.at(3)-'0';
          	sig.at(2) = '-';
        }
      	if(result == 7)
        {
          for(j = 0; j < 3; j++)
          {
			cout << s.at(j) << sig.at(j);
          }
          cout << s.at(3) << "=7" << endl;
          break;
        }
      result = 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
string s, t;
int dp[3002][3002], dp2[3002][3002];
int maxLength;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s >> t;
    // 1 indexed arrays are better because dealing with cases is easier
    s = ' ' + s;
    t = ' ' + t;
    int n = s.size() - 1;
    int m = t.size() - 1;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
        {
            dp[i][j] = max(dp[i-1][j], max(dp[i][j-1], (s[i] == t[j]) + dp[i-1][j-1]));
            /// I assigned 1, 2 or 3 because it's easier to reconstruct
            /// 1 => from (i, j) -> (i-1, j)
            /// 2 => from (i, j) -> (i, j-1)
            /// 3 => from (i, j) -> (i-1, j-1)
            if(dp[i-1][j] == dp[i][j])
                dp2[i][j] = 1;
            else
                if(dp[i][j-1] == dp[i][j])
                    dp2[i][j] = 2;
                else
                    dp2[i][j] = 3;
            if(dp[i][j] > maxLength)
                maxLength = dp[i][j];
        }
    int x = 0, y = 0;
    for(int i = 1; i <= n; ++i)
        for(int j = 1; j <= m; ++j)
            if(dp[i][j] == maxLength)
            {
                x = i;
                y = j;
                i = n+1, j = m+1;
                break;
            }
    string answer;
    while(x && y)
    {
        if(dp2[x][y] == 3)
            answer += s[x], --x, --y;
        else
            if(dp2[x][y] == 1)
                --x;
            else
                --y;
    }
    reverse(answer.begin(), answer.end());
    cout << answer;
    return 0;
}


Measured memory_bytes: 70656
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<map>
using namespace std;
int main() {
	int A;
	int B;
	int C;
	cin >> A >> B >> C;
	if (A + B + C >= 22)
		cout << "bust" << endl;
	else
		cout << "win" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
using namespace std;

int N,M,L,K,A,B,C,ans=0,cnt=0;
string S,T;
vector<int> P,Q;
vector<pair<int,int>> PP;
bool CAN=false;


int main(){
  cin>>N>>L;
  int a[N],t;
  REP(i,N){
    cin>>a[i];
    if(i>0){
      if(a[i]+a[i-1]>=L){
        t=i;
        CAN=true;
      }
    }
  }
  
  if(CAN){
    cout<<"Possible"<<endl;
    for(int i=1; i<t; ++i) cout<<i<<endl;
    for(int i=N-1; i>t; --i) cout<<i<<endl;
    cout<<t<<endl;
  }
  else cout<<"Impossible"<<endl;
  
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int a[4];
	cin >> a[0] >> a[1] >> a[2] >> a[3];
	sort(a, a + 4);
	if (*a == 1 && *(a+1) == 4 && *(a+2) == 7 && *(a+3) == 9)cout << "YES";
	else cout << "NO";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void){
  int n,len,i,j;
  char s[101000],t[101000];
  scanf("%d %s %s",&n,s,t);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(s[i+j]-t[j])break;
    }
    if(s[i+j]==0)break;
  }
  printf("%d",n+i);
  return 0;
}

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

int main(){
    int H,W;
    
    for(;;){
        cin >> H>> W ;
        if(H==0 && W==0)break;
        
        for(int i=0; i<H; i++){
            for(int j=0; j<W; j++){
                if((i+j)%2==0){
                    cout << "#";}
                else{cout << ".";}
            } cout << endl;
        } cout << endl;
        
    }return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=55,INF=1e9+1;
int n;
int x,d;
vector <int> son[N];
int a[N],size[N],*b=size,c[N],id[N];
void dfs(int x){
	size[x]=1;
	for (auto y : son[x]){
		dfs(y);
		size[x]+=size[y];
		a[x]=min(a[x]+a[y],INF);
	}
}
const int N3=N*N*N;
int dp[N3];
bool cmp(int i,int j){
	// a[i]/b[i] < a[j]/b[j]
	return (LL)a[i]*b[j]<(LL)a[j]*b[i];
}
int main(){
	n=read(),x=read(),d=read();
	a[1]=read(),c[1]=INF;
	For(i,2,n){
		a[i]=read();
		son[read()].pb(i);
		c[i]=d;
	}
	dfs(1);
	dp[0]=0;
	For(i,1,N3-1)
		dp[i]=INF;
	For(i,1,n){
		int v=min(c[i],50);
		For(j,0,6){
			int t;
			if (v>=(1<<j))
				t=1<<j,v-=t;
			else
				t=v,v=0;
			if ((LL)a[i]*t>=INF)
				continue;
			Fod(k,N3-1,0)
				if (dp[k]<INF)
					dp[k+t*b[i]]=min(dp[k+t*b[i]],dp[k]+a[i]*t);
			if (!v)
				break;
		}
	}
	Fod(i,N3-2,0)
		dp[i]=min(dp[i],dp[i+1]);
	For(i,1,n)
		id[i]=i,c[i]-=min(c[i],50);
	sort(id+1,id+n+1,cmp);
	int ans=-1,p=1;
	int sa=0,sb=0;
	Fod(i,N3-1,0){
		if (dp[i]>x)
			continue;
		int rem=x-dp[i];
		while (p<=n&&rem>=sa+(LL)a[id[p]]*c[id[p]]){
			sa+=a[id[p]]*c[id[p]];
			sb+=b[id[p]]*c[id[p]];
			p++;
		}
		if (p<=n)
			ans=max(ans,i+sb+(rem-sa)/a[id[p]]*b[id[p]]);
		else
			ans=max(ans,i+sb);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<stdio.h>
using namespace std;

main() {

  string number;
  int  i,c = 0, num, sum;

  while(1){
    sum = 0;
    c = 0;
    cin >> number;
    
    if(number[0] == '0') break;

    for(i = 0; number[i] != '\0'; i++){

	c++;

    }

    for(i = 0; i < c; i++){

	num = number[i] - '0';
	sum += num;

	

      
    }
    printf("%d\n",sum);
     
  }

}

Measured memory_bytes: 1180
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#define _USE_MATH_DEFINES
#include<cmath>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdint>
#include<unordered_map>
#include<sstream>
#include<boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;

typedef pair<int, int> P;

bool ps1(const P& element1, const P& element2)
{//first昇順
	return element1.first < element2.first;
}
bool ps2(const P& element1, const P& element2)
{//first降順
	return element1.first > element2.first;
}
bool ps3(const P& element1, const P& element2)
{//second昇順
	return element1.second < element2.second;
}
bool ps4(const P& element1, const P& element2)
{//second降順
	return element1.second > element2.second;
}

ll combination(ll n, ll r) {
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
int main() {
	int n;
	cin >>n;
	vector<int>a(n + 1), b(n),c(n);
	ll prev = 0;
	rep(i, n + 1) {
		cin >> a[i];
		prev += a[i];
	}
	rep(i, n) {
		cin >> b[i];
		if (a[i] <= b[i]) {
			a[i+1]=max(a[i + 1] - b[i] + a[i],0);
			a[i] = 0;

		}
		else {
			a[i] -= b[i];
		}
	}
	ll sum = 0;
	rep(i, n+1) {
		//cout << a[i] << endl;
		sum += a[i];
	}
	cout << prev - sum << endl;
	
}

Measured memory_bytes: 1408