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

ll func1(ll n,int p){
    if(n==0) return 0;
    return n/p+func1(n/p,p);
}

ll func2(ll n,int p){
    if(n%2) return 0;
    ll r=func1(n/2,p);
    if(p==2) r+=n/2;
    return r;
}

int main(){
    ll n;
    cin>>n;
    cout<<min(func2(n,2),func2(n,5))<<endl;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

const ll MAX_N = 3e6 + 10;
const ll MOD = 1e9+7;
ll Inv[MAX_N];
ll fact[MAX_N];
ll factInv[MAX_N];
void Inv_init(){
    Inv[1] = 1;
    for(int i = 2; i < MAX_N; i++) {
        Inv[i] = Inv[MOD%i] * (MOD - MOD/i) % MOD;
    }
}
void fact_init(){
    fact[0] = fact[1] = factInv[0] = factInv[1] = 1;
    for(int i = 2; i < MAX_N; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        factInv[i] = (factInv[i-1] * Inv[i])%MOD;
    }
}

// a^b % MOD;
ll powmod(ll a,ll b) {ll res=1;a%=MOD; for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
// 逆元 1/a % MOD
ll inversemod(ll a) { return powmod(a,MOD - 2);}

// 1 以上 N 以下の N 個の整数の中から，相異なる K 個の整数を選ぶパターンの数
ll nCr(int n,int r) {
    if(n < r) return 0;
    return (fact[n] * (factInv[r] * factInv[n-r] % MOD)) % MOD;
}
// 1 以上 N 以下の N 個の整数の中から，相異なる K 個の整数を選び，順番に並べるパターンの数
ll nPr(int n,int r){
    if(n < r) return 0;
    return (fact[n]*factInv[n-r])%MOD;
}
// 1 以上 N 以下の N 個の整数の中から，重複を許して K 個の整数を選ぶパターンの数
ll nHr(int n,int r){
    if(n == 0 && r == 0) return 1;
    return nCr(n+r-1,r);
}

void init(){
    Inv_init();
    fact_init();
}


/* 素因数分解 */
void PrimeFact(ll n,map<ll,ll>& mp){
    while(n!=1){
        if(n == 2 || n == 3){
            mp[n]++;
            n/=n;
            continue;
        }
        bool prime_flag = false;
        for(ll i = 2;i*i <= n;i++){
            if(n%i==0){
                mp[i]++;
                n/=i;
                prime_flag = true;
                break;
            }
        }
        if(!prime_flag){mp[n]++; n/= n;}
    }
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    init();
    ll N,M; cin >> N >> M;
    map<ll,ll> mp;
    PrimeFact(M,mp);
    ll ans = 1;
    for(auto p:mp){
        ans *= nHr(N,p.second);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 70528
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<functional>
using namespace std;
#define ll long long int
#define ld long double
using namespace __gnu_pbds;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,
tree_order_statistics_node_update> in_set;
#define rep(n) for(ll i=0;i<(n);i++)
#define jrep(n) for(ll j=0;j<(n);j++)
#define all(a) (a).begin(), (a).end()
#define dpp(a) cout<<(a).first<<" "<<(a).second<<endl;
#define append push_back
#define mod 1000000007
#define ff first
#define ss second
#define ffast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fast ios::sync_with_stdio(0);
ll pw(ll x,ll y,ll p=mod){ll r=1; x=x%p;while(y>0){ if(y&1)r=(r*x)%p;
y=y>>1;x=(x*x)%p;} return r; } vector<ll> uniq(vector<ll> arr)
{vector<ll>brr;sort(all(arr));brr.append(arr[0]);
for(auto i:arr)if(brr.back()!=i)brr.append(i);return brr;}


void solve(){
    string a,b; cin>>a>>b; ll op=0;
    rep(a.size()) if(a[i]!=b[i]) op++; cout<<op<<endl;
}

int main(){
    ffast;
    ll t=1; //cin>>t;
    rep(t) solve();
}


// *p.find_by_order(n) : nth value (0 indexed)
// p.order_of_key(7): index of 7 (0 indexed)

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

#define ll long long
ll mod =1000000007;
ll solve(vector<ll> &v,ll n,ll k){
    ll dp[n+2][k+2];
    for(ll j=0;j<=k;j++){
        dp[1][j]=(j>v[1])? 0 : 1;
    }

    for(ll i=2;i<=n;i++){
        for(ll j=0;j<=k;j++){
            if(j==0)
            dp[i][j]=dp[i-1][j];

            else
            dp[i][j]=(mod+dp[i-1][j]+dp[i][j-1]-((j-v[i]-1>=0)? dp[i-1][j-v[i]-1] : 0))%mod;
        }
    }
return dp[n][k];



}
int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n+1);
    for(ll i=1;i<=n;i++){
        cin>>v[i];
    }
    cout<<solve(v,n,k)<<endl;

    return 0;
}


Measured memory_bytes: 81744
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
	int m,d;
	cin >> m >> d;
	int ans = 0;
	for(int i=1;i<=m;++i)
	{
		for(int j=1;j<=d;j++)
		{
			if((j%10)>=2&&(j/10)>=2)
			if(i==(j%10)*(j/10))
			{
				ans ++ ;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static class State implements Comparable<State> {
		int index;
		long value;
		
		public State (int index, long value) {
			this.index = index;
			this.value = value;
		}
		
		@Override public int compareTo(State o) {
			return Long.compare(this.value, o.value); 
		}
	}
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			PriorityQueue<State> queue = new PriorityQueue<State>();
			for(int i = 0; i < N; i++) {
				queue.add(new State(i, sc.nextLong()));
			}
			
			StringBuilder sb = new StringBuilder();
			boolean first = true;
			
			while(!queue.isEmpty()) {
				sb.append(first ? "" : " ");
				first = false;
				sb.append(queue.poll().index + 1);
			}
			
			System.out.println(sb);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 44204
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
#define MOD 1'000'000'007
using namespace std;
typedef long long ll;
typedef long double ld;

ll N;
ll ans[10001];

int main(){
    cin>>N;

    repn(x,150){
        repn(y,150){
            repn(z,150){
                ll res=x*x+y*y+z*z+x*y+y*z+z*x;
                if(res<=N) ans[res]++;
            }
        }
    }

    repn(i,N) cout<<ans[i]<<endl;
}

Measured memory_bytes: 3692
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>
using namespace std;
using ll=long long;
using R=double;

int a[100003];
int ans[100003];
int find(int x){
	if(a[x] == x)return x;
	else {
		int tmp = find(a[x]);
		a[x] = tmp;
		return tmp;
	}
}

void Union(int x,int y){
	int x_h = find(x);
	int y_h = find(y);

	if(x_h != y_h)a[x_h] = y_h;
}
int main(){
	
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>ans[i];
		a[i] = i;
	}

	int tmp1,tmp2;
	for(int i=0;i<m;i++){
		cin>>tmp1>>tmp2;
		Union(tmp1,tmp2);
	}
	int cnt = 0;
	for(int i=1;i<=n;i++){
		if(find(i)==find(ans[i]))cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<vector<vector<int>>> v3int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef vector<vector<vector<ll>>> v3ll;
typedef list<int> liint;
typedef pair<int, int> pint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, int>> vpll_int;
typedef vector<pair<int, ll>> vpint_ll;
typedef set<pair<int, int>> spint;
typedef set<pair<ll, int>> spll;
typedef unordered_map<int, unordered_set<int>> Graph;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

bool is_ok(vll& SA, vll& SB, ll K, int N, int M, ll X) {
    if (X > ll(N + M)) return false;
    rep(i, X + 1) {
        ll ra = i;
        ll rb = X - i;
        if (ra > N) {
            ra = N;
            rb = X - ra;
            
        }
        if (rb > M) {
            rb = M;
            ra = X - rb;
        }
        ///cout << ra + rb << " " << X << endl;
        if (SA[ra] + SB[rb] <= K) return true;
    }
    return false;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, M;
    ll K;
    cin >> N >> M >> K;
    deque<ll> A(N), B(M);
    rep(i, N) cin >> A[i];
    rep(i, M) cin >> B[i];
    ll ans = 0;

    vll SA(N + 1);
    rep(i, N) SA[i + 1] = SA[i] + A[i];
    vll SB(M + 1);
    rep(i, M) SB[i + 1] = SB[i] + B[i];

    int l = 0, r = N + M + 1;
    while (r - l > 1) {
        int m = (r + l) / 2;
        if (is_ok(SA, SB, K, N, M, m) == true) {
            l = m;
        }
        else {
            r = m;
        }
    }
    ans = l;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9468
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	string s[110];
	int n,m;
	cin>>n>>m;
	REP(i,n){
		cin>>s[i];
	}
	sort(s,s+n);
	REP(i,n){
		cout<<s[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
n,a,b,c=map(int,input().split())
l=[int(input()) for _ in range(n)]
def func(g):
  if len(g[0])==0 or len(g[1])==0 or len(g[2])==0:return -1
  ret=0
  ret+=10*(len(g[0])-1)
  ret+=10*(len(g[1])-1)
  ret+=10*(len(g[2])-1)
  a_=sum([l[i] for i in g[0]])
  b_=sum([l[i] for i in g[1]])
  c_=sum([l[i] for i in g[2]])
  ret+=abs(a-a_)
  ret+=abs(b-b_)
  ret+=abs(c-c_)
  return ret
m=n*2
ans=pow(10,9)
for i in range(2**m):
  g=[[]for _ in range(4)]
  for j in range(n):
    g[(i//pow(4,j))%4].append(j)
  tmp=func(g)
  if tmp>=0:
    ans=min(ans,tmp)

print(ans)


Measured memory_bytes: 3188
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
#define MN 200005
using namespace std;
inline ll in(){
    ll x=0;bool f=0; char c;
    for (;(c=getchar())<'0'||c>'9';f=c=='-');
    for (x=c-'0';(c=getchar())>='0'&&c<='9';x=(x<<3)+(x<<1)+c-'0');
    return f?-x:x;
}
char s[MN];
ll sum[MN],len,res=0ll;
int main()
{
	scanf("%s",s);len=strlen(s);
	for (int i=0;i<len;++i) ++sum[s[i]-'a'];
	for (int i=0;i<26;++i) res+=1ll*sum[i]*(sum[i]-1ll);  
	printf("%lld",((len*(len-1ll)-res)>>1ll)+1ll);return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
const int sz = 1e5+1;
ll mod=1e9+7;


 
bool cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    if(a.first==b.first)
    {
        return a.second<b.second;
    }
    else
    {
        return a.first>b.first;
    }
}
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int t;
    t=1;
    // cin>>t;
    //sieve();
    for(int cs=1;cs<=t;cs++)
    {
        
        ll n,m,k;
        cin>>n>>m>>k;
        vector<ll> sum1(n+1,0),sum2(m+1,0);
        for(int i=1;i<=n;i++)
        {
            ll x;
            cin>>x;
            sum1[i]=sum1[i-1]+x;
        }
        for(int i=1;i<=m;i++)
        {
            ll x;
            cin>>x;
            sum2[i]=sum2[i-1]+x;
        }
        ll res = 0;
        for(int i=0;i<=n;i++)
        {
            ll left = k - sum1[i];
            if(left<0)
                break;
            ll pos = lower_bound(sum2.begin(),sum2.end(),left)-sum2.begin();
            if(pos>m or sum2[pos]>left)
                pos--;
            res = max(res,i+pos);

        }

        cout<<res<<endl;

 
 
 
    }
    return 0;
} 

Measured memory_bytes: 6364
//============================================================================
// Author       : Sun YaoFeng
//============================================================================

//#pragma 	comment(linker, "/STACK:100240000,100240000")
//#include	<cstdio>
//#include	<cstdlib>
//#include	<cstring>
//#include	<algorithm>

#include	<bits/stdc++.h>

using	namespace	std;

#define DB		double
#define	lf		else if
#define I64		long long
#define	Rd()	(rand()<<15|rand())
#define For(i,a,b)	for(int i=a,lim=b;i<=lim;i++)
#define Rep(i,a,b)	for(int i=a,lim=b;i>=lim;i--)

#define	fi	first
#define se	second
#define MK	make_pair
#define pb	push_back
#define PA	pair<int, int>

//#define	min(a,b)	((a)<(b)?(a):(b))
//#define	max(a,b)	((a)<(b)?(b):(a))

#define	CH	(ch=getchar())
int		IN()	{
		int x= 0, f= 0, ch;
		for	(; CH < '0' || ch > '9';)	f= (ch == '-');
		for	(; ch >= '0' && ch <= '9'; CH)	x= x*10 + ch -'0';
		return	f? -x : x;
}

#define n	505

int		N, cnt, wei[n];

char	s[n][n];

int		main(int argc, char* argv[]){
	//	freopen("B.in", "r", stdin);
	//	freopen("B.out", "w", stdout);
	
		N= IN();
		For(i, 1, N)	{
			scanf("%s", s[i] + 1);
			For(j, 1, N)	{
				cnt+= s[i][j] == '#';
				if	(s[i][j] == '#')	wei[j]= 1;
			}
		}
		
		if	(cnt == 0)	return	puts("-1"), 0;
		if	(cnt == N*N)	return	puts("0"), 0;
		
		int	gtw= 0;
		For(j, 1, N)	{
			int t= 0;
			For(i, 1, N)	if	(s[i][j] == '.')	t= 1;
			gtw+= t;
		}
		
		int	Ans= 1 << 30;
		For(i, 1, N)	{
			int	t= gtw;
			For(j, 1, N)	t+= s[i][j] == '.';
			
			if	(! wei[i])	t++;
			Ans= min(Ans, t);
		}
		
		printf("%d\n", Ans);
		
		return	0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;

signed main() {
	int a, b;
	cin >> a >> b;
	cout << (a - 1) * (b - 1) << endl;
	return 0;
}

Measured memory_bytes: 256
tiles = list(map(int, input()))
# inputs = "10010010"
# tiles = list(map(int, inputs))


def count_repaint_tiles(tiles):
    if len(tiles) == 0:
        return 0
    counts = 0
    color = tiles[0]
    for tile in tiles[1:]:
        if tile == color:
            counts = counts + 1
        color = 1 - color
    return counts


print(count_repaint_tiles(tiles))


Measured memory_bytes: 4640
#include<bits/stdc++.h>
using namespace std;
int h[100005];
int dp[100005];
int func(int i,int n,int k)
{
    if(i==n)
        return 0;
    if(dp[i]!=INT_MAX)
        return dp[i];
    int ans=INT_MAX;
    int ansi;
    for(int j=1;j<=k;j++)
    {   if(i+j<=n)
        {
            ansi=abs(h[i]-h[i+j]);
            ansi+=func(i+j,n,k);
            ans=min(ansi,ans);
        }
    }
    dp[i]=ans;
    return dp[i];
}

int main()
{   int n,k;
    cin>>n>>k;
    fill(dp,dp+n,INT_MAX);
    for (int i = 1; i <= n ; i++) {
        cin>>h[i];
    }
    cout<<func(1,n,k);
   
   
}

Measured memory_bytes: 8832
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
using namespace std;
#define MATH_PI 3.14159265358979323846
string strReverse(string strOrigin){
	if (strOrigin.length() == 0){
		return "";
	}
	long long i;
	string ans;
	for (i = strOrigin.length() - 1; i >= 0; --i) ans += strOrigin[i];
	return ans;
}
int main(){
	string sInput;
	cin >> sInput;
	if (strReverse(sInput)==sInput)
		cout << "Yes\n";
	else
		cout << "No\n";
	//system("pause > nul");
	return 0;
}


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

using namespace std;

#define ll long long int

int main()
{
	ll a,b,c,d;
	cin >> a >> b;
	vector<ll> v,w;
	for(ll i=0;i<a;i++)
	{
		cin >> c;
		w.push_back(c);
		cin >> c;
		v.push_back(c);
	}
	ll ve[b+1][a+1];
	ve[0][0]=0;
	for(ll i=1;i<=b;i++)
	{
		ve[i][0]=0;
	}
	for(ll i=1;i<=b;i++)
	{
		ve[0][i]=0;
	}
	for(ll i=1;i<=b;i++)
	{
		for(ll j=1;j<=a;j++)
		{
			if(i>=w[j-1])
			{
				ve[i][j]=max(v[j-1]+ve[i-w[j-1]][j-1],ve[i][j-1]);
			}
			else
			{
				ve[i][j]=ve[i][j-1];
			}
		}
	}
	cout << ve[b][a];
}

Measured memory_bytes: 79104
import java.util.Scanner;

 
public class Main {
 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int N = sc.nextInt();
		
		for(int i = 0; i < N; i++) {
			H = H - sc.nextInt();
		}

		if(H <= 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		sc.close();
	}
	
}

Measured memory_bytes: 47288
#include <iostream>
using namespace std;
typedef long long ll;
int N;
ll dp[3010][3010] = {},A[3010];

int main(){
	cin >> N;
	for(int i=1;i<=N;i++){
		cin >> A[i];
		dp[i][i] = A[i];
		if(N%2==0) dp[i][i] *= -1;
	}
	for(int i=1;i<=N-1;i++){
		for(int j=1;j<=N-i;j++){
			if((N-i)%2==1){
				dp[j][j+i] = max(dp[j][j+i-1]+A[j+i],dp[j+1][j+i]+A[j]);
			}else{
				dp[j][j+i] = min(dp[j][j+i-1]-A[j+i],dp[j+1][j+i]-A[j]);
			}
		}
	}
	cout << dp[1][N] << endl;
}

Measured memory_bytes: 70016
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

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

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

int main() {
	int A,B,C,K;
    cin >> A >> B >> C >> K;
  
  	int maximum = max(A,max(B,C));
  
  	for(int i = 0; i < K; i++) {
    	maximum *= 2;
    }
  
  	cout << A + B + C - max(A,max(B,C)) + maximum << endl;
}

Measured memory_bytes: 256
while (ln = gets.chomp) != '0 0'
  h, w = ln.split.map(&:to_i)

  h.times do |i|
    fmt = '#.'
    fmt = '.#' if i % 2 > 0
    s = fmt * (w.to_f / 2).ceil
    s = s[0, s.length-1] if w.to_f % 2 > 0
    puts s
  end

  puts
end

Measured memory_bytes: 6128
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MOD = 998244353;

int n;
int dat[100005];

int main()
{
	scanf("%d", &n);
	rep(i, n) scanf("%d", &dat[i]);
	
	sort(dat, dat + n);
	
	int pos = 1;
	for(; pos < n - 1; pos ++) if(dat[pos] > 0) break;
	
	int ret = 0;
	rep(i, pos) ret -= dat[i];
	for(int i = pos; i < n; i ++) ret += dat[i]; 
	printf("%d\n", ret);
	
	for(int i = 1; i < pos; i ++) {
		printf("%d %d\n", dat[pos], dat[i]);
		dat[pos] -= dat[i];
	}
	
	for(int i = pos + 1; i < n; i ++) {
		printf("%d %d\n", dat[0], dat[i]);
		dat[0] -= dat[i];
	}
	
	printf("%d %d\n", dat[pos], dat[0]);
	return 0;
}

Measured memory_bytes: 2304
n, m = map(int,input().split())

cnt = [ 0  for i in range(m) ]

for i in range(n):
    a = [ int(i) for i in input().split() ]
    for j in range(1,len(a)):
        cnt[a[j]-1]+=1

ans = 0
for i in cnt:
    if i == n:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;
long long int d[200][200] = {},n;


void dijkstra() {
	
	for (int k = 1; k <= n; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}


int main() {
	complex<long double>cmpmp;
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	string str,str2,tmp;
	//cout << fixed << setprecision(10);
	long long int res = 0, y, id = 0, m = 0, a[2000], b[2000], c[2000], x, k, ng[2000] = {}, left = 0, dp[100][3] = {};
	cin >>n>> m;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (i != j) { d[i][j] = 9999999999; }
		}
	}

	for (int i = 0; i < m; i++) {
		cin >> a[i]>>b[i]>>c[i];
		d[a[i]][b[i]] = c[i];
		d[b[i]][a[i]] = c[i];
	}

	dijkstra();



	for (int k = 0; k < m; k++) {
		for (int i = 1; i <= n; i++) {
			for (int j = i+1; j <= n; j++) {
				if (d[i][j] == c[k] + d[i][a[k]]+d[b[k]][j]) { ng[k] = 1;
				}
				if (d[i][j] == c[k] + d[i][b[k]] + d[a[k]][j]) {
					ng[k] = 1;
				}
			}
		}
	}
	id = m;
	for (int k = 0; k < m; k++) {
		if (ng[k] == 1) { id--; }
	}

	cout << id << endl;
} 


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 2 * 1e5 + 5;
const ll mod = 998244353;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int pre[N];
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    int n, m;
    cin >> n;
    fore(i, 1, n){
        cin >> m;
        pre[m]++;
    }
    fore(i, 1, n + 1)
        cout << pre[i] << '\n';
    return 0;
}   

Measured memory_bytes: 4404
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<std::vector<int>> p(N);
  for (int n = 0; n < N; ++n) {
    int K;
    std::cin >> K;
    p[n].resize(K);
    for (int k = 0; k < K; ++k) {
      std::cin >> p[n][k];
    }
  }

  std::vector<int> sum(M, 0);
  std::for_each(p.begin(), p.end(), [&sum](const auto& v) {
    std::for_each(v.begin(), v.end(), [&sum](const auto i) { ++sum[i - 1]; });
  });

  int count =
      std::count_if(sum.begin(), sum.end(), [N](int c) { return c == N; });
  std::cout << count << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    int H, W, A, B;
    cin >> H >> W >> A >> B;

    rep(i, H) {
        rep(j, W) {
            int s;
            if (j < A) {
                if (i < B) {
                    s = 0;
                }
                else {
                    s = 1;
                }
            }
            else {
                if (i < B) {
                    s = 1;
                }
                else {
                    s = 0;
                }
            }
            cout << s;
        }
        cout << endl;
    }
    return 0;
}

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

int main()
{
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    for (int i = 0; i <= a; i++)
    {
        for (int j = 0; j <= b; j++)
        {
            for (int k = 0; k <= c; k++)
            {
                if (500 * i + 100 * j + 50 * k == x)
                {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  if (abs(a-c) <= d) {
    cout << "Yes" << endl;
  } else if (abs(a-b)<=d && abs(b-c)<=d) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>

using namespace std;

void solve(int N, int K, vector<int> v) {
  int ans = 0;
  for (int l = 0; l <= K; l++) {
    for (int r = 0; r <= K - l; r++) {
      if (l + r > N) {
        continue;
      }
      int d = K - l - r;
      int cur = 0;
      vector<int> vv;
      for (int i = 0; i < l; i++) {
        cur += v[i];
        vv.emplace_back(v[i]);
      }
      for (int i = N - r; i < N; i++) {
        cur += v[i];
        vv.emplace_back(v[i]);
      }
      sort(vv.begin(), vv.end());
      for (int i = 0; i < d; i++) {
        if (i >= vv.size()) {
          break;
        }
        if (vv[i] < 0) {
          cur -= vv[i];
        }
      }
      ans = max(ans, cur);
    }
  }
  printf("%d\n", ans);
}

int main() {
  int N, K;
  scanf("%d %d", &N, &K);
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  solve(N, K, v);
  return 0;
}

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

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define REP(i,n) for(ll i = 1; i < (n); i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pll = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  int x;
  cin >> x;
  int a = x / 500;
  x -= 500*a;
  int b = x / 5;
  ll ans = a * 1000 + b * 5;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;
void solve(){
    ll n,m,k;
    cin>>n>>m>>k;
    vector<ll>arr(n),brr(m);
    for(int i=0;i<n;++i){
        cin>>arr[i];
        if(i) arr[i]+=arr[i-1];
    }
    for(int i=0;i<m;++i){
        cin>>brr[i];
        if(i) brr[i]+=brr[i-1];
    }
    int book=upper_bound(brr.begin(),brr.end(),k)-brr.begin();

    for(int i=0;i<n;++i){
        if(arr[i]>k)break;

        int j = upper_bound(brr.begin(),brr.end(),k-arr[i])-brr.begin();
            book=max(book,i+j+1);
    }
    cout<<book<<endl;
}

int main()
{
    fast;
    int t;
    solve();
}





Measured memory_bytes: 6372
import bisect
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
L = list(map(int, input().split()))
L = sorted(L)
sum_L = sum(L)
N_neg = bisect.bisect_left(L, 0)
process = []
if N_neg == 0:  # minのみ-にする
    ans = sum_L-min(L)*2
    l = min(L)
    for r in L[1:-1]:
        process.append(str(l)+" "+str(r))
        l -= r
    process.append(str(L[-1])+" "+str(l))
elif N_neg == N:  # maxのみを+にする
    ans = -sum_L+max(L)*2
    l = L[-1]
    for r in reversed(L[:-1]):
        process.append(str(l)+" "+str(r))
        l -= r
else:  # negのやつを-にする
    ans = sum([abs(v) for v in L])
    l = L[0]
    for r in L[N_neg:-1]:
        process.append(str(l)+" "+str(r))
        l -= r
    process.append(str(L[-1])+" "+str(l))
    l = L[-1]-l
    for r in L[1:N_neg]:
        process.append(str(l)+" "+str(r))
        l -= r
print(ans)
print("\n".join(process))


Measured memory_bytes: 20616
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<ll, ll> P;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n;
  cin >> n;
  
  int dp[n][n];
  bool space[n][n];
  rep(i,n){
    rep(j,n){
      dp[i][j] = min(min(i,j), min(n-1-i,n-1-j));
      space[i][j] = false;
    }
  }
  
  int ans = 0;
  rep(i,n*n){
    int p;
    cin >> p;
    p--;
    int sy = p/n;
    int sx = p%n;
    ans += dp[sy][sx];
    space[sy][sx] = true;
    
    queue<P>que;
    que.push(P(sy,sx));

    while(!que.empty()){
      auto t = que.front();
      que.pop();
      int y = t.first, x = t.second;
      int cost = space[y][x] ? 0 : 1;
      rep(i,4){
        int ny = y + dy[i];
        int nx = x + dx[i];
        if(ny < 0 || ny >= n || nx < 0 || nx >= n)continue;
        if(dp[ny][nx] > dp[y][x]+cost){
          dp[ny][nx] = dp[y][x]+cost;
          que.push(P(ny,nx));
        }
      }
    }
  }
  
  cout << ans << endl;
  return 0;     
}


Measured memory_bytes: 4764
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n,m;
	cin>>n>>m;
	vector<string>a(n),b(m);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<m;i++){
		cin>>b[i];
	}
	for(int i=0;i+m<=n;i++){
		for(int j=0;j+m<=n;j++){
			bool ok=true;
			for(int ii=0;ii<m;ii++){
				for(int jj=0;jj<m;jj++){
					if(a[i+ii][j+jj]!=b[ii][jj]) {
						ok=false;
					}
				}
			}
			if(ok){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}


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

#define ll long long

ll n, x;

ll rec(ll b, ll a){
	if(a == 0 || b == 0)
		return -(a + b);
	ll c = b / a;
	return 2LL * c * a + rec(a, b % a);	
}

int main(){
	cin >> n >> x;
	cout << n + rec(n - x, x);
	return 0;
}

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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define SORT(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> p;

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


Measured memory_bytes: 256
from sys import setrecursionlimit

setrecursionlimit(10 ** 9)

dir_h = [1, -1, 0, 0, 1, -1, -1, 1]
dir_w = [1, -1, 1, -1, 0, 0, 1, -1]


def dfs(i, j):

    if i < 0 or i >= h or j < 0 or j >= w:
        return

    if field[i][j] == 0 or seen[i][j] != 0:
        return

    seen[i][j] = 1

    for dh, dw in zip(dir_h, dir_w):
        nh = i + dh
        nw = j + dw

        dfs(nh, nw)


while True:
    w, h = map(int, input().split())

    if h == 0 and w == 0:
        break

    field = [list(map(int, input().split())) for _ in range(h)]
    seen = [[0 for _ in range(w)] for _ in range(h)]
    cnt = 0

    for i in range(h):
        for j in range(w):

            if field[i][j] == 0 or seen[i][j] != 0:
                continue

            cnt += 1
            dfs(i, j)

    print(cnt)



Measured memory_bytes: 7044
fn main() {
    use std::io;
    let mut input = String::new();
    let _ = io::stdin().read_line(&mut input);
    let inputs = input.trim()
        .split_whitespace()
        .map(|x| x.parse::<isize>().unwrap())
        .collect::<Vec<isize>>();
    let num = inputs[1] * 10 + inputs[2];
    if num % 4 == 0 {
        println!("YES");
    } else {
        println!("NO");
    }
}

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

int main(){
    int n;
    cin >> n;
    long long int a[n];
    long long int t[n];
    for(int i = 0; i < n; i++){
        cin >> t[i] >> a[i];
    }
    for(int i = 0; i < n-1; i++){
        if(t[i] > t[i+1] || a[i] > a[i+1]){
            for(long long int j = max(t[i]/t[i+1], a[i]/a[i+1]);;j++){
                if(t[i] <= t[i+1]*j && a[i] <= a[i+1]*j){
                    t[i+1] = t[i+1]*j; a[i+1] = a[i+1]*j;
                    break;
                }
            }
        }
    }
    cout << t[n-1] + a[n-1] << endl;
}

Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l(): #intのlist
	return list(map(int,input().split()))
def m(): #複数文字
	return map(int,input().split())
def onem(): #Nとかの取得
	return int(input())
def s(x): #圧縮
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x): #listをスペースごとに分ける
	return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
	return max(map(max,x))

n = onem()

a = l()

b = l()

co = 0

if a[0] <= b[0]:
	co += a[0]
	nokori = b[0] - a[0]
	a[0] = 0
else:
	nokori = 0
	co = b[0]


for i in range(1,n):
	if nokori >= a[i]:
		co += a[i]
		nokori = b[i]
	else:
		if nokori + b[i] >= a[i]:
			co += a[i]
			nokori = b[i] + nokori - a[i]
		else:
			co += b[i] + nokori
			nokori = 0

if nokori >= a[-1]:
	co += a[-1]
else:
	co += nokori

print(co)











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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

const int N = int(1e5) + 2;
const int LG = 20;
const ll mod = 998244353;
const int INF = 2147483647;
const ll linf = 1e18;
const ld pi = acos(-1);
const ld EPS = 1e-10;

int n, k;
string s;
int main (){
    cin >> n >> k >> s;
    int id1 = 0, id2 = 0;
    for (int i = 0; i < sz(s); ++i){
        if (s[i] == '0'){
            id2 = i;
            break;
        }
    }
    for (int i = 1; i <= k; ++i){
        int kek = 0;
        while (id2 < n && s[id2] == '0') id2++;
        while (id2 < n && s[id2] == '1') id2++;
    }
    int ans = id2;
    while (id2 < n){
        while (s[id1] == '1') id1++;
        while (s[id1] == '0') id1++;
        while (id2 < n && s[id2] == '0') id2++;
        while (id2 < n && s[id2] == '1') id2++;
        ans = max(ans, id2 - id1);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int A, B, C, X, Y;
	cin >> A >> B >> C >> X >> Y;

	int s = min(A + B, C * 2);
	int a, b;
	a = s * min(X, Y);
	b = 0;

	if (X > Y) {
		b = (X - Y) * min(A, C * 2);
	}
	else if (X < Y) {
		b = (Y - X) * min(B, C * 2);
	}

	cout << a + b << endl;
}

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

int main()
{
     int n, num, digit, rev = 0;
     cin >> num;

     n = num;

     do
     {
         digit = num % 10;
         rev = (rev * 10) + digit;
         num = num / 10;
     } while (num != 0);


     if (n == rev)
         cout << "Yes";
     else
         cout << "No";

    return 0;
}

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

constexpr int MAX_N = 300;

int N;
std::string col[MAX_N];
std::string row[MAX_N];

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

	std::cin >> N;

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

	for(int i = 0; i < N; ++i){
		for(int j = 0; j < N; ++j){
			row[i] += col[j][i];
		}
		row[i] = row[i] + row[i];
	}

	int ans = 0;
	int memo[MAX_N * 2][MAX_N * 2] = {}; //0:Unknown 1:OK 2:NG
	for(int i = 0; i < N; ++i){
		for(int j = 0; j < N; ++j){
			bool flag = true;
			for(int k = 0; k < N; ++k){
				if(memo[i + k][j + k] == 1){
					continue;
				}
				if(memo[i + k][j + k] == 2){
					flag = false;
					break;
				}
				if(col[(k + j) % N].substr(i, N) != row[(k + i) % N].substr(j, N)){
					memo[i + k][j + k] = 2;
					flag = false;
					break;
				}
				memo[i + k][j + k] = 1;
			}
			if(flag){
				++ans;
			}
		}
	}

	std::cout << ans << std::endl;

	return 0;
}


Measured memory_bytes: 2296
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>
#include <math.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

int main()
{
    ll n, m, k;
    cin >> n >> m >> k;
    rep(i,n+1){
        rep(j,m+1){
            ll x = n * j + m * i - 2 * i * j;
            if (x==k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#define MOD 1000000007
using namespace std;
int main()
{
	int cnt;
	int x[200];
	bool flg = true;
	cin >> cnt;
	for (size_t i = 0; i < cnt; i++)
	{
		cin >> x[i];
	}
	for (size_t i = 0; i < cnt; i++)
	{
		if (~x[i] & 1) {
			if (x[i] % 3 == 0 || x[i] % 5 == 0) {
			}
			else {
				flg = false;
			}
		}
	}
	
	if (flg) {
		cout << "APPROVED" << endl;
	}
	else {
		cout << "DENIED" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <typeinfo>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define vi vector<int>
#define pb push_back

const int INF = 100000001;

int n;
vi p;

int main(){
    //FILE* fp_in = freopen("input.txt","r",stdin);
    cin >> n;
    p.pb(-1);
    FOR(i,1,n+1){
        int in;
        cin >> in;
        p.pb(in);
    }
    int ans = 0;
    int renzo = 0;
    FOR(i,1,n+1){
        if(i == p[i]){
            renzo++;
        }
        else{
            ans += renzo/2 + renzo%2;
            renzo = 0;
        }
        // cout << i << " "<< p[i] <<"   " << ans << " " << renzo << endl;
    }
    ans += renzo/2 + renzo%2;
    cout << ans << endl;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string N;
  cin >> N;
  if (N[0] == '9' || N[1] == '9') {
    print("Yes");
  } else {
    print("No");
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if(a[0]==5&&a[1]==5&&a[2]==7)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;

}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  int ans = 0;
  for (int i = 0; i < n; i+=2) ans += a[i];
  for (int i = 1; i < n; i+=2) ans -= a[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 504
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cmath>
#include<map>
#include<sstream>
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define down(i,l,r) for (int i=l;i>=r;i--)
#define clr(x,y) memset(x,y,sizeof(x))
#define maxn 500500
#define inf 1152921504606846976
#define ll long long
#define mm 1000000007
#define eps 1e-9
#define low(x) x&(-x)
#define pb push_back
#define PII pair<int,int>
using namespace std;

ll read(){
    ll x=0,f=1; char ch=getchar();
    while (!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-'0'; ch=getchar();}
    return x*f;
}
int s[maxn],tot,n,m,head[maxn];
struct data{int obj,pre;
}e[maxn*2];
void insert(int x,int y){
	e[++tot].obj=y;	 e[tot].pre=head[x]; head[x]=tot;
}
void dfs(int u){
	if (s[u]==3) return;
	for (int j=head[u];j;j=e[j].pre){
		int v=e[j].obj;
		if (!s[v]) s[v]=s[u]+1,dfs(v);
	}
}
int main(){
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);
	n=read(); m=read();
	rep(i,1,m) {
		int x=read(),y=read();
		insert(x,y); insert(y,x);
	}
	s[1]=1;
	dfs(1);
	if (s[n]) puts("POSSIBLE");
	else puts("IMPOSSIBLE");
    return 0;
}

Measured memory_bytes: 8704
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#define int long long
#define endl '\n'
typedef long long ll;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,a,b;
	cin >> n >> a >> b;
	if(a > n || b > n) {
		cout << -1;
		return 0;
	}
	if(a+b-1 > n) {
		cout << -1;
		return 0;
	}
	if((n+a-1)/a > b) {
		cout << -1;
		return 0;
	}
	vector<int> res(n);
	int low = 1;
	int tempN = n;
	while(n-tempN + (tempN+a-1)/a < b) {
		res[tempN-1] = low++;
		--tempN;
	}

	int mnUsed = n+1;
	int pos = 0;
	//cout << "mnUsed: " << mnUsed << endl;
	for(int i = 0; i < tempN; i += a) {
		int len = min(a,tempN-i);
		int startVal = mnUsed - len;
		mnUsed -= len;
		for(int j = i; j < i+a && j < tempN; ++j) {
			res[j] = startVal++;
		}
	}



	for(int val : res) cout << val << " ";
	cout << endl;
}


Measured memory_bytes: 5464