akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL << 60;
const int MOD = (int) 1e9 + 7;

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

int h, w;

bool is_in(int y, int x, int diff_y, int diff_x) {
    return 0 <= y + diff_y && y + diff_y <= h - 1 && 0 <= x + diff_x && x + diff_x <= w - 1;
}

signed main() {
    cin >> h >> w;
    vector<string> grid(h);
    for (int i = 0; i < h; i++) {
        cin >> grid.at(i);
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (grid[i][j] == '#') {
                bool flag = false;
                for (int k = 0; k < 4; k++) {
                    if (is_in(i, j, dy[k], dx[k]) && grid[i + dy[k]][j + dx[k]] == '#') {
                        flag = true;
                        break;
                    }
                }
                if (!flag) {
                    cout << "No" << "\n";
                    return 0;
                }
            }
        }
    }
    cout << "Yes" << "\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<iostream>
#include<algorithm>
#define m(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long LL;
typedef pair<int,int>PII;
const LL inf = 1 << 30;
const int mod = 998244353;
map<int,int>mp;
map<int,int>mp1;
map<PII,int>::iterator it;
const int maxn = 1e5;
struct point{
    int x,y,flag;
}s,q;
int n;
int ans = 0;
int num[2*maxn+5],vis[2*maxn+5];
int main(){
	cin >> n;
	for(int i = 1;i<=n;i++){
		cin >> num[i];
		vis[i] = num[i];
	}
	sort(vis+1,vis+1+n);
	for(int i = 1;i<=n;i++){
		int mid = n/2;
		if(num[i] <= vis[mid]) mid++;
		cout << vis[mid] <<  endl;
	}
    return 0;
}

Measured memory_bytes: 3712
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 998244353
#define INF2 1000000000000000000
#define int long long
int A[3010];
#define int long long 
int F[2100010];

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

void fact(void) {
	F[0] = 1;
	F[1] = 1;
	for (int i = 2; i <= 2100000; i++) {
		F[i] = Mul(i, F[i - 1]);
	}
}
int square(int x) {
	return (x * x) % mod;
}

int power(int x, int y) {
	if (y == 0) return 1;
	else if (y == 1) return x % mod;
	else if (y % 2 == 0) return square(power(x, y / 2)) % mod;
	else return square(power(x, y / 2)) * x % mod;
}

int Div(int a, int b) {
	return Mul(a, power(b, mod - 2));
}
int P(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	return Div(F[n], F[n - r]);
}

int C(int n, int r) {
	if (n < r || n < 0 || r < 0) return 0;
	int ret;
	ret = Div(F[n], Mul(F[n - r], F[r]));
	return ret;
}
int H(int n, int r) {
	if (n == 0 && r == 0) return 1;
	return C(n + r - 1, r);
}
int dp[3010][3010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, S;
    cin >> N >> S;
    rep(i, N) cin >> A[i];
    int ans = 0;
    rep(i, 3010) rep(j, 3010) dp[i][j] = 0;
    dp[0][0] = 1;
    rep(i, N) {
        REP(j, 0, S) {
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % mod;
            if(j == 0) dp[i + 1][j]++;
            if (j - A[i] >= 0) 
                dp[i + 1][j] = (dp[i + 1][j] + dp[i][j - A[i]]) % mod;
        }
    }
    rep(i, N + 1) {
        ans = (ans + dp[i][S]) % mod;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 71936
/*AtCoder Beginner Contest 074 A-Bichrome Cells kento_titech*/
#include <stdio.h>
 
int main(void){
  int N,A;
  
  scanf("%d\n",&N);//N入力
  scanf("%d",&A);//A入力
  if((1<=N<=100)&&(0<=A<=(N*N))){ 
    printf("%d\n",N*N-A);//N*N-A出力
  }
  return 0;
 
}


Measured memory_bytes: 128
# include<bits/stdc++.h>
using namespace std;
int gcd(int x,int y)
{
    int t;
    while(y)
    {
        t=x%y;
        x=y;
        y=t;
    }
    return  x;
}
int main()
{
    int n;
    cin>>n;
    int sum=0;
    for(int j=1;j<=n;j++)
       {
           for(int k=1;k<=n;k++)
               {
                   for(int i=1;i<=n;i++)
                    {
                        sum=sum+gcd(j,gcd(k,i));
                    }
               }
       }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int n;
    cin >> n;
    vector< vector<int> > G(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        int u, k;
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            int v;
            cin >> v;
            v--;
            G[u][v] = 1;
        }
    }
 
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (j > 0) cout << " ";
            cout << G[i][j];
        }
        cout << endl;
    }
    return 0;
}


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

string to_string(string s) {
	return '"' + s + '"';
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto &x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}";
	return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

