akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main()
{
    int n, sum = 0;
    char s[101];
    scanf("%d", &n);
    getchar();
    scanf("%s", s);
    for(int i=0;i<n;i++)
    {
    	if(i>0&&i<n-1)
    	{
    		if(s[i]=='B'&&s[i-1]=='A'&&s[i+1]=='C')
    		    sum++;
		}
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

func main() {
	N := nextInt()
	ans := map[string]int{}
	for i := 0; i < N; i++ {
		s := nextString()
		ans[s]++
	}
	cnt := 0
	for _, v := range ans {
		if v > 0 {
			cnt++
		}
	}
	fmt.Println(cnt)
}

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

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

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

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 18312
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int MAX = 5000;
const int maxnum = 10010;
bool V[MAX];

int n, A[MAX], s;
int B[MAX], T[maxnum];
int solve() {
	int ans = 0;

	// T??°???????????????????´????????????????????????????????????\??¨??????????????¢???
	for (int i = 0; i < n; i++)
		T[B[i]] = i;
	for (int i = 0; i < n; i++) {
		// ????????¨???????????¢????????¨??????
		if (V[i])
			continue;

		int cur = i;
		int S = 0, m = maxnum, an = 0;
		// ?????¢?????????
		while (!V[cur]) {
			V[cur] = true;
			// ?????¢?????°????´????
			an++;
			int v = A[cur];
			// ??????????????¢??????????°????
			m = min(m, v);
			S += v;
			// ?????¢??????????????????
			cur = T[v];
		}
		ans += min(S + (an - 2) * m, m + S + (an + 1) * s);
	}
	return ans;

}
int main() {

	scanf("%d", &n);
	s = maxnum;
	for (int i = 0; i < n; i++) {
		scanf("%d", &A[i]);
		s = min(s, A[i]);
		B[i] = A[i];
		V[i] = false;
	}
	sort(B, B + n);
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 3312
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;

int main(){
    string w; cin >> w;
    vector<int> cnt(27);
    bool flag = true;
    
    for(char c: w){
       cnt.at(c - 'a')++;
    }
    
    for(int i: cnt){
        if(i % 2 != 0){
            cout << "No" << endl;
            flag = false;
            break;
        }
        
    }
    if(flag){
        cout << "Yes" << endl;
    }
    
}

// GCC reference:
//   https://gcc.gnu.org/

// C++ language references:
//   https://cppreference.com/
//   https://isocpp.org/
//   http://www.open-std.org/jtc1/sc22/wg21/

// Boost libraries references:
//   https://www.boost.org/doc/



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    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;
}
// End of template code!
int main() 
{
    buff();
    vi v(5);
    rep(i, 0, 5) {
        cin >> v[i];
        if(v[i] == 0) {
            cout << i + 1 << '\n';
            return 0;
        }
    }

    return 0;
}



Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
int main() {
  int n,a[200000];
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
  }
  for(int i=n-1; i>=0; i-=2) {
    cout << a[i] << " ";
  }
  for(int i=n%2; i<n; i+=2) {
    cout << a[i] << " ";
  }
}

Measured memory_bytes: 2944
n = 101
rec = [0] * 101
num = 0
q = 1
for i in range(n):
    if i % 2 == 0:
        k = 0
        p = i
        while p % 2 == 0 and p > 1:
            p //= 2
            k += 1
        if k > num:
            num = k
            q = i
    rec[i] = q

print(rec[int(input())])

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

using namespace std;

struct UnionFind
{
	vector<int> data;

	UnionFind(int sz)
	{
		data.assign(sz, -1);
	}

	bool unite(int x, int y)
	{
		x = find(x), y = find(y);
		if(x == y) return(false);
		if(data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return(true);
	}

	int find(int k)
	{
		if(data[k] < 0) return(k);
		return(data[k] = find(data[k]));
	}

	int size(int k)
	{
		return(-data[find(k)]);
	}
};

int p[100000];

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

	int n, m;
	cin >> n >> m;
	UnionFind uf(n + 1);
	for(int i = 0; i < n; i++)cin >> p[i];
	for(int i = 0; i < m; i++)
	{
		int x, y;
		cin >> x >> y;
		uf.unite(x-1, y-1);
	}
	int ret = 0;
	for(int i = 0; i < n; i++)
	{
		if(uf.find(p[i]-1) == uf.find(i))ret++;
	}
	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long fib[100];
long long fibonacci(long long n)
{
    if(fib[n])
        return fib[n];
    if(n<=1) return n;
    return fib[n]=fibonacci(n-2)+fibonacci(n-1);
}

int main()
{
    long long n;
    cin>>n;
    fibonacci(n);
    cout<<fibonacci(n+1)<<endl;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    
    vector<int> storage(n);
    for( int i = 0; i < n; i++ ){
        cin >> storage[i];
    }
    
    
    int n2, apple, storage_number, order;
    vector<int> applenum(n);
    cin >> n2;
    for( int i = 0; i < n2; i++ ){
        
            cin >> order >> storage_number >> apple;
        
            if( order == 1 ){
                if( storage[storage_number - 1] < applenum[storage_number - 1] + apple ){
                    cout << storage_number << endl;
                    return  0;
                }
                applenum[storage_number - 1 ] += apple;
            }else{
                if( applenum[storage_number - 1] - apple < 0 ){
                    cout << storage_number << endl;
                    return 0;
                }
                applenum[storage_number - 1] -= apple;
            }
            
            
        
    }
    
    cout << 0 << endl;
    
    
}


Measured memory_bytes: 3120
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;

int main() {
	int n, k[100005], dp[100005];
	cin >> n;
	for (int i = 0; i < n; ++i) { cin >> k[i]; }
	dp[0] = 0;
	for (int i = 1; i < n; ++i) {
		dp[i] = dp[i - 1] + abs(k[i] - k[i - 1]);
		if (i != 1) { dp[i] = min(dp[i], dp[i - 2] + abs(k[i] - k[i - 2])); }
	}
	cout << dp[n - 1] << endl;
}

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

int main() {
  int r, d;
  vector<int> x(11);
  cin >> r >> d >> x.at(0);
  for(int i = 1; i < 11; i++) {
    x.at(i) = r * x.at(i-1) - d;
    cout << x.at(i)<< endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define MAXN 200005
#define REP(temp, init_val, end_val) for (int temp = init_val; temp <= end_val; ++temp)
#define REPR(temp, init_val, end_val) for (int temp = init_val; temp >= end_val; --temp)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> intpair;
int read(){
    int f = 1, x = 0;
    char c = getchar();
    while (c < '0' || c > '9'){if(c == '-') f = -f; c = getchar();}
    while (c >= '0' && c <= '9')x = x * 10 + c - '0', c = getchar();
    return f * x; 
}
inline int lowbit(int x){
    return x & (-x);
}
inline int modadd(int x, int y){
    return (x + y >= MOD ? x + y - MOD: x + y);
}
inline int sgn(int x){
    return (x < 0 ? -1: (x > 0 ? 1: 0));
}
template<typename T>
T gcd(T a, T b){
    return (!b) ? a: gcd(b, a % b);
}
int poww(int a, int b){
    int res = 1;
    while (b > 0){
        if (b & 1) res = 1ll * res * a % MOD;
        a = 1ll * a * a % MOD, b >>= 1;
    }
    return res;
}
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1};
const int ddx[] = {-1, -1, -1, 0, 0, 1, 1, 1}, ddy[] = {-1, 0, 1, -1, 1, -1, 0, 1};

/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/

int n, k, a[200005];
void init(){
    n = read(), k = read();
    REP(i, 1, n)
        a[i] = read();
}
void solve(){
    int l = 1, r = 1000000000;
    while (r > l){
        int mid = (l + r) >> 1;
        ll cnt = 0;
        REP(i, 1, n){
            cnt += (1ll * a[i] - 1) / mid;
        }
        if (cnt <= k) r = mid;
        else l = mid + 1;
    }
    printf("%d\n", l);    
}
int main(){
    init();
    solve();
    return 0;
}

Measured memory_bytes: 4436
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    if (a <= b) {
        cout << "unsafe" << endl;
    }
    else {
        cout << "safe" << endl;
    }
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define MAXN 100000
#define INF 2000000000
int h[MAXN];
int dp[MAXN];
int n,k;
int main() {
	int i,j;
	scanf("%d %d",&n,&k);
	for (i=0; i<n;i++) {
		scanf("%d",&h[i]);
	}
	dp[n-1]=0;
	dp[n-2]=abs(h[n-1]-h[n-2]);
	for (i=n-3; i>=0; i--) {
		dp[i]=INF;
		for (j=1; j<=k && i+j<n; j++) {
			dp[i]=min(dp[i],abs(h[i]-h[i+j])+dp[i+j]);
		}
	}
	printf("%d\n",dp[0]);
	return 0;
}

Measured memory_bytes: 4540
n,m = map(int,input().split(' '))
Result = [0]*n
i = 0
while i < m:
    a,b = map(int,input().split(' '))
    Result[a-1] += 1
    Result[b-1] += 1
    i += 1
ans = ''
for r in Result:
    ans += str(r) + '\n'
print(ans)

Measured memory_bytes: 3064
import sys
#import time
import copy
#from collections import deque, Counter, defaultdict
#from fractions import gcd
#import bisect
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
inf = 10**20
ri = lambda : int(input())
rs = lambda : input().strip()
rl = lambda : list(map(int, input().split()))
a,b=rl()
print(a*b)

Measured memory_bytes: 68208
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n, C;
ll d[30][30];
ll c[500][500];

vector<ll> solve(ll pos) {
	vector<ll> vp;
	FOR(k, 1, C + 1) {
		ll cost = 0;
		rep(i, n) {
			rep(j, n) {
				if ((i + j) % 3 == pos)cost += d[c[i][j] - 1][k - 1];
			}
		}
		vp.push_back(cost);
	}
	return vp;
}

int main() {
	cin >> n >> C;
	rep(i, C) {
		rep(j, C)cin >> d[i][j];
	}
	rep(i, n) {
		rep(j, n)cin >> c[i][j];
	}
	vector<vector<ll>> vvp;
	rep(i, 3)vvp.push_back(solve(i));
	ll ans = INF;
	rep(i, C) {
		rep(j, C) {
			rep(k, C) {
				if (i != j&&j != k&&i != k) {
					//cout << i << " " << j << " " << k << " " << vvp[0][i] + vvp[1][j] + vvp[2][k] << endl;
					ans = min(ans, vvp[0][i] + vvp[1][j] + vvp[2][k]);
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,t,a;
  cin>>n>>t;
  int ans=0,sum=0;
  for(int i=0;i<n;i++){
    cin>>a;
    if(sum<a){
      ans+=t;
    }else {
      ans+=(a+t-sum);
    }
    sum=t+a;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(float, input().split()))

dp = [[0]*3100 for _ in range(3100)]

N = int(input())
P = input_nums()

dp[0][0] = 1.0

for i in range(N):
    for j in range(i+1):
        dp[i+1][j+1] += dp[i][j] * P[i]
        dp[i+1][j] += dp[i][j] * (1-P[i])

res = 0.0
a = ((N+1)//2)
for j in range(a, N+1):
    res += dp[N][j]
print(res)


Measured memory_bytes: 265608
N=int(input())
evidence=[[[-1]*2 for i in range(N)]for j in range(N)]
for i in range (0,N):
    A=int(input())

    for j in range (0,A):
        [x,y]=list(map(int, input().split()))
        evidence[i][j]=[x,y]

for i in range (2**N):
    TF=[1]*N

    for j in range (N):
        if ((i>>j)&1):
            TF[N-j-1]=0
    
        #print(TF)

        STOP=0
        
        for k in range (0,N):

            if STOP==1:
                break
            if TF[k]==1: #k番目の人が正直者なら
                if STOP==1:
                    break
                for l in range (0,N): #k番目の人の発言を全部調べて
                    if STOP==1:
                        break
                    if evidence[k][l][1]==0: #誰かを不親切だと証言したなら
                        if TF[evidence[k][l][0]-1]!=0: #その人が正直者だったらアウト
                            STOP=1
                    if evidence[k][l][1]==1: #誰かを正直者だと証言したなら
                        if TF[evidence[k][l][0]-1]!=1: #その人が不親切だったらアウト
                            STOP=1
    
    if STOP==0:
        print(sum(TF))
        break

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

public class Main {

    public static void main(String[] args) {
        try {
            InputReader in;
            PrintWriter out;
            boolean useOutput = false;
            // if (System.getProperty("ONLINE_JUDGE") == null) useOutput = true;
            if (useOutput) {
                FileInputStream fin = new FileInputStream(new File("src/testdata.in"));
                in = new InputReader(fin);
                FileOutputStream fout = new FileOutputStream(new File("src/testData.out"));
                out = new PrintWriter(fout);
            } else {
                InputStream inputStream = System.in;
                in = new InputReader(inputStream);
                OutputStream outputStream = System.out;
                out = new PrintWriter(outputStream);
            }
            Solver solver = new Solver();
            solver.solve(in, out);
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static class Solver {

        public void solve(InputReader cin, PrintWriter cout) {
            try {
                int n = cin.nextInt(), w = cin.nextInt();
                long dp[] = new long[w + 1];
                Arrays.fill(dp, Long.MIN_VALUE);
                dp[0] = 0;
                for (int i = 0; i < n; ++i) {
                    int weight = cin.nextInt(), value = cin.nextInt();
                    for (int j = w - weight; j >= 0; --j) {
                        dp[j + weight] = Math.max(dp[j] + value, dp[j + weight]);
                    }
                }
                long res = Long.MIN_VALUE;
                for (long i : dp) {
                    res = Math.max(res, i);
                }
                cout.println(res);
            } catch (RuntimeException e) {
                e.printStackTrace();
                return;
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }

        }
    }

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

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

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

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

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

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

    }

}

Measured memory_bytes: 22228
n = int(input())

for _ in range(n):
    xa, ya, ra, xb, yb, rb = map(float, input().split())
    if xa - ra < xb - rb and xa + ra > xb + rb and ya - ra < yb - rb and ya + ra > yb + rb:
        print(2)
    elif xa - ra > xb - rb and xa + ra < xb + rb and ya - ra > yb - rb and ya + ra < yb + rb:
        print(-2)
    elif (xa - xb)**2 + (ya - yb)**2 <= (ra + rb)**2:
        print(1)
    else:
        print(0)



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

using namespace std;

int main() {
	int a,b;
	int d,r;
	double f;
	cin >> a >> b;
	d = a / b;
	r = a % b;
	f = (double)a/b;
	printf( "%d %d %.5f", d, r, f );
	return 0;
}

Measured memory_bytes: 3200
n=int(input())
routes=list(map(int,input().split()))
dp=[float("inf") for i in range(n)]
dp[0]=0
for i in range(n):
    for j in range(i+1,i+3):
        if j<n:
            dp[j]=min(dp[j],dp[i]+abs(routes[i]-routes[j]))
print(dp[-1])

Measured memory_bytes: 20512
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int result=0;
    for(int i=1;i<=n;i++){
        result+=i;
    }
    cout<<result<<endl;

    return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  string S;
  cin >> S;
  S.at(3) = '8';
  cout << S << endl;

  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;

#define int long long
typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int H, W;
int solve() {
  //if ((H%3 == 0) || (H%3 == 0)) return 0;
  int m = (1LL<<60);
  for (int x=1; x<=W-1; x++) {
    int c = x*H;
    int a = (W-x) * (H/2);
    int b = (W-x) * (H - (H/2));
    m = min(m, max(a, max(b, c)) - min(a, min(b, c)));
  }

  if (W>=3) {
    for (int x=1; x<=W-1; x++) {
      int l = (W-x)/2;
      int r = (W-x)-l;
      int c = x*H;
      int a = l*H;
      int b = r*H;
      m = min(m, max(a, max(b, c)) - min(a, min(b, c)));
    }
  }
  return m;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> H >> W;
  int m = solve();
  swap(H, W);
  m = min(m, solve());
  cout << m << "\n";
  return 0;
}


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

#define int long long
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 reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

#define D  double
typedef pair<D,int>T;
int N;
int X[1111],Y[1111],R[1111];
D dist[1111];
D INF=1e12;
D EPS=1e-9;

int table2[1111][1111];
D table[1111][1111];

signed main(){

    cin>>X[0]>>Y[0]>>X[1]>>Y[1];
    cin>>N;
    rep(i,N)cin>>X[i+2]>>Y[i+2]>>R[i+2];
    N+=2;

    rep(i,N)rep(j,N){
        table2[i][j]=(X[i]-X[j])*(X[i]-X[j])+(Y[i]-Y[j])*(Y[i]-Y[j]);
        table[i][j]=sqrt(1.0*table2[i][j]);
    }

    fill_n(dist,1111,INF);
    dist[0]=0;
    priority_queue<T,vector<T>,greater<T>>que;
    que.push(make_pair(0,0));
    while(que.size()){
        D d;
        int idx;
        tie(d,idx)=que.top();
        que.pop();
        if(dist[idx]!=d) continue;
 
        rep(i,N){
            int foo=table2[i][idx];
            int bar=R[i]+R[idx];
            D cost=d;
            if(foo>bar*bar) cost+=sqrt(1.0*foo)-bar;
            if(dist[i]<=EPS+cost)continue;
                dist[i]=cost;
                que.push(T(dist[i],i));
            
        }
    }
    printf("%.20f\n",dist[1]);
    return 0;
}


Measured memory_bytes: 21872
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
constexpr int INF = 1001001001;
using ll = long long;
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    
    vector<int> dp(n+10, INF);
    dp[0] = 0;
    rep(i, 1, n) {
        int m = INF;
        rep(j, 1, k+1) {
            if (i - j < 0)
                continue;
            m = min(m, dp[i-j] + abs(h[i-j] - h[i]));
        }
        dp[i] = m;
    }
    
    cout << dp[n-1] << endl;
    
    return 0;
}

Measured memory_bytes: 1024
N, K = map(int, input().split(" "))
expect = [(int(p) + 1) / 2 for p in input().split(" ")]
e_sum = 0
for i in range(0, K):
  e_sum += expect[i]
  
ans = e_sum
for i in range(K, N):
  e_sum += expect[i]
  e_sum -= expect[i - K]
  ans = max(ans, e_sum)

print(ans)

Measured memory_bytes: 23588
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

ll a[2000];
int main(){
	int n,k;scanf("%d%d",&n,&k);
	rep(i,n){
		scanf("%lld",&a[i]);
	}
	multiset<ll>se;
	rep(i,n){
		ll cnt=0;
		for(int j=i;j<n;j++){
			cnt+=a[j];
			se.insert(cnt);
		}
	}
	ll ans=0;
	for(int i=60;i>=0;i--){
		multiset<ll>se2;
		for(auto j:se){
			if(j>>i&1)se2.insert(j);
		}
		if(se2.size()>=k){
			ans+=1LL<<i;
			se=se2;
		}
	}
	cout<<ans<<endl;
}

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

int main() 
{
    int n;
    cin >> n;
    double a[n];
    rep(i,n) cin >> a[i];

    double ans = 0.0;
    rep(i,n) ans += 1.0/a[i];
    ans = 1.0 / ans;

    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 256
def main():
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())
    k = int(input())
    if e - a > k:
        print(":(")
    else:
        print("Yay!")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
#define lli long long int
int main(int argc, char **argv)
{
	lli a,b;
	string c;
	cin>>a;
	cin>>c;
	cin>>b;
	if(c=="+"){
		cout<<a+b<<endl;}
		else{
			cout<<a-b<<endl;}
	return 0;
}

Measured memory_bytes: 256
n,c,k = [int(x) for x in input().split()]
t = []
for _ in range(n):
    t.append(int(input()))
t.sort()

ans = 0
tmp = {"f": 0, "num": c}

for x in t:
    if tmp["f"] >= x and tmp["num"] > 0:
        tmp["num"] -= 1
    else:
        ans += 1
        tmp["num"] = c-1
        tmp["f"] = x+k


print(ans)


Measured memory_bytes: 7384
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector<int> a(n); std::cin>>a;
  debug(a);

  lint ans = 0;
  int now = 0;
  int r = 0;
  rep(l,0,n) {
    while (r < n) {
      int y = a.at(r);
      if (now&y) break;
      now |= y;
      r++;
    }
    ans += r - l;
    debug(std::vector<int>(a.begin()+l,a.begin()+r));
    now ^= a.at(l);
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>

using namespace std;

template <class T>
void print_vec(const vector<T>& v) {
  for (auto t = begin(v); t != end(v);) {
    cout << *t;
    if (++t != end(v)) {
      cout << " ";
    }
  }
  cout << endl;
}

tuple<vector<int>, int> selectionSort(const vector<int>& a, const int& n) {
  vector<int> ret = a;
  int count = 0;
  int ms;
  for (int i = 0; i < n; i++) {
    ms = i;
    for (int j = i; j < n; j++) {
      if (ret[j] < ret[ms]) {
        ms = j;
      }
    }
    swap(ret[i], ret[ms]);
    if (ret[i] != ret[ms]) {
      count++;
    }
  }
  return make_tuple(ret, count);
}

int main(int ac, char **av) {
  int n;
  while (cin >> n, n) {
    vector<int> a;
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      a.push_back(x);
    }
    auto ret = selectionSort(a, n);
    print_vec(get<0>(ret));
    cout << get<1>(ret) << endl;
    n = 0;
  }
  return 0;
}

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

int main(){
	int a, b;
	string s;
	cin>>a>>b;
	cin>>s;
	for(int i=0; i<a; i++){
		if(s[i]<'0' || s[i]>'9'){
			cout<<"No"<<endl;
			return 0;
		}
	}
	if(s[a]!='-'){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=a+1; i<a+b+1; i++){
		if(s[i]<'0' || s[i]>'9'){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}


Measured memory_bytes: 256
s=input()
count_1=0
count_2=0
p=0
for i in range(0,len(s)):
    if (s[i]=='0' and p==0) or (s[i]=='1' and p==1):
        if(p==0):
            p=1
        elif(p==1):
            p=0
        continue
    else:
        if(p==0):
            p=1
        elif(p==1):
            p=0
        count_1=count_1+1
p=1
for i in range(0,len(s)):
    if (s[i]=='0' and p==0) or (s[i]=='1' and p==1):
        if(p==0):
            p=1
        elif(p==1):
            p=0
        continue
    else:
        if(p==0):
            p=1
        elif(p==1):
            p=0
        count_2=count_2+1
print(min(count_1,count_2))


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

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

using namespace std;

int main(void){
  int n, k;
  cin >> n >> k;

  vector<ll> h(n);
  rep(i, n) cin >> h[i];

  if(!is_sorted(h.begin(), h.end())){
    sort(h.begin(), h.end());
  }
  
  ll ans = 0;
  rep(i, n-k){ans += h[i];}

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

Measured memory_bytes: 1792
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

n,t = inp
tt= na2(n,2)
a = na(n)
b = na(n)
n.times do |i|
  tt[i] = inp
end
tt.sort_by!{|u|u[0]}
n.times do |i|
  a[i],b[i] = tt[i]
end
ans = 0
dp = na(t+1)
l = dp.size-1
n.times do |i|
  ans = [ans,dp[-2]+b[i]].max
  next if(a[i] > t)
  l.downto(a[i]) do |j|
    buf = dp[j-a[i]]+b[i]
    dp[j] = buf if dp[j] < buf
  end
end
p ans

Measured memory_bytes: 2296
#include<cstdio>

int main(void){
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);
	if(A == B)
		printf("%d\n", C);
	else if(C == A)
		printf("%d\n", B);
	else
		printf("%d\n", A);
	return 0;
}

Measured memory_bytes: 128
def solve():
    K, S = map(int, input().split())
    
    c = 0
    for x in range(K+1):
        for y in range(K+1):
            if 0 <= S-(x+y) <= K:
                z = S-(x+y)
                if x+y+z == S:
                    c += 1
    return c

print(solve())


Measured memory_bytes: 2940
/* 	* In the name of GOD 
	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second

int32_t main(){
	int m, d;
	cin >> m >> d;
	int ans = 0;
	for (int i = 1; i <= m; i++){
		for (int j = 10; j <= d; j++){
			string s = to_string(j);
			int mul = 1;
			for (int k = 0; k < 2; k++){
				mul *= (s[k] - '0');
			}
			if (mul == i && s[0] >= '2' && s[1] >= '2'){
				ans ++;
//				cout << i << ' ' << j << endl;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3732
H, W, K = map(int, input().split())
c = []
for k in range(H):
    c.append(input())
"""
total = 0
for k in range(H):
    for j in range(W):
        if c[k][j] == '#':
            total +=1
"""
ans =0
for w in range(2**W):
    binw = str(bin(w))[2:]
    binw = "0"*(W-len(binw)) + binw
    for h in range(2**H):
        binh = str(bin(h))[2:]
        binh = "0"*(H-len(binh)) + binh 
        count = 0
        for k in range(H):
            for j in range(W):
                if binw[j] == '0' and binh[k] == '0':
                    if c[k][j] == '#':
                        count+=1
        if count == K:
            #print(binw, binh)
            ans +=1
print(ans)
                

Measured memory_bytes: 9076
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second 
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert

const int MAX = INT_MAX;

int main() {
	
	int x;
	cin>>x;
	printf("%d\n", x == 1 ? 0 : 1);
	return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdbool.h>

#define limit_input_char_num (200)
#define limit_dataset_num (10)

//#define DEBUG_BUILD

#ifdef DEBUG_BUILD
# define DEBUG_PRINT(fmt, ...)  printf(fmt, ## __VA_ARGS__)
# define DEBUG_F_PRINT(fp,fmt, ...)  fprintf(fp,fmt, ## __VA_ARGS__)
#else
# define DEBUG_PRINT(fmt, ...)
# define DEBUG_F_PRINT(fmt, ...)
#endif

#ifdef DEBUG_BUILD
FILE *fp;
#endif

void shufflePrint(char str[],int shuffleCharNum);

int main(void) {
	char input[limit_input_char_num+1];

#ifdef DEBUG_BUILD
	fp=fopen("output.txt","w");
#endif

	while(1){
		memset(input,0,sizeof(input));
		int shuffleCount=0;
		//最初の並びを表す文字列
		scanf("%s",input);
		// - だけなら終了
		if(strcmp(input,"-")==0){
			break;
		}
		//シャッフル回数 m
		scanf("%d",&shuffleCount);
		int shuffleSum=0;
		for(int i=0;i<shuffleCount;i++){
			int num=0;
			scanf("%d",&num);
			shuffleSum+=num;
		}
		DEBUG_PRINT("len=%d sum=%d\n",(int)strlen(input),shuffleSum);
		shufflePrint(input,shuffleSum);

	}
#ifdef DEBUG_BUILD
	fclose(fp);
#endif
	return 0;
}

void shufflePrint(char str[],int shuffleCharNum){
	int strLength=strlen(str);
	char strShuffled[strLength+1];
	memset(strShuffled,0,sizeof(strShuffled));
	shuffleCharNum%=strLength;

	DEBUG_PRINT("len=%d shfNum=%d\n",strLength,shuffleCharNum);

	strncpy(strShuffled,str+shuffleCharNum,strLength-shuffleCharNum);
	strncpy(strShuffled+strLength-shuffleCharNum,str,shuffleCharNum);

	DEBUG_PRINT("before %c [%d]\n",*(str+shuffleCharNum),strLength-shuffleCharNum);
	DEBUG_PRINT("after  %c [%d]\n",*str,shuffleCharNum);

	printf("%s\n",strShuffled);
	DEBUG_F_PRINT(fp,"%s\n",strShuffled);

}



Measured memory_bytes: 2052
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
if sum(A)>sum(B):
    ans='No'
else:
    c=0
    d=0
    for a,b in zip(A,B):
        if a<b:
            d+=(b-a)//2+(b-a)%2
            c+=(b-a)%2
        else:
            c+=a-b
    if d>=c:
        ans='Yes'
    else:
        ans='No'
print(ans)

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

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

using ll = int64_t;

using namespace std;

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

    int64_t a;cin >> a;
    cout << a + a * a + a * a * a << '\n';
    
} 



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

int main(){
    while(true){
        int n;
        map<char,char> ctable; 
        cin >> n;
        if(n == 0) break;
        char tA, tB;
        for(int i = 0; i < n; i++){
            cin >> tA >> tB;
            ctable[tA] = tB;
        }
        cin >> n;
        for(int i = 0; i < n; i++){
            cin >> tA;
            map<char,char>::iterator itr = ctable.find(tA);
            if(itr != ctable.end()) cout << ctable[tA];
            else cout << tA;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,c=0,a[100];
    cin>>n;
    for(i=0;i<n;i++)
        cin>>a[i];
    for(i=1;i<n-1;i++)
    {
        if((a[i-1]<=a[i]&&a[i+1]>=a[i])||
           (a[i-1]>=a[i]&&a[i+1]<=a[i]))
        {
            c++;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3596
import time
startTimeProblem=time.time()

import fileinput, sys, itertools, functools
from math import *
from bisect import *
from heapq import *
from collections import *

def lcm(a, b):  
    return (a*b)/gcd(a, b)

class InputHelper:
    def __init__(self):
        self.myinput = fileinput.input()

    def isLocal(self):
        return not fileinput.isstdin()

    def int(self):
        return int(self.myinput.readline().rstrip())

    def ints(self):
        return [int(_) for _ in self.myinput.readline().rstrip().split()]

    def str(self):
        return self.myinput.readline().rstrip()

    def strs(self):
        return [_ for _ in self.myinput.readline().rstrip().split()]

class OutputHelper:
    def int(self, a):
        print(a)    

    def ints(self, a):  
        print(" ".join([str(_) for _ in a]))
    
    def intsNL(self, a):
        for _ in a:
            print(_)
    
    def str(self, s):
        print(s)

    def strs(self, s):
        print(" ".join([_ for _ in s]))

    def strsNL(self, s):
        for st in s:
            print(st)

class ListNode:
    def __init__(self, val):
        self.val = val
        self.next = None
        self.prev = None

In = InputHelper()
Out = OutputHelper()

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

N = In.int()

seen = set()
for _ in range(N):
    S = In.str()

    if S not in seen:
        seen.add(S)

Out.int(len(seen))

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

if len(sys.argv)>2 and sys.argv[2]=="TIMEIT":
    fin = (time.time()-startTimeProblem)*1000
    print("{:.2f}".format(fin) + "ms")

Measured memory_bytes: 86432
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<functional>
#include<map>
#include<deque>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PIPII pair<int, pair<int, int> >
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define ctoi(x) (x - 'a') 
#define CTOI(x) (x - 'A')
#define BIT(x) (1 << (x))
using namespace std;
int main(){
    int N, Q;
    cin >> N >> Q;
    // time pos uniq
    priority_queue<PIPII, vector<PIPII>, greater<PIPII> > que;
    REP(i, N){
        int a, b, c;
        cin >> a >> b >> c;
        PIPII d;
        d.first = a - c;
        d.second.first = c;
        d.second.second = i;
        que.push(d);
        d.first = b - c;
        d.second.first = c;
        d.second.second = i;
        que.push(d);
    }
    vector<int> used(N, 0);
    priority_queue<PII, vector<PII>, greater<PII> > nq;
    REP(i, Q){
        int d;
        cin >> d;
        while(!que.empty() && que.top().first <= d){
            PIPII dd = que.top();
            que.pop();
            if(++used[dd.second.second]==1){
                nq.push(PII(dd.second.first, dd.second.second));
            }
        }
        while(!nq.empty()&&used[nq.top().second]==2)nq.pop();
        if(nq.empty()){
            cout << -1 << endl;
        }else{
            cout << nq.top().first << endl;
        }
    }
    return 0;
}


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

int main() {
  ll s, c;
  cin >> s >> c;

  ll ans;
  if (2 * s >= c) {
    ans = c / 2;
  } else {
    ans = s + (c - 2 * s) / 4;
  }

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

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

using namespace std;
int main(){
    int i,n,a=0,b=0;
    string s;
    cin >> n;
    cin >> s;
for(i=0;i<n;i++){
    if(s[i]=='('){
        a++;
    }else{
        if(a>0){
            a--;
        }else{
            b++;
        }
    }
}
    for(i=0;i<b;i++){
        cout <<'(' ;
    }
    cout << s ;
    for(i=0;i<a;i++){
        cout << ')';
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll h, w;
    cin, h, w;
    if (w == 1 || h == 1) {
        cout << 1 << endl;
        return 0;
    }
    ll ans = (h * w + 1) / 2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printInt(a) printf("%d\n", a)
#define printll(a) printf("%lld\n", a)
#define printdbl(a) printf("%lf\n", a)
#define printYes() printf("Yes\n")
#define printNo() printf("No\n")
#define scanll(a) scanf("%lld", &a)
#define scanInt(a) scanf("%d", &a)
#define scan2Int(a, b) scanf("%d %d", &a, &b)
#define scan3Int(a, b, c) scanf("%d %d %d", &a, &b, &c)
#define scan4Int(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
typedef long long ll;
const int INF = 1001001001;
using namespace std;
void swap(int *a, int *b) {
    int tmp = *a;
    *a = *b;
    *b = tmp;
    return;
}
int gdc(int a, int b) {
    int r;
    if (a < b)
        swap(&a, &b);
    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
int factorial(int a) {
    int ans = 1;
    for (int i = 1; i <= a; ++i) 
        ans *= i;
    return ans;
}

int main() {
    int count = 0;
    int tmp = 0;
    char s[4];
    scanf("%s", s);
    bool flag = false;
    rep(i, 3) {
        if (s[i] == 'R') {
            tmp += 1;
            count = count > tmp ? count : tmp;
        } else {
            tmp = 0;
        }
    }
    printInt(count);
    return 0;
}

Measured memory_bytes: 3752
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():

    
    N,K=MI()
    a=LI()#下位の連続するn枚が不要なはず
    a.sort(reverse=True)
    #大きい方から順に足していき，K未満の最大の和を作っておく．これに対して，足してK以上になるのならそれは必要．K未満なら端しておく．
    #最終的に必要なもののうち最も小さいものがわかるはず
    
    temp=0
    ans=N
    for i in range(N):
        if temp+a[i]<K:
            temp+=a[i]
        else:
            ans=min(ans,N-i-1)
            
    print(ans)
    
    


main()


Measured memory_bytes: 39408
n,m,c = gets.split(" ").map(&:to_i)

count = 0

b = []
b = gets.split(" ").map(&:to_i)

n.times do |n_c|

  a = gets.split(" ").map(&:to_i)
  if a.zip(b).map{|t| t[0]*t[1] }.reduce(:+) + c > 0
    count += 1
  end
end

puts count


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

using namespace std;

typedef long long ll;

const int maxn = 2e5 + 50;
const int mod = 1e9 + 7;

int main(){
	ios_base::sync_with_stdio(false);
	int a, b, c;
	cin >> a >> b >> c;
	for (int i = 0; ; i++){
		if (a & 1 or b & 1 or c & 1)
			return cout << i << endl, 0;
		if (a == b and a == c)
			return cout << -1 << endl, 0;
		int ta = a, tb = b, tc = c;
		a = (tb + tc) >> 1, b = (ta + tc) >> 1, c = (ta + tb) >> 1;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define inf 1000000009
#define int long long

int p[214514], q[214514], r[214514], s[214514];
int ap[200009], bp[200009];
int par[200009], rnk[200009];
typedef pair<int, int> P;
map<P, int>M;

void init(int n) {
	for (int i = 0; i<n; i++) {
		par[i] = i;
		rnk[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x)return x;
	return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rnk[x]<rnk[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rnk[x] == rnk[y])rnk[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}

signed main() {
	int n, k, l;
	cin >> n >> k >> l;
	for (int i = 0; i<k; i++)cin >> p[i] >> q[i];
	for (int i = 0; i<l; i++)cin >> r[i] >> s[i];

	init(n);
	for (int i = 0; i<k; i++) {
		unite(p[i] - 1, q[i] - 1);
	}

	for (int i = 0; i<n; i++)ap[i] = find(par[i]);

	init(n);
	for (int i = 0; i<l; i++) {
		unite(r[i] - 1, s[i] - 1);
	}
	for (int i = 0; i<n; i++)bp[i] = find(par[i]);

	for (int i = 0; i < n; i++) {
		P a = make_pair(ap[i], bp[i]);
		auto itr = M.find(a);
		if (itr != M.end()) {
			M[a]++;
		}
		else {
			M[a] = 1;
		}
	}

	for (int i = 0; i<n; i++) {
		if (i)cout << ' ';
		cout << M[P(ap[i], bp[i])];
	}
	cout << endl;
}


Measured memory_bytes: 24320
#include  <functional>
#include  <algorithm>
#include  <exception>
#include  <stdexcept>
#include  <streambuf>
#include  <iterator>
#include  <string.h>
#include  <stdlib.h>
#include  <typeinfo>
#include  <valarray>
#include  <iostream>
#include  <sstream>
#include  <istream>
#include  <stdio.h>
#include  <climits>
#include  <clocale>
#include  <complex>
#include  <csetjmp>
#include  <csignal>
#include  <cstdarg>
#include  <cstddef>
#include  <ctype.h>
#include  <cassert>
#include  <cstdlib>
#include  <utility>
#include  <cstring>
#include  <numeric>
#include  <ostream>
#include  <cwctype>
#include  <fstream>
#include  <iomanip>
#include  <math.h>
#include  <bitset>
#include  <cctype>
#include  <string>
#include  <vector>
#include  <limits>
#include  <locale>
#include  <memory>
#include  <cerrno>
#include  <time.h>
#include  <iosfwd>
#include  <cfloat>
#include  <cstdio>
#include  <cwchar>
#include  <cmath>
#include  <ctime>
#include  <deque>
#include  <queue>
#include  <stack>
#include  <list>
#include  <ios>
#include  <map>
#include  <set>
#include  <new>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ll long long
#define pii pair<int,int>
using namespace std;
string s;
ll ans,sum[27];
int n;
int main()
{
    cin>>s;
    n=int(s.size());
    for(int i=0;i<n;i++)
        sum[s[i]-'a']++,ans+=(i+1);
    ans-=n;
    for(int i=0;i<27;i++)
    {
        if(sum[i]>1){
        ll t=sum[i]-1,t1=t*(t+1)/2;
        ans-=t1;}
    }
    cout<<ans+1<<endl;
    return 0;
}


Measured memory_bytes: 640