akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define UP(a,b,c) for(ll (a)=(b);(a)<(c);(a)++)
#define UU(a,b,c) for(ll (a)=(b);(a)<=(c);(a)++)
#define DN(a,b,c) for(ll (a)=(b);(a)>(c);(a)--)
#define DU(a,b,c) for(ll (a)=(b);(a)>=(c);(a)--)
ll d(ll H,ll cnt)
{
	if(H==1)
	{
		return 1;
	}
	else
	{
		return cnt*2+d(H/2,cnt*2);
	}
}
int main()
{
	ll H,total=0,cnt=0;
	cin>>H;
	cout<<d(H,1)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        int N;
        cin >> N;
        vector<int> vec(N);

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

        sort(vec.begin(), vec.end());
        int sum = 0;
        for (int i = 0; i < N - 1; i++)
        {
                sum += vec[i];
        }

        int l = vec[N - 1];

        if (sum > l)
        {
                cout << "Yes" << endl;
        }
        else
        {
                cout << "No" << endl;
        }

        return 0;
}


Measured memory_bytes: 256
/*ANKON GHOSH
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define MAX 100005
#define mod 998244353
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) printf("Case %lld:\n",i)
#define pf(a) printf("%lld ",a)
#define pfsn printf("NO\n")
#define pfs  printf("YES\n")
#define pff(a,b) printf("%lld %lld\n",a,b)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll r=x;r<=y;r++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p(a,b) make_pair(a,b)
#define p_b(a) push_back(a)
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
map<ll,ll>mp,mp1;
vector<pair<ll,pair<ll,pair<ll,ll> > > >vpp,vpp1;
vector<pair<ll,ll> >vp,fin;
vector<ll>v,v1,v2,dummy;
map<pair<ll,ll>,ll>mpp;
map<ll,bool>mb;
ll n,x,k,a,b,c,d,ta,sum=0,cnt=0,m,l,req,sz,w;
bool sortbysec(const pair<pair<ll,ll>,ll> &a,const pair<pair<ll,ll>,ll> &b)
{
    return (a.second < b.second);
}
struct data
{
    ll weight,value;
}arr[MAX];
ll dp[110][MAX];
ll calc(ll pos,ll w)
{
    if(pos>n) return 0;
    else if(dp[pos][w]!=-1) return dp[pos][w];
    ll ret=0;
    if(w-arr[pos].weight>=0) ret=max(ret,max(ret+arr[pos].value+calc(pos+1,w-arr[pos].weight),ret+calc(pos+1,w)));
    else ret=max(ret,ret+calc(pos+1,w));
    return dp[pos][w]=ret;
}
int main()
{
    cin>>n>>w;
    v.clear();
    memset(arr,0,sizeof arr);
    FOR1(i,n)
    {
        cin>>arr[i].weight>>arr[i].value;
    }
    memset(dp,-1,sizeof dp);
    ll ans=calc(1,w);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 87808
import java.util.*;
public class Main {
	public static void main(String[]args) {

		
		Scanner sc = new Scanner(System.in);
		
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		
		sc.close();
		
		int res = 0;
				
		for (int a = 0; a <= A ; a++) {
			
			for (int b = 0 ; b <= B ; b++) {
				
				for (int c = 0 ; c <= C ; c ++ ) {
					
					int total = 500*a + 100*b + 50*c;
					
					if (total == X) res++;
				}
			}
			
		}
		
		System.out.println(res);
			
	}	


}

Measured memory_bytes: 23892
#include<iostream>
#include<array>
#include<algorithm>
using namespace std;
int main(){
  array<int,3> ls;
  for(int i=0;i<3;i++)cin>>ls[i];
  sort(ls.begin(),ls.end());
  for(auto i:ls){
    if(i == ls[2]){
      cout<<i<<endl;
    }else{
      cout<<i<<" ";
    }
  }
}



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

#define ll long long
const int maxn=10000;
const long long inf=1e11;

int n,m,ans;
int b[100010],c[100010],u[10010],pr[10010];
long long a[100010];
map<long long,int> h;
vector<long long> f;

long long gcd(long long x,long long y)
{return y==0?x:gcd(y,x%y);
}

long long mul(long long x,long long y,long long p)
{x%=p;
 y%=p;
 return (x*y-(ll)((long double)x*y/p+0.5)*p+p)%p;
 /*
 long long ret=0;
 while(y)
 {	if(y&1) ret=(ret+x)%p;
 	x=(x+x)%p;
 	y/=2;
 }
 return ret;
 */
}

long long fpow(long long i,long long j,long long p)
{long long ret=1;
 for(;j;i=mul(i,i,p),j/=2)
 	if(j&1) ret=mul(ret,i,p);
 return ret;
}

long long pollard_rho(long long p,int seed)
{long long x,y,k,i,z;
 
 x=y=1;
 k=2;
 i=1;
 while(1)
 {	x=(mul(x,x,p)+seed)%p;
	if(x==y) return p;
	i++;
	z=gcd((y-x+p)%p,p);
	if(z!=1 && z!=p) return z;
	if(i==k)
	{	y=x;
		k*=2;
	}
 }
}

int check(long long p,long long x)
{long long y,i;
 if(p==x) return 1;
 i=p-1;
 while(!(i&1)) i/=2;
 x=fpow(x,i,p);
 while(1)
 {	if(i==p-1) return x==1;
 	y=mul(x,x,p);
 	i*=2;
 	if(y==1)
 	{	if(x!=1 && x!=p-1) return 0;
	 	return 1;
	}
	x=y;
 }
}

