akhauriyash/Code-Regression huggingface dataset:
/****************************************************************
# @Author:      iLovePKU_zbtxdy
# @DateTime:    2020-03-22 20:05:57
# @Description: Think twice . Code once. 
# @More: Once lots of AC, try Brute-force,dynamic programming 
****************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define close std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define eps 1e-8
typedef long long ll;
const int maxn = 1e6;
const int INF = 1e9;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
ll mod = 1e9+7;
int main()
{
    int m , n;
    cin >> n>> m;
    cout << (n*(n-1)+(m-1)*m)/2;
}
/***************************************************************************
 *stuff you should look for
 *int overflow, array bounds
 *special cases (n=1?), set tle
 *do smth instead of nothing and stay organized
***************************************************************************/


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define OUT(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int a, b, c;
    cin >> a >> b >> c;
    ATYN(a+b >= c)

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, m, i, j, k, ans, ss, MOD = 1000000007LL;
	cin >> n >> m;
	vector<long long> s(n + 1), t(m + 1);
	for (i = 1; i <= n; i++) cin >> s[i];
	for (i = 1; i <= m; i++) cin >> t[i];

	vector<vector<long long >> dp(n + 1, vector<long long>(m + 1, 0));
	vector<vector<long long >> sum(n + 1, vector<long long>(m + 1, 0));
	ans = 1;
	sum[0].assign(m + 1, 1);
	for (i = 1; i <= n; i++) sum[i][0] = 1;
	for (i = 1; i <= n; i++) {
		ss = 0;
		for (j = 1; j <= m; j++) {
			if (s[i] == t[j]) {
				dp[i][j] = sum[i - 1][j - 1];
				ans = (ans + sum[i - 1][j - 1]) % MOD;
			}
			ss += dp[i][j];
			sum[i][j] = (sum[i - 1][j] + ss) % MOD;
		}
	}

	cout << ans % MOD << "\n";

	return 0;
}


Measured memory_bytes: 62976
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;
int o[4];
int main()
{
    std::ios::sync_with_stdio(false);
    int n,m,k,x;
    while(cin>>n>>m)
    {
        int flag=1;
        o[1]=-1;o[2]=-1;o[3]=-1;
        while(m--)
        {
            cin>>k>>x;
            if(o[k]==-1||o[k]==x)
                o[k]=x;
            else
                flag=0;
        }
        if(flag&&(o[1]!=0||(n==1&&o[1]==0)))
        {
            if(n!=1&&o[1]==-1)
                o[1]=1;
            for(int i=1;i<=n;i++)
                if(o[i]==-1)
                    o[i]=0;
            for(int i=1;i<=n;i++)
                cout<<o[i];
            cout<<endl;
        }
        else
            cout<<-1<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include<unordered_map>
using namespace std;
const long long int mod1=1000000007;
const long long int mod2 = -1;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define pp pop_back                                       
#define ff first
#define ss second
#define ll long long int
#define ull unsigned long long int
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define ordered1 tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define inf mod1
#define all(x) x.begin(),x.end()
ll gcd(ll a, ll b){
    ll c;
     while(b){
        c = b;
        b = a % b;
        a = c;
     }
     return a;
}
ll power1(ll a, ll b){
     if(b == 0) return 1;
     else if(b % 2) return a * power1(a, b - 1);
     else {
        ll temp = power1(a, b / 2);
        return temp * temp;
     }
}
ll power2(ll a, ll b, ll m){
     a %= m;
     if(b == 0) return 1;
     else if(b % 2) return (a * power2(a, b - 1, m)) % m;
     else{
        ll temp = power2(a, b / 2, m);
        return (temp * temp) % m;
     }
}
ll mod(ll x, ll p){
return (x % p + p) % p;
}
ll lcm(ll x, ll y){
return (x * y)/gcd(x, y);
}
int main(){
    fast;
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        string s, t;
        cin >> s >> t;
        t.pop_back();
        if(s == t){
            cout << "Yes";
        }
        else{
            cout << "No";
        }
    }
}


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

int main(){
  int n;
  cin >> n;
  int a[n];
  int counter=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i]%2 == 1){
      a[i]=1;
      counter++;
    }
  }
  int kaisu=0;
  int j=0;
  while(1){
    if(counter == n) break;
    for(int i=j;i<n;i++){
      if(a[i]%2 == 0){
        a[i]=a[i]/2;
        if(a[i]%2 == 1) counter++;
        j=i;
        break;
      }
    }
    kaisu++;
  }
  cout << kaisu << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;typedef long long lint;typedef vector<lint> liv;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(),v.end()
#define linf 1152921504606846976
#define MAXN 100010
#define md 1000000007//998244353

