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

using namespace std;

typedef long long ll;

const ll MAXV = (ll)((1 << 18) + 10);

int A[MAXV];

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

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

	int ans = A[0] + A[1];
	printf("%d\n", ans);
	for(int mask = 2;mask < (1 << n);mask ++){
		int a = 0, b = 0;
		for(int submask = mask;submask * 2 > mask;submask = (submask - 1) & mask){
			if(A[submask] > a)
				b = a, a = A[submask];
			else if(A[submask] > b)
				b = A[submask];
			if(A[submask ^ mask] > a)
				b = a, a = A[submask ^ mask];
			else if(A[submask ^ mask] > b)
				b = A[submask ^ mask];
		}

		ans = max(ans, a + b);
		cout << ans << "\n";
	}

	return 0;
}


Measured memory_bytes: 4224
#include <stdio.h>
#include <set>

using namespace std;

int main(){
  while (1){

    set<int> s;

    int n[5];
    for(int i=0;i<5;i++){
      scanf("%d", n+i);
      if(n[i]==0) return 0;
      s.insert(n[i]);
    }

    if(s.size() == 2){
      if(s.find(1) != s.end()){
        if(s.find(2) != s.end()){
          for(int i=0;i<5;i++) printf("%d\n", (n[i] == 1)? 1:2);
        }else {
          for(int i=0;i<5;i++) printf("%d\n", (n[i] == 1)? 2:1);
        }
      }else {
        for(int i=0;i<5;i++) printf("%d\n", (n[i] == 2)? 1:2);
      }
    }else {
      for(int i=0;i<5;i++) puts("3");
    }

  }
}

Measured memory_bytes: 0
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String[] s = new String[N];
		for(int i = 0;i < N;++i)
			s[i] = sc.next();
		int M = sc.nextInt();
		String[] t = new String[M];
		for(int i = 0;i < M;++i)
			t[i] = sc.next();
		sc.close();
		
		Map<String, Integer> sMap = new HashMap<>();
		for(int i = 0;i < N;++i) {
			if(sMap.containsKey(s[i])) {
				Integer cap = sMap.get(s[i]) + 1;
				sMap.remove(s[i]);
				sMap.put(s[i], cap);
			} else {
				sMap.put(s[i], 1);
			}
		}
		Map<String, Integer> tMap = new HashMap<>();
		for(int i = 0;i < M;++i) {
			if(tMap.containsKey(t[i])) {
				Integer cap = tMap.get(t[i]) + 1;
				tMap.remove(t[i]);
				tMap.put(t[i], cap);
			} else {
				tMap.put(t[i], 1);
			}
		}
		
		int ans = 0;
		for(String key : sMap.keySet()) {
			if(tMap.containsKey(key)) {
				if(ans < sMap.get(key) - tMap.get(key))
					ans = sMap.get(key) - tMap.get(key);
			} else {
				if(sMap.get(key) > ans)
					ans = sMap.get(key);
			}
		}
		System.out.println(ans);
	}
}


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

int dp[5005][5005];

int main(){
    int n;
    string s;
    cin>>n>>s;
    for(int i=n-2; i>=0; --i){
        for(int j=n-1; j>=i+1; --j){
            if(s[i]==s[j])dp[i][j]=dp[i+1][j+1]+1;
            else dp[i][j]=0;
        }
    }
    int ans=0;
    rep(i,n)rep(j,n)ans=max(ans,min(dp[i][j],j-i));
    cout<<ans<<endl;
}

Measured memory_bytes: 70304
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,x,y) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok, flag;
ll dx[5] = { 1,-1,0,0,0 }, dy[5] = { 0,0,1,-1,0 };
ll ddx[9] = { 1,-1,0,0,1,1,-1,-1,0 }, ddy[9] = { 0,0,1,-1,1,-1,1,-1,0 };
#pragma endregion
#define MAX 111111

int main(void) {
  cin >> n >> m;
  vll a, b;
  rep(i, n) {
	scan(tmp);
	if (tmp >= 0) a.pb(tmp);
	else b.pb(-tmp);
  }
  reverse(all(b));
  while (a.size() < m)a.pb(inf);
  while (b.size() < m)b.pb(inf);
  ans = inf;
  ans = a[m - 1];
  ans = min(ans, b[m - 1]);

  rep(i, a.size() - 1) {
	if (m - i - 2 < 0) break;
	ans = min(ans, 2 * a[i] + b[m - i - 2]);
	ans = min(ans, a[i] + 2 * b[m - i - 2]);
  }

  cout << ans << endl;

  return 0;
}

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

int main()
{
	int ans=1,a[15],n,i,tmp=1;
	cin >> n;
	for(i=0;i<n;i++)
		cin >> a[i],ans*=3;
	for(i=0;i<n;i++)
		if(a[i]%2==0) tmp*=2;
	cout << ans-tmp << "\n";
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    vector<string> s(3);
    REP(i, 3) cin >> s[i];
    int i = 0;
    while(1){
        if(s[i].length() == 0){
            cout << (char)('A' + i) << endl;
            break;
        }
        int next = s[i][0] - 'a';
        s[i].erase(s[i].begin());
        i = next;
    }
    return 0;
}