int miller_rabin(long long p)
{if(!check(p,2)) return 0;
 if(!check(p,3)) return 0;
 if(!check(p,7)) return 0;
 if(!check(p,61)) return 0;
 //if(!check(p,24251)) return 0;
 return 1;
}

void find(vector<long long> &A,long long p)
{int seed;
 long long x;

 if(p==1) return;
 if(miller_rabin(p))
 {	A.push_back(p);
 	return;
 }
 seed=3;
 x=pollard_rho(p,seed);
 while(x==p) x=pollard_rho(p,++seed);
 find(A,x);
 find(A,p/x);
}

int main()
{int i,j,k,s,last;
 long long x,y,z,t;
 long double z1; 
  
 for(i=2;i<=maxn;i++)
 {	if(!u[i]) pr[++m]=i;
 	for(j=2;i*j<=maxn;j++)
	 	u[i*j]=1;
 }
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {	scanf("%lld",&a[i]);
 	x=a[i];
 	//t=x;
 	for(j=1;j<=m && (ll)pr[j]*pr[j]*pr[j]<=x;j++)
 	{	y=(ll)pr[j]*pr[j]*pr[j];
 		while(x%y==0) x/=y;
 	}
	f.clear();		
	find(f,x);
	sort(f.begin(),f.end());
	t=1;
	z=1;
	z1=1.0;
	for(j=0;j<f.size();j=last+1)
	{	last=j;
		while(last+1<f.size() && f[last+1]==f[j]) last++;
		if((last-j+1)%3==1)
		{	t*=f[j];
			z*=(ll)f[j]*f[j];
			z1=z1*f[j]*f[j];
		}
		else if((last-j+1)%3==2)
		{	t*=(ll)f[j]*f[j];
			z*=f[j];
			z1=z1*f[j];
		}
	}
	if(z1>inf)
	{	ans++;
		continue;
	}
	if(t==1)
	{	b[0]=1;
		continue;
	}
	
	k=h[t];
 	if(k==0)
	{ 	h[t]=i;
		h[z]=-i;
		b[i]++;
	}
	else if(k>0)
		b[k]++;
	else
		c[-k]++;
 }
 /*
 for(i=1;i<=n;i++) cout<<b[i]<<" ";
 cout<<endl;
 for(i=1;i<=n;i++) cout<<c[i]<<" ";
 cout<<endl;
 */
 for(i=0;i<=n;i++) ans+=max(b[i],c[i]);
 printf("%d\n",ans);
 return 0;
}

Measured memory_bytes: 12032
const input = require('fs').readFileSync('/dev/stdin', 'utf8');
const line = input.split(' ');
const N = +line[0];
const K = +line[1];

const sums = [0];
for (let i = 0; i < N + 1; i++) {
    sums.push(i + sums[i]);
}

let sum = 0;
for (let i = K; i <= N + 1; i++) {
    const min = sums[i] - sums[0];
    const maxIndex = sums.length - 1;
    const max = sums[maxIndex] - sums[maxIndex - i];
    sum += (max - min + 1)
}

const MOD = 1000000007;
console.log(sum % MOD);



Measured memory_bytes: 38692
//https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_c
//C - Different Strokes
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
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;}
struct Info{
    ll A,B;
    ll sum;
};
int main() {
#if LOCAL&01
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N; cin>>N;
    vector<Info> abn(N);
    for(auto&& ab:abn){
        cin>>ab.A>>ab.B;
        ab.sum=ab.A+ab.B;
    }
    //a1+a3-b1
    //a1+b1+a3+b3-(b1+b2+b3)
    sort(abn.begin(),abn.end(),[](const auto&a, const auto&b){ return a.sum>b.sum;});
    ll ans=0;
    FOR(i,0,N){
        const auto& ab = abn.at(i);
        ans -= ab.B;
        if(i%2==0){
            ans += ab.sum;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

struct Node{
    ll v, dis;
};


vector <Node> neighbor[ll(1e5+1)] = {};

ll color[ll(1e5+1)] = {};
ll n;
void bfs(Node s){
    queue<Node> q;
    q.push(s);
    for (ll i=1; i<=n;i++){
        color[i] = -1;
    }
    color[s.v] = 0;
    Node u;
    while(!q.empty()){
        u = q.front();
        q.pop();

        for (ll v=0;v<neighbor[u.v].size();v++){
            if(color[neighbor[u.v][v].v] != -1){
                continue;
            }
            if(neighbor[u.v][v].dis % 2 == 0) {
                color[neighbor[u.v][v].v] = color[u.v];
            }else{
                color[neighbor[u.v][v].v] = (color[u.v] + 1)%2;
            }
            q.push(neighbor[u.v][v]);
        }
    }

}

int main() {
    


    cin >> n;
    for (ll i=0;i<n-1;i++){
        ll u,v,w;
        cin >> u >> v >> w;
        Node uNode, vNode;
        uNode.v = u;
        uNode.dis = w;
        vNode.v = v;
        vNode.dis = w;
        neighbor[v].push_back(uNode);
        neighbor[u].push_back(vNode);
    }
    Node s;
    s.v = 1;
    s.dis = 0;
    bfs(s);
    for (ll i=1;i<=n;i++){
        cout << color[i] << endl;
    }
}

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

using namespace std;

int main() {
   int a1, a2, a3;
   cin >> a1 >> a2 >> a3;
   
   if (a1 < a2) {
      swap(a1, a2);
   }
   if (a2 < a3) {
      swap(a2, a3);
   }
   if (a1 < a2) {
      swap(a1, a2);
   }
   int ans = (a1 - a2) + (a2 - a3);
   cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define MAXN 1000007
#define fr(i, s, e, st) for(ll (i) = (s); (i) < (e); (i) += (st))
#define fre(i, s, e, st) for(ll (i) = (s); (i) <= (e); (i) += (st))
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
 
using namespace std;

int main()
{
    fastio;
    int T = 1;
    while(T--){
        ll a, b;
        cin>>a>>b;
        cout<<(a*b)/__gcd(a, b);
    }                                               
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n;
  cin >> n;
  cout << (n - 2) * 180 << endl;
  return 0;
}


Measured memory_bytes: 256
// Created by  Ambesh kumar
#include "bits/stdc++.h"

//I already compile this file in my computer system to save the time
//if get the compiler error then you should change this header to
// #include "bits/stdc++.h"  ---> #include <bits/stdc++.h>

using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0, lim - 1);
	return uid(rang);
}
int mpow(int base, int exp);
void ipgraph(int n, int m);
void dfs(int u, int par);

const int mod = 1000000007;
const int N = 3e5, M = N;
//=================================================================================================================================//

vi g[N];
int a[N];

void solve() {
	ll a, b, c, d, x, y;

	cin >> a >> b >> c >> d;



	ll ans1 = a * c;
	ll ans2 = a * d;

	ll ans3 = b * c;

	ll ans4 = b * d;

	ll max1 = ans1;

	max1 = max(ans2, max1);


	max1 = max(ans3, max1);


	max1 = max(ans4, max1);




	cout << max1 << '\n' ;
}







int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());

	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}

	return 0;
}