int main(){
	lint n;cin>>n;
	liv b(n),ans;rep(i,n)cin>>b[i];
	rep(i,n){
		for(lint j=b.size()-1;j>=0;--j){
			if(j+1==b[j]){
				ans.push_back(j+1);
				b.erase(b.begin()+j);break;
			}
			else if(!j){
				cout<<"-1\n";return 0;
			}
		}
	}
	for(lint i=n-1;i>=0;--i){
		cout<<ans[i]<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int value[3][101];
int sum[3][101];
 
int main()   //main body
{
	int n;
	cin >> n;     //input member
	for (int i = 1; i <= n; i++) cin >> value[1][i];          //loop and input
	for (int i = 1; i <= n; i++) cin >> value[2][i];
	for (int i = 0; i <= 2; i++) sum[i][0] = 0;
	for (int i = 0; i <= n; i++) sum[0][i] = 0;
	for (int i = 1; i <= 2; i++)
		for (int j = 1; j <= n; j++)
			sum[i][j] = max(sum[i][j - 1], sum[i - 1][j]) + value[i][j];    //formula
	cout << sum[2][n] << endl;      //main output
}

Measured memory_bytes: 256
#include<cstdio>
#include<unordered_map>
#define re register
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,a[300002],b[300002],q,suma[300002],sumb[300002],mn[300002],p[513][100002];
inline int ask(re int x,re int y){
	if(x<=512)return p[x][y];
	if(y<mn[x])return 0;
	if(y>sumb[x])return suma[x];
	if(x==1)return (y>=b[x])*a[x];
	if(y>=b[x])return max(ask(x>>1,y),a[x]+ask(x>>1,y-b[x]));
	else return ask(x>>1,y);
}
signed main(){
	n=read();
	for(re int i=1;i<=n;++i)a[i]=read(),b[i]=read();mn[0]=1e9;
	for(re int i=1;i<=n;++i)suma[i]=suma[i>>1]+a[i],sumb[i]=sumb[i>>1]+b[i],mn[i]=min(b[i],mn[i>>1]);
	for(re int i=1;i<=min(n,512);++i)for(re int j=100000;j;--j)if(j>=b[i])p[i][j]=max(p[i>>1][j],p[i>>1][j-b[i]]+a[i]);else p[i][j]=p[i>>1][j];
	q=read();
	while(q--){
		re int x=read(),y=read();
		printf("%d\n",ask(x,y));
	}
}

Measured memory_bytes: 206768
#include <bits/stdc++.h>
using namespace std;
#define fori(i,n) for(int i =0;i<n;i++)
#define pb push_back
#define ll long long
#define int long long
#define F first
#define S second
#define mp make_pair
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout.precision(15);
 
 
int mod = 1e9+7;
 
int pow(int a, int b) {
    int ans = 1;
    a %= mod;
    while(b) {
        if(b%2) {
            ans *= a;
            ans %= mod;
        }
        b /= 2;
        a *= a;
        a %= mod;
    }
    return ans;
}

int inv(int a) {
    return pow(a,mod-2);
}

int mul (int a,int b) {
    return ((a%mod)*(b%mod))% mod;
}

struct cmp {
    bool operator() (pair<int,int> a, pair<int,int> b) const {
        int x = a.F;
        int y = b.F;
        return x>=y;
    }
};

int pr[10001];

void pre() {
    for(int x = 1; x<102;x++) {
        for(int y = 1; y<102;y++) {
            for(int z = 1; z<102;z++) {
                int an = (x*x) + (y*y) + (z*z) + x*(y+z) + y*z;
                if(an <= 10000) pr[an]++;
            }
        }
    }
}


int32_t main() {
    FAST;
    int t;
    // cin>>t;
    t = 1;
    pre();
    while(t--) {
        int n;
        cin>>n;
        fori(i,n) {
            cout<<pr[i+1]<<"\n";
        }

    }
    
    return 0;
}

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


	public class Main {
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			char[] s = sc.next().toCharArray();
			
			int[] num = new int[3];
			
			for(int i=0;i<s.length;i++) {
				if(s[i]=='a') {
					num[0]++;
				}else if(s[i]=='b') {
					num[1]++;
				}else {
					num[2]++;
				}
			}
			
			Arrays.sort(num);
			
			num[1] -= num[0];
			num[2] -= num[0];
			
			if((num[1]==0&&num[2]==0) || (num[1]==0&&num[2]==1) || (num[1]==1&&num[2]==1)) {
				System.out.println("YES");
			}else {
				System.out.println("NO");
			}
			
		}
		
		
	}


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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)

int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  int r; cin >> r;
  cout << 3 * r * r << endl;

  return 0;
}



Measured memory_bytes: 256
S2 = list(input())
T = list(input())
S = []
Temp = 0

