akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define MOD 1000000007
#define ll long long
#define ld long double
#define int ll
#define pb push_back
#define ii pair<int,int>
#define llll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<ii>
#define vllll vector<llll>
#define ff first
#define ss second
#define INF 1000000000
#define HINF 1000000000000000
#define mem(a,b) memset(a,b,sizeof(a))
#define arrin(x,n) int x[n]; for(int o=0;o<n;o++) cin>>x[o]
#define arrout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define vecin(x,n); vi x;int hool; for(int o=0;o<n;o++) {cin>>hool; x.pb(hool);}
#define vecout(x,n) for(int o=0;o<n;o++) cout<<x[o]<<" "; cout<<endl
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<'='<<x<<endl
#define deb2(x,y) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<endl
#define deb3(x,y,z) cout<<#x<<'='<<x<<" "<<#y<<'='<<y<<" "<<#z<<'='<<z<<endl
#define debarr(arr,n) for(int o=0;o<n;o++) deb2(o,arr[o])
#define IO freopen("input.txt", "r", stdin); freopen("output.txt", "w+", stdout)
const double pi = 3.14159265358979323846;

ll power(ll a, ll b){//a^b
    ll res=1;
    //a=a%MOD;
    while(b>0){
        if(b&1)
		{res=(res*a);
		//res%=MOD;
		b--;}
        a=(a*a);
        //a%=MOD;
        b>>=1;
    }
    return res;
}
ll fermat_inv(ll y){return power(y,MOD-2);}
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
int C(int n,int k)
{
	int ans=1;
	if(k>n-k)
	k=n-k;
	for(int i=1;i<=k;i++)
	ans*=(n-i+1),ans/=i;
	return ans;
}

void solve()
{

	int i=0,j=0,k=0,m,n,p,sum=0,cnt=0;
	cin>>i>>j>>k>>m;
	cout<<max(max(i*k,i*m),max(j*k,j*m));
	
	
	
	
	
	 
}
int32_t main() {
    fast
    //IO;
	//cout<<fixed<<setprecision(6);
    //test
    {
        
        solve();
		
		      
    }
    return 0;
}
  

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

int main() {
  int N;
  cin>>N;
  if(N<1200){
    cout<<"ABC"<<endl;
  }
  else if(N<2800){
    cout<<"ARC"<<endl;
  }
  else{
    cout<<"AGC"<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	int a[n][m],b[m];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++) cin >> a[i][j];
	}
	for(int j=0;j<m;j++) cin >> b[j];
	for(int i=0;i<n;i++){
		int c = 0;
		for(int j=0;j<m;j++) c += a[i][j]*b[j];
		cout << c << endl;
	}
}

Measured memory_bytes: 1200
#include<stdio.h>