Measured memory_bytes: 256
def solve(T, n):
    def judge(x):
        return True if 0 <= x < n else False

    for i in range(n):
        print("node " + str(i + 1) + ": ", end = "")
        print("key = " + str(T[i]) + ", ", end = "")
        if judge(int((i + 1) / 2) - 1):
            print("parent key = " + str(T[int((i+1)/2)-1]) + ", ", end = "")
        if judge(2 * i + 1):
            print("left key = " + str(T[2*i+1]) + ", ", end = "")
        if judge(2 * i + 2):
            print("right key = " + str(T[2*i+2]) + ", ", end = "")
        print("")
    return

n = int(input())
T = list(map(int, input().split(" ")))
solve(T, n)


Measured memory_bytes: 5720
n = int(input())
a = [int(input()) for i in range(n)]
l = [0]*n
num = 0

for i in a:
    l[num] += 1
    if l[1] == 1:
        print(sum(l)-1)
        break
    else:
        num = a[num]-1
        if l[num] == 2:
            print(-1)
            exit()

Measured memory_bytes: 7852
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			double W = scan.nextDouble();
			double H = scan.nextDouble();
			double x = scan.nextDouble();
			double y = scan.nextDouble();
			
			
			if(x==W/2.0&&y==H/2.0) {
				System.out.println(H*W/2);
				System.out.println(1);
			}else{
				System.out.println(H*W/2);
				System.out.println(0);
			}
				
			/*
				double cx =W/2.0; 
				double cy =H/2.0; 
				
				if(x==cx||y==cy||y==(H/W)*x||y==(-H/W)*x+H) {
					
				}else {
					double a = (y-cy)/(x-cx);
					
					
					
				}
				
				
				
				double jyou = cy-a*cx;
				double kate = a*(double)W+cy-a*cx;
				System.out.println((jyou+kate)*(double)W/2.0);
				System.out.println(0);*/
				
			
			
			
			
			
			
			
		}
		
		
	}
		

}


Measured memory_bytes: 23124
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cmath>
#define N 200005
using namespace std;
int Rank,n,l,t;
int x[N],w[N],e[N];
int main()
{
	scanf("%d%d%d",&n,&l,&t);
	Rank=0;
	for (int i=0;i<n;i++)
	{
		scanf("%d%d",&x[i],&w[i]);
		e[i]=x[i]+((w[i]==1)?1:-1)*t;
		e[i]%=l;
		e[i]=(e[i]+l)%l;
		if (w[i]==1)
			Rank+=(x[i]+t)/l; else
			Rank-=(l-x[i]-1+t)/l;
		Rank=(Rank%n+n)%n;
	}
	sort(e,e+n);
	for (int i=Rank;i<n;i++)
		printf("%d\n",e[i]);
	for (int i=0;i<Rank;i++)
		printf("%d\n",e[i]);
	return 0;
}

Measured memory_bytes: 4804
#include <cstdio>
#include <cstring>
inline void read(int &k)
{
	register int f=1,c=getchar();k=0;
	while (c<'0'||c<'9')c=='-'&&(f=-1),c=getchar();
	while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
	k*=f;
}
char s[23333];
int main()
{
	scanf("%s",s);
	for (int i=0;i<strlen(s)-8;i++)printf("%c",s[i]);
}

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

int main() {
    int     N;
    int     sum = 0;
    
    cin >> N;
    
    for ( int ii = 1; ii <= N; ii++ ) {
        sum += ii;
    }
    
    cout << sum << endl;
    return 0;
}

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

