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

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

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N;
    cin >> N;
    vector<int> A,B,C;

    rep(i,N) {
        int x,y;
        cin >> x >> y;
        A.push_back(x+y);
        B.push_back(x-y);
        C.push_back(y-x);
    }

    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    sort(C.begin(),C.end());

    int ans = 0;
    ans = max(A.back()-A.front(), ans);
    ans = max(B.back()+C.back(), ans);
    cout << ans << endl;
}


Measured memory_bytes: 5876
#include<cstdio>

int main() {
    int a,b,d,r;
    double f;
    scanf("%d %d",&a,&b);
    d = a / b;
    r = a % b;
    f = 1.0 * a / b;
    printf("%d %d %.5f\n",d,r,f);

}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> vec;
    for (int i = 0; i < n; i++) {
        vec.push_back(0);
    }
    int temp1, temp2;
    vector<int> a, b;
    for (int i = 0; i < m; i++) {
        cin >> temp1 >> temp2;
        a.push_back(temp1);
        b.push_back(temp2);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    int de = b.front();
    int dc = a.back();
    int count;
    if (de >= dc)
        count = de - dc + 1;
    else
        count = 0;

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 1912
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)
















int main(){
    ll n;
    cin >> n;
    set<ll> st;
    ll ans = 0;
    REP(i, n){
        ll p;
        cin >> p;
        st.insert(p);
        if(*st.begin() == p) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin>>a.at(i);
  vector<int> b;
  for(int i=1;i<n;i+=2)
    b.push_back(a.at(i));
  reverse(b.begin(),b.end());
  for(int i=0;i<n;i+=2)
    b.push_back(a.at(i));
  if(n%2==1)
    reverse(b.begin(),b.end());
  for(int i=0;i<n;i++)
    cout<<b.at(i)<<(i+1<n?" ":"");
  cout<<endl;
}

Measured memory_bytes: 3828
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        long max = 1_000_000_000_000_000_000L;
        long root = 3037000499L;
        Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = in.nextInt();
        long ans = 1;

        if (N == 0) {
            System.out.println(0);
            return;
        }

        //System.out.println(max * max);

        List<Long> list = new ArrayList<>();
        for (int i = 0; i < N; ++i) {
            long a = in.nextLong();
            if (a > max) {
                System.out.println(-1);
                return;
            }

            if (a == 0) {
                System.out.println(0);
                return;
            }

            list.add(a);

        }

        for (long a : list) {
            if (ans > root && a > root) {
                System.out.println(-1);
                return;
            }
            ans *= a;

            if (ans < 0 || ans > max) {
                System.out.println(-1);
                return;
            }
        }
        System.out.println(ans);
        in.close();
    }
}

