akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC target ("avx2,sse2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <set>
#include <queue>

using namespace std;

const int N = 2e6 + 14;
const int INF = 1e9;
const int mod = 1e9;
const int SZ = (1 << 17) - 1;
const int K = 320;

#define eb emplace_back
#define sz(s) (int)(s.size())
#define ppb pop_back

#define ll long long

#define int ll

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int ans = 0;
	int x = 1;
	while(n) {
		ans += x;
		x *= 2;
		n /= 2;
	}
	cout << ans;
	return 0;
}


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

using namespace std;
using ull = unsigned long long;
using ll = long long;
using lli = long long int;
using ld = long double;
using pa = pair<int, int>;
using ppa = pair<pa, int>;
#define SORT(v, n) sort(v, v + n);
#define ALL(v) v.begin(), v.end()
#define VSORT(v) sort(ALL(v))
#define GRESORT(v) sort(ALL(v), greater<ll>())
#define REVERSE(v) reverse(ALL(v))
#define overlap(v) v.erase(unique(ALL(v)), v.end())
#define debug(x) cout << #x << ": " << x << endl
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (b - 1); i >= a; i--)
#define rrep(i, n) RFOR(i, 0, n)
#define INF INT_MAX
#define SUP INT_MIN
#define mins(a, b) a = min(a, b)
#define maxs(a, b) a = max(a, b)

// 4近傍
// int dy[]={0, 1, 0, -1};
// int dx[]={1, 0, -1, 0};

// 8近傍
// int dy[]={0,0,1,-1,1,1,-1,-1};
// int dx[]={1,-1,0,0,1,-1,1,-1};

// const ll MOD = 1000000007;

ll pow_mod(ll a, ll b, ll mod) {
    ll tmp = 1;
    a %= mod;
    if (b > 0) {
        tmp = pow_mod(a, b / 2, mod);
        if (b % 2)
            tmp = (((tmp * tmp) % mod) * a) % mod;
        else
            tmp = (tmp * tmp) % mod;
    }
    return tmp;
}

ll gcd(ll x,ll y){
    if(x == 0) return y;
    return gcd(y%x,x);
}

void solve(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(a*b,c*d) << endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct UnionFind {
    UnionFind() {}
    UnionFind(int n) {
        resize(n);
    }
    
    void resize(int n) {
        par.resize(n, -1);
    }
    
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    
    bool merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    
    bool is_same(int x, int y) {
        return (root(x) == root(y));
    }
    
    int size(int x) {
        return -par[root(x)];
    }
    
private:
    vector<int> par;
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    const ll MAX = 101000;
    ll n;
    cin >> n;
    vector<pair<ll, ll>> xy(n);
    rep(i, n) cin >> xy[i].first >> xy[i].second;
    UnionFind uf(MAX * 2);
    rep(i, n) {
        uf.merge(xy[i].first, xy[i].second + MAX);
    }
    map<ll, ll> mx, my;
    reps(i, 0, MAX) mx[uf.root(i)]++;
    reps(i, MAX, MAX * 2) my[uf.root(i)]++;
    ll res = 0;
    rep(i, MAX * 2) res += mx[i] * my[i];
    cout << (res - n) << endl;
    return 0;
}


Measured memory_bytes: 27904
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> P;
#define INF 10000000000000
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for(ll i = 1; i < (ll)(n); i++)
#define repN_1(i, n) for(ll i = 0; i < (ll)(n - 1); i++)
#define repM(i, n) for(ll i = (ll)(n - 1); i >= 0; i--)
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; }

int main()
{
	ll n, q;
	string s, ss;
	ll l[100005], r[100005];
	vector<ll> p;
	memset(l, 0, sizeof(l));
	memset(r, 0, sizeof(r));

	cin >> n >> q;
	cin >> s;
	rep(i, q)
		cin >> l[i] >> r[i];

	ss = s;

	while (1)
	{
		auto f = s.rfind("AC");
		if (f != string::npos)
		{
			p.push_back(f);
			s.erase(f);
		}
		else
			break;
	}

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

	rep(i, q)
	{
		auto ra = lower_bound(p.begin(), p.end(), r[i] - 1);
		auto la = lower_bound(p.begin(), p.end(), l[i] - 1);
		
		cout << distance(la, ra) << endl;
	}


	return 0;
}

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

namespace C
{
    public class Solver
    {
        public void Solve()
        {
            int N = ri();
            int[] H = ria();

            int ans = 0;
            int temp = 0;

            for (int i=0; i<N-1; i++)
            {
                if (H[i] >= H[i+1])
                {
                    temp++;
                    ans = Math.Max(ans, temp);
                }
                else
                {
                    temp = 0;
                }
            }

            Console.WriteLine(ans);

        }

        int ri() { return int.Parse(Console.ReadLine()); }
        long rl() { return long.Parse(Console.ReadLine()); }
        double rd() { return double.Parse(Console.ReadLine()); }
        string rs() { return Console.ReadLine(); }

        int[] ria() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray(); }
        long[] rla() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray(); }
        double[] rda() { return Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray(); }
        string[] rsa() { return Console.ReadLine().Split(' '); }

    }

    public class Program
    {
        static void Main()
        {
            var solver = new Solver();
            solver.Solve();
        }
    }
}

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