int main(void)
{
  char N[3];
  scanf("%s",&N);
  if(N[0] == '7' || N[1] == '7' || N[2] =='7'){
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 1620
#include <stdio.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <cassert>

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define MAXN 100001
#define MOD 1000000007
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define FAIL {printf("NO\n"); return 0;}

int N;
LL K;
LL A[MAXN];
int B[65];
//LL pw2[13];
LL ans;

LL f(LL T) {
	LL r = 0;
	for (int i = 0; i < N; i++)
		r += T ^ A[i];
	return r;
}

int main() {
#ifdef OJ
	freopen("input.txt", "rt", stdin);
	//freopen("output.txt", "wt", stdout);
#endif

	scanf("%d", &N);
	scanf("%lld", &K);
	for (int i = 0; i < N; i++) scanf("%lld", &A[i]);

	//pw2[0] = 1;
	//for (int i = 1; i <= 12; i++) pw2[i] = pw2[i-1] * 2;

	for (int k = 0; k < 64; k++) {
		for (int i = 0; i < N; i++) {
			if (A[i] & (1LL<<k)) B[k]++;
			else B[k]--;
		}
		//printf("%d %d\n", k, B[k]);
	}

	if (K == 0) {
		ans = A[0];
	} else if (K == 1) {
		if (B[0] < 0) ans = max(f(0), f(1));
	} else if (K > 1) {
		int k = 0;
		while((1LL<<k) <= K) k++;
		k--;

		assert(k >= 1);
		LL T = 0;
		for (int i = 0; i < k; i++)
			if (B[i] < 0) T |= (1LL<<i);

		ans = f(T);
		//printf("%lld\n", T);
		//printf("%lld\n", ans);

		T = 1LL<<k;
		k--;
		int flag = 1;
		for(; k >=0; k--) {
			if (flag) {
				if (K & (1LL<<k)) {
					if (B[k] < 0) T |= (1LL<<k);
					else flag = 0;
				} 
			} else {
				if (B[k] < 0) T |= (1LL<<k);
			}
		}

		//printf("%lld\n", T);
		ans = max(ans, f(T));
	}

	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    int d[N];
    REP(i, N){
        cin >> d[i];
    }

    sort(d, d+N);

    int ans = d[N/2] - d[N/2 - 1];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3960
for e in iter(input,'0 0'):
 r=int(e.split()[0])
 d=[int(''.join(x),2)for x in zip(*[input().split()for _ in[0]*r])]
 a=[]
 for i in range(1<<r):
  b=0
  for j in d:
   c=bin(i^j).count('1')
   b+=c if c>r//2 else r-c
  a+=[b]
 print(max(a))


Measured memory_bytes: 6820
#include<iostream>
#include<string>
using namespace std ;
using ll = long long ;

int main(){
    string s ; cin >> s ;
    ll k ; cin >> k ;
    ll cnt = 0 ;
    ll sub1 = 0 ;
    ll sub2 = 0 ;
    if(s.at(0)==s.at(s.size()-1)){
        bool ok = false ;
        for(int i=0;i<s.size();i++){
            if(s.at(i)==s.at(0)) sub1++ ;
            else{
                ok = true ;
                break ;
            }
        }
        if(!ok){
            cout << s.size()*k/2 << endl ;
            return 0 ;
        }else{
            for(int i=s.size()-1;i>=0;i--){
                if(s.at(i)==s.at(0)) sub2++ ;
                else break ;
            }
        }
    }
    for(int i=sub1+1;i<s.size()-sub2;i++){
        if(s.at(i)==s.at(i-1)){
            s.at(i) = '0' ;
            cnt++ ;
        }
    }
    cout << sub1/2+sub2/2+(sub1+sub2)/2*(k-1)+cnt*k << endl ;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include "time.h"
#include "unistd.h"
#include "string.h"
#include <math.h>
int ans=0;
int main(int argc, char* argv[]){
	long long int a, b = 1, c = 1;
	scanf("%lld", &a);
	for(;a > 1;) {
		a /= 2;
		b *= 2;
		c += b;
	}
	printf("%lld\n",c);
	return 0;
}


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

long long divis(long long x, long long y, long long z) {
	long long p = y / z;
	long long q = (x + z - 1) / z;
	long long r = p - q+1;
	return r;
}

int main() {
	long long a, b, c;
	cin >> a >> b >> c;
	long long d = divis(a, b, c);
	cout << d << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    vector<bool> win(k+1, false);
    for (int j = 1; j <= k; ++j) {
        for (int i = 0; i < n; ++i) {
            if(j >= v[i]) win[j] = win[j] | (!win[j-v[i]]);
        }
    }
    cout << (win[k] ? "First" : "Second") << "\n";
    return 0;
}


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

int main()
{
	int n,m,X,Y;
	cin >> n >> m >> X >> Y;
	vector<int> x(n);
	for(int i = 0; i < n; i++){
		cin >> x[i];
	}
	vector<int> y(m);
	for(int i = 0; i < m; i++){
		cin >> y[i];
	}

	sort(x.begin(),x.end());
	sort(y.begin(),y.end());

	if(x[n-1] < y[0] && x[n-1] < Y && y[0] > X){
		cout << "No War\n";
	}else{
		cout << "War\n";
	}
	
	return 0;
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        GoodINteger solver = new GoodINteger();
        solver.solve(1, in, out);
        out.close();
    }

    static class GoodINteger {
        public void solve(int testNumber, FastReader in, PrintWriter out) {
            char[] s = in.next().toCharArray();
            if (s[0] == s[1] && s[1] == s[2]) {
                out.println("Yes");
                return;
            }
            if (s[1] == s[2] && s[2] == s[3]) {
                out.println("Yes");
                return;
            }
            out.println("No");
        }

    }

    static class FastReader {
        BufferedReader reader;
        StringTokenizer st;

        public FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

    }
}



Measured memory_bytes: 21332
#include <iostream>
#include <string.h>
using namespace std;

int main () {
  int n;
  cin >> n;
  string h;
  cin >> h;
  for (int i = 0; i < h.size(); i++) {
    h[i] = (char) ((h[i] - 'A' + n) % 26 + 'A');
    cout << h[i]; 
  }
  cout << endl;
}

Measured memory_bytes: 256
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    way = [[] for i in range(n)]
    for _ in [0]*(n-1):
        a,b = map(int,ipt().split())
        way[a].append(b)
        way[b].append(a)
    rt = -1
    for i in range(n):
        if len(way[i]) > 2:
            rt = i
            break

    def dp(pp,np):
        sum = 0
        n0 = 0
        for i in way[np]:
            if i == pp:
                continue
            tmp = dp(np,i)
            sum += tmp
            if tmp == 0:
                n0 += 1
        if n0 > 1:
            sum += n0-1
        return sum

    if rt == -1:
        print(1)
        exit()
    else:
        print(dp(-1,rt))

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 80580
#include <bits/stdc++.h>
using namespace std;
#define pb 		push_back
#define mp 		make_pair
#define pii 	pair<int,int>
#define vi 		vector<int>
#define vii 	vector<vector<int>>;
#define vpii 	vector<pii>
#define ar 		array
#define SZ(x) 	((int)(x.size()))
#define fi 		first
#define se 		second


#define TRvi(a,it)   for(auto (it)=(a).begin(),it!=(a).end();it++) 	
#define FORV (a,x)   for(auto (x):(a))
#define FOR(i,n)	 for(int (i)=0;(i)<(n);++(i))
#define FORI(i,n) 	for(int (i)=1;(i)<=(n);++(i))
#define REP(i,a,b) for(int (i)=(a);(i)<=(b);++i)
#define REPD(i,a,b) for(int (i)=(a); (i)>=(b);--i)

#define IN(x,y) 	((y).find((x))!=(y).end())
#define ALL(t) 		t.begin(),t.end()

#define REMAX(a,b) (a)=max((a),(b));
#define REMIN(a,b) (a)=min((a),(b));
#define DBG cerr << "debug here" << endl;
#define DBGV(vari) cerr << #vari<< " = "<< (vari) <<endl;
#define all(x) (x).begin(), (x).end()
#define str(s) to_string(s);

typedef long long ll;

const int INF = 1e9;

const int MINV = 1;
const int MAXV = 10;



void a_m(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}
//type the code here






int32_t main()
{
	//type your code here
	a_m();
	int T,N,X;
	cin>>N>>X>>T;
	int count=N/X;
    if(N%X!=0){
		cout<<(count+1)*T<<endl;
	}else{
		cout<<(count)*T<<endl;
	}
	
    return 0;
    
}



Measured memory_bytes: 3648
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef long long ll;
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
ll cnt[10][10];

class DHandstand2 {
public:
	void solve(std::istream& cin, std::ostream& cout) {

		int n;cin >> n;
		ll ans = 0;
		for(int i = 0;i < 10;i++)for(int j = 0;j < 10;j++)cnt[i][j] = 0;
		for(int i = 1;i <= n;i++){
			string s = to_string(i);
			int p = s[0] - '0',q = s[s.size()-1] - '0';
			//cout << p << " " << q << endl;
			cnt[p][q]++;
			//if(p == q)ans--;
		}
		for (int i = 0; i < 10; ++i)
		{
			for (int j = 0; j < 10; ++j)
            {
			    //cout << cnt[i][j] << " ";
				ans += cnt[i][j] * cnt[j][i];
			}
			//cout << endl;
		}
		cout << ans << endl;
	}
};


int main() {
	DHandstand2 solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
#define mo 1000000007
using namespace std;
int main(){
    int r,c;
    cin>>r>>c;
    vector <string> v(r);
    for(int i=0; i<r;i++){
        cin>>v[i];
    }
    vector <vector <int> > dp(r, vector <int>(c,0));
    for(int i=0; i<c;i++){
        if(v[0][i]=='#'){
            break;
        }
        else{
            dp[0][i]=1;
        }
    }
    for(int i=0; i<r;i++){
        if(v[i][0]=='#'){
            break;
        }
        else{
            dp[i][0]=1;
        }
    }
    for(int i=1; i<r;i++){
        for(int j=1; j<c;j++){
            if(v[i][j]=='#'){
                continue;
            }
            else{
                if(v[i-1][j]!='#'){
                    dp[i][j]=dp[i-1][j]%mo;
                }
                if(v[i][j-1]!='#'){
                    dp[i][j] = (dp[i][j]+dp[i][j-1])%mo;
                }
            }
        }
    }
    cout<<dp[r-1][c-1]<<endl;
}


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

int main(){
    int x,y;
    cin >> x >> y;
    if((4*x-y)%2==0 && 0<=(4*x-y) && (4*x-y)<=2*x){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3532
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e4+10;
int n,c[maxn],ans,u,v,b[maxn],pt=1;
vector<int> a[maxn];
vector<pair<int,int>>edge;
void dfs(int nod,int pa){
    b[nod]=c[pt];
    pt++;
    for(int i:a[nod]){
        if(i!=pa){
            dfs(i,nod);
        }
    }
    return;
}


int main(){
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        scanf("%d%d",&u,&v);
        a[u].push_back(v);
        a[v].push_back(u);
        edge.push_back(make_pair(u,v));
    }
    for(int i=1;i<=n;i++)
        scanf("%d",&c[i]);
    sort(c+1,c+1+n);
    reverse(c+1,c+1+n);
    dfs(1,0);
    for(auto i:edge){
        ans+=min(b[i.first],b[i.second]);
    }
    printf("%d\n",ans);
    for(int i=1;i<=n;i++)
        printf("%d ",b[i]);
}


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

vector<int> x,y,s;

int tax(int p ,int x){
  return (int)floor((p * (100+x) / 100));
}

void calc(int n){
  int ans = 0;
  for(int i = 1; i < s[n]; i++){
    for(int j = i; j < s[n]; j++){
      if(tax(i,x[n]) + tax(j,x[n]) == s[n]){
        ans = max(ans, tax(i, y[n]) + tax(j, y[n]));
      }
    }
  }
  cout << ans << endl;
}

int main(){
  int tmp_x,tmp_y,tmp_s;
  while(true){
    cin >> tmp_x >> tmp_y >> tmp_s;
    if(tmp_x == 0 && tmp_y == 0 && tmp_s == 0)
      break;
    x.push_back(tmp_x);
    y.push_back(tmp_y);
    s.push_back(tmp_s);
  }
  for(int i = 0; i < x.size(); i++)
    calc(i);
  return 0;
}

Measured memory_bytes: 3156
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, std::vector<std::string> S){
  set<string> x;
  for(ll i=0; i<N; i++)
    x.insert(S[i]);
  std::cout << x.size() << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  std::vector<std::string> S(N);
  for(int i = 0 ; i < N ; i++){
    std::cin >> S[i];
  }
  solve(N, std::move(S));
  return 0;
}



Measured memory_bytes: 19996
import java.util.Scanner;

public class Main {

    public static int Max;

    public static void main(String[] args)
    {
        Scanner scan =new Scanner(System.in);
	    int x=scan.nextInt();
        int y=scan.nextInt();

        Common_Divisir(x,y);

        System.out.println(Max);
    }

    public static void Common_Divisir(int a, int b)
    {
        int c=a%b;
        if(c!=0){
            a=b;
            b=c;
            Common_Divisir(a,b);
        }
        if(c==0){
            Max=b;
        }
    }
}

Measured memory_bytes: 26208
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException{
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		char[] str = br.readLine().toCharArray();
		
		for(int i = str.length - 1; i >= 0; i--){
			System.out.print(str[i]);
		}
		System.out.print('\n');
	}

}


Measured memory_bytes: 24108
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int D = sc.nextInt();
        if(N % (2*D +1) == 0){
            System.out.println(N / (2*D +1));
        } else {
            System.out.println((N / (2*D +1)) +1);
        }

    }

}


Measured memory_bytes: 22996
#coding:utf-8
 
s = str(input())
string  = list(s)
string_unique = list(set(string))
 
#print(string_unique)
 
if len(string_unique) == 2:
    if string.count(string_unique[0]) == 1 or string.count(string_unique[0]) == 3:
        print("No")
    else:
        print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<cstdio>
#include<algorithm>
#include<vector>
#define ll long long
using namespace std;
int n;
vector<ll> vt;
ll ch[16];
ll x;
int main()
{
	ch[0] = 1;
	for (int i = 1; i <= 14; i++)
		ch[i] = ch[i - 1] * 10;
	for (int i = 1; i < 10; i++)
		vt.push_back(i);
	for (int i = 1; i <= 14; i++)
	{
		for (int xx = 1; xx <= 9; xx++) {
			ll sum = ch[i]*xx;
			ll Ssum = xx;
			for (int y = 0; y < i; y++)
			{
				for (int z = 0; z < 9; z++)
				{
					if (sum <= Ssum*ch[y]) {
						vt.push_back(sum);
					}
					sum += ch[y];
					Ssum++;
				}
				if (sum <= Ssum*ch[y+1]) {
					vt.push_back(sum);
				}
			}
		}
	}
	sort(vt.begin(), vt.end());
	vt.erase(unique(vt.begin(), vt.end()), vt.end());
	scanf("%lld", &x);
	for (int i = 0; i < x; i++)
		printf("%lld\n", vt[i]);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

void max_self(ll& a, ll b) {
    a = max(a, b);
}

// O(n * W)

int main() {
  int n,W;
  cin >> n >> W;
  vector<ll> dp(W+1);
  for(int i=0;i<n;++i){
	int val;
	ll weight;
	cin >> weight >> val;  
	for(int left_weight = W - weight;left_weight>=0;--left_weight){
		max_self(dp[left_weight+weight],dp[left_weight] + val);
	} 
  }  
  ll answer = 0;
  for(int i=0;i<W+1;i++){
	   max_self(answer,dp[i]); 
  }
  cout << answer;
}










Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n,m;
  cin >> n >> m;
  vector<ll> x(m), dif(m-1);
  rep(i,m) cin >> x[i];
  if (n >= m) {
    cout << 0 << endl;
    return 0;
  }
  sort(all(x));
  rep(i,m-1) {
    dif[i] = x[i+1] - x[i];
  }
  sort(all(dif), greater<ll>());
  ll ans = x[m-1] - x[0];
  rep(i,n-1) {
    ans -= dif[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

void input(vector<ll> &pt){
  rep(i, 10){
    rep(j, i+1){
      string s;
      rep(k, i){
        if(i-j <= k) s.push_back('1');
        else s.push_back('0');
      }
      do{
        bool flag = true;
        rep(i, s.size()-1){
          if(s.at(i) == s.at(i+1) && s.at(i) == '1'){
            flag = false;
            break;
          }
        }
        if(flag == true){
          pt.at(i)++;
        }
      }while(next_permutation(s.begin(), s.end()));
    }
  }
}

mint fanc(vector<ll> &pt, mint now, int j, int w, int mode){
  mint ad1 = now;
  int lc, rc;
  lc = j - 1;
  rc = w - j - 2;
  if(mode == 0) lc--;
  if(mode == 2) rc--;
  if(lc > 0) ad1 *= pt.at(lc);
  if(rc > 0) ad1 *= pt.at(rc);
  return ad1;
}

int main(){
  int h, w, k;
  cin >> h >> w >> k;
  vector<mint> dp(w, 0);
  vector<ll> pt(10, 0);
  input(pt);
  dp.at(0) = 1;
  rep(i, h){
    vector<mint> nxdp(w, 0);
    rep(j, w){
      mint now = dp.at(j);
      nxdp.at(j) += fanc(pt, now, j, w, 1);
      if(j - 1 >= 0) nxdp.at(j-1) += fanc(pt, now, j, w, 0);
      if(j + 1 < w) nxdp.at(j+1) += fanc(pt, now, j, w, 2);
    }
    dp = nxdp;
    // rep(j, w){
    //   cerr << dp.at(j).x << " ";
    // }
    // cerr << endl;
  }
  cout << dp.at(k-1).x << endl;
  return 0;
}

Measured memory_bytes: 256
s = input()
i=len(s)-1
while i > 0:
    if i<4:
        print("NO")
        exit()
    check=s[i-2:i+1]

    if check == "eam": # dream
        if s[i-4:i+1] == "dream":
            i-=5
            continue
    elif check == "mer": # dreamer
        if i > 5 and s[i-6:i+1] == "dreamer":
            i-=7
            continue
    elif check == "ase": # erase
        if s[i-4:i+1] == "erase":
            i-=5
            continue
    elif check == "ser": # eraser
        if i > 4 and s[i-5:i+1] == "eraser":
            i-=6
            continue

    print("NO")
    exit()

print("YES")

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


int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    vector<ll> A(4);
    A[0] = a * c;
    A[1] = a * d;
    A[2] = b * c;
    A[3] = b * d;
    sort(A.begin(),A.end());
    cout << A[3] << endl;
}

Measured memory_bytes: 3628
import sys
input = sys.stdin.readline
N, W = map(int, input().split())
b = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(N):
  for j in range(W + 1):
    if j + b[i][0] <= W:
      dp[i + 1][j + b[i][0]] = max(dp[i][j] + b[i][1], dp[i + 1][j + b[i][0]])
    dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
print(max(dp[-1]))

Measured memory_bytes: 120940
#include <stdio.h>
#include <stdlib.h>
#define MAX 1000

int top=0;
int S[MAX];

void push(int x);
int pop();

int main(){
	int a,b;
	char str[MAX];
	while(scanf("%s",str)!=EOF){
		if(str[0]=='+'){
			a=pop();
			b=pop();
			push(b+a);
		}else if(str[0]=='-'){
			a=pop();
			b=pop();
			push(b-a);
		}else if(str[0]=='*'){
			a=pop();
			b=pop();
			push(b*a);
		}else{
			push(atoi(str));
		}
	}
  printf("%d\n",pop());
  return 0;
}

void push(int x){
	top++;
	S[top]=x;
}

int pop(){
	top--;
	return S[top+1];
}

Measured memory_bytes: 1820
#include <stdio.h>
#include <string.h>
#include <vector>
#define maxn 111
using namespace std;

int mp[maxn][maxn];
char s[maxn][maxn];
int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
char dd[4][5] = {"E","S","W","N"};
int dic[maxn][maxn][4];

struct I
{
    int x, y, d;
};
vector <I> vec;

int H, W;
long long L;

int check(int x, int y)
{
    if(x > 0 && x <= H && y > 0 && y <= W && mp[x][y] == 1)
    {
        return 1;
    }
    return 0;
}
void step(int x, int y, int sd)
{

    I tmp;
    tmp.x = x;
    tmp.y = y;
    tmp.d = sd;
    vec.push_back(tmp);

    if (dic[x][y][sd] == 1)
    {
        return ;
    }

    dic[x][y][sd] = 1;

    int xx, yy;
    while (1)
    {
        xx = x + dir[sd][0];
        yy = y + dir[sd][1];
        if (check(xx,yy)){
            step(xx,yy,sd);
            break;
        }
        sd = (sd + 1) % 4;
    }
    return ;
}

int main()
{
    while(scanf("%d%d%lld", &H, &W, &L))
    {
        if(H == 0 && W == 0 && L == 0)
        {
            break ;
        }
        memset(mp, 0, sizeof(mp));
        memset(s, 0, sizeof(s));
        for(int i = 0; i < H; i++)
        {
            scanf("%s", s[i]);
        }
        int si, sj, sdir;
        for(int i = 0; i < H; i++)
        {
            for(int j = 0; j < W; j++)
            {
                if(s[i][j] == '#')
                {
                    mp[i + 1][j + 1] = 0;
                }
                else
                {
                    mp[i + 1][j + 1] = 1;
                    if(s[i][j] != '.')
                    {
                        si = i + 1;
                        sj = j + 1;
                        if(s[i][j] == 'E')
                        {
                            sdir = 0;
                        }
                        else if(s[i][j] == 'S')
                        {
                            sdir = 1;
                        }
                        else if(s[i][j] == 'W')
                        {
                            sdir = 2;
                        }
                        else
                        {
                            sdir = 3;
                        }
                    }
                }
            }
        }
        memset(dic, 0, sizeof(dic));

        //dic[si][sj][sdir] = 1;
        int num = 0;
        vec.clear();
        step(si, sj, sdir);

        int sz = vec.size();
        int t = 0;

        //puts("**************************");
        //printf("%d\n",sz);

        for (int i=0; i<sz; i++)
        {
            if (vec[i].x  == vec[sz-1].x && vec[i].y == vec[sz -1].y && vec[i].d == vec[sz-1].d)
            {
                t = i;
                break;
            }
        }

        int s = sz - t - 1;
        int ans = 0;


        //printf("%d %d\n",s, t);
        if (L < t)
        {
            ans = (int)L;
        }
        else
        {
            ans = (int)t + (int)((L - t) % s);
        }

        //printf("%d\n",ans);
        //int ansi = vec[L].x, ansj = vec[L].y, ansd = vec[L].d;


        printf("%d %d %s\n", vec[ans].x, vec[ans].y, dd[vec[ans].d]);
    }
    return 0;
}

Measured memory_bytes: 1676
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T, class U>T rem(T a, U b) { return a - b*floor(a/b); }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

bool eq(string s, string t)
{
        if (s < t) return false;
        ll flg = true;
        ll len = min(len(s), len(t));
        rep(i, 0, len) {
                if (s[i] != t[i]) flg = false;
        }
        return flg;
}

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

        vector<string> list{"dreameraser", "dreamerase", "dreamer", "dream", "eraser", "erase"};

        while (true) {
                bool flg = false;
                rep(i, 0, len(list)) {
                        if (eq(S, list[i])) {
                                S.erase(S.begin(), S.begin()+len(list[i]));
                                flg = true;
                                //cout << S << endl;
                                break;;
                        }
                }
                if (! flg) break;
        }
        if (len(S) == 0) {
                cout << "YES" << endl;
        } else {
                cout << "NO" << endl;
        }

}






Measured memory_bytes: 512
#include<iostream>
using namespace std;
int main(){
  char c;
  cin >> c;
  if(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'){
  cout << "vowel" << endl; 
  }
  else{
  cout << "consonant" << endl;
  }
  

}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
	long long n, k, r, s, p;
	string str;
	cin >> n >> k >> r >> s >> p;
	cin >> str;

	long long ans = 0;
	vector<bool> vec(n);

	for (int i = 0; i < k; i++) {
		vec[i] = true;
	}
	for (int i = k; i < str.length(); i++) {
		if (str[i - k] != str[i]) {
			vec[i] = true;
		}
		else {
			if (vec[i - k]) {
				vec[i] = false;
			}
			else {
				vec[i] = true;
			}
		}
	}

	for (int i = 0; i < str.length(); i++) {
		switch (str[i]){
		case 'r':
			if (vec[i]) {
				ans += p;
			}
			break;
		case 's':
			if (vec[i]) {
				ans += r;
			}
			break;
		case 'p':
			if (vec[i]) {
				ans += s;
			}
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
n = int(input())
A = list(map(int, input().split()))

csum = [0] * n
csum[0] = A[0] 
for i in range(1, n):
	csum [i] = csum[i - 1] + A[i]

mind = 1 << 40
sumA = csum[-1]
for i in range(n):
	diff = abs(sumA - 2 * csum[i])
	mind = min(mind, diff)

print(mind)

Measured memory_bytes: 89164
#include <iostream>
#include<algorithm>
#include<stdio.h>
#include<string.h>
#include<vector>
using namespace std;
#define FOR(i,a) for(int i=0;i<a;i++)
#define MP make_pair
const int MAXN = 2e4;
int main()
{
    int health, moves;cin >> health >> moves;
    vector<pair<int, int>>v(moves, MP(0, 0));
    FOR(i, moves) {
        cin >> v[i].first >> v[i].second;
    }

    //cout << (double)least << leastdam << leastcost << "\n";
    int dp[MAXN];
    for (int i = 0;i < MAXN;i++) {
        dp[i] = 1073709056;
    }
    dp[0] = 0;
    for (int i = 1;i < MAXN;i++) {
        for (auto x : v) {
            if (x.first <= i) {
                dp[i] = min(dp[i], dp[i - x.first] + x.second);
            }
        }
    }
    int ans = dp[health];
    for (int i = health;i < MAXN;i++) {
        ans = min(ans, dp[i]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 384
int main(){
int a, b, c;
int t;
scanf("%d%d%d", &a, &b, &c);

if(a > b) {
 t=a;
 a=b;
 b=t;
}

if(a > c) {
 t=a;
 a=c;
 c=t;
}

if(b > c) {
 t=b;
 b=c;
 c=t;
}

printf("%d %d %d\n", a, b, c);
return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
using namespace std;
struct node
{
	vector<int>Ve;
}N[200000+10];
int symbol[200000+10];
int flag=0;
void dfs(int now,int end,int sum)
{
	
	symbol[now]=1;
	if(flag==1)
		return ;
	if(sum==2 )
	{
		if(now==end)
			flag=1;
		return ;
	}
	for(int i=0;i<N[now].Ve.size();i++)
	{
		if(symbol[N[now].Ve[i]]==0)
			dfs(N[now].Ve[i],end,sum+1);
	}
	symbol[now]=1;
}
int main()
{
	int N_,M;
	scanf("%d %d",&N_,&M);
	while(M--)
	{
		int a1,a2;
		scanf("%d%d",&a1,&a2);
		N[a1].Ve.push_back(a2);
		N[a2].Ve.push_back(a1);
	}
	dfs(1,N_,0);
	if(flag)
		printf("POSSIBLE");
	else
		printf("IMPOSSIBLE");
	printf("\n");
	return 0;
}

Measured memory_bytes: 12784
using System;
using System.Linq;

namespace abc140_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var BL = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();

            int r = BL[0];
            int bf = BL[0];

            for (int i = 1; i < N - 1; i++) 
            {
                if (BL[i] < bf) 
                    r += BL[i];
                else 
                    r += bf;

                bf = BL[i];
            }
            
            r += bf;

            Console.WriteLine(r);
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <time.h>
#include <complex>
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF (1<<21)
#define rep(i,n) for(int (i)=0;(i)<n;(i)++)
#define Rrep(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=a;i<n;i++)
#define SORT(v) sort((v).begin(),(v).end())
#define TEMP(type,x,y) do {temp temp=x,x=y,y=temp}while(0)

int main() {

	string s, t;
	cin >> s;
	cin >> t;

	int count = 0;
	rep(i, s.size()) {
		if (s[i] == t[i]) count++;
	}

	cout << count << endl;

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
int main()
{
    string S;
    int N,difference;
    cin >> N >> S;
    for (int i = 0; i < S.size(); i++)
    {
        S[i] += N;
        if(S[i] >'Z'){
            difference = S[i] - 'Z';
            S[i] = 'A' + difference - 1;
        }
    }
    cout << S << endl;
}

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

struct edge{
    int y,c,w;
    edge(){y=c=w=0;}
    edge(int _y,int _c,int _w){y=_y;c=_c;w=_w;}
};

int n;
vector<edge> g[100005];
int dep[100005];
int fa[100005][17];

void dfs4lca(int x,int p,int cd){
    fa[x][0]=p;
    dep[x]=cd;
    for(edge &e:g[x])if(e.y!=p){
        dfs4lca(e.y,x,cd+1);
    }
}

void init4lca(){
    dfs4lca(1,-1,0);
    for(int j=0;j<16;j++){
        for(int i=1;i<=n;i++){
            if(fa[i][j]==-1)fa[i][j+1]=-1;
            else fa[i][j+1]=fa[fa[i][j]][j];
        }
    }
}

int lca(int x,int y){
    if(dep[x]<dep[y])swap(x,y);
    for(int i=16;i>=0;i--){
        if(fa[x][i]!=-1&&dep[fa[x][i]]>=dep[y])x=fa[x][i];
    }
    if(x==y)return x;
    for(int i=16;i>=0;i--){
        if(fa[x][i]!=fa[y][i]){
            x=fa[x][i];
            y=fa[y][i];
        }
    }
    return fa[x][0];
}

struct query{
    int id,x,y;
    query(){}
    query(int _id,int _x,int _y){
        id=_id;x=_x;y=_y;
    }
};

vector<query> qs[100005];
int sum[100005],cnt[100005],ans[300005];

void dfs(int x,int p,int d){
    for(query &q:qs[x]){
        ans[q.id]=d+cnt[q.x]*q.y-sum[q.x];
    }
    for(edge &e:g[x])if(e.y!=p){
        sum[e.c]+=e.w;
        cnt[e.c]++;
        dfs(e.y,x,d+e.w);
        sum[e.c]-=e.w;
        cnt[e.c]--;
    }
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int q;
    cin>>n>>q;
    for(int i=1;i<n;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        g[a].push_back(edge(b,c,d));
        g[b].push_back(edge(a,c,d));
    }
    init4lca();
    for(int i=1;i<=q;i++){
        int x,y,u,v,anc;
        cin>>x>>y>>u>>v;
        anc=lca(u,v);
        qs[anc].push_back(query(i,x,y));
        qs[u].push_back(query(i+q,x,y));
        qs[v].push_back(query(i+q+q,x,y));
    }
    dfs(1,-1,0);
    for(int i=1;i<=q;i++){
        cout<<-ans[i]-ans[i]+ans[i+q]+ans[i+q+q]<<endl;
    }

    return 0;
}

Measured memory_bytes: 26808
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using uint = unsigned int;
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }

int main(){
    int n, m;
    scanf("%d %d", &n, &m);
    vector<vector<pair<int, int>>> rds(n + 1);
    for(int i = 0; i < m; i++){
        int l, r, d;
        scanf("%d %d %d", &l, &r, &d);
        rds[l].emplace_back(r, d);
        rds[r].emplace_back(l, -d);
    }
    vector<char> checked(n + 1);
    vector<int> poss(n + 1, -M);
    bool ok = true;
    for(int i = 1; i <= n && ok; i++){
        printd(checked);
        if(checked[i]){ continue; }
        queue<int> q;
        checked[i] = true;
        q.push(i);
        while(ok && q.size()){
            int idx = q.front(); q.pop();
            if(poss[idx] == -M){
                poss[idx] = 0;
            }
            for(auto& rd : rds[idx]){
                int pos = poss[idx];
                int i2 = rd.first;
                int p2 = pos + rd.second;
                if(!checked[i2]){
                    checked[i2] = true;
                    q.push(i2);
                }
                if(poss[i2] == -M){
                    poss[i2] = p2;
                }else{
                    if(poss[i2] != p2){
                        ok = false;
                    }
                }
            }
            printd(poss);
        }
    }
    cout << (ok ? "Yes" : "No") << '\n';
}


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

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

    int a, b, c;
    cin >> a >> b >> c;
    
    if(a == b and b == c){
        if(a % 2) cout << 0 << endl;
        else cout << -1 << endl;
        return 0;
    }

    int cnt = 0;
    while(!(a % 2) and !(b % 2) and !(c % 2)){
        int x = a, y = b, z = c;
        a = y / 2 + z / 2;
        b = x / 2 + z / 2;
        c = x / 2 + y / 2;
        cnt++;
    }
    cout << cnt << endl;

    return 0;
}

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

#ifdef ENABLE_LL
#define int long long
#endif

#ifdef ENABLE_LL
#define I "%lld"
#define II "%lld%lld"
#define III "%lld%lld%lld"
#define IIII "%lld%lld%lld%lld"
#define IN "%lld\n"
#define IIN "%lld%lld\n"
#define IIIN "%lld%lld%lld\n"
#define IIIIN "%lld%lld%lld%lld\n"
#else
#define I "%d"
#define II "%d%d"
#define III "%d%d%d"
#define IIII "%d%d%d%d"
#define IN "%d\n"
#define IIN "%d%d\n"
#define IIIN "%d%d%d\n"
#define IIIIN "%d%d%d%d\n"
#endif

#ifdef __LOCALE__
#define see(a) std::cout << #a << "=" << a << std::endl
#define ses(a) std::cout << #a << "=" << a << " " 
#else
#define see(a) //std::cout << #a << "=" << a << std::endl
#define ses(a)
#endif
#define repe(a,b) for (int a=0;a<(int)b.size();a++)
#define rep(i,n) for (int i=0;i<n;i++)
#define repa(i,n) for (int i=1;i<=n;i++)
#define repi(i,a,b) for (int i=a;i<=b;i++) 
#define repb(i,a,b) for (int i=a;i>=b;i--)
typedef pair < int , int > pr;
typedef pair < pr  , int > prr;
#define L first
#define R second
template <class T> inline bool checkMin(T& a , T b) { return (a > b ? a=b,1 : 0); }
template <class T> inline bool checkMax(T& a , T b) { return (a < b ? a=b,1 : 0); }
class Scanner{ private: istream& ist;public: Scanner(istream& in):ist(in){} string next(){ string r; ist >> r; return r; } string nextLine(){ string r; getline(ist,r); return r; } int nextInt(){ int r; ist >> r; return r; } double nextDouble(){ double r; ist >> r; return r; }};
Scanner sc(cin);

const int M = 1e18;
int n, a, b, c, d;

map < int , int > mp;
void init() {
    scanf(I,&n);
    scanf(IIII,&a,&b,&c,&d); 
    mp.clear();
}

int get(int u) {
    if (u<=0) return 0;
    if (mp.count(u)) return mp[u];
    int res = 0x3f3f3f3f3f3f3f3f;
    if (u <= 2e9) checkMin(res, d*u);
    int x = u/2, x0=x*2, x1=(x+1)*2;
    if (x   != u) checkMin(res, get(x  ) +a+d*(u-x0));
    if (x+1 != u) checkMin(res, get(x+1) +a+d*(x1-u));
    int y = u/3, y0=y*3, y1=(y+1)*3;
    if (y   != u) checkMin(res, get(y  ) +b+d*(u-y0));
    if (y+1 != u) checkMin(res, get(y+1) +b+d*(y1-u));
    int z = u/5, z0=z*5, z1=(z+1)*5;
    if (z   != u) checkMin(res, get(z  ) +c+d*(u-z0));
    if (z+1 != u) checkMin(res, get(z+1) +c+d*(z1-u));
    return mp[u]=res;
}

void solve() {
    printf(IN,get(n));
}

#ifdef ENABLE_LL
#undef int
#endif
int main(){
    int T; scanf("%d",&T);
    while (T--) {
        init();
        solve();
    }
    return 0;
}


Measured memory_bytes: 4936
import math
def mid(a,b,c):
  if (a<=b and b<=c) or (c<=b and b<=a): # a<b<c or c<b<a
    return b
  elif (b<=a and a<=c) or (c<=a and a<=b): # b<a<c or c<a<b
    return a
  elif (a<=c and c<=b) or (b<=c and c<=a): # b<c<a or a<c<b
    return c
A,B,C = map(int,input().split())
middle = mid(A,B,C)
minimum = min(A,B,C)
m = max(A,B,C)
ans = m - middle
minimum += max(A,B,C) - middle
if (m - minimum)%2==0:
  ans += (m - minimum)//2
else:
  ans += math.ceil((m - minimum)/2)+1
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<Pll> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

int main(){
  vll box(3);
  ll N;
  cin >> box[0] >> box[1] >> box[2] >> N;

  sort(all(box));
  ll ans = 0;

  erep(i,0,N){
    erep(j,0,N){
      if((N - (box[0]*i + box[1]*j)) < 0) break;
      if((N - (box[0]*i + box[1]*j)) % box[2] == 0){
        ans++;
      }
    }
  }

  print(ans);

  

 return 0;
}


Measured memory_bytes: 256