for _ in range(len(S2)-len(T)+1):
    for j in range(len(T)):
        if T[j] == S2[Temp + j] or S2[Temp + j] == "?":
            if j == len(T) - 1:
                S.append([S2[x] for x in range(Temp)] + [T[x] for x in range(len(T))] + [S2[x] for x in range(Temp + len(T), len(S2))])
                Temp += 1
                break
            else:
                continue
        else:
            Temp += 1
            break

#print(S2)
#print(S)
for i in range(len(S)):
    for j in range(len(S2)):
        if S[i][j] == '?':
            S[i][j] = 'a'
    S[i] = ''.join(S[i])
if S != []:
    print(sorted(S)[0])
else: print('UNRESTORABLE')

Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int i,t[2]={0};
	char s[100];
	for(;scanf("%s",s),s[0]!='0';t[0]>t[1]?t[0]++:t[1]++,printf("%d %d\n",t[0],t[1]))
		for(i=1,t[0]=t[1]=0;s[i];i++)
			t[s[i]-'A']++;
	return 0;
}

Measured memory_bytes: 536
#include <stdio.h>
#include <stdlib.h>

int sums(int n, int a, int b);
int main(void);

int sums(int n, int a, int b){
    int i, i_tmp, j, sum_one;
    int sum_nums = 0;
    for(i=1; i<n+1; i++){
        i_tmp = i;
        sum_one = 0;
        while(1){
           sum_one += i_tmp%10;
           i_tmp /= 10;
           if(i_tmp == 0)
              break;
        }
        if(a<=sum_one && sum_one<=b)
           sum_nums += i;
    }

    return sum_nums;
}

int main(void){
    int n, a, b, sum;
    scanf("%d %d %d", &n, &a, &b);
    sum = sums(n, a, b);
    printf("%d\n", sum);

    return 0;
}


Measured memory_bytes: 128
import math
N, D = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
  for j in range(i + 1, N):
    diff = 0
    for k in range(D):
      diff += (li[i][k] - li[j][k]) ** 2
    if math.sqrt(diff).is_integer():
      ans += 1
print(ans)


Measured memory_bytes: 3316
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;

void main()
{
	auto weight = [1000, 1200, 1500, 200, 300, 500];
	auto tplace =  [380*5*0.8, 550*4*0.85, 850*3*0.88, 380, 550, 850];
	auto place = tplace.map!(to!int).array;

	int[10000] dp;
	dp[] = int.max;
	foreach (i; 0..6) {
		dp[weight[i]] = place[i];
	}

	foreach (i; iota(100, 5001, 100)) {
		if (dp[i] == int.max) continue;
		foreach (j; 0..6) {
			dp[i + weight[j]] = min(dp[i + weight[j]], dp[i] + place[j]);
		}
	}

	int n;
	while (n = readln.chomp.to!int, n) {
		dp[n].writeln;
	}
}

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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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; }

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; }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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; }

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll a,b,c,d; cin>>a>>b>>c>>d;
  ll l = lcm(c,d);
  ll ans=b-a+1-(b/c-(a-1)/c+b/d-(a-1)/d - (b/l-(a-1)/l));
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <functional>
#define rep(i, a, n) for(int i = a;i < n;i++)
using namespace std;


string s1, s2;


bool solve(){
	rep(i, 0, min(s1.size(), s2.size())){
		if(s1[i] < s2[i])
			return true;
		if(s1[i] > s2[i])
			return false;
	}
	if(s1.size() < s2.size()) return true;
	return false;
}


int main(){
	cin >> s1 >> s2;

	sort(s1.begin(), s1.end());
	sort(s2.begin(), s2.end(), greater<int>());

	if(solve()) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#define INFLL        1e18
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define DELNL        cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll=long long;
using ull=unsigned long long;
template<typename T>using pqg=priority_queue<T,vector<T>,greater<T>>;
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}

