akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main() {
  int n;
  scanf("%d", &n);

  unsigned long long sum = 0;

  for (int i = 1; i <= n; i++) {
    if (!(i % 3 == 0 || i % 5 == 0)) {
      sum += i;
    }
  }

  printf("%llu\n", sum);
}

Measured memory_bytes: 3812
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long LL;
const int INF = 1 << 25;
const LL MOD = 1000000007LL;
using namespace std;
typedef pair<int, int> P;
struct UnionFind {
	int *par;
	int *rank;
	UnionFind(int n) {
		par = new int[n];
		rank = new int[n];
		rep(i, n) {
			par[i] = i;
			rank[i] = 0;
		}
	}
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y]) rank[x]++;
		}
	}
};
int main() {
	int N, K, L;
	cin >> N >> K >> L;
	UnionFind road(N), rail(N);
	rep(i, K) {
		int p, q;
		cin >> p >> q;
		p--; q--;
		road.unite(p, q);
	}
	rep(i, L) {
		int r, s;
		cin >> r >> s;
		r--; s--;
		rail.unite(r, s);
	}
	map<P, int> cnt;
	rep(i, N) {
		cnt[P(road.find(i), rail.find(i))]++;
	}
	rep(i, N) {
		if (i > 0) cout << " ";
		cout << cnt[P(road.find(i), rail.find(i))];
	}
	cout << endl;
}

Measured memory_bytes: 15104
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL<<60;

int main() {
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; ++i) cin >> A[i] >> B[i];
    
    vector<long long> dp(H+1, INF);
    dp[0] = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= H; ++j) {
            chmin(dp[min(j+A[i], H)], dp[j] + B[i]);
        }
    }
    cout << dp[H] << endl;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long a[n],ans=0;
    for(int i=0;i<n;i++)
    cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<n-2;i++)
    {
        for(int j=i+1;j<n-1;j++)
        {
            int k=j+1,cnt=0;
            while(k<n&&a[i]+a[j]>a[k])
            {
                if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k])
                cnt++;
                k++;
            }
            ans+=cnt;
        }
    }
    cout<<ans;
    
}

Measured memory_bytes: 3632
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll N, Z, W; cin >> N >> Z >> W;
    vll A(N);
    rep(i, 0, N){
        cin >> A[i];
    }
    if(N == 1){
        prt(abs(W-A[0]));
        return 0;
    }
    ll l = A[N-1], l2 = A[N-2];
    ll z = Z, w = W;
    ll s = max(abs(l-w), abs(l2-l));
    prt(s);
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;