Measured memory_bytes: 61112
#include <iostream>
#include <cstdio>
using namespace std;
char s[10];
int main(void)
{
    scanf("%s",s);
    for(int i=0;i<3;i++)
    {
        if(s[i]=='7')
        {
            printf("Yes");
            return 0;
        }
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 3716
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vll = vector<vector<ll> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using the = pair<int, int>;
using lthe = pair<ll, ll>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };


priority_queue<the> p[200000];
const int MAXP = 2 * 1e5;

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	int an = 0, kg = 0;
	rep(i, n) {
		char c;
		cin >> c;
		if (c == 'a') {
			if (an < a + b) {
				an++;
				cout << "Yes" << endl;
			}
			else  cout << "No" << endl;
		}
		else if (c == 'b') {
			if (an < a + b && kg < b) {
				an++;
				kg++;
				cout << "Yes" << endl;
			}
			else cout << "No" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
}


Measured memory_bytes: 6912
/* Author:bhagatsunny96
         JGEC
	   template__
	lets_code_it_ */
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long int 
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define test long long int t; cin>>t; while(t-->0)
#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define loop(n) for(long long int i=0;i<n;i++)
#define loopr(n) for(long long int i=n-1;i>=0;i--)
#define lrp(a,b) for(long long int i=a;i<=b;i++)
#define lrn(a,b) for(long long int i=b;i>=a;i--)
#define endl '\n'
#define ivec vector<ll>
#define ivecp vector<pair<ll,ll>>
#define imap map<ll,ll>
#define uimap unordered_map<ll,ll>
#define iset set<ll>;
#define cvec vector<char>
#define civecp vector<pair<char,ll>>
#define cimap map<char,ll>
#define ucimap unordered_map<char,ll>
#define cset set<char>
using namespace std;
ll gcd(ll a, ll b)
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);
}
ll lcm(ll a, ll b)  
 {  
    return (a*b)/__gcd(a, b);  
 }
 ll power(ll x, unsigned ll y) 
 { 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2); 
    if (y%2 == 0) 
        return temp*temp; 
    else
        return x*temp*temp; 
 }
 bool isPrime(ll num)
 {
    bool flag=true;
    for(ll i =2;i<=num/2;i++) 
    {
       if(num%i==0) 
       {
          flag=false;
          break;
       }
    }
    return flag;
}
bool isPalin(ll num)
{
    bool flag=false;
    ll digit,rev=0,n=num;
    do
     {
         digit = num % 10;
         rev = (rev * 10) + digit;
         num = num / 10;
     } while (num != 0);
     if(rev==n)
     flag=true;
     return flag;
}
ll sumofdigits(ll n)
{
    ll c=0;
    while(n>0)
    {
        c++;
        n/=10;
    }
    return c;
}
bool sortinrev(const pair<int,int>&a,const pair<int,int>&b) 
{ 
    return (a.first > b.first); 
}
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b) 
{ 
    return (a.second < b.second); 
}
string sortString(string &str) 
{ 
   sort(str.begin(), str.end()); 
   return str;
} 
void countSort(ll arr[], ll n, ll exp) 
{ 
	ll output[n];
	ll i, count[10] = {0}; 
	for (i = 0; i < n; i++) 
		count[ (arr[i]/exp)%10 ]++; 
	for (i = 1; i < 10; i++) 
		count[i] += count[i - 1]; 
	for (i = n - 1; i >= 0; i--) 
	{ 
		output[count[ (arr[i]/exp)%10 ] - 1] = arr[i]; 
		count[ (arr[i]/exp)%10 ]--; 
	} 
	for (i = 0; i < n; i++) 
		arr[i] = output[i]; 
} 
void radixsort(ll arr[], ll n) 
{
    ll mx = arr[0]; 
	for (ll i = 1; i < n; i++) 
		if (arr[i] > mx) 
			mx = arr[i];
	ll m =mx;
	for (ll exp = 1; m/exp > 0; exp *= 10) 
		countSort(arr, n, exp); 
} 
void print(ll arr[], ll n) 
{ 
    for (ll i = 0; i < n; i++) 
        cout << arr[i] << " "; 
} 
int main() 
{
    fIO
    ll x;
    cin>>x;
    ll ans=0;
    ll w=x/500;
    ans=ans+(w*1000);
    ll r=x%500;
    ans=ans+((r/5)*5);
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

double[10^^5] AS;
double[10^^5][3] MEMO;

void main()
{
    auto N = readln.chomp.to!int;
    auto AS = readln.split.to!(double[]);

    double solve(int i, int f) {
        if (i == N-1) return AS[N-1] * (f-1);
        if (!MEMO[f][i].isNaN) return MEMO[f][i];
        return MEMO[f][i] = max(
            solve(i+1, 2) + AS[i] * (f-1),
            solve(i+1, 0) + AS[i] * -(f-1)
        );
    }

    writeln(solve(0, 2).to!long);
}

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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  reverse(a.begin(), a.end());

  vector<int> ans(n);
  int l = 0, r = n - 1, sgn = 1;

  for (int i = 0; i < n; i++) {
    if (sgn > 0) {
      ans[l++] = a[i];
    } else {
      ans[r--] = a[i];
    }
    sgn ^= 1;
  }

  for (int i = 0; i < n; i++) {
    cout << ans[i] << ' ';
  }
  cout << '\n';
  return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<string>
#include<set>
#include<cctype>
#include<algorithm>
using namespace std;
typedef string::const_iterator State;

string s;
int yuusenn[10], mx;
int expr(State& begin, int& now, int num);
bool zero = false;

int number(State& begin, int& now) {
  if (zero) return 0;
  int ans = 0;
  if (*begin == '(') {
    begin++;
    ans = expr(begin, now, 0);
    begin++;
    return ans;
  }
  while (isdigit(*begin)) ans *= 10, ans += *begin - '0', begin++;
  return ans;
}

int expr(State& begin, int& now, int num) {
  if (num == mx) return number(begin, now);
  int ans = expr(begin, now, num+1);
  while (1) {
    if (zero) return 0;
    if (*begin == '+' && yuusenn[now] == num) begin++, now++, ans += expr(begin, now, num+1);
    else if (*begin == '*' && yuusenn[now] == num) begin++, now++, ans *= expr(begin, now, num+1);
    else if (*begin == '/' && yuusenn[now] == num) {
      begin++, now++;
      int temp = expr(begin, now, num+1);
      if (temp == 0) {
        zero = true;
        return 0;
      }
      ans /= temp;
    } else if (*begin == '-' && yuusenn[now] == num) begin++, now++, ans -= expr(begin, now, num+1);
    else return ans;
  }
}

int main() {
  while (cin >> s, s != "#") {
    mx = 0;
    int ans = 0;
    set<int> st;
    for (int i = 0; i < s.length(); i++) if (s[i] == '+' || s[i] == '-' || s[i] == '*' || s[i] == '/') mx++;
    for (int i = 0; i < mx; i++) yuusenn[i] = i;
    do {
      State state = s.begin();
      int now = 0;
      zero = false;
      int temp = expr(state, now, 0);
      if (zero) continue;
      if (st.count(temp) == 0) st.insert(temp), ans++;
    } while (next_permutation(yuusenn, yuusenn + mx));
    printf("%d\n", ans);
  }
}



Measured memory_bytes: 3312
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef pair<int, int> P;
int main()
{
    ll H, W, K;
    cin >> H >> W >> K;

    vector<vector<ll>> dp(H + 1, vector<ll>(W, 0));
    dp[0][0] = 1;

    rep(i, H) {
        rep(j, W) {
            for (ll k = 0; k < (1 << (W - 1)); k++) {
                bool flag = true;
                rep(l, W - 2) {
                    if (((k >> l) & 1) && ((k >> (l + 1)) & 1)) {
                        flag = false;
                        break;
                    }
                }
                if (flag) {
                    // left
                    if (j >= 1 && ((k >> (j - 1)) & 1)) {
                        dp[i + 1][j - 1] += dp[i][j];
                        dp[i + 1][j - 1] %= MOD;
                    }
                    // right
                    else if (j <= W - 2 && ((k >> j) & 1)) {
                        dp[i + 1][j + 1] += dp[i][j];
                        dp[i + 1][j + 1] %= MOD;
                    }
                    // center
                    else {
                        dp[i + 1][j] += dp[i][j];
                        dp[i + 1][j] %= MOD;
                    }
                }
            }
        }
    }

    cout << dp[H][K - 1] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] c = str.toCharArray();
        int n = c.length;
        
        boolean ok = false;
        for (int i = 0; i < n; i++) {
            String tmp = "";
            for (int j = 0; j < i; j++) {
                tmp += c[j];
            }
            for (int j = i; j < n; j++) {
                String tmp2 = "";
                for (int k = j; k < n; k++) {
                    tmp2 += c[k];
                }
                
                String tmp3 = tmp + tmp2;
                // System.out.println(tmp3);
                if (tmp3.equals("keyence")) {
                    ok = true;
                }
            }
        }
        
        if (ok) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 42960
import bisect
N,Q=map(int,input().split())
S=input()

AC=[]

for i,s in enumerate(S):
    if i>=1:
        if s=="C" and S[i-1]=="A":
            AC.append(i-1)
#print(AC)
for i in range(Q):
    l,r=map(int,input().split())
    left=bisect.bisect_left(AC,l-1)
    right=bisect.bisect_right(AC,r-2)
    #print("----")
    print(right-left)
    

Measured memory_bytes: 5724
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val w = (0 until n).map { sc.next().toInt() }
    println(problem129b(n, w))
}