int main(){
     
     int E,Y;
     cin>>E>>Y;

     if(E==0){
         if(1868<=Y&&Y<=1911) cout<<"M"<<Y-1867<<endl;
         else if(1912<=Y&&Y<=1925) cout<<"T"<<Y-1911<<endl;
         else if(1926<=Y&&Y<=1988) cout<<"S"<<Y-1925<<endl;
         else cout<<"H"<<Y-1988<<endl;
     }else if(E==1) cout<<Y+1867<<endl;
      else if(E==2) cout<<Y+1911<<endl;
      else if(E==3) cout<<Y+1925<<endl;
      else cout<<Y+1988<<endl;
    
    return 0;
}


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

ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

vector<pair<ll,int>> factorize(ll n) {
  vector<pair<ll,int>> res;
  for (ll i = 2; i*i <= n; ++i) {
    if (n%i) continue;
    res.emplace_back(i,0);
    while (n%i == 0) {
      n /= i;
      res.back().second++;
    }
  }
  if (n != 1) res.emplace_back(n,1);
  return res;
}

int main() {
  ll a, b;
  cin >> a >> b;
  ll g = gcd(a,b);
  auto f = factorize(g);
  int ans = f.size() + 1;
  cout << ans << endl;
  return 0;
}

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,n,a) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using ll = long long;
using v_int = std::vector<int>;
using v2_int = std::vector<v_int>;
using v_ll = std::vector<ll>;
using v2_ll = std::vector<v_ll>;
using v_string = std::vector<std::string>;
using v_bool = std::vector<bool>;
using v2_bool = std::vector<v_bool>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using mii = std::map<int, int>;
using mll = std::map<ll, ll>;

const double PI = 3.1415926535897932;
const int INF = 2*(int)1e9;
const ll LINF = (ll)1e18;
const ll MOD = 1000000007;
//const int dc[4] = {1, -1, 0,  0};
//const int dr[4] = {0,  0, 1, -1};
const int dc[8] = {1, -1, 0,  0, 1, -1,  1, -1};
const int dr[8] = {0,  0, 1, -1, 1,  1, -1, -1};

using namespace std; 

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p)
{
    return o << "{" << p.first << "," << p.second << "}";
}

template<typename T, typename U, typename V> inline
ostream& operator<<(ostream &o, tuple<T,U,V> &p)
{
    return o << "{" << get<0>(p) << "," << get<1>(p) << "," << get<2>(p) << "}";
}

template<typename T> inline
istream& operator>>(istream &is, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) {
        is >> v[i]; 
    }
    return is;
}

template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) { 
        os << v[i];
        if(i != len-1) { os << ","; } 
    } 
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }

template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    int n;
    cin >> n;
    
    v_int a(100001);
    irep(i, n) {
        int tmp;
        cin >> tmp;
        a[tmp]++;
    }

    int even = 0;
    int cnt = 0;
    irep2(i, 1, 100001) {
        if(a[i] != 0 && a[i] % 2 == 0) { even++; }
        if(a[i]) { cnt++; }
    }
    
    cout << cnt - (even % 2) << endl;

    return 0;
}

/*atcoder*/


Measured memory_bytes: 3792
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <cctype>

using namespace std;

struct process{
	string name;
	int time;
};

int main(){
	int n, q, t = 0;
	process p;
	queue<process> que;
	cin >> n >> q;
	for (int i = 0; i < n; i++){
		cin >> p.name >> p.time;
		que.push(p);
	}
	while (!que.empty()){
		p = que.front();
		que.pop();
		if (p.time > q){
			p.time -= q;
			que.push(p);
			t += q;
		}
		else {
			t += p.time;
			cout << p.name << " " << t << endl;
		}
	}
}

Measured memory_bytes: 6224
def main():
    S = input()
    if S.count('R') != 0:
        out = 1
    else:
        out = 0
    if S == 'RRR':
        out = 3
    if (S == 'SRR') or (S == 'RRS'):
        out = 2
    print(out)


if __name__ == '__main__':
    main()


Measured memory_bytes: 8904
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int K, X;	
	cin >> K >> X;
  	int s,e;
	s = max(-1000000, X-K+1);
  	e = min(X+K-1, 1000000);
	for(int i = s; i < e; i++){
    	cout << i << ' ';
    }
  	cout << e << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;


ll n, k, r, s, p, total;
string t;
int f[100005];

int main() {

	cin >> n >> k >> r >> s >> p >> t;

	rep(i, n) {
		if (i >= k && f[i - k] == 1 && t[i] == t[i - k])continue;
		if (t[i] == 'r') total += p;
		if (t[i] == 's') total += r;
		if (t[i] == 'p') total += s;
		f[i] = 1;
	}

	cout << total << endl;

	return 0;
}


Measured memory_bytes: 896
#include<stdio.h>
#include<stdlib.h>
#define mymalloc(p,n) {p = malloc((n)*sizeof(*p));if ((p)==NULL) {printf("not enough memory?\n"); exit(1);};}

typedef struct node{
	struct node *parent;
	struct node *right;
	struct node *left;
	int id;
	int degree;
	int depth;
	int height;
	int sibling;
}node;

