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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

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

    int N=S.size();
    vector<int> T;
    vector<int> modtt(N+1);
    int k,moda=0,ans=0;
    modtt[0]=1;
    rep(i,N){
        if(S[N-i-1]=='?'){
            T.push_back(i);
        }else{
            k=S[N-i-1]-'0';
            moda+=modtt[i]*k;
            moda%=13;
        }
        modtt[i+1]=(modtt[i]*10)%13;
    }
    if(T.size()==0){
        cout<<( (moda==5) ? 1 : 0 )<<endl;
        return 0;
    }
    vector<ll> modbak(13,0),modbakb(13,0),modbakc(13,0);
    modbak[moda]++;
    rep(k,T.size()){
        rep(i,10)
            modbakb[(modtt[T[k]]*i)%13]++;
        rep(i,13)
            rep(l,13)
                modbakc[(i+l)%13]+=modbak[i]*modbakb[l];
        rep(i,13){
            modbak[i]=modbakc[i]%mod;
            modbakb[i]=0;
            modbakc[i]=0;
        }
    }
    cout<< modbak[5] <<endl;
    return (0);
}

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

const int maxn=1e5+10;

int n,m,u,v,cnt=0,ans[maxn][2],dep[maxn];
vector<int> E[maxn];
bool Vis[maxn];

void ad(int u,int v){
	ans[cnt][0]=u;
	ans[cnt][1]=v;
	++cnt;
}

bool DFS(int o,int fa){
	Vis[o]=true;
	int lft=0;
	for(int i=0,_=E[o].size();i<_;i++){
		int v=E[o][i];
		if(v==fa)continue;
		if(dep[v]==0){
			dep[v]=dep[o]+1;
			bool hs=DFS(v,o);
			if(hs){
				if(lft!=0){
					ad(o,v);
					ad(o,lft);
					lft=0;
				}else{
					lft=v;
				}
			}
		}else if(dep[v]<dep[o]){
			if(lft!=0){
				ad(o,v);
				ad(o,lft);
				lft=0;
			}else{
				lft=v;
			}
		}
	}
	if(lft!=0){
		ad(o,lft);
		ad(o,fa);
		return false;
	}
	return true;
}

int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>u>>v;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	bool flag=true;
	for(int i=1;i<=n&&flag;i++){
		if(!Vis[i]){
			dep[i]=1;
			if(!DFS(i,0))flag=false;
		}
	}
	if(flag){
		for(int i=0;i<cnt;i++){
			cout<<ans[i][0]<<' '<<ans[i][1]<<endl;
		}
	}else{
		cout<<-1;
	}
	return 0;
}

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