void test_case() {
	string s;
	cin >> s;
	sort(s.begin(), s.end());
	if (s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 200005;



int main() {
  int n;
  scanf("%d",&n);
  vi a(n), b(n);
  cin>>a>>b;
  int ans = 0;
  rep(i,n) ans += max(0,a[i]-b[i]);
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int A,B,i,j,k;
    scanf("%d%d", &A, &B);
    i=A+B;
    j=A-B;
    k=A*B;
    if(i>j){
		if(i>k)
    	printf("%d\n",i);
   		else
    	printf("%d\n",k);
    }
    else{
    	if(k>j)
    	printf("%d\n",k);
    	else
    	printf("%d\n",j);
    }
    return 0;
}


Measured memory_bytes: 1696
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    INT(n);
    vector<ll> vec(n);
    in(vec);
    vector<ll> sum(n+1,0);
    for(int i=1;i<n+1;i++){
        sum[i]=sum[i-1]+vec[i-1];
    }
    sort(all(sum));
    ll ans=0,d;
    for(int i=0;i<n+1;i++){
        d=1;
        while(i+1<n+1&&sum[i]==sum[i+1]){
            i++;
            d++;
        }
        if(d>=2){
            ans+=d*(d-1)/2;
        }
    }
    out(ans);
}


Measured memory_bytes: 6428
#include <bits/stdc++.h>
using namespace std;
int a[20005],b[20005];
pair<int,int> p[20005];

int main(){
  int st,n;
  cin>>n;
  int d=30000;
  for(int i=0;i<n;i++){cin>>p[i].first;p[i].second=i;}
  sort(p,p+n);
  for(int i=0;i<n;i++){
    a[i] = (1+i)*d;
    b[i] = (n-i)*d+p[i].second;
  }
    
  for(int i=0;i<n;i++){
    cout<<a[i];
    if(i<n) cout<<" ";
  }
  cout<<endl;
  for(int i=0;i<n;i++){
    cout<<b[i];
    if(i<n) cout<<" ";
  }
  cout<<endl;
  return 0;
}


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

class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));
		String input = reader.readLine();
		String str[] = input.split(" ");
		int a = Integer.parseInt(str[0]);
		int b = Integer.parseInt(str[1]);
		int c = Integer.parseInt(str[2]);

		if(a < b && a < c && b < c){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 24304
#include<bits/stdc++.h>
/*
ID: arun.ga1
LANG: C++
TASK: 
 */

using namespace std;

#define prime 1000000007
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF = 1<<29;
typedef long long ll;

/////////////////////////////////////////////////////////////////////

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	char s[100005];
	ll len,i,pos;
	cin >> s;
	for(i=strlen(s)-1;i>=0;i--)
	{
		if(s[i]=='m' && s[i-1]=='a' && s[i-2]=='e' && s[i-3]=='r' && s[i-4]=='d' && i-4>=0)
		{
			i-=4;
		}
		else if(s[i]=='r' && s[i-1]=='e' && s[i-2]=='m' && s[i-3]=='a' && s[i-4]=='e' && s[i-5]=='r' && s[i-6]=='d' && i-6>=0)
		{
			i-=6;
		}
		else if(s[i]=='r' && s[i-1]=='e' && s[i-2]=='s' && s[i-3]=='a' && s[i-4]=='r' && s[i-5]=='e' && i-5>=0)
		{
			i-=5;
		}
		else if(s[i]=='e' && s[i-1]=='s' && s[i-2]=='a' && s[i-3]=='r' && s[i-4]=='e' && i-4>=0)
		{
			i-=4;
		}
		else if(i==0)
		{
			cout << "YES";
			return 0;
		}
		else 
		{
			cout << "NO";
			return 0;
		}
	}
	cout << "YES";
	return 0;
}


Measured memory_bytes: 384
#!/usr/bin/env python3
from collections import Counter
n = int(input())
s = []
for _ in range(n):
    s.append(input())
a = Counter(s).most_common()
c = a[0][1]
ans = []
for i in a:
    if i[1] == c:
        ans.append(i[0])
ans = sorted(ans)
for j in ans:
    print(j)

Measured memory_bytes: 45044
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		MyScanner sc = new MyScanner();
		int d=sc.nextInt();
		System.out.println(d==25?"Christmas":d==24?"Christmas Eve":d==23?"Christmas Eve Eve":"Christmas Eve Eve Eve ");
	}
		
	//-----------http://codeforces.com/blog/entry/7018---------------------------------
	public static PrintWriter out;

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

	}
	//--------------------------------------------------------

}