int main()
{
    vector<pair<double,string>>inp(in());
    REPC(&i,inp){
        double x;string u;cin>>x>>u;
        i=make_pair(x,u);
    }
    auto money=[](const pair<double,string>&p){return p.first*(p.second=="JPY"?1:380000);};
    SETP(20);
    cout<<accumulate(ALL(inp),.0,[money](double acc,const pair<double,string>&p){return acc+money(p);})<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<vector>
#define fst first
#define snd second

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;

int N;

bool wrap(pii a, pii b) {
    return a.fst <= b.fst && b.snd <= a.snd;
}

int f(vector<pii> &segs) {
    int max_fst = 0, min_snd = 1e9, max_len = 0;
    int fst_p, snd_p;
    for (int i = 0; i < segs.size(); i++) {
        if (max_fst < segs[i].fst) {
            max_fst = segs[i].fst;
            fst_p = i;
        }
        if (min_snd > segs[i].snd) {
            min_snd = segs[i].snd;
            snd_p = i;
        }
        max_len = max(max_len, segs[i].snd - segs[i].fst + 1);
    }

    int same_v = max_len + max(0, min_snd - max_fst + 1);
    if (fst_p == snd_p) return same_v;

    vector<pii> incomplete;
    for (auto &seg: segs) {
        if (!wrap(seg, segs[fst_p]) && !wrap(seg, segs[snd_p])) {
            incomplete.push_back(seg);
        }
    }

    int v = 0, t_min_snd = segs[fst_p].snd;
    reverse(incomplete.begin(), incomplete.end());
    for (auto &seg: incomplete) {
        int lv = min_snd - seg.fst + 1;
        int rv = max(0, t_min_snd - max_fst + 1);
        v = max(v, lv + rv);
        t_min_snd = min(t_min_snd, seg.snd);
    }
    v = max(v, min_snd - segs[snd_p].fst + 1 + max(0, t_min_snd - max_fst + 1));

    return max(same_v, v);
}

int main() {
    scanf("%d", &N);
    vector<pii> segs;
    for(int i = 0; i < N; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        segs.emplace_back(a, b);
    }
    sort(segs.begin(), segs.end());
    printf("%d\n", f(segs));
    return 0;
}

Measured memory_bytes: 2548
#include <iostream>

using namespace std;

void dispVector(int *v, int n)
{
	for(int i = 0; i < n; i++)
	{
		if( i != (n-1) ) 
		{
			cout << v[i] << " ";
		}
		else
		{
			cout << v[i] << endl;
		}
	}
}

void insertionSort(int *v, int n)
{
	int tmp;

	dispVector(v, n);
	for(int i = 1; i <= n-1; i++)
	{
		tmp = v[i];
		int j = i - 1;

		while( (j >= 0) && (v[j] > tmp) )
		{
			v[j+1] = v[j];
			j--;
		}
		v[j+1] = tmp;
		dispVector(v, n);
	}
}

int main(void)
{
	int N;
	int *A;

	cin >> N;
	A = new int[N];

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

	insertionSort(A, N);

	return 0;
}



Measured memory_bytes: 3088
R , C , K = map(int,input().split())
masu = [[0 for i in range(C)] for j in range(R)]
for i in range(K):
    r , c , v = map(int,input().split())
    masu[r-1][c-1] = v

dp0 = [[0 for i in range(C)] for j in range(R)]
dp1 = [[0 for i in range(C)] for j in range(R)]
dp2 = [[0 for i in range(C)] for j in range(R)] 
dp3 = [[0 for i in range(C)] for j in range(R)]

if masu[0][0] != 0:
    dp1[0][0] = masu[0][0]
for i in range(1,C):
    dp0[0][i] = max(dp0[0][i],dp0[0][i-1])
    dp1[0][i] = max(dp1[0][i],dp1[0][i-1])
    dp2[0][i] = max(dp2[0][i],dp2[0][i-1])
    dp3[0][i] = max(dp3[0][i],dp3[0][i-1])
    if masu[0][i] != 0:
        dp3[0][i] = max(dp3[0][i],dp2[0][i]+masu[0][i])
        dp2[0][i] = max(dp2[0][i],dp1[0][i]+masu[0][i])
        dp1[0][i] = max(dp1[0][i],dp0[0][i]+masu[0][i])




for i in range(1,R):
    for j in range(C):
        dp0[i][j] = max(dp0[i][j],dp0[i-1][j],dp1[i-1][j],dp2[i-1][j],dp3[i-1][j])
        if j != 0:
            dp0[i][j] = max(dp0[i][j],dp0[i][j-1])
            dp1[i][j] = max(dp1[i][j],dp1[i][j-1])
            dp2[i][j] = max(dp2[i][j],dp2[i][j-1])
            dp3[i][j] = max(dp3[i][j],dp3[i][j-1])
        if masu[i][j] != 0:
            dp3[i][j] = max(dp3[i][j],dp2[i][j]+masu[i][j])
            dp2[i][j] = max(dp2[i][j],dp1[i][j]+masu[i][j])
            dp1[i][j] = max(dp1[i][j],dp0[i][j]+masu[i][j])
print(max(dp0[-1][-1],dp1[-1][-1],dp2[-1][-1],dp3[-1][-1]))

Measured memory_bytes: 471216
// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> IP;
typedef pair<ll, LP> LLP;

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

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;
// }}}

int N, Y;

void init()
{
}

void solve()
{
    REP(i, N+1){
        REP(j, N+1){
            if(i + j > N) continue;
            int k = N - i - j;
            if(10*i + 5*j + k == Y){
                cout << i << " " << j << " " << k << endl;
                return;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> Y;
    Y /= 1000;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


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

#define mod 1000000007
#define maxn 1005

int n, m;
int dp[maxn][5005];

int main()
{
    //freopen("monotonic.in", "r", stdin);
    //freopen("monotonic.out", "w", stdout);
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int c, k;
        cin >> c >> k;
        int S = 0;
        for (int j = 0; j < k; j++)
        {
            int x;
            scanf("%d", &x);
            x--;
            S |= (1 << x);
        }
        for (int j = 0; j < (1 << n); j++)
            dp[i + 1][j] = dp[i][j];
        for (int j = 0; j < (1 << n); j++)
        {
            if (dp[i][j] == 0 && j != 0)
                continue;
            if (dp[i + 1][j | S] == 0)
                dp[i + 1][j | S] = dp[i][j] + c;
            else
                dp[i + 1][j | S] = min(dp[i + 1][j | S], dp[i][j] + c);
        }
    }
    if (dp[m][(1 << n) - 1] == 0)
        printf("-1\n");
    else
        printf("%d\n", dp[m][(1 << n) - 1]);

    return 0;
}

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

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;

signed main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<ll> b(m);

    for(auto& x : a){
        cin >> x;
        if(x > n * m){
            cout << 0 << endl;
            return 0;
        }
        --x;
    }
    for(auto& x : b){
        cin >> x;
        if(x > n * m){
            cout << 0 << endl;
            return 0;
        }
        --x;
    }
    sort(a.begin(), a.end(), greater<ll>());
    sort(b.begin(), b.end(), greater<ll>());
    ll sq = n * m;
    vector<ll> av(sq, -1);
    vector<ll> bv(sq, -1);
    for(ll i = 0; i < n; ++i){
        if(av[a[i]] != -1){
            cout << 0 << endl;
            return 0;
        }
        av[a[i]] = i + 1;
    }
    for(ll i = 0; i < m; ++i){
        if(bv[b[i]] != -1){
            cout << 0 << endl;
            return 0;
        }
        bv[b[i]] = i + 1;
    }
    auto avrui = av;
    auto bvrui = bv;
    avrui.back() = max(avrui.back(), 0LL);
    bvrui.back() = max(bvrui.back(), 0LL);
    for(ll i = sq - 1; i > 0; --i){
        avrui[i - 1] = max(avrui[i], avrui[i - 1]);
        bvrui[i - 1] = max(bvrui[i], bvrui[i - 1]);
    }

    ll ans = 1;
    ll c = 0;
    for(ll i = sq - 1; i >= 0; --i){
        if((av[i] != -1) != (bv[i] != -1)){
            ll ind = (av[i] == -1 ? avrui[i] : bvrui[i]);
            ans *= ind;
            ans %= MOD;
        }else if(av[i] == -1 && bv[i] == -1){
            ans *= max(0LL, avrui[i] * bvrui[i] - c);
            ans %= MOD;
        }
        c++; // C++
    }
    cout << ans % MOD << endl;
}


Measured memory_bytes: 31488
#include <stdio.h>
#include <math.h>

#define SQ(X) \
  ( (X) * (X) )
#define LEN(AX,AY,BX,BY) \
  ( sqrt ( SQ( (BX) - (AX) ) + SQ( (BY) - (AY) ) ) )

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  double ax, ay, bx, by, cx, cy;
  double res = 0.;

  scanf ( "%lf,%lf %lf,%lf", &ax, &ay, &bx, &by );

  while ( scanf ( " %lf,%lf", &cx, &cy ) == 2 )
  {
    double a = LEN( ax, ay, bx, by )
         , b = LEN( bx, by, cx, cy )
         , c = LEN( cx, cy, ax, ay );
    double z = ( a + b + c ) / 2.;
    
    res += sqrt ( z * ( z - a ) * ( z - b ) * ( z - c ) );
    bx = cx; by = cy;
  }

  printf ( "%.6f\n", res );

  return ( 0 );
}

Measured memory_bytes: 0
import java.util.*;

public class Main{
	public static void main(String args[]){
     	Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	char[] c = sc.next().toCharArray();
        int count = 0;
       int extra = 0;
      	int len = c.length;
        for(char ch: c){
            if(ch=='W')
            count++;
        }
      	for(int i =len-1;i>=len-count;i--){
            if(c[i]=='W')
            extra++;
        }
       if(count-extra < len/2)
        System.out.println(count-extra);
      else{
        System.out.println(len-count+extra);
      }
    }
}


Measured memory_bytes: 40708
#include<bits//stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	int t, n,p;
	priority_queue<int> pq;
	cin >> n >> t;vector<int> x(t);
	if (n >= t) {
		cout << 0 << endl;
		return 0;
	}
	rep(i, t) cin >> x[i];
	sort(x.begin(), x.end());
	vector<int> l(t - 1);
	rep(i, t - 1) pq.push(x[i + 1] - x[i]);
	p = x[t - 1] - x[0];
	rep(i, n - 1) {
		p -= pq.top();pq.pop();
	}
	cout << p << endl;
}

Measured memory_bytes: 1660
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef complex<double> com;
typedef pair<int, int> P;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 4e18;



int main() {
	int h, w; cin >> h >> w;
	ll ans = INF;
	rep(i, 0, h+1) {
		ll a = 1LL*i * w;
		ll b = 1LL*(h - i) * (w / 2);
		ll c = 1LL*h * w - a - b;
		ans = min(ans, max({ a,b,c })-min({ a,b,c }));
		b = 1LL*(h - i) / 2 * w;
		c = 1LL*h * w - a - b;
		ans = min(ans, max({ a,b,c }) - min({ a,b,c }));
	}
	rep(i, 0, w + 1) {
		ll a = 1LL*i * h;
		ll b = 1LL*(w - i) * (h / 2);
		ll c = 1LL*h * w - a - b;
		ans = min(ans, max({ a,b,c }) - min({ a,b,c }));
		b = 1LL*(w - i) / 2 * h;
		c = 1LL*h * w - a - b;
		ans = min(ans, max({ a,b,c }) - min({ a,b,c }));
	}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

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

Measured memory_bytes: 596
if __name__ == '__main__':
    h, w = map(int, input().split())
    map=[]
    for i in range(h):
        a=input()
        map.append(a)
    checkH=[False]*h
    checkW=[False]*w

    for i in range(h):
        for j in range(w):
            if map[i][j] =="#":
                checkH[i]=True
                checkW[j] = True

    for i in range(h):
        ans=""
        for j in range(w):
            if checkH[i] ==True and checkW[j]==True:
                ans+=map[i][j]
        if ans != "":
            print(ans)

Measured memory_bytes: 9088
H,W = map(int,input().split())
N = int(input())
a = list(map(int,input().split()))
l = [[0]*W for _ in range(H)]
bol = 1
line,cnt = 0,0

for i in range(1,N+1):
    for j in range(a[i-1]):
        if bol == 1:
            l[line][cnt] = i
        else:
            l[line][-cnt-1] = i
        cnt += 1
        if cnt == W:
            cnt = 0
            line += 1
            bol *= -1

for i in range(H):
    print(*l[i])

Measured memory_bytes: 9428
import collections

N = int(input())
A = list(map(int,input().split()))
B = collections.Counter(A)
C = []
for a,c in B.items():
    C += [a] * (c//2)
C.sort()

if len(C) >= 2:
    print(C[-1]*C[-2])
else:
    print(0)


Measured memory_bytes: 18600
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <climits>

using namespace std;

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

typedef long long LL;
typedef vector<int> VI;

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W, '0'));
  queue<VI> q;
  REP(i, H) {
    REP(j, W) {
      cin >> A[i][j];
      if (A[i][j] == '#') {
        VI v = {i, j, 0};
        q.push(v);
      }
    }
  }
  VI iv = {1, 0, -1, 0};
  VI jv = {0, -1, 0, 1};
  int maxcnt = 0;
  while (!q.empty()) {
    VI v = q.front();
    q.pop();
    maxcnt = max(maxcnt, v[2]);
    for (int k = 0; k < 4; k++) {
      int nexti = v[0]+iv[k];
      int nextj = v[1]+jv[k];
      if (0 <= nexti && nexti < H && 0 <= nextj && nextj < W && A[nexti][nextj] == '.') {
        A[nexti][nextj] = '#';
        VI nextv = {nexti, nextj, v[2]+1};
        q.push(nextv);
      }
    }
  }
  cout << maxcnt << endl;
  return 0;
}


