akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;


void solve() {
}

int H, N, A[101010];
signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> H >> N;
    int tmp = 0;
    FOR(N)
        cin >> A[i];
    FOR(N)
    tmp += A[i];
    if (tmp >= H)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    solve();
    return 0;
}


Measured memory_bytes: 1024
def solve():
    s = input()
    ans = ''
    for i in range(len(s)+1):
        for j in range(i+1, len(s)+1):
            if s[i:j].replace('A', '').replace('C', '').replace('G', '').replace('T', '') == '':
                if len(ans) < len(s[i:j]):
                    ans = s[i:j]
    print(len(ans))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int A,B,K;
	cin>>A>>B>>K;
	vector<int> divisors;
	int min = A;
	if(min > B)min = B;
	for(int i = 1; i <= min; i++){
		if(A % i == 0 && B % i == 0){
			divisors.push_back(i);
			//cout<<min<<endl;
		}
	}
	for(int i = 0; i < K - 1; i++){
		divisors.pop_back();
	}
	cout<<divisors.back()<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;
const int MOD = 1000000007;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

int K;
string initial, unlocking;

int solve(){
    map<string, int> dist;
    queue<string> que;
    
    dist[initial] = 0;
    que.push(initial);
    while(!que.empty()){
        string s = que.front(); que.pop();
        int pdist = dist[s];
        if(s == unlocking)
            return pdist;
        
        int i = 0;
        while(i<K && s[i]==unlocking[i]) i++;
        
        int diff = (unlocking[i]-s[i]+10)%10;
        for(int j=i; j<K; j++){
            s[j] = (s[j]-'0'+diff)%10 + '0';
            if(dist.find(s) == dist.end()){
                dist[s] = pdist + 1;
                que.push(s);
            }
        }
    }
    //not implemented
    return -1;
}

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.precision(16);
    //cout.setf(ios::fixed);
    
    while(cin>>K, K){
        cin >> initial >> unlocking;
        
        cout << solve() << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2644
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d,e,f,i,flag;

int main(){
	cin>>a>>b;
	c=(int)(a/0.08),d=(int)((a+1)/0.08)+1;
	e=(int)(b/0.1),f=(int)((b+1)/0.1)+1;
	
	if(c<=e) c=e;
	if(d>=f) d=f;
	
	for(i=c;i<=d;i++){
		e=(int)(i*0.08);
		f=(int)(i*0.1);
		
		if(e==a&&f==b){
			flag=i;
			break;
		}
	}
	
	if(flag){
		cout<<flag;
	}else{
		cout<<-1;
	}
	
	return 0;
}

Measured memory_bytes: 256
def ltos(l):
  s=''
  for i in range(len(l)):
    s+=' '
    s+=str(l[i])
    
  print(s)

b1=[[0]*10 for i in range(3)]
b2=[[0]*10 for i in range(3)]
b3=[[0]*10 for i in range(3)]
b4=[[0]*10 for i in range(3)]
b=[b1,b2,b3,b4]

n=int(input())
for i in range(n):
  bn,f,r,v=map(int,input().split(' '))
  b[bn-1][f-1][r-1]+=v


for i in range(len(b)):
  for j in range(len(b[i])):
    ltos(b[i][j])
  if i == 3:
    pass
  else:
    print("####################")




Measured memory_bytes: 5604
import itertools
n = int(input())
l = ["".join(sorted(input())) for i in range(n)]
d = {}
cnt = 0

for i in range(n):
  if l[i] not in d:
    d[l[i]] = 1
  else:
    cnt += d[l[i]]
    d[l[i]] += 1

print(cnt)

Measured memory_bytes: 19528
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


class Main {


   public static void main(String args[]) throws IOException{

	   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	   int n = Integer.parseInt( br.readLine()  );
	   String[] string =  br.readLine().split(" ");
	   int[] A = new int[n];
	   for(int i = 0;i < n; i++){
         A[i] = Integer.parseInt( string[i] ) ;
	   }

	   int n2 = Integer.parseInt( br.readLine()  );
	   String[] string2 =  br.readLine().split(" ");
	   int[] m = new int[n2];
	   for(int i = 0;i < n2; i++){
         m[i] = Integer.parseInt( string2[i] ) ;
	   }


	   for(int i = 0;i < n2; i++){

		   if( solve(0 ,m[i] ,n , A ) ){

			   System.out.println("yes");
		   }
		   else{
			   System.out.println("no");
		   }

	   }



   }




   public static boolean solve( int i , int m , int n , int[] A){

	   boolean res;

	   if (m == 0){
		  return true;
	   }

	   if( i >= n ){
		   return false;
	   }
	   res = solve(i + 1, m, n, A) || solve(i + 1, m - A[i], n , A);
	  // System.out.println( i + " " + m+ " "+n +res);
	   return res;

   }
}

Measured memory_bytes: 24816
#include<stdio.h>
#include<set>
typedef std::multiset<int>S;
int main()
{
	int w,d,r,t;
	while(scanf("%d%d",&w,&d),w)
	{
		S s;
		r=0;
		while(w--)scanf("%d",&t),r+=t,s.insert(t);
		while(d--)
		{
			scanf("%d",&t);
			S::iterator i=s.find(t);
			if(i==s.end())r+=t;
			else s.erase(i);
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 0
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, m = na()

b = []
for i in range(n):
    b.append(ns())

for i in range(n):
    for j in range(m):
        if b[i][j] == "#":
            yes = 0
            if j-1 >= 0 and b[i][j-1] == "#":
                yes = 1
            if i-1 >= 0 and b[i-1][j] == "#":
                yes = 1
            if j+1 < m and b[i][j+1] == "#":
                yes = 1
            if i+1 < n and b[i+1][j] == "#":
                yes = 1
            if yes == 0:
                print("No")
                sys.exit(0)
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
int main()
{
    long i,j,t,a,b,n,c,temp,m;
    t=1;
    // cin>>t;
    while(t--)
    {
       cin>>a>>b;
       cout<<(a-1)*(b-1);
       
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
const int INF = 1e18;

using namespace std;


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

  int ans = -1;
  REP(i, 50000) if((int)((double)i*1.08) == N) ans = i;

  if(ans == -1) cout << ":(" << endl;
  else cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
// Problem : A - Rainy Season
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	string s;
	cin>>s;
	int count=0,r=0;
	l00p(i,1,3)
	{
		if(s[i]==s[i-1] && s[i]=='R')
		count++;
		if(s[i]=='R'||s[i-1]=='R')
		r++;
	}
	if(r!=0)
	cout<<count+1<<nl;
	else
	cout<<0<<nl;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

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

// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

// dp[ni][wi] := ni個までの品物で最大Wとした時の価値の最大値
// Wは10^9だが, w1との差分を考えればok
int dp[575][5*575];

signed main() {
  INIT;
	VAR(int, n, W);
	vector< int > w(n), v(n);
	REP(i, n) cin >> w[i] >> v[i];
	int w_init = w[0];
	REP(i, n) w[i] -= w_init;

	int w_sum = 0;
	REP(ni, n) {
		RREP(nj, ni + 1) {
			RREP(wi, w_sum + 1) {
				// if (nj * w_init + wi + w[ni] > W) continue;
				dp[nj+1][wi+w[ni]] = max(dp[nj+1][wi+w[ni]], dp[nj][wi] + v[ni]);
			}
		}
		w_sum += w[ni];
	}

	int ans = 0;
	REP(ni, n+1) {
		REP(wi, 575) {
			if (ni * w_init + wi > W) continue;
			ans = max(ans, dp[ni][wi]);
		  // debug(dp[ni][wi]);
		}
	}
	OUT(ans)BR;
	
  
  return 0;
}


Measured memory_bytes: 2816
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int player = sc.nextInt();
        int[][] n = new int[player][3];
        int[][] flag = new int[player][3];

        int[] score = new int[player];
        int cnt = 0;
        int buf = 0;
        for(int i = 0;i < player;i++){
            for(int j = 0;j < 3;j++){
                n[i][j] = sc.nextInt();
                flag[i][j] = 1;
            }
        }
        for(int i = 0;i < player;i++){
            for(int j = 0;j < 3;j++){
                for(int k = i+1;k < player;k++){
                    if(n[i][j] == n[k][j]){
                        flag[i][j] = 0;
                        flag[k][j] = 0;
                    }
                }
            }
        }
        for(int i = 0;i < player;i++){
            for(int j = 0;j < 3;j++){
                score[i] += n[i][j] * flag[i][j];
            }
            System.out.println(score[i]);            
        }
    }
}

Measured memory_bytes: 28824
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	D := nextInt()
	c := nextInts(26)
	s := make([][]int, D)
	for i := range s {
		s[i] = nextInts(26)
	}

	last := [26]int{}
	v := 0
	for d := 0; d < D; d++ {
		t := nextInt() - 1
		last[t] = d + 1

		v += s[d][t]
		dec := 0
		for i := 0; i < 26; i++ {
			dec += c[i] * (d + 1 - last[i])
		}
		v -= dec

		puts(v)
	}
}


Measured memory_bytes: 2004
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int n,m,ans=0;
bool used[10];
int perm[10],a[50],b[50];

bool che(int x,int y){
    for(int i=0;i<m;i++){
        if(a[i]==x&&b[i]==y)return true;
        if(a[i]==y&&b[i]==x)return true;
    }
    return false;
}

void solve(){
    bool res=true;
    for(int i=0;i<n-1;i++){
        int x=perm[i],y=perm[i+1];
        if(!che(x,y))res=false;
    }
    if(res)ans++;
}

void permutation1(int pos,int n){
    if(pos==n){
        if(perm[0]==1)solve();
        return ;
    }
    
    for(int i=0;i<n;i++){
        if(!used[i]){
            perm[pos]=i+1;
            used[i]=true;
            permutation1(pos+1,n);
            used[i]=false;
        }
    }
    return ;
}

int main(void){
    cin>>n>>m;
    for(int i=0;i<m;i++){
        cin>>a[i]>>b[i];
    }
    permutation1(0,n);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n1,n2,n3,n4;
    scanf("%d%d%d%d",&n1,&n2,&n3,&n4);
    n1=n1*n2;
    n3=n3*n4;
    if(n1>=n3){
        printf("%d",n1);
    }
    else{
        printf("%d\n",n3);
    }

    return 0;
}


Measured memory_bytes: 128
fn main() {
    proconio::input! {
        n: u128,
        k: u128,
    }
    fn sum(min: u128, max: u128) -> u128 {
        (min + max) * (max - min + 1) / 2
    }
    let mut count = 0u128;
    for i in k..=n {
        count += 1 + sum(n + 1 - i, n) - sum(0, i - 1);
    }
    count += 1;
    count %= 1_000_000_007;
    println!("{}", count);
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    int n, q;
    cin >> n >> q;
    vector<ll> a(n);
    REP(i,n) {
        cin >> a[i];
    }
    REP(i, q) {
        ll x; cin >> x;
        int right = 0;
        ll ans = 0;
        ll sum = 0;
        for (int left = 0; left < n; ++left) {
            while (right < n && sum+a[right] <= x) {
                sum += a[right];
                ++right;
            }
            ans += (right-left);
            if (left == right) ++right;
            else sum -= a[left];
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fr(a,b) for(long long i=a;i<b;i++)
#define vi vector<ll>
const ll MAX=1e4;
const ll mod=1e9+7;
const ll INF=1e18+12;
set< pair<ll,ll> >ss;
ll dp[MAX][MAX];

                                    //SAMEER KUMAR SINGH//
// ================================================================================================================================//
// ================================================================================================================================//
// ================================================================================================================================//

int fun(string s1,string s2,ll n1,ll n2){

     if(n1<0||n2<0)
       return 0;
     if(dp[n1][n2]!=0)
       return dp[n1][n2];
     if(s1[n1]==s2[n2]){
      dp[n1][n2]=1+fun(s1,s2,n1-1,n2-1);
      return dp[n1][n2];
      }
     else{
       ll k1=fun(s1,s2,n1-1,n2);
       ll k2=fun(s1,s2,n1,n2-1);
       dp[n1][n2]=max(k1,k2);
       return dp[n1][n2];
     }
}

int main(){
   FASTIO;
   ll tt=1;
   //cin>>tt;

   while(tt--){
     //ll n1,n2;cin>>n1>>n2;
     string s1,s2;cin>>s1>>s2;

     for(ll i=1;i<=s1.size();i++){
       for(ll j=1;j<=s2.size();j++){
          if(s1[i-1]==s2[j-1])
           dp[i][j]=dp[i-1][j-1]+1;
          else{
           dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
          }
       }
     }
     vector<char>vv;
     ll i=s1.size();
     ll j=s2.size();



     while(i>0&&j>0){
        if(s1[i-1]==s2[j-1]){
         vv.push_back(s1[i-1]);
         i--;
         j--;
         }
         else if(dp[i-1][j]>=dp[i][j-1]){
              i--;
         }
         else{
             j--;
         }
     }
     reverse(vv.begin(),vv.end());
     for(auto x:vv)
      cout<<x;
   }

   return 0;
}


Measured memory_bytes: 234496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
const ll INF = 1LL << 58;
const ll MOD = 1000000007;
typedef vector<pii> vpii;
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;
}

signed main()
{
    int N;
    cin >> N;
    string tmp;
    int A, B, BA;
    A = 0;
    B = 0;
    BA = 0;
    int ans = 0;
    REP(i, N)
    {
        cin >> tmp;
        if (tmp[0] == 'B' and tmp[tmp.size() - 1] == 'A')
            BA++;
        else if (tmp[0] == 'B')
            B++;
        else if (tmp[tmp.size() - 1] == 'A')
            A++;
        REP(j, tmp.size() - 2)
        {
            if (tmp.substr(j, 2) == "AB")
                ans++;
        }
    }
    if (BA > 0)
    {
        ans += BA - 1;
        if (A > 0)
        {
            A--;
            ans++;
        }
        if (B > 0)
        {
            B--;
            ans++;
        }
    }
    ans += min(A, B);

    cout << ans << endl;
    // system("pause");
}

Measured memory_bytes: 384
def resolve():
    n = int(input())
    h = list(map(int, input().split()))

    for i in range(n-1):
        if h[len(h)-2-i] - h[len(h)-1-i] >= 2:
            print("No")
            return
        elif h[len(h)-2-i] - h[len(h)-1-i] == 1:
            h[len(h) - 2 - i] = h[len(h)-2-i] - 1

    print("Yes")
    
resolve()

Measured memory_bytes: 63984
import Control.Applicative
import Control.Monad
import Data.List

main = do
    n <- readLn :: IO Int
    as <- fmap read . words <$> getLine :: IO [Int]
    let evs = length $ filter even as
    let ods = length $ filter odd as
    let a1 = 2 ^ evs
    let a2 = 1 ^ ods
    print $ 3 ^ n - (a1 * a2)

Measured memory_bytes: 508
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const double EPS = 1.0e-10;

class Point
{
public:
    double y, x;
    Point(){
        y = x = 0.0;
    }
    Point(double y0, double x0){
        y = y0;
        x = x0;
    }
    Point operator+(const Point& p) const{
        return Point(y + p.y, x + p.x);
    }
    Point operator-(const Point& p) const{
        return Point(y - p.y, x - p.x);
    }
    Point operator*(double a) const{
        return Point(y * a, x * a);
    }
    Point operator/(double a) const{
        return Point(y / a, x / a);
    }
    double length() const{
        return sqrt(y * y + x * x);
    }
    double dist(const Point& p) const{
        return sqrt(pow(y - p.y, 2) + pow(x - p.x, 2));
    }
    double dot(const Point& p) const{
        return y * p.y + x * p.x; // |a|*|b|*cos慮
    }
    double cross(const Point& p) const{
        return x * p.y - y * p.x; // |a|*|b|*sin慮
    }
};

int n;
vector<Point> p;
vector<int> v;

double check(Point q)
{
    double ret = 0.0;
    for(int i=0; i<n; ++i)
        ret = max(ret, p[i].dist(q) / v[i]);

    return ret;
}

double solveY(double x)
{
    double a = 0.0;
    double b = 100.0;

    while(a < b - EPS){
        double s = check(Point((2*a+b) / 3, x));
        double t = check(Point((a+2*b) / 3, x));
        if(s > t)
            a = (2*a+b) / 3;
        else
            b = (a+2*b) / 3;
    }

    return check(Point((a+b) / 2, x));
}

double solveX()
{
    double a = 0.0;
    double b = 100.0;

    while(a < b - EPS){
        double s = solveY((2*a+b) / 3);
        double t = solveY((a+2*b) / 3);
        if(s > t)
            a = (2*a+b) / 3;
        else
            b = (a+2*b) / 3;
    }

    return solveY((a+b) / 2);
}

int main()
{
    for(;;){
        cin >> n;
        if(n == 0)
            return 0;

        p.resize(n);
        v.resize(n);
        for(int i=0; i<n; ++i)
            cin >> p[i].x >> p[i].y >> v[i];

        printf("%.10f\n", solveX());
    }
}

Measured memory_bytes: 1268
L, R = list(map(int, input().split()))
ans = 2020
if abs(L-R)>=2020:
    print(0)
else:
    for i in range(L, R):
        for j in range(L, R+1):
            if i==j:
                continue
            else:
                ans = min(ans, (i*j)%2019)
    print(ans)



Measured memory_bytes: 2940
#pragma GCC optimize("-O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void Main();
#ifdef ConanYu
#include "local.hpp"
#else
#define debug(...) do { } while(0)
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  Main();
}
#endif

const int N = 1e5 + 10;
int a[N];

int fpow(int a, int b, int c) {
  int ans = 1;
  for(; b; b >>= 1, a = 1ll * a * a % c) {
    if(b & 1) {
      ans = 1ll * ans * a % c;
    }
  }
  return ans;
}

void Main() {
  map<int, int> mp;
  int n; cin >> n;
  for(int i = 1; i <= n; i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  if(a[1] != 0) {
    cout << 0 << "\n";
    return;
  }
  if(mp[0] >= 2) {
    cout << 0 << "\n";
    return;
  }
  int ans = 1;
  for(int i = 1; i <= n - 1; i++) {
    ans = 1ll * ans * fpow(mp[i - 1], mp[i], 998244353) % 998244353;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
    int64_t H;
    cin >> H;

    int64_t ans=1;
    while(H > 0){
        H /= 2;
        ans *= 2;
    }

    cout << ans-1 << endl;
}


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

namespace id_0238cs
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var t = int.Parse(Console.ReadLine());
                if (t == 0) break;
                var n = int.Parse(Console.ReadLine());
                List<int> studyTimes = new List<int>();
                foreach (var s in Enumerable.Range(0, n))
                {
                    var vs = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    studyTimes.Add(vs[1] - vs[0]);
                }
                
                var totalStudyTime = studyTimes.Sum();
                if (totalStudyTime < t)
                {
                    Console.WriteLine(t - totalStudyTime);
                }
                else
                {
                    Console.WriteLine("OK");
                }
            }
        }
    }
}



Measured memory_bytes: 9696
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    N%=10;
    if(N==3) cout<<"bon";
    else if(N==0 || N==1 || N==6 || N==8) cout<<"pon";
    else cout<<"hon";
    
}



Measured memory_bytes: 3616
#include<iostream>
#include<string>

#define reps(i,f,n) for(int i = f; i <= n; ++i)
#define rep(i,n) reps(i, 0, n-1)

using namespace std;

int main(){
  int n;
  while(1){
    cin >> n;
    if(n == 0)break;
    string x[1024];
    rep(i,n){
      cin >> x[i];
    }
    rep(i,n){
      for(int j = x[i].size()-1; j >= 0; --j){
        if(x[i][j] == '.'){
          x[i][j] = '+';
          break;
        }
      }
    }
    rep(i,n){
      rep(j,x[i].size()){
        if(x[i][j] == '+'){
          bool flag = false;
          reps(k,i+1,n-1){
            if(x[k].size() > j){
              if(x[k][j] == '+'){
                flag = true;
                break;
              }
              if('a'<= x[k][j]  && x[k][j] <= 'z'){
                break;
              }
            }
          }
          if(flag){
            reps(k,i+1,n-1){
              if(x[k][j] != '+'){
                x[k][j] = '|';
              }else{
                break;
              }
            }
          }
        }
      }
    }
    rep(i,n){
      rep(j,x[i].size()){
        if(x[i][j] == '.'){
          x[i][j] = ' ';
        }
      }
    }
    rep(i,n){
      cout << x[i] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3852
#include <iostream>
#include <algorithm>
#include <queue>

using namespace std;

int H,W;
int C[1410][1410];
int S[1410][1410];

deque<pair<int,int>> Q; 
int main(){
	iostream::sync_with_stdio(false);
	cin>>H>>W;
	for(int y=0;y<H;y++)
		for(int x=0;x<W;x++)
			cin>>C[y][x];
	for(int x=0;x<=W;x++)S[0][x]=0;
	//for(int y=0;y<=H;y++)S[y][0]=0;
	for(int y=0;y<H;y++)
	{
		for(int x=0;x<W;x++)
			S[y+1][x]=C[y][x]==0?S[y][x]+1:0;
		//cerr<<endl;
	}
	int m=0;
	
	for(int y=0;y<=H;y++){
		Q.emplace_front(-1,0);
		for(int x=0;x<=W;x++){
			int last_pop=x;
			while(Q.front().second>S[y][x]){
				m=max(m,(x-Q.front().first)*Q.front().second);
				last_pop=Q.front().first;
				Q.pop_front();
			}
			if(S[y][x]>Q.front().second){
				Q.emplace_front(last_pop,S[y][x]);
				//cerr<<x<<" "<<S[y][x]<<endl;
			}
		}
	}
			
	cout<<m<<endl;
	return 0;
	
}

Measured memory_bytes: 18672
#include<stdio.h>
int main(void){
    int a,b,c,T=0,H=0;
    while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){
        if(a==b)H++;
        if(a*a+b*b==c*c)T++;
    }
    printf("%d\n%d\n",T,H);
    return 0;
}

Measured memory_bytes: 596
#include <cstdio>
#include <iostream>

using namespace std;

int num[10];

int main() {
	while (scanf("%d", &num[0]) != EOF) {
		for (int i=1; i<10; ++i) scanf ("%d", &num[i]);
		for (int i=0; i<3; ++i) {
			for (int j=i+1; j<10; ++j) {
				if (num[i] < num[j]) {
					int tmp = num[i];
					num[i] = num[j];
					num[j] = tmp;
				}
			}
		}
		printf ("%d\n%d\n%d\n", num[0], num[1], num[2]);
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner scan = new Scanner(is);
        int N = scan.nextInt();
        Map<String, Integer> map = new HashMap();
        for(int i = 0; i < N; i++) {
            String str = scan.next();
            map.put(str, map.getOrDefault(str, 0)+1);
        }
        PriorityQueue<Map.Entry<String, Integer>> pq = new PriorityQueue<Map.Entry<String, Integer>>(
            (e1, e2) -> e1.getValue() != e2.getValue() ? e2.getValue() - e1.getValue() : e1.getKey().compareTo(e2.getKey())
        );
        for(Map.Entry<String, Integer> e : map.entrySet()) {
            pq.offer(e);
        }
        int max = pq.peek().getValue();
        while(!pq.isEmpty()) {
            Map.Entry<String, Integer> e = pq.poll();
            if(e.getValue() != max)
                return;
            os.println(e.getKey());
        }
    }
}

Measured memory_bytes: 85064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        DStringFormation solver = new DStringFormation();
        solver.solve(1, in, out);
        out.close();
    }

    static class DStringFormation {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            String x = in.next();
            int q = in.nextInt();
            StringBuilder a[] = new StringBuilder[2];
            a[0] = new StringBuilder();
            a[1] = new StringBuilder();
            int r = 0;
            while (q-- > 0) {
                int t = in.nextInt();
                if (t == 1) {
                    r++;
                    continue;
                }
                int p = in.nextInt() - 1;
                String c = in.next();
                a[(p + r) % 2].append(c);
            }
            StringBuilder ans = new StringBuilder();
            if (r % 2 == 0) {
                ans.append(a[0].reverse());
                ans.append(x);
                ans.append(a[1]);
            } else {
                ans.append(a[1].reverse());
                ans.append(new StringBuilder(x).reverse().toString());
                ans.append(a[0]);
            }
            out.println(ans.toString());
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 47536
#include<stdio.h>

#define X 100000

int partition(int [], int, int);

int main(){
  int i, n, p=0, q, r;
  int A[X];

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

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

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



Measured memory_bytes: 2124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;


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

    int A,B,C;
    cin >> A >> B>> C;
    int x=max(max(A,B),C);
    int a,b,c;
    a=x-A;
    b=x-B;
    c=x-C;
    int sum=a+b+c;
    int ans=0;
    if(sum%2==0){
        ans=sum/2;
    }
    else{
        ans=(1+sum)/2+1;
    }

    cout << ans << endl;

}


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

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

  vector<pair<int, int>> sc(M);
  for(auto& x: sc){
    cin >> x.first >> x.second;
  }

  int ans = -1;
  if(all_of(sc.begin(), sc.end(), [](pair<int, int> x){return x.second == 0;}) && N == 1){
    cout << 0 << endl;
    return 0;
  }
  

  int start = 1;
  for(int n = 0; n < N - 1; n++){
    start *= 10;
  }
  for(int n = start; n < start * 10; n++){
    bool ok = true;
    for(auto x: sc){
      int n_copy = n;
      for(int i = 0; i < N; i++){
        int digit = n_copy % 10;
        n_copy /= 10;
        if(N - x.first == i && digit != x.second){
          ok = false;
        }
      }
    }
    if(ok){
      ans = n;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, n) for(int i = 1; i < n; i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


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


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

#define trav(a, A) for (auto & a : A)
#define f first
#define s second

typedef long long ll;

const ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	ll i, j, n, x, y, r, g, c;
	cin >> x >> y >> r >> g >> c;
	vector <ll> R (r), G (g), eaten (x + y + c);
	trav (a, R) cin >> a;
	trav (a, G) cin >> a;
	sort (R.rbegin (), R.rend ());
	sort (G.rbegin (), G.rend ());
	for (i = j = 0; i < x; ++i, ++j) eaten[j] = R[i];
	for (i = 0; i < y; ++i, ++j) eaten[j] = G[i];
	for (; j < eaten.size (); ++j) cin >> eaten[j];
	sort (eaten.rbegin (), eaten.rend ());
	ll ans = 0;
	for (i = 0; i < x + y; ++i) ans += eaten[i];
	cout << ans << '\n';

	return 0;
}



Measured memory_bytes: 3968
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

ll ns,nc;

void run() {
	scanf("%lld%lld",&ns,&nc);

	// max(x=0..nc/2,min(ns+x,(nc-2*x)/2))

	ll ret=min(ns,nc/2);
	if(2*nc>=ns) {
		ll x=nc/4-ns/2;
		for(ll xx=x-5;xx<=x+5;++xx) {
			if(xx>=0&&2*xx<=nc) {
				//printf("%lld -> %lld\n",xx,min(ns+xx,(nc-2*xx)/2));
				ret=max(ret,min(ns+xx,(nc-2*xx)/2));
			}
		}
	}
	printf("%lld\n",ret);
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int l,r;
  cin>>l>>r;
  vector<int> v;
  if(r-l+1<2019){
    set<int> s;
    for(int i=l;i<=r;i++)
      s.insert(i%2019);
    for(int i:s)
      v.push_back(i);
  }else
    for(int i=0;i<2019;i++)
      v.push_back(i);
  int m=2019;
  for(int i=0;i<v.size();i++)
    for(int j=i+1;j<v.size();j++)
      m=min(m,v.at(i)*v.at(j)%2019);
  cout<<m<<endl;
}

Measured memory_bytes: 384
// C - Count order

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

bool equal(vector<int> A, vector<int> B) {
    for (int i=0; i<A.size(); i++) {
        if (A[i] != B[i]) {
            return false;
        }
    }

    return true;
}

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

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

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

    int order = 1;
    int P_order, Q_order;
    do {
        if (equal(vec, P)) {
            P_order = order;
        }
        if (equal(vec, Q)) {
            Q_order = order;
        }
        order++;
    } while (next_permutation(vec.begin(), vec.end()));

    cout << abs(P_order - Q_order) << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

const int N = 1e5;
const int INF = 1e9;

string s;
set<string> st;
bool ok[N + 1];

int check(int r) {
    string t[3];
    t[0] = s.substr(max(0, r - 4), r - max(0, r - 4) + 1);
    t[1] = s.substr(max(0, r - 5), r - max(0, r - 5) + 1);
    t[2] = s.substr(max(0, r - 6), r - max(0, r - 6) + 1);
    for (string z : t)
        if (st.count(z))
            return z.length();
    return 0;
}


int main() {
    cin >> s;
    int n = s.size();
    st.insert("dream");
    st.insert("dreamer");
    st.insert("erase");
    st.insert("eraser");
    for (int i = 0; i < n; i++) {
        int rng = check(i);
        if (rng && ok[i - rng] || rng && i - rng < 0)
            ok[i] = 1;
    }
    if (ok[n - 1])
        cout << "YES";
    else
        cout << "NO";
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL);

int main() {
  FAST;
  double R;
  cin >> R;
  cout << fixed << setprecision(10);
  cout << 2 * R * M_PI << endl;
}

Measured memory_bytes: 3800
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;

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

	if (x >= 1200) {
		cout << "ARC" << endl;
	}
	else {
		cout << "ABC" << endl;
	}

	return 0;
}

Measured memory_bytes: 3596
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000000
#define VMAX 10000

int main(){
  unsigned short *A,*B;

  int C[VMAX+1];
  int n,i,j;
  scanf("%d",&n);

  A=malloc(sizeof(short)*n+1);
  B=malloc(sizeof(short)*n+1);

  for(i=0;i<VMAX;i++){
    C[i]=0;
  }

  for(i=0;i<n;i++){
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }

  for(i=1;i<=VMAX;i++){
    C[i]=C[i]+C[i-1];
  }

  for(j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n;i++){
    if(i>1){
      printf(" ");
    }
    printf("%d",B[i]);
  }
  printf("\n");

  return 0;
}

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

#define lp(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define ff first
#define ss second

using namespace std;

void maxMultiple(){
    int l,r,ans=2019;
    cin>>l>>r;
    for(long long i=l;i<=r;i++){
        for(long long j=i+1;j<=r;j++){
            int a=i*j%2019;
            ans=min(a,ans);
            if (ans==0) break;
        }
        if(ans==0)break;
    }
    cout<<ans<<endl;
}

int main() {
    maxMultiple();
}

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

using namespace std;

int x[100005];
int y[100005];
int B[2005][2005];
int W[2005][2005];

template<int VW, int VH> struct add2D {
	int v[VH][VW];
	void set(int x,int y,int c){v[y][x]=c;}
	void build(){
	int i,j;
	for(i=0;i<VH;i++){
		for(j=0;j<VW;j++){
			if(i>0){v[i][j]+=v[i-1][j];}
			if(j>0){v[i][j]+=v[i][j-1];}
			if(i>0&&j>0){v[i][j]-=v[i-1][j-1];}
		}
	}
	}
	int get(int sx,int sy,int tx,int ty){
	int ret=v[ty][tx];
	if(sy>0){ret-=v[sy-1][tx];}
	if(sx>0){ret-=v[ty][sx-1];}
	if(sy>0&&sx>0){ret+=v[sy-1][sx-1];}
	return ret;
	}
};

add2D<4005,4005>BR,WR;

int main() {

	int N,K;

	cin>>N>>K;

	int i,j;

	for(i=0;i<N;i++){
		char c;
		cin>>x[i]>>y[i]>>c;

		if(c=='W'){W[y[i]%(2*K)][x[i]%(2*K)]++;}
		else{B[y[i]%(2*K)][x[i]%(2*K)]++;}
	}
	for(i=0;i<4*K;i++){
		for(j=0;j<4*K;j++){
		BR.set(j,i,B[i%(2*K)][j%(2*K)]);
		WR.set(j,i,W[i%(2*K)][j%(2*K)]);
		}
	}
	BR.build();
	WR.build();

	int ans=0;

	for(i=0;i<2*K;i++){
		for(j=0;j<2*K;j++){
			int b=BR.get(j,i,j+K-1,i+K-1)+BR.get(j+K,i+K,j+(2*K)-1,i+(2*K)-1);
			int w=WR.get(j+K,i,j+(2*K)-1,i+K-1)+WR.get(j,i+K,j+K-1,i+(2*K)-1);
			if(ans<w+b){ans=w+b;}
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 157696
#!/usr/bin/env python3
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
pre=-1
ans=0
for A in a:
    ans+=b[A-1]
    if pre==A-1:
        ans+=c[A-2]
    pre = A
print(ans)

Measured memory_bytes: 38256
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    grid = []
    3.times do |r|
      grid << gets.split.map(&:to_i)
    end

    n = gets.to_i
    n.times do |i|
      b = gets.to_i
      make_hole(grid, b)
    end
    # print(grid)

    if validate_horizontal(grid) || validate_vertical(grid) || validate_naname(grid)
      puts "Yes"
    else
      puts "No"
    end
  end

  def make_hole(g, x)
    g.each do |r|
      0.upto(2) do |i|
        if r[i] == x
          r[i] = 0
        end
      end
    end
  end

  def validate_horizontal(g)
    # 横
    g.each do |r|
      if r[0] == 0 && r[1] == 0 && r[2] == 0
        return true
      end
    end
    false
  end
  def validate_vertical(g)
    0.upto(2) do |col|
      if g[0][col] == 0 && g[1][col] == 0 && g[2][col] == 0
        return true
      end
    end
    false
  end
  def validate_naname(g)
    if g[0][0] == 0 && g[1][1] == 0 && g[2][2] == 0
      return true
    end
    if g[0][2] == 0 && g[1][1] == 0 && g[2][0] == 0
      return true
    end
    false
  end

  def print(grid)
    grid.each do |row|
      puts row.join(",")
    end
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2172
A = int(input())
B = int(input())
C = int(input())
D = int(input())

count = 0

for x in range(A+1):
    for y in range(B+1):
        for z in range(C+1):
            if x*500 + y*100 + z*50 == D:
                count += 1

print(count)

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

int main(){
  int N;
  cin >> N;
  
  vector <int> A(N);
  vector <int> B(N-1);
  int i;
  
  for(i=0;i<N-1;i++){
    cin >> B[i];
  }
  int sum = 0;
  
  A[0] = B[0];
  A[N-1] = B[N-2];
  
  sum += A[0];
  sum += A[N-1];
  
  
  for(i=1;i<N-1;i++){
    A[i] = min(B[i-1],B[i]);
    sum += A[i];
  }
  
  cout << sum << endl;
  
}

Measured memory_bytes: 256