Measured memory_bytes: 10692
S = input()
K = int(input())
count_ones = 0
inf_n = 0
for c in S:
  n = int(c)
  if n == 1:
    count_ones += 1
  else:
    inf_n = n
    break
if K <= count_ones:
  print(1)
else:
  print(inf_n)

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int a,b=0,c;
    char s[101];
    // 整数の入力
    scanf("%d", &a);
    // 文字列の入力
    scanf("%s",s);
    // 出力
  for(c=0;c<a;c++){
  	if (s[c]=='R'){
  	b++;
  	}else{
    b--;
    }
  }
  if(b>0){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
#if 1
#pragma GCC optimize "O3"
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>
#include <fstream>
#include <iostream>
#include <sstream>
#include <random>
#include <cassert>
#include <cmath>
#include <cstring>
#include <chrono>
using namespace std;
using i8 = int8_t; using i16 = int16_t; using i32 = int32_t; using i64 = int64_t; using u8 = uint8_t; using u16 = uint16_t; using u32 = uint32_t; using u64 = uint64_t; using f32 = float; using f64 = double;
template <class T> inline T sq(T a) { return a * a; }
template <class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } return false; }
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
void _u() { cerr << endl; } template <class H, class... T> void _u(H&& h, T&&... t) { cerr << h << ", "; _u(move(t)...); }
#define _polyfill(v) v
#define _overload3(a, b, c, d, ...) d
#define _rep3(i, a, b) for (i32 i = i32(a); i < i32(b); ++i)
#define _rep2(i, b) _rep3(i, 0, b)
#define _rep1(i) for (i32 i = 0; ; ++i)
#define rep(...) _polyfill(_overload3(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__))
#define A(a) begin(a), end(a)
#define S(a) i32((a).size())
#define U(...) { cerr << #__VA_ARGS__ << ": "; _u(__VA_ARGS__); }
#define lin U(__LINE__)
#define exi exit(0);
#endif

class timer {
    vector<timer> timers;
    int n = 0;
public:
    double limit = 2.95;
    double t = 0;
    timer() {}
    timer(int size) : timers(size) {}
    bool elapses() const {
        return time() - t > limit;
    }
    void measure() {
        t = time() - t;
        ++n;
    }
    void measure(char id) {
        timers[id].measure();
    }
    void print() {
        if (n % 2)
            measure();
        for (int i = 0; i < 128; ++i) {
            if (timers[i].n)
                cerr << (char)i << ' ' << timers[i].t << 's' << endl;
        }
        cerr << "  " << t << 's' << endl;
    }
    static double time() {
#ifdef LOCAL
        return __rdtsc() / 3.3e9;
#else
        using namespace std::chrono;
        return duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count() / 1000.0;
#endif
    }
} timer(128);

constexpr bool Deterministic = 0;
class rando {
    unsigned y;
public:
    rando(unsigned y) : y(y) {}
    unsigned next() {
        return y ^= (y ^= (y ^= y << 13) >> 17) << 5;
    }
    int next(int b) {
        return next() % b;
    }
    int next(int a, int b) {
        return next(b - a) + a;
    }
    double nextDouble(double b = 1) {
        return b * next() / 4294967296.0;
    }
    double nextDouble(double a, double b) {
        return nextDouble(b - a) + a;
    }
    int operator() (int b) {
        return next(b);
    }
} rando(Deterministic ? 2463534242 : random_device()());