Measured memory_bytes: 56628
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))), end((c)))
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int h, w;
char maze[100][100];

int sx, sy, gx, gy;

int d[1001][1001];
int bfs() {
	queue<pair<int, int>> que;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			d[i][j] = HINF;
		}
	}
	que.push(pair<int, int>(sx, sy));
	d[sy][sx] = 0;
	while (que.size()) {
		pair<int, int> p = que.front();
		que.pop();
		for (int i = 0; i < 4; i++) {
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (0 <= nx&&nx < w && 0 <= ny&&ny < h &&maze[ny][nx] != '#'&&d[ny][nx] == HINF) {
				que.push(pair<int, int>(nx, ny));
				d[ny][nx] = d[p.second][p.first] + 1;
			}
		}
	}
	return d[gy][gx];
}

int main() {
	cin >> h >> w;
	int num = 0;
	REP(i, h)REP(j, w) {
		cin >> maze[i][j];
		if (maze[i][j] == '#')num++;
	}
	sx = 0, sy = 0;
	gx = w - 1, gy = h - 1;
	int ret = bfs();
	cout << (ret != HINF ? h*w - ret - num - 1:-1) << endl;
}

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

using namespace std;

#define REP(var, n)  for (int var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<int>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pii;

#define all(c) begin(c),end(c)