int main(){
    int N,K;
    int sum;
    int i;
    cin >> N >> K;
    
    if (N==1){
        cout << K << endl;
    }
    else if (N>1){
        sum = K;
        for (i=0; i<N-1; i++){
            sum = sum * (K-1);
        }

        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 256
from collections import deque


class Dinic:

    def __init__(self, N0, N1):
        self.N0 = N0
        self.N1 = N1
        self.N = N = 2+N0+N1
        self.G = [[] for i in range(N)]
        for i in range(N0):
            forward = [2+i, 1, None]
            forward[2] = backward = [0, 0, forward]
            self.G[0].append(forward)
            self.G[2+i].append(backward)
        self.backwards = bs = []
        for i in range(N1):
            forward = [1, 1, None]
            forward[2] = backward = [2+N0+i, 0, forward]
            bs.append(backward)
            self.G[2+N0+i].append(forward)
            self.G[1].append(backward)

    def add_edge(self, fr, to):
        #assert 0 <= fr < self.N0
        #assert 0 <= to < self.N1
        v0 = 2 + fr
        v1 = 2 + self.N0 + to
        forward = [v1, 1, None]
        forward[2] = backward = [v0, 0, forward]
        self.G[v0].append(forward)
        self.G[v1].append(backward)

    def bfs(self):
        G = self.G
        level = [None]*self.N
        deq = deque([0])
        level[0] = 0
        while deq:
            v = deq.popleft()
            lv = level[v] + 1
            for w, cap, _ in G[v]:
                if cap and level[w] is None:
                    level[w] = lv
                    deq.append(w)
        self.level = level
        return level[1] is not None

    def dfs(self, v, t):
        if v == t:
            return 1
        level = self.level
        for e in self.it[v]:
            w, cap, rev = e
            if cap and level[v] < level[w] and self.dfs(w, t):
                e[1] = 0
                rev[1] = 1
                return 1
        return 0

    def flow(self):
        flow = 0
        while self.bfs():
            *self.it, = map(iter, self.G)
            while self.dfs(0, 1):
                flow += 1
        return flow

    def matching(self):
        return [cap for _, cap, _ in self.backwards]

#####################################################################################

N = int(input())
s = []
ss = []
for i in range(N):
    s.append([int(i) for i in input().split()])

for i in range(N):
    ss.append([int(i) for i in input().split()])

pair = []
for i in range(len(s)):
    right = []
    for j in range(N):
        if s[j][0] < ss[i][0] and s[j][1] < ss[i][1]:
            right.append(j)
    pair.append(right)

# print(pair)

#####################################################################################


# 頂点の組u,vと辺の重みc（今回は1）からグラフ作って最大流で解くFOOOOOOOOOOOOOOOOO

V = len(pair) + N + 2  # (sとt追加)

dinic = Dinic(V, V)

for i in range(len(pair)):  # 始点s（番号0）から青い点(1から最大len(pair))への辺
    u, v, c = 0, i + 1, 1
    dinic.add_edge(u, v)

for i in range(N):  # 赤い点（len(pair)+1から最大len(pair)+n）から終点t（番号V-1）への辺
    u, v, c = i + len(pair) + 1, V - 1, 1
    dinic.add_edge(u, v)

for i in range(len(pair)):  # 青い点（番号1から最大len(pair)に振り直し）から　赤い点（番号1～100に振り直し）への辺
    for j in range(len(pair[i])):
        node1, node2 = i + 1, pair[i][j] + len(pair) + 1

        u, v, c = node1, node2, 1
        dinic.add_edge(u, v)

print(dinic.flow() - 2)

Measured memory_bytes: 75784
#define scanf_s scanf
//#define gets_s gets
#include <stdio.h>
#include <string>
#include <iostream>
#include <math.h>
using namespace std;
#define MIN -1
#define MAX 1000000
int main(void)
{
	char a, b, x = 'A';
	while (scanf_s("%c,%c",&a,&b) != EOF) {
		if (a == x) x = b;
		else if (b == x) x = a;
	}
	printf("%c\n", x);
}

Measured memory_bytes: 1140
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
//using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
  
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * (B / gcd(A, B));
}
  
/*------------------------------------------------------------------*/
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
Graph G;
vector<int> ans;

void dfs(int v, int parent, int color){
    ans[v] = color;

    for(auto e : G[v]){
        if(e.first == parent) continue;
        if(e.second % 2 == 0) dfs(e.first, v, color);
        else dfs(e.first, v, 1 - color);
    }
}

int main(){
    int n; cin >> n;
    G.assign(n, vector<Edge>());
    rep(i, n - 1){
        int from, to, distance; cin >> from >> to >> distance;
        from--, to--;
        G[from].push_back(Edge(to, distance));
        G[to].push_back(Edge(from, distance));
    }

    ans.assign(n, 0);
    dfs(0, -1, 1);
    
    for(auto v : ans) cout << v << endl;
}

Measured memory_bytes: 8960
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll n,m,l,r,d;
std::vector<pair<ll,ll>> adj[200007];
set<ll> seen;
ll parr[200007];
ll size[200007];
ll dis[200007];
ll vis[200007];
ll vist[200007];

ll find(ll u) {
  if (parr[u] == u) return u;
  return parr[u] = find(parr[u]);
}
void init(ll n) {
  for(ll i = 1; i<=n; i++){
    parr[i] = i;
    size[i] = 1;
  }
}
void unify(ll a, ll b) {
  a = find(a);
  b = find(b);
  if (a != b) {
    if (size[b] > size[a])
      swap(a, b);
    parr[b] = a;
    size[a] += size[b];
  }
}

void reset(){
  for(ll e : seen) dis[e] = vis[e] = vist[e] = 0;
  seen.clear();
}

int dfs(ll cur, ll d){
  seen.insert(cur);
  vis[cur] = 1;
  dis[cur] = d;
  int res = 1 ;
  for(auto e : adj[cur]){
    if(!vis[e.first]) res&=dfs(e.first, d+e.second);
  }
  for(auto e : adj[cur]){
    ll v = e.first;
    ll duv = e.second;
    if((dis[v]-dis[cur])!=duv)  return 0;
  }
  return res;
}
int main(){
  std::cin >> n >> m;
  init(n);
  for(ll i = 0; i<m; i++){
    std::cin >> l >> r >> d;
    unify(l, r);
    adj[l].push_back({r, d});
    adj[r].push_back({l, -d});
  }
  set<ll> cc;
  for(ll i = 1; i<=n; i++) cc.insert(find(i));
  for(ll e : cc){
    reset();
    if(!dfs(e, 0)) return 0*printf("No\n");
  }
  return 0*printf("Yes\n");
}


Measured memory_bytes: 29312
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define INF (ll)(1e18)
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }


// youtube editorial