i32 main() {
    i32 a, p;
    while (cin >> a >> p) {
        p += a * 3;
        cout << p / 2 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int main(){

    string s;
    int n;
    priority_queue<int> q;


    while(cin >> s,s != "end"){

        if(s == "insert"){
            cin >> n;
            q.push(n);
        }else if(s == "extract"){
            cout << q.top() << endl;
            q.pop();
        }

    }














    return 0;
}


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

typedef long long LL;

const double PI = acos(-1.0);

int n, m, q, a[60], b[60], c[60], d[60], v[30], ans;

void dfs(int p, int x) {
    //printf("dfs %d %d\n", p, x);
    v[p] = x;
    if (p == n) {
        int t = 0;
        for (int i = 0; i < q; ++i) {
            if (v[b[i]] - v[a[i]] == c[i]) t += d[i];
        }
        ans = max(ans, t);
        return ;
    }
    for (int i = x; i <= m; ++i) dfs(p+1, i);
}

int work() {
    scanf("%d%d%d", &n, &m, &q);
    for (int i = 0; i < q; ++i) scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
    dfs(1, 1);
    printf("%d\n", ans);

    return 0;
}

int main() {
    work();
    //while (~scanf("%d", &n)) work();
    //scanf("%d", &T); while (T--) work();

    return 0;
}


Measured memory_bytes: 3808
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>

using namespace std;

#define MAX_N 100

int G[MAX_N][MAX_N];

int mincost[MAX_N];
bool used[MAX_N];
int V;
int prim() {
	for (int i = 0; i < V; i++) {
		mincost[i] = INT_MAX;
		used[i] = false;
	}
	mincost[0] = 0;
	int res = 0;

	while (1) {
		int v = -1;
		for (int u = 0; u < V; u++)
			if (!used[u] && (v == -1 || mincost[u] < mincost[v]) )
				v = u;

		if (v == -1)
			break;
		used[v] = true;
		res += mincost[v];

		for (int u = 0; u < V; u++)
			mincost[u] = min(mincost[u], G[v][u]);
	}
	return res;
}

int main() {
	int n, c;
	cin >> n;
	V = n;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++) {
			cin >> c;
			if (c == -1) c = INT_MAX;
			G[i][j] = c;
		}

	cout << prim() << endl;
	return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>
int main(void){
    int a,i,n,min,max;
    long long int sum=0;
    scanf("%d",&n);
    scanf("%d",&a);
    sum=a;
    min=a;
    max=a;
    for(i=1;i<=n-1;i++){
        scanf("%d",&a);
        sum+=a;
        if(a<=min){
            min=a;
        }
        if(a>=max){
            max=a;
        }
    }
    printf("%d %d %ld\n",min,max,sum);
    return 0;
}


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

/// --- math {{{ ///
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll extgcd(ll a, ll b, ll &x, ll &y) {
  ll d;
  return b == 0 ? (x = 1, y = 0, a)
    : (d = extgcd(b, a % b, y, x), y -= a / b * x, d);
}
ll modinv(ll a, ll mod = 1e9 + 7) {
  ll x = 0, y = 0;
  extgcd(a, mod, x, y);
  return (x + mod) % mod;
}
ll modpow(ll a, ll b, ll mod = 1e9 + 7) {
  ll r = 1;
  a %= mod;
  while(b) {
    if(b & 1) r = r * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return r;
}
/// }}}--- ///


int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, x;
  int t[112345];
  cin >> n >> x;
  int g = 0;
  for(int i = 0; i < n; i++) {
    cin >> t[i];
    g = gcd(g, abs(t[i] - x));
  }
  cout << g << endl;
  return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
#define lg 18
//<<fixed << setprecision(9)
pii edge[space],foo[space],col[space];//count,length

int up[space][lg],in[space],out[space],tim,dist,ans[space];
vector<pii> G[space],query[space];

void dfs(int n,int p)
{
    in[n]=++tim;
    up[n][0]=p;
    int i;
    rep(i,1,lg)
    {
        up[n][i]=up[up[n][i-1]][i-1];
    }

    for(auto z:G[n])
    {
        if(z.F!=p)
        {
            dfs(z.F,n);
        }
    }
    out[n]=++tim;
}

void dfs2(int n,int p)
{
    for(auto x:query[n])
    {
        ans[x.F]+=(dist-col[foo[x.F].F].S+col[foo[x.F].F].F*foo[x.F].S)*x.S;
    }

    for(auto z:G[n])
    {
        if(z.F!=p)
        {
            dist+=edge[z.S].S;
            col[edge[z.S].F].F++;
            col[edge[z.S].F].S+=edge[z.S].S;
            dfs2(z.F,n);
            dist-=edge[z.S].S;
            col[edge[z.S].F].F--;
            col[edge[z.S].F].S-=edge[z.S].S;
        }
    }
}

bool anc(int a,int b)
{
    return in[a]<in[b] && out[a]>out[b];
}
int lca(int u,int v)
{
    for(int i=lg-1;i>=0;i--)
    {
        if(!anc(up[u][i],v))
        {
            u=up[u][i];
        }
    }
    return up[u][0];
}
int main()
{
    int n,i,j,t;
    boost;

    cin>>n>>t;
    int a,b,c,d;
    rep(i,0,n-1)
    {
        cin>>a>>b>>c>>d;
        edge[i]={c,d};
        G[a].pb({b,i});
        G[b].pb({a,i});
    }

    dfs(1,1);

    rep(i,1,t+1)
    {
        cin>>c>>d>>a>>b;
        foo[i]={c,d};
        if(anc(a,b))
        {
            query[a].pb({i,-1});
            query[b].pb({i,1});
        }
        else if(anc(b,a))
        {
            query[b].pb({i,-1});
            query[a].pb({i,1});
        }
        else
        {
            j=lca(a,b);
            query[j].pb({i,-2});
            query[a].pb({i,1});
            query[b].pb({i,1});
        }
    }
    dfs2(1,-1);

    rep(i,1,t+1) cout<<ans[i]<<'\n';
    return 0;
}



Measured memory_bytes: 26616
#include<iostream>
#include<queue>
using namespace std;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
static const int MAX = 10000;
static const int INFTY = (1 << 21);

int n;
vector<pair<int, int> > adj[MAX]; //重み付き有向グラフの隣接リスト表現

void dijkstra(int s){
    priority_queue<pair<int, int> > PQ;
    int d[MAX], color[MAX];
    for(int i = 0; i < n; i++){
        d[i] = INFTY;
        color[i] = WHITE;
    }

    d[s] = 0;
    PQ.push(make_pair(0, s));
    color[s] = GRAY;

    while( !PQ.empty()){
        pair<int, int> f = PQ.top(); PQ.pop();
        int u = f.second;
        color[u] = BLACK;
/*
        //最小値を取り出し、それが最短でなければ無視
        if( d[u] < f.first * (-1)) continue;
*/
        for(int j = 0; j < adj[u].size(); j++){
            int v = adj[u][j].first;
            if( color[v] == BLACK) continue;
            if( d[v] > d[u] + adj[u][j].second ){
                d[v] = d[u] + adj[u][j].second;
                //priority_queue　はデフォルトで大きい値を優先するため -1 をかける
                PQ.push(make_pair(d[v] * (-1), v)); //pqは一つ目の値でソートされるため、第一項に距離を持ってきている
                color[v] = GRAY;
            }
        }
    }

    for( int i = 0; i < n; i++){
        cout << i << " " << (d[i] == INFTY ? -1 : d[i]) << endl;
    }
}

int main(){
    cin >> n;
    int u, k, v, c;

    for(int i = 0; i < n; i++){
        cin >> u >> k;
        for(int j = 0; j < k; j++){
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra(0);

    return 0;
}



Measured memory_bytes: 7996
fn main() {
    let (_n, mut m) = read_tuple::<i64>();
    let mut an: Vec<i64> = read_vec();

    let c = two_div_counter(an[0]);
    for a in an.iter_mut() {
        let ac = two_div_counter(*a);
        if c != ac {
            println!("0");
            std::process::exit(0);
        }
        *a >>= c;
    }
    m >>= c-1;
    let t = lcm(&an);
    m /= t;

    println!("{:?}", (m+1)/2);
}

fn two_div_counter(n: i64) -> i64 {
    let mut a = n;
    let mut count = 0;
    while a % 2 == 0 {
        count += 1;
        a /= 2;
    }
    count
}

pub fn gcd(a: i64, b: i64) -> i64 {
    let (mut a, mut b) = (a, b);
    while b != 0 {
        let tmp = a - (a / b) * b;
        a = b;
        b = tmp;
    }
    a
}


pub fn lcm(iterable: &Vec<i64>) -> i64 {
    let mut a = iterable[0];
    for b in iterable.iter() {
        a = a / gcd(a, *b) * b;
    }
    a
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}
fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T) {
    let temp = read_vec();
    (temp[0], temp[1])
}



Measured memory_bytes: 8444
//#include <bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<cstring>
#include<bitset>
#include<stack>

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define ALL(x) x.begin(),x.end()
#define mst(var,val) memset(var,val,sizeof(var))
#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ls rt<<1
#define rs rt<<1|1
#define lson rt<<1, l, M
#define rson rt<<1|1, M+1, r
#ifdef local
#define dbg(a) cout << #a": " << a << endl;
#else
#define dbg(a)
#endif // loacl


using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <double, double> pdd;
const int inf=0x3f3f3f3f;
const long long INF=0x3f3f3f3f3f3f3f3fLL;
const double PI=acos(-1.0);
const long double eps=1e-6;
const int mod=1e9+7;
const int maxn=200+10;
const int N=1e5+10;
const int M=N*20;
const ll mm=(1LL<<32);

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
    int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}
ll qpow(ll a,ll b,ll MOD)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=(ans*a)%MOD;
        b>>=1;
        a=(a*a)%MOD;
    }
    return ans;
}

int n,m;
ll f[N];
int vis[N];
int main()
{
	IOS;
	cin>>n>>m;
	rep(i,m) {int x;cin>>x;vis[x]=1;};
	if(!vis[1]) f[1]=1; if(!vis[1]&&!vis[2]) f[2]=2;
	if(vis[1]&&!vis[2]) f[2]=1;
	for(int i=3;i<=n;++i)
    {
        if(!vis[i])
        {
            f[i]=(f[i-1]+f[i-2])%mod;
        }
    }
	cout<<f[n];
    return 0;
}



Measured memory_bytes: 1408
#include <stdio.h>

int 
main(){
	int N,X;
	int L[100];

	scanf("%d %d",&N ,&X);
	int i;
	for(i=0;i<N;i++)scanf("%d",&L[i]);
	
	int D=0;
	int cnt=1;
	for(i=0;i<N;i++){
		D += L[i];
		if(D<=X)cnt++;
	}
	printf("%d\n",cnt);
 return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
string S;
char c;
int Q,d,q,F,j;
cin>>S>>Q;
deque<char> s;
for(auto i:S)s.push_back(i);
for(int i=0;i<Q;i++){
cin>>q;
if(q==1){
d^=1;
}else{
cin>>F>>c;
if(d+F==2){s.push_back(c);}else{s.push_front(c);}
}
}
while(j<s.size()){cout<<s[d==0?j:s.size()-j-1];j++;}
}

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

#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SIZE(array) (sizeof(array) / sizeof(array[0]))

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

#define MAX_V 100000

#define MOD 1000000007L
#define INF 100000000000

bool solve(int a, int b, int c) {
	return b - a == c - b;
}

signed main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << (solve(a, b, c) ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lim 100005
#define mod 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define sd(n) scanf("%lld",&n)
 int main()
 {
 ll h,w,n;
 cin>>h>>w>>n;
 ll a[n];
 for(ll i=0;i<n;i++)
  cin>>a[i];
ll ans[h+1][w+1];
ll i=0,j=0,k=0,t=0;
while(k<n)
{
  ans[i][j]=k+1;
  a[k]--;
  if(a[k]==0)
    k++;
  if(t==0)
  {
    i++;
    if(i==h)
    {
      i--;
      j++;
      t=!t;
    }
  }
  else
  {
    i--;
    if(i==-1)
    {
      i++;
      j++;
      t=!t;
    }
  }
}
for(ll i=0;i<h;i++)
{
  for(ll j=0;j<w;j++)
    cout<<ans[i][j]<<" ";
  cout<<endl;
}
 }

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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

typedef long long Weight;
const Weight WEIGHT_INF = std::numeric_limits<Weight>::max()/4;

struct Edge {
    int src, dst;
    Weight weight;
};
bool operator<(const Edge& a, const Edge& b) {
    return (a.weight < b.weight);
};
bool operator>(const Edge& a, const Edge& b) {
    return (a.weight > b.weight);
};
typedef std::vector<Edge> Edges;
typedef std::vector<Edges> Graph;

Graph g;
Edges msTree;
Weight prim(int r) {
    int n = g.size();
    Edges T;
    Weight total = 0;
    std::vector<bool> visited(n, false);
    std::priority_queue<Edge, std::vector<Edge>, std::greater<Edge> > que;
    que.push(Edge{-1, r, 0});
    while(!que.empty()) {
        Edge e = que.top();
        que.pop();
        if(visited[e.dst]) continue;
        T.push_back(e);
        total += e.weight;
        visited[e.dst] = true;
        for(auto ce: g[e.dst]){
            if(!visited[ce.dst]) {
                que.push(ce);
            }
        }
    }
    return total;
}

int V, E;
int main() {
    std::cin >> V >> E;
    g.resize(V);
    REP(i, E) {
        int s, t, w;
        std::cin >> s >> t >> w;
        Edge e1{s, t, w};
        Edge e2{t, s, w};
        g[s].pb(e1);
        g[t].pb(e2);
    }
    auto res = prim(0);
    std::cout << res << std::endl;
}

Measured memory_bytes: 10564
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    ll N;
    cin >> N;
    ll count=0;
    vector<ll> A(N);
    ll Amax = pow(10,6);
    vector<ll> divs(Amax+1);
    for(size_t i=0;i<N; i++)
    {
        cin >> A[i];
        divs[A[i]]++;
    }
    ll div_count = 0;
    for(size_t i=0;i<=Amax; i++)
    {
        if(divs[i]==0) continue;
        if(divs[i]==1) div_count++;
        for(size_t j=2;i*j<=Amax; j++)
        {
            divs[i*j]=0;
        }
    }
    cout << div_count << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 12672
using System;
using System.Linq;
using System.Collections.Generic;

namespace abc126
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] month = { "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", };
            string onetwo = s.Substring(0,2);
            string thrfour = s.Substring(2, 2);
            string ans;
            if (!month.Contains(onetwo.ToString()) && month.Contains(thrfour.ToString())) ans = "YYMM";
            else if (month.Contains(onetwo.ToString()) && !month.Contains(thrfour.ToString())) ans = "MMYY";
            else if (month.Contains(onetwo.ToString()) && month.Contains(thrfour.ToString())) ans = "AMBIGUOUS";
            else ans = "NA";
            Console.Write(ans);

        }
    }
}