#define D(x) do { std::cerr << x << " "; } while (0)
#define D2(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)


template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    return os << '(' << p.first << ',' << p.second << ')';
}


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

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


auto solve() {
    int n;
    cin>>n;
    string s;
    cin>>s;

    int r = 0, b = 0;
    for(auto&&e:s) {
        if(e == 'R') r++;
        else b++;
    }

    return r > b;
}


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

//    cout << (solve() ? "Heisei" : "TBD") << endl;
    cout << (solve() ? "Yes" : "No") << endl;
//    cout << solve() << endl;
//    solve();

    return 0;
}


Measured memory_bytes: 256
// Goods things are coming, just keep believing 
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
 
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define okay cout << "okay" << endl
// #define hey cout << "hey" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
// #define mpp make_pair
#define endl '\n'
#define ff first 
#define int long long
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()
 #define ld long double
#define INF 1000000000;
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
 
 
 
const int N = 2e5 + 5;
const int LG = 20;
const int mod = 1e9 + 7;
 
void solve()
{
	int a, b, c;
	cin >> a >> b >> c;
	if(a+  b + c >= 22)
	{
		cout << "bust";
	}
	else
	{
		cout << "win";
	}
}
 
int32_t main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int t = 1;
	// cin >> t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;

int main() {
    int t=1;
    //cin >> t;
    while(t--){
        ll a,b,c,d;
        cin >> a >> b >> c >> d;
        cout << max(a*c, max(a*d , max(b*c , b*d)));
    }
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
        int n;
        int ans = 0;
        cin >> n;
        map<string, bool> m;
        string sn;
        for(int i = 0; i < n; i++){
                cin >> sn;
                if(m[sn] != true){
                        m[sn] = true;
                        ans++;
                }

        }
        cout << ans << endl;
}