void solve() {
    int n, q;
    cin >> n >> q;
    
    vector<tuple<int, int, int> > v(n);
    rep(i, n) {
        int l, r, x;
        cin >> l >> r >> x;
        r--;
        l -= x;
        r -= x;
        v[i] = tie(x, l, r);
    }
    sort(all(v));
    rep(i, n) {
        int l, r, x;
        tie(x, l, r) = v[i];
        // cout << x << " " << l << " " << r << endl;
    }
    set<pii> s;
    rep(i, q) {
        int d;
        cin >> d;
        s.insert(pii(d, i));
    }
    vector<int> ans(q, -1);
    rep(i, n) {
        int x, l, r;
        tie(x, l, r) = v[i];
        auto it = s.lower_bound(pii(l, -1));
        // cout << "i " << i << " " << it->S << endl;
        while (it != s.end()) {
            if (it->F > r) break;
            ans[it->S] = x;
            // cout << it->S << " " << x << endl;
            s.erase(it++);
        }
    }
    rep(i, q) cout << ans[i] << endl;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int T;
    // cin >> T;
    T = 1;
    
    while (T--) {
        solve();
    }
}




Measured memory_bytes: 14464
using System;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            Boolean flag = true;
            
            for(int i=0;i<S.Length;i++){
                if(S[i]!=T[i]){
                    flag=false;
                }
            }
            
            if(flag){
                Console.WriteLine("Yes");
            }else{
                Console.WriteLine("No");
            }
        }

    }

}


Measured memory_bytes: 25880
#include <stdio.h>

int main(){
    
    int i,j = 0;
    long x[20000],y[20000];
    
    for(i = 0; i < 20000;i++){
        scanf("%ld %ld",&x[i],&y[i]);
        j++;
        if(x[i] == 0){
            if(y[i]==0){
                break;
            }
        }
    }
    
    for(i = 0; i < j-1; i++){
        if(x[i] < y[i]){
            printf("%ld %ld\n",x[i],y[i]);
        }else{
            printf("%ld %ld\n",y[i],x[i]);
        }
    }
    
    return 0;
    
}

Measured memory_bytes: 644
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const long long INF = 1e18;

long long GetCost(const char* a, const char* aEnd, const char* b, const char* bEnd) {
    --aEnd;
    --bEnd;

    long long cost = 0;
    while (aEnd >= a && bEnd >= b) {
        if (*aEnd == *bEnd) {
            ++cost;
        }
        --aEnd;
        --bEnd;
    }

    return cost;
}

int main() {
    ios_base::sync_with_stdio(false);

    long long h, w;
    cin >> h >> w;

    vector<string> a(w);
    for (long long i = 0; i < h; ++i) {
        string s;
        cin >> s;
        for (long long j = 0; j < w; ++j) {
            a[j] += s[j];
        }
    }

    vector<long long> prev(h + 1, 0);
    vector<vector<long long>> dp(h + 1, vector<long long>(h + 1, 0));
    vector<vector<long long>> cost(h + 1, vector<long long>(h + 1, 0));

    for (long long t = 1; t < w; ++t) {
        for (long long j = h; j >= 0; --j) {
            cost[h][j] = GetCost(a[t - 1].c_str(), a[t - 1].c_str() + h, a[t].c_str(), a[t].c_str() + j);
        }
        for (long long i = h; i >= 0; --i) {
            cost[i][h] = GetCost(a[t - 1].c_str(), a[t - 1].c_str() + i, a[t].c_str(), a[t].c_str() + h);
        }
        for (long long i = h - 1; i >= 0; --i) {
            for (long long j = h - 1; j >= 0; --j) {
                cost[i][j] = cost[i + 1][j + 1] - (a[t - 1][i] == a[t][j] ? 1 : 0);
            }
        }

        for (long long i = h; i >= 0; --i) {
            for (long long j = h; j >= 0; --j) {
                dp[i][j] = INF;
            }
        }

        dp[h][h] = 0;

        for (long long i = h; i >= 0; --i) {
            for (long long j = h; j >= 0; --j) {
                if (i - 1 >= 0) {
                    dp[i - 1][j] = min(dp[i - 1][j], dp[i][j] + cost[i][j] + prev[i - 1] - prev[i]);
                }
                if (j - 1 >= 0) {
                    dp[i][j - 1] = min(dp[i][j - 1], dp[i][j] + cost[i][j]);
                }
            }
        }

        for (long long j = h; j >= 0; --j) {
            prev[j] = dp[h][j];
            for (long long i = h; i >= 0; --i) {
                prev[j] = min(prev[j], dp[i][j]);
            }
        }
        prev[0] = dp[0][0];
    }

    cout << prev[0] << endl;

    return 0;
}


Measured memory_bytes: 1920
// #pragma GCC optimize("Ofast")

// #pragma GCC optimize("no-stack-protector")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stdio.h>
#include <cstdio>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <random>
#include <iomanip>
#include <bitset>

using namespace std;

template<typename T> void uin(T &a, T b) {
    if (b < a) {
        a = b;
    }
}

template<typename T> void uax(T &a, T b) {
    if (b > a) {
        a = b;
    }
}

#define int long long
#define left left228
#define right right228
#define ld long double
#define list list228
// #define prev prev228
#define mp make_pair
#define list list228
#define all(v) v.begin(), v.end()

const int N = 200 * 1000 + 228;
const int INF = 2e9 + 228;

