akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//  F - LCS
//
//  Created by Nishant Dhankhar on 16/01/19.
//  Copyright © 2019 Nishant Dhankhar. All rights reserved.
//
#include <bits/stdc++.h> //REMEMBER TO REMOVE '/'
#include <iostream>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define RE(i,n) for(int i=1;i<=n;i++)
#define ss second
#define ff first
#define vi vector<int>

int dp[3003][3003];
//string dp2[3003][3003];
signed main() {
    string s,t;
    cin>>s>>t;

    for(int i=0;i<max(s.size(),t.size())+3;i++){
        dp[i][0]=dp[0][i]=0;
        //dp2[i][0]=dp2[0][i]="";
    }
    rep(i,s.size()){
        rep(j,t.size()){
               dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
            if(s[i]==t[j]){dp[i+1][j+1]=max(dp[i+1][j+1],1+dp[i][j]);}  //dp2[i+1][j+1]=dp2[i][j]+t[j];}
            
    }
    }
    //int x=dp[s.size()][t.size()];
    string a="";
    for(int i=s.size() ,j=t.size(); i>0&&j>0;){
        
        if(dp[i][j]==dp[i-1][j]) i--;
        else if(dp[i][j]==dp[i][j-1])j--;
        else  {a+=s[i-1] ; i--; j--;}
    }
    for(int i=a.size()-1;i>=0;i--) cout<<a[i];
    cout<<endl;
    
    return 0;
}


Measured memory_bytes: 35456
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

#define UNDEF -1

struct node{
	int parent = 0;
	int left = 0;
	int right = 0;
};

void Postorder_Rec(vector<node> tree, int root, bool &isFirst){
	if (tree[root].left != UNDEF) Postorder_Rec(tree, tree[root].left, isFirst);
	if (tree[root].right != UNDEF) Postorder_Rec(tree, tree[root].right, isFirst);
	cout << (isFirst ? "" : " ") << root;
	isFirst = false;
	return;
}

int Reconstruct(vector<node> &tree, vector<int> preorder, vector<int> inorder, int start, int end){ //0, n-1
	if (start > end) return UNDEF;
	if (start == end ) return inorder[start];
	int mini, minj;
	int cur;
	for (int i = start; i <= end; i++){
		for (int j = 0; j <= preorder.size(); j++){
			if (preorder[j] == inorder[i]){
				cur = j;
				break;
			}
		}
		if (i == start || cur < minj){
			minj = cur;
			mini = i;
		}
	}
	tree[inorder[mini]].left = Reconstruct(tree, preorder, inorder, start, mini - 1);
	tree[inorder[mini]].right = Reconstruct(tree, preorder, inorder, mini + 1, end);
	return inorder[mini];
}

int height(vector<node> tree, const int id){
	if (tree[id].left == UNDEF && tree[id].right == UNDEF) return 0;
	if (tree[id].left == UNDEF) return height(tree, tree[id].right) + 1;
	if (tree[id].right == UNDEF) return height(tree, tree[id].left) + 1;
	int r = height(tree, tree[id].right);
	int l = height(tree, tree[id].left);
	return r > l ? r + 1 : l + 1;
}

int main(){

	int n;
	cin >> n;
	vector<int> preorder(n), inorder(n);
	int id;
	node nullnode;
	nullnode.parent = UNDEF;
	nullnode.left = UNDEF;
	nullnode.right = UNDEF;
	vector<node> tree(n+1, nullnode);
	for (int i = 0; i < n; i++){
		cin >> id;
		preorder[i] = id;
	}
	for (int i = 0; i < n; i++){
		cin >> id;
		inorder[i] = id;
	}

	Reconstruct(tree, preorder, inorder, 0, n-1);

	int maxheight = height(tree, 1);
	int root = 1;
	for (int i = 1; i < tree.size(); i++){
		if (maxheight < height(tree, i)){
			maxheight = height(tree, i);
			root = i;
		}
	}
	bool isFirst = true;
	Postorder_Rec(tree, root, isFirst);
	cout << endl;

	return 0;
}


Measured memory_bytes: 3188
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn main() {
    let n:usize = read();
    println!("{}", if n % 2 == 0 { n/2 } else { n/2 + 1 });
}

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