Measured memory_bytes: 19100
import java.util.*;


public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    long N = Long.parseLong(scanner.nextLine());

    String name = "";

   name = calc(N, name);

   System.out.println(name);
    scanner.close();
    return;
  }

  public static String calc(long N, String name){
    char c = (char) (N % 26 + 'a' - 1);
    if( N%26 == 0){
      c = 'z';
      N -= 26;
    }
    name = String.valueOf(c) + name;
    N = N - N%26;
    if(N / 26 > 0){
      name = calc(N / 26, name);
    }
    return name;
  }
}


Measured memory_bytes: 39240
#include <iostream>
#include <map>

int main(){
    int n;
    std::cin >> n;

    int val;
    std::map<int, int> a;
    for(int i = 0; i < n; ++i){
        std::cin >> val;
      	auto itr = a.find(val);
      	if(itr != a.end()){
	      	a.erase(itr);
        }else{
	      	a.insert(std::make_pair(val, 1));
        }
    }

    std::cout << a.size() << std::endl;

    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
	int n;
	cin >> n;
	long long cur = 1, inf = 1e18;
	vector<long long> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (a[i] == 0) {
			cout << 0;
			exit(0);
		}
	}
	for (int i = 0; i < n; ++i) {
		if (cur > inf / a[i]) {
			cout << -1;
			exit(0);
		}
		cur *= a[i];
	}
	cout << cur;
	return 0;
}

Measured memory_bytes: 4312
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int dp[100010][3];
int v[3];

int main() {
  int n;
  while(cin>>n) {
    memset(dp,0,sizeof(dp));
    REP(i,n) {
      inputs(v,3);
      if (i == 0) {
        REP(j,3) {
          dp[i+1][j] = v[j];
        }
      } else {
        REP(j,3) {
          REP(k,3) {
            if (j == k) continue;
            chmax(dp[i+1][k], dp[i][j] + v[k]);
          }
        }
      }
    }
    cout<< max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
  }
}


Measured memory_bytes: 1408
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

func main() {
	n := readi()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = readi()
	}

	// Note: agg1[a[i]] == 1のとき、同じ数が他に存在しない
	aMax := 0
	agg1 := make(map[int]int)
	for i := 0; i < n; i++ {
		agg1[a[i]]++
		aMax = max(aMax, a[i])
	}

	// Note: agg2[a[i]] = 1のとき、a[i]より小さい約数が存在する
	agg2 := make(map[int]bool, aMax)
	for i := 0; i < n; i++ {
		idx := 2
		for {
			tmp := a[i] * idx
			agg2[tmp] = true
			if tmp >= aMax {
				break
			}
			idx++
		}
	}

	ans := 0
	for i := 0; i < n; i++ {
		if agg1[a[i]] == 1 && !agg2[a[i]] {
			ans++
		}
	}

	fmt.Println(ans)
}