int a[N], b[N];
int mint[N];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, T;
    cin >> n >> T;
    vector< pair<int, int> > v;
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
        ++a[i];
        b[i] += a[i];
        v.emplace_back(a[i], b[i]);
    }
    sort(all(v), [&] (pair<int, int> F, pair<int, int> S) {
        int a1 = F.first, b1 = F.second;
        int a2 = S.first, b2 = S.second;
        return a2 * b1 + b2 < a1 * b2 + b1;
    });
    for (int i = 0; i < n; ++i) {
        a[i] = v[i].first;
        b[i] = v[i].second;
    }
    for (int i = 1; i <= 31; ++i) {
        mint[i] = INF;
    }
    vector<int> one;
    for (int i = 0; i < n; ++i) {
        if (a[i] > 1) {
            for (int j = 30; j + 1; --j) {
                if (mint[j] * a[i] + b[i] < mint[j + 1]) {
                    mint[j + 1] = mint[j] * a[i] + b[i];
                }
            }
        } else {
            one.emplace_back(b[i]);
        }
    }
    sort(all(one));
    int end = 0;
    int ans = 0;
    for (int take = 0; take <= (int)one.size(); ++take) {
        if (end > T) break;
        for (int l = 0; l <= 31; ++l) {
            if (mint[l] + end <= T) uax(ans, take + l);
        }
        if (take < (int)one.size()) {
            end += one[take];
        }
    }
    cout << ans << '\n';
    return 0;
}

/*
3
1 1 2
2 2 2
3 3 2
2 1 1
3 2 1


2 2
1 1 2
2 2 2
1 2 3
2 1 1

2
2 1 2 2 3
2 2 2 1 1

бархатом обитый гроб
5
1 2
2 3
3 4
3 5
1
2 3
1 2
4 3
2 3 5

*/




Measured memory_bytes: 11244
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc_167a
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();

            string Tt = T.Substring(0, S.Length);

            if(Tt == S)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

            Console.Read();
        }
    }
}


Measured memory_bytes: 25892
#include<bits/stdc++.h>
using namespace std;
int main(){
	vector<int>s(3);
	for(int i=0;i<3;i++){
		cin>>s.at(i);
	}
	sort(s.begin(),s.end());
	if(s.at(0)+s.at(1)==s.at(2))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {

    public static void main(String args[])  {
        Scanner sc = new Scanner(System.in);
        ArrayList<Integer> aList = new ArrayList();
        ArrayList<Integer> bList = new ArrayList();
        ArrayList<Integer> cList = new ArrayList();

        int days = sc.nextInt();
        for (int d=0;d<days;d++) {
            aList.add(sc.nextInt());
            bList.add(sc.nextInt());
            cList.add(sc.nextInt());
        }

        ArrayList<ArrayList<Integer>> plan = new ArrayList<>();
        plan.add(aList);
        plan.add(bList);
        plan.add(cList);

        for (int i=1; i<days;i++){
            plan.get(0).set(i, plan.get(0).get(i) + Math.max(plan.get(1).get(i-1), plan.get(2).get(i-1)));
            plan.get(1).set(i, plan.get(1).get(i) + Math.max(plan.get(0).get(i-1), plan.get(2).get(i-1)));
            plan.get(2).set(i, plan.get(2).get(i) + Math.max(plan.get(1).get(i-1), plan.get(0).get(i-1)));
        }
//        System.out.println(plan);

        System.out.println(Math.max(plan.get(2).get(days-1), Math.max(plan.get(0).get(days-1), plan.get(1).get(days-1))));

    }


}


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

namespace ConsoleApp2
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int mod = 2019;

            int[] LR = Read(Console.ReadLine());
            int L = LR[0];
            int R = LR[1];

            if (R - L >= 2019)
            {
                Console.WriteLine(0);
                return;
            }


            int min = mod;
            for (long i = L; i < R; i++)
            {
                for (long j = i+1; j <= R; j++)
                {
                    min = Math.Min(min, (int)((i*j) % mod));
                }
            }

            Console.WriteLine(min);
            Console.ReadLine();
        }

        private static int[] Read(string input)
        {
            string[] strings = input.Split(' ');
            int num = strings.Length;
            int[] ints = new int[num];
            for (int i = 0; i < num; i++)
            {
                ints[i] = int.Parse(strings[i]);
            }
            
            return ints;
        }


    }


}


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

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
#define log2(x) (log(x)/log(2))
#define ln '\n'
#define bln(i,n) ((i==n-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ');}}

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int n, a[200200], b[200200], res;
// a<b, a==b, a>b
vpii x, y, z;
vector<pair<double,int>> p;

signed main() {
	cin >> n;
	rep(i,n) {
		cin >> a[i] >> b[i];
		if (a[i]<b[i]) x.pb({a[i],b[i]});
		else if (a[i]==b[i]) y.pb({a[i],b[i]});
		else z.pb({a[i],b[i]});
	}
	if (y.size()==n) return cout << 0 << ln, 0;
	
	// まずa<bのやつで差をつけて時間稼ぎ
	// ゲザンはこれを絶対処理しないといけない
	int as = 0, bs = 0;
	each(i,x) as += i.fi, bs += i.se;
	res += as, bs -= as, as = 0;
	x.clear();
	// 稼いだ時間でa==bの差をつけておく トザン的にa>bのやつはなるべく手をつけたくない
	// ゲザンは稼がれた時間を終わったらすぐこれに手をつける
	each(i,y) res += i.fi;
	// bsターンの猶予がある 効率良い順に使う
	int dec = linf;
	each(i,z) {
		res += i.fi;
		chmin(dec, i.se);
	}
	res -= dec;
	cout << res << ln;
}