fun problem129b(n: Int, w: List<Int>): Int {
    var min = Integer.MAX_VALUE
    for (t in 1 until n) {
        val current = Math.abs(w.subList(0, t).sum() - w.subList(t, w.size).sum())
        if (min > current) {
            min = current
        }
    }
    return min
}

Measured memory_bytes: 31644
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <queue>
using namespace std;

typedef long long LL;
 
const int OO = 1e9;
const int MOD = 1e9 + 7;

class Task {
public:

	int n;
	vector<vector<int>> g;

	vector<int> bfs(int v) {
		vector<int> dist(n, -1);
		dist[v] = 0;
		
		queue<int> q;
		q.push(v);
		
		while (!q.empty()) {
			int u = q.front();
			q.pop();
			for (int w: g[u]) {
				if (dist[w] == -1) {
					dist[w] = dist[u] + 1;
					q.push(w);
				}
			}
		}
		
		return dist;
	}
	
	int get_diam() {
		vector<int> dist;
		int v = 0;
		dist = bfs(v);
		for (int i = 0; i < n; ++i)
			if (dist[v] < dist[i])
				v = i;
		dist = bfs(v);
		for (int i = 0; i < n; ++i)
			if (dist[v] < dist[i])
				v = i;
		return dist[v];
	}

	void solve() {
		cin >> n;
		g.resize(n);
		for (int i = 1; i < n; ++i) {
			int u, v;
			cin >> u >> v;
			--u, --v;
			g[u].push_back(v);
			g[v].push_back(u);
		}
		
		int diam = get_diam() + 1;
		
		if (diam % 3 < 2)
			cout << "First\n";
		else
			cout << "Second\n";
	}
};
 
int32_t main() {
//~ #ifndef ONLINE_JUDGE
	//~ freopen("input.txt", "r", stdin);
//~ #endif
 
	Task *task = new Task();
	task->solve();
	return 0;
}


Measured memory_bytes: 14324
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>


using namespace std;

struct Node {
	int key;
	Node *prev;
	Node *next;
};

Node *header;

void init() {
	header = (Node *)malloc(sizeof(Node));
	header->prev = header;
	header->next = header;
}

void insert(int key) {
	Node *data = (Node *)malloc(sizeof(Node));
	data->key = key;
	data->next = header->next;
	data->prev = header;
	header->next->prev = data;
	header->next = data;
}

void deleteKey(int key) {
	Node *p = header;
	while (p->next != header) {
		if (p->next->key == key) {
			Node *temp = p->next;
			p->next = temp->next;
			temp->next->prev = p;
			free(temp);
			return;
		}
		else {
			p = p->next;
		}

	}
}

void deleteFirst() {
	if (header->next == header) {
		return;
	}
	else {
		Node *temp = header->next;
		header->next = temp->next;
		temp->next->prev = header;
		free(temp);
		return;
	}
}

void deleteLast() {
	if (header->prev == header) {
		return;
	}
	else {
		Node *temp = header->prev;
		header->prev = temp->prev;
		temp->prev->next = header;
		free(temp);
		return;
	}

}

void print() {
	Node *p = header;
	while (p->next != header) {
		if (p->next->next == header) {
			cout << p->next->key << endl;
		}
		else {
			cout << p->next->key << " ";
		}
		p = p->next;
	}
}

int main() {
	init();
	int n;
	char com[20];
	int a;
	cin >> n;
	for (int i = 0; i < n; i++) {
		scanf("%s", com);
		if (com[0] == 'i') {
			scanf("%d", &a);
			insert(a);
		}
		else if (strlen(com) == 6) {
			scanf("%d", &a);
			deleteKey(a);
		}
		else if (com[6] == 'F') {
			deleteFirst();
		}
		else {
			deleteLast();
		}
	}

	print();

	return 0;
}

Measured memory_bytes: 32420
N, Q = map(int, input().split())
S = input()
t = S.count('AC')
L = [0]
R = [0]
for i in range(N-1):
    L.append(L[i]+1 if S[i:i+2] == 'AC' else L[i])
    R.append(R[i]+1 if S[N-i-2:N-i] == 'AC' else R[i])
R.reverse()
for i in range(Q):
    l, r = map(int, input().split())
    print(t-L[l-1]-R[r-1])


Measured memory_bytes: 85812
#include<stdio.h>
#include<iostream>
using namespace std;
int main()
{
	int x=0,y,z=0;
	scanf("%d",&y);
	char a[y];
	for(int p=0;p<y;p++)
	cin>>&a[p];
	
	if(y>=1&&y<=100)
	{
	for(int q=0;q<y;q++)
	{if(a[q]=='I'||a[q]=='D')
	{
	if(a[q]=='I')
	x++;
	if(a[q]=='D')
	x--;
	if(z<x)
	z=x;}
	else{
	break;}
	
}
cout<<z;
}

}

Measured memory_bytes: 256
// header {{{
#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>
#include <utility>
#include <string>
#include <sstream>
#include <queue>
#include <map>
#include <list>
#include <stack>
#include <tuple>
#include <cstdio>
#include <cmath>
using namespace std;

#define ALPHABET    26
#define EPS         (1e-10)
#define EQ(a, b)    (abs((a)-(b)) < EPS)
#define INF         1000000005

typedef long long ll;
typedef unsigned long long ull;
// }}}
// data structure {{{

// Union-Find
// verified AOJ DSL_1_A
struct UF {
    vector<int> p;  // parent
    vector<int> r;  // rank

    UF(int n) {
        p.resize(n);
        r.resize(n);
        for(int i=0;i<n;i++){
            p[i] = i;
            r[i] = 1;
        }
    }

    int find(int x) {
        if(x == p[x]){
            return x;
        }else{
            return p[x] = find(p[x]);
        }
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(r[x] < r[y]){
            p[x] = y;
        }else{
            p[y] = x;
            if(r[x] == r[y]){
                r[x]++;
            }
        }
    }
};
//}}}

