akhauriyash/Code-Regression huggingface dataset:
const int LG = 21;
const int FN = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define pb push_back
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Ans[2] = {"No", "Yes"};
string ANS[2] = {"NO", "YES"};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(FN);
    __ufact.resize(FN);
    __rev.resize(FN);
    __rev[1] = 1;
    for (int i = 2; i < FN; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < FN; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int Root(int x, vector<int> &root)
{
    if (x == root[x]) return x;
    return root[x] = Root(root[x], root);
}

void Merge(int v, int u, vector<int> &root, vector<int> &sz)
{
    v = Root(v, root), u = Root(u, root);
    if (v == u) return;
    if (sz[v] < sz[u])
    {
        sz[u] += sz[v];
        root[v] = u;
    }
    else
    {
        sz[v] += sz[u];
        root[u] = v;
    }
}

int ok(int x, int n)
{
    return 0 <= x && x < n;
}

void bfs(int v, vi &dist, vector<vi> &graph)
{
    fill(all(dist), -1);
    dist[v] = 0;
    vi q = {v};
    for (int i = 0; i < q.size(); i++)
    {
        for (auto u : graph[q[i]])
        {
            if (dist[u] == -1)
            {
                dist[u] = dist[q[i]] + 1;
                q.push_back(u);
            }
        }
    }
}


signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int a, b;
    cin >> a >> b;
    cout << a + b / 2;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/


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

int main() {
    string S;
    char r='1';
    ll K,m=101;
    cin >> S >> K;

       
    rep(i,S.size())
        if(S.at(i) != '1') {
            r = S.at(i);
            m = i;
            break;
        }
    if(K<=S.size() && K-1<m)
        r = '1';

    cout << r << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long ll;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	vector<int> v(2);
	for (int i = 0; i < 3001; ++i) {
		cin >> v[0] >> v[1];
		if (v[0] == 0 && v[1] == 0) {
			break;
		}
		else if(v[0] > v[1]) {
			std::swap(v[1], v[0]);
			cout << v << endl;
		}
		else {
			cout << v << endl;
		}
	}
}


Measured memory_bytes: 3036
#include <queue>
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<int> > G(N);
	for (int i = 0; i < M; ++i) {
		int a, b, c;
		cin >> a >> b >> c; --a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	int cnt = 0;
	vector<long long> dist(N, -1);
	for (int i = 0; i < N; ++i) {
		if (dist[i] != -1) continue;
		++cnt;
		dist[i] = 0;
		queue<int> que;
		que.push(i);
		while (!que.empty()) {
			int u = que.front(); que.pop();
			for (int e : G[u]) {
				if (dist[e] == -1) {
					dist[e] = dist[u] + 1;
					que.push(e);
				}
			}
		}
	}
	cout << cnt << endl;
	return 0;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vl = vector<ll>;
using vs = vector<string>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
	int n;
	cin >> n;
	vector<int> p(n);
	int ma = 0, mai = 0;
	for(int i = 0; i < n; ++i){
		cin >> p[i];
		if(ma < p[i]){
			ma = p[i];
			mai = i;
		}
	}
	p[mai] /= 2;
	cout << accumulate(begin(p), end(p), 0) << "\n";
	
	return 0;
}


Measured memory_bytes: 896
use std::io::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_spc<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn print<T: std::fmt::Display>(x: T) -> () {
    println!("{}", x);
}

fn main() {
    bitter_alchemy();
}

fn bitter_alchemy() {
    let nx: Vec<i64> = read_spc();
    let n = nx[0];
    let mut x = nx[1];
    let mut ms = vec![];
    for i in 0..n {
        let mut m: i64 = read();
        ms.push(m);
    }
    let sum: i64 = ms.iter().sum();
    x -= sum;
    let m = ms.iter().min().unwrap();
    print(x / m + n);
}

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

int main() {
  int n; cin >> n;
  vector<int> d(n);
  for(int i = 0; i < n; i++) cin >> d.at(i);
  sort(d.begin(), d.end());
  cout << d.at(n/2) - d.at(n/2-1) << endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
 
double eps = .000000001;
long long save[2001][2001];
int main(){
  prep();
  int n, m;
  cin >> n >> m;
  int a[n];
  int b[m];
  for (int i=0; i<n; i++){
      cin >> a[i];
  }
  for (int i=0; i<m; i++){
      cin >> b[i];
  }
  for (int i=0; i<n; i++){
      save[i][m] = 1;
  }
  for (int i=0; i<m; i++){
      save[n][i] = 1;
  }
  save[n][m] = 1;
  for (int i=n-1; i>=0; i--){
      for (int j=m-1; j>=0; j--){
          long long val = mymod(-save[i+1][j+1]+save[i+1][j]+save[i][j+1]);
          if (a[i] == b[j]){
              save[i][j] = mymod(save[i+1][j+1]+val);
          }else{
              save[i][j] = val;
              
          }
         // cout << i << " " << j << " " << save[i][j] << endl;
      }
  }
  
  cout <<save[0][0];
  return 0; 
}

Measured memory_bytes: 31616
#define _overload(_1, _2, _3, _4, name, ...) name
#define _rep1(Itr, N) _rep3(Itr, 0, N, 1)
#define _rep2(Itr, a, b) _rep3(Itr, a, b, 1)
#define _rep3(Itr, a, b, step) for (i64 (Itr) = a; (Itr) < b; (Itr) += step)
#define repeat(...) _overload(__VA_ARGS__, _rep3, _rep2, _rep1)(__VA_ARGS__)

#include "bits/stdc++.h"
using i64 = long long;
using namespace std;

int main() {
    i64 x;
    cin >> x;
    cout << (int)(!x) << endl;
    return 0;
};


Measured memory_bytes: 3568
num = list(map(int,input().split()))
A = num[0]#1
B = num[1]#0
C = num[2]#-1
K = num[3]

if A>=K:
    print(K)
elif (A+B>=K)and(K>A):
    print(A)
elif (A+B<K)and(K<=A+B+C):
    print(A-(K-(A+B)))

Measured memory_bytes: 8956
#include <stdio.h>
#define MAX 100000

typedef struct node{
  int left;
  int right;
  int p;
}Node;

Node node[MAX];
int depth[MAX];

void depthSearch(int a, int b){
  depth[a] = b;
  if(node[a].left != -1)depthSearch(node[a].left,b+1);

  if(node[a].right != -1)depthSearch(node[a].right,b);
}

int main(){
  int n;
  int id;
  int k;
  int c;
  int l;
  int a;
  int i , j;

  scanf("%d",&n);
    for(i = 0 ; i < n ; i++){
    node[i].p = -1;
    node[i].left = -1;
    node[i].right = -1;
  }

  for(i = 0 ; i < n  ; i++){
    scanf("%d",&id);
    scanf("%d",&k);

    if(k != 0){
      for(j = 0 ; j < k ; j++){
        scanf("%d",&c);
        if(j == 0)node[id].left = c;
        else{
          node[l].right=c;
        }
        l=c;
        node[l].p = id;
      }
    }
  }

  for(i = 0 ; i < n ; i++){
    if(node[i].p == -1)depthSearch(i,0);
  }

  for(i = 0 ; i < n ; i++){
    printf("node %d: parent = %d, depth = %d, ",i,node[i].p,depth[i]);

    if(node[i].p == -1){
      printf("root, ");
      printf("[");
      for(j = 0 , a=node[i].left ; a !=-1 ; a =node[a].right ,j++){
        if(j == 0)printf("%d",a);
        else printf(", %d",a);
      }
      printf("]\n");
    }

    else if(node[i].left == -1){
      printf("leaf, ");
      printf("[]\n");
    }

    else {
      printf("internal node, ");
      printf("[");

      for(j = 0 , a=node[i].left ; a != -1 ; a=node[a].right , j++){
        if(j == 0)printf("%d",a);
        else printf(", %d",a);
      }
      printf("]\n");
    }
  }
  return 0;
}



Measured memory_bytes: 3288
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n;
	cin>>n;
	long long s=0;
	for(int i=1;i<=n;i++)
	{
		long long a;
		cin>>a;
		while(a%2==0)
		{
			a=a/2;
			s++;
		}
	}
	cout<<s;
 } 

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

int main(){
  int N;
  int a[110];
  cin >> N;
  for(int i = 0; i < N; i++)cin>>a[i];

  sort(a, a + N, greater<int>());
  int Alice = 0;
  int Bob = 0;
  for(int i = 0; i < N; i++){
    if(i % 2 == 0){
      Alice += a[i];
    }else{
      Bob += a[i];
    }
  }
  cout << Alice - Bob << endl;
}


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

const long long mod = 1e9 + 7;

map<int, int> mp;

void prime_factor(int n){
    for(int i = 2; i * i <= n; i++){
        while(n % i == 0){
            mp[i]++;
            n /= i;
        }
    }
    if(n != 1) mp[n]++;
    return;
}

int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        prime_factor(i);
    }
    long long ans = 1;
    for(map<int, int>::iterator it = mp.begin(); it != mp.end(); it++){
        ans = (ans * (it -> second + 1)) % mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const X = parseInt(arg[0].split(" ")[0]);
    
    if(X === 1) {
        console.log(1);
        return;
    }
    
    let sum = 0;
    let now = 0;
    
    for(let i=1; i<=X; i++) {
        sum += i;
        now = i;
        
        if(sum === X) {
            console.log(i);
            return;
        }
        
        if(sum > X) break;
    }

    console.log(now);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
import sys

def read_str(): return sys.stdin.readline().strip()
def read_int(): return int(sys.stdin.readline().strip())
def read_ints(): return map(int, sys.stdin.readline().strip().split())
def read_str_split(): return list(sys.stdin.readline().strip())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))