Measured memory_bytes: 1152
def main():
    N = int(input())
    sum = 0
    for i in range(N):
        i = i+1
        if i%3 == 0 or i%5 == 0 or i%15 == 0:
            continue
        else:
            sum = sum + i

    print(sum)




if __name__ == "__main__":
    main()

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

class C
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();

		var M = 0;
		var l = new List<string>();
		if (a[0] >= 0)
		{
			M = a[0];
			for (int i = 1; i < n - 1; i++)
			{
				l.Add($"{M} {a[i]}");
				M -= a[i];
			}
			l.Add($"{a[n - 1]} {M}");
			M = a[n - 1] - M;
		}
		else if (a[n - 1] <= 0)
		{
			M = a[n - 1];
			for (int i = 0; i < n - 1; i++)
			{
				l.Add($"{M} {a[i]}");
				M -= a[i];
			}
		}
		else
		{
			M = a[0];
			int i = n - 2;
			for (; a[i] > 0; i--)
			{
				l.Add($"{M} {a[i]}");
				M -= a[i];
			}
			l.Add($"{a[n - 1]} {M}");
			M = a[n - 1] - M;
			for (; i > 0; i--)
			{
				l.Add($"{M} {a[i]}");
				M -= a[i];
			}
		}
		Console.WriteLine(M);
		foreach (var item in l) Console.WriteLine(item);
	}
}


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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N, W;
int w[110];
int v[110];
ll dp[110][100100];

int main()
{
    cin >> N >> W;
    rep(i, N)
    {
        cin >> w[i] >> v[i];
    }

    for (int i = 1; i <= N; i++)
    {
        for (int j = 1; j <= W; j++)
        {
            if (j < w[i-1])
            {
                dp[i][j] = dp[i-1][j];
            }
            else
            {
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]] + v[i-1]);
            }
        }
    }

    cout << dp[N][W] << endl;
}


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

int main() {
	int size;
	cin>>size;
	int arr[2*size]={};
	int ans=0;
	
	for(int i=0;i<2*size;i++){
	    cin>>arr[i];
	    
	}
	
	sort(arr,arr+2*size);
	for(int i=0;i<2*size;i++){
	    if(i%2==0){
	        ans=ans+arr[i];
	    }
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int h,w;
    cin >> h >> w;
    char c[h][w];
    for(int i = 0;i < h;i++)
    {
        for(int j = 0;j < w;j++)
        {
            cin >> c[i][j];
        }
    }
    for(int i = 0;i < w;i++)
    {
        cout << c[0][i];
    }
    cout << "\n";
    for(int i = 0;i < 2 * h - 1;i++)
    {
        for(int j = 0;j < w;j++)
        {
            cout << c[(i + 1) / 2][j];
        }
        cout << "\n";
    }

    return 0;
}

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

int main(int argc, const char * argv[]) {

    while(true){
        int n;
        cin >> n;
        if(n==0){
            break;
        }
        
        int array[100] = {0};
        for(int i=0;i<n;i++){
            cin >> array[i];
        }
        
        
        int count = 0;
        int i = 0;
        int j = n - 1;
        while(j>0){
            
            if(i == j){
                i = 0;
                j--;
            }
            else if(array[i] > array[i+1]){
                int t = array[i];
                array[i] = array[i+1];
                array[i+1] = t;
                i++;
                count++;
            }
            else{
                i++;
            }
            
        }
        
        cout << count << endl;
        
    }
    
    
    return 0;
}

Measured memory_bytes: 1160
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
bool g[10][10];
int solve(){
  int n,m;
  cin >> n >> m;
  vector<int>s(n);
  rep(i,n)s[i] = i;
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    g[a][b] = true;
    g[b][a] = true;
  }
  int ans = 0;
  do{
    if(s[0] != 0)continue;
    bool can = true;
    rep(i,n - 1)if(g[s[i]][s[i + 1]] != true)can = false;
    if(can)ans++;
  }while(next_permutation(s.begin(),s.end()));
  cout << ans << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
} 

Measured memory_bytes: 256
///
// File:  alds1_8_ba.cpp
// Author: ymiyamoto
//
// Created on Sun Oct 15 00:50:39 2017
//

#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
struct tree_t {
  tree_t *left;
  tree_t *right;
  int64_t value;
  tree_t(int64_t val)
  {
    left = NULL;
    right = NULL;
    value = val;
  }
};

static tree_t *tree;
static vector<int64_t> pre, in;

void insert(tree_t *top, int64_t val)
{
  if (top == NULL) {
    tree = new tree_t(val);
    return;
  }

  if (val < top->value) {
    if (top->left == NULL) {
      tree_t *node = new tree_t(val);
      top->left = node;
    } else {
      insert(top->left, val);
    }
  } else if (val > top->value) {
    if (top->right == NULL) {
      tree_t *node = new tree_t(val);
      top->right = node;
    } else {
      insert(top->right, val);
    }
  }
}