int main()
{
    ll A,B,C;
    cin >> A >> B >> C;
    ll ans = 1e18+100;
    if(A%2 == 0 || B%2==0|| C%2==0) ans = 0;

    ans = min({ans, A*B, B*C, C*A});
    cout << ans << endl;
    
    
    
    

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,Y;
  cin >> N >> Y;

  int x=-1,y=-1,z=-1;

  for(int i=0;i<=N;i++){
    for(int j=0;i+j<=N;j++){
      if(10000*i+5000*j+1000*(N-i-j)==Y){
        x=i;
        y=j;
        z=N-i-j;
        break;
      }
    }
  }
  cout << x << " " << y << " " << z << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<limits>
#include<boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
using namespace std;
#define BEGIN ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define END return EXIT_SUCCESS
#define up(I,A,B) for(auto I=(A);I<=(B);++I)
#define dw(I,A,B) for(auto I=(A);I>=(B);--I)
#define rep(I,N) up(I,0,N-1)
#define all(C) (C).begin(),(C).end()
#define rall(C) (C).rbegin(),(C).rend()
#define ft first
#define sd second
#define mp make_pair
#define mt make_tuple
#define pf push_front
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define rs resize
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>inline void                                      in(T &p){cin>>p;}
template<class T1,class T2>inline void                            in(T1 &p1,T2 &p2){cin>>p1>>p2;}
template<class T1,class T2,class T3>inline void                   in(T1 &p1,T2 &p2,T3 &p3){cin>>p1>>p2>>p3;}
template<class T1,class T2,class T3,class T4>inline void          in(T1 &p1,T2 &p2,T3 &p3,T4 &p4){cin>>p1>>p2>>p3>>p4;}
template<class T1,class T2,class T3,class T4,class T5>inline void in(T1 &p1,T2 &p2,T3 &p3,T4 &p4,T5 &p5){cin>>p1>>p2>>p3>>p4>>p5;}
template<class T>inline void                                      ins(T &p){for_each(all(p),in<decltype(p[0])>);}
template<class T>inline void                             out(T p){cout<<p<<"\n";}
template<class T1,class T2>inline void                   out(T1 p1,T2 p2){cout<<p1<<" "<<p2<<"\n";}
template<class T1,class T2,class T3>inline void          out(T1 p1,T2 p2,T3 p3){cout<<p1<<" "<<p2<<" "<<p3<<"\n";}
template<class T1,class T2,class T3,class T4>inline void out(T1 p1,T2 p2,T3 p3,T4 p4){cout<<p1<<" "<<p2<<" "<<p3<<" "<<p4<<"\n";}
inline void                                              out(ld p){printf("%.12Lf\n",p);}
template<class T>inline void outml(T p){for_each(all(p),out<decltype(p[0])>);}//ml=multi line
template<class T>inline void outol(T V){auto n=V.size();rep(i,n)cout<<V[i]<<" \n"[i==n-1];}//ol=one line
string s,t;
inline void solve(void){
  in(s,t);
  out(s==t.substr(0,s.size())&&s.size()+1==t.size()?"Yes":"No");
}
int main(void){
  BEGIN;
  solve();
  END;
}


Measured memory_bytes: 3640
#include<stdio.h>
int A[44];
int fib(int n){
    if(n==0 || n==1) return A[n]=1;
    if(A[n]!=-1) return A[n];
    return A[n]=fib(n-1)+fib(n-2);
}
int main(){
    int i,a;
    for(i=0;i<=44;i++) A[i]=-1;
    scanf("%d",&a);
    printf("%d\n",fib(a));
    return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

class comb{
	vector<ll> f,fr;
	ll MOD;
	public:
	//a^(p-1) = 1 (mod p)(p->Prime numbers)
	//a^(p-2) = a^(-1)
	ll calc(ll a,ll b,ll p){//a^(b) mod p   
		if(b==0)return 1;
		ll y = calc(a,b/2,p);y=(y*y)%p;
		if(b & 1) y = (y * a) % p;
		return y;
	}
	void init(ll n,ll mod){//input max_n
		MOD = mod;
		f.resize(n+1);
		fr.resize(n+1);
		f[0]=fr[0]=1;
		for(ll i=1;i<n+1;i++){
			f[i] = (f[i-1] * i) % mod;
			fr[i] = calc(f[i],mod-2,mod);
		}
	}
	ll nCr(ll n,ll r){
		if(r>n)return 0;
		return f[n] * fr[r] % MOD * fr[n-r] % MOD;
	}
};

int main(){
		ios::sync_with_stdio(false);
		cin.tie(0);
		ll n;
		cin>>n;
		vector<ll> a(n+1),index(n+1,-1);
		comb co;
		co.init(n+1,MOD);
		ll x,y;
		FOR(i,0,n+1){
			cin>>a[i];
			if(index[a[i]]!=-1){
				x = index[a[i]];
				y = i;
			}
			index[a[i]] = i;
		}
		y = n - y;
		x += y; 
		FOR(i,1,n+2){
			ll ans=0;
			ans = co.nCr(n+1,i);
			ans -= co.nCr(x,i-1);
			while(ans<0)ans+=MOD;
			cout << ans <<endl;
		}
}


Measured memory_bytes: 4352
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def SelectionSort(aa,n):
    for i in range(n):
        min_j=i
        for j in range(i+1,n):
            if int(aa[j][1])<int(aa[min_j][1]):min_j=j
        if min_j!=i:
            aa[i],aa[min_j]=aa[min_j],aa[i]
    return aa

def BubbleSort(aa,n):
    for i in range(n):
        for j in range(i,0,-1):
            if int(aa[j-1][1])<=int(aa[j][1]):break
            aa[j-1],aa[j]=aa[j],aa[j-1]
    return aa

def main():
    n = int(input())
    #aa = list(map(int, input().split()))
    aa=input().split()
    atoi={}
    for i,a in enumerate(aa):
        atoi[a]=i

    sorted_aa=BubbleSort(aa[:],n)
    stable=True
    for a0,a1 in zip(sorted_aa,sorted_aa[1:]):
        if a0[1]==a1[1] and atoi[a0]>atoi[a1]:
            stable=False
    print(*sorted_aa)
    print("Stable") if stable else print("Not stable")

    sorted_aa=SelectionSort(aa[:],n)
    stable=True
    for a0,a1 in zip(sorted_aa,sorted_aa[1:]):
        if a0[1]==a1[1] and atoi[a0]>atoi[a1]:
            stable=False
    print(*sorted_aa)
    print("Stable") if stable else print("Not stable")

main()



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



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

for(int i=0;i<N;i++)
{answer[A[i]-1]=i+1;}

for(int i=0;i<N-1;i++)
{cout<<answer[i]<<" ";}
cout<<answer[N-1]<<endl;
}


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

typedef long long ll;
const int M = 1e9 + 7;
const int N = 2e5 + 10;
const int MAX = 1e9 + 1;
//int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};

int n;
ll mp[400][400];
ll mp2[400][400];

bool s() {
    int i, j, k;
    for (i = 1; i <= n; ++i) {
        for (j = 1; j <= n; ++j) {
            if (j == i)
                continue;
            for (k = j + 1; k <= n; ++k) {
                if (k == i)
                    continue;
                ll t = mp[j][i] + mp[i][k];
                if (t < mp[j][k])
                    return 0;
                if (mp2[j][k] == 0)
                    mp2[j][k] = t;
                else
                    mp2[j][k] = min(mp2[j][k], t);
            }
        }
    }
    return 1;
}

int main() {
    int i, j;
    cin >> n;
    for (i = 1; i <= n; ++i) {
        for (j = 1; j <=n; ++j) {
            cin >> mp[i][j];
        }
    }
    if (!s()) {
        cout << -1 << endl;
        return 0;
    }
    ll sum = 0;
    for (i = 1; i <= n; ++i) {
        for (j = i + 1; j <= n; ++j) {
            if (mp2[i][j] < mp[i][j]) {
                sum += mp[i][j];
                sum += mp2[i][j];
            }
            else if (mp2[i][j] > mp[i][j]) {
                sum += mp[i][j];
            }
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.rbegin(),t.rend());
  //cout<<s<<" "<<t<<endl;
  cout<<(s<t?"Yes":"No")<<endl;
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
const long long MOD = 1e9+7;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ll> pdl;
typedef pair<ld, ld> pdd;
//typedef boost::multiprecision::cpp_int bigint;

ll A, B, Q;
vector<ll> S, T;

ll solve(ll X) {
	//Sの中で挟めるやつ
	//S[e] > X >= S[s]
	ll ss = 0, se = A + 1;
	while (se - ss > 1) {
		ll m = (se + ss) / 2;
		if (X >= S[m])ss = m;
		else se = m;
	}
	ll ans = LLONG_MAX;
	//S[ss]に行った後どこに行くか考える
	ll ts = 0, te = B + 1;
	while (te - ts > 1) {
		ll m = (te + ts) / 2;
		if (T[m] > S[ss])te = m;
		else ts = m;
	}
	ans = min(ans, (X - S[ss]) + min(T[te] - S[ss], S[ss] - T[ts]));
	//S[se]に行った後どこに行くか考える
	ts = 0, te = B + 1;
	while (te - ts > 1) {
		ll m = (te + ts) / 2;
		if (T[m] > S[se])te = m;
		else ts = m;
	}
	ans = min(ans, (S[se]-X) + min(T[te] - S[se], S[se] - T[ts]));
	//Tの中で挟めるやつ
	//T[e] > X >= T[s]
	ts = 0, te = B + 1;
	while (te - ts > 1) {
		ll m = (te + ts) / 2;
		if (X >= T[m])ts = m;
		else te = m;
	}
	//S[ss]に行った後どこに行くか考える
	ss = 0, se = A + 1;
	while (se - ss > 1) {
		ll m = (se + ss) / 2;
		if (S[m] > T[ts])se = m;
		else ss = m;
	}
	ans = min(ans, (X - T[ts]) + min(S[se] - T[ts], T[ts] - S[ss]));
	//S[se]に行った後どこに行くか考える
	ss = 0, se = A + 1;
	while (se - ss > 1) {
		ll m = (se + ss) / 2;
		if (S[m] > T[te])se = m;
		else ss = m;
	}
	ans = min(ans, (T[te] - X) + min(S[se] - T[te], T[te] - S[ss]));
	return ans;
}

int main() {
	cin >> A >> B >> Q;
	S.resize(A + 2);
	T.resize(B + 2);
	S[0] = -1e10 - 1;
	for (ll n = 1; n <= A; n++)cin >> S[n];
	S[A + 1] = 2e10 + 1;
	T[0] = -1e10 - 1;
	for (ll b = 1; b <= B; b++)cin >> T[b];
	T[B + 1] = 2e10 + 1;
	sort(S.begin(), S.end(), [](ll a, ll b) {
		return a < b;
	});
	sort(T.begin(), T.end(), [](ll a, ll b) {
		return a < b;
	});
	for (ll q = 0; q < Q; q++) {
		ll X;
		cin >> X;
		cout << solve(X) << endl;
	}
	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
#include <stack>

using namespace std;

int main()
{
	int D, N; cin >> D >> N;
	int ans = 0;

	if (D == 0) ans = N;
	if (D == 1) ans = 100 * N;
	if (D == 2) ans = 10000 * N;

	//Nは100までなので、100のときは101をかけてあげる（99までは答えは上記）
	if (N == 100) {
		if (D == 0) ans = N+1;
		if (D == 1) ans = 100*(N+1);
		if (D == 2) ans = 10000*(N+1);
	}	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int A = 0;
  int C = 1;
  int G = 2;
  long MOD = 1e9 + 7;
  long dp[101][5][5][5] = {};
  dp[0][4][4][4] = 1;
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < 5; j++)
    {
      for (int k = 0; k < 5; k++)
      {
        for (int l = 0; l < 5; l++)
        {
          for (int m = 0; m < 4; m++)
          {
            if (k == A && l == G && m == C)
              continue;
            if (k == A && l == C && m == G)
              continue;
            if (k == G && l == A && m == C)
              continue;
            if (j == A && l == G && m == C)
              continue;
            if (j == A && k == G && m == C)
              continue;
            dp[i + 1][k][l][m] += dp[i][j][k][l];
            dp[i + 1][k][l][m] %= MOD;
          }
        }
      }
    }
  }
  long ans = 0;
  for (int j = 0; j < 4; j++)
  {
    for (int k = 0; k < 4; k++)
    {
      for (int l = 0; l < 4; l++)
      {
        ans += dp[N][j][k][l];
        ans %= MOD;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 384
/*Author: Gautam*/
 
 
#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
#define MOD 1000000007
#define ull unsigned long long int
#define newline cout<<endl
 
 
/* TYPE DEFINITIONS */
typedef     long long int        ll;
typedef     vector<ll>     vi;
typedef     pair<ll,ll>   pi;
 
 
 
/* MATH */
bool isPrime(ull n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ull i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 
ll pow(ll a,ll b,ll m)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)res=(res*a)%m;
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}
 
  
//
/* MACROS */
 
#define  all(A)         (A).begin() , (A).end()
#define  arrall(A,n)    (A),((A)+(n))
#define  rall(A)        (A).rbegin() , (A).rend()
#define  sz(A)          (int)(A).size()
#define  pb             push_back
#define  ppb            pop_back
#define  mp             make_pair
#define  ln(X)          (int)(X).length()
#define  square(X)      ((X)*(X))
#define  cube(X)        ((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)    for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) 

void solve()
{
    int n;
    cin>>n;
    int arr[2*n];
    forn(i,2*n)cin>>arr[i];
    sort(arr,arr+2*n);
    ll ans=0;
    for(int i=0;i<2*n;i+=2)
    {
        ans+=arr[i];
    }
    cout<<ans<<endl;
}
 
int main()
{
    FastIO;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << std::setprecision(10);

  ll x, y; std::cin >> x >> y;
  int ans = 0;
  while (x <= y) {
    x *= 2;
    ans++;
  }
  std::cout << ans << "\n";
}


Measured memory_bytes: 384
import java.util.*

fun calcY(i: Int, j: Int, w: Int) = if (i % 2 == 0) {
    j
} else {
    w - j - 1
}

fun main(args: Array<String>) {
    var n = 0
    val y = mutableListOf<Int>()
    val x = mutableListOf<Int>()
    val yp = mutableListOf<Int>()
    val xp = mutableListOf<Int>()

    Scanner(System.`in`).use {
        val h = it.nextInt()
        val w = it.nextInt()
        val a = mutableListOf<MutableList<Int>>()

        for (i in 0 until h) {
            val ai = mutableListOf<Int>()

            for (j in 0 until w) {
                ai.add(it.nextInt())
            }

            a.add(ai)
        }

        for (i in 0 until h) {
            for (j in 0 until w) {
                val k = calcY(i, j, w)
                if (a[i][k] % 2 != 0) {
                    val kp = calcY(i, j + 1, w)
                    if ((-1 < kp && kp < w) || i + 1 < h) {
                        n++
                        a[i][k]--
                        y.add(i + 1)
                        x.add(k + 1)
                        if (-1 < kp && kp < w) {
                            a[i][kp]++
                            yp.add(i + 1)
                            xp.add(kp + 1)
                        } else {
                            a[i + 1][k]++
                            yp.add(i + 2)
                            xp.add(k + 1)
                        }
                    }
                }
            }
        }
    }

    println(n)

    for (i in 0 until n) {
        println(listOf(y[i], x[i], yp[i], xp[i]).joinToString(" "))
    }
}


Measured memory_bytes: 134880
#include <bits/stdc++.h>
using namespace std;
#define rep for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;
bool compare(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){
    return a.second < b.second;
}
int main(){
    int n;cin >> n;
    int a[n]; rep{
        cin >> a[i];
    }
    sort(a,a+n);
    cout << a[n/2]-a[n/2-1] << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MM = 1000000000;
#define mod = MM + 7;
#define INF (ll)1e18
#define pi acos(-1.0)
#define MAX 100005
#define NIL -1
int main(){
    int s; cin >> s;
    map<ll, int> mp;
    mp[s]++;
    ll ans = 0;
    for(int i = 2; i < 1000000; i++){
        if(s%2 == 0){
            s /= 2;
        } else {
            s = 3*s + 1;
        }
        mp[s]++;
        if(mp[s] == 2){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

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

const int M = (int) 1e9 + 7;
const int N = (int) 	1e6 + 10;
int s[N], ns[N], fact[N], inv[N], a[N];

int mult(int a, int b) {
	return a * (long long) b % M;
}

int sum(int a, int b) {
	return (a + b) % M;
}

int sub(int a, int b) {
	return (a - b + M) % M;
}

int pow(int a, int b) {
	if (b == 0) return 1;
	if (b & 1) return mult(pow(a, b - 1), a);
	return pow(mult(a, a), b / 2);
}

int get_ns(int l, int r) {
	return sub(ns[r], ns[l]);
}

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &a[i]);
		s[i + 1] = sum(s[i], a[i]);
	}
	for (int i = 0; i <= n; ++i) {
		ns[i + 1] = sum(ns[i], s[i]);
	}
	fact[0] = 1;
	for (int i = 0; i <= n; ++i) {
		fact[i + 1] = mult(fact[i], i + 1);
		inv[i + 1] = pow(i + 1, M - 2);
	}
	int ans = 0;
	for (int l = 1; l <= n; ++l) {
		if (l <= n - 2) {
			int coef = mult(mult(mult(fact[n], 2), inv[l + 1]), inv[l + 2]);
			int all = sub(get_ns(l + 1, n), get_ns(1, n - l));
			ans = sum(ans, mult(coef, all));
		}
		
		if (l <= n - 1) {
			int coef = mult(fact[n], inv[l + 1]);
			int all = sum(s[l], sub(s[n], s[n - l]));
			ans = sum(ans, mult(coef, all));
		}

		if (l == n) {
			int coef = fact[n];
			int all = s[n];
			ans = sum(ans, mult(coef, all));
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 12928
N, M = (int(i) for i in input().split())

LR = [list(map(int, input().split())) for _ in range(M)]
L = [i[0] for i in LR]
R = [i[1] for i in LR]

# print(L)
# print(R)
result =  min(R) - max(L) + 1
if (result < 0):
    result = 0
print(result)

Measured memory_bytes: 29076
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;

ll binary_search(function<bool(ll)> func, ll start, ll end) {
    /*      func:int ->bool
            returns smallest int x where func(x) evaluates to true, searches in [start,end), it is assumed the values are false, .. , false, true ...
             */
    if (end <= start) {   return end;  }   // has to be here, otherwise func(end-1) in next line could be a problem
    if (!func(end-1)) {  return end;  }
    while (end-start>1) {
        ll mid = (start+end)/2;
        if (func(mid)) {  end = mid;  } else { start = mid;   }
    }
    if (func(start)) {  return start;  } else {  return end;   }
}; 


int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
 
//    auto start = chrono::steady_clock::now();
  
//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(h); readint(n);
        vector<ll> a, b;
        forr(i,0,n) {
            readint(aa); readint(bb);
            a.push_back(aa); b.push_back(bb);
        }

        vector<ll> min_cost(h+1);   // minmoves[i,j] = only spells < i used, health of monster j at beginning
        min_cost[0] = 0;
        forr(he,1,h) {
            min_cost[he] = 1000000000000000LL;
            forr(i,1,n) {
                if (a[i-1]>=he) {  min_cost[he] = min(min_cost[he], b[i-1]);  }
                  else {
                      min_cost[he] = min(min_cost[he], b[i-1] + min_cost[he-a[i-1]]);
                  }
            }
        }

        cout << min_cost[h] << endl;

    }
 
//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
 
    return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

#define dicemin 1
#define dicemax 6
#define eps 10e-9
#define max 105

int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	while(1){
		int N, T, L, B;
		bool lose[max];
		bool back[max];
		double prob[max][max];
		double loseprob[max][max];
		cin >> N >> T >> L >> B;
		if( N == 0 && T == 0 && L == 0 && B == 0 ) break;
		for(int i = 0; i < max; i++) {
			lose[i] = false;
			back[i] = false;
			for(int j = 0; j < max; j++) {
				prob[j][i] = 0.0;
				loseprob[j][i] = 0.0;
			}
		}
		prob[0][0] = 1.0;

		for(int i = 0; i < L; i++){
			int tmp;
			cin >> tmp;
			lose[tmp] = true;
		}
		for(int i = 0; i < B; i++){
			int tmp;
			cin >> tmp;
			back[tmp] = true;
		}

		//シュミレート
		for(int i = 0; i < T; i++) {
			for(int j = 0; j < N; j++) {
				for(int k = dicemin; k <= dicemax; k++) {
					int next = j + k;
					if( next > N ) next = N - ( next - N );
					if( back[next] ) {
						prob[i + 1][0] += (double)( 1.0 * prob[i][j] ) / 6.0;
					} else if( lose[next] ) {
						loseprob[ i + 1 ] [next] += (double)( 1.0 * prob[i][j] ) / 6.0;
						prob[i + 2][next] += (double)( 1.0 * prob[i][j] ) / 6.0;
					} else {
						prob[i + 1][next] += (double)( 1.0 * prob[i][j] ) / 6.0;
					}
				}
			}
		}
/*		
		for(int i = 0; i < max; i++)
			for(int j = 0; j < max; j++)
				prob[i][j] += loseprob[i][j];

		/*
		for(int i = 0; i <= T; i++) {
			for(int j = 0; j <= N; j++) {
				printf("%lf\n", prob[i][j]);
			}
			cout << "***" << endl;

		}
		*/
		double ans = 0.0;
		for(int i = 0; i <= T; i++)
			ans += prob[i][N];
		
		printf("%lf\n", ans);
		
	}

	//while(1){}
	return 0;
}

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

int main()
{
  int n, k;
  cin >> n >> k;
  string s;
  cin >> s;

  s[k - 1] = s[k - 1] + ('a' - 'A');

  cout << s << endl;

  return 0;
}


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

using ll = long long;

const int INF = 1001001001;
const ll INF_LL = 1001001001001001001LL;

int main(void){
  int n; cin >> n;
  string s = to_string(n);

  int sn=0;
  rep(i,s.size()){
    int tmp = s[i]-'0';
    sn+=tmp;
  }

  if(n%sn==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h> 
#define ll long long int
#define DEBUG(x) cerr<<"> "<< #x << ':' <<x<<endl;
using namespace std;
ll INF = 1e15;
ll MOD = 1e9 + 7;
vector <ll> a;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    bool t = false;
    for(int i=0;i<n;i++)
    {
        ll input;
        cin>>input;
        a.push_back(input);
        if(input == 0)
        {
            t = true;
        }
    }
    if(t)
    {
        cout<<"0\n";
        return 0;
    } 
    ll ans = 1;
    ll old_ans = 1;
    for(int i=0;i<n;i++)
    {
        ans = (ans*a[i]);
        if(ans > ((ll)1e18))
        {
            cout<<"-1\n";
            return 0;
        }
        if(ans < old_ans )
        {
            cout<<"-1\n";
            return 0;
        }
        old_ans = ans;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 4272
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

struct Edge {
  // Edge(ll i, ll e) : id(i), end(e) {}

  ll end;
  ll id;
};

vector< vector<Edge> > graph;
vector<ll> ans; // The ans of each edge. (edge id) => (color). default is -1.
ll degree; // Maximum degree of graph. This is color.

// Calculate the color of each edge
void dfs(ll v, ll parent, ll parent_edge) {
  ll color = 0; // We use color
  for (auto e : graph[v]) {
    if (e.end == parent) { continue; } // Skip parent
    // We paint color of each edge. We can select anything other than parent edge one.

    if (parent_edge == -1) { // root
      ans[e.id] = color;
      ++color;
    } else {
      if (color == ans[parent_edge]) { ++color; } // skip parent edge's color.
      ans[e.id] = color;
      ++color;
    }

    dfs(e.end, v, e.id);
  }
}

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  graph.resize(n);
  ans.assign(n-1, -1); // -1 is initial value.

  rep(i, n-1) {
    ll a; ll b;
    cin >> a >> b;
    --a; --b;
    graph[a].push_back({b, i});
    graph[b].push_back({a, i});
  }
  // cout << "graph: ";

  // First, we want to know the maximum degree
  rep(i, n) {
    chmax(degree, (ll)graph[i].size());
  }
  // cout << "degree: " << degree << endl;

  // Set ans by dfs
  dfs(0, -1, -1);

  cout << degree << endl;
  rep(i, ans.size()) {
    cout << ans[i] + 1 << endl;
  }
}


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

// Shrotening
#define fst first
#define snd second
#define pb push_back
#define mp std::make_pair

// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto 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;

int N;
VI A;
int main(){
    std::cin >> N;
    A.resize(N);
    REP(i, N) {
        std::cin >> A[i];
    }
    SORT(A);
 
    LL max1, max2;
    int idx;
    max1 = max2 = 0;
    idx = -1;
    RFOR(i, N-1, 1) {
        if(A[i] == A[i-1]){
            max1 = A[i];
            idx = i-2;
            break;
        }
    }
    RFOR(i, idx, 1) {
        if(A[i] == A[i-1]){
            max2 = A[i];
            break;
        }
    }
    std::cout << max1*max2 << std::endl;
    return 0;
}

Measured memory_bytes: 640
from collections import deque
import sys
input = sys.stdin.readline


def bellman_ford(N, adj, start):
    ans = [float("inf")] * N
    q = deque()
    q.append((start, 0, 0))
    while len(q):
        i, cost, path = q.pop()
        if cost >= ans[i]:
            continue
        ans[i] = cost
        for j in adj[i]:
            ncost = cost + adj[i][j]
            if path > N:
                ncost = -float("inf")
            q.append((j, ncost, path+1))
    return ans


def main():
    N, M, P = map(int, input().split())
    adj = [{} for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        if B-1 in adj[A-1]:
            adj[A-1][B-1] = min(P-C, adj[A-1][B-1])
        else:
            adj[A-1][B-1] = P-C
    costs = bellman_ford(N, adj, 0)
    ans = -costs[N-1]
    if ans < 0:
        print(0)
    elif ans == float("inf"):
        print(-1)
    else:
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 49500
import math
import sys
import os

sys.setrecursionlimit(10**7)

def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))

if os.getenv("LOCAL"):
    inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
    sys.stdin = open(inputFile, "r")
INF = float("inf")

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N,M = LI()
AB = [LI() for _ in range(M)]
ans = 0

road = UnionFind(N)
for r in AB:
    f = r[0]-1
    t = r[1]-1
    road.union(f,t)

# group数 - 1
ans = road.group_count() - 1

print(ans)

Measured memory_bytes: 29428
from math import ceil

def solve(n, CSF):
    times = [0] * n
    for i, (c, s, f) in enumerate(CSF):
        for j in range(i + 1):
            if times[j] <= s:
                times[j] = s
            else:
                times[j] = s + ceil((times[j] - s) / f) * f
            times[j] += c
    return times

_n = int(input())
_CSF = [map(int, input().split()) for _ in range(_n - 1)]
print(*solve(_n, _CSF), sep='\n')


Measured memory_bytes: 3316
//#pragma comment(linker, "/STACK:102400000,102400000") 
#pragma warning(disable:4996)
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define eps 1e-10
#define LL_INF 0x33ffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back

const int maxn = 1e5 + 5;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }

int h, w;
int ex, ey;
char val[101][101];
int col[101][101], row[101][101];
int dp[101][101][101][101];

int co(int x, int y, int c)
{
	return col[y][c] - col[x - 1][c];
}

int ro(int x, int y, int r)
{
	return row[r][y] - row[r][x - 1];
}

void solve()
{
	scanf("%d%d", &h, &w);
	for (int i = 1; i <= h; i++)
	{
		scanf("%s", val[i] + 1);
		for (int j = 1; j <= w; j++)
		{
			if (val[i][j] == 'E')
			{
				ex = i;
				ey = j;
			}
		}
	}

	for (int i = 1; i <= h; i++)
	{
		for (int j = 1; j <= w; j++)
		{
			row[i][j] = row[i][j - 1] + (val[i][j] == 'o');
		}
	}
	for (int j = 1; j <= w; j++)
	{
		for (int i = 1; i <= h; i++)
		{
			col[i][j] = col[i - 1][j] + (val[i][j] == 'o');
		}
	}
	int leb = ey, rib = w - ey + 1;
	int upb = ex, dob = h - ex + 1;
	int res = 0;
	for (int le = 0; le < leb; le++)
	{
		for (int ri = 0; ri < rib; ri++)
		{
			for (int u = 0; u < upb; u++)
			{
				for (int d = 0; d < dob; d++)
				{
					res = max(res, dp[le][ri][u][d]);
					if (ri < ey - le - 1)
					{//left
						int x = max(d + 1, ex - u);
						int y = min(ex + d, h - u);
						dp[le + 1][ri][u][d] = max(dp[le + 1][ri][u][d], dp[le][ri][u][d] + co(x, y, ey - le - 1));
					}
					if (w - le>ey + ri)
					{//right
						int x = max(d + 1, ex - u);
						int y = min(ex + d, h - u);
						dp[le][ri + 1][u][d] = max(dp[le][ri + 1][u][d], dp[le][ri][u][d] + co(x, y, ey + ri + 1));
					}
					if (d < ex - u - 1)
					{//up
						int x = max(ri + 1, ey - le);
						int y = min(ey + ri, w - le);
						dp[le][ri][u + 1][d] = max(dp[le][ri][u + 1][d], dp[le][ri][u][d] + ro(x, y, ex - u - 1));

					}
					if (h - u>ex + d)
					{//down
						int x = max(ri + 1, ey - le);
						int y = min(ey + ri, w - le);
						dp[le][ri][u][d + 1] = max(dp[le][ri][u][d + 1], dp[le][ri][u][d] + ro(x, y, ex + d + 1));
					}
				}
			}
		}
	}
	printf("%d\n", res);
	//printf("%d\n", dp[leb - 1][rib - 1][upb - 1][dob - 1]);
}

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




Measured memory_bytes: 93184
#include<stdio.h>

int main(void){
    int a,b;
    
    scanf("%d%d",&a,&b);
    
    if(a<b){
        printf("a < b\n");
    }
    if(a>b){
        printf("a > b\n");
    }
    if(a==b) {
        printf("a == b\n");
    }
    
    return 0;
}


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

using namespace std;

#define int long long
#define  IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int INF = 1e9;

signed main() {
    int x;
    cin>>x;
    int sum=0;
    while(x>0) {
        int _500yen=x/500;
        int _5yen=x/5;
        if(_500yen) {
            sum+=_500yen*1000;
            x-=500*_500yen;
        } else if(_5yen) {
            sum+=_5yen*5;
            x-=5*_5yen;
        } else {
            break;
        }
    }
    cout<<sum<<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    int n, i, a[100003], amin, amax;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }

    amin = INF;
    amax = 0;
    for (i = 0; i < n; i++) {
        amin = min(amin, a[i]);
        amax = max(amax, a[i]);
    }

    if (amax - amin >= 2) {
        printf("No\n");
        return 0;
    }

    if (amax == amin) {
        if (amin == n - 1 || amin <= n / 2) {
            printf("Yes\n");
        }
        else {
            printf("No\n");
        }
        return 0;
    }

    int b, s, t;
    b = amin;
    s = t = 0;
    for (i = 0; i < n; i++) {
        if (a[i] == b) s++;
        else t++;
    }

    if (b + 1 > s && t >= (b + 1 - s) * 2) {
        printf("Yes\n");
    }
    else {
        printf("No\n");
    }

    return 0;
}

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

int main(){
	
	string mozi;
	
	getline(cin,mozi);
	
	for(int i=0;i<(int)mozi.size();i++){
		
	if(islower(mozi[i])){
		mozi[i] = toupper(mozi[i]);
	}	
	else if(isupper(mozi[i])){
		mozi[i] = tolower(mozi[i]);
	}
	}
	cout<< mozi<<endl;
	
	return 0;
}


Measured memory_bytes: 3120
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    void solve() throws IOException {
        int H = ni();
        int W = ni();

        char[][] C = new char[H][W];
        for (int i = 0; i < H; i++) C[i] = ns().toCharArray();

        int ans = 0;
        for (int i = 0; i < W - 1; i++) {
            int[][] cost = new int[H + 1][H + 1];
            for (int j = H - 1; j >= 0; j--) {
                for (int k = H - 1; k >= 0; k--) {
                    cost[j][k] = cost[j + 1][k + 1] + (C[H - 1 - j][i] == C[H - 1 - k][i + 1] ? 1 : 0);
                }
            }

            int[][] dp = new int[H + 1][H + 1];
            for (int j = 0; j <= H; j++) {
                for (int k = 0; k <= H; k++) {
                    if (j > 0 && k > 0) {
                        dp[j][k] = Math.min(dp[j - 1][k] + cost[j - 1][k], dp[j][k - 1] + cost[j][k - 1]);
                    } else if (j > 0) {
                        dp[j][k] = dp[j - 1][k] + cost[j - 1][k];
                    } else if (k > 0) {
                        dp[j][k] = dp[j][k - 1] + cost[j][k - 1];
                    }
                }
            }

            ans += dp[H][H];
        }

        out.println(ans);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 73996
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt(), c = sc.nextInt();
        int[] A = new int[m];
        int[] B = new int[m];
        int res = 0;
        Arrays.setAll(B, i -> Integer.parseInt(sc.next()));
        for(int i = 0; i < n; i++) {
            int sum = c;
            for(int b : B) {
                sum += b * Integer.parseInt(sc.next());
            }
            if(sum > 0) res++;
        }
        System.out.println(res);
    }
}

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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;

#define MAX_N 100001

signed main() {
	string s;
	getline(cin, s); 
	for (auto a : s) {
		if ('a' <= a && a <= 'z') {
			a = a + 'A' - 'a';
		}
		else if ('A' <= a && a <= 'Z') {
			a = a - 'A' + 'a';
		}
		cout << a;
	}
	cout << endl;
}


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

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

    int MAX=0;
    int flagf=false;
    for(int i=0;i<N-1;i++){
        if(MAX<i) break;
        MAX=max(MAX,d[i]/10+i);
        if(MAX>=N-1){
            flagf=true;
            break;
        }
    }
    int MIN=N-1;
    int flagr=false;
    for(int i=N-1;i>0;i--){
        if(MIN>i) break;
        MIN=min(MIN,i-d[i]/10);
        if(MIN<=0){
            flagr=true;
            break;
        }
    }

    if(flagf&flagr) cout<<"yes"<<endl;
    else cout<<"no"<<endl;

    return 0;
}


Measured memory_bytes: 4284