def Main():
    n = read_int()
    a = read_int_list()
    ans = [0] * n
    ans[0] = sum(a) - 2 * sum(a[1::2])
    for i in range(1, n):
        ans[i] = 2 * a[i - 1] - ans[i - 1]
    print(*ans)

if __name__ == '__main__':
    Main()


Measured memory_bytes: 20568
#include<iostream>
using namespace std;
int main() {
  int a,b,cnt=0;
  cin >> a >> b;
  if(a>b){
    for(int i=0; i<a-1; i++){
      cnt++;
    }
    cout << cnt << endl;
  }else{
    for(int i=0; i<a; i++){
      cnt++;
    }
    cout << cnt << endl;
  }
}

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


int main()
{
	int a, b, c;
	int k;
	cin >> a >> b >> c;
	cin >> k;
	int sum;
	int max = 0;
	int a_c, b_c, c_c;
	for (int i = 0; i <= k; ++i) {
		for (int j = 0; j <= k - i; ++j) {
			int l = k - j - i;
			a_c = a;
			for (int i1 = 0; i1 < i; ++i1) {
				a_c *= 2;
			}
			b_c = b;
			for (int i1 = 0; i1 < j; ++i1) {
				b_c *= 2;
			}
			c_c = c;
			for (int i1 = 0; i1 < l; ++i1) {
				c_c *= 2;
			}
			sum = a_c + b_c + c_c;
			if (sum > max) {
				max = sum;
			}
		}
	}
	cout << max;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    INT(n);
    VI c(n-1),s(n-1),f(n-1);
    rep(i,n-1) cin >> c[i] >> s[i] >> f[i];
    rep(i,n){
        int ans = 0;
        FOR(j,i,n-1){
            if(ans%f[j] != 0) ans += f[j]-ans%f[j];
            ans = max(ans,s[j]) + c[j];
        }
        ANS;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
int mod =1000000007;
const double PI = acos(-1);
int main(){
    ll n,m,x;cin>>n>>m;bool f=false;
    rep(i,n){
        cin>>x;
        if(x%2)f=true;
    }
    ll ans =pow(2,n-1);
    if(!f&&m){
        ans=0;
    }
    else if(!f){
        ans=pow(2,n);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3984
/*input
y
1
2 1 x
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 100001
#define M 1000000007
#define ll long long
#define vll vector<long long>
#define vi vector<int>
#define pll pair<long long,long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<long long,long long> >
#define pb push_back
#define pf pop_front
#define F first
#define S second
#define endl '\n'

using namespace std;
using namespace __gnu_pbds; 

template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


ll power(ll a,ll m,ll mod){
    ll ans=1;
    while(m){
        if(m%2){
            ans*=a;
            ans%=(mod);
        }
        a=(a*a)%(mod);
        m>>=1;
    }
    return ans;
}


void init(long long* a,long long n,long long val){
    for(long long i=0;i<n;i++)
        a[i]=val;
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL); 
    ll t=1,i,j;
    string s;
    cin>>s;
    ll q;
    ll b=0;
    char c;
    ll f;
    ll k=0;
    string s1="",s2="";
    cin>>q;
    while(q--){
    	cin>>t;
    	if(t==1){
    		b=!b;
    		k++;
    		continue;
    	}
    	cin>>f>>c;
    	if(f==1){
    		if(b){
    			s2+=c;
    		}
    		else{
    			s1+=c;
    		}	
    	}else{
    		if(b){
    			s1+=c;
    		}else {
    			s2+=c;
    		}
    	}
    }
    reverse(s1.begin(),s1.end());
    s1+=s;
    s1+=s2;
    if(k%2)reverse(s1.begin(),s1.end());
    cout<<s1<<endl;
    return 0;
}




Measured memory_bytes: 1300
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

int main() {
    int n, p1 = 0, p2 = 0;
    string str1, str2;
    cin >> n;
    for(int i = 0; i < n; ++i) {
        cin >> str1 >> str2;
        if(str1 > str2) {
            p1 += 3;
        }
        else if(str1 < str2) {
            p2 += 3;
        }
        else {
            ++p1; ++p2;
        }
    }
    cout << p1 << " " << p2 << endl;
    return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  int a,b;
  cin >> a >> b;
  cout << (a+b+1)/2 << endl;
  return 0;
}

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

wars=[None]*M
for i in range(M):
  a,b=map(int,input().split())
  wars[i]=a-1,b-1

wars=sorted(wars,key=lambda x:x[1])

ans=0
cut=-1
for i in range(len(wars)):
  a,b=wars[i]
  if a>cut:
    cut=b-1
    ans+=1

print(ans)

Measured memory_bytes: 19044
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<typeinfo>
#include<cassert>
#include<functional>
#include<algorithm>
#include<climits>
#include<map>

using namespace std;



int main(){

    int A,B,C;
    int X;

    cin >> A >> B  >> C >> X;

    int ans = 0;

    for(int i = 0;i <= A;i++){
    	for(int j = 0;j <= B;j++){
    		for(int l = 0;l <= C;l++){
    		   if(500*i + 100*j+ 50*l == X){
    			   ans++;
    		   }
    		}
    	}
    }

    cout << ans  << endl;

    return 0;

}


Measured memory_bytes: 256
%:pragma GCC optimize("Ofast")
  %:pragma GCC optimize("inline")
#include <bits/stdc++.h>
#define rint register int
  using namespace std;

template<typename tp> inline void read(tp &x) {
  x = 0; char c = getchar(); int f = 0;
  for (; c < '0' || c > '9'; f |= c == '-', c = getchar());
  for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
  if (f) x = -x;
}
namespace {
  const int mo = 998244353;
  inline int add(int x, int y) {
    if((x += y) >= mo) x -= mo;
    return x;
  }
  inline int sub(int x, int y) {
    if((x -= y) < 0) x += mo;
    return x;
  }
  inline int mul(int x, int y) {
    return 1LL * x * y % mo;
  }
  inline int pw(int a, int k) {
    int ans = 1;
    for (; k; k >>= 1, a = mul(a, a))
      if (k & 1) ans = mul(ans, a);
    return ans;
  }
}
const int N = 1e6 + 233;
int fac[N], ifac[N];
int n, m;
inline int C(int n, int m) {
  if (n < 0) return 0;
  else if (m == n || m == 0) return 1;
  else return mul(fac[n], mul(ifac[m], ifac[n - m]));
}

main(void) {
  read(n); read(m);
  int o = 1e6;
  fac[0] = 1;
  for (int i = 1; i <= o; i ++)
    fac[i] = mul(fac[i - 1], i);
  ifac[o] = pw(fac[o], mo - 2);
  for (int i = o - 1; i >= 0; i --)
    ifac[i] = mul(ifac[i + 1], i + 1);
  // cout << C(4, 2) << "\n";
  int ans = 0;
  for (int i = 1; i <= min(n, m); i ++)
    ans = add(ans, mul(C(2 * i, i), C(n + m - 2 * i, n - i)));
  ans = mul(ans, pw(mul(2, C(n + m, n)), mo - 2));
  ans = add(ans, max(n, m));
  cout << ans << "\n";
}


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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define read            freopen("in.txt","r",stdin)
#define write           freopen("out.txt","w",stdout)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (ll i = a; i >= b; i--)
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           (a)*(a)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)

int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        int x;
        cin>>x;
        cout<<(!x);
    }
    return 0;
}


Measured memory_bytes: 3652
N, X, Y = map(int, input().split())
cnt = [0]*N

for i in range(1, N+1):
    for j in range(i+1, N+1):
        d = min(j-i, abs(X-i) + abs(Y-j) + 1)
        cnt[d] += 1

for i in range(1,N):
    print(cnt[i])


Measured memory_bytes: 3444
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
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;
}
 
using namespace std;

void solve(){
  long double a,b,c;
  cin>>a>>b>>c;
  if((long double)2*sqrtl(a*b)+a+b-c<(long double)0)cout<<"Yes";
  else cout<<"No";
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        
        int numberOfEvenBalls = n * (n - 1)/2;
        int numberOfOddBalls = m * (m - 1)/2;
        
        System.out.println(numberOfEvenBalls + numberOfOddBalls);

    }
}


Measured memory_bytes: 21844
import qualified Data.Char as Char (isUpper, isLower, toUpper, toLower)

main = putStrLn . toggleCases =<< getLine

toggleCases :: String -> String
toggleCases [] = []
toggleCases (x:xs)
    | Char.isLower x = Char.toUpper x : toggleCases xs
    | Char.isUpper x = Char.toLower x : toggleCases xs
    | otherwise      = x : toggleCases xs

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill( x, y ) memset( x, y, sizeof x )
#define copy( x, y ) memcpy( x, y, sizeof x )
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

const int MAXN = 3005;

int n, dp[MAXN], a[MAXN];
vector < int > G[MAXN];

inline void dfs(int x, int fa = 0)
{
	dp[ x ] = 0;
	for( auto y : G[ x ] ) if( y ^ fa )
		dfs( y, x ), dp[ x ] |= ( !dp[ y ] && a[ x ] > a[ y ] );
}

int main()
{
#ifdef wxh010910
	freopen( "data.in", "r", stdin );
#endif
	scanf( "%d", &n );
	for( int i = 1 ; i <= n ; i++ ) scanf( "%d", &a[ i ] );
	for( int i = 1, x, y ; i < n ; i++ ) scanf( "%d%d", &x, &y ), G[ x ].pb( y ), G[ y ].pb( x );
	for( int i = 1 ; i <= n ; i++ )
	{
		dfs( i );
		if( dp[ i ] ) printf( "%d ", i );
	}
	putchar( 10 );
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, z = 0;
    string s;
    cin >> n >> s;
    for (int i = 1; i < n; i++) {
        string t = s.substr(0, i), u = s.substr(i, n - i);
        int c[26] = {}, d[26] = {}, e = 0;
        for (int j = 0; j < i; j++) c[t[j] - 'a'] = 1;
        for (int j = 0; j < n - i; j++) d[u[j] - 'a'] = 1;
        for (int j = 0; j < 26; j++) if (c[j] && d[j]) e++;
        z = max(z, e);
    }
    cout << z;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 1000000000
int main(){
	int n,m;cin>>n>>m;

	int MIN=INF,MAX=-1;
	for(int i=0;i<m;i++){
		int l,r;cin>>l>>r;
		MAX=max(MAX,l);
		MIN=min(MIN,r);
	}

	if(MAX>MIN){cout<<0<<endl;}
	else{
		cout<<MIN-MAX+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  int n, a[SIZE], b[SIZE];
  vector<int> vec;
  int ans = 0;
  ll need = 0;

  scanf("%d", &n);

  for(int i=0;i<n;i++) scanf("%d", a+i);
  for(int i=0;i<n;i++) scanf("%d", b+i);

  for(int i=0;i<n;i++){
    if (b[i] > a[i]){
      need += b[i] - a[i];
      ans++;
    } else {
      vec.push_back(a[i] - b[i]);
    }
  }

  sort(vec.begin(), vec.end(), greater<int>());

  for(int i=0;i<vec.size() && need > 0;i++){
    auto p = vec[i];
    ans++;
    need -= p;
    debug(p);
  }

  if (need > 0) {
    puts("-1");
  }else{
    printf("%d\n", ans);
  }


  return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

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; }

vector< vector<int> > Graph;
vector< int > value;



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

    cin.tie(0);
    ios::sync_with_stdio(false);
   
    
    string s,t; cin >> s >> t;
    
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());
    
    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
     
    
    
    
    
    
}


Measured memory_bytes: 256
MOD = 1_000_000_007
io = DATA.eof? ? STDIN : DATA
n=io.gets.to_i
ar=io.gets.split.map(&:to_i)
ans=0
#累積和
cum=ar.clone
(ar.size-1).times do |i|
  cum[i+1]+=cum[i]
end

(n-1).times do |i|
  ans+=ar[i]*(cum[-1]-cum[i])
  ans%=MOD
end
puts ans
__END__


Measured memory_bytes: 35268
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>

using namespace std;


int main()
{
double N;
cin>>N;
int a[100];
int k=0;
int sum=0;
for(int i=0;i<N;i++){
  cin>>a[i];
  if(k<a[i])k=a[i];
  sum=sum+a[i];
}
if(sum-k>k){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

return 0;
}

Measured memory_bytes: 256
h,w = gets.split.map(&:to_i)
a,b = 2.times.map{(1..h).map{gets.split.map(&:to_i)}}
ab = a.zip(b).map{|ta,tb|ta.zip(tb).map{|ua,ub|(ua-ub).abs}}

max = ab.map(&:max).max
zero = 1 << (h+w)*max/2

ans = ab.each_with_object([zero]+[0]*w){|di,dp|
  pre = 0
  dp.replace(
    di.zip(dp).map{|dt,dpi|
      s = dpi | pre
      pre = (s << dt) | (s >> dt)
    }
  )
}[-1]

p (0..max).find{|i|ans & ((zero << i)|(zero >> i)) > 0}

Measured memory_bytes: 18428
using System;

namespace _063_Palindrome
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;
			int count = 0;

			while ((inputStr = Console.ReadLine ()) != null)
			{
				bool isPalindrome = true;

				int halfIndex = inputStr.Length / 2 - 1;

				for (int index = 0; index <= halfIndex; index++)
				{
					int reverseIndex = inputStr.Length - 1 - index;

					if (inputStr[index] != inputStr[reverseIndex])
					{
						isPalindrome = false;
						break;
					}
				}

				if (isPalindrome)
					count++;
			}

			Console.WriteLine (count);
		}
	}
}

Measured memory_bytes: 8976
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> X(N);
  for(int i = 0; i < N; i++) cin >> X.at(i);
  
  sort(X.begin(), X.end());
  
  int min = 1000000;
  int sum= 0;
  
  for(int i = X.at(0); i < (X.at(N - 1) + 1); i++) {
    sum = 0;
    for(int j = 0; j < N; j++) sum += (X.at(j) - i) * (X.at(j) - i);
    if(sum <= min) min = sum;
  }
  
  cout << min << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var s = Console.ReadLine();
        var regex = new Regex("^A[a-z]+C[a-z]+$");
        var match = regex.Match(s);
        Console.WriteLine(match.Success ? "AC" : "WA");
    }
}

Measured memory_bytes: 15940
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<functional>

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

using namespace std;

struct square{
	int x,y,a; // 左上の座標, 幅
	bool operator<(const square &S)const{ return a<S.a; }
};

int h,w;
int B[10][10];

vector<square> S;
int cnt[10][10]; // マス (i, j) を覆うことのできる正方形の個数

#define update_cnt(i,d) for(int y=S[i].y;y<S[i].y+S[i].a;y++) for(int x=S[i].x;x<S[i].x+S[i].a;x++) cnt[y][x]+=d

int hstar(int i){
	int n=0;
	static int val[100]; // i 番目以降の正方形で新たに覆えるマスの個数を大きい順に並べたもの
	for(;i<S.size();i++){
		val[n]=0;
		for(int y=S[i].y;y<S[i].y+S[i].a;y++) for(int x=S[i].x;x<S[i].x+S[i].a;x++) {
			if(B[y][x]==1) val[n]++;
		}
		n++;
	}
	sort(val,val+n,greater<int>());

	int a=0; // まだ覆っていないマスの数
	rep(y,h) rep(x,w) if(B[y][x]==1) a++;

	int res=0;
	for(i=0;a>0;i++){
		a-=val[i];
		res++;
	}
	return res;
}

int res;
void dfs(int i,int sum){
	if(sum+hstar(i)>=res) return;

	if(i==S.size()){
		res=sum;
		return;
	}

	bool ok1=false,ok2=false;
	for(int y=S[i].y;y<S[i].y+S[i].a;y++) for(int x=S[i].x;x<S[i].x+S[i].a;x++) {
		if(B[y][x]==1) ok1=true;
		if(B[y][x]==1 && cnt[y][x]==1) ok2=true;
	}

	bool use=true,notuse=true;
	// 正方形 i を使うことで新たに覆えるマスがないなら使わない
	if(!ok1) use=false;
	// 正方形 i を使わないと絶対に覆えないマスができるようなら使う
	if(ok2) notuse=false;

	// いずれでもなければ両方試す
	update_cnt(i,-1);
	if(use){
		int tmp[10][10];
		memcpy(tmp,B,sizeof B);
		for(int y=S[i].y;y<S[i].y+S[i].a;y++) for(int x=S[i].x;x<S[i].x+S[i].a;x++) B[y][x]=i+2;
		dfs(i+1,sum+1);
		memcpy(B,tmp,sizeof B);
	}
	if(notuse){
		dfs(i+1,sum);
	}
	update_cnt(i,+1);
}

int main(){
	for(;scanf("%d%d",&w,&h),w;){
		rep(i,h) rep(j,w) scanf("%d",B[i]+j);

		S.clear();
		rep(i,h) rep(j,w) if(B[i][j]==1) {
			int a;
			for(a=1;i+a<=h&&j+a<=w;a++){
				bool ok=true;
				for(int y=i;y<i+a;y++) for(int x=j;x<j+a;x++) if(B[y][x]==0) ok=false;
				if(!ok) break;
			}
			S.push_back((square){j,i,a-1});
		}

		// 他の正方形に完全に覆われるような正方形を削除
		rep(i,S.size()){
			bool covered=false;
			rep(j,S.size()) if(i!=j) {
				if(S[j].x<=S[i].x
				&& S[j].y<=S[i].y
				&& S[i].x+S[i].a<=S[j].x+S[j].a
				&& S[i].y+S[i].a<=S[j].y+S[j].a) covered=true;
			}
			if(covered){
				S.erase(S.begin()+i);
				i--;
			}
		}
		sort(S.begin(),S.end()); // 小さい正方形から順に調べる

		rep(i,h) rep(j,w) cnt[i][j]=0;
		rep(i,S.size()) update_cnt(i,1);

		res=S.size();
		dfs(0,0);
		printf("%d\n",res);
	}

	return 0;
}

Measured memory_bytes: 0
import sys


fin = sys.stdin.readline
N, M, X = [int(elem) for elem in fin().split()]
A_list = [int(elem) for elem in fin().split()]
is_cost_taken = [False] * N
for A in A_list:
    is_cost_taken[A] = True

min_total_cost = min(
    sum(is_cost_taken[i] for i in range(X)),
    sum(is_cost_taken[i] for i in range(X + 1, N))
)
print(min_total_cost)


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

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

  if (A <= C && B >= C){
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3572
#include<stdio.h>

int main()
{
	int pointa[4],pointb[4],suma=0,sumb=0,i;
	char buf[17];

	fgets(buf,17,stdin);
	sscanf(buf,"%d %d %d %d",pointa,pointa+1,pointa+2,pointa+3);
	fgets(buf,17,stdin);
	sscanf(buf,"%d %d %d %d",pointb,pointb+1,pointb+2,pointb+3);
	for(i=0;i<4;i++)
	{
		suma+=*(pointa+i);
		sumb+=*(pointb+i);
	}
	if(suma>=sumb){printf("%d\n",suma);}
	else{printf("%d\n",sumb);}
	return 0;
}

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

int main(){
    int n, m;
    string s, t, u;
    cin >> s >> t;
    cin >> n >> m;
    cin >> u;
    if(s==u)
	n--;
    else
	m--;
    
    cout << n <<" "<<m << 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<ll, ll>;

// 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);
    int n;
    cin, n;
    int cnt = 0;
    REP(i, 0, n) {
        int a;
        cin, a;
        cnt += (i % 2 == 0 && a % 2 == 1);
    }
    print(cnt);
    return 0;
}


Measured memory_bytes: 3604
h,w = map(int,input().split())

mind = float('inf')

for i in range(1,h):
  d = max(abs(w*i-(w//2)*(h-i)),abs(w*i+(-w//2)*(h-i)),(h-i)*bool(w%2))
  mind = min(mind,d)

for i in range(1,w):
  d = max(abs(h*i-(h//2)*(w-i)),abs(h*i+(-h//2)*(w-i)),(w-i)*bool(h%2))
  mind = min(mind,d)

mind = min(mind,min(h,w)*bool(max(h,w)%3)*bool((h*w)%3))

print(mind)


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

ll gcd(ll a,ll b){
	if(a%b==0) return b;
	else{
		a%=b;
		gcd(b,a);
	}
}

ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	vector<ll> t(n);
	rep(i,n) cin >> t.at(i);
	if(n==1){
		cout << t.at(0) << endl;
		return 0;
	}
	ll ans=lcm(t.at(0),t.at(1));
	rep(i,n-2){
		ans=lcm(ans,t.at(i+2));
	}
	cout << ans << endl;
}

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

int main(){
  
  int h,a;
  cin >>h >>a;
  
  int ans;
  
  if(h%a == 0){
    ans = h/a;
  }
  else{
    ans = h/a+1;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
vector<string> ans;
signed main(){
    string s,t;cin >> s >> t;
    int n = s.size();
    bool ok = false;
    int start;
    for(int i = 0;i < n-(int)t.size()+1;i++){
        if(s[i] == '?' || s[i] == t[0]){
            auto check = [&](int start){
                for(int j = start;j < start + (int)t.size();j++){
                    //trace(start,s[j],t[j-start]);
                    if(s[j] == '?')continue;
                    if(s[j] == t[j-start])continue;
                    return false;

                }
                return true;

            };
            if(check(i)){
                start = i;
                ok = true;
            }
            if(ok){
                string ret = "";
                
                for(int i = 0;i < start;i++){
                    if(s[i] == '?')ret += 'a';
                    else ret += s[i];
                }
                
                for(int i = start;i < start + (int)t.size();i++){
                    ret += t[i-start];
                }
                
                for(int i = start + (int)t.size();i < n;i++){
                    if(s[i] == '?')ret += 'a';
                    else ret += s[i];
                }
                ans.push_back(ret);

            }
        }
    }
    
    if(!ans.size())cout << "UNRESTORABLE" << endl;
    else{
        sort(ans.begin(),ans.end());
        cout << ans[0] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#define N 100005
typedef long long ll;
using namespace std;
int n;
struct edge{
	int to,next;
}e[N<<1];
int head[N],cnt;
void add(int u,int v){
	e[++cnt]=(edge){v,head[u]};
	head[u]=cnt;
}
int son[N];
int path[N],len;
bool dfs(int x,int fa){
	int toN=0;
	for(int i=head[x];i;i=e[i].next){
		int v=e[i].to;
		if(v==fa)continue;
		if(dfs(v,x))
			toN=v;
	}
	son[fa]+=son[x]+1;

	if(x==n){
		path[++len]=n;
		return true;
	}
	if(toN){
		path[++len]=x;
		return true;
	}
	return false;
}
int main(){
	scanf("%d",&n);
	for(int i=1,u,v;i<n;++i){
		scanf("%d%d",&u,&v);
		add(u,v);add(v,u);
	}
	dfs(1,0);
	int ans=son[path[len]]-son[path[len-1]];

	for(int i=len-1;i>len/2;--i)
		ans+=son[path[i]]-son[path[i-1]];
	if(ans*2>n)
		puts("Fennec");
	else
		puts("Snuke");
	return 0;
}

Measured memory_bytes: 9088
using System;
using System.Collections.Generic;
using System.Globalization;

namespace cswork
{
    class Program
    {
        public Program() { }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        void Omame()
        {
            cin = new Scanner();
            string s = cin.next();

            bool flag = true;
            for (int i = 0; i < s.Length / 2; i++)
            {
                if (!s[i].Equals(s[s.Length - i - 1]))
                {
                    flag = false;
                }
            }

            if (flag)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        static void Main(string[] args)
        {
            new Program().Omame();
        }

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }
    }
}

Measured memory_bytes: 11220
#include<iostream>
#include<iomanip>
#include<math.h>
using namespace std;
void d()
{
    double a,b,x;
    cin >>a>>b>>x;
    double vol = a*a*b;
    double space = vol -x;
    double angle = 0;
    double a_half = atan(b/a)/M_PI*180;
    if(space>vol/2)
    {
        space -= vol/2;
        double target = vol/2 -space;
        double omega = atan((2*target/(a*b))/b)/M_PI*180;
        angle = 90 - omega;
    }
    else
    {
        double target = space;
        double theta = atan((2*target/(a*a))/a)/M_PI*180;
        angle = theta;
    }
    cout << fixed << setprecision(10);   
    cout << angle; 
    /*if(space>vol/2)
    {
        angle+=a_half;
        space -=vol/2;
        space = vol/2 - space;
        angle+=(90-a_half-binary_b(space,x,a,b,a_half));
    }
    else
    {
        angle+=binary_a(space,a,b,a_half);
    }
    */
    return;
    

}
void c()
{
    long long int n;
    cin >>n;
    long long int m = (long long int)sqrt(n);
    for(long long int i=m;i>=1;i--)
    {
        if(n%i==0)
        {
        cout << (i-1)+(n/i-1);
        return;
        }
    }

}
void b()
{
    int n;
    cin >>n;
    for(int i=1;i<10;i++)
    {
        if(n%i ==0)
     if(n/i<10)
     {
     cout<< "Yes";
     return;
     }

    }
    cout<<"No";
    return;
    


}
void a()
{
    int a,b;
    cin >>a>>b;
    if(a<10 && b<10)
    cout << a*b;
    else cout << -1;
    return;

}
int main(void){
    //a();
    //b();
    //c();
    d();
    //e();
    return 0;
}

Measured memory_bytes: 256
h,a,*m=open(0)
h,w,k,a,b,f,g=map(int,(h+a).split())
I=h*w
d=[I]*I
a=~w+a*w+b
d[a]=1
q=[a]
for s in q:
 for y,x in(1,0),(-1,0),(0,1),(0,-1):
  for z in range(k):
   i,j=s//w+y*~z,s%w+x*~z;t=i*w+j
   if(h>i>-1<j<w)-1or'.'<m[i][j]or d[t]<=d[s]:break
   if d[t]==I:q+=t,;d[t]=d[s]+1
print(d[~w+f*w+g]%I-1)

Measured memory_bytes: 132028
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def resolve():
    k = int(input())

    tmp = []
    for a in range(1, k+1):
        for b in range(1, k+1):
            tmp.append(gcd(a,b))

    ans = 0
    for c in range(1,k+1):
        for i in tmp:
            ans += gcd(i, c)
    
    print(ans)
    
resolve()

Measured memory_bytes: 9300