int main(){
  int A, B, C;
  cin >> A >> B >> C;

  int K;
  cin >> K;

  int multi;
  for (int i = 0; i < K; i++)
  {
    multi = max(A, max(B, C)) * 2;
    if (A * 2 == multi) A = multi;
    else if (B * 2 == multi)
    {
      B = multi;
    }
    else
    {
      C = multi;
    }
    
    
  }
  
  cout << A + B + C << endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define all(x)begin(x),end(x)
using namespace std;int f,Q,T,F;char C;string S;deque<char>q;main(){for(cin>>S>>Q,q={all(S)};Q--&&cin>>T;)if(T&1)f^=1;else cin>>F>>C,F-1^f?q.push_back(C):q.push_front(C);S={all(q)};if(f)reverse(all(S));cout<<S;}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

int main() {
	int a, b;
	cin >> a >> b;
	if (a < 10 && b < 10)cout << a * b << endl;
	else cout << "-1" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int X,count;
count=0;
cin>>X;
 
  if( X%10==1)
   count++;
X/=10;
if( X%10==1)
   count++;
 X/=10;
   if( X==1)
   count++;
cout<<count;
return 0;}

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

int main() {
	// your code goes here
	int n;
	cin >> n;
	int b[n-1];
	int a[n];
	int ans;
	for(int i=0; i<n-1; i++)
	{
		cin >> b[i];
	}
	a[0] = b[0];
	ans += a[0];
	for(int i=1; i<n-1; i++)
	{
		a[i] = min(b[i-1], b[i]);
		ans += a[i];
	}
	a[n-1] = b[n-2];
	ans += a[n-1];
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;


int main() {

    int N, L;

    cin >> N >> L;

    vector<string> ss;

    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        ss.push_back(s);
    }

    sort(ss.begin(), ss.end());

    string result;

    for (int i = 0; i < N; i++) {
        result += ss[i];
    }

    cout << result << "\n";

    return 0;
}

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

typedef long long ll;

static const int MAX = 1e6;
static const int NIL = -1;
static const ll INF = 1<<21;
static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

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

    vector<int> A(N);
    for(int i=0;i<N;i++) {
        cin >> A.at(i);
    }

    sort(A.begin(), A.end());

    for(int i=0;i<N-1;i++) {
        if(A.at(i)==A.at(i+1)) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


int main(){
    ll n, a, b;
    cin >> n >> a >> b;

    ll res = n % (a+b);
    ll cnt = n / (a+b);

    cout << cnt * a + min(a, res) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp>
#define priority_queue __gnu_pbds::priority_queue
typedef long long LL;
typedef long double LD;
typedef unsigned int ui;
typedef unsigned long long ul;
#define ri register int
#define pb push_back
#define fi first
#define se second
#define mid ((l + r) >> 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
#define enum(i, j, k) for(int i = j; i <= k; i ++)
#define FO(x) { freopen(#x".in", "r", stdin); freopen(#x".out", "w", stdout); }
using namespace std;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef vector<int> vi;
#define ae(x) for(node *p = h[x]; p; p = p->nxt)
#define G \
	struct node { int v; node *nxt; } e[maxm], *h[maxn]; int z;\
	void adde(int u, int v) { e[++z].v = v; e[z].nxt = h[u]; h[u] = &e[z]; }\
	void addrev(int u, int v) { adde(u, v); adde(v, u); }
#define W \
	struct node { int v, w; node *nxt; } e[maxm], *h[maxn]; int z;\
	void adde(int u, int v, int w) { e[++z].v = v; e[z].w = w; e[z].nxt = h[u]; h[u] = &e[z]; }\
	void addrev(int u, int v, int w) { adde(u, v, w); adde(v, u, w); }
inline int _() // ret >= 0
{
	int ret = 0; char ch = getchar();
	while(ch < '0' || ch > '9') ch = getchar();
	do { ret = ret * 10 + ch - '0'; ch = getchar(); } while('0' <= ch && ch <= '9');
	return ret;
}
inline void _(int x) // x >= 0
{
	if(x < 10) { putchar(x + '0'); return ; }
	_(x / 10); putchar(x % 10 + '0');
}
void What_are_you_doing_at_the_end_of_the_world_Are_you_busy_Can_you_save_us()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cout << fixed << setprecision(16);
}
/* Default Code Ends Here. */

int a, b;
void zero()
{
	cout << "Zero";
	exit(0);
}
void po()
{
	cout << "Positive";
	exit(0);
}
void ne()
{
	cout << "Negative";
	exit(0);
}
int main()
{
	What_are_you_doing_at_the_end_of_the_world_Are_you_busy_Can_you_save_us();
	
	cin >> a >> b;
	if(a <= 0 && b >= 0)
		zero();
	if(a > 0)
		po();
	if(b - a + 1 & 1)
		ne();
	po();
	return 0;
}


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

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<lli> vli;
typedef vector<pii> vii;

const int MOD   = 1e9 + 7;
const double PI = acos(-1.0);
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
const int INF   = 1e18;

#define fastio            ios_base::sync_with_stdio(false);cin.tie(0)
#define sz(a) int((a).size())
#define rsz resize
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define f first
#define s second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define spc " "
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }

void solve(){

    string s, t;
    cin >> s >> t;
    int n = sz(s);
    int ans = 0;
    rep(i, n){
        if(s[i] != t[i]){
            ans++;
        }
    }
    cout << ans << endl;
}

signed main(){
    fastio;

    solve();

    return 0;
}


Measured memory_bytes: 3688
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
    int n , i , j , k , v[3] = {0}, a[3];
    cin>>n;
    for(i=0;i<n;i++) 
    {
        for(j = 0;j<3;j++)
          cin>>a[j];
        int x[3] = {0};
        for(k = 0;k<3;k++)
        {
            for(j = 0;j<3;j++)
            {
                if(k!=j)
                x[k] = max(x[k],v[j]+a[k]);
            }
        }
        for(j = 0;j<3;j++)
          v[j]= x[j];
    }
    cout<<max(max(v[0],v[1]),v[2]);
}

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