void walk(tree_t *top)
{
  if (top == NULL) return;
  pre.push_back(top->value);
  walk(top->left);
  in.push_back(top->value);
  walk(top->right);
}

void print()
{
  pre.clear();
  in.clear();
  walk(tree);
  for (uint32_t i = 0; i < in.size(); i++) {
    cout << " " << in[i];
  }
  cout << endl;

  for (uint32_t i = 0; i < pre.size(); i++) {
    cout << " " << pre[i];
  }
  cout << endl;
}

bool find(tree_t *top, int64_t val)
{
  if (top == NULL)
    return false;
  else {
    if (val == top->value) {
      return true;
    } else if (val < top->value) {
      return find(top->left, val);
    } else {
      return find(top->right, val);
    }
  }
}

int32_t main()
{
  uint32_t n;
  cin >> n;

  for (uint32_t i = 0; i < n; i++) {
    string str;
    int64_t val;
    cin >> str;
    if (str[0] == 'i') {
      cin >> val;
      insert(tree, val);
    } else if (str[0] == 'f') {
      cin >> val;
      if (find(tree, val)) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    } else {
      print();
    }
  }

  return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int ab = abs(a - b);
  int bc = abs(b - c);
  int ca = abs(c - a);

  if (ca <= d) {
    cout << "Yes" << endl;
  } else if (ab <= d && bc <= d) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
 
  int main(){
    int h,w,n;cin>>h>>w>>n;
    int p=max(h,w);
    int sum=0;
    int ans=0;
    while(sum<n)
    {
      ans++;
      sum+=p;
    }
    cout<<ans;
  }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

class Segment_Tree{
	private:
	int n;
	vi date;
	public:
	Segment_Tree(int n_){
		n=1;
		while(n<n_) n*=2;
		date=vi(2*n-1);
	}
	void Update(int k,int x){
		k+=n-1;
		date[k]+=x;
		while(k>0){
			k=(k-1)/2;
			date[k]=date[k*2+1]+date[k*2+2];
		}
	}
	int Query(int a,int b){
		a+=n-1;b+=n-1;
		int m=0;
		while(a<b){
			if(a%2==0) m+=date[a++];
			if(b%2==0) m+=date[--b];
			a/=2;b/=2;
		}
		return m;
	}
	int Open(int k){return date[k+n-1];}
};

typedef pair<double,int> T;

ll n,N;
vd a,b,c;

ll Count(double x){
	vector<T> d(n),e(n);
	vi A(n),B(n),C(n);
	for(int i=0;i<n;i++){
		d[i]={(c[i]-a[i]*x)/b[i],i};
		e[i]={-a[i]/b[i],i};
	}
	sort(d.begin(),d.end());
	sort(e.begin(),e.end());
	for(int i=0;i<n;i++){
		A[d[i].second]=i;
		B[e[i].second]=i;
	}
	for(int i=0;i<n;i++) C[A[i]]=B[i];
	ll sum=0;
	Segment_Tree st(n);
	for(int i=0;i<n;i++){
		sum+=st.Query(0,C[i]);
		st.Update(C[i],1);
	}
	return sum;
}

double f(){
	double l=-inf,r=inf;
	for(int i=0;i<80;i++){
		double m=(l+r)/2;
		if(Count(m)>=(N+1)/2) r=m;
		else l=m;
	}
	swap(a,b);
	return r;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	N=n*(n-1)/2;
	a=b=c=vd(n);
	for(int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];
	double x=f(),y=f();
	cout<<syosu(11)<<x<<' '<<y<<endl;
}

Measured memory_bytes: 3612
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int32_t main()
{
	int n=in();
	vector<int> a;
	int x=in();
	a.push_back(x);
	for(int i=1;i<n;i++)
	{
		x=in();if(x==a.back())continue;
		a.push_back(x);
	}
	
	//1000 yen
	vector<int> df;vector<pair<int,int>> costs;
	n=a.size();
	for(int i=0;i<n-1;i++)
	{
		x=a[i+1]-a[i];if(x<0)continue;
		if(x>0 and df.empty()){df.push_back(x);costs.push_back({a[i],a[i+1]});}
		else if(x>=0){df.push_back(x);costs.push_back({a[i],a[i+1]});}
	}
	int cur=1000;
	
	auto buysell=[&](int buy, int sell)
	{
		int stocks=cur/buy;
		int cost=stocks*buy;cur-=cost;
		int profit=stocks*sell;cur+=profit;
		
	};
	
	if(costs.size()==0){cout<<"1000";return 0;}
	for(auto i:costs)
	{
		buysell(i.first,i.second);
		//cout<<cur<<" "<<i.first<<" "<<i.second<<"\n";
	}
	cout<<cur;
	
	
	
}

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

using namespace std;
int main(){
    int a,b,c,k;cin>>a>>b>>c>>k;
    long ans=0;
                                                                                                                         if(a <= k){
        ans+=a;
        k-=a;
    }else{
        ans+=k;
        cout << ans << endl;
        return 0;
    }

    if(b <= k){                                                                                                              k-=b;                                                                                                            }else{
        cout << ans << endl;
        return 0;
    }

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

Measured memory_bytes: 3592
#include <vector>
#include <algorithm>
#include <limits.h>
#include <iostream>
#include <set>
#include <cmath>
#include <queue>
#include <cstring>
#include <string.h>
#include <stdio.h>
#include <iomanip>
#include <map>
#include <unordered_map>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

      int n; int W; cin>>n;
      cin>>W;

      int w[n],v[n];
      for(int i=0;i<n;i++){cin>>w[i]>>v[i];}

      int maxV=1e5+1;
       long long  f[n+1][maxV+1];
      for(int i=0;i<=maxV;i++){f[0][i]=INT_MAX;}
      for(int i=0;i<=n;i++){f[i][0]=0;}
      for(int i=1;i<=n;i++)
      {
          for(int j=1;j<=maxV;j++)
          {
              f[i][j]=f[i-1][j];
              if(j-v[i-1]>=0){f[i][j]=min(f[i][j],f[i-1][j-v[i-1]]+w[i-1]);}
              //cout<<f[i][j]<<" ";
          }
         // cout<<"\n";
      }
    long long  ans=0;
    for(int i=maxV;i>=0;i--)
    {
      //cout<<f[n][i]<<" ";
            if(f[n][i]<=W)
            {
                ans=i;
                break;
            }

    }
      cout<<ans<<"\n";



    return 0;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 
int N, a, b;
  cin >> N;
  
    a = N / 10;
    b = N % 10;
  
  if(a == 9 || b == 9) cout << "Yes" << endl;
  else cout << "No" << endl;
  
return 0;
 
}

Measured memory_bytes: 256
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
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;}