int main() {

  int N ;
  cin >> N ;
  ll ans = 1e18 ;
  ll count = 0 ;
  vector<int> A(N) ;
  rep(i,N) cin >> A.at(i) ;
  rep(i,101){
    rep(j,N) count += ( A.at(j) - i ) *  ( A.at(j) - i )  ;
    ans = min(ans,count) ;
    count = 0 ;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a1,a2,a3,a4,a5,a6;
	int x1,y1,z1,x2,y2,z2,r1,h1,m1,s1,k1;
int i;
	for(i=0;i<3;i++)	{
		scanf("%d %d %d %d %d %d",&a1,&a2,&a3,&a4,&a5,&a6);
		x1=a1*3600;
		y1=a2*60;
		z1=x1+y1+a3;
		x2=a4*3600;
		y2=a5*60;
		
		z2=x2+y2+a6;
		r1=z2-z1;
		h1=r1/3600;
		k1=r1%3600;
		m1=k1/60;
		s1=k1%60;
		printf("%d %d %d\n",h1,m1,s1);
	}
	return 0;
}

Measured memory_bytes: 1812
#include <algorithm>
#include <climits>
#include <iostream>

using namespace std;

int main(void)
{
	int N;
	cin >> N;
	int a[N], b[N], c[N];
	for (int i = 0; i < N; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}

	int d[N][3];
	d[0][0] = a[0];
	d[0][1] = b[0];
	d[0][2] = c[0];
	for (int i = 1; i < N; i++) {
		d[i][0] = max(d[i-1][1]+a[i], d[i-1][2]+a[i]);
		d[i][1] = max(d[i-1][0]+b[i], d[i-1][2]+b[i]);
		d[i][2] = max(d[i-1][0]+c[i], d[i-1][1]+c[i]);
	}
	cout << *max_element(&d[N-1][0], &d[N-1][3]) << endl;
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string n;
  cin >> n;
  int l=n.size();
  switch (n.at(l-1)) {
		case '3':
			cout << "bon";
			break;
		case '0':
			cout << "pon";
			break;
        case '1':
			cout << "pon";
			break;
        case '6':
			cout << "pon";
			break;
        case '8':
			cout << "pon";
			break;
		default:
			cout << "hon";
			break;
	}
  return 0;
}

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

int main(){
  string S,T;
  cin>>S;
  cin>>T;
  int count=0;
  for(int i=0;i<3;++i){
    if(S.at(i)==T.at(i)){
      ++count;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
N = int(input())
A_list = [int(e) for e in input().split()]
B_list = [int(e) for e in input().split()]

#B-Aで過剰/不足を取得
#過剰を並び替え、大きいものから不足に割り当てていく

shortage_list = list()
surplus_list = list()

for i in range(N):
    C = B_list[i]-A_list[i]
    if C > 0:
        shortage_list.append(C)
    elif C < 0:
        surplus_list.append(-C)
        
if sum(surplus_list) < sum(shortage_list):
    print(-1)
elif len(shortage_list) == 0:
    print(0)
else:
    surplus_list.sort(reverse=True)
    sum_shortage = sum(shortage_list)
    for i in range(len(surplus_list)):
        sum_shortage -= surplus_list[i]
        if sum_shortage <= 0:
            print(i + 1 + len(shortage_list))
            break

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

int main() {
	int		a[3],b,h,c,i,j,k,n,m,x,y,ans = 0;
	string	s,t,u;

	cin >> a[0] >> a[1] >> a[2];
	
	sort(a,a+3);
	
	if ((a[0] == a[1]) && ( a[1] != a[2])) {
		ans = 1;
	}

	if ((a[2] == a[1]) && ( a[1] != a[0])) {
		ans = 1;
	}
	
	if (ans == 1) printf("Yes\n");
	else printf("No\n");

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main() {
    int a,b;
    cin>>a>>b;
    if(a==b){
        cout<<"Draw"<<endl;
    }else if(a>b){
        if(b!=1){
            cout<<"Alice"<<endl;
        }else{
            cout<<"Bob"<<endl;
        }
    }else{
        if(a!=1){
            cout<<"Bob"<<endl;
        }else{
            cout<<"Alice"<<endl;
        }
    }
}   



Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <functional>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define _CRT_SECURE_NO_WARNIGS
#pragma warning (disable:4996)
using namespace std;
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

struct edge_t { int to, cap, rev; };
int maximum_flow_destructive(int s, int t, vector<vector<edge_t> > & g) { // ford fulkerson, O(EF)
	int n = g.size();
	vector<bool> used(n);
	function<int(int, int)> dfs = [&](int i, int f) {
		if (i == t) return f;
		used[i] = true;
		for (edge_t & e : g[i]) {
			if (used[e.to] or e.cap <= 0) continue;
			int nf = dfs(e.to, min(f, e.cap));
			if (nf > 0) {
				e.cap -= nf;
				g[e.to][e.rev].cap += nf;
				return nf;
			}
		}
		return 0;
	};
	int result = 0;
	while (true) {
		used.clear(); used.resize(n);
		int f = dfs(s, numeric_limits<int>::max());
		if (f == 0) break;
		result += f;
	}
	return result;
}
void add_edge(vector<vector<edge_t> > & g, int from, int to, int cap) {
	g[from].push_back(edge_t{ to, cap, int(g[to].size()) });
	g[to].push_back(edge_t { from, 0, int(g[from].size() - 1) });
}

int main() {
	// input
	int h, w; scanf("%d%d", &h, &w);
	int inf = 100000000;
	vector<vector<char> > f = vectors(h, w, char());
	repeat(y, h) repeat(x, w) scanf(" %c", &f[y][x]);
	// maximum flow
	const int src = 0;
	const int dst = 1;
	auto node_y = [&](int y) { return 2 + y; };
	auto node_x = [&](int x) { return 2 + h + x; };
	vector<vector<edge_t> > g(2 + h + w);
	repeat(y, h) repeat(x, w) {
		if (f[y][x] == 'S') {
			add_edge(g, src, node_y(y), inf);
			add_edge(g, src, node_x(x), inf);
		}
		else if (f[y][x] == 'T') {
			add_edge(g, node_y(y), dst, inf);
			add_edge(g, node_x(x), dst, inf);
		}
		if (f[y][x] != '.') {
			add_edge(g, node_y(y), node_x(x), 1);
			add_edge(g, node_x(x), node_y(y), 1);
		}
	}
	int flow = maximum_flow_destructive(src, dst, g);
	// output
	if (flow >= inf) flow = -1;
	printf("%d\n", flow);
	return 0;
}

Measured memory_bytes: 896
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;

int main() {
        int n;
        scanf("%d", &n);
        vector<vector<int>> g(n);
        for (int i = 0; i < n - 1; i ++) {
                int a, b;
                scanf("%d%d", &a, &b);
                a --, b --;
                g[a].push_back(b);
                g[b].push_back(a);
        }
        int leaf = 0;
        for (int i = 0; i < n; i ++) if (g[i].size() == 1) leaf ++;
        vector<int> dp(n), dp2(n);
        function<void (int, int)> dfs = [&](int u, int prev) {
                vector<int> len;
                for (auto v : g[u]) if (v != prev) {
                        dfs(v, u);
                        len.push_back(dp2[v]);
                        dp[u] = max(dp[u], dp[v]);
                        dp2[u] = max(dp2[u], dp2[v] + (g[u].size() == 2));
                }
                sort(len.begin(), len.end(), greater<int>());
                if (len.size() >= 2) dp[u] = max(dp[u], len[0] + len[1] + (g[u].size() == 2));
        };
        dfs(0, -1);
        printf("%d\n", dp[0] + leaf);
        return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int ans;
  if (n == 2) {
    ans = max(v[0], v[1]);
  }
  else {
    vector<int> f(n);
    vector<int> b(n);
    f[0] = v[0];
    for (int i = 1; i < n; i++) {
      f[i] = __gcd(f[i - 1], v[i]);
    }
    b[n - 1] = v[n - 1];
    for (int i = n - 2; i >= 0; i--) {
      b[i] = __gcd(b[i + 1], v[i]);
    }
    for (int i = 0; i < n; i++) {
      if (i == 0) {
        ans = b[1];
      }
      else if (i == n - 1) {
        if (ans < f[n - 2]) {
          ans = f[n - 2];
        }
      }
      else {
        ans = max(ans, __gcd(f[i - 1], b[i + 1]));
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define bitrep(i,s,n) for(long long i=(s);i<(1LL<<(n));i++)
#define bitcheck(bit,i) (bit)&(1LL<<(i))
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin,(s))

//Yes,No
void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//切り上げ除算
long long cutup(long long a,long long b){return (a+b-1)/b;}

//累乗
template<typename t>
constexpr t my_pow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
    }
    return x;
}
#define pow my_pow

//chmin,chmax
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin>>s;
    s[5]=' ';
    s[13]=' ';
    cout<<s<<endl;
}

Measured memory_bytes: 3640
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-8;

long long int N, M, K, L, R, H, W;
//int N, M, K, L, R, H, W;

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

	long double K;
	cin >> K;
	cout <<setprecision(20)<< K * K*K / 27 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define F first
#define S second

string s;

signed main(){
	cin>>s;
	int n=s.size();
	int A=0,B=0;
	r(i,n){
		char c;
		if(i%2==0)c='0';
		else c='1';
		if(s[i]!=c)A++;
	}
	r(i,n){
		char c;
		if(i%2==1)c='0';
		else c='1';
		if(s[i]!=c)B++;
	}
	cout<<min(A,B)<<endl;
}

Measured memory_bytes: 512
#include <stdio.h>
int main(void) {
	long long n, ans = 0, count = 5;
	scanf("%lld", &n);
	if (n % 2 == 1)
		ans = 0;
	else
		while (count <= n) {
			ans += n / count / 2;
			count *= 5;
		}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

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

    string ans;
    while(N) {
        --N;
        ans.push_back('a' + N%26);
        N /= 26;
    }

    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3628
// ABC156D - Bouquet

#include <bits/stdc++.h>
using namespace std;

#define MOD 1000000007

#define MOD 1000000007 // MOD must be prime number.

int powerMOD(int n, int p) {
	if (p == 0) {
		return 1;
	}
	if (p % 2 == 0) {
		long long int t = powerMOD(n, p / 2);
		return (int)(t * t % MOD);
	}
	return (int)(((long long int)n * powerMOD(n, p - 1))% MOD);
}

// Big number combination MOD Version
int nCr(int n, int r) {
	long long int retValue = 1;
	long long int temp = 1;

	for (int i = n; i > n - r; --i) {
		retValue *= i;
		retValue %= MOD;
	}

	for (int i = 1; i < r + 1; ++i) {
		temp *= i;
		temp %= MOD;
	}

	retValue *= powerMOD(temp, MOD - 2); // Fermat's little theorem
	retValue %= MOD;

	return (int)retValue;
}

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

	int answer;

	answer = powerMOD(2, n) - 1;
	answer = (answer - nCr(n, a)+ MOD)% MOD;
	answer = (answer - nCr(n, b)+ MOD)% MOD;

	cout << answer << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r) {
  int x, i, j, t;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j] <= x) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

int main(void) {
  int i, q;

  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d",&A[i]);
  q = partition(0,n-1);

  for(i=0; i<n; i++) {
    if(i) printf(" ");
    if(i==q) printf("[");
    printf("%d",A[i]);
    if(i==q) printf("]");
  }
  printf("\n");

  return 0;
}


Measured memory_bytes: 3056
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

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









Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<tuple>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
int main() {
	int n, m;
	cin >> n >> m;
	vector<int>a(m);
	int cnt = 0;
	rep(i, m) {
		cin >> a[i];
		cnt += a[i];
	}
	if (n < cnt) {
		cout << -1 << endl;
	}
	else {
		cout << n - cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3636
fun main(args: Array<String>) {
    val INF_MAX = 1000000007
    val N = readLine()!!.toInt()
    val W = readLine()!!.split(" ").map(String::toInt)
    var S1 = 0
    var S2 = W.sum()
    var result = INF_MAX
    W.forEach { w ->
        S1 += w
        S2 -= w
        result = Math.min(result, Math.abs(S1 - S2))
    }
    println(result)
}

Measured memory_bytes: 36008
n,x=map(int, input().split())
total = n
h = n-x
w = x
while h and w:
    if h == w:
        total += h
        h = 0
        w = 0
        break
    elif h > w:
        total += (h//w)*2*w
        h %= w
    else:
        total += (w//h)*2*h
        w %= h
total -= max(w,h)
print(total)

Measured memory_bytes: 7268
#include <stdio.h>
int bubble(int*, int);

int main(int argc, char const *argv[])
{
	int i, n, a[100];
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%d", &a[i]);
	}
	printf("\n%d\n", bubble(a, n));
	return 0;
}

int bubble(int *A, int n){
	int i, j, flag=1, temp, count;
	temp=count=i=0;
	while(flag){
		flag=0;
		for(j=n-1;j>0;j--){
			if(A[j]<A[j-1]){
				temp=A[j];
				A[j]=A[j-1];
				A[j-1]=temp;
				flag=1;
				count++;
			}
		}
	}
	for(i=0;i<n;i++){
		printf("%d", A[i]);
		if(i!=(n-1)){
			printf(" ");
		}
	}
	return count;
}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const long double PI = acos(-1);
const long long INF = (1 << 30);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  ll n;
  cin >> n;

  ll ans = 0;
  for(ll i = 1; i <= n; i++){
    for(ll j = 1; j <= n; j++){
      for(ll k = 1; k <= n; k++){
        ans += gcd(i, gcd(j, k));
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>

int s[1000];
int p;

void push(int x) {
  s[p]=x;
  p++;
}

int pop() {
  p--;
  return s[p];
}

int main() {
  p=0;
  char c[10];
  while(scanf("%s",c)==1) {
    if(c[0]=='+' || c[0]=='-' || c[0]=='*') {
      int x=pop();
      int y=pop();
      if(c[0]=='+') push(x+y);
      else if(c[0]=='-') push(y-x);
      else push(x*y);
    } else {
      int x=0,k=0;
      while(c[k]>='0' && c[k]<='9') {
	x*=10;
	x+=c[k]-'0';
	k++;
      }
      push(x);
    }
  }
  printf("%d\n",pop());
  return 0;
}


Measured memory_bytes: 540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;

int main()
{
    ll k, a, b;
    cin >> k >> a >> b;
    ll bis = 1, en = 0;
    if (a + 1 < b)
    {
        bool tata = false;
        rep(i, k - 1)
        {
            if (!tata)
            {
                if (bis >= a)
                {
                    en++;
                    bis -= a;
                    tata = true;
                }
                else
                    bis++;
            }
            else
            {
                if (en == 0)
                {
                    bis -= a;
                    en++;
                }
                else
                {
                    en--;
                    bis += b;
                }
            }
        }
        if (en == 0)
            bis++;
        else
            bis += b;
    }
    else
    {
        bis = bis + k;
    }

    cout << bis << endl;
}

Measured memory_bytes: 3616
<?php

fscanf(STDIN, "%d", $n);
$H = array_map('intval', explode(' ', trim(fgets(STDIN))));

$max = 0;
$flg = true;
for ($i = 0; $i < $n; ++$i) {
    if ($max - $H[$i] >= 2) {
        $flg = false;
        break;
    }

    $max = max($max, $H[$i]);
}

echo $flg ? 'Yes' : 'No';


Measured memory_bytes: 16884
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

inline bool r(char a) {
   if (a >= '0' && a <= '9') return true;
   else return false;
}

inline bool x(string a, string b) {
    if (a.size() > b.size()) return true;
    else if (a.size() == b.size() && a > b) return true;
    else return false;
}

int main(void){
    int w, h;
    while (cin>>w>>h && w) {
        vector<string> g(h);
        for (int i = 0; i < h; i++) cin >> g[i];
        
        vector<vector<string> > dp(h, vector<string>(w));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (r(g[i][j])) dp[i][j] = g[i][j];
            }
        }
        
        string ans = "";
        for (int i = h-1; i >= 0; i--) {
            for (int j = w-1; j >= 0; j--) {
                if (!r(g[i][j])) continue;
                if (j-1 >= 0 && r(g[i][j-1])) {
                    string t = g[i][j-1] + dp[i][j];
                    if (x(t, dp[i][j-1])) dp[i][j-1] = t;
                }
                if (i-1 >= 0 && r(g[i-1][j])) {
                    string t = g[i-1][j] + dp[i][j];
                    if (x(t, dp[i-1][j])) dp[i-1][j] = t;
                }
                if (dp[i][j][0] != '0' && x(dp[i][j], ans)) ans = dp[i][j];
            }
        }
        cout << ans << endl;
    }
}

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

int main(){
  int n;cin>>n;
  int a,b,c;
  int r1,r2,r3;
  cin>>r1>>r2>>r3;
  int t1,t2,t3;
  for(int i=1;i<n;++i){
    cin>>a>>b>>c;
    t1 = r1; t2 = r2; t3 = r3;
    // cout<<r1<<" "<<r2<<" "<<r3<<endl;
    r1 = max(t2+a,t3+a);
    r2 = max(t1+b,t3+b);
    r3 = max(t2+c,t1+c);
    
  }
  cout<<max(max(r1,r2),r3)<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int h,w;
	vector<vector<char>>bord;
	cin >> h >> w;
	vector<vector<int>>ANS;
	for(int i=0;i<h;i++){
		vector<char> bo;
		for(int j=0;j<w;j++){
			char t;
			cin >> t;
			bo.push_back(t);
		}
		bord.push_back(bo);
	}
	for(int i=0;i<h+2;i++){
		vector<int> AN;
		for(int j=0;j<w+2;j++){
			AN.push_back(0);
		}
		ANS.push_back(AN);
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(bord[i][j]=='#'){	
				ANS[i][j]++;
				ANS[i][j+1]++;
				ANS[i][j+2]++;
				ANS[i+1][j]++;
				ANS[i+1][j+2]++;
				ANS[i+2][j]++;
				ANS[i+2][j+1]++;
				ANS[i+2][j+2]++;
			}
		}
	}
	/*for(int i=0;i<h+2;i++){
		for(int j=0;j<w+2;j++){
			cout << ANS[i][j];
		}
		cout << endl;
	}*/
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(bord[i][j]=='#'){
				cout << "#";
			}
			else{
				cout << ANS[i+1][j+1];
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stdio.h>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
//　ceil(a/b)   (a + (b - 1))/ b
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

// int gcd(int a, int b){
//   if (a%b==0){
//     return(b);
//   }
//   else{
//     return(gcd(b,a%b));
//   }
// }


vector<int> v[100001];
int c[100000];
int y[100000];

int main(){
  int n;
  cin >> n;
  if(n == 1) cout << "Hello World" << endl;
  else {
    int a, b;
    cin >> a >> b;
    cout << a+b << endl;
  }
}



Measured memory_bytes: 2560
package main

import "fmt"

func main()  {
	var a, b, c int
	div := 0
	fmt.Scan(&a, &b, &c)
	for i := a; i < b+1; i++ {
		if c%i == 0 {
			div++
		}
	}
	fmt.Println(div)
}


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

#define int long long
#define fi first
#define se second
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) ct(v[i])
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define pb(n) push_back(n);

int ans=100;
string s;

main() {
    cin >> s;
    rep(i,26) {
        int cnt=0,cntmax=0;
        rep(j,s.size()) {
            if ('a'+i == s[j]) cntmax = max(cntmax,cnt),cnt=0;
            else cnt++;
        } cntmax = max(cntmax,cnt);
        ans = min(ans,cntmax);
    }
    ct(ans)
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,m;
  cin >> n >> m;
  vector<ll> num(n);
  for(int i = 0;i < n;i++)cin >> num[i],num[i] /= 2;
  ll k = -1;
  for(int i = 0;i < n;i++){
    ll nowk = 0;
    while(num[i] % 2 == 0)nowk++,num[i] /= 2;
    if(k == -1)k = nowk;
    else if(k != nowk){
      cout << 0 << endl;
      return 0;
    }
  }
  for(int i = 0;i < k;i++)m /= 2;
  //cout << num[0] << " " << num[1] << endl;
  ll lc = 1;
  for(int i = 0;i < n;i++){
    lc = lc * num[i] / __gcd(lc,num[i]);
    if(lc > m){
      cout << 0 << endl;
      return 0;
    }
  }
  //cout << lc << endl;
  if(lc > m)cout << 0 << endl;
  else cout << (m / lc + 1) / 2 << endl;
}

Measured memory_bytes: 4048
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

int num[5];

int main()
{
    int k;
    bool flag = true;

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

    cin >> k;

    for (int i = 0; i < 5; i++)
    {
        for (int j = i + 1; j < 5; j++)
        {
            if (num[j] - num[i] > k)
            {
                flag = false;
            }
        }
    }

    if (flag)
    {
        cout << "Yay!";
    }
    else
    {
        cout << ":(";
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,N) for(int i=0; i<N; i++){    ;
int main() {
 string T;
 cin>>T;
 int h=T.size();
 rep(i,h);
 if(T.at(i)=='?'){
     T.at(i)='D';
 }
}
cout<<T<<endl;
}

Measured memory_bytes: 3724
#include<stdio.h>
#include<iostream>
#include<cstdlib>

class Stack{
    private:
        int n;
        int *array;
        int top;
        
    public: Stack(int _n){
        top = 0;
        n = _n;
        array = new int[n];
    }
    
    bool isEmpty(){return top == 0;}
    bool isFull(){return top >= n-1;}
    public: int push(int o){
        if(isFull()){
            throw "Overflow";
        } else {
            top++;
            array[top] = o;
            return 1;
        }
    }
    public: int pop(){
        if(isEmpty()){
            throw "Underflow";
        } else {
            top--;
            return array[top+1];
        }
    }
    
    
};


int main(){
    char c[100];
    Stack st(200);
    int op1,op2,S;
    while(scanf("%s",c) != EOF){
        if(c[0] == '+'){
            op1 = st.pop();
            op2 = st.pop();
            st.push(op2+op1);
        } else if(c[0] == '-'){
            op1 = st.pop();
            op2 = st.pop();
            st.push(op2-op1);
        } else if(c[0] == '*'){
            op1 = st.pop();
            op2 = st.pop();
            st.push(op2*op1);
        } else {
            st.push(std::atoi(c));
        }
    }
    printf("%d\n",st.pop());
    
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<"@"<<__LINE__<<": "<<x<<endl
using ll = long long;
using vi = vector<int>;
using pii = pair<int,int>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int m;
    cin >> m;
    ll digits = 0, dsum = 0;
    rep(i,0,m) {
        ll c, d;
        cin >> d >> c;
        digits+=c;
        dsum += d*c;
    }
    ll ans = digits-1+(dsum-1)/9;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
h,w = map(int,input().split())
count = [0]*26
l = [input() for i in range(h)]
for i in l:
    for j in i:
        count[ord(j)-ord("a")] += 1

if h%2:
    if w%2:
        c = 0
        c2 = 0
        for i in count:
            if i%4:
                if i%2:
                    c2 += 1
                else:
                    c += 1
        if c <= w//2+h//2 and c2 == 1:
            print("Yes")
        else:
            print("No")
    
    else:
        c = 0
        for i in count:
            if i%4:
                if i%2:
                    print("No")
                    exit()
                else:
                    c += 1
        if c <= w//2:
            print("Yes")
        else:
            print("No")
else:
    if w%2:
        c = 0
        for i in count:
            if i%4:
                if i%2:
                    print("No")
                    exit()
                else:
                    c += 1
        if c <= h//2:
            print("Yes")
        else:
            print("No")
            
    else:
        for i in count:
            if i%4:
                print("No")
                exit()
        print("Yes")

Measured memory_bytes: 9108
import math

a, b, x = map(int, input().split())
if x < a**2 * b / 2:
    rad = math.pi / 2 - math.atan2(2 * x, a * b**2)
else:
    rad = math.atan2(2 * (a**2 * b - x), a**3)
deg = rad / math.pi * 180
print(deg)


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

#define int long long int
#define ll long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define pii pair<int, int>
#define mod 1000000007
#define pi 3.141592653589
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod) ;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<typename T>
// using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
// template<typename T>
// using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
//(*****FOR USING ORDERED SET CHANGE INT*******)

int power(int x, int y) ;
int gcd(int a, int b) ;


signed main() {
    quickie
    string s ;
    cin >> s ;
    int mx = 0, curr = 0 ;
    rep(i, 0, SZ(s)) {
        if(s[i] == 'R') curr++ ;
        else {
            mx = max(mx, curr) ;
            curr = 0 ;
        }
    }
    mx = max(mx, curr) ;
    cout << mx << "\n" ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}

int gcd(int a,int b){
    if(a==0) return b;
    return gcd(b%a,a);
}



Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>

using namespace std;
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(),x.end()

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

int main() {
	int x;
	cin >> x;
    if (x == 3 || x == 5 || x == 7) {
        Yes();
    }
    No();
}

Measured memory_bytes: 256
// AOJ 0056: Goldbach's Conjecture
// 2017.10.28 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#define TM 0
#if TM
#include <time.h>
#endif

#define MAX  50000
#define HALF 2761			// prime[2760]=24989, prime[2761]=25013
char tbl[MAX+1];			// zero: if prime 

int sz;						// max sz = 5132
int prime[5200] = {   		// prime[46] = 223, 223^2 = 49729
  3,  5,  7, 11, 13, 17, 19, 23, 29, 
 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 
 73, 79, 83, 89, 97,101,103,107,109,113, 
127,131,137,139,149,151,157,163,167,173, 
179,181,191,193,197,199,211,223 };

int sqp[47] = {				// squre of prime: sqp[i] = prime[i] * prime[i]
  9,25,49,121,169,289,361,529,841,961,
1369,1681,1849,2209,2809,3481,3721,4489,5041,
5329,6241,6889,7921,9409,10201,10609,11449,11881,12769,
16129,17161,18769,19321,22201,22801,24649,26569,27889,29929,
32041,32761,36481,37249,38809,39601,44521,49729 };

int ans[MAX+MAX] = {0,0,0,0,1,0};

int main()
{
	int i, j, k;
	char buf[10], *p;
#if TM
	clock_t start, finish;
	start = clock();
#endif

	for (i = 0; i < 47; i++) {
		k = prime[i];
//		for (j = k+k; j < MAX; j += k) tbl[j] = 1;		// k+k ? 
//		for (j = k*k; j < MAX; j += k) tbl[j] = 1;		// k*k ?
		for (j = sqp[i]; j < MAX; j += k) tbl[j] = 1;
	}
	for (sz = 47, i = 225; i <= MAX; i += 2) if (!tbl[i]) prime[sz++] = i;
	for (i = 0; i < HALF; i++) {
		for (j = i; prime[i]+prime[j] <= MAX; j++) ans[prime[i]+prime[j]]++;
	}

	while (fgets(p=buf, 8, stdin) && *p != '0') {
		i = 0; while (*p >= '0') i = (i<<3) + (i<<1) + (*p++ & 0xf);
		if (i & 1) putchar('1'-tbl[i-2]);
		else printf("%d", ans[i]);
		putchar('\n');
	}
#if TM
	finish = clock();
	printf("time %lf\n", (double)(finish-start)/CLOCKS_PER_SEC);
#endif
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define fr(i,k) for(i=0;i<k;i++)
#define ALL(c) (c).begin(),(c).end()
#define deb(x) cerr<<#x<<"  = "<<x<<endl;
#define SZ(x) (x).size();
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define em emplace_back
#define ulli unsigned long long int
#define INF 1e18
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> ii;
void solve();

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main() {
	fastio;
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/

	int t;
	t=1;

    //cin>>t;
	while (t--)
	{
		solve();
	}
	return 0;
}

void solve()
{
	ll n,m,i,j,ans,c;
	string s1,s2;
	cin>>s1>>s2;

	n=s1.size();
	m=s2.size();

    ans=m;
    for(i=0;i<n-m+1;i++)
    {
        c=0;
        for(j=0;j<m;j++)
        {
            if(s1[i+j]==s2[j])
            {
                c++;
            }
        }
        ans=min(ans,m-c);

    }

    cout<<ans<<endl;
}


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

int main() {
	int T; cin >> T;
	for (int t = 1; t <= T;t++) {
		double xa, ya, ra, xb, yb, rb;
		cin >> xa >> ya >> ra >> xb >> yb >> rb;

		double dist = pow(xa - xb, 2) + pow(ya - yb, 2);
		if (pow(ra + rb, 2) < dist) {
			cout << 0 << endl;
		}
		else {
			if (dist < pow(ra - rb, 2) && rb < ra) {
				cout << 2 << endl;
			}
			else if(dist < pow(ra - rb,2) && ra < rb){
				cout << -2 << endl;
			}
			else {
				cout << 1 << endl;
			}
		}
	}
}

Measured memory_bytes: 3128
/* ANTHOR KUMAR DAS
KUET ECE 2K18*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define sc(a) scanf("%d",&a)
#define sc1(n) scanf("%lld",&n)
#define sc2(b,c) scanf("%lld%lld",&b,&c)
#define f(a,b) for(a=0;a<b;a++)
#define pb(a) push_back(a)
#define br break
int main()
{
    int n,a;
    cin>>n;
    a=n*n*n;
    cout<<a<<endl;

    return 0;
}



Measured memory_bytes: 256
N = int(input())
l = list(map(int, input().split(" ")))

left = 0
right = 0
sum_list = 0
count = 0

while right < N:
    if sum_list & l[right] == 0:
        sum_list += l[right]
        right += 1
        count += right - left
    elif left == right:
        left += 1
        right += 1
    # 左端を進める
    else:
        sum_list -= l[left]
        left += 1

print(count)


Measured memory_bytes: 24712
import java.util.Scanner;

public class Main {
    public static void main(String [] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long [] a = new long[n + 1];
        long [] b = new long[n + 1];
        long [] c = new long[n + 1];
        long [][] happy = new long [n + 1][3];

        for (int i = 1; i <= n; ++i) {
            a[i] = scanner.nextLong();
            b[i] = scanner.nextLong();
            c[i] = scanner.nextLong();
        }
        happy[0][0] = 0;
        happy[0][1] = 0;
        happy[0][2] = 0;
        for (int i = 1; i <= n; ++i) {
            happy[i][0] = Math.max(happy[i - 1][1] + a[i],
                    happy[i - 1][2] + a[i]
                    );
            happy[i][1] = Math.max(happy[i - 1][0] + b[i],
                    happy[i - 1][2] + b[i]);
            happy[i][2] = Math.max(happy[i - 1][0] + c[i],
                    happy[i - 1][1] + c[i]);
        }
        System.out.println(Math.max(happy[n][0], Math.max(happy[n][1], happy[n][2])));
    }
}


Measured memory_bytes: 103348
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX(a,b) ((a)>(b)?(a):(b))

#define POS(i,j) ((i)*(m+1)+(j))

void run(void){
  char *s=(char *)calloc(3000+1,sizeof(char));
  char *t=(char *)calloc(3000+1,sizeof(char));
  scanf("%s",s);
  scanf("%s",t);
  int n=strlen(s);
  int m=strlen(t);
  int *dp=(int *)calloc((n+1)*(m+1),sizeof(int));
  int i,j;
  for(i=1;i<=n;i++){
    for(j=1;j<=m;j++){
      if(s[i-1]==t[j-1]){
	dp[POS(i,j)]=dp[POS(i-1,j-1)]+1;
      } else {
	dp[POS(i,j)]=MAX(dp[POS(i-1,j)],dp[POS(i,j-1)]);
      }
    }
  }
  char *ans=(char *)calloc(3000+1,sizeof(char));
  int front=3000;
  i=n;
  j=m;
  while(i>0 && j>0){
    if(s[i-1]==t[j-1]){
      ans[--front]=s[i-1];
      i--;
      j--;
    } else if(dp[POS(i,j)]==dp[POS(i-1,j)]){
      i--;
    } else {
      j--;
    }
  }
  printf("%s\n",ans+front);
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 35328
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>
#include <numeric>
#include <iomanip>

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

using namespace std;

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

    vector<int> check(n);
    vector<int> wa_count(n);

    int ac_ans = 0;
    int wa_ans = 0;

    for (int i = 0; i < m; i++)
    {
        int n; cin >> n;
        string s; cin >> s;

        if (s == "AC" && check[n-1] == 0)
        {
            check[n-1] = 1;
            ac_ans++;
        }
        else if (s == "AC" && check[n-1] == 1)
        {
            
        }
        else if (s == "WA" && check[n-1] == 0)
        {
            wa_count[n-1]++;
        }
        else if (s == "WA" && check[n-1] == 1)
        {
            
        }
    }

    for (int i = 0; i < n; i++)
    {
        if (check[i] == 1)
        {
            wa_ans += wa_count[i];
        }
        
    }
    

    cout << ac_ans << " " << wa_ans << endl;
    
}


Measured memory_bytes: 1152
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef unsigned long ul;
typedef pair<ul, ul> P;
map<int, int> dp;
#define REP(i,n) for(ul i=0;i<n;i++)

ul L, R, N, M, Q;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> Q;
    P LR[M];
    auto pq = vector<P> (Q, make_pair(0, 0));
    auto train_table = vector<vector<int>> (N + 1, vector<int>(N + 1, 0));
    auto cum = vector<vector<int>> (N + 1, vector<int>(N + 1, 0));
    REP(itr, M) {
      cin >> LR[itr].first >> LR[itr].second;
      ++train_table[LR[itr].first][LR[itr].second];
    }
    for (int i = 1; i <= N; ++i) {
      for (int j = 1; j <= N; ++j) {
        cum[i][j] = cum[i][j-1] + train_table[i][j];
      }
    }

    for (ul itr = 0; itr < Q ; ++itr) {
      cin >> pq[itr].first >> pq[itr].second;
      ul ans = 0;
      for (ul j = pq[itr].first; j <= pq[itr].second; ++j) {
        ans += cum[j][pq[itr].second];
      }
      cout << ans << endl;
    }
}


Measured memory_bytes: 7680
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#define REP(i,a,n) for(int i = a;i < n;i++)
#define ll long long 
#define MAX 100000
#define INF 100000000
using namespace std;

int N, A, B, C;
int l[10];

int dfs(int cur, int a, int b, int c) {
    int ret0, ret1, ret2, ret3;
    if (cur == N) {
        if (a > 0 && b > 0 && c > 0) {
            return abs(a-A) + abs(b-B) + abs(c-C) -30;
        } else {
            return INF;
        }
    }

    ret0 = dfs(cur+1, a, b, c);
    ret1 = dfs(cur+1, a+l[cur], b, c) + 10;
    ret2 = dfs(cur+1, a, b+l[cur], c) + 10;
    ret3 = dfs(cur+1, a, b, c+l[cur]) + 10;

    return min({ret0, ret1, ret2, ret3});
}

int main(void) {
    scanf("%d %d %d %d", &N, &A, &B, &C);
    for (int i=0; i<N; i++) {
        scanf("%d", &l[i]);
    }

    printf("%d\n", dfs(0,0,0,0));
}


Measured memory_bytes: 256
/*input
*/
#include <bits/stdc++.h>
using namespace std;
 
#define all(a) a.begin(),a.end()
#define ff first
#define ss second
#define pb push_back
 
using ll = long long;
using pii = pair<int, int>;
using ld = long double;
 
template<typename T> using V = vector<T>;
 
int main() {
	ios::sync_with_stdio(false);cin.tie(nullptr);
	int k, x; cin >> k >> x;
	for (int i = x-k+1; i <= x+k-1; ++i) {
		cout << i << ' ';
	}
	return 0;
}

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

int main() {
    int n;
    string s,t,ans="";
    cin>>n>>s>>t;
  	for(int i=0;i<2*n;i++){
      ans += "a";
    }
  	int counter = 0;
    for(int i=0;i<2*n;i+=2){
        ans.at(i)=s.at(counter);
      	ans.at(i+1)=t.at(counter);
      counter++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
 
s = []
 
for i in range(n):
    s.append(input())
 
m = int(input())
 
t = []
 
for i in range(m):
    t.append(input())

x = 0

for i in range(n):
	x = max(x, s.count(s[i])-t.count(s[i]))
print(x)


Measured memory_bytes: 3060
#include <iostream>

int main(){
  long long L , R ;
  std::cin >> L >> R;
  int min = 2018 * 2018;
  
  if( R - L >= 2019){
    std::cout << 0 << std::endl;
    return 0;
  }else{
    for(int i = L ; i <= R ; i++ ){
      for(int j = i + 1; j <= R ; j++ ){
	int l = i % 2019;
	int r = j % 2019;
	int Z = l * r;
	int min_temp = l * r % 2019;
	if(min >= min_temp) min = min_temp;
      }
    }
  }
  std::cout << min << std::endl;
  return 0;
}


Measured memory_bytes: 256
//競技プログラミング用のテンプレート
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <math.h>
#include <stack>
#include <limits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repr(i, n) for(int i = n - 1; i >= 0; i--)

using namespace std;
//エイリアス
using ll = long long int;
using p = pair<int, int>;
using pl = pair<ll, ll>;
using v = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vl = vector<ll>;

//定数
const int intmax = numeric_limits<int>::max();
const ll llmax = numeric_limits<ll>::max();
const ll mod = 1e9 + 7;
const double pi = M_PI;

int main()
{
  string n;
  cin >> n;
  ll t = 0;
  rep(i, n.size()) {
    t += n[i] - '0';
  }
  if (t % 9 == 0) {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

using namespace std;

int N, K;
vector<int> adj[2001];
int sz[2001];
int dp[2001][2001];
int ndp[2001][2001];

void dfs(int u, int p)
{
    sz[u]=1;
    dp[u][0]=1;
    ndp[u][0]=1;
    for(auto& v: adj[u]) if(v!=p)
    {
        dfs(v, u);
        for(int i=0; i<sz[u]; i++)
            for(int j=0; j<sz[v] && i+j+1<=K; j++)
                ndp[u][max(i, j+1)]=max(ndp[u][max(i, j+1)], dp[u][i]+dp[v][j]);
        sz[u]+=sz[v];
        for(int i=0; i<sz[u]; i++)
            dp[u][i]=ndp[u][i];
    }
}

int main()
{
    scanf("%d%d", &N, &K);
    for(int i=0; i<N-1; i++)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(1, 1);
    int ans=0;
    for(int i=1; i<=N; i++)
        for(int j=0; j<=K; j++)
            ans=max(ans, dp[i][j]);
    printf("%d\n", N-ans);
    return 0;
}


Measured memory_bytes: 25600