node *createNode(){
	node *node;
	mymalloc(node,1);
	node->parent=NULL;
	node->right=NULL;
	node->left=NULL;
	node->id=0;
	node->degree=0;
	node->depth=0;
	node->height=0;
	return node;
}

node **readNode(int n){
	int i,id,left,right;
	node **T;
	mymalloc(T,n);
	for(i=0;i<n;i++){
		T[i]=createNode();
	}
	for(i=0;i<n;i++){
		scanf(" %d %d %d",&id,&left,&right);
		T[id]->id=id;
		if(left!=-1){
			T[id]->left=T[left];
			T[left]->parent=T[id];
		}
		if(right!=-1){
			T[id]->right=T[right];
			T[right]->parent=T[id];
		}
	}
	return T;
}

node *returnRoot(node **T,int n){
	int i;
	for(i=0;i<n;i++){
		if(T[i]->parent==NULL){
			return T[i];
		}
	}
}

int calcDepth(node *root,int depth){
	int degree,height1,height2;
	degree=0;height1=0;height2=0;
	root->depth=depth;
	if(root->left!=NULL){
		height1=calcDepth(root->left,depth+1);
		degree++;
	}
	if(root->right!=NULL){
		height2=calcDepth(root->right,depth+1);
		degree++;
	}
	root->degree=degree;
	if(root->degree==0){
		root->height=0;
	}else{
	if(height1>height2){
		root->height=height1+1;
	}else{
		root->height=height2+1;
	}}
	
	return root->height;
}

void printNode(node **T,int n){
	int i;
	node *sibling;
	for(i=0;i<n;i++){
		printf("node %d: ",T[i]->id);
		if(T[i]->parent==NULL){
			printf("parent = -1, ");
			printf("sibling = -1, ");
		}else{
			printf("parent = %d, ",T[i]->parent->id);
			if(T[i]->parent->degree==2){
				if(T[i]->parent->left!=T[i]){
					printf("sibling = %d, ",T[i]->parent->left->id);
				}else{
					printf("sibling = %d, ",T[i]->parent->right->id);
				}
			}else{
				printf("sibling = -1, ");
			}
		}
		printf("degree = %d, ", T[i]->degree);
		printf("depth = %d, ", T[i]->depth);
		printf("height = %d, ", T[i]->height);
		if(T[i]->parent==NULL){
			printf("root\n");
		}else{
		if(T[i]->degree!=0){
			printf("internal node\n");
		}else{
			printf("leaf\n");
		}}
	}
}

void freeNode(node **T,int n){
	int i;
	for(i=0;i<n;i++){
		free(T[i]);
	}
	free(T);
}

main(){
	int n;
	node **T;
	node *root;
	scanf("%d",&n);
	T=readNode(n);
	root=returnRoot(T,n);
	calcDepth(root,0);
	printNode(T,n);
	freeNode(T,n);
	return 0;
}

Measured memory_bytes: 612
#include <algorithm>
#include <iostream>
#include <map>

using namespace std;

#define fst first
#define snd second
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
typedef pair<int,int> pii;


int dp[1010][1010];

int w[1010];
int c[1010];

int W;
int n;

int loop=1;

int main(void){
	while(cin >> W,W){
		rep(i,1010)rep(j,1010) dp[i][j]=0;

		cin >> n;
		rep(i,n){
			char tmp;
			cin >> c[i] >> tmp >> w[i];
		}


		rep(i,n)rep(j,W+1){
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
			if(j+w[i]<=W)
				dp[i+1][j+w[i]]=max(dp[i+1][j+w[i]],dp[i][j]+c[i]);
		}

		int cans=0;
		int wans=-1;

		rep(j,W+1){
			if(dp[n][j] > cans){
				cans=dp[n][j];
				wans=j;
			}
		}

		cout << "Case " << loop++ << ":" << endl;
		cout << cans << endl;
		cout << wans << endl;
		//cout << dp[1][10] << endl;
	}
	return 0;
}

Measured memory_bytes: 5156
#include<stdio.h>
#include<iostream>
using namespace std;
int d[1000000]={0};
int s[1000000]={0};
int main(void){
	int n=0;
	int a=0;
	int max=0;
	int i=0;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>d[i];
		a+=d[i];
	}
	if(d[0]<10){
		cout<<"no"<<endl;
		return 0; 
	}
	for(i=1,max=d[0]/10;(i<=max)&&(i<n);++i){
		if(max<d[i]/10+i){//(d[i]/10)+i
			max=i+d[i]/10;
		}
	}
	if(i!=n){
		cout<<"no"<<endl;
		return 0;
	}
	if(d[n-1]<10){
		cout<<"no"<<endl;
		return 0; 
	}
	for(i=n-2,max=d[n-1]/10;((n-1)-i<=max)&&(i>=0);i--){//when can go right end
		if(max<d[i]/10+(n-1)-i){//(d[i]/10)+i//update max value
			max=d[i]/10+(n-1)-i;
		}
	}
	if(i!=-1){
		cout<<"no"<<endl;
		return 0;
	}
	else if(i==-1){
		cout<<"yes"<<endl;
		return 0;
	}
	return 0;
}


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