int main() {
    int n, k, l;cin >> n >> k >> l;
    UF ufp(n), ufr(n);
    for(int i=0;i<k;i++){
        int a, b;cin >> a >> b;a--;b--;
        ufp.unite(a, b);
    }
    for(int i=0;i<l;i++){
        int a, b;cin >> a >> b;a--;b--;
        ufr.unite(a, b);
    }

    map<pair<int, int>, int> m;

    for(int i=0;i<n;i++){
        pair<int, int> p = {ufp.find(i), ufr.find(i)};
        if(m.find(p) == m.end()){
            m[p] = 0;
        }
        m[p]++;
    }

    bool flag = true;
    for(int i=0;i<n;i++){
        if(!flag){
            cout << " ";
        }
        flag = false;
        pair<int, int> p = {ufp.find(i), ufr.find(i)};
        cout << m[p];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 15104
char s[1<<17];n;i,j;
main(p){
	gets(s);
	for(j=i=(n=strlen(s))-1;i--;)if(s[i]-s[n-i-2]|s[j]%2|*s%7)return!puts("-1");
	for(;j--;s[j]%2&&(p=n-j))printf("%d %d ",p,n-j);
}

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

int main(){
    int n,m,c;
    int ans = 0;
    cin>>n>>m>>c;
    int b[m];
    for(int i=0;i<m;i++){
        cin>>b[i];
    }
    for(int i=0;i<n;i++){
        int tmp;
        int sum = 0;
        for(int j=0;j<m;j++){
            cin>>tmp;
            sum += tmp*b[j];
        }
        sum += c;
        if(sum>0){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,count=0;
    cin>>n;
    int a[n];
    for(i=0; i<n; i++)
        cin>>a[i];
    for(i=0; i<n; i+=2)
    {
        if(a[i]%2==1)
            count++;
    }
    cout<<count;
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

map<ll,ll> m;




int main(){
  cout << setprecision(10);
  ll N; cin >> N;
  ll ans = 0;

  for(ll i = 1; i <= N; i++){

    ll max = N / i;
    ans += i * max * (max+1) / 2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3592
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e18;
const double PI = 2 * asin(1);
typedef long long ll;


int main(){

  int Q; cin >> Q;
  vector <ll> ans(Q);

  for (int i = 0; i < Q; i++){
    ll A, B; cin >> A >> B;
    ll M = max(A, B), m = min(A, B);

    ll border = A * B;
    ll cnt1 = sqrt(border);

    if (M == m){
      ans[i] = 2 * (M - 1);
    }else if (M == m + 1){
      ans[i] = m - 1;
      ans[i] += border / (M + 1);
    }else{
      if (cnt1 * cnt1 == border) cnt1--;

      if (cnt1 * (cnt1 + 1) >= A * B){
        ans[i] = 2 * cnt1 - 2;
      }else{
        ans[i] = 2 * cnt1 - 1;
      }
    }
  }
  
  for (int i = 0; i < Q; i++){
    cout << ans[i] << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

class UnionFind:
    def __init__(self, element_count):
        self.parent = [i for i in range(element_count)]
        self.counter = [1 for _ in range(element_count)]
    
    def root(self, index):
        root = index
        while root != self.parent[root]:
            root = self.parent[root]
        while index != root:
            index, self.parent[index] = self.parent[index], root
        return root
    
    def unite(self, x, y):
        x, y = self.root(x), self.root(y)
        if x != y:
            self.parent[y] = x
            self.counter[x] += self.counter[y]
            self.counter[y] = 0
    
    def count(self, index):
        return self.counter[self.root(index)]

    def is_same(self, x, y):
        return self.root(x) == self.root(y)

uf = UnionFind(N)
for _ in range(M):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  uf.unite(a,b)
print(max(uf.counter))

Measured memory_bytes: 94152
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define LL long long
#define pii pair<int,int>
#define pll pair<LL,LL>

using namespace std;
struct E{LL to,cost;};
vector<E> edge[100001];
LL length[100001];
bool used[100001];

void dfs(int v,LL cost){
    length[v]=cost;
    used[v]=true;
    for(E e : edge[v])if(!used[e.to])dfs(e.to,e.cost + cost);
}

int main(){

    int N;cin>>N;
    REP(i,N-1){
        int a,b,c;cin>>a>>b>>c;
        edge[--a].push_back(E{--b,c});
        edge[b].push_back(E{a,c});
    }
    int Q,K;cin>>Q>>K;
    fill_n(used,N,false);
    dfs(--K,0);

    while(Q--){
        int x,y;
        cin>>x>>y;
        cout<<length[--x]+length[--y]<<endl;
    }
    cout<<endl;


    return 0;
}

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

using namespace std;

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

  int a, b, c, k;
  cin >> a >> b >> c >> k;
  while (a >= b) {
    b *= 2;
    --k;
  }
  while (b >= c) {
    c *= 2;
    --k;
  }
  cout << (k >= 0 ? "Yes" : "No");

  return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1000000007;
signed main(){
  int N,K;
  cin>>N>>K;
  vector<int> A(N);
  for(int &i:A)cin>>i;
  int ans=0;
  for(int i=0;i<N;i++){
    int n=0;
    for(int j=0;j<i;j++)
      if(A[j]>A[i])n++;
    int m=n;
    for(int j=i+1;j<N;j++)
      if(A[j]>A[i])m++;
    ans=(ans+K*(K-1)/2%mod*m%mod+n*K)%mod;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <queue>
#include <vector>
#include <map>
using namespace std;

typedef pair<int,int> P;

int main(){
	int n;
	while( scanf("%d", &n) , n ){
		// (時刻,列車の増減) のペアを格納する優先度つきキュー
		// 時刻の早いほうから順に出てくる.
		priority_queue< P , vector<P> , greater<P> > q;
		
		for(int i=0 ; i < n ; i++ ){
			int h1, m1, s1, h2, m2, s2;
			scanf("%d:%d:%d %d:%d:%d", &h1, &m1, &s1, &h2, &m2, &s2);
			int t1 = h1 * 60 * 60 + m1 * 60 + s1;
			int t2 = h2 * 60 * 60 + m2 * 60 + s2;
			q.push( P(t1,+1) );
			q.push( P(t2,-1) );
		}
		int ans = 0, cnt = 0;
		while( !q.empty() ){
			cnt += q.top().second;
			q.pop();
			ans = max( ans , cnt );
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 944
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		String[] goodCondition = { ".*keyence", "k.*eyence", "ke.*yence", "key.*ence", "keye.*nce", "keyen.*ce",
				"keyenc.*e", "keyence.*" };

		if (Stream.of(goodCondition).anyMatch(str::matches)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 28628
import java.util.*;


public class Main{
    static long count=0;
    public static void main(String [] args){
        Scanner sc=new Scanner(System.in);
        long H=sc.nextLong();
        long sum=0;
        int i=0;
        while(H>sum){
            
            sum=sum+(long)Math.pow(2, i);
            i++;
        }
        //sum=sum+Math.pow(2, i);
        System.out.println(sum);
        
    }
}


Measured memory_bytes: 23252
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        long k = sc.nextLong();
        if(k % 2 == 0){
            System.out.println(a-b);
        }else{
            System.out.println(b-a);
        }
    }
}


Measured memory_bytes: 21972
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    int n , k;
    cin>>n>>k;
    k--;
    string s;
    cin>>s;
    if(s[k]>='A' && s[k]<='C')
        s[k]=s[k]-'A'+'a';
    cout<<s;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define  forn(i, n)  for(int i=0; i < (int)n; i++)
using namespace std ;
// #define INPUT_OUTPUT { \
//  freopen("input.txt","r",stdin) ; \
//  freopen("output.txt","w",stdout) ; \
// }
void solve() {
  long long n, sum = 0;
  cin >> n;
  for(long long i=1; i<=n; i++) {
    if(i % 3 == 0 or i % 5 == 0) continue ;
    else sum = sum + i ;
  }
  cout << sum ;
}
int main() {
  // INPUT_OUTPUT ;
  int t=1;
  //cin >> t ;
  while(t--) solve() ;
  return 0 ;
}

Measured memory_bytes: 3588
#include <iostream>
using namespace std;
typedef long long ll;
ll n, k, d, s, M=1e9+7;
string a, b;
 
int main() {
	cin>>n>>a>>b;
	a[k]==b[k] ? (d=1,s=3) : (d=2,s=6);
	k += d;
	while(k<n) {
		if(a[k]==b[k]) s*=3-d, d=1;
		else s*=d+1, d=2;
		k += d;
		s %= M;
	}
	cout<<s;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int max,len,sum,ans;
int dfs(int depth,int rem,int j){
	int i,a=0;
	if(rem==0&&depth==len){
		return 1;
	}
	if(rem<0||depth>len){
		return 0;
	}
	for(i=j+1;i<=max;i++){
		a+=dfs(depth+1,rem-i,i);
	}
	return a;
}
int main(void){
	int p;
	while(1){
		ans=0;
		scanf("%d %d %d",&max,&len,&sum);
		if(max==0&&len==0&&sum==0){
			break;
		}
		else{
			for(p=1;p<=max;p++){
				ans+=dfs(1,sum-p,p);
			}
			printf("%d\n",ans);
		}
	}
	return 0;
}

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

int main(){
  string s;
  cin>>s;
  int count=0;
  for(int i=0;i<4;i++){
    if(s.at(i)=='+'){
      count++;
    }
    else{
      count--;
    }
  }
    cout<<count<<endl;
}
      

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

const int maxN = 100001;
// 隣接リスト
vector<int> G[maxN];
// 各辺の次数
int degree[maxN];
bool visited[maxN];
// 各頂点の親
int parent[maxN];

// #define TEST
int main() {
  #ifdef TEST
    freopen("input.txt", "r", stdin);
  #endif
  int N, M;
  cin >> N >> M;

  for (int i = 0; i < maxN; i++) {
    degree[i] = 0;
    visited[i] = false;
    parent[i] = -1;
  }

  for (int i = 0; i < N + M - 1; i++) {
    int s, t;
    cin >> s >> t;
    G[s - 1].push_back(t - 1);
    degree[t - 1] += 1;
  }

  queue<int> q;
  for (int i = 0; i < N; i++) {
    if (degree[i] == 0) {
      q.push(i);
    }
  }
  // 根付き木なので根は1個しかない
  // assert (q.size() == 1);

  vector<int> sorted;
  // topological sort
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    visited[u] = true;
    sorted.push_back(u);

    for (auto v : G[u]) {
      degree[v]--;
      if (degree[v] == 0 && visited[v] == false) {
        q.push(v);
        parent[v] = u;
      }
    }
  }

  for (int i = 0; i < N; i++) {
    if (parent[i] == -1) {
      cout << 0 << endl;
    }
    else {
      cout << parent[i] + 1 << endl;
    }
  }
  return 0;
}

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

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    int V[50];
    int ans = 0;
    for(int i = 0; i < N; i++) cin >> V[i];
    for(int l = 0; l < N; l++){
        for(int r = 0; r <= (N-l); r++){
            if(l+r > K) continue;
            vector<int> buf;
            int sum = 0;
            for(int i = 0; i < l; i++) {
                buf.push_back(V[i]);
                sum += V[i];
            }
            for(int i = 0; i < r; i++) {
                buf.push_back(V[N-i-1]);
                sum += V[N-i-1];
            }
            if(buf.size() == 0) continue;
            sort(buf.begin(), buf.end());
            for(int i = 0; i+l+r < K && i < buf.size(); i++){
                if(buf[i] < 0) sum -= buf[i];
            }
            ans = max(ans, sum);
            //cout << l << ' ' << r << ' ' << sum << endl;
        }
    }
    cout << ans << endl;
}

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

int main()
{
	std::string str;
	std::cin >> str;
	int q;
	std::cin >> q;
	while (q--) {
		std::string command;
		std::cin >> command;
		if (command == "replace") {
			int a, b;
			std::string rep_str;
			std::cin >> a >> b >> rep_str;
			str = str.substr(0, a) + rep_str + str.substr(b+1);
		} else if (command == "reverse") {
			int a, b;
			std::cin >> a >> b;
			std::string rev_str;
			for (int i = b; i >= a; --i) {
				rev_str += str[i];
			}
			str = str.substr(0, a) + rev_str + str.substr(b+1);
		} else {
			int a, b;
			std::cin >> a >> b;
			for (int i = a; i <= b; ++i) {
				std::cout << str[i];
			}
			std::cout << std::endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3184
n = int(input())
alist = list(map(int, input().split()))

pos = 1
ans = 0
leng = len(alist)
while(leng >= pos+ans):
    if (pos != alist[pos-1+ans]):
        ans += 1
    else:
        pos += 1

if (leng == ans):
    print("-1")
else:  
    print (ans)


Measured memory_bytes: 26268
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 100010
typedef long long ll;
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
ll ans=0;
int n,a[N],b[N];
int main(){
	n=read();
	for(int i=1;i<=n+1;i++){
		a[i]=read();
	}
	for(int i=1;i<=n;i++){
		b[i]=read();
	}
	for(int i=n;i>=1;i--){
		if(a[i+1]>=b[i]){
			ans+=b[i];
		}
		else{
			ans+=a[i+1];
			b[i]-=a[i+1];
			if(a[i]<=b[i]){
				ans+=a[i];
				a[i]=0;
			}
			else{
				ans+=b[i];
				a[i]-=b[i];
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<stdio.h>
#include<ios>
#include<cmath>
#include<string>
#include<string.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<assert.h>
#include<bitset>
#include<tuple>
#include<climits>
#include<deque>
#include<utility>
#include<unordered_map>
#include<unordered_set>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<ext/pb_ds/assoc_container.hpp>
#include<chrono>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define int            int64_t
#define double         long double
#define nitro          ios_base::sync_with_stdio(false);cin.tie(0);
#define vi             vector<int64_t>
#define pub            push_back
#define puf            push_front
#define pob            pop_back
#define pof            pop_front
#define PI             3.1415926535897932384626433832795
#define read(a)        for(auto& x : a) cin>> x
#define endl           '\n'
#define gap            ' '
#define min3(a,b,c)    min(a, min(b, c))
#define max3(a,b,c)    max(a, max(b, c))
#define MOD            1000000007
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main()
{
    nitro
    int a,b,c;
    cin>>a>>b>>c;
    if(c>=a and c<=b)cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    #define PAIN___ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define ll long long int
    #define fi first
    #define se second
    #define pb push_back
    #define pii pair < int , int >
    #define mp make_pair
    #define vec vector < ll >
    #define vecp vector < pii  >
    #define forl(i,q1,n,q2) for(ll i=q1;i<q2;i++)
    #define null NULL
    #define mm 1000005

    ll mat[100005][3];
    ll dp[1000005][3];
    ll n;


    int main()
    {

      // unordered_map< pair<char,int> ,ll> :: iterator itr;
      ll t;
      t=1;
      while(t--)
      {
        PAIN___;
     // unordered_map< char ,ll >um1,um2;

        cin>>n;
        mat[n][3];
        ll j1,j2;
        forl(i,1,n,n+1){
            forl(j,1,n,4){
                cin>>mat[i][j];
                dp[i][j]=mat[i][j];}}
        for(ll i=n-1;i>=1;i--){
            forl(j,1,n,4){
                if(j==1){j1=2,j2=3;}if(j==2){j1=1;j2=3;}if(j==3){j1=1;j2=2;}
                dp[i][j]=mat[i][j]+max(dp[i+1][j1],dp[i+1][j2]);}}
       cout<<max(max(dp[1][1],dp[1][2]),dp[1][3])<<endl;
      }}



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

const int Maxn = 1 << 19 | 5, p = 924844033;
int cnt, rev[Maxn],  siz[Maxn], head[Maxn];
long long fac[Maxn], inv[Maxn];
void get_rev(int n)
{
	for (int i = 0; i < n; i++)
		rev[i] = (rev[i >> 1] >> 1) | ((i & 1) * (n >> 1));
}
long long fast_pow(long long x, long long y)
{
	long long ans = 1, now = x;
	while (y)
	{
		if (y & 1) ans = ans * now % p;
		now = now * now % p;
		y >>= 1;
	}
	return ans;
}
void NTT(long long now[], int n, bool type = false)
{
	get_rev(n);
	for (int i = 0; i < n; i++)
		if (i < rev[i]) swap(now[i], now[rev[i]]);
	for (int i = 1; i < n; i <<= 1)
	{
		long long w = fast_pow(type ? 554906420 : 5, (p - 1) / (i << 1));
		for (int j = 0; j < n; j += (i << 1))
		{
			long long l = 1;
			for (int k = j; k < i + j; k++, l = l * w % p)
			{
				long long x = now[i + k] * l % p, y = now[k];
				now[k] = (x + y) % p;
				now[i + k] = (y - x + p) % p;
			}
		}
	}
	if (type)
	{
		long long inv = fast_pow(n, p - 2);
		for (int i = 0; i < n; i++)
			now[i] = now[i] * inv % p;
	}
}
int n;
void init(void)
{
	fac[0] = 1;
	for (int i = 1; i <= n; i++)
		fac[i] = fac[i - 1] * i % p;
	inv[n] = fast_pow(fac[n], p - 2);
	for (int i = n - 1; i >= 0; i--)
		inv[i] = inv[i + 1] * (i + 1) % p;
}
struct edg
{
	int nxt, to;
} edge[2 * Maxn];
void add(int x, int y)
{
	edge[++cnt] = (edg){head[x], y};
	head[x] = cnt;
}
void dfs(int u, int fa)
{
	siz[u] = 1;
	for (int i = head[u]; i; i = edge[i].nxt)
	{
		int to = edge[i].to;
		if (to != fa)
			dfs(to, u), siz[u] += siz[to];
	}
}
int lower(int x)
{
	int tmp = 1;
	for (; tmp <= x; tmp <<= 1);
	return tmp;
}
long long C(int x, int y)
{
	return fac[x] * inv[y] % p * inv[x - y] % p;
}
long long A[Maxn], B[Maxn];
int main()
{
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		add(x, y);
		add(y, x);
	}
	dfs(1, 0);
	init();
	for (int i = 2; i <= n; i++)
	{
		A[n - siz[i]] += fac[n - siz[i]];
		A[siz[i]] += fac[siz[i]];
	}
	int len = lower(n) << 1;
	for (int i = 0; i <= n; i++)
		B[n - i] = inv[i];
	NTT(A, len), NTT(B, len);
	for (int i = 0; i < len; i++)
		(A[i] *= B[i]) %= p;
	NTT(A, len, true);
	for (int i = n + 1; i <= 2 * n; i++)
		printf("%lld\n", (n * C(n, i - n) % p - A[i] * inv[i - n] % p + p) % p);
	return 0;
}

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

const long long maxi = 1LL << 31;

int main(){
  map<long long,int> M;
  int n;
  cin >> n;
  for(int i = 0;i < n;i++){
    int tmp;
    cin >> tmp;
    M[tmp]++;
  }
  
  int ans = 0;
  for(long long sum = maxi;sum >=2 ;sum /= 2){
    auto itr = M.begin();
    for(;itr != M.end();itr++){
      long long cur = (*itr).first;
      if (cur >= sum || (*itr).second == 0)continue;
      long long tar = sum - cur;
      if (M[tar] != 0){
	if (tar == cur){
	  ans += M[tar]/2;
	  M[cur] = 0;
	} else {
	  ans += min(M[tar], M[cur]);
	  int tmp =  min(M[cur], M[tar]);
	  M[tar] -= tmp;
	  M[cur] -= tmp;
	}
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 51200
#include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, m; double a[17][17], dp[18][65555]; bool vis[18][65555];
double solve(int t, int bit) {
	if (bit == 0) return 0.0;
	if (vis[t][bit]) return dp[t][bit];
	double ret = 0;
	for (int i = 0; i < m; i++) {
		if (!(bit & (1 << i))) continue;
		double res = 0.0, mul = 1.0;
		for (int j = t; j < n; j++) {
			res += solve(j, bit - (1 << i)) * mul * (1.0 - a[i][j]);
			mul *= a[i][j];
		}
		res += mul; // all complete
		ret = max(ret, res);
	}
	vis[t][bit] = true;
	return dp[t][bit] = ret;
}
int main() {
	scanf("%d%d", &m, &n);
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < n; j++) scanf("%lf", &a[i][j]);
	}
	printf("%.12lf\n", solve(0, (1 << m) - 1));
	return 0;
}

Measured memory_bytes: 11980
H, W = map(int, input().split())

if H*W%3==0:
    print(0)
    exit()

ans = H*W

if H%2==0 and W%2==0:
    for k in range(1,W):
        ans = min(ans,max(H*k,(W-k)*(H//2))-min(H*k,(W-k)*(H//2)))
    for k in range(1,H):
        ans = min(ans,max(W*k,(H-k)*(W//2))-min(W*k,(H-k)*(W//2)))
elif H%2==1 and W%2==0:
    for k in range(1,W):
        ans = min(ans,max(H*k,(W-k)*(H//2),(W-k)*(H//2+1))-min(H*k,(W-k)*(H//2),(W-k)*(H//2+1)))
    for k in range(1,H):
        ans = min(ans,max(W*k,(H-k)*(W//2))-min(W*k,(H-k)*(W//2)))
elif H%2==0 and W%2==1:
    for k in range(1,W):
        ans = min(ans,max(H*k,(W-k)*(H//2))-min(H*k,(W-k)*(H//2)))
    for k in range(1,H):
        ans = min(ans,max(W*k,(H-k)*(W//2),(H-k)*(W//2+1))-min(W*k,(H-k)*(W//2),(H-k)*(W//2+1)))
else:
    for k in range(1,W):
        ans = min(ans,max(H*k,(W-k)*(H//2),(W-k)*(H//2+1))-min(H*k,(W-k)*(H//2),(W-k)*(H//2+1)))    
    for k in range(1,H):
        ans = min(ans,max(W*k,(H-k)*(W//2),(H-k)*(W//2+1))-min(W*k,(H-k)*(W//2),(H-k)*(W//2+1)))

for k in range(1,W):
    if (W-k)%2==0:
        ans = min(ans, max(H*k,H*((W-k)//2))-min(H*k,H*((W-k)//2)))
    else:
        ans = min(ans, max(H*k,H*((W-k)//2),H*((W-k)//2+1))-min(H*k,H*((W-k)//2),H*((W-k)//2+1)))
for k in range(1,H):
    if (H-k)%2==0:
        ans = min(ans, max(W*k,W*((H-k)//2))-min(W*k,W*((H-k)//2)))
    else:
        ans = min(ans, max(W*k,W*((H-k)//2),W*((H-k)//2+1))-min(W*k,W*((H-k)//2),W*((H-k)//2+1)))

print(ans)


Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
vector<int> node[10010];
bitset<10010> vis;
int n,m;
void dfs(int k)
{
	vector<int>::iterator v;
	if(vis[k])
		return ;
	cout<<k<<endl;
	vis[k]=1;
	v=node[k].begin()+1;
	if(v==node[k].end())
		return ;
	for(; v!=node[k].end(); ++v)
	{
		node[*v][0]--;
		if(node[*v][0]==0)
			dfs(*v);
	}
	return ;
}
int main()
{
	cin>>n>>m;
	for(int i=0; i<n; ++i)
		node[i].push_back(0);
	for(int i=1; i<=m; ++i)
	{
		int r1,r2;
		cin>>r1>>r2;
		node[r2][0]++;
		node[r1].push_back(r2);
	}
	for(int i=0; i<n; ++i)
		if(node[i][0]==0)
			dfs(i);
	return 0;
}


Measured memory_bytes: 3808
#include <stdio.h>
#include <stdlib.h>
#include <math.h>


int digit_count(long);

int main(){
    int i;
    long S;
    int a;
    int s[15] = {0};
    scanf("%ld", &S);
    a = digit_count(S);

    for (i = a-1; i>=0 ; i--){
        s[i] = S % 10;
        S /= 10;
    }

    int b;
    int min = 5000;

    for(i = 0; i< a-2; i++){
        b = 100 * s[i] + 10 * s[i+1] + s[i+2];
        if(abs(b - 753) < min){
            min = abs(b-753);
        }
    }
    printf("%d\n", min);

    return 0;
}


int digit_count(long number) { //桁数計算
        int digit = 0;
        long number_tmp = number;
        while (number_tmp != 0) {
            number_tmp /= 10;
            digit++; 
        }
    return digit;
    }

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

template <typename InputIterator>
typename InputIterator::value_type
summation(InputIterator first, InputIterator last) {
  using T = typename InputIterator::value_type;
  T *p = new T();
  const auto sum = std::accumulate(first, last, *p);
  delete p;
  return sum;
}
template <typename T>
std::istream& operator>> (std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream& operator>> (std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream& operator>> (std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream& operator>> (std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  char a, b;
  std::cin >> a >> b;

  if (a == b) {
    std::cout << "H" << std::endl;
  } else {
    std::cout << "D" << std::endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define mod 1000000007
#define MAXN 100001
#define MAXM 100005
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};
UnionFind tree(MAXN);
ll conv[MAXM];
int a[MAXM];
int b[MAXM];
int main() {
    int n, m;
    cin >> n >> m;
    conv[10001] = 0;
    for (int i = 1; i <= m; i++) {
        cin >> a[i] >> b[i];
    }
    for (int i = m; i >= 1; i--) {
        if (tree.issame(a[i], b[i])) {
            conv[i] = conv[i + 1];
        }
        else {
            conv[i] = conv[i + 1] + tree.size(a[i]) * tree.size(b[i]);
            tree.merge(a[i], b[i]);
        }
    }
    for (int i = 2; i <= m + 1; i++) {
        cout << conv[1] - conv[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 6408
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int c = 0;
  cin >> n;
  vector<int> a(n);
  for(int i = 0;i < n;i++){
    cin >> a.at(i);
  }
  sort (a.begin(),a.end());
  for(int i = 0;i < n;i++){    
    for(int j = 0;j < i; j++){
        for(int k = 0; k < j; k++){
          if(a.at(k) != a.at(j) && a.at(j) != a.at(i)){
            if(a.at(k) + a.at(j) > a.at(i)){
              c++;
            }
          }

        }
    }
  }
  cout << c << endl;
}

Measured memory_bytes: 3644
package main

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

func main() {
	A, B, C, D := ReadInt(), ReadInt(), ReadInt(), ReadInt()
	t := true
	for A > 0 && C > 0 {
		if t {
			C -= B
		} else {
			A -= D
		}
		t = !t
	}
	if A > 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const double pi=acos(-1);
int n,x[101],y[101];
double p[201];
int pp;
double Max(double a,double b){return a>b?a:b;}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d%d",&x[i],&y[i]);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)if(i!=j) p[++pp]=atan2(y[j]-y[i],x[j]-x[i]);
		sort(p+1,p+pp+1);
		for(int j=1;j<=pp;j++) p[pp+j]=p[j]+pi+pi;
		double mx=0;
		for(int j=1;j<=pp;j++) mx=max(mx,pi-p[j+pp-1]+p[j]);
		printf("%.8lf\n",mx/pi/2);
		pp=0;
	}
}

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

#define I inline
#define fi first
#define se second
#define R register
#define LL long long
#define mp make_pair
#define reg register int
#define pii pair<int,int>
#define fo(i, a, b) for(reg i = a; i <= b; i++)
#define fd(i, a, b) for(reg i = a; i >= b; i--)
#define cr const reg&
using namespace std;
const int N = 3e5 + 1;

I int _max(cr x, cr y) {return x > y ? x : y;}
I int _min(cr x, cr y) {return x < y ? x : y;}
I int read() {
	reg x = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
	return x * f;
}
I void ptt(LL x) {if(x >= 10) ptt(x / 10); putchar(x % 10 + '0');}
I void put(LL x) {x < 0 ? putchar('-'), ptt(-x) : ptt(x);}
I void pr1(LL x) {put(x), putchar(' ');}
I void pr2(LL x) {put(x), puts("");}

int x[N], t[N];

int main() {
	reg n = read(), L = read(), mid;
	LL ans = 0, lst = 0;
	fo(i, 1, n) {
		x[i] = read();
		if(x[i] <= L - x[i]) mid = i;
	} fo(i, 1, n) {
		t[i] = read();
		lst += t[i] / (2 * L), t[i] %= 2 * L;
		if(t[i] > 2 * _max(x[i], L - x[i])) t[i] = 0, lst++;
	} reg l = 0, r = 0, m = 0;
	bool fl = 0, fr = 0, fm = 0;
	fd(i, mid, 1) {
		if(!t[i]) continue;
		if(t[i] <= 2 * _min(x[i], L - x[i])) {
			if(!l) m++;
			else l--, lst++, fl |= l == 0;
		} else l++;
	} fo(i, mid + 1, n) {
		if(!t[i]) continue;
		if(t[i] <= 2 * _min(x[i], L - x[i])) {
			if(!r) m++, fr = 0;
			else r--, lst++, fr |= r == 0;
		} else r++;
	} fm = m >= 2;
	lst += m / 2, m %= 2;
	if(r) ans = l + r + m + 1;
	else {
		ans = l + r + m;
		if(t[n] == 0 || fr) ans++;
		else if(m == 0 && (fm || fl)) ans++;
	} pr2(L * 2LL * (ans + lst));
	return 0;
}



Measured memory_bytes: 2560