int N,K,i,a=1;
inline void solve(){
  IN2(N,K);
  REP(i,N){
    a=min(a*2,a+K);
  }
  OUT(a);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
	
	long long int n;
	cin>>n;
	long long int ans=1;
	int i=0;
	while(n>0){
		ans|=(1ull<<i++);
		n/=2;
//cout<<"hari"<<" "<<i<<"\n";
//	cout<<"ans = "<<ans;		
	}
	
	cout<<ans;
	return 0;		
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    int n;
    string s;
    cin >> n >> s;

    vector<vector<int>> v(3);
    REP(i, n){
        if(s[i] == 'R') v[0].push_back(i);
        else if(s[i] == 'G') v[1].push_back(i);
        else v[2].push_back(i);
    }

    ll ans = 0;

    REP(i, v[0].size()){
        REP(j, v[1].size()){
            int a = v[0][i], b = v[1][j];
            if(a > b) swap(a, b);
            ans += v[2].size();
            ll d = b - a;
            if(b + d < n && s[b+d] == 'B'){
                ans--;
            }
            if((b - a)%2 == 0 && s[(a + b) / 2] == 'B'){
                ans--;
            }
            if(a - d >= 0 && s[a-d] == 'B'){
                ans--;
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	int n;
	cin >> n;
	bool ans = false;
	for(int i = 0;i<n;i++)
	{
		int x;
		cin >> x;
		if(x&1)ans=true;
	}
	if(ans)
	{
		cout<<"first"<<endl;
	}
	else
	{
		cout<<"second"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import bisect
def put(a,b): #結果の表示
    l=max(len(a),len(b)) #aとbの長さが違うときに壊れるので以下で十分な長さの0を結合しておく
    a="0"*l+a
    b="0"*l+b
    s=""
    for i in range(-1,-l-1,-1): #長さの偶奇を考えたくないので逆順に生成してあとで反転
        s+=a[i]+b[i]
    s=s[-1::-1] #反転
    ind=s.find("1")
    print(s[ind:]) #頭にたくさんついている0を除いて表示

def quad(i): #数値を4進数表記の文字列に直す。16→"100"など。
    s=""
    while i>0:
        s+=str(i%4)
        i//=4
    return s[-1::-1]

l=[0,1]
for i in range(1,18): #候補の生成。最長で18ビット。
    l+=[4**i+j for j in l]

n=int(input())
if n==0: #n==0は出力が空文字になってしまうので別に扱う
    print("0")
else:
    for i in range(len(l)):
        ind=bisect.bisect_left(l,(l[i]-n)//2)
        if l[i]-2*l[ind]==n:
            put(quad(l[i]),quad(l[ind]))
            break

Measured memory_bytes: 57968
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>

typedef unsigned long long int ull;

using namespace std;


int main(){
	ull a[3];
	cin >> a[0] >> a[1] >> a[2];
	if (a[0] % 2 == 0 || a[1] % 2 == 0 || a[2] % 2 == 0) {
		cout << "0\n";
		return 0;
	}
	sort(a, a + 3);
	cout << a[0]*a[1] << "\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod=1e9+7;

             
        
int main() {
			   fast
            //    #ifndef ONLINE_JUDGE
            //    freopen("input.txt","r",stdin);
            //    freopen("output.txt","w",stdout);
            //    #endif
               
                    ll n,m;
                    cin>>n>>m;
                    ll sum=0;
                    for(ll i=0;i<m;i++)
                    {
                        ll x;
                        cin>>x;
                        sum+=x;

                    }
                    if(sum>n)
                    {
                        cout<<-1;
                        return 0;
                    }
                    cout<<n-sum;
                

                return 0;
            }


Measured memory_bytes: 3652