Measured memory_bytes: 21972
# include <bits/stdc++.h>
# define ll long long
using namespace std;
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s;
	int ans = 0;
	cin >> s;
	for(int i = 0; i < s.size(); i ++){
		if(s[i] != s[s.size() - i - 1]) s[i] = s[s.size() - i - 1] = '0', ans ++;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(s) s.begin(),s.end()
using namespace std;

bool check(int num){
	int cnt=0;
	while(num/(int)pow(10,cnt)!=0)cnt++;
	bool res=true;
	int pre;
	for(int i=cnt-1;i>=0;i--){
		if(i==cnt-1)pre=num/(int)pow(10,i);
		else{
			if(num/(int)pow(10,i)!=pre+1){
				res=false;
				break;
			}
			pre=num/(int)pow(10,i);
		}
		num-=pre*(int)pow(10,i);
	}
	return res;
}

int main(){
	int n;
	cin>>n;
	int a[n];
	rep(i,n)cin>>a[i];
	vector<int> vec;
	rep(i,n)loop(j,i+1,n)vec.pb(a[i]*a[j]);
	sort(all(vec));
	bool tmp=true;
	for(int i=vec.size()-1;i>=0;i--){
		if(check(vec[i])){
			tmp=false;
			cout<<vec[i]<<endl;
			break;
		}
	}
	if(tmp)cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 4948
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
int a, b, c, d;

int main()
{
	scanf("%d %d %d %d", &a, &b, &c, &d);
	int A = min(a, b);
	int B = min(c, d);
	printf("%d\n", A + B);
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()

ans = set()
def rec(i, S):
    if S in ans:
        return
    if i == N:
        ans.add(S)
        return
    # 今までに出現した文字は全部追加できる
    for c in S:
        rec(i+1, S+c)
    # 今までに出現した中で最大の文字の次も追加できる
    rec(i+1, S+chr(ord(max(S))+1))
rec(1, 'a')
ans = sorted(ans)
[print(s) for s in ans]


Measured memory_bytes: 15748
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

const int MAX_N = 10002;
int n;
bool used[MAX_N];
vector<int> primes;

int main() {
  int twins[MAX_N];
  int twins_size = 0;
  fill(used, used + MAX_N, true);
  for (int i = 2; i < MAX_N; ++i) {
    if (used[i]) {
      primes.push_back(i);
      for (int j = i+i; j < MAX_N; j+=i) used[j] = false;
    }
  }
  for (int i = 1; i < primes.size(); ++i) {
    if (primes[i] - primes[i-1] == 2) {
      twins[twins_size] = primes[i];
      twins_size++;
    }
  }
  // int *a = lower_bound(twins, twins + twins_size, 11);
  // a--;
  // cout << *a << endl;
  while (cin >> n, n) {
    if (binary_search(twins, twins + twins_size, n)) {
      cout << n-2 << " " << n << endl;
    } else {
      int *a = lower_bound(twins, twins + twins_size, n);
      a--;
      cout << *a - 2 << " " << *a << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 936
#include <algorithm>
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

struct Restaurant {
  int id;
  string name;
  int point;

  Restaurant(int i, string n, int p) 
    : id(i), name(n), point(p) {}
  
  bool operator<(const Restaurant& rhs) {
    if (this->name != rhs.name) {
      return this->name < rhs.name;
    } else {
      return this->point > rhs.point;
    }
  }
};

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

  vector<Restaurant> restaurants;
  restaurants.reserve(N);
  for (int n = 1; n <= N; ++n) {
    string name;
    int point;
    cin >> name >> point;
    restaurants.push_back(Restaurant(n, name, point));
  }
  sort(restaurants.begin(), restaurants.end());
  
  for (const Restaurant& r : restaurants) {
    cout << r.id << endl;
  }
  
  return 0;
}


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

using namespace std;

using int64 = long long;

int64 mul(int a, int b) {
  int64 k = a;
  while(b--) k *= 2;
  return k;
}


int main() {
  int64 A, B, C, K;
  cin >> A >> B >> C >> K;
  int64 ret = 0;
  for(int i = 0; i <= K; i++) {
    for(int j = 0; i + j <= K; j++) {
      int k = K - i - j;
      ret = max(ret, mul(A, i) + mul(B, j) + mul(C, k));
    }
  }
  cout << ret << endl;
}


Measured memory_bytes: 256
def resolve():
    S = str(input())
    N = len(S)

    one = False
    pt = 0
    ans = 0

    while pt < N:
        if (pt == N - 2 and S[pt] == S[pt + 1]):
            ans += 1
            break

        if (one and S[pt] == S[pt - 1]):
            ans += 1
            pt += 2
            one = False
        else:
            ans += 1
            pt += 1
            one = True

    print(ans)

    return

resolve()

Measured memory_bytes: 9364
import java.util.Scanner;

public class Main {
	 public static void main(String[] args)
	 {
		 int a,b,c,tmp;
         Scanner std = new Scanner(System.in);
    
        
          a = std.nextInt();
          b = std.nextInt();
          c = std.nextInt();
          
         if(a>b){
        	 tmp=a;
        	 a=b;
        	 b=tmp;
         }
         if(b>c){
        	 tmp=b;
        	 b=c;
        	 c=tmp;
         }
         if(a>b){
        	 tmp=a;
        	 a=b;
        	 b=tmp;
         }
        	 System.out.println(a+" "+b+" "+c);
        	 
         
         std.close();
	 }
	 }
	 




Measured memory_bytes: 26204
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
#define pow_10_5 100000
#define pow_10_9 1000000000

// ---
const int Qlim = 2*pow_10_5;
int N, Q;
string s;
char t[Qlim], d[Qlim];

bool leftOut(int pos){
    rep(i,Q){
        if(s[pos]==t[i]){
            if(d[i]=='L'){
                pos--;
                if(pos<0) return true;
            } 
            else{
                pos++;
                if(pos>N-1) return false;
            }
        }
    }
    return false;
}

bool rightOut(int pos){
    rep(i,Q){
        if(s[pos]==t[i]){
            if(d[i]=='L'){
                pos--;
                if(pos<0) return false;
            } 
            else{
                pos++;
                if(pos>N-1) return true;
            }
        }
    }
    return false;
}

int Ans(){
    int ans=N;
    
    // [l,r)
    if(leftOut(0)){
        int l=0,r=N;
        while(l+1!=r){
            int m = (l+r)/2;
            if(leftOut(m)){
                l = m;
            }
            else{
                r = m;
            }
        }
        ans -= l+1;
    }

    // (l,r]
    if(rightOut(N-1)){
        int l=-1,r=N-1;
        while(l!=r-1){
            int m = (l+r)/2;
            if(rightOut(m)){
                r = m;
            }
            else{
                l = m;
            }
        }
        ans -= N-r;
    }
    return ans;
}

int main() {
    cin >> N >> Q;
    cin >> s;
    rep(i,Q) {cin >> t[i] >> d[i];}
    int ans = Ans();
    cout << ans << endl;
    return 0;
}

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

int main()
{
    string S;
    cin >> S;

    if (S.length() == 2)
    {
        cout << S << endl;
        return 0;
    }
    else
    {
        std::reverse(S.begin(), S.end());
        cout << S << endl;
    }
}

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

using namespace std;

namespace FastIO {
struct Strs {
  char strs[10000 * 4];
  constexpr Strs() : strs() {
    for (int i = 0; i < 10000; ++i) {
      int j = i;
      for (int t = 3; t >= 0; --t) {
        strs[i * 4 + t] = j % 10 + '0';
        j /= 10;
      }
    }
  }
} constexpr strs;
static constexpr size_t buf_size = 1 << 9;
char buf_in[buf_size], buf_out[buf_size];
size_t pt_in = 0, pt_out = 0, tail_in = 0;
inline size_t num_digits(long long x) {
  if (x >= (long long)1e9) return 10;
  if (x >= (long long)1e8) return 9;
  if (x >= (long long)1e7) return 8;
  if (x >= (long long)1e6) return 7;
  if (x >= (long long)1e5) return 6;
  if (x >= (long long)1e4) return 5;
  if (x >= (long long)1e3) return 4;
  if (x >= (long long)1e2) return 3;
  if (x >= (long long)1e1) return 2;
  return 1;
}
inline void load() {
  memcpy(buf_in, buf_in + pt_in, tail_in - pt_in);
  size_t width = tail_in - pt_in;
  tail_in = width + fread(buf_in + width, 1, buf_size - width, stdin);
  pt_in = 0;
}
inline void flush() {
  fwrite(buf_out, 1, pt_out, stdout);
  pt_out = 0;
}
inline void scan(char& c) { c = buf_in[pt_in++]; }
template <class T>
inline void scan(T& x) {
  char c;
  x = 0;
  scan(c);
  while (c >= '0') {
    x = x * 10 + (c & 15);
    scan(c);
  }
}
inline void print(char c) { buf_out[pt_out++] = c; }
template <class T>
inline void print(T x) {
  if (pt_out > buf_size - 32) flush();
  if (x < 0) {
    print('-');
    x = -x;
  }
  size_t digits = num_digits(x);
  int i;
  for (i = pt_out + digits - 4; i > (int)pt_out; i -= 4) {
    memcpy(buf_out + i, strs.strs + (x % 10000) * 4, 4);
    x /= 10000;
  }
  memcpy(buf_out + pt_out, strs.strs + x * 4 + (pt_out - i), 4 + i - pt_out);
  pt_out += digits;
}
inline void print(const char* s) {
  for (int i = 0; s[i] != 0; ++i) print(s[i]);
}
template <class T>
inline void println(T x) {
  print(x);
  print('\n');
}
struct SetUp {
  SetUp() { load(); }
  ~SetUp() { flush(); }
} setup;
}  // namespace FastIO

using FastIO::print;
using FastIO::println;
using FastIO::scan;

int main() {
  int N;
  scan(N);
  int ct = 0;
  char t;
  while (N--) {
    char l, r;
    scan(l);
    FastIO::pt_in++;
    scan(r);
    FastIO::pt_in++;
    if (l == r) {
      ct++;
      if (ct >= 3) {
        println("Yes");
        return 0;
      }
    } else {
      ct = 0;
    }
  }
  println("No");
  return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,a,b;
    cin >> n >> a >> b;
    string s;
    cin >> s;
    int dom=0,ove=0;
    REP(i,n){
        if(s[i]=='a'){
            if(dom+ove < a+b){
                cout << "Yes" << endl;
                dom++;
            }else{
                cout << "No" << endl;
            }
        }
        else if(s[i]=='b'){
            if(dom+ove < a+b && ove < b){
                cout << "Yes" << endl;
                ove++;
            }else{
                cout << "No" << endl;
            }
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    string n;
    ll s= 0;

    cin>> n;

    for (auto x: n)
    s+= (x- '0');

    cout << (s% 9== 0? "Yes\n" : "No\n");


    return 0;
}




Measured memory_bytes: 3768
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>

// using boost::multiprecision::cpp_int;
using namespace std;

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<ll, ll> p;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;

  char before = '@';
  ll res = 0;
  for(auto a : s){
    if(a != before){
      res++;
      before = a;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 512
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			String str = scanner.nextLine();
			if (str.equals("0"))
				break;
			StringTokenizer tokenizer = new StringTokenizer(str);
			int i = tokenizer.countTokens();
			int sum = 0;
			int a = 0;
			while (i-- > 0) {
				int num = Integer.parseInt(tokenizer.nextToken());
				if (num > 10) {
					num = 10;
				} else if (num == 1) {
					a++;
				}
				sum += num;
			}
			if (sum > 21) {
				System.out.println(0);
			} else {
				if (a > 0) {
					if (sum < 12) {
						sum += 10;
					}
				}
				System.out.println(sum);
			}
		}
	}
}

Measured memory_bytes: 18344
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    when {
        n <= 9 -> print(n)
        n <= 99 -> print(9)
        n <= 999 -> print(9 + (n - 99))
        n <= 9999 -> print(9 + 900)
        n <= 99999 -> print(9 + 900 + (n - 9999))
        else -> print(90909)
    }
}


Measured memory_bytes: 31860
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int H, W;
  cin >> H >> W;
  string row;

  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
  
  for (int i = 0; i < H; i++) {
    cin >> row;
    cout << '#' + row + '#' << endl;
  }
  
  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
}

Measured memory_bytes: 256
import sys
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
from collections import deque
from bisect import bisect_left
from itertools import product
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
#文字列を一文字ずつ数字に変換、'5678'を[5,6,7,8]とできる
def LSI(): return list(map(int, list(sys.stdin.readline().rstrip())))
def LSI2(N): return [list(map(int, list(sys.stdin.readline().rstrip()))) for i in range(N)]
#文字列として取得
def ST(): return sys.stdin.readline().rstrip()
def LST(): return sys.stdin.readline().rstrip().split()
def LST2(N): return [sys.stdin.readline().rstrip().split() for i in range(N)]
def FILL(i,h): return [i for j in range(h)]
def FILL2(i,h,w): return [FILL(i,w) for j in range(h)]
def FILL3(i,h,w,d): return [FILL2(i,w,d) for j in range(h)]
def FILL4(i,h,w,d,d2): return [FILL3(i,w,d,d2) for j in range(h)]
def sisha(num,digit): return Decimal(str(num)).quantize(Decimal(digit),rounding=ROUND_HALF_UP)
#'0.01'や'1E1'などで指定、整数に戻すならintをかます
MOD = 1000000007
INF = float("inf")
sys.setrecursionlimit(10**6+10)

N = I()
A = LI()
one = 0
two = 0
three = 0
for a in A:
    if a==1:
        one += 1
    elif a==2:
        two += 1
    elif a==3:
        three += 1

dp = FILL3(0.0,N+2,N+2,N+2)
dp[0][0][0] = 0
for  k in range(0,three+1):
    for j in range(0,two+three-k+1):
        for i in range(0,one+two+three-k-j+1):
            if i==j==k==0:
                continue
            zero = N-i-j-k
            p_0 = zero/N
            p_1 = i/N
            p_2 = j/N
            p_3 = k/N
            ret = 1
            if i>0:
                ret += p_1*dp[i-1][j][k]
            if j>0:
                ret += p_2*dp[i+1][j-1][k]
            if k>0:
                ret += p_3*dp[i][j+1][k-1]
            ret /= 1-p_0
            dp[i][j][k] = ret

print(dp[one][two][three])


Measured memory_bytes: 268384
#include<bits/stdc++.h>
using namespace std;
#define PI          acos(-1)
#define INF         0x3f3f3f3f
#define sc(n)       scanf("%d",&n);
#define lsc(n)      scanf("%lld",&n);
#define dsc(n)      scanf("%lf",&n);
#define LL          long long int
#define UI          unsigned int
#define ULL         unsigned long long int
#define DB          double
#define pii         pair<int,int>
#define PB          push_back
#define MP          make_pair
#define M(mx,a)     mx=max(mx,a)
#define IT          ::iterator
#define all(a)      a.begin(),a.end()
#define mems(a,b)   memset(a,b,sizeof(a))
#define ARC(n)      for(i=0;i<n;i++)
#define ASC(n,aa)   for(i=0;i<n;i++)scanf("%lld",&aa[i]);
#define PNT(n,aa)   for(i=0;i<n;i++)printf("%lld ",aa[i]);
#define mod         1000000007
#define NUM         100050
#define NUM2        1000000000

class node
{
public:
    LL a=0,mx=0;
    char c;
};
bool cmp(node aa,node bb)
{
    return aa.a<bb.a;
}
int main()
{
    int T=1,QQ=0;
    //cin >> T ;
    while(T--)
    {
        int n,k,i,j;
        cin >> n >> k ;
        node aa[n],pp[n],nn[n] ;
        LL jj;
        for(i=0;i<n;i++)
        {
            lsc(jj);
            if(jj>0)aa[i].a=jj,aa[i].c='+';
            else aa[i].a=-jj,aa[i].c='-';
        }
        sort(aa,aa+n,cmp);
        LL pos=0,neg=0,ans=1e18,pc=0,nc=0;
        for(i=0;i<n;i++)
        {
            if(aa[i].c=='+')
            {
                pos=max(pos,aa[i].a);
                pp[pc++].mx=pos;
                if(pc+nc>=k && pc<k)
                {
                    ans=min(ans,pp[pc-1].mx*2+nn[k-pc-1].mx);
                    ans=min(ans,pp[pc-1].mx+2*nn[k-pc-1].mx);
                }
                if(pc==k)ans=min(ans,pos);

            }
            else
            {
                neg=max(neg,aa[i].a);
                nn[nc++].mx=neg;
                if(pc+nc>=k && nc<k)
                {
                    ans=min(ans,nn[nc-1].mx*2+pp[k-nc-1].mx);
                    ans=min(ans,nn[nc-1].mx+2*pp[k-nc-1].mx);
                }
                if(nc==k)ans=min(ans,neg);
            }
        }
        cout << ans ;
    }
}
//printf("Case %d: ",++QQ);


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

typedef long long ll;

ll n, ans = 1e13;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (ll i = 1; i * i <= n; i++)
		if (n % i == 0)
			ans = min(ans, i - 1 + (n / i) - 1);
	cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cmath>
#define LL long long
#define N 1000001
#define NN 2002
using namespace std;
LL a,b,c,d,i;
LL f[N];
int main()
{
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	f[1]=a*c,f[2]=a*d,f[3]=b*c,f[4]=b*d;
	printf("%lld",max(f[1],max(f[2],max(f[3],f[4]))));
	return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	const int N = 100000;
	int n; cin >> n;
	vector<int> v(n + 1), w(n + 1);
	for (int i = 1; i <= n; i++) cin >> v[i] >> w[i];
	int m = min(n, 511);
	vector<vector<long long>> f(m + 1, vector<long long>(N + 1, 0));
	for (int i = w[1]; i <= N; i++) f[1][i] = v[1];
	for (int i = 2; i <= m; i++) {
		for (int j = 1; j <= N; j++) {
			f[i][j] = max(f[i][j - 1], f[i >> 1][j]);
			if (j >= w[i]) f[i][j] = max(f[i][j], f[i >> 1][j - w[i]] + v[i]);
		}
	}
	function<long long(int, int)> solve = [&](int id, int l) {
		if (l <= 0) return 0ll;
		if (id <= m) return f[id][l];
		long long ans = solve(id / 2, l);
		if (l >= w[id]) ans = max(ans, solve(id / 2, l - w[id]) + v[id]);
		return ans;
	};
	int q; cin >> q;
	while (q--) {
		int id, l; cin >> id >> l;
		cout << solve(id, l) << "\n";
	}
	return 0;
}


Measured memory_bytes: 407372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define reps(i,n) for(int i = 1; i <= (int)(n); i++)
#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)
#define rreps(i,n) for(int i = (int)(n); i > 0; i--)
#define FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
template <class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = INT_MAX;
const int MOD = 1000000007;

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

int main() {
    int H, W;
    cin >> H >> W;
    vs field(H);
    rep(y, H) cin >> field[y];
    
    vvi dist(H, vi(W, -1));
    queue<int> qy, qx;
    dist[0][0] = 0;
    qy.push(0); qx.push(0);

    while (!qy.empty()) {
        int y = qy.front(), x = qx.front();
        qy.pop(); qx.pop();
        rep(i, 4) {
            int ny = y + dy[i], nx = x + dx[i];
            if (ny < 0 || H <= ny || x < 0 || W <= nx) continue;
            if (dist[ny][nx] != -1) continue;
            if (field[ny][nx] == '#') continue;
            dist[ny][nx] = dist[y][x] + 1;
            qy.push(ny); qx.push(nx);
        }
    }
    
    int min_dist = dist[H-1][W-1];
    if (min_dist == -1) {
        cout << min_dist << endl;
        return 0;
    }
    int n_white = 0;
    rep(y, H) {
        n_white += count(field[y].cbegin(), field[y].cend(), '.');
    }
    int ans = n_white - (min_dist + 1);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<set>
using namespace std;
int a,b,bj=0;
int main() {
	cin>>a>>b;
	if((!((a+b)%3))||(!(b%3))||(!(a%3)))puts("Possible");
	else puts("Impossible");
	return 0;
}

Measured memory_bytes: 256
{-# LANGUAGE FlexibleContexts, OverloadedStrings #-}
import Control.Applicative
import Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace

solve s = ('N' `elem` s) == ('S' `elem` s) && ('W' `elem` s) == ('E' `elem` s)

main = do
  s <- getLine
  putStrLn $ if solve s then "Yes" else "No"


-- util
getInts :: IO [Int]
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine

substr :: Int -> Int -> B.ByteString -> B.ByteString
substr b l s = B.take l $ B.drop b s


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

using namespace std;

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

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define VEC vector

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				Vint;
typedef vector<Vint>			VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		400010

const ll LINF = (ll)9e18+7;		//
const int INF = 100100100;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//

// int DP[MAX];

//
int main(){
	int A,B;cin >> A >> B;

	cout << (A-2*B > 0 ? A-2*B : 0) << endl;

	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int H, W;
string s[110];

const int MAX_V = 20100; //必要な頂点数
struct Flow{
    struct edge{
        int to, cap, rev;
    };
    vector<edge> G[MAX_V];//隣接リスト
    bool used[MAX_V];
 
    void add_edge(int from, int to, int cap){
        G[from].push_back((edge){to, cap, (int)G[to].size()});//from -> to
        G[to].push_back((edge){from, 0, (int)G[from].size() - 1});//to -> from
    }
    //増加パスを探す
    int dfs(int v, int t, int f){
        if(v == t) return f;
        used[v] = true;
        for (int i = 0; i < G[v].size(); ++i){
            edge &e = G[v][i];
            if(!used[e.to] && e.cap > 0){
                int d = dfs(e.to, t, min(f, e.cap));
                if(d > 0){
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    //sからtへの最大流
    int max_flow(int s, int t){
        int flow = 0;
        while(1){
            memset(used, 0, sizeof(used));
            int f = dfs(s, t, INF);
            if(f == 0) return flow;
            flow += f;
        }
    }
};

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

int main(void) {
	scanf("%d %d", &H, &W);
	rep(i, H) cin >> s[i];
	int start = 2 * (H * W) + 1, goal = 2 * (H * W) + 2;
	int N = H * W;

	bool flag = false;
	rep(i, H)rep(j, W){
		if((i == 0 || i == H - 1 || j == 0 || j == W - 1) && s[i][j] == 'X')
			flag = true;
	}
	if(flag){
		printf("-1\n"); return 0;
	}

	Flow fw;
	rep(i, H)rep(j, W){
		int u = i * W + j;
		if(s[i][j] == 'X') {
			fw.add_edge(start, u, INF);
			fw.add_edge(u, u + N, INF);
		}else{
			fw.add_edge(u, u + N, 1);
		}
		if(i == 0 || i == H - 1 || j == 0 || j == W - 1){
			fw.add_edge(u + N, goal, INF);
		}
	}
	rep(i, H)rep(j, W)rep(k, 4){
		int y = i, x = j;
		int ny = y + dy[k], nx = x + dx[k];
		if(!(0 <= ny && ny < H && 0 <= nx && nx < W)) continue;
		int u = y * W + x, v = ny * W + nx;
		fw.add_edge(N + u, v, INF);
	}

	int ret = fw.max_flow(start, goal);
	printf("%d\n", ret);
	return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
    int n;
    cin>>n;
    ll a[n];
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    for(int i=0; i<n; i++){
        if(a[i]==0){
            cout<< "0"<<endl;
            return 0;
        }
    }
    ll p=1;
    for(int i=0; i<n; i++){
        if(a[i]<=1000000000000000000/p){
            p*=a[i];
        }
        else{
            cout<< "-1"<<endl;
            return 0;
        }



    }
    cout<<p<<endl;


}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(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 Pl = 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);

  ll a;
  cin >> a;
  ll ans = infll;
  for(ll x = 1; x*x <= a; x++){
    ll y = a / x;
    if(a % y != 0) continue;
    ll tmp = (y-1) + (x-1);
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

int m;
char s[50];

int main(){
	int n=read(),ans=0;
	poly cnt(3);
	For(i,1,n){
		scanf("%s",s+1),m=strlen(s+1);
		FOR(j,1,m) ans+=s[j]=='A'&&s[j+1]=='B';
		if (s[1]=='B'&&s[m]=='A') ++cnt[0];
		else if (s[1]=='B') ++cnt[1];
		else if (s[m]=='A') ++cnt[2];
	}
	if (cnt[0]){
		if (cnt[1]) --cnt[1],++ans;
		if (cnt[2]) --cnt[2],++ans;
		ans+=cnt[0]-1;
	}
	ans+=min(cnt[1],cnt[2]),printf("%d\n",ans);
}

Measured memory_bytes: 3772
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
sys.setrecursionlimit(10**7)
from pprint import pprint as pp
from pprint import pformat as pf

import math
#from sortedcontainers import SortedList, SortedDict, SortedSet # no in atcoder
import bisect


if __name__ == '__main__':
    n, m = list(map(int, input().split()))
    a_list = list(map(int, input().split()))
    s = sum(a_list)
    if n >= s:
        print(n - s)
    else:
        print(-1)

    #print('\33[32m' + 'end' + '\033[0m') # debug


Measured memory_bytes: 69072
#include <bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
typedef long long ll;
using namespace std;

int a[100];

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m, sm = 0;
    cin >> n >> m;
    FOR(i, 0, n) {
        cin >> a[i];
        sm += a[i];
    }
    int cnt = 0;
    FOR(i, 0, n) {
        if (sm <= 4 * m * a[i]) cnt++;
    }
    if (cnt >= m) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 256
"""
NTC here
"""
import sys
inp= sys.stdin.readline
input = lambda : inp().strip()
flush= sys.stdout.flush
# import threading
# setrecursionlimit(10**6)
# threading.stack_size(2**26)

def iin(): return int(input())
def lin(): return list(map(int, input().split()))

# range = xrange
# input = raw_input

def main():
    k, a, b = lin()
    ans = 1
    lf = max(0, k - a+1)
    lf1 = lf//2
    if lf:
        ans = a+lf1*(b - a) + lf%2
    else:
        ans += k
    print(max(ans, k+1))








        
main()
#threading.Thread(target=main).start()

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

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

using namespace std;

typedef long long ll;

ll n, k;

bool is_ok(ll x, vector<ll> a, vector<ll> f) {
  ll p = k;
  for (int i = 0; i < n; i++) {
    if ( x/f[i] < a[i] ) {
      p -= (a[i]-x/f[i]);
    }
  }
  return p >= 0;
}

int main() {
  cin >> n >> k;
  vector<ll> a(n), f(n);

  rep(i, n) { cin >> a[i]; }
  rep(i, n) { cin >> f[i]; }

  sort( a.begin(), a.end() );
  sort( f.begin(), f.end(), greater<ll>() );

  ll ok = 1e12+1;
  ll ng = -1;
  
  while ( abs(ok-ng) > 1 ) {
    ll mid = (ok+ng) / 2;

    if ( is_ok(mid, a, f) ) {
      ok = mid;
    } else {
      ng = mid;
    }
  }

  cout << ok << endl;

  return 0;
}

Measured memory_bytes: 6552
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define pb emplace_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define vll vector<ll>
#define fast ios:: sync_with_stdio(false),cin.tie(0);
#define COUT cout<<fixed<<setprecision(12)
#define SET set<ll,greater<ll>>gquiz
#define ITERATOR set<ll,greater<ll>> :: iterator itr
#define V vector<ll>vector
#define sz size()
#define A vector<pair<ll,ll>>vect
ll N=100000,M=100000;
#define B vect.push_back(make_pair(N,M));
ll MOD=1000000007;
 
ll gcd(ll a,ll b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
ll ncr(ll n,ll r)
{
	if(n==1 || r==0)
	return 1;
	if(r>n/2)
	r=n-r;
	ll ans=1;
	for(ll i=1;i<=r;i++)
	{
		ans=((ans * n )/i);
		n--;
	}
	return ans;
}
int main()
{
	ll n;
	cin>>n;
	if(n%2==1)
	cout<<(n/2)+1;
	else
	cout<<n/2;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  
  int W, H, x, y, r;
  
  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  if(W < x + r ){
    printf("No\n");
  }
  else if(H < y + r){
    printf("No\n");
  }
  else if(0 > x - r){
    printf("No\n");
  }
  else if(0 > y - r){
    printf("No\n");
  }
  else{
    printf("Yes\n");
  }

  return 0;
}

    


Measured memory_bytes: 1992