/*-------------------utilities-------------------*/

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func chmin(x *int, y int) bool {
	if *x > y {
		*x = y
		return true
	}
	return false
}

func chmax(x *int, y int) bool {
	if *x < y {
		*x = y
		return true
	}
	return false
}

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

func lcm(a, b int) int {
	return (a * b) / gcd(a, b)
}

func permutations(arr []int) [][]int {
	var helper func([]int, int)
	res := [][]int{}

	helper = func(arr []int, n int) {
		if n == 1 {
			tmp := make([]int, len(arr))
			copy(tmp, arr)
			res = append(res, tmp)
		} else {
			for i := 0; i < n; i++ {
				helper(arr, n-1)
				if n%2 == 1 {
					tmp := arr[i]
					arr[i] = arr[n-1]
					arr[n-1] = tmp
				} else {
					tmp := arr[0]
					arr[0] = arr[n-1]
					arr[n-1] = tmp
				}
			}
		}
	}
	helper(arr, len(arr))
	return res
}

func isPrime(n int) bool {
	if n == 1 {
		return false
	}
	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			return false
		}
	}
	return true
}

func divisor(n int) (res []int) {
	for i := 1; i*i <= n; i++ {
		if n%i == 0 {
			res = append(res, i)
			if i*i != n {
				res = append(res, n/i)
			}
		}
	}
	sort.Ints(res)
	return
}

// func searchInts(a []int, k int) int {
// 	return binarySearch(len(a), func(i int) bool {
// 		return a[i] >= k
// 	})
// }

func binarySearch(n int, f func(int) bool) int {
	i, j := 0, n
	for i < j {
		h := int(uint(i+j) >> 1)
		if !f(h) {
			i = h + 1
		} else {
			j = h
		}
	}
	return i
}

/*-------------------init-------------------*/

const (
	INF = 1000000000000000000
	MOD = 1e9 + 7
)

var (
	readString func() string
)

func init() {
	readString = newReadString(os.Stdin)
}

/*-------------------inputs-------------------*/

func readi() int {
	return int(readi64())
}

func readi64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readf() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}


Measured memory_bytes: 38384
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600

int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  rep(i,n) scanf("%d", &vec[i]);
  rep(i,n) vec[i]--;

  int res=0;
  rep(i,n){
    if(vec[vec[i]]==i) res++;
  }

  cout<<res/2<<endl;
  return 0;
}


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

using namespace std;

const int N = 2e5 ;
int cost[N], n , a[N];
int main()
{
    cin >> n ;
    for ( int i = 0 ; i < n ; i++) cin >> a[i] ;
    cost[0] = 0 ;
    cost[1] = abs(a[1]-a[0]);
    for ( int i = 2 ; i < n ; i++) {
        cost[i] = min(cost[i-1]+abs(a[i]-a[i-1]),cost[i-2]+abs(a[i]-a[i-2]));
    }
    cout << cost[n-1] ;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll D, G;
    cin >> D >> G;
    vec P(D), C(D);
    REP(i,0,D) cin >> P[i] >> C[i];

    ll m = INF;
    REP(i,0,1<<D) {
        ll cnt = 0, sum = 0;
        REP(j,0,D) {
            if((i>>j) & 1) {
                sum += 100 * (j+1) * P[j] + C[j];
                cnt += P[j];
            }
        }
        if(sum >= G) {
            m = MIN(m,cnt);
            continue;
        }
        for(ll j=D-1; j>=0; --j) {
            if(((i>>j) & 1) == 0) {
                if(sum + 100 * (j+1) * P[j] < G) {
                    sum += 100 * (j+1) * P[j];
                    cnt += P[j];
                }
                else {
                    ll n = (G-sum+100*(j+1)-1) / (100*(j+1));
                    sum += 100 * (j+1) * n;
                    cnt += n;
                    break;
                }
            }
        }
        if(sum >= G) m = MIN(m,cnt);
    }
    PR(m);

    return 0;
}

/*



*/

Measured memory_bytes: 3624
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;

int main(){
  int a,b; cin>>a>>b;
  int aa=min(a,b);
  int bb=max(a,b);
  for(int i=0;i<bb;i++) cout<<aa;
}


Measured memory_bytes: 256
/* Dsingh_24 */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ios	    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

#define N  100005

int main()
{
	ios
	ll n,k,a,b;
	cin>>n>>a>>b;
	cout<<min(a,b)<<" "<<max(0LL,a+b-n);
	return 0;
}

Measured memory_bytes: 256