Measured memory_bytes: 11220
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
  long long int a,b,n;
  while(cin >> a >> b >> n){
    int sum = 0;
    for(int i = 0; i < n; i++){
      a *= 10;
      sum  += (a/b)%10;
      a %= b;
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
vector<int> G[2<<17];
int S[2<<17];
void dfs(int u, int p, int s) {
	S[u] += s;
	for (int v: G[u]) {
		if (v != p) {
			dfs(v, u, S[u]);
		}
	}
	return;
}
void solve() {
	int n, q; cin >> n >> q;
	rep (i, n - 1) {
		int a, b; cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	rep (i, q) {
		int p, x; cin >> p >> x;
		p--;
		S[p] += x;
	}
	dfs(0, -1 , 0);
	rep (i, n) {
		cout << S[i] << endl;
	}
	return;
}

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

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

int main()
{
  ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
  int x;
  cin >> x;
  long double ans = (-1.0 + sqrt(8.0*x+1.0))/2.0;
  cout << int(ceil(ans)) << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100;
 
 
ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}
 
bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}
 
int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}
 
 
int main(){
    int a, b;
    cin >> a >> b;
    int k = keta(b);
    int num = a * pow(10, k) + b;
    rep(i, 1000){
        if(i * i == num){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

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

using namespace std;

bool solve(string s)
{
  if(s == "ABC") return true;
  if(s.find("ABC") == string::npos) return false;
  set<char> st;
  for(int i = 0; i < s.size(); i++) {
    if(i+3 <= s.size() && s.substr(i, 3) == "ABC") i += 2;
    else st.insert(s[i]);
  }
  bool ret = false;
  for(char c = 'A'; c < 'D'; c++) {
    if(st.find(c) != st.end()) continue;
    string t = "";
    for(int i = 0; i < s.size(); i++) {
      if(i+3 <= s.size() && s.substr(i, 3) == "ABC") t += c, i += 2;
      else t += s[i];
    }
    ret |= solve(t);
  }
  return ret;
}

int main()
{
  string s; cin >> s;
  cout << (solve(s) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 22128
#include <stdio.h>

int main()
{
    int A[4][3][10]={0};
    int i,j,k,n;
    int b,f,r,v;
    scanf("%d",&n);
    for(i=0; i<n; i++){
        scanf("%d%d%d%d",&b,&f,&r,&v);
        A[b-1][f-1][r-1]=A[b-1][f-1][r-1]+v;
    }
    
    for(i=0;i <4;i++){
        for(j=0;j<3;j++){
            for(k =0; k<10;k++){
            printf(" %d",A[i][j][k]);
            }
            printf("\n");
        }
        if(i != 3)printf("####################\n");
    }
    return 0;
}
    



Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

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

  int ans = 0;
  int tmp = 0;
  for (int i = 0; i < N + 1; i++)
  {
    int A = 0;
    cin >> A;
    if (A == 0)
    {
      ans += tmp / 2;
      tmp = 0;
    }
    else tmp += A;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N int(1e5)
int main(void)
{
	int n, a[N], ans = 0;
	map<int, int> ma;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
	{
		scanf("%d", a + i);
		ma[a[i]]++;
	}
	map<int, int>::iterator mite = ma.begin();
	for(mite; mite != ma.end(); mite++)
	{
		if(mite->first != mite->second)
		{
			ans += mite->first > mite->second ? mite->second : mite->second - mite->first;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int b;
  cin >> b;
  string a;
  cin >> a;
  for(int i = 0;i < b;i++){
    for(int j = 0;j < a.size();j++){
      if(a.at(j) == 'Z')a.at(j) = 'A';
      else{a.at(j)++;}
    }
  }
  cout << a << endl;
}

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

struct Node{
    int key;
    Node *parent,*left,*right;
};

Node *nil,*root=nil;

void insert(int key){
    Node *x=root;
    Node *y=nil;
    Node *z=new Node;
    z->key=key;
    z->left=z->right=nil;
    while(x!=nil){
        y=x;
        if(z->key<x->key) x=x->left;
        else x=x->right;
    }
    z->parent=y;
    if(y==nil) root=z;
    else if(z->key<y->key) y->left=z;
    else y->right=z;
}

bool find(Node *u,int key){
    while(u!=nil&&u->key!=key){
        if(key<u->key) u=u->left;
        else u=u->right;
    }
    if(u!=nil) return true;
    else return false;
}

void inorder(Node *u){
    if(u==nil) return;
    inorder(u->left);
    cout<<' '<<u->key;
    inorder(u->right);
}

void preorder(Node *u){
    if(u==nil) return;
    cout<<' '<<u->key;
    preorder(u->left);
    preorder(u->right);
}

int main(){
    int m,k;
    string com;
    cin>>m;
    for(int i=0;i<m;i++){
        cin>>com;
        if(com=="insert"){
            cin>>k;
            insert(k);
        }
        else if(com=="find"){
            cin>>k;
            if(find(root,k)) cout<<"yes"<<endl;
            else cout<<"no"<<endl;
        }
        else if(com=="print"){
            inorder(root);
            cout<<endl;
            preorder(root);
            cout<<endl;
        }
    }
}


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

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


void f(ll x, ll d, vector<ll>& v, vector<ll>& s) {
  if(d==5)
    return;
  for(auto val: v) {
    s.push_back(x*10+val);
    f(x*10+val, d+1, v, s);
  }
}

void solve(long long N, long long K, std::vector<long long> D){
  vector<ll> v;
  vector<ll> x;
  for(ll i=0; i<10; i++) {
    auto res = find(D.begin(), D.end(), i);
    if(res == D.end())
      v.push_back(i);
  }
  f(0, 0, v, x);
  
  // for(ll i=0; i<v.size(); i++) {
  //   x.push_back(v[i]);
  // }
  // for(ll i=0; i<v.size(); i++) {
  //   for(ll j=0; j<v.size(); j++) {
  //     x.push_back(v[j]*10+v[i]);
  //   }
  // }
  // for(ll i=0; i<v.size(); i++) {
  //   for(ll j=0; j<v.size(); j++) {
  //     for(ll k=0; k<v.size(); k++) {
  // 	x.push_back(v[k]*100+v[j]*10+v[i]);
  //     }
  //   }
  // }
  // for(ll i=0; i<v.size(); i++) {
  //   for(ll j=0; j<v.size(); j++) {
  //     for(ll k=0; k<v.size(); k++) {
  // 	for(ll l=0; l<v.size(); l++) {
  // 	  x.push_back(v[l]*1000+v[k]*100+v[j]*10+v[i]);
  // 	}
  //     }
  //   }
  // }
  // for(ll i=0; i<v.size(); i++) {
  //   for(ll j=0; j<v.size(); j++) {
  //     for(ll k=0; k<v.size(); k++) {
  // 	for(ll l=0; l<v.size(); l++) {
  // 	  for(ll m=0; m<v.size(); m++) {
  // 	    x.push_back(v[m]*10000+v[l]*1000+v[k]*100+v[j]*10+v[i]);
  // 	  }
  // 	}
  //     }
  //   }
  // }
  sort(x.begin(), x.end());
  ll n = N;
  while(n!=0) {
    ll y = n % 10;
    n = n / 10;

    if(find(D.begin(), D.end(), y) != D.end()) {
      auto it = lower_bound(x.begin(), x.end(), N);
      std::cout << *it << std::endl;
      return;
    }
  }
  std::cout << N << std::endl;
}

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


Measured memory_bytes: 1400
import sys
input = sys.stdin.readline
import math
def print_ans(ar):
    """Test Case
    >>> print_ans([5, 7, 5])
    Yes
    >>> print_ans([4, 4, 4])
    No
    >>> print_ans([4, 9, 6])
    No
    >>> print_ans([3, 3, 4])
    Yes
    """
    print("Yes" if len(set(ar)) == 2 else "No")


if __name__ == '__main__':
    ar = list(map(int, input().rstrip().split()))
    print_ans(ar)




Measured memory_bytes: 2940
#include<map>
#include<string>
#include<vector>
#include<complex>
#include<iostream>

#define	pb	push_back

using namespace std;

typedef	complex<int>	P;

const int dx[]={1,1,0,-1,-1,-1,0,1},dy[]={0,1,1,1,0,-1,-1,-1};

int w,h;
string pic[1000];

void trace(const P &p,vector<P> &v,int bef){
	int x=p.real(),y=p.imag();
	pic[y][x]='+';
	for(int i=0;i<8;i++){
		int xx=x+dx[i],yy=y+dy[i];
		if(0<=xx && xx<w && 0<=yy && yy<h && pic[yy][xx]=='*'){
			if(i!=bef)	v.pb(P(x,y));
			trace(P(xx,yy),v,i);
			break;
		}
	}
}

int main(){
	w=80;
	for(int t=0;cin>>h,h;t++){
		cin.ignore();
		for(int i=0;i<h;i++){
			getline(cin,pic[i]);
			pic[i]+=string(w-pic[i].length(),' ');
		}

		map<int,int> acnt;
		for(int i=0;i<h;i++)for(int j=0;j<w;j++){
			if(pic[i][j]=='*'){
				vector<P> v;
				trace(P(j,i),v,-1);
				int ub=v[1].real()-v[0].real()+1;
				int lb=v[2].real()-v[3].real()+1;
				int hh=v[2].imag()-v[0].imag()+1;
				acnt[(ub+lb)*hh/2]++;
			}
		}

		map<int,int>::iterator it;
		if(t)	cout<<"----------"<<endl;
		for(it=acnt.begin();it!=acnt.end();it++){
			cout<<it->first<<' '<<it->second<<endl;
		}
	}

	return 0;
}

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

uint64_t gcd(const uint64_t a, const uint64_t b) {
    if(a == 0) {
        return b;
    }

    return gcd(b % a, a);
}

// this function returns number of primes p which satisfies
// p divides d
// p >= start
int solve(uint64_t d, const uint64_t start) {
    if(d <= 1) {
        return 0;
    }

    const int p_max = std::floor(std::sqrt(d));

    for(int p = start; p <= p_max; ++p) {
        if(d % p == 0) {
            do {
                d /= p;
            } while(d % p == 0);

            return solve(d, p + 1) + 1;
        }
    }

    // d itself is prime
    return 1;
}

int main() {
    uint64_t a, b;
    std::cin >> a >> b;

    const uint64_t d = gcd(a, b);

    const int answer = 1 + solve(d, 2);

    std::cout << answer;

    return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main() {
	int N;
	cin >>  N;
	
	vector<string> s;
	for(int i = 0;i<N;i++){
		string si;
		cin >> si;
		s.push_back(si);
	}
	
	int ans = 0;
 
	for(int j = 0; j < N ; j++){
		for(int i = 1; i < s[j].size(); i++){
			if(s[j][i-1]=='A' && s[j][i]=='B') ans++;
		}
	}
 
	int a=0,b=0,c=0;
	for(int j = 0; j < N ; j++){
		if(s[j].front()=='B' && s[j].back()=='A')c++;	
		else if(s[j].back()=='A')a++;
		else if(s[j].front()=='B') b++;
	}
 
	if(a == b && a==0 && c>0) ans += c-1;
  	else ans += min(a,b)+c;
	cout << ans;
}

Measured memory_bytes: 768