int main()
{
int a,b,c,A,B,C,x,y,z,i,n;
for(i=0;i<3;i++){
cin>>a>>b>>c>>A>>B>>C;
n=(3600*A+60*B+C)-(3600*a+60*b+c);
x=n/3600;
y=(n-3600*x)/60;
z=n-(3600*x+60*y);
cout<<x<<' '<<y<<' '<<z<<'\n';
}
return 0;
}

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

int main(){
  ll n,power=1;
  cin >> n;
  while(n--){
    power*=n+1;
    power=power%1000000007;
  }
  cout << power <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    string s; cin >> s;
    for(int i=0; i<s.size()-1; i++){
        if(s[i] == 'A' && s[i+1] == 'C'){
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

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

int main(void){
    int n, k;
    std::cin >> n >> k;
    std::vector<int> p(n);
    for(int i = 0; i < n; i++){
	std::cin >> p[i];
    }
    std::sort(p.begin(), p.end());

    int sum = 0;
    for(int i = 0; i < k; i++){
	sum += p[i];
    }

    std::cout << sum << std::endl;

}


Measured memory_bytes: 3568
#include<iostream>

using namespace std;


int main(){
    
    int a,b,c;
    int count=0;
    cin>>a>>b>>c;
    
    for(int x=a;x<=b;x++){
        if(c%x==0){
            count++;
        }
    }
    
    cout<<count<<endl;
    
}


Measured memory_bytes: 3100
n = int(input())

c = [1 for i in range(n+1)]
c [0] = 0
if n == 1:
  print (1)
  exit()

for i in range(2,n+1):
  x = i
  while x <= n:
    c[x] += 1
    x += i
s = 0
for i in range(n+1):
  s += i * c[i]
print (s)






Measured memory_bytes: 224600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100005],n,q,k;
ll binary(ll i){
	ll lb=-1; ll ub=n;
	while(ub-lb>1){
		ll mid=(lb+ub)/2;
		if(a[mid]>=i){
			ub=mid;
		}else{
			lb=mid;
		}
	}
	return ub;
}
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>k;
        if(a[binary(k)]==k)cout<<1<<endl;
        else cout<<0<<endl;
    }
    return 0;
}


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




Measured memory_bytes: 3476
// D - Prediction and Restriction
#include <bits/stdc++.h>
using namespace std;

map<char,int> win={{'r',0},{'s',0},{'p',0}};

int main(){
	int N,K; string T;
	cin>>N>>K>>win['s']>>win['p']>>win['r']>>T;
	int ans = 0;
	for(int i=0; i<N; ++i)
		if(i >= K && T[i-K] == T[i]) T[i] = '-';
		else ans += win[T[i]];
	cout<< ans <<endl;
}

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

int main() {

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    const int lower = max(A, C);
    const int upper = min(B, D);

    cout << max(0, upper - lower) << endl;
    
    return 0;

}

Measured memory_bytes: 256
w,h,n = map(int,input().split())
minx = 0
miny = 0
maxx = w
maxy = h

for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        minx = max(minx,x)
    elif a == 2:
        maxx = min(maxx,x)
    elif a == 3:
        miny = max(miny, y)
    elif a == 4:
        maxy = min(maxy, y)
if minx > maxx or miny > maxy:
    print(0)
else:
    print((maxx-minx)*(maxy-miny))

Measured memory_bytes: 3064
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//233
	char c;
	cin>>c;
	if(c=='A')cout<<"T";
	else if(c=='T')cout<<"A";
	else if(c=='C')cout<<"G";
	else if(c=='G')cout<<"C";
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////

//verify by https://atcoder.jp/contests/nikkei2019-final/tasks/nikkei2019_final_d
//RSQ and RUQ
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
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;
}

int main(){
    int A,B,C;
    cin >> A >> B >> C;
    cout << min(C,B/A) << "\n";


}


Measured memory_bytes: 256
#include "iostream"
using namespace std;

int n,l,r,seats=0;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>l>>r;
		seats+=(r-l+1);
	}
	cout<<seats;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

const int LOG_A = 60;
ll basis[LOG_A];

ll shifts[60];

void insertVector(ll mask) {
	for (int i = LOG_A - 1; i >= 0; i--) {
		if ((mask & shifts[i]) == 0) continue;

		if (!basis[i]) {
			basis[i] = mask;
			return;
		}

		mask ^= basis[i];
	}
}
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	int N; cin >> N;
	
	ll data[N];
	shifts[0] = 1;
	FOR(i, 1, 60) shifts[i] = shifts[i-1]*2;
	ll totalXor = 0;
	F0R(i, N) {
		cin >> data[i];
		//insertVector(data[i]);
		totalXor ^= data[i];
	}
	
	F0R(i, 60) {
		if (totalXor & shifts[i]) {
			F0R(j, N) {
				if (data[j] & shifts[i]) data[j] -= shifts[i];
			}
		}
	}
	
	F0R(i, N) insertVector(data[i]);
	
	ll ans = 0;
	
	F0Rd(i, 60) {
		if (!basis[i]) continue;
		if (ans & shifts[i]) continue;
		ans ^= basis[i];
	}
	
	cout << (ans + (totalXor ^ ans)) << endl;
	//cout << ans << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 1024