int main(){
  for(int b = 0;;b++){
    int stun,listn;
    int a = 0;
    cin >> stun >> listn;
    if(stun == 0 && listn == 0)break;
    vector<int> fl1(listn);
    vector<int> fl2(listn);
    vector<int> fre1(0),fre2(0);
    for(int n = 0;n<listn;n++){
      cin >> fl1[n] >> fl2[n];
      if(fl1[n] == 1){
        fre1.push_back(fl2[n]);
        a = 1;
      }else if(fl2[n] == 1){
        fre1.push_back(fl1[n]);
        a = 1;
      }
    }
    sort(fre1.begin(),fre1.end(),greater<int>());
    for(int n = 0;n<fre1.size();n++){
      for(int g = 0;g<listn;g++){
        if(fre1[n] == fl1[g]){
          fre2.push_back(fl2[g]);
        }else if(fre1[n] == fl2[g]){
          fre2.push_back(fl1[g]);
        }
      }
    }
    if(a != 0){
      fre2.insert(fre2.end(),fre1.begin(),fre1.end());
      sort(fre2.begin(), fre2.end());
      fre2.erase(unique(fre2.begin(), fre2.end()), fre2.end());
      cout << fre2.size() - 1 << endl;
    }else{
      cout << 0 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1316
import java.util.*;
import java.util.stream.*;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        // programming
		String n = Util.getInputString(sc);
        String[] ns = Util.toList(n);
        StringBuilder result = new StringBuilder();
        for (String s : ns) {
            if (s.equals("1")) {
                result.append("9");
            } else if (s.equals("9")) {
                result.append("1");
            } else {
                result.append(s);
            }
        }

		Util.output(result.toString());
	}
}

// =========common=========
class Util {
	public static String getInputString(Scanner sc) {
		return sc.next();
	}

	public static int getInputInteger(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	public static void output(String... params) {
		boolean isInit = true;
		String str = "";
		for (String s : params) {
			if (!isInit) {
				str += " ";
			}
			str += s;
			isInit = false;
		}
		System.out.println(str);
	}

    public static int[] toIntegerList(String... ss) {
        return Stream.of(ss).mapToInt(Integer::parseInt).toArray();
    }

    public static String[] toList(String s) {
        String[] ret = s.split("");
        return ret;
    }

    public static int sum(int... vals) {
        int sum = 0;
        for (int val : vals) {
            sum += val;
        }
        return sum;
    }

    public static int[] sort(int[] vals, boolean isAsc) {
        Arrays.sort(vals);
		if (isAsc) {
			return vals;
		}
        int[] ret = new int[vals.length];
        for (int i = 0; i < vals.length; i++) {
            ret[vals.length - i - 1] = vals[i];
        }
		return ret;
	}

    public static void gc() {
        System.gc();
    }

	public static int diff(int a, int b) {
		return Math.abs(a - b);
	}

	public static int max(int... a) {
		int temp_max = Integer.MIN_VALUE;
		for (int v : a) {
			if (v > temp_max) {
				temp_max = v;
			}
		}
		return temp_max;
	}

	public static int min(int... a) {
		int temp_min = Integer.MAX_VALUE;
		for (int v : a) {
			if (v < temp_min) {
				temp_min = v;
			}
		}
		return temp_min;
	}
}

Measured memory_bytes: 23892
/*
//TLE
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
typedef priority_queue<int> p_queue;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define fir first
#define sec second
map<pii,bool>mp;
ll res;
int n;
int get_top(int x){
	while(x>=10)x/=10;
	return x;
}
int get_last(int x){
	return (x%10);
}
int pow(int x){
	int num=1;
	while(x--){
		num*=10;
	}
	return num;
}
bool check(int x){
	return (x<=n);
}
void make(int x){
	pii num;
	num.fir=get_top(x);
	num.sec=get_last(x);
//	cout<<x<<":  "<<num.fir<<','<<num.sec<<'\n';
	if(num.sec==0)return;
	if(x<10)res+=!mp[make_pair(x,x)],mp[make_pair(x,x)]=1;
	res+=int(mp[make_pair(min(x,num.sec*10+num.fir),max(x,num.sec*10+num.fir))]==0&&num.sec*10+num.fir<=n),mp[make_pair(min(x,num.sec*10+num.fir),max(x,num.sec*10+num.fir))]=(num.sec*10+num.fir<=n);
	res+=int(mp[make_pair(max(x,num.sec*10+num.fir),min(x,num.sec*10+num.fir))]==0&&num.sec*10+num.fir<=n),mp[make_pair(max(x,num.sec*10+num.fir),min(x,num.sec*10+num.fir))]=(num.sec*10+num.fir<=n);
	for(int i=1;i<10;i++){
		for(int j=0;j<pow(i);j++){
			int y=num.sec*pow(i+1)+j*10+num.fir;
			if(!check(y))goto found;
			else{
				res+=!mp[make_pair(min(x,y),max(x,y))],mp[make_pair(min(x,y),max(x,y))]=1;
				res+=!mp[make_pair(max(x,y),min(x,y))],mp[make_pair(max(x,y),min(x,y))]=1;
			}
		}
	}
	found:;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++){
		make(i); 
	} 
	cout<<res<<'\n';
//	for(int i=1;i<=n;i++)for(int j=i;j<n;j++)if(mp[make_pair(i,j)])cout<<'('<<i<<','<<j<<')'<<"   ";
//	cout<<mp[make_pair(1,11)];
	return 0;
}
*/
//AC
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_pack
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll a[15][15];
ll res,n;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
	for(ll i=1;i<=n;i++){
		if(i<10){
			a[i][i]++;
			continue;
		}
		string s=i_to_s(i);
		a[s[0]-'0'][s[s.size()-1]-'0']++;
	}
	for(ll i=0;i<10;i++)for(int j=0;j<10;j++)res+=(a[i][j]*a[j][i]);
	cout<<res;
	return 0;
}


Measured memory_bytes: 256
X = int(input())

N = list(range(-150,150))

M =[]
for i in N:
    m = i**5
    M.append(m)
    
for i in range(0,300):
    Y = M[i]+X
    if Y in M:
        l = M.index(Y)
        print(N[l], N[i])
        break

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

using namespace std;
#define ff(i, a, b) for(long long i = (a), _b = (b); i <= _b; ++i)
#define rep(i, a, b) for(int i = (a), _b = (b); i < _b; ++i)
#define fd(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
#define SZ(x) ((int)(x).size())
#define db(x) cout << #x << " == " << x << endl
#define _ << ", " << 
#define X first
#define Y second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define endl '\n'
#define pc putchar
#define gc getchar 
#define bit(i) (1<<(i))

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;

ll n;

void enter(){
	cin>>n;
}

void process(){
	ll bon=4;
	if (n<0){
		bon=-4;
		n=-n;
	}

	ff(b,1,3500) ff(c,1,3500){
		ll mau=bon*b*c - n*b - n*c;
		if (mau>0 && n*b*c%mau==0){
			cout<<n*b*c/mau<<' '<<b<<' '<<c<<endl;
			return;
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	//freopen("test.inp","r",stdin);
	//freopen("test.out","w",stdout);

	enter();
	process();	

	return 0;
}

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

const int nm = 1e5+10;
int main(){
    int n; cin >> n;
    ll a[nm], b[nm];
    rep(i, n+1){
        cin >> a[i];
    }
    rep(i, n){
        cin >> b[i];
    }
    ll sum = 0;
    for(int i=0; i<n; i++){
        if(a[i] >= b[i]){
            sum+=b[i];
            a[i]-=b[i];
            b[i]=0;
        } else {
            sum += a[i];
            b[i] -= a[i];
            a[i] = 0;
            if(a[i+1] >= b[i]){
                sum += b[i];
                a[i+1] -= b[i];
                b[i] = 0;
            } else {
                sum += a[i+1];
                b[i] -= a[i+1];
                a[i+1] = 0;
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int cmp(ll a,ll b)
{
    return a>b;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    printf("%d",n%m==0?n/m:n/m+1);
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
ans = [0 for _ in range(N)]
for _ in range(K):
  d = int(input())
  a = list(map(int, input().split()))
  for i in range(d):
    ans[a[i]-1] += 1
ans = [1 if i == 0 else 0for i in ans]
print(sum(ans))

Measured memory_bytes: 9196
n, m = map(int, input().split())
x = sorted(list(map(int, input().split())))
if m > 1:
  y = sorted([x[i + 1] - x[i] for i in range(m - 1)])
total = 0

if n >= m:
  print(0)
else:
  for i in range(m - n):
    total += y[i]
  print(total)

Measured memory_bytes: 13968
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define PI 3.14159265359
using namespace std;
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> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
vector<int> Eratosthenes(const int N)
{
    vector<bool> is_prime(N+1, true);
    vector<int> P;
    for(int i=2; i<=N; i++) {
        if (is_prime[i]) {
            for(int j=2*i; j<=N; j+=i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}
 
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    int l,r;
    int cnt = 0;
    int left = 1;
    int right = n;
    rep(i,m) {
        cin >> l >> r;
        left = max(left, l);
        right = min(right, r);
    }
    if (right-left+1>0) {
        cout << right-left+1 << "\n";
    } else {
        cout << 0 << "\n";
    }

}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H,W,N;
int sy,sx;
string S,T;

signed main(){
	cin>>H>>W>>N;
	cin>>sy>>sx;sy--;sx--;
	cin>>S>>T;

	int l=0,r=W-1;
	for(int i=N-1;i>=0;i--){
		if(T[i]=='L')r=min(r+1,W-1);
		if(T[i]=='R')l=max(l-1,0ll);

		if(S[i]=='L')l++;
		if(S[i]=='R')r--;
		if(l>r){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	if(l>sx||r<sx){
		cout<<"NO"<<endl;
		return 0;
	}

	l=0;
	r=H-1;

	for(int i=N-1;i>=0;i--){
		if(T[i]=='U')r=min(r+1,H-1);
		if(T[i]=='D')l=max(l-1,0ll);

		if(S[i]=='U')l++;
		if(S[i]=='D')r--;
		if(l>r){
			cout<<"NO"<<endl;
			return 0;
		}
	}
	if(l>sy||r<sy){
		cout<<"NO"<<endl;
		return 0;
	}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 776
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<deque>

using namespace std;

#define sz(x) (int)(x.size())
#define rep(i, a, b) for(int i=a;i<b;++i)
#define per(i, a, b) for(int i=b-1;i>=a;--i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

////////////////

int const N = 1e5 + 41;
int cnt[N];

void solve(){
	int n, m;
	cin >> n >> m;
	rep(i, 0, m){
		int a, b;
		cin >> a >> b;
		++cnt[a];
		++cnt[b];
	}
	rep(i, 1, n+1){
		if(cnt[i] % 2 == 1){
			cout << "NO" << endl;
			return;
		}
	}
	cout << "YES" << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();

	return 0;
}

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

int n, m;
int a[28], b[28];

int route(bool alrdy[], int cnt, int now){
    if(cnt == n){
        return 1;
    }
    
    int ans = 0;
    int i;
    for(i = 0; i < m; i++){
        if(a[i] == now && alrdy[b[i]] == false){
            alrdy[b[i]] = true;
            ans += route(alrdy, cnt + 1, b[i]);
            alrdy[b[i]] = false;
        }
        if(b[i] == now && alrdy[a[i]] == false){
            alrdy[a[i]] = true;
            ans += route(alrdy, cnt + 1, a[i]);
            alrdy[a[i]] = false;
        }
    }
    
    return ans;
}

int main(void){
    cin >> n >> m;
    
    int i;
    for(i = 0; i < m; i++){
        cin >> a[i] >> b[i];
    }
    
    bool alrdy[9] = {false, true};
    int ans = route(alrdy, 1, 1);
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict
from heapq import *
def input(): return sys.stdin.readline().strip()


def main():
    n = int(input())
    A = list(map(int, input().split()))
    """
    すべて正の場合は簡単で、
        ai > a(i+1) <= a(i+2) <= ... <= aj > a(j+1) <= ...
    となっていたらa(i+1)~ajすべてにaiを加えればよい。

    実はすべて負の場合も同様で、上のようになっていたら
    ai~ajすべてにa(j+1)を加えればよい。

    「「部分問題が解けたのだから、一般の場合はここに帰着させる！！！」」
    すなわち正負が混ざっている場合は、Aの最大値もしくは最小値をすべての要素に
    足すことで、すべて正もしくはすべて負にすることができるので解けた。
    """
    M_idx, m_idx = 0, 0
    M, m = A[0], A[0]
    for i, a in enumerate(A):
        if a > M:
            M_idx, M = i, a
        if a < m:
            m_idx, m = i, a
    print(2 * n - 1)
    if M >= -m:
        for i in range(n): print(M_idx + 1, i + 1)
        for i in range(n - 1): print(i + 1, i + 2)
    else:
        for i in range(n): print(m_idx + 1, i + 1)
        for i in range(n, 1, -1): print(i, i - 1)
    



if __name__ == "__main__":
    main()


Measured memory_bytes: 67436
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;

const string YES = "Yes";
const string NO = "No";

void solve(long long A, long long B, long long C){
	int i=0;
	if(A==B){
		i++;
	}
	if(A==C){
		i++;
	}
	if(B==C){
		i++;
	}
	if(i==1){
		cout << YES << endl;
	}

	else{
		cout << NO << endl;
	}
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    solve(A, B, C);
    return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
c = Counter(a)
s = set()
ans = 0
for i in sorted(set(a)):
    j=i*2
    while j<=1000000:
        s.add(j)
        j+=i
    if i not in s and c[i]==1:
        ans+=1
            
print(ans)

Measured memory_bytes: 182980
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define SWAP(a, b) (a += b, b = a - b, a -= b)

int hsize; // ヒープサイズ

int parent(int i)
{
    return (int)(i / 2);
}

int left(int i)
{
    return 2 * i;
}

int right(int i)
{
    return 2 * i + 1;
}

void maxHeapify(int *H, int i)
{
    int l = left(i);
    int r = right(i);
    int largest;

    if (l <= hsize && H[l] > H[i])
    {
        largest = l;
    }
    else
    {
        largest = i;
    }
    if (r <= hsize && H[r] > H[largest])
    {
        largest = r;
    }

    if (largest != i)
    {
        SWAP(H[i], H[largest]);
        maxHeapify(H, largest);
    }
}

void buildMaxHeap(int *H)
{
    for (int i = hsize / 2; i >= 1; i--)
    {
        maxHeapify(H, i);
    }
}

int main(void)
{
    int H[500001];
    int key;

    scanf("%d", &hsize);
    for (int i = 1; i <= hsize; i++)
    {
        scanf("%d", &key);
        H[i] = key;
    }

    buildMaxHeap(H);

    for (int i = 1; i <= hsize; i++)
    {
        printf(" %d", H[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B_Christmas_Eve_Eve
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] P = new int[N];
            for(int i = 0; i < N; i++)
            {
                P[i] = int.Parse(Console.ReadLine());
            }
            int max = P[0];
            int total = P[0];
            for(int i = 1; i < N; i++)
            {
                if (max< P[i])
                {
                    max = P[i];
                }
                total += P[i];
            }
            total -= max / 2;

            Console.Write(total);
          
           
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <string.h>
#include <algorithm>

using namespace std;
static const int INF = 1e9;
int memo[10][10][10][10][50];
int W, H;
int field[10][10];
int f, o, olimit;


int rec(int y, int x, int l, int r, int oxy)
{
	if (oxy <= 0)
	{
		return(INF);
	}
	if (y == H - 1)
	{
		return(0);
	}
	if (memo[y][x][l][r][oxy] >= 0)
	{
		return(memo[y][x][l][r][oxy]);
	}

	if (oxy == 1) return (INF);

	int cost = 0;
	int oxygen = 0;
	int res = INF;
	if (x > 0)
	{
		if (l > x - 1)
		{
			if (field[y][x - 1] < 0)
			{
				cost = -field[y][x - 1];
			}
			else
			{
				oxygen = field[y][x - 1];
			}
		}
		res = min(res, rec(y, x - 1, min(l, x - 1), r, min(olimit, oxy + oxygen - 1)) + cost);
	}
	if (x < W - 1)
	{
		cost = 0;
		oxygen = 0;
		if (x + 1 > r)
		{
			if (field[y][x + 1] < 0)
			{
				cost = -field[y][x + 1];
			}
			else
			{
				oxygen = field[y][x + 1];
			}
		}
		res = min(res, rec(y, x + 1, l, max(r, x + 1), min(olimit, oxy + oxygen - 1)) + cost);
	}

	cost = 0;
	oxygen = 0;
	if (field[y + 1][x] < 0)
	{
		cost = -field[y + 1][x];
	}
	else
	{
		oxygen = field[y + 1][x];
	}
	res = min(res, rec(y + 1, x, x, x, min(olimit, oxy + oxygen - 1)) + cost);
	return(memo[y][x][l][r][oxy] = res);
}

void solve()
{
	while (cin >> W >> H, W || H)
	{
		cin >> f >> olimit >> o;
		for (int i = 0; i < H; ++i)
		{
			for (int j = 0; j < W; ++j)
			{
				cin >> field[i][j];
			}
		}
		if (o <= 1)
		{
			cout << "NA" << endl;
			continue;
		}
		memset(memo, -1, sizeof(memo));
		int ans = INF;
		for (int i = 0; i < W; ++i)
		{
			int cost = 0;
			int oxy = 0;
			if (field[0][i] < 0)
			{
				cost = -field[0][i];
			}
			else
			{
				oxy = field[0][i];
			}
			ans = min(ans, rec(0, i, i, i, min(olimit, o + oxy - 1)) + cost);
		}
		if (ans == INF || ans > f)
		{
			cout << "NA" << endl;
		}
		else
		{
			cout << ans << endl;
		}
	}
}

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

Measured memory_bytes: 3172
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
// #include <unordered_map>
// #include <unordered_set>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

int l[1 << 18];
int ret[1 << 18];

int n;
pii big1[1 << 18];
pii big2[1 << 18];

int main() {
  scanf("%d", &n);
  for(int i = 0; i < (1<<n); i++) {
    int t;
    scanf("%d", &t);
    if(i == 0) {
      big1[i] = pii(t, 0);
    }
    else {
      set<pii> all;
      for(int a = 0; a < n; a++) {
        if(i&(1<<a)) {
          all.insert(big1[i ^ (1<<a)]);
          all.insert(big2[i ^ (1<<a)]);
        }
      }
      all.insert(pii(t, i));
      big1[i] = *all.rbegin();
      all.erase(big1[i]);
      big2[i] = *all.rbegin();
      ret[i] = big1[i].first + big2[i].first;
    }
    if(i >= 1) {
      ret[i] = max(ret[i], ret[i-1]);
      printf("%d\n", ret[i]);
    }
  }
}


Measured memory_bytes: 9216
a,b=map(int,input().split())
k=[]
o=[]
p=[]
for i in range(1,5000):
    if int(i*0.08)==a:
        k.append(i)
for j in range(1,5000):
    if int(j*0.1)==b:
        o.append(j)
for t in range(len(k)):
    for u in range(len(o)):
        if k[t]==o[u]:
            p.append(k[t])
if p==[]:
    print(-1)
else:
    print(min(p))


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

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

  ll ans = 0;
  for (int i = 0; i < (1 << s.size() - 1); ++i) {
    ll t = s[0] - '0';
    for (int j = 0; j < s.size() - 1; ++j) {
      if (i & (1 << j)) ans += t, t = 0;
      t = t * 10 + s[j + 1] - '0';
    }
    ans += t;
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
  string s, t;
  cin >> s;
  cin >> t;
  bool ans = true;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == t.at(i)) {
      continue;
    }
    else {
      ans = false;
      break;
    }
  }
  if (ans == true) cout << "Yes" << endl;
  else if (ans == false) cout << "No" << endl;
}

Measured memory_bytes: 3628
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let a: Vec<i32> = (0..n).map(|_| input()).collect();

    let mut l = vec![0; n];
    let mut r = vec![0; n];
    l[0] = a[0];
    r[n - 1] = a[n - 1];
    for i in 1..n {
        l[i] = gcd(l[i - 1], a[i]);
        r[n - i - 1] = gcd(r[n - i], a[n - i - 1]);
    }

    let mut ans = std::cmp::max(r[1], l[n - 2]);
    for i in 1..n - 1 {
        ans = std::cmp::max(ans, gcd(l[i - 1], r[i + 1]));
    }
    println!("{}", ans);
}

fn gcd(x: i32, y: i32) -> i32 {
    if y == 0 {
        x
    } else {
        gcd(y, x % y)
    }
}


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

using namespace std;
typedef long long int lld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
#define MOD 998244353
vector<int> nei[1000000][3];
int used[1000000][3];

int main(){
  lld base=1;
  rep(i,0,18){
    base*=10;
    base%=MOD;
  }
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  rep(i,0,3){
    int m;
    cin>>m;
    rep(j,0,m){
      int x,y;
      cin>>x>>y;
      x--;y--;
      if(x>y)swap(x,y);
      nei[x][i].push_back(y);
    }
  }
  /*lld Res[3][2];
  rep(k,0,3){
    rep(i,0,2)Res[k][i]=0;
    rep(i,0,n)used[i][k]=-1;
    for(int i=n-1;i>-1;i--){
      if(used[i][k]==-1){
	used[i][k]=1;
	trav(a,nei[i][k]){
	  used[a][k]=0;
	}
      }
    }
    lld Pow=base;
    rep(i,0,n){
      if(used[i][k]){
	Res[k][1]+=Pow;
	Res[k][1]%=MOD;
      }else{
	Res[k][0]+=Pow;
	Res[k][0]%=MOD;
      }
      Pow*=base;
      Pow%=MOD;
    }
  }
  lld ans=0;
  rep(msk,0,8){
    lld can=1;
    int cnt=0;
    rep(i,0,3){
      if((msk>>i)%2>0)can*=Res[i][1],cnt++;
      else can*=Res[i][0];
      can%=MOD;
    }
    cnt%=2;
    //ans+=can;
    if(cnt==1){
      ans+=can;
      ans%=MOD;
    }
    }
    cout<<ans<<endl;*/
  int nim[n][3];
  int max_nim=0;
  set<int> s;
  rep(j,0,3){
    for(int i=n-1;i>-1;i--){
      s.clear();
      trav(a,nei[i][j]){
	s.insert(nim[a][j]);
      }
      int cnt=0;
      while(s.find(cnt)!=s.end())cnt++;
      nim[i][j]=cnt;
      max_nim=max(max_nim,cnt+1);
    }
  }
  lld Tot[max_nim][3];
  rep(i,0,max_nim){
    rep(j,0,3)Tot[i][j]=0;
  }
  //cout<<base<<endl;
  rep(j,0,3){
    lld Pow=base;
    rep(i,0,n){
      Tot[nim[i][j]][j]+=Pow;
      Tot[nim[i][j]][j]%=MOD;
      Pow*=base;
      Pow%=MOD;
    }
  }
  /*rep(i,0,max_nim){
    rep(j,0,3)cout<<Tot[i][j]<<" ";
    cout<<endl;
  }*/
  lld ans=0;
  rep(i,0,max_nim){
    rep(j,0,max_nim){
      if((i^j)<max_nim){
      lld can=1;
      can*=Tot[i][0];
      can%=MOD;
      can*=Tot[j][1];
      can%=MOD;
      can*=Tot[i^j][2];
      can%=MOD;
      ans+=can;
      ans%=MOD;
      //cout<<i<<" "<<j<<" "<<(i^j)<<endl;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

int main() {
  int x, a, b;
  cin >> x >> a >> b;
  int da, db;
  da = abs( a - x );
  db = abs( b - x );
  if( da > db )
    cout << 'B' << endl;
  else
    cout << 'A' << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N,M;
    cin >> N;
    vector<int> T(N);
    for(int i = 0; i < N; i++) cin >> T[i];
    cin >> M;
    vector<int> P(M),X(M);
    for(int i = 0; i < M; i++) cin >> P[i] >> X[i];
    for(int i = 0; i < M; i++){
        int S = 0;
        for(int j = 0; j < N; j++){
                if(j+1 == P[i]) S += X[i];
                else S += T[j];
            }
            cout << S << endl;
        }
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long A = sc.nextInt();
		long B = sc.nextInt();
		long pile = 1;
		
		for(long i=2; i<=Math.min(A, B);i++) {
			if(A%i==0 && B%i==0) {
				A /= i;
				B /= i;
				pile *= i;
				i--;
			}
        }
      long answer = A*B*pile;
      System.out.println(answer);
    }
}

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

int main() {
    int n;
    int k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i=0; i<n; ++i) cin >> p[i];
    sort(p.begin(), p.end());
    int ans = 0;
    for (int i=0; i<k; ++i) {
        ans += p[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
  int n,cnt=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    int tmp;
    scanf("%d",&tmp);
    if(tmp==cnt+1) cnt++;
  }
  if(cnt==0) printf("-1");
  else printf("%d",n-cnt);
  return 0;
}

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

// 相似 r : r-x -> (r-x)/r -> 1 - x/r
int main(){
    double x[3], y[3];
    for(int i = 0; i < 3; i++)  cin >> x[i] >> y[i];
    double d[3];
    for(int i = 0; i < 3; i++){
        d[i] = sqrt(pow(x[i]-x[(i+1)%3], 2.0)+pow(y[i]-y[(i+1)%3], 2.0));
    }
    double s = (d[0]+d[1]+d[2])/2;
    double area = sqrt(s*(s-d[0])*(s-d[1])*(s-d[2]));
    double r = area/s;
    double ma = *max_element(d, d+3);
    cout << fixed << setprecision(12) << r*ma/(2*r+ma) << endl;
    return 0;
}

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

using namespace std;

#define int long long

bool codejam = 0;

typedef long long li;
typedef long double ld;

void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t = 1; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}
#define get gett
const int N = 1e5 + 55;
int cnt[N] = {0};
int S[N] = {0};
int curtot = 0;
int tot[N] = {0};
set<int> get[N];
vector<pair<int, pair<int, int>>> adj[N];
vector<int> adj2[N];
map<int, int> sums[N];
map<int, int> cnts[N];
const int upper = N;
int s[upper], e[upper], up[upper][20];
int clk = 0;
bool is_ancestor (int a, int b) {
	return (s[a] <= s[b] and e[a] >= e[b]);
}
void dfs_lca (int v, int p) {
	s[v] = ++clk;
	up[v][0] = p;
	for (int i = 1; i < 20; i += 1) 
		up[v][i] = up[up[v][i - 1]][i - 1];
	for (auto i: adj2[v])
		if (i != p)
			dfs_lca(i, v);
	e[v] = clk;
}
int lca (int a, int b) {
	if (is_ancestor(a, b)) return a;
	if (is_ancestor(b, a)) return b;
	for (int i = 19; i >= 0; i -= 1) {
		if (!is_ancestor(up[a][i], b)) a = up[a][i];
	}
	return up[a][0];
}
void dfss (int v, int p) {
	tot[v] = curtot;
	for (auto i: adj[v]) {
		if (i.first != p) {
			curtot += i.second.first;
			dfss(i.first, v);
			curtot -= i.second.first;
		}
	}
}
void dfs (int v, int p) {
	for (auto i: get[v]) {
		sums[v][i] += S[i];
		cnts[v][i] += cnt[i];
	}
	for (auto i: adj[v]) {
		if (i.first == p)
			continue;
		S[i.second.second] += i.second.first;
		cnt[i.second.second] += 1;
		dfs(i.first, v);
		S[i.second.second] -= i.second.first;
		cnt[i.second.second] -= 1;
	}	
}
vector<pair<pair<int, int>, pair<int, int>>> queries;
void solve() {	
	int n, q;
	cin >> n >> q;
	for (int i = 1; i < n; ++i) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		adj[a].push_back(make_pair(b, make_pair(d, c)));
		adj[b].push_back(make_pair(a, make_pair(d, c)));
		adj2[a].push_back(b);
		adj2[b].push_back(a);
	}
	dfs_lca(1, 1);
	dfss(1, 1);
	for (int i = 1; i <= q; ++i) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		queries.push_back(make_pair(make_pair(c, d), make_pair(a, b)));
		get[c].insert(a);
		get[d].insert(a);
		get[lca(c, d)].insert(a);
	}
	dfs(1, 1);	
	for (auto i: queries) {
		int a = i.first.first, b = i.first.second;
		int cur = 0;
		int c = i.second.first;
		int l = lca(a, b);
 		cur += tot[a];
		cur += tot[b];
		cur -= 2 * tot[l];
		int rm = 0;
		rm += sums[a][c];
		rm += sums[b][c];
		rm -= 2 * sums[l][c];
		cur -= rm;
		rm = 0;
		rm += cnts[a][c];
		rm += cnts[b][c];
		rm -= 2 * cnts[l][c];
		rm *= i.second.second;
		cur += rm;
		cout << cur << endl;
	}
}

Measured memory_bytes: 96172
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
#include <array>
using namespace std;
using ll = long long;
#define rep(i,n) for(decltype(n) i=0; i<n; ++i)
inline constexpr ll Inf = (1ULL << 62) -1;

template <class T>
void updatemax(T& a, T b) { if (b > a) a = b; }

int main() {
    ll N;
    cin >> N;
    if (N >= 30)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}


Measured memory_bytes: 3132
# -*- coding: utf-8 -*-

def main():
    n = int(input())
    a_list = list(map(int, input().split()))

    ans = 'APPROVED'

    for i in a_list:
        if divide(i, 2):
            if not divide(i, 3) and not divide(i, 5):
                ans = 'DENIED'
                break
    
    print(ans)

def divide(x, k):
    if x % k == 0:
        return True
    return False

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const int N = 5;
int dig[N];

void fail() {
  cout << -1 << nl;
  exit(0);
}

int main() {
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  // Emily <3
  int n, m; cin >> n >> m;
  if (n == 1 && m == 0) {
    cout << "0\n";
    return 0;
  }
  memset(dig, -1, sizeof dig);
  for (int i = 0; i < m; ++i) {
    int s,c; cin >> s>> c;
    s--;
    if (dig[s] == -1 || dig[s] == c) {
      dig[s] = c;
      continue;
    }
    fail();
  }
  if (dig[0] == 0 && n > 1) fail();
  for (int i = 0; i < n; ++i) {
    if (dig[i] == -1) dig[i] = i == 0;
    cout << dig[i];
  } cout << nl;
  return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> P; typedef pair<Int,Int> Pl;
static const int mod = 1e9+7;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
#define Pr(t) priority_queue<t>
#define gPr(t) priority_queue<t,vector<t>,greater<t>>
#define V(t) vector<t>
#define rep(i,n) for(int(i)=0; i<n; i++)
#define rer(i,l,r) for(int i=l; i<=r; i++)
#define gnr(i,l,r) for(int i=r; i>=l; i--)
#define eb emplace_back
#define pri1(a) cout<<(a)<<'\n'
#define pri2(a,n) {rep(pri2i,n-1)cout<<a[pri2i]<<' '; cout<<a[n-1]<<'\n';}
#define prip(p) cout<<p.fi<<' '<<p.se<<'\n'
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n,m,_,x,y,q;
string s,sb;
bool ok;
char cf,cb;

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

  int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
  cout<<x2+y1-y2<<' '<<y2+x2-x1<<' '<<x1+y1-y2<<' '<<y1+x2-x1<<'\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
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; }
#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 rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    int N;
    cin >> N;
    int K; cin >>K;
    VLL h(1000000);
    rep(i,N){
        cin >> h[i];
    }
    VLL ans(10000000, INF);
    ans[0]=0;
    rep(i,N){
        if(K>1){
        rept(j,1,K+1){
            chmin(ans[i+j],ans[i]+abs(h[i]-h[i+j]));
        }
        }
        else{
            chmin(ans[i+1],ans[i]+abs(h[i]-h[i+1]));
        }
    }
    cout << ans[N-1] << endl;
}

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

vector<P>a[10000];
int b[10000];
int main() {
	int n, m; scanf("%d%d", &n, &m);
	int s, t, e;
	while (scanf("%d%d%d", &s, &t, &e), s) {
		s--; t--; a[s].push_back(P(t, e));
	}
	int l; scanf("%d", &l);
	rep(i, l) {
		rep(j, m)scanf("%d", &b[j]);
		rep(j, n) {
			int sum = 0;
			for (P p : a[j])sum += p.second*b[p.first];
			if (j)printf(" ");
			printf("%d", sum);
		}
		printf("\n");
	}
}

Measured memory_bytes: 4232