akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;

#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;

const ll MOD = (ll)1e9 + 7;
const ll MOD2 = 998244353;
const ll LLINF = (ll)1e18;
const ll INTINF = (ll)1e9;
const long double PI = 3.1415926535897932384626433;

template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max<T>(a,b);}
template <class T> void chmin(T& a, const T b){a=min<T>(a,b);}
void YN(bool flg) {cout << ((flg) ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << ((flg) ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << ((flg) ? "yes" : "no") << endl;}

int main() {
	int N; cin >> N;
	V<ll> a(N); REP(i,N) cin >> a[i];
	auto b = a;
	V<ll> c(N,0),d(N);
	for(int i = 0; i < N-1; ++i){
		if(b[i]<0){
			c[i]++;
			b[i] *= -1;
			b[i+1] *= -1;
		}
	}
	b = a;
	for(int i = N-1; 0 < i; --i){
		if(b[i]<0){
			d[i]++;
			b[i] *= -1;
			b[i-1] *= -1;
		}
	}
	ll sum = 0;
	for(int i = 0; i < N; ++i) sum += abs(a[i]);
	
	ll ans = 0;
	ll cnt = 0;
	
	cnt = sum - abs(a[0]) + (d[1]?-1:1)*a[0];
	chmax(ans,cnt);
	for(int i = 1; i+1<N; ++i){
		cnt = sum - abs(a[i]) + ((c[i-1]+d[i+1])%2?-1:1)*a[i];
		chmax(ans,cnt);
	}
	cnt = sum - abs(a[N-1]) + (c[N-2]?-1:1)*a[N-1];
	chmax(ans,cnt);
	cout << ans << endl;
	return 0;
}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;

constexpr int MOD = 1000000007;

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

    int n, m;
    cin >> n >> m;

    vi c(m);
    rep(i, 0, m) { cin >> c[i]; }

    vi dp(n + 1, INT_MAX);

    dp[0] = 0;
    rep(i, 1, n + 1) {
        rep(j, 0, m) {
            if (i - c[j] >= 0) { dp[i] = min(dp[i], dp[i - c[j]] + 1); }
        }
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, begin, end) for(ll i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(ll i=(begin)-1;i>=(end);i--)
#define IREP(i, n) IFOR(i,n,0)
#define SORT(a) sort(a.begin(), a.end())	//昇順
#define ISORT(a) sort(a.begin(), a.end(),greater<ll>())	//降順
#define REVERSE(a) reverse(a.begin(), a.end())
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=(" << v[0]; FOR(i_debug, 1, v.size()){ cout << "," << v[i_debug]; } cout << ")" << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)

#define ll long long
#define ld long double
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define INF 1000000000000000000


using vec = vector<ll>;
using mat = vector<vec>;
using Pii = pair<ll, ll>;
using PiP = pair<ll, Pii>;
using PPi = pair<Pii, ll>;
using bvec = vector<bool>;
using Pvec = vector<Pii>;


template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

ll mod = 1000000007;

int main()
{
	stringstream ss;
    // 入力
    ll N;
    cin>>N;

    ll ans=0;
    if(N%2==0) {
    	ans=N/2-1;
    }
    else {
    	ans=(N-1)/2;
    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn._

object Main extends App {
  def sumTo(n: Long): Long = n * (n + 1) / 2
  def calc(s: String): Array[Long] = s.split("(?<=>)(?=<)").map {
     _.split("(?<=<)(?=>)") match {
      case Array(l, r) => 
        val max = Math.max(l.size, r.size)
        val min = Math.min(l.size, r.size)
        sumTo(max) + sumTo(min - 1)
      case Array(u) => sumTo(u.size)
     }
  }
  println(calc(readLine).sum)
}

Measured memory_bytes: 94448
#include <bits/stdc++.h>
using namespace std;
#ifdef __DEBUG__
    void debug_out() { cerr << endl; } 
    template <typename Head, typename... Tail>
    void debug_out(Head H, Tail... T) {cerr << " " << H; debug_out(T...);}
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 
#endif

using ll = long long int;

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#include <atcoder/modint>
#include <atcoder/convolution>
using modint = atcoder::modint998244353;

int N;
vector<int> H;
inline void input(){
    fast_io();
    cin >> N;
    H = fetch_vec<int>(2*N);
}

int solve(){
    vector<modint> fact(2*N+1), revfact(2*N+1);
    fact[0] = fact[1] = 1;
    for (int i = 0; i < 2*N; i++) fact[i+1] = fact[i]*(i+1);
    revfact[2*N] = fact[2*N].inv();
    for (int i = 2*N-1; i >= 0; i--) revfact[i] = revfact[i+1]*(i+1);

    // modint ans = fact[2*N]*revfact[N]*modint(2).pow(N).inv();
    map<int, int> cnt;
    for(auto h:H) cnt[h]++;
    vector<ll> nums;
    for(auto [h,c]:cnt) nums.emplace_back(c);
    int K = nums.size();
    sort(nums.begin(),nums.end());
    deque<vector<modint> > q;
    for (int k = 0; k < K; k++)
    {
        ll n = nums[k];
        vector<modint> tmp;
        for (int i = 0; 2*i <= n; i++)
        {
            tmp.push_back(fact[n]*revfact[i]*revfact[n-2*i]*modint(2).pow(i).inv());
        }
        q.push_back(tmp);
    }
    auto cmp = [](vector<modint> a, vector<modint> b){return a.size() < b.size();};
    sort(q.begin(), q.end(), cmp);

    while(q.size()>1){
        vector<modint> c = atcoder::convolution(q[0], q[1]);
        q.push_back(c);
        q.pop_front();
        q.pop_front();
    }
    
    vector<modint> d = q.front();
    modint ans = 0;
    for (int k = 0; k < min((int)d.size(), N+1); k++)
    {
        modint ans_k = d[k]*fact[2*N-2*k]*revfact[N-k]*modint(2).pow(N-k).inv();
        if(k%2) ans -= ans_k;
        else ans += ans_k;
    }
    cout << ans.val() << "\n";
    return 0;
}   

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


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

int n;
vector<pair<int,int>> x, y;

double find_size(double mid)  {
	double mn = 2e18, mx = -2e18;
	for (int i = 0; i < n; ++i) {
		mn = min(mn, x[i].first + x[i].second * mid);
		mx = max(mx, x[i].first + x[i].second * mid);
	}
	double sz = (mx - mn);
	mn = 2e18, mx = -2e18;
	for (int i = 0; i < n; ++i) {
		mn = min(mn, y[i].first + y[i].second * mid);
		mx = max(mx, y[i].first + y[i].second * mid);
	}
	sz *= (mx - mn);
	return sz;
}

int main(int argc, char **argv) {
	cin >> n;
	x.resize(n);
	y.resize(n);
	for (int i = 0; i < n; ++i) {
		char d;
		int a, b;
		cin >> a >> b >> d;
		switch (d) {
			case 'L':
				x[i] = {a, -1};
				y[i] = {b, 0};
				break;
			case 'R':
				x[i] = {a, 1};
				y[i] = {b, 0};
				break;
			case 'D':
				x[i] = {a, 0};
				y[i] = {b, -1};
				break;
			case 'U':
				x[i] = {a, 0};
				y[i] = {b, 1};
				break;
		}
	}

	double lo = 0., hi = 1e12;
	for (int i = 0; i < 500; ++i) {
		double t1 = lo + (hi - lo) / 3.;
		double t2 = lo + (hi - lo) / 3. * 2;
		if (find_size(t1) < find_size(t2))
			hi = t2;
		else
			lo = t1;
	}

	cout << fixed;
	cout.precision(9);
	cout << find_size(lo) << '\n';

	return 0;
}



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


void solve()
{
    string str="ACL";
    int k;
    cin>>k;string ans = "";
    while(k--)
        ans+=str;
    cout<<ans<<endl;

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

    ll t;
    solve();
}





Measured memory_bytes: 3648
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t N;
	std::cin >> N;
	std::vector<int64_t> a(N);
	for (int64_t i = 0; i < N; i++)
	{
		std::cin >> a[i];
	}

	int64_t ans = 0;
	int64_t current = 1;

	for (int64_t i = 0; i < N; i++)
	{
		if (a[i] == current)
		{
			current++;
		}
		else
		{
			ans++;
		}
	}

	if (current == 1) ans = -1;

	std::cout << ans << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	solve();
}


Measured memory_bytes: 4712
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) c.begin(),c.end()
static const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
static const int MOD = (int)(1e9 + 7);

signed main() {
	int r, c; cin >> r >> c;
	vector<vector<int>> v(r+1, vector<int>(c+1, 0));
	rep(i, 0, r) rep(j, 0, c) cin >> v[i][j];
	rep(i, 0, r) {
		v[i][c] = accumulate(v[i].begin(), v[i].end(), 0);
	}
	rep(j, 0, c+1) {
		rep(i, 0, r) {
			v[r][j] += v[i][j];
		}
	}
	rep(i, 0, v.size()) {
		cout << v[i][0];
		rep(j, 1, v[i].size()) { cout << " " << v[i][j]; }
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    vector<int> h(n);
    for(int i = 0;i<n;i++){
        cin >> h[i];
    }

    vector<int> flag(n,1);
    for(int i = 0;i<m;i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        if(h[a] > h[b]){
            flag[b]=0;
        }else if(h[b] > h[a]){
            flag[a]=0;
        }else{
            flag[a]=0;
            flag[b]=0;
        }
    }
    int ans = 0;
    for(int i = 0; i<n;i++){
        if(flag[i] > 0) ans++;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 3988
#include <iostream>
#include <vector>

using namespace std;

bool can_load(int n, int k, vector<int>& w, int P)
{
	int cost = 0, cnt = 0;
	for (int i = 0; i < n; ++i)
	{
		cost += w[i];
		while (cost > P)
		{
			cost = w[i];
			cnt++;
			if (cnt == k)
				return false;
		}
	}

	return true;
}

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

	int n, k;
	cin >> n >> k;

	vector<int> w(n);
	int sum = 0;
	for (int i = 0; i < n; ++i)
		cin >> w[i], sum += w[i];

	// Binary Search
	int left = sum / k;
	int right = sum;
	while (left < right)
	{
		int P = (left + right) / 2;
		if (can_load(n, k, w, P))
			right = P;
		else
			left = P + 1;
	}

	cout << left << endl;

	return 0;
}

Measured memory_bytes: 1532
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define fi first
#define se second
#define db double
#define ld long db
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline int read(){
	ri x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline ll readll(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

const int N=1005,p=1e9+7;
int n,k,a[N],f[25][N],c[N][N];
inline void add(ri &x,ri y){x+=y;x>=p?x-=p:0;}
inline int add2(ri x,ri y){x+=y;return x>=p?x-p:x;}
int main()
{
	n=read();k=read();
	rep(i,1,k)a[i]=read();
	c[0][0]=1;
	rep(i,1,n){
		c[i][0]=1;
		rep(j,1,i)c[i][j]=add2(c[i-1][j],c[i-1][j-1]);
	}
	f[0][0]=1;
	rep(i,1,k)rep(j,0,n)rep(l,0,min(a[i],j)){
		add(f[i][j],(ll)f[i-1][j-l]*c[j][l]%p*c[n-l][n-a[i]]%p);
	}
	printf("%d\n",f[k][n]);
	return 0; 
}

Measured memory_bytes: 4224
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main{

	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-9;

	void run(){
		for(;;){
			int n=sc.nextInt();
			int m=sc.nextInt();
			if((n|m)==0){
				break;
			}
			int[] a=new int[n];
			for(int i=0; i<n; i++){
				a[i]=sc.nextInt();
			}
			Arrays.sort(a);
			int sum=0;
			for(int i=1; i<=n; i++){
				if(i%m!=0){
					sum+=a[n-i];
				}
			}
			println(sum+"");
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

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

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

    for(int i=1; i<=9; ++i){
        for(int j=1; j<=9; ++j){
            std::cout << i << "x" << j << "=" << i*j << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 3032
k = int(input())
a, b = [int(i) for i in input().split()]

kk = a // k
kk = k*kk

while(kk <= 1000):
    if(kk <= b and kk >= a):
        print("OK")
        exit()
    #print(kk)
    kk = kk + k
    #j = j + 1

print("NG")


Measured memory_bytes: 9116
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {
        String[] in = null;
        ArrayList<Integer> a = new ArrayList<>();
        ArrayList<Integer> resultHit = new ArrayList<>();
        ArrayList<Integer> resultBlow = new ArrayList<>();
        //ArrayList<Integer> b = new ArrayList<>();
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int rawNumber = 0;
        int hit = 0, blow = 0;
        String line = null;
        try {
            while ((line = input.readLine()) != null) {
                rawNumber++;
                in = line.split(" ");
                if (rawNumber % 2 == 1) { //odd raws
                    for (int i = 0; i < 4; i++) {
                        a.add(Integer.parseInt(in[i]));
                    }
                } else {
                    for (int i = 0; i < 4; i++) { //index of b
                        for (int j = 0; j < a.size(); j++){ //index of a
                            if(Integer.parseInt(in[i]) == a.get(j)){ //hit or blow
                                if(i == j){
                                    hit++;
                                } else{
                                    blow++;
                                }
                            }
                        }
                    }
                    resultHit.add(hit);
                    resultBlow.add(blow);
                    hit = 0;
                    blow = 0;
                    a.clear();
                }
            }
        } catch (NumberFormatException e) {
            System.out.println(line + "include not int");
        } catch (IOException e) {
            System.out.println("IOException");
        }

        for(int i = 0; i < resultHit.size(); i++){
            System.out.println(resultHit.get(i) + " " + resultBlow.get(i));
        }
    }
}


Measured memory_bytes: 24420
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n,m;cin>>n>>m;
    vector<pair<int,int>> p;
    if(m%2==0){
        ll buf=m/2;
        rep(i,buf){
            p.push_back({i+1,m-i});
        }
        rep(i,buf){
            p.push_back({m+i+1,2*m+1-i});
        }
    }else{
        ll buf=(m+1)/2;
        rep(i,buf-1){
            p.push_back({i+1,m-i});
        }
        rep(i,buf){
            p.push_back({m+i+1,2*m+1-i});
        }
    }
    rep(i,p.size()){
        cout<<p[i].first<<" "<<p[i].second<<endl;
    }
}

Measured memory_bytes: 4320
#include <bits/stdc++.h>
#define rep(i, n) REP(i, 0, n)
#define REP(i, l, r) for (int i = l; i < r; ++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int, int> P;
struct edge {
  int to, cost;
};
// other libs
int gcd(int a, int b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
int lcm(int a, int b) {
  return a * b / gcd(a, b);
}

class dijkstra {
private:
  int V;
  int d[100002];
  priority_queue<P, vector<P>, greater<>> que;

public:
  dijkstra(int v, int s, vector<edge> G[]) {
    V = v;
    update(s, G);
  }

  void update(int s, vector<edge> G[]) {
    fill(d, d + V + 1, 100000000000ll);
    d[s] = 0;
    que.push(make_pair(0, s));
    while (!que.empty()) {
      P p = que.top();
      que.pop();
      int v = p.second;
      if (d[v] < p.first)
        continue;
      rep(i, G[v].size()) {
        edge e = G[v][i];
        if (d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          que.push(make_pair(d[e.to], e.to));
        }
      }
    }
  }

  int find(int e) {
    return d[e];
  }
};
template<typename T>
class Union_Find {
private:
  vector<T> t, s;

public:
  Union_Find(T max_length) {
    rep(i, max_length + 1) {
      t.push_back(i);
      s.push_back(1);
    }
  }

  void Union(T x, T y) {
    if (same(x, y))
      return;
    T tx = Find(x), ty = Find(y);
    if (s[tx] < s[ty]) {
      s[ty] += s[tx];
      t[tx] = ty;
    }
    else if (s[tx] > s[ty]) {
      s[tx] += s[ty];
      t[ty] = tx;
    }
    else if (tx > ty) {
      t[tx] = ty;
      s[ty] += s[tx];
    }
    else {
      t[ty] = tx;
      s[tx] += s[ty];
    }
  }
  T Find(T n) {
    if (t[n] == n)
      return n;
    else
      return t[n] = Find(t[n]);
  }

  bool same(T x, T y) {
    return Find(x) == Find(y);
  }

  T get_Size(size_t a) {
    return s[a];
  }
};
bool ifPrime(int n) {
  if (n == 1)
    return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)
      return false;
  }
  return true;
}

set<int> prime_num_factor(int n){
  if(n<2)return set<int>();
  set<int> prime;
  prime.insert(2);
  for(int i=3;i<=n;i++){
    for(int it:prime){
      if(it*it>i){
        prime.insert(i);
        break;
      }
      if(i%it==0)break;
    }
  }
  return prime;
}
vector<int> makeDivisors(int n){
  vector<int> re;
  REP(i,1,sqrt(n)+1){
    if(n%i==0){
      re.push_back(i);
      if(i!=n/i)re.push_back(n/i);
    }
  }
  return re;
}
int modPow(int a,int n,int mod){
  int ret=1;
  while(n){
    if(n&1)ret=ret*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return ret;
}
signed main(signed argc, char* argv[]) {
  int n;
  cin>>n;
  vector<int> l(n);
  rep(i,n)cin>>l[i];
  sort(l.begin(),l.end());
  int ans=0;
  REP(i,1,n){
    rep(j,i){
      ans+=lower_bound(l.begin(),l.end(),l[i]+l[j])-l.begin()-i-1;

    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    
    int a, b, c;
    
    scanf("%d %d %d", &a, &b, &c);
    
    int save;
    
    if(a > b){
        save = b;
        b = a;
        a = save;
    }
    
    if(a > c){
        save = c;
        c = a;
        a = save;
    }
    
    if(b > c){
        save = c;
        c = b;
        b = save;
    }

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



Measured memory_bytes: 2096
#include <cstdio>
#include <vector>

using namespace std;

//  a^b % m
long long powmod(long long a, long long b, long long m)
{
    long long r = 1;
    for (; b>0; b>>=1, a=a*a%m)
        if (b&1)
            r = r*a%m;
    return r;
}

long long powdiv(long long a, long long b, long long m)
{
    return a * powmod(b, m-2, m) % m;
}

int main()
{
    int n;
    scanf("%d", &n);
    vector<int> A(n+1);
    for (int &a: A)
        scanf("%d", &a),
        a--;
    vector<int> T(n);
    for (int a: A)
        T[a]++;
    int x;
    for (int i=0; i<n; i++)
        if (T[i] == 2)
            x = i;
    int p1 = -1;
    int p2 = -1;
    for (int i=0; i<n+1; i++)
        if (A[i] == x)
            (p1==-1 ? p1 : p2) = i;
    long long l = p2 - p1 + 1;

    long long M = 1000000007;
    vector<long long> F(n+2);
    F[0] = 1;
    for (int i=1; i<=n+1; i++)
        F[i] = F[i-1] * i % M;

    for (int i=1; i<=n+1; i++)
    {
        long long a = powdiv(F[n+1], F[i]*F[n+1-i]%M, M);
        long long b = n+1-l < i-1 ? 0 : powdiv(F[n+1-l], F[i-1]*F[(n+1-l)-(i-1)]%M, M);
        printf("%lld\n", (a-b+M)%M);
    }
}


Measured memory_bytes: 2816
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
//#define INF 1100000000000000000LL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main() {
	int a,b;
	cin>>a>>b;
	cout<<(a+b+1)/2<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>

int main () {
    int n, ans = 0;
    std::cin >> n;
    int d[n];
    for(int i = 0; i < n; ++i) {
        std::cin >> d[i];
    }
    for(int i = 0; i < n; ++i) {
        for(int j = i + 1; j < n ; ++j){
            ans += d[i] * d[j];
        }
    }
    std::cout << ans << std::endl;
}


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

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int K;
    cin >> K;
    
    char a = S.at(K - 1);
    
    for(int i = 0; i < S.size();i++){
        if(S.at(i) != a){
            S.at(i) = '*';
        }
    }
    
    cout << S << endl;
    
}


Measured memory_bytes: 256
N, M = map(int, input().split())
link = [[] for i in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    link[A-1].append(B-1)
    link[B-1].append(A-1)
visited = [False for i in range(N)]
result = [0] * N
Q = [0]
visited[0] = True
#Qに要素がなくなるまで
while Q:
    #一番上の要素をpop
    v = Q.pop(0)
    for i in link[v]:
        if visited[i] == False:
            visited[i] = True
            result[i] = v
            Q.append(i)
print("Yes")
for i in range(1, N):
    print(result[i] + 1)

Measured memory_bytes: 34504
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<string> w(n);
	for (int i = 0; i < n; i++)cin >> w.at(i);
	set<string> said = { w.at(0) };
	int x = w.at(0).length() - 1;
	char last = w.at(0).at(x);
	for (int i = 1; i < n; i++) {
		string z = w.at(i);
		int x = w.at(i).length() - 1;
		if (said.count(z)) {
			cout << "No" << endl;
			return 0;
		}
		if (last != z.at(0)) {
			cout << "No" << endl;
			return 0;
		}
		else {
			said.insert(z);
			last = w.at(i).at(x);
		}
	}
	cout << "Yes" << endl;
}

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

using namespace std;


int main(void){
    int n;
    cin >> n;
    int h[n];
    int i = 0;
    for(i=0;i<n;i++){
        cin >> h[i];
    }
    
    int max=0;
    int num=0;
    
    for(i=0;i<n-1;i++){
        if(h[i] >= h[i+1]){
            num++;
          	if(i==n-2){
              	if(max < num){
               		 max = num;
            	}
            }
        }
        else{
            if(max < num){
                max = num;
            }
          	num = 0;
        }
    }
    
    cout << max << endl;
    
    
    
    return 0;
}


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

int main(){
  ll n;
  cin >> n;
  map<string,ll> s;
  rep(i,n){
    string t;
    cin >> t;
    s[t]++;
  }
  cout << s.size() << endl;
  return 0;
}

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

/* 平面幾何の基本要素 */
 
#define EPS (1e-10)
#define equals(a,b) (fabs((a) - (b)) < EPS )
 
class Point { // 点を表すクラス
public:
  double x,y;
  
  Point(double x=0,double y=0): x(x),y(y) {}
  
  Point operator + (Point p) { return Point(x + p.x, y + p.y); }
  Point operator - (Point p) { return Point(x - p.x, y - p.y); }
  Point operator * (double a) { return Point(a * x, a * y); }
  Point operator / (double a) { return Point(x / a, y / a); }
  
  double abs() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  
  bool operator < (const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }
  
  bool operator == (const Point &p) const {
    return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
  }
};

typedef Point Vector; // ベクトルを表す構造体

struct Segment { // 線分を表す構造体
  Point p1,p2;
};

typedef Segment Line; // 直線を表す構造体

class Circle { // 円を表すクラス
public:
  Point c;
  double r;
  Circle(Point c = Point(), double r = 0.0): c(c),r(r) {}
};
typedef vector < Point > Polygon; // 多角形

double dot(Vector a, Vector b) {
  return a.x * b.x + a.y * b.y;
}
 
double cross(Vector a, Vector b) {
  return a.x * b.y - a.y * b.x;
}

bool isParallel(Vector a,Vector b){
  return equals(cross(a,b),0.0);
}

bool isParallel(Point a1,Point a2,Point b1,Point b2){
  return isParallel(a1-a2,b1-b2);
}

bool isParallel(Segment s1,Segment s2){
  return equals(cross(s1.p2 - s1.p1,s2.p2 - s2.p1),0.0);
}

int main(){
  int n;
  Point p1,p2,p3,p4;
  cin >> n;
  while(n--){
    cin >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y >> p4.x >> p4.y;
    if(isParallel(p1,p2,p3,p4)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,cl[100005];
vector<pair<int,int> > tree[100005];
void dfs(int v,int pre)
{
	for(int i=0;i<tree[v].size();i++)
	{
		int u=tree[v][i].first;
		int w=tree[v][i].second%2;
		if(u!=pre)
		{
			cl[u]=cl[v]^w;
			dfs(u,v);
		}
	}
}
int main()
{
	cin>>n;
	for(int i=1;i<=n-1;i++)
	{
		int u,v,w;
		cin>>u>>v>>w;
		tree[u].push_back(make_pair(v,w));
		tree[v].push_back(make_pair(u,w));
	}
	dfs(1,-1);
	for(int i=1;i<=n;i++)
		cout<<cl[i]<<endl;
	return 0;
}

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

struct Edge{int to, id;};
vector<vector<Edge>> glaph;
vector<int> ans;

void dfs(int v, int p=-1, int c=-1){
  int k = 1;              //辺の色
  rep(i, glaph[v].size()){
    int u = glaph[v][i].to, ei = glaph[v][i].id;
    if(u == p) continue;    //親方向の頂点と同じ場合スキップ
    if(k == c) k++;         //親方向の辺と同色の場合スキップ
    ans[ei] = k;  k++;      //辺に色を付ける
    dfs(u, v, ans[ei]);     //dfs(現在の頂点, 親方向の頂点, 親方向の辺)
  }
}
int main(){
  int n;
  cin >> n;
  glaph.resize(n);          //要素数nでリサイズ
  ans.resize(n);            //要素数nでリサイズ
  rep(i, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;               //1 <= ai < bi <= N のためデクリメント
    glaph[a].push_back((Edge){b, i});
    glaph[b].push_back((Edge){a, i});
  }
  dfs(0);
  int mx = 0;
  rep(i, n) mx = max(mx, int(glaph[i].size()));
  cout << mx << endl;
  rep(i, n-1) cout << ans[i] << endl;
  return 0;
}

Measured memory_bytes: 8320
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

struct COMB
{
    int L;
    vll kaijo, gyaku;
    const ll mod = 1e9 + 7;
    void __init__(int sz)
    {
        L = sz;
        kaijo.resize(L + 1, 0);
        gyaku.resize(L + 1, 0);
        kaijo[0] = 1;
        repf(i, 1, L + 1)
            kaijo[i] = (kaijo[i - 1] * i) % mod;
        gyaku[L] = powmod(kaijo[L], mod - 2, mod);
        rep(i, L)
            gyaku[L - 1 - i] = gyaku[L - i] * (L - i) % mod;
    }
    ll powmod(ll x, ll y, ll mod)
    {
        if (y==0)
            return 1;
        map<ll, ll> Z;
        Z[0] = 1;
        Z[1] = x;
        ll nowy = 1;
        ll nowx = x;
        while (nowy * 2 <= y)
        {
            nowy *= 2;
            nowx = nowx * nowx % mod;
            Z[nowy] = nowx;
        }
        ll nowz = nowy / 2;
        while (nowy < y)
        {
            if (nowz + nowy <= y)
            {
                nowy += nowz;
                nowx = (nowx * Z[nowz]) % mod;
            }
            nowz /= 2;
        }
        return nowx;
    }

    ll calc_comb(int n, int k)
    {
        if (n > L)
            return -1;
        return (((kaijo[n] * gyaku[k]) % mod) * gyaku[n - k]) % mod;
    }
    ll calc_kaijo(int i)
    {
        return kaijo[i];
    }
    ll calc_gyaku(int i)
    {
        return gyaku[i];
    }
    ll calc_pow_gyaku(int x,int k){
        return powmod(gyaku[x], k, mod);
    }
};

ll n, a, b, c, d;


int main()
{
    cin >> n >> a >> b >> c >> d;
    COMB comb;
    comb.__init__(n);
    vll dp(n + 1);
    dp[0] = 1;
    repf(x,a,b+1){
        vll dpc(n + 1);
        copy(all(dp), dpc.begin());
        ll snow = comb.calc_pow_gyaku(x, c-1);
        //ｘ人のグループを作っていく
        repf(k, c, d+1){
            snow = (snow * comb.calc_gyaku(x))%mod;
            if (k*x>n)
                break;
            //ｘ人のグループをｋ個作る
            rep(i,n+1){
                if (i+x*k>n)break;
                //ｎ人を超える場合は調べなくてよい
                    dp[i+x*k]=(dp[i+x*k]+(((dpc[i]*snow)%mod)
                    *comb.calc_gyaku(k))%mod)%mod;
                
            }
        }
    }
    ll ans = 0;
    /* rep(i,n+1){rep(j,n+1){
        cout<<(dp[i][j])%mod << " ";
    }
    cout << endl;
    }*/
    cout << (dp[n]*comb.calc_kaijo(n))%mod << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <set>
#include <deque>
#include <iostream>

static int count_graph(const std::vector< std::vector<int> > &edges, int n) {
    int c = 0;
    std::set<int> unvisited;
    for (int i = 0; i < n; i++) {
        unvisited.insert(i);
    }

    while (!unvisited.empty()) {
        int f = *unvisited.begin();
        unvisited.erase(f);
        std::deque<int> q;
        q.push_back(f);

        c++;

        while (!q.empty()) {
            int u = q.front();
            q.pop_front();

            for (std::vector<int>::const_iterator it = edges[u].begin(); it != edges[u].end(); ++it) {
                if (unvisited.count(*it) != 0) {
                    q.push_back(*it);
                    unvisited.erase(*it);
                }
            }
        }
    }

    return c;
}

int main() {
    int n;
    int m;
    std::vector< std::vector<int> > edges;

    std::cin >> n >> m;

    edges.resize(n);

    for (int i = 0; i < m; i++) {
        int x, y, z;
        std::cin >> x >> y >> z;
        edges[x-1].push_back(y-1);
        edges[y-1].push_back(x-1);
    }

    std::cout << count_graph(edges, n) << std::endl;

    return 0;
}

Measured memory_bytes: 11128
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>
#include <unordered_map>

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define SW(x) setw(x)    // 桁数指定
#define SF(c) setfill(c) // 埋め文字指定('0')
#define ALL(v) v.begin(), v.end()

int main(int argc, char const *argv[])
{
    ll a, b;
    cin >> a >> b;
    for (ll i = 1; i < 10000; i++)
    {
        if ((int)(i * 0.08) == a && (int)(i * 0.1) == b)
        {
            cout << i << endl;
            exit(0);
        }
    }
    cout << -1 << endl;

}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  
    int n = 700; string s; cin >> s;
    for (int i = 0; i < 3; ++i)
    {
        if (s[i] == 'o')
            n += 100;
    }
    cout << n << endl;


    return 0;
}


Measured memory_bytes: 3148
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>

using std::vector;
using std::printf;
using std::cout;
using std::endl;
using std::string;
using std::cin;
using std::pair;
using std::sort;
using std::priority_queue;

#define i64t long long int
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

template<typename T>
void dump(vector<T> vec) {
    for (auto x : vec) {
        std::cout << x << " ";
    }
    std::cout << std::endl;
}

// ---------------------------

const i64t MOD = 1000000007;

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

    vector<int> A(N+1, 0);
    for (int i = 1; i <= N; ++i) {
        cin >> A[i];
    }

    vector<int> B(N+1, 0);
    for (int i = 1; i <= N; ++i) {
        B[A[i]] = i;
    }

    for(int i = 1; i <= N; ++i) {
        printf("%d", B[i]);
        if (i != N) {
            printf(" ");
        }
    }

}

Measured memory_bytes: 1536
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.next());
    int T = Integer.parseInt(sc.next());
    
    int min = 10000;
    for(int i = 0; i < N; i++){
      int c = Integer.parseInt(sc.next());
      int t = Integer.parseInt(sc.next());
      if(t <= T && c < min){
        min = c;
      }
    }
    System.out.println(min == 10000 ? "TLE" : min);
  }
}

Measured memory_bytes: 22996
#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++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793;

int main(){
  string s;
  cin >> s;
  cout << s.at(0) << s.size()-2 << s.at(s.size()-1) <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>
i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

//メモリ置き場
int r, d, x;

//inputします
void input() {
    cin >> r >> d >> x;
}

//ライブラリ置き場



//main
int main() {
    input();
    ff(i, 0, 10) {
        x *= r;
        x -= d;
        cout << x << endl;
    }
    return 0; 
}

Measured memory_bytes: 768
/*input
3 4 240
60 90 120
80 150 80 150
*/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>

using namespace std; 

int GCD(int x,int y){return y?GCD(y,x%y):x;}
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rep(i,n) for(int i=0;i<(n);i++)
#define repl(i,a,b) for(int i=(a);i<(b);i++)
#define repm(i,a,b) for(int i=(a);i>(b);i--)
#define rept(v) for(auto it=v.begin();it<v.end();it++)
#define all(v) v.begin(),v.end()
const int INF = 1<<30;
typedef long long ll;
typedef pair<int,int> pii;





int main() {
	ll n;
	ll m;
	ll k;
	cin>>n>>m>>k;
	ll index1 = 0;
	ll index2 = m;
	ll arr[n+1];
	memset(arr,0,sizeof(arr));
	ll arr1[m+1];
	memset(arr1,0,sizeof(arr1));
	for(int i = 1; i<n+1;i++){
		ll a;
		cin>>a;
		arr[i] = a + arr[i-1];
	}
	for(int i = 1; i<m+1;i++){
		ll a;
		cin>>a;
		arr1[i] = a + arr1[i-1];
	}
	ll j = m;
	ll ma = 0;
	rep(i,n+1){
		if(arr[i]>k){
			break;
		}
		while(arr[i] + arr1[j] > k){
			j--;
		}
		ma = max(ma, i + j);
	}
	cout<<ma<<endl;
	

}



Measured memory_bytes: 6636
#include <cstdio>
#include <cstring>
#include <utility>
using namespace std;

int main() {
	char str[21];
	scanf("%s",str);
	int length = strlen(str);
	for(int i=0;i<length/2;++i) {
		swap(str[i],str[(length-1)-i]);
	}
	puts(str);
	return 0;
}

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

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

void dfs(vector<int>A){
  if(A.size() == n+1){
    int temp = 0;
    rep(i,0,q) if(A[b[i]]-A[a[i]] == c[i]) temp += d[i];
    ans = max(ans,temp);
    return;
  }
  A.push_back(A.back());
  while(A.back() <= m){
    dfs(A);
    A.back()++;
  }
}

int main() {
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i,0,q) cin >> a[i] >> b[i] >> c[i] >> d[i];
  vector<int>A(1,1);
  dfs(A);
  cout << ans << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string a, b, c;
  cin >> a >> b >> c;
  if (a.at(a.size() - 1) == b.at(0) && b.at(b.size() - 1) == c.at(0)) {
  	cout << "YES" << "\n";
  }else {
  	cout << "NO" << "\n";
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def main():
	N = int(input())
	a = list(map(int,input().split()))
	a.sort()
	sum_list = [a[0]]
	for i in range(N-1):
		sum_list.append(sum_list[i]+a[i+1])
	count = 0
	for i in range(N-1):
		if 2*sum_list[i] < a[i+1]:
			count = i+1

	print(N-count)

if __name__ == "__main__":
	main()

Measured memory_bytes: 14400
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>

using namespace std;

int r,c,n;
	
bool inedge(int x1,int y1){
	if(x1==0||x1==r||y1==0||y1==c){
		return 1;
	}
	return 0;
}

int calc(int x1,int y1){
	if(x1==0){
		return 2*r+c+(c-y1);
	}
	if(y1==0){
		return x1;
	}
	if(x1==r){
		return r+y1;
	}
	if(y1==c){
		return r+c+(r-x1);
	}
}
vector<int>p;
int vp[100002][2];
bool saiki(int x,int y){
	if(x>y)return 1;
	if(x==y)return 0;
	if(p[x]==p[y]){
		return saiki(x+1,y-1);
	}
	if(p[x]==p[x+1]){
		return saiki(x+2,y);
	}
	if(p[y]==p[y-1]){
		return saiki(x,y-2);
	}
	if(saiki(x+1,vp[p[x]][1]-1)){
		return saiki(vp[p[x]][1]+1,y);
	}else{
		return 0;
	}
}

int main(){
	cin >> r >> c >> n;
	int x1,y1,x2,y2;
	int j=0;
	vector<pair<int,int> > v;
	for(int i=0;i<n;i++){
		cin >> x1 >> y1 >> x2 >> y2;
		if(inedge(x1,y1)&&inedge(x2,y2)){
			v.push_back(make_pair(calc(x1,y1),j));
			v.push_back(make_pair(calc(x2,y2),j));
			j+=1;
		}
	}
	sort(v.begin(),v.end());
	for(int i=0;i<100002;i++){
		for(int k=0;k<2;k++){
			vp[i][k] = -1;
		}
	}
	for(int i=0;i<v.size();i++){
		p.push_back(v[i].second);
		if(vp[v[i].second][0]==-1){
			vp[v[i].second][0]=i;
		}else{
			vp[v[i].second][1]=i;
		}
	}
	if(saiki(0,p.size()-1)){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
}

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

int main(){
  int N ;
  cin >> N;
  int ans =0;
  vector<int> a(25);
  vector<int> b(25);
  vector<int> c(25);
  for(int i=0;i<N;i++) cin >> a[i]; 
  for(int i=0;i<N;i++) cin >> b[i]; 
  for(int i=0;i<N;i++) cin >> c[i]; 
  
  for(int i=0;i<N;i++){
    ans += b[a[i]-1];
    if(a[i]+1==a[i+1]) ans += c[a[i]-1];
  }
  
  
  cout << ans << endl;
}
  

Measured memory_bytes: 256
n = gets.to_i

edges = []
g = Array.new(n){ [] }
(n-1).times do |i|
  e = gets.split.map(&:to_i).map{|k|k-=1}
  e[1], e[0] = e[0], e[1] if e[0] > e[1]
  g[e[0]] << e[1]
  g[e[1]] << e[0]
  edges << e
end

colors = Hash.new() # Esge => color # 辺についてO(1)で使った色を見れる。O(1)はホントに?
colors_used = Array.new(n){Hash.new} # 頂点と色についてO(1)で使ったか確かめられる。
used = Array.new(n){false} # 頂点について探索済みかどうかO(1)でわかる。
que = [0] # 頂点0から見ていくので0が入っている # 探索待ちの未探索の頂点リスト

k = 0 # 答えとなる色の数
while !que.empty? do
  v = que.shift # queにある頂点を取り出す. 破壊的メソッドなので先頭は削除される。
  cur = 1 # 色?
  g[v].each do |w| # vの隣接頂点wを見ていく。
    k = g[v].size if k < g[v].size  # 隣接する頂点数より色数が小さければ色数を更新
    v<w ? (i,j = v,w) : (i,j = w,v) # i < jの並びで頂点を捉える。
    next if colors[[i,j]] != nil # nilでなければi-jの辺に色がついてるので,次に。
    cur += 1 while colors_used[v][cur] == true # v周りの頂点で色をつかっていれば次の色に更新していく。
    colors_used[v][cur] = true # vに色を使ったので記録する。
    colors_used[w][cur] = true # wに色を使ったので記録する。
    colors[[i,j]] = cur # 辺に使った色をいれる。
    que.push(w)# 未探索なら、探索待ちの未探索リストに入れる。
    used[v] = true # 頂点vを探索済みにする。
  end
end

puts k
edges.each{ |e| puts colors[e] }

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

int main(){
	int A, B, C;
	cin >> A >> B >> C;
	int K;
	cin >> K;
	int maxabc = max(max(A, B), C);
	int ans = A + B + C -maxabc;
	for(int i = 0; i < K; i++)
	{
		maxabc*=2;
	}
	ans += maxabc;
	cout << ans << endl;
	
	return 0;
}

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

int main()
{
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a+b)*h/2 << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n, a[100] = {0};
    cin >> n;
    
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    
    for(int j = n-1; 0 < j; j--){
        cout << a[j] << " ";
    }
    cout << a[0];
    cout << endl;
}
//ITP1_6_A


Measured memory_bytes: 3088
/*
ID: 123feli1
TASK: test
LANG: C++
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
int main(){
	string s;
	cin>>s;
	int count=0;
	if(s=="RRR"){
		cout<<"3\n";
	}else if(s=="RRS"||s=="SRR"){
		cout<<"2\n";
	}else if(s=="RSR"||s=="RSS"||s=="SRS"||s=="SSR"||s=="RSS"){
		cout<<"1\n";
	}else{
		cout<<"0\n";
	}
	
    return 0;
}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    string s;
    cin>>s;
    if(s[2]==s[3] && s[4] == s[5]) cout<<"Yes";
    else cout<<"No";
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

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

#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);

int main() {
    fast_io;

    long long n,r,g,b;
    cin>>n;
    string s;
    cin>>s;

    r=0;
    g=0;
    b=0;

    for(int i=0;i<n;i++) {
        if(s[i]=='R')r++;
        else if (s[i]=='G')g++;
        else if (s[i]=='B')b++;
    }

    int count =0;
    for(int i=0;i<n;i++) {
        for(int j=0;j<n;j++) {
            int k=2*j-i;

            if(i>=j||k>=n||k<=j) continue;

            if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k]) count++;
        }
    }

    cout<<r*g*b-count<<endl;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define pf printf
#define sf scanf
typedef long long LL;
using namespace std;
int main()
{
    int a,b,c;
    sf("%d %d %d",&a,&b,&c);
    /*while(t--)
    {

    }*/
    if(abs(b-a)>abs(c-a))
    {
        printf("B");
    }
    else
        printf("A");



    return 0;
}


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

int main() {

	string s;

	cin >> s;

	int i = 0;
	int count = 0;

	while (s[i] != NULL) {
		i++;
		count++;
	}

	cout << s[0] << count-2 << s[i-1] << endl;

	return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define lop(i, n) for(i=0; i<n; i++)

int gcd(long int a, long int b){
	long int t;
	if(a<b){ t=a; a=b; b=t; }
	if(b<1)return -1;
	
	if(a%b==0)return b;
	else return gcd(b, a%b);
}

int main()
{
	long int a, b, tmp;
	scanf("%ld %ld", &a, &b);
	long int x = a * b;

	long int p=gcd(a, b);
	
	printf("%ld", x/p);
	
return 0;
}

Measured memory_bytes: 128