//love yjl forever
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int INF=0x3f3f3f3f,N=2e5+5;
int n,k;
int a[N],b[N];
void op()
{
	int i;
	for(i=1;i<=n;i++)
		b[i]=0;
	for(i=1;i<=n;i++)
	{
		int l=max(1,i-a[i]);
		int r=min(n,i+a[i]);
		b[l]++;
		b[r+1]--;
	}
	for(i=1;i<=n;i++) b[i]+=b[i-1];
	for(i=1;i<=n;i++)
		a[i]=b[i];
}
bool check()
{
	for(int i=1;i<=n;i++)
		if(a[i]!=n) return 0;
	return 1;
}
int main()
{
/*	freopen("","r",stdin);
	freopen("","w",stdout);*/
	int i;
	cin>>n>>k;
	for(i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(i=1;i<=k;i++)
	{
		op();
		if(check()) break;
	}
	for(i=1;i<=n;i++)
		printf("%d ",a[i]);
	
}

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

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

int main() {
  int K, X;
  cin >> K >> X;
  if (K * 500 >= X)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
H, W=map(int, input().split())
S=[]
S.append("".join(["#" for _ in range(W+2)]))
S.extend(["#"+input()+"#" for _ in range(H)])
S.append("".join(["#" for _ in range(W+2)]))
co1=[[0 for _ in range(W+2)] for _ in range(H+2)]
co2=[[0 for _ in range(W+2)] for _ in range(H+2)]

for i in range(1, H+2):
    ppos=0
    for j in range(W+2):
        if S[i][j]=="#":
            if S[i][j-1]==".":
                for k in range(ppos, j):
                    co1[i][k]=j-ppos
            ppos=j+1

for j in range(1, W+2):
    ppos=0
    for i in range(H+2):
        if S[i][j]=="#":
            if S[i-1][j]==".":
                for k in range(ppos, i):
                    co2[k][j]=i-ppos
            ppos=i+1

ans=0
for i in range(1, H+2):
    for j in range(1, W+2):
        ans=max(ans, co1[i][j]+co2[i][j]-1)
print(ans)


Measured memory_bytes: 125912
#include<iostream>
#include<climits>
#include<cmath>
#include<math.h>
#include<string>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef long long ll;
using namespace std;

int main(){
    int X,Y;
    int judge = 0;
    cin >> X >> Y;
    for(int i=0;i<X+1;i++){
        if(i*2+(X-i)*4 == Y){
            judge = 1;
        }
    }
    if(judge == 1){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3132
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <vector>
#include <utility>
#include <map>
#include <set>
using namespace std;

#define REP(i, a, b) for (int(i) = int(a); (i) <= int(b); (i)++)
#define ALL(c) begin(c), end(c)
#define SIZE(c) int((c).size())
#define PB push_back
#define F first
#define S second

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main() {
	ll N;
	cin >> N; 
	ll array[3*N];
	for(int i = 0; i < 3*N; i++) {
		cin >> array[i];
	}
	sort(array, array + 3 * N);
	ll total = 0;
	for(int i = 0; i < N; i++) {
		total += array[N+2*i];
	}
	cout << total << endl;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, first, last) for (int i = (first); i < (last); ++i)
#define REP(i, n) FOR(i, 0, n)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) std::cerr << #x << " = " << (x) << std::endl;
#define DUMPR(v) REP(_i,v.size()){std::cerr<< #v << "[" << _i << "] = " << (v[_i]) << std::endl;}
#define CIN_VEC(v,N) {v.clear(); v.reserve(N); REP(i,N){typename decltype(v)::value_type x; cin>>x; v.emplace_back(x);}};

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_string(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef unsigned long long ull;
typedef unsigned long ul;

int main() {
  int N;
  cin>>N;
  vector<ull> A,B,C;

  CIN_VEC(A,N);
  CIN_VEC(B,N);
  CIN_VEC(C,N);

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

  ull ans = 0;
  // loop for B
  for(const ull b:B) {
    // find A elem less than b
    auto low = lower_bound(A.begin(), A.end(), b);
    ull na = low - A.begin();

    // find C elem greater than b
    auto up = upper_bound(C.begin(), C.end(), b);
    ull nc = C.end() - up;

    ans += na * nc;
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

typedef long long ll;

struct data{
  string name;
  int hyou;
  bool fav;
  data(const char *nm, int hy) :
    name(nm), hyou(hy), fav(false) {}
};

bool operator < (const data &lhs, const data &rhs){
  if(lhs.hyou != rhs.hyou)
    return lhs.hyou > rhs.hyou;
  return lhs.name < rhs.name;
}

int main(){
  int n, m, k, l;

  while(scanf("%d%d%d%d", &n, &m, &k, &l),
        n + m + k + l){
    vector<data> v; v.reserve(n);
    map<string, int> memo;
    vector<int> favs(m);
    REP(i,n){
      char buff[200]; int h;
      scanf("%s%d", buff, &h);
      v.push_back(data(buff, h));
    }

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

    REP(i,n)
      memo[v[i].name] = i;

    REP(i,m){
      char buff[200];
      scanf("%s", buff);
      favs[i] = memo[buff];
      v[favs[i]].fav = true;
    }

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

    int low  = 0;
    int high = min(m, k);

    while(low <= high){
      int mid = (low + high) / 2;
      bool ok = false;

      int cnt = 0;
      int i;
      for(i = 0; i < n; i++){
        if(k - i <= mid - cnt && !v[i].fav) break;
        if(v[i].fav) cnt++;
      }

      if(i == n){
        ok = true;
      }else{
        const data &border = v[i];

        ll need = 0;

        REP(j,mid){
          int id = favs[j];
          if(id <= i) continue;
          const data &now = v[id];
          if(now.name < border.name){
            need += border.hyou - now.hyou;
          }else{
            need += border.hyou - now.hyou + 1;
          }
        }

        if(need <= l) ok = true;
        //printf("%d: %d (%d) %lld\n", mid, ok, i, need);
      }

      if(ok){
        low  = mid + 1;
      }else{
        high = mid - 1;
      }
    }

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

  return 0;
}

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

int main()
{
    int r, d, x2000;
    vector<int> x(10);
    cin >> r >> d >> x2000;
    x[0] = r * x2000 - d;
    cout << x[0] << endl;
    for (int i = 1; i < 10; i++)
    {
        x[i] = r * x[i - 1] - d;
        cout << x[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s,str="hi";
int main(){
	cin>>s;
	if(s.size()%2){
		cout<<"No";
		return 0;
	}
	for(int i=0;s[i];i++)
		if(s[i]!=str[i%2]){
			cout<<"No";
			return 0;
		}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  var N1 = parseInt(input[0].split(" ")[0]);
  var N2 = parseInt(input[0].split(" ")[1]);
  var N3 = parseInt(input[0].split(" ")[2]);
  var N4 = parseInt(input[0].split(" ")[3]);
  N = new Array(N1,N2,N3,N4);
  var ans = "NO";
  N.sort(function(a, b) {
    return a-b;
});
  NN=(parseInt(N.join("")));
  if(NN==1479){
    ans="YES";
  }


  
  
  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            String[] S = new String[N];
            for (int i = 0; i < N; i++) {
                S[i] = in.next();
            }

            ArrayList<String> list = new ArrayList<>();
            for (int i = 0; i < N; i++) {
                char[] cs = S[i].toCharArray();
                Arrays.sort(cs);
                list.add(new String(cs));
            }
            Collections.sort(list);

            long res = 0;
            long count = 1;
            for (int i = 1; i < list.size(); i++) {
                if (list.get(i - 1).equals(list.get(i))) {
                    count++;
                } else {
                    res += (count * (count - 1)) / 2;
                    count = 1;
                }
            }
            res += (count * (count - 1)) / 2;

            System.out.println(res);
        }
    }
}


Measured memory_bytes: 57204
import numpy as np
a = np.arange(1, 100001)
t = np.ones([len(a)], dtype=bool)
for i in range(1, 50000):
    t[i + a[i]::a[i]] = False
t[0] = False
s = [0, 0]
for i in range(2, 100000):
    if i % 2:
        s.append(s[-1])
    else:
        if t[i] and t[(i + 2) // 2 - 1]:
            s.append(s[-1] + 1)
        else:
            s.append(s[-1])
Q = int(input())
ans = []
for i in range(Q):
    L, R = map(int, input().split())
    if L == 1:
        ans.append(s[R - 1])
    else:
        ans.append(s[R - 1] - s[L - 2])
for i in range(Q):
    print(ans[i])

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

int main() {
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  int X=(A+D-1)/D;
  int Y=(C+B-1)/B;
  cout<<(X>=Y?"Yes":"No")<<"\n";
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip> 

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;

int main() {
    int n, k;
    cin >> n >> k;
    int p[n];

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

    vector<bool> win(k+1, false);

    for (int i = 1; i <= k; i++) {
        for (int j = 0; j < n; j++) {
            if (i >= p[j]) {
                win[i] = win[i] | !win[i-p[j]];
            }
        }
    }
    cout << (win[k] ? "First" : "Second") << endl;
    return 0;
}



Measured memory_bytes: 256
var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
    input += chunk;
});
process.stdin.on('end', function() {
    input = input.split('\n');
    main();
});

function main() {
    var
    i,
    n = +input[0],
    lines = input.slice(1);
    for(i = 0; i < n; i++) {
        console.log(calc(lines[i]));
    }
}

function calc(src) {
    src = src.replace(/([-+*\/()=])/g, ' $1 ').split(' ').filter(function(s) {
        return s.trim() !== '';
    });
    return add(src);

    function add(src) {
        var
        ret = mul(src);
        while(src[0] in {'+': 1,'-': 1}) {
            switch(src.shift()) {
            case '+':
                ret += mul(src);
                break;
            case '-':
                ret -= mul(src);
                break;
            }
        }
        return ret;
    }

    function mul(src) {
        var
        val, sign,
        ret = prim(src);
        while(src[0] in {'*': 1,'/': 1}) {
            switch(src.shift()) {
            case '*':
                ret *= prim(src);
                break;
            case '/':
                val = prim(src);
                sign = ret * val < 0 ? -1 : 1;
                ret = sign * Math.floor(Math.abs(ret) / Math.abs(val));
                break;
            }
        }
        return ret;
    }

    function prim(src) {
        var
        ret, 
        head = src.shift();
        switch(head) {
        case '+':
           return prim(src);
        case '-':
           return -prim(src);
        case '(':
           ret = add(src);
           src.shift();
           return ret;
        default:
           return parseInt(head, 10);
        }
    }
}

Measured memory_bytes: 9788
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
//#include <function>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


int main() {

  int N;
  cin >> N;
  vector<int> H(N);
  REP(i, N) cin >> H[i];

  int tmp = H[0];
  int count = 0;

  REP(i, N){
    if (tmp <= H[i]){
      count++;
      tmp = H[i];
    }
  }

  cout << count << endl;
  return 0;
}


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

#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define mt make_tuple
#define int long long
#define OK puts("OK")
#define sz(s) (int)s.size()
#define all(s) s.begin(), s.end()

using namespace std;


int N, X[1009], Y[1009], H[1009];
vector< tuple < int , int , int > > v;

 main() {
	cin >> N;
	tuple < int , int , int > G = mt ( -1 , -1 , -1 ) ;
	for (int i = 1; i <= N; i++)
    {
		cin >> X[i] >> Y[i] >> H[i];
		if ( H[i] >= 1)
		G = mt (X[i], Y[i], H[i]);
	}
    for (int j = 0; j <= 100; j++)
	 {
	   for (int i = 0; i <= 100; i++)
        {
			int V = get<2> (G) + abs ( get<0> (G) - i) + abs(get<1>(G) - j);
            V = max(V, 0LL);
            bool f = true;

			for (int k = 1; k <= N; k++)
            {
				int VV = V - abs( X[k] - i) - abs ( Y[k] - j );
                VV = max(VV, 0LL);
				if (H[k] != VV)
                    f = false;
			}
			if (f == true)
                v.push_back(make_tuple(i, j, V));
		}
	}

    cout << get<0> ( v[0] ) << " " << get<1> ( v[0] ) << " " << get<2> (v[0]) << endl;

}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>

using namespace std;

uint64_t swap(uint64_t xx, uint64_t kw);

int main()
{
    uint64_t nn;
    uint64_t temp_nn = 0;
    uint64_t kk;
    cin >> nn >> kk;
    temp_nn = nn;
    if(nn >= kk)
        temp_nn = nn % kk;
    
    while(temp_nn > swap(temp_nn, kk)){
        temp_nn = swap(temp_nn, kk);
    }

    cout << temp_nn << endl;
    return 0;
}

uint64_t swap(uint64_t xx, uint64_t kw){
    if(xx >= kw){
        return (xx - kw);
    }else{
        return (kw - xx);
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

int n, m, q;
vector<int> a,b,c,d;
int ans = 0;

void dfs(vector<int> v){
    if(v.size()==n+1){
        //cout<<"Yes"<<endl;
        int now = 0;
        rep(i,q){
            if(v[b[i]]-v[a[i]]==c[i]) now+=d[i];
        }
        ans = max(ans,now);
        return ;
    }
    v.push_back(v.back());
    while(v.back()<=m){
        //out<<"No"<<endl;
        dfs(v);
        v.back()++;
    }
}

int main(){
    cin >> n >> m >> q;

    a=b=c=d=vector<int>(q);

    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    dfs(vector<int>(1,1));
    cout<< ans << endl;

    return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits.h>

template<typename T>
T Input()
{
	T value;
	std::cin >> value;
	return value;
}

int main()
{
	std::ios::sync_with_stdio(false);
	int num, max, min;
	std::vector<int> arr(200000);
	std::cin >> num;
	for (auto i = 0; i < num; ++i)
		arr[i] = Input<int>();
	min = arr[0];
	max = INT_MIN;
	for (auto i = 1; i < num; ++i)
	{
		max = std::max(max, arr[i] - min);
		min = std::min(min, arr[i]);
	}

	std::cout << max << "\n";

	return 0;
}

Measured memory_bytes: 1792
#include <queue>
#include <iostream>
#include <algorithm>
#define ll long long
#define INF 100000000000000
using namespace std;
int main(){
  ios_base::sync_with_stdio(false);
  ll V, E, r;
  cin >> V >> E >> r;
  vector< vector< pair<ll,ll> > > edges(V);
  ll dist[V];
  for(ll i = 0; i < V; i++){
    dist[i] = INF;
  }
  for(ll i = 0; i < E; i++){
    ll s,t,d;
    cin >> s >> t >> d;
    edges[s].push_back(make_pair(t,d));
  }

  dist[r] = 0;

  for(ll i = 0; i < V; i++){
    for(ll k = 0; k < V; k++){
      if(dist[k] != INF){
	for(pair<ll,ll> edge: edges[k]){
	  if(dist[edge.first] > dist[k] + edge.second){
	    if(i == V - 1){
	      cout << "NEGATIVE CYCLE" << endl;
	      return 0;
	    }
	    dist[edge.first] = dist[k] + edge.second;
	  }
	}
      }
    }
  }
  for(ll i = 0; i < V; i++){
    if(dist[i] == INF)
      cout << "INF" << endl;
    else
      cout << dist[i] << endl;
  }
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N; cin >> N;
    int A[N]; rep(i, N) cin >> A[i];
    int sum = 0;
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            sum += A[i]*A[j];
        }
    }
    cout << sum << endl;
    return 0;
}

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

const int MAX = 100000;
const int MOD = 1000000007;

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;
}
// 計算例 COM(100000, 50000)

long long modinv(long long a) {
    long long b = MOD, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u = u%MOD;
    if (u < 0) u += MOD;
    return u;
}

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        n >>= 1;
    }
    return res;
}

long long oneminus(long long a){
	//return 1-a % MOD
	if (1-a < 0) {
		return (1-a)+MOD;
	} else {
		return 1-a;
	}
}

int main(void){
	long long int n,i,ans=0,temp,teninv;
	cin >> n;
	/*teninv = modinv(10);
	//COMinit();
	for (i=0;i<n-1;i++) {
		temp = ((modpow(8,i))*(modpow(10,n-2-i)*(oneminus(modpow((9*teninv)%MOD,n-1-i)))*10)) % MOD;
		ans += temp;
		ans = ans%MOD;
//cout << temp << '\n';
	}
	ans *= 2;
	ans = ans%MOD;*/
	ans = modpow(10,n)+modpow(8,n)-(2*modpow(9,n));
	ans = ans % MOD;
	if (ans < 0) ans += MOD;
	cout << ans << '\n';
}


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

void doRoutine() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    srand(322179);
#ifdef LOCAL
    freopen("/root/alg/clion_main/input.txt", "rt", stdin);
    freopen("/root/alg/clion_main/output.txt", "wt", stdout);
#endif
}

#define DBG(VAR) cerr << #VAR << ": " << VAR << endl

#define all(x) x.begin(), x.end()
#define vb vector<bool>
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define vc vector

#ifndef LOCAL
#define cerr if(0) cerr
#define DBG(...) (true)
#endif

#define D double
#define int long long

// ----------------------------- CODE NOW ------------------------




signed main() {
    doRoutine();

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

    int ans = 0;
    for (int i = 0; i < n;) {
        int j = i;
        while (j < n && a[j] == a[i]) {
            ++j;
        }
        ans += (j - i) / 2;
        i = j;
    }

    cout << ans << endl;

    return 0;
}

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

int main()
{
    int n;
	list<int> lst;

	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int tmp;
		cin >> tmp;
		lst.push_back(tmp);
	}

	lst.sort();
	int answer = 0;
	int sabun = lst.back() + 1;
	double mid = lst.back() / 2.0;

	for (auto ite = lst.begin(); ite != lst.end(); ite++)
	{
		double diff = abs(mid - (double)*ite);
		if (sabun > diff)
		{
			sabun = diff;
			answer = *ite;
		}
	}

	cout << lst.back() << " " << answer;

	return 0;
}


Measured memory_bytes: 3328
#![allow(non_snake_case)]

//use itertools::Itertools as _;
use permutohedron::LexicalPermutation as _;
use num::traits::One; // One is an unit for multipolication
use petgraph::graph::{IndexType, NodeIndex, UnGraph};
use proconio::input;
use proconio::source::{Readable, Source};

// use std::collections::HashMap;
use std::io::BufRead;
use std::marker::PhantomData;
use std::ops::Sub;

fn main() {
    input! {
        _: usize,
        m: usize,
        r: usize,
        rs: [NodeIndex1<u32>; r],
        abcs: [(NodeIndex1<u32>, NodeIndex1<u32>,u32);m],
    }
    // for abc in abcs{
    //     let (a,b,c) = abc;
    //     println!("{} {} {}", a.index(),b.index(),c);
    // }
    let graph = UnGraph::<(),u32>::from_edges(&abcs);
    let mut towns: Vec<Vec<u32>> = vec![vec![0;r];r];
    for i in 0..r{
        let dijkstra = petgraph::algo::dijkstra(&graph, rs[i], None, |e| *e.weight());
        for j in 0..r{
            towns[i][j] = dijkstra[&rs[j]];
        }
    }
    // for &s in &rs{
    //     let dijkstra = petgraph::algo::dijkstra(&graph, s, None, |e| *e.weight());
    //     for &t in &rs{
    //         towns[s.index()][t.index()] = dijkstra[&t];
    //     }
    // }
    let mut ans:u32 = 1000000000;
    // if m == 1{
    //     ans = 0;
    // }
    let mut values:Vec<usize> = (0..r).collect();
    loop {
        let mut temp_ans: u32 = 0;
        for i in 0..(r-1){
            temp_ans += towns[values[i]][values[i+1]];
        }
        if temp_ans < ans{
            ans = temp_ans;
        }
        if !values.next_permutation() {
            break
        }
    }
    println!("{}", ans);
}


struct NodeIndex1<Ix>(PhantomData<fn() -> Ix>);
// Ix型

impl<Ix: IndexType + Readable<Output = Ix> + One + Sub<Output = Ix>> Readable for NodeIndex1<Ix> {
    // input!でR読み込むには、eadable traitを実装する必要がある
    // https://docs.rs/proconio/0.3.4/proconio/source/trait.Readable.html
    type Output = NodeIndex<Ix>;

    fn read<R: BufRead, S: Source<R>>(source: &mut S) -> NodeIndex<Ix> {
        NodeIndex::from(Ix::read(source) - Ix::one())
    }
}


Measured memory_bytes: 3104