akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("-O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 
#define N 100001

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
    #endif
    // int T;cin>>T;while(T--) 
    {
        ll n, m, k;
        cin>>n>>m>>k;
        ll a[n], b[m];
        ll sufa[n+1], sufb[m+1];
        ifr(i, 0, n) cin>>a[i];
        ifr(i, 0, m) cin>>b[i];
        reverse(a, a+n);
        reverse(b, b+m);
        sufa[n] = sufb[m] = 0;
        ifr(i, n, 0) sufa[i]=sufa[i+1]+a[i];
        ifr(i, m, 0) sufb[i]=sufb[i+1]+b[i];
        auto fun = [&](ll mid) -> bool {
            ll mi = inf;
            ifr(i, 0, mid+1) {
                if(n-i>=0 && (m-(mid-i))>=0)
                mi = min(mi,sufa[n-i]+sufb[m-(mid-i)]);
            }
            // cout<<mid<<" "<<mi<<endl;
            return mi <= k;
        };

        ll l = 0, r = n+m, mid;
        while((r-l)>1) {
            mid = l + (r-l)/2;
            if(fun(mid)) l = mid;
            else r = mid;
        }
        if(fun(r)) cout<<r<<endl;
        else cout<<l<<endl;
    }
    return 0;
}

Measured memory_bytes: 9904
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N,A,B,count=0;
  cin>>N>>A>>B;
  long long a[N];
  for(long long i=0;i<N;++i)
    cin>>a[i];
  for(int i=0;i<N-1;++i){
    if(((a[i+1]-a[i])*A)>B)
      count+=B;
    else
      count+=(a[i+1]-a[i])*A;
  }
  cout<<count<<endl;
  return 0;
}

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

using namespace std;

int n, k;

int DFS(int n, int val){
    if(n == 0) return val;
    int a = DFS(n - 1, val * 2);
    int b = DFS(n - 1, val + k);
    return a > b ? b : a;
}
int main(){
    cin >> n >> k;
    cout << DFS(n, 1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define dbg          cout<<"Freak"<<endl;
#define dbgg(i)      cout<<i<<endl;
#define N            1e9+7;
using namespace std;
ll t;
ll arr[200005];
int main()
{
    ll a,b,c,d,e,f,g,i,j;
    cin>>a;
    for(i=1;i<=a;i++)cin>>arr[i];
    b=0;
    for(i=1;i<=a;i++)
    {
        if(i!=a&&arr[i]==i)
        {
            swap(arr[i],arr[i+1]);
            b++;
        }
        else if(arr[i]==i)
        {
            swap(arr[i],arr[i-1]);
            b++;

        }
    }
    cout<<b<<endl;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
	
	int n,m,ans;
	
	scanf("%d %d",&n,&m);
	
	if(n>=2){
		ans = (n*(n-1))/2;
	}
	
	if(m>=2){
		ans = ans + (m*(m-1))/2;
	}
	
	printf("%d",ans);
	
	return 0;
}


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

int main(){
    int n,a,x[55];
    long long d[55][55][2550]={0};
    cin>>n>>a;
    for(int i=0;i<n;i++) cin>>x[i];
    d[0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<=i;j++){
            for(int k=0;k<=2550;k++){
                d[i+1][j][k]+=d[i][j][k];
                d[i+1][j+1][k+x[i]]+=d[i][j][k];
            }
        }
    }
    long long ans=0;
    for(int i=1;i<=n;i++) ans+=d[n][i][i*a];
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 60544
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

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

    ll K;
    cin >> K;
    vec A(K);
    Rep (i, K) {
        cin >> A[i];
    }
    reverse(A.begin(), A.end());

    ll L = 2, R = 2;
    Rep (i, K) {
        ll l = L, r = R;
        L = (l + A[i] - 1) / A[i] * A[i];
        R = r / A[i] * A[i] + A[i] - 1;
        if (L > R) {
            cout << "-1\n";
            return 0;
        }
    }

    cout << L << " " << R << "\n";
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n;
bool lazy[2][4 * maxn];
ll A, B, S[maxn], seg[2][4 * maxn];

inline void pushDown(int id, int u, int l, int r)
{
	if (r - l > 1)
	{
		lazy[id][2 * u] = lazy[id][2 * u + 1] = true;
		seg[id][2 * u] = seg[id][2 * u + 1] = 0;
	}
	lazy[id][u] = true;
}

void reset(int id, int u, int l, int r, int b, int e)
{
	if (lazy[id][u])
		pushDown(id, u, l, r);
	if (b <= l && r <= e)
	{
		lazy[id][u] = true;
		seg[id][u] = 0;
		return;
	}

	int mid = (l + r) / 2;
	if (b < mid)
		reset(id, 2 * u, l, mid, b, e);
	if (e > mid)
		reset(id, 2 * u + 1, mid, r, b, e);
	seg[id][u] = (seg[id][2 * u] + seg[id][2 * u + 1]) % mod;
}

void update(int id, int u, int l, int r, int x, ll val)
{
	if (lazy[id][u])
		pushDown(id, u, l, r);
	if (r - l == 1)
	{
		seg[id][u] = (seg[id][u] + val) % mod;
		return;
	}

	int mid = (l + r) / 2;
	if (x < mid)
		update(id, 2 * u, l, mid, x, val);
	else
		update(id, 2 * u + 1, mid, r, x, val);
	seg[id][u] = (seg[id][2 * u] + seg[id][2 * u + 1]) % mod;
}

ll query(int id, int u, int l, int r, int b, int e)
{
	if (lazy[id][u])
		pushDown(id, u, l, r);
	if (b <= l && r <= e)
		return seg[id][u];

	int mid = (l + r) / 2;
	ll res = 0;
	if (b < mid)
		res = (res + query(id, 2 * u, l, mid, b, e));
	if (e > mid)
		res = (res + query(id, 2 * u + 1, mid, r, b, e));
	return res;
}

void print(int id, int u, int l, int r)
{
	if (lazy[id][u])
		pushDown(id, u, l, r);
	if (r - l == 1)
	{
		cerr << '_' << seg[id][u];
		return;
	}

	int mid = (l + r) / 2;
	print(id, 2 * u, l, mid);
	print(id, 2 * u + 1, mid, r);
}

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

	cin >> n >> A >> B;
	for (int i = 0; i < n; i++)
		cin >> S[i];

	update(0, 1, 0, n + 1, 0, 1);
	update(1, 1, 0, n + 1, 0, 1);
	
	ll valX, valY;
	for (int i = 1; i < n; i++)
	{
		int pos = upper_bound(S, S + n, S[i] - A) - S;
		ll val = query(1, 1, 0, n + 1, 0, pos + 1);
		valX = val;

		pos = upper_bound(S, S + n, S[i] - B) - S;
		val = query(0, 1, 0, n + 1, 0, pos + 1);
		valY = val;

		update(0, 1, 0, n + 1, i, valX);
		update(1, 1, 0, n + 1, i, valY);

		if (S[i] - S[i - 1] < A)
			reset(0, 1, 0, n + 1, 0, i);
		if (S[i] - S[i - 1] < B)
			reset(1, 1, 0, n + 1, 0, i);
	}
	cout << (query(0, 1, 0, n + 1, 0, n + 1) + query(1, 1, 0, n + 1, 0, n + 1)) % mod << endl;
}



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

using namespace std;
#define CLOCK_START double start_t = clock();
#define CLOCK_STOP cout << "Took: " << ((clock() - start_t) / CLOCKS_PER_SEC);
#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ii pair<int,int>
#define vi vector<int>
#define CLR(a, x) memset( a, x, sizeof( a ) )
#define LL long long
#define ULL unsigned long long
#define FOR(i,a,b) for(int i=a; i<b; i++)

int main()
{
	int N,M; cin>>N>>M;
	vector<int> vt;int i=0;
	while(i<M)
	{
		int x; cin>>x;
		vt.push_back(x);
		i++;
	}
	sort(vt.begin(), vt.end());
	vector<int> DP(N+1,INT_MAX);
	DP[0]= 0;	
	for(int i=0; i<=N; i++)
	{
		for(int j=0; j<M && vt[j]<=i; j++)
		{
			DP[i] = min(DP[i],1+DP[i-vt[j]]);
		}
	}
	cout<<(DP[N]!=INT_MAX?DP[N]:-1)<<"\n";
	return 0;
}

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

#ifdef LOCAL
#include "../lib/dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

typedef tuple<int, int, int> T;
typedef pair<ll, T> S;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("temp.1", "r", stdin);

  ll x, y, z, K;
  cin >> x >> y >> z >> K;
  vector<ll> a, b, c;
  for (int i = 0; i < x; i++) {
    ll v;
    cin >> v;
    a.push_back(v);
  }
  for (int i = 0; i < y; i++) {
    ll v;
    cin >> v;
    b.push_back(v);
  }
  for (int i = 0; i < z; i++) {
    ll v;
    cin >> v;
    c.push_back(v);
  }
  sort(a.begin(), a.end(), greater<ll>());
  sort(b.begin(), b.end(), greater<ll>());
  sort(c.begin(), c.end(), greater<ll>());
  priority_queue<S> pq;
  map<T, int> mp;
  pq.push(S(a[0] + b[0] + c[0], T(0, 0, 0)));
  int cnt = 0;
  while (!pq.empty()) {
    ll sum;
    int i, j, k;
    S s = pq.top();
    pq.pop();
    sum = s.first;
    tie(i, j, k) = s.second;
    if (mp[T(i, j, k)])
      continue;
    mp[T(i, j, k)] = 1;
    dump(sum, i, j, k);
    cout << sum << endl;
    cnt++;
    if (cnt == K)
      break;
    if (i < x - 1)
      pq.push(S(a[i + 1] + b[j] + c[k], T(i + 1, j, k)));
    if (j < y - 1)
      pq.push(S(a[i] + b[j + 1] + c[k], T(i, j + 1, k)));
    if (k < z - 1)
      pq.push(S(a[i] + b[j] + c[k + 1], T(i, j, k + 1)));
  }
  return 0;
}


Measured memory_bytes: 640
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		for(;;)
		{
			char c[]=in.next().toCharArray();
			if(c[0]=='#')
				return;
			char state='A';
			boolean judge=true;
			for(int i=0;i<c.length;i++)
			{
				if(state=='A')
				{
					if(c[i]=='0')
						state='X';
					else
						state='Y';
				}
				else if(state=='X')
				{
					if(c[i]=='0')
						judge=false;
					else
						state='Z';
				}
				else if(state=='Y')
				{
					if(c[i]=='0')
						state='X';
					else
						judge=false;
				}
			    else if(state=='Z')
				{
					if(c[i]=='0')
						state='W';
					else
						state='B';
				}
			    else if(state=='W')
				{
					if(c[i]=='0')
						state='B';
					else
						state='Y';
				}
			    else if(state=='B')
				{
					if(c[i]=='0')
						state='Y';
					else
						state='X';
				}
				if(!judge)
					break;
				if(i==c.length-1)
				{
					if(state=='B')
						break;
					else
						judge=false;
				}
			}
			System.out.println(judge ? "Yes":"No");
		}
	}

	static public void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 17140
#! /usr/bin/python3

while True:
    try:
        l=list(map(int, input().split()))
        x=(l[1]*l[5]-l[2]*l[4])/(l[1]*l[3]-l[0]*l[4])
        y=(l[2]-l[0]*x)/l[1]
        if x == 0: x = 0
        print( "{0:.3f} {1:.3f}".format(x,y))
    except:
        break

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

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

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

int main(){
    
    long long int a,b;
    cin >> a >> b;
    long long int c,d;
    cin >> c >> d;
    long long int e=lcm(c,d);

    cout << (b-a+1)-(b/c-(a-1)/c+b/d-(a-1)/d-b/e+(a-1)/e) << endl;

}

Measured memory_bytes: 3608
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft



def main():
    a, b, c = map(int, input().split())
    s = 0
    for i in range(a, b+1):
        if i % c == 0:
            s += 1
    print(s)

main()


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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	
	string s;
	cin >> s; cout << s[0];
	cin >> s; cout << s[1];
	cin >> s; cout << s[2];
	
	return 0;
}

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

int main ()
{
	bool found = 0;
	int counter = 1;
	while (!found)
	{
		int x; cin >> x;
		if (x == 0)
		{
			found = 1;
			cout << counter << '\n';
		}
		else
			counter++;
	}
}


Measured memory_bytes: 3616
use std::cmp;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let k: u32 = sc.read();
    let mut a: Vec<u32> = vec![0; n];
    let mut b: Vec<u64> = vec![0; n];
    for i in 0..n {
        a[i] = sc.read();
        b[i] = sc.read();
    }

    let mut ans = 0;
    for pos in 0..32 {
        if (k >> pos) & 1 == 0 {
            continue;
        }

        let suffix = (1 << pos) - 1;
        let prefix = (k >> (pos + 1)) << (pos + 1);
        let x = prefix + suffix;

        let mut value = 0;
        for i in 0..n {
            if (a[i] | x) == x {
                value += b[i];
            }
        }

        ans = cmp::max(ans, value);
    }
    let mut value = 0;
    for i in 0..n {
        if (a[i] | k) == k {
            value += b[i];
        }
    }

    ans = cmp::max(ans, value);
    println!("{}", ans);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


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

using namespace std;

int main() 
{
    int n, q, x, y, z;
    scanf("%d %d", &n, &q);
    
    vector<vector<int> > v(n);
    
    for(int i = 0; i < q; i++)
    {
        scanf("%d %d", &x, &y);
        
        if(x == 0)
        {
            scanf("%d", &z);
            v[y].push_back(z);
        }
        else if(x == 1)
        {
            if(v[y].size() > 0)
            {
                int j;
                for(j = 0; j < (int)v[y].size()-1; j++)
                    printf("%d ", v[y][j]);
                printf("%d\n", v[y][j]);
            }
            else
                printf("\n");
        }
        else if(x == 2)
        {
            if(v[y].size() > 0)
                v[y].clear();
        }
    }
        
    return 0;
}


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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int n;
#define MOD 1000000007
vector<int> tree[200010];

template<int64_t mod> struct Combination{
    vector<int64_t> f, rf;
 
    Combination(int max_n): f(max_n+1), rf(max_n+1){
        f[0] = 1;
        for(int i = 1;i <= max_n;i++) f[i] = f[i-1] * i % mod;
		int64_t a = f[max_n], inv = 1;
		for(int64_t b = mod-2;b > 0;b>>=1){
			if(b & 1) inv = inv*a % mod;
			a = a * a % mod;
		}
		for(int i = max_n;i >= 0;i--) inv = (rf[i] = inv) * i % mod;
    }
 
    int64_t operator()(int n, int r){
        return (r < 0 || n < r) ? 0 : f[n] * rf[r] % mod * rf[n-r] % mod;
    }
};

Combination<MOD> combi(200010);

int dp1[200010];
int dp2[200010];
int pd1[200010];
int pd2[200010];
int ans[200010];

void dfs1(int i, int par){
	int ans = 1;
	int size = 0;

	for(auto e : tree[i]){
		if(e != par){
			dfs1(e, i);
			size += dp2[e];
			ans = combi(size, dp2[e])*dp1[e] % MOD * ans % MOD;
		}
	}

	dp1[i] = ans;
	dp2[i] = size+1;
	return;
}

void dfs2(int i, int par){
	vector<int> r1(tree[i].size()+1);
	vector<int> r2(tree[i].size()+1);
	vector<int> r3(tree[i].size()+1);
	vector<int> r4(tree[i].size()+1);

	int idx = 0;
	int all = 0;
	for(auto e : tree[i]){
		if(e != par){
			r1[idx+1] = r2[idx] = dp1[e];
			r3[idx+1] = r4[idx] = dp2[e];
			all++;
			idx++;
		}
	}

	r1[0] = r2[all] = 1;
	r3[0] = r4[all] = 0;

	for(int j = 1;j <= all;j++){
		int tmp = r3[j];
		r3[j] = r3[j]+r3[j-1];
		r1[j] = combi(r3[j], tmp) * r1[j] % MOD * r1[j-1] % MOD; 
	}

	for(int j = all;j > 0;j--){
		int tmp = r4[j-1];
		r4[j-1] = r4[j-1]+r4[j];
		r2[j-1] = combi(r4[j-1], tmp) * r2[j] % MOD * r2[j-1] % MOD; 
	}

	ans[i] = combi(r3[all]+pd2[i], pd2[i]) * pd1[i] % MOD * r1[all] % MOD; 

	idx = 0;
	for(auto e : tree[i]){
		if(e != par){
			int si = r4[idx+1] + r3[idx];
			int p = combi(si, r4[idx+1]) * r2[idx+1] % MOD * r1[idx] % MOD; 
			si += pd2[i];
			p = combi(si, pd2[i])*pd1[i]%MOD * p % MOD;
			si++;
			pd1[e] = p;
			pd2[e] = si;
			dfs2(e, i);
			idx++;
		}
	}
	return;
}


signed main(){
	cin >> n;

	for(int i = 0;i < n-1;i++){
		int a, b;
		cin >> a >> b;
		a--; b--;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}

	dfs1(0, -1);

	pd1[0] = 1;
	pd2[0] = 0;
	dfs2(0, -1);

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

	return 0;
}

Measured memory_bytes: 29936
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<int> a(n);
    int sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }

    double ave = (double)sum/n;
    vector<pair<double, int>> p(n);
    rep(i, n) {
        p[i] = make_pair(abs(a[i] - ave), i);
    }
    sort(p.begin(), p.end());

    cout << p[0].second << endl;
    return 0;
}

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

const int D = 64;

bool insertVector(long long mask, vector<long long> &basis) {
	for (int i = 0; i < D; i++) {
		if ((mask & (1LL << i)) != 0) {
            if (!basis[i]) {
                basis[i] = mask;
                return true;
            }
            mask ^= basis[i];
        }
	}
    return false;
}

void testcase() {
    int N;
    cin >> N;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    string S;
    cin >> S;
    int L = S.length();
    vector<long long> basis(D, 0);
    for (int i = L - 1; i >= 0; --i) {
        if (S[i] == '0') {
            insertVector(A[i], basis);
        } else {
            if (insertVector(A[i], basis)) {
                cout << "1\n";
                return;
            }
        }
    }
    cout << "0\n";
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while (T--) {
        testcase();
    }
    return 0;
}

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

int main() {
    int A, B;
    cin >> A >> B;
    int cnt = 0;
    if (A < B) {
        cnt += B;
        --B;
    } else {
        cnt += A;
        --A;
    }
    if (A < B) {
        cnt += B;
        --B;
    } else {
        cnt += A;
        --A;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;

#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
        cout << it << " ";        \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){\
cout << it.fi << " " << it.se << endl;}


#define mod 1000000007
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
//#define endl "\n"
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
int mI(int a, int m)  {return power(a, m - 2, m);}
vector<pair<int, int>> v1;
int n;
int dp[2001][2001];
int fun(int in,int l){
    int r = n-(in - l + 1);
    if(in>=n)
        return 0;
    if(dp[in][l]!=-1)
        return dp[in][l];
    return dp[in][l]=max(v1[in].fi * abs(v1[in].se - l) + fun(in + 1, l + 1), v1[in].fi * abs(v1[in].se - r) + fun(in + 1, l));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    vec v(n);
    fo(i, n)
            cin >>
        v[i];
    v1.resize(n);
    fo(i, n)
        v1[i] = {v[i], i};
    so(v1);
    reverse(v1.begin(), v1.end());
    memset(dp, -1, sizeof(dp));
    cout << fun(0, 0);
}


Measured memory_bytes: 35124
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
signed main()
{
    SPEED;
    int n;
    cin>>n;
    int freq[n+1]={0},a[n],cnt=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        ++freq[a[i]];
    }
    for(int i=0;i<=n;i++)
    {
        cnt+=(freq[i]*(freq[i]-1))/2;
    }
    for(int i=0;i<n;i++)
    {
        int ans=cnt;
        ans-=(freq[a[i]]*(freq[a[i]]-1))/2;
        ans+=((freq[a[i]]-1)*(freq[a[i]]-2))/2;
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 5760
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	var n, m int
	var ans, max int64
	fmt.Sscan(getNextLine(scanner), &n, &m)
	xyz := make([][]int, n)
	sums := make(SortBy, n)
	for i := 0; i < n; i++ {
		xyz[i] = getIntList(scanner)
	}
	for x := -1; x <= 1; x += 2 {
		for y := -1; y <= 1; y += 2 {
			for z := -1; z <= 1; z += 2 {
				ans = 0
				for i := 0; i < n; i++ {
					sums[i] = int64(xyz[i][0]*x + xyz[i][1]*y + xyz[i][2]*z)
				}
				sort.Sort(sums)
				for i := 0; i < m; i++ {
					ans += sums[i]
				}
				if max < ans {
					max = ans
				}
			}
		}
	}
	fmt.Println(max)
}

type SortBy []int64

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i] > a[j] }


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s; cin >> s;
  int ans = INF;
  REP(i,s.size()-2){
      int tmp = (s[i]-'0') * 100 + (s[i+1] -'0') * 10 + s[i+2] - '0';
      ans = min(ans, abs(753-tmp));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define pb push_back
#define ll long long
#define all(x) x.begin() , x.end()
#define mod(x,m) ((x%m + m )%m)
using namespace std;
using namespace __gnu_pbds;
void OJ();

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

pair<int,int> intersect( pair<int,int> a , pair<int,int> b ){
    return { max(a.first , b.first) , min(a.second , b.second) };
}

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

    int n , m;
    cin >> n >> m;
    pair<int,int> p = {1 , n};
    while ( m-- ){
        pair<int,int> a;
        cin >> a.first >> a.second;
        p = intersect(p , a);
        if ( p.second < a.first )
            return cout << 0 , 0;
    }
    cout << p.second - p.first + 1;
    return 0;
}

void OJ(){
#ifndef ONLINE_JUDGE
    freopen( "C:\\Users\\ehab\\Desktop\\Code Forces\\CF\\in.txt" , "r" , stdin  );
    // freopen( "C:\\Users\\ehab\\Desktop\\Code Forces\\CF\\out.txt", "w" , stdout );
#endif // ONLINE_JUDGE
}
ll binEXP( ll x , ll pw , ll MOD )
{ ll res=1; while(pw>0){ pw%2 ? res *= x : 0; x *= x; x%=MOD; pw /= 2; res%= MOD; } return res%=MOD; }

Measured memory_bytes: 256
n, k = [ int( val ) for val in input( ).split( " " ) ]
w = [ int( input( ) ) for val in range( n ) ]
sumW = sum( w )
maxW = max( w )

minP = 0
if 1 == k:
	minP = sumW
elif n == k:
	minP = maxW
else:
	left = maxW
	right = 100000*10000
	while left <= right:
		middle = ( left+right )//2
		truckCnt = i = loadings = 0
		while i < n:
			loadings += w[i]
			if middle < loadings:
				truckCnt += 1
				if k < truckCnt+1:
					break
				loadings = w[i]
			i += 1

		if truckCnt+1 <= k:
			minP = middle
		
		if k < truckCnt+1:
			left = middle + 1
		else:
			right = middle - 1

print( minP )

Measured memory_bytes: 11136
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

int32_t n, *a, *b;

void swap (int32_t *x, int32_t *y) {
    int32_t t = *x;
    *x = *y;
    *y = t;
}

int32_t main(){
    scanf("%d", &n);
    a = (int32_t*)malloc(n * sizeof(int32_t));
    b = (int32_t*)malloc(n * sizeof(int32_t));

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

    bool bad = false;
    for (int i = 0; i < n; i++) {
        if (a[i] == b[i]) {
            bool ok = false;
            for (int j = 0; j < n; j++) {
                if (a[i] != b[j] && a[j] != b[i]) {
                    swap(&b[i], &b[j]);
                    ok = true;
                    break;
                }
            }

            if (!ok) {
                bad = true;
                break;
            }
        }
    }

    if (bad) {
        puts("No");
        exit(0);
    }

    puts("Yes");
    for (int i = 0; i < n; i++) printf("%d ", b[i]);
    puts("");
    return 0;
}


Measured memory_bytes: 3300
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a1[13]={1,2,4,7,12,20,33,54,88,143};
ll n,an[15][15],no=1;
bool vi[15];
int main(){
	cin>>n;
	for (int i=1;i<=n;i++)an[i][i]=0;
	for (int i=1;i<=n;i++){
		for (int j=i+1;j<=n;j++)an[i][j]=an[j][i]=no*a1[j-i-1];
		no*=a1[n-i];
	}
	if (n==10){an[8][10]=an[10][8]=25979230488;an[9][10]=an[10][9]=38734963162;}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++)cout<<an[i][j]<<' ';
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>


ll a, b, c;
int main() {
	cin >> a;
	b = a / 100;
	c = a % 100;
	if (b <= 12 and b >= 1 and c <= 12 and c >= 1)cout << "AMBIGUOUS" << endl;
	else if (b <= 12 and b >= 1)cout << "MMYY" << endl;
	else if (c <= 12 and c >= 1)cout << "YYMM" << endl;
	else cout << "NA" << endl;
	
}

Measured memory_bytes: 256
/******************************************
* AHAM BRAHMASHMI ;) *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define F first
#define S second


int main()
{

// #ifndef ONLINE_JUDGE
// 	// for getting input from input.txt
// 	freopen("input1.txt", "r", stdin);
// 	// for writing output to output.txt
// 	freopen("output1.txt", "w", stdout);
// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll t;
	cin>>t;
	ll out = 0;
	out = out+(t/500)*1000;
	t%=500;
	out = out+(t/5)*5;
	cout<<out<<"\n";

	return 0;
}

Measured memory_bytes: 256
def answer(H,W,ans_kari):

    for x in range(1,W):
        y1 = H // 2
        Sa1 = H * x
        Sb1 = (W - x) * y1
        Sc1 = (W - x) * (H - y1)
        M = max(Sa1,Sb1,Sc1)
        m = min(Sa1,Sb1,Sc1)

        y2 = (W - x) // 2
        Sa2 = H * x
        Sb2 = H * y2
        Sc2 = H * (W - x - y2)
        M2 = max(Sa2,Sb2,Sc2)
        m2 = min(Sa2,Sb2,Sc2)

        if ans_kari > min(M-m,M2-m2):
            ans_kari = min(M-m,M2-m2)

    return ans_kari

if __name__ == '__main__':
    H,W = [int(i) for i in input().split()]
    ans = H * W
    ans = answer(H,W,ans)
    
    H,W = W,H

    if answer(H,W,ans) < ans:
        ans = answer(H,W,ans)

    print(ans)


Measured memory_bytes: 9264
//According to Grammarly tone detector: this is 'Forceful'

#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define f first
#define s second
using namespace std;

ll x,n,w,y,z,dp[105][100005],ar[105][3];

int main(){
	cin >> n >> w;
	for (int a = 1; a <= n; a++) {
		for (int b = 1; b <= 2; b++) {
			cin >> ar[a][b];
		}
	}
	for (int a = 1; a <= n; a++) {
		for (int b = 0; b <= w; b++) {
			if (b < ar[a][1]) dp[a][b] = dp[a-1][b]; else {
				dp[a][b] = max(dp[a-1][b],dp[a-1][b-ar[a][1]] + ar[a][2]);
			} 
		}
	}
	cout << dp[n][w] << "\n";
    return 0;
}

Measured memory_bytes: 79488
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<map>
const int mod = 1e9+7;
using namespace std;
int main()
{
    long long i;
    int m;
    cin >> m;
    for(i = 1; i*i+i<2*m; i ++);
    cout << i <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int i,x,y;
	for(i=1;;i++){
		scanf("%d %d",&x,&y);
		if(x==0 && y==0){
			break;
		}
		else if(x<=y){
			printf("%d %d\n",x,y);
		}
		else{
			printf("%d %d\n",y,x);
		}
	}
	
	return 0 ;
}

Measured memory_bytes: 2696
#include <bits/stdc++.h>
//#include <atcoder/fenwicktree>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
//#define _GLIBCXX_DEBUG

using ll = long long;
using ull = unsigned long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll mod = 1e9+7;
void chmod(ll &M){
  if(M >= mod) M %= mod;
  else if(M < 0){
     M += (abs(M)/mod + 1)*mod;
    M %= mod;
}
}
ll modpow(ll x, ll n){
   if(n==0) return 1;
  ll res=modpow(x, n/2);
 if(n%2==0) return res*res%mod;
else return res*res%mod*x%mod;
}
int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  else return GCD(b, a % b);
}

using namespace std;
int main()
{
    int N, K;
    cin >> N >> K;

    int count = 1;
    while(N/K > 0) {
        count++;
        N /= K;
    } 
    cout << count << "\n";
}

Measured memory_bytes: 3548
i = gets.to_i
s = gets.split(" ").map(&:to_i)
k =[]
s.map.with_index {|n,count|
    k << [count+1,n]
}
ab = k.sort_by { |k, v| v }.to_a
i.times {|n|print "#{ab[n][0]} "}  

Measured memory_bytes: 19032
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    for _ in range(int(input())):
        a,b=map(int,input().split())
        s=(a*b)**.5
        c=int(s)-1 if(s==int(s)) else int(s)
        if(a>b): a,b=b,a # a<=b
        if(b-a<=1):
            print(2*a-2)
        elif(c*(c+1)>=a*b):
            print(2*c-2)
        else:
            print(2*c-1)
resolve()

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

using namespace std;

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

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

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

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n,m,p,a,b;

template<class T> 
class DK{
public:
    struct edge{
        ll to;
        T cost;
        edge(ll _to,T _cost):to(_to),cost(_cost){}
    };

    vector<T> d;
    vector<vector<edge>> G;

    DK(ll _n){
        d.resize(_n);
        G.resize(_n);
    }

    void add_edge(ll from,ll to,T cost){
        G[from].push_back(edge(to,cost));
        G[to].push_back(edge(from,cost));
    }

    void dijkstra(ll start,const vector<T> &t){
        fill(ALL(d),INF);
        d[start] = 0;

        typedef pair<T,P> PP;
        priority_queue<PP, vector<PP>, greater<PP>> que;
        que.push(PP(0,P(0, start)));

        while (!que.empty()){
            PP p = que.top();
            que.pop();
            ll v = p.second.second;
            ll cnt = p.second.first;
            T cost = p.first;
            if(cost - d[v] > EPS)continue;
            if(cnt == t.size())continue;
            rep(i,G[v].size()){
                edge e = G[v][i];
                ll to = e.to;
                T ncost = cost + e.cost/t[cnt];
                if (d[e.to] - ncost > EPS){
                    d[e.to] = ncost;
                    que.push(PP(d[e.to],P(cnt+1, to)));
                }
            }
        }
    }
};



int main(){
    while(cin >> n >> m >> p >> a >> b && n){
        a--; b--;
        DK<double> dk(m);
        vector<double> t(n);
        rep(i,n)cin >> t[i];
        rep(i,p){
            ll x,y; 
            double z;
            cin >> x >> y >> z;
            x--; y--;
            dk.add_edge(x,y,z);
        }
        sort(ALL(t));
        double ans = INF;
        do{
            dk.dijkstra(a,t);
            // cout << "!" << setprecision(10) << dk.d[b] << endl;
            ans = min(ans,dk.d[b]);
        }while(next_permutation(ALL(t)));
        if(fabs(ans-INF) < EPS)cout << "Impossible" << endl;
        else cout << setprecision(10) << ans << endl;
    }
}


Measured memory_bytes: 3312
/*
 * ----------------------------------------------------------------------------
 (: Bismillahir Rahmanir Rahim :) 
 * File: /root/Programming/Atcoder/C_Replacing_Integer.cpp
 * Project: /root/Programming/Atcoder
 * Created Date: Saturday, April 4th 2020, 6:16:18 pm
 * Author: Grim Firefly :)
 * Author Mail : GrimFirefly1@gmail.com
 * -----
 * Last Modified: Sat Apr 04 2020
 * Modified By: Grim Firefly :)
 * -----
 * ----------------------------------------------------------------------------
 */

//Code Start
#include <bits/stdc++.h>
using namespace std;

//constant
#define PI acos(-1.0)

//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned un;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef map<int, int> mii;
typedef map<char, char> mcc;
typedef map<char, int> mci;
typedef map<string, int> msi;
typedef map<ll, ll> mll;

//defined for loop

// defined for taking input
#define gl(x) getline(cin, x)
#define sf scanf
#define sfi(x) sf("%d", &x)
#define sfc(x) sf("%c", &x)
#define sfl(x) sf("%lld", &x)
#define sflu(x) sf("%llu", &x)
#define sfii(x, y) sf("%d %d", &x, &y)
#define sfll(x, y) sf("%lld %lld", &x, &y)
#define sfiii(x, y, z) sf("%d %d %d", &x, &y, &z)
#define sflll(x, y, z) sf("%lld %lld %lld", &x, &y, &z)

//defined for printing
#define pf printf
#define pfn pf("\n")
#define pfcas pf("Case %d: ", cas)
#define pfyes pf("YES")
#define pfno pf("NO")
#define pfi(x) pf("%d", x)
#define pfl(x) pf("%lld", x)

//Defined for loop
//increament
#define loopi(i, j, k) for (int i = j; i < k; i++)
#define loopl(i, j, k) for (ll i = j; i < k; i++)
#define loopc(i, j, k) for (char i = j; i < k; i++)
#define looplu(i, j, k) for (ull i = j; i < k; i++)
//decreament
#define loopri(i, j, k) for (int i = j; i > k; i--)
#define looprl(i, j, k) for (ll i = j; i > k; i--)
#define looprlu(i, j, k) for (ull i = j; i > k; i--)
#define looprc(i, j, k) for (char i = j; i > k; i--)
#define wa(t) while (t--)

//testcases
#define testc(t) for (char cas = 1; cas <= t; cas++)
#define testi(t) for (int cas = 1; cas <= t; cas++)
#define testl(t) for (ll cas = 1; cas <= t; cas++)

//some cmd
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define SZ 10000

//Main Function Start

int main()
{
    ull a, b;
    sflu(a);
    sflu(b);
    if (a >= b)
    {
        ull x = a % b;
        cout << min(b - x, x) << endl;
    }
    else
    {
        ull x = b - a;
        cout << min(b - a, b - x) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
#include <utility>
#include <bitset>
#include <iostream>
using namespace std;

const int inf = 1000000009;

int dfs(vector<vector<int>> &graph, bitset<101> &used, int flow, int pos, int t) {
    if (pos == t) return flow;
    used[pos] = 1;
    for (int i=0; i<graph[pos].size(); i++) {
        if (used[i] == 0 && graph[pos][i] > 0) {
            int maxflow = dfs(graph, used, min(flow, graph[pos][i]), i, t);
            if (maxflow > 0) {
                graph[i][pos] = graph[i][pos] + maxflow;
                graph[pos][i] = graph[pos][i] - maxflow;
                return maxflow;
            }
        }
    }
    return 0;
}

int maxflow(vector<vector<int>> graph, int s, int t) {
    bool f = true;
    int sum = 0;
    while (f) {
        bitset<101> b(0); b[s] = 1;
        int current = dfs(graph, b, inf, s, t);
        sum += current;
        f &= current != 0;
    }
    return sum;
}

int main() {
    int v, e;
    cin >> v >> e;
    vector<vector<int>> graph(v);
    for(auto &l: graph) l.resize(v, 0);

    for(int i=0; i<e; i++) {
        int u, v, c; cin >> u >> v >> c;
        graph[u][v] = c;
    }
    
    cout << maxflow(graph, 0, v-1) << endl;
}


Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5 ;

void solve()
{
	int a, b, c, k;
	cin>>a>>b>>c;
	cin>>k;
	while(k>0 && b<=a)
	{
		b*=2;
		k--;
	}
	while(k>0 && c<=b)
	{
		c*=2;
		k--;
	}
//	cout<<a<<", "<<b<<", "<<c<<"\n";
	if(b>a && c>b)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t = 1;
//	cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3652
# coding: utf-8
# Your code here!
K, A, B = list(map(int, input().split()))
if B-A > 2:
    K -= A-1
    if K%2 != 0:
        print(A+(B-A)*(K//2)+1)
    else:
        print(A+(B-A)*(K//2))
else:
    print(K+1)

Measured memory_bytes: 2940
using System;
using System.Linq;

namespace atcoder_Beginner_Contest096_Question2
{
    class Program
    {
        static void Main(string[] args)
        {
            var input1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var input2 = int.Parse(Console.ReadLine());

            var sum = input1.Max() * Math.Pow(2, input2) + input1.Sum() - input1.Max();
            Console.WriteLine(sum);
        }
    }
}


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

int main() {
    int D, N; cin >> D >> N;
    if (N == 100) {
        int ans = 1;
        for (int i = 0; i < D; i++) ans *= 100;
        cout << ans * 101 << endl;
    }
    else cout << pow(100, D) * N << endl;
}

Measured memory_bytes: 3880
#include <iostream>
#include <string>
using namespace std;
int main(){
    string a,b;
    cin>>a>>b;
    if(a.size()>b.size())cout<<"GREATER"<<endl;
    else if(a.size()<b.size())cout<<"LESS"<<endl;
    else {
        for(int i=0;i<a.size();i++){
            if(a[i]>b[i]){
                cout<<"GREATER"<<endl;
                return 0;
            }
            else if(a[i]<b[i]){
                cout<<"LESS"<<endl;
                return 0;
            }
            else continue;
        }
        cout<<"EQUAL"<<endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100001;
const int MOD = pow(10, 9) + 7;
// dp[i] : 13で割ったあまりが i である数値の個数
int dp[13], new_dp[13];
string s;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> s;
    // for (int i = 0; i < MAX; i++) s[i] = '?';

    dp[0] = 1;
    int mul = 1;
    for (int i = s.length() - 1; i >= 0; i--) {
        if (s[i] == '?') {
            for (int j = 0; j < 10; j++) {
                for (int k = 0; k < 13; k++) {
                    new_dp[(mul * j + k) % 13] += dp[k];
                    new_dp[(mul * j + k) % 13] %= MOD;
                }
            }
        } else {
            int j = s[i] - '0';
            for (int k = 0; k < 13; k++) {
                new_dp[(mul * j + k) % 13] += dp[k];
                new_dp[(mul * j + k) % 13] %= MOD;
            }
        }

        for (int l = 0; l < 13; l++) {
            dp[l] = new_dp[l];
            new_dp[l] = 0;
        }
        mul *= 10;
        mul %= 13;
    }

    cout << dp[5] << endl;
    return 0;
}


Measured memory_bytes: 512
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <numeric>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr long long MOD = 1000000000 + 7;
constexpr double DINF = 100000000000000000.0;
constexpr long long INF = 9000000000000000000;
//                        3999999996000000001

const double PI = acos(-1);

int main() {
	int n, k;
	vector<LL>w, h;
	LL ans = pow(10, 9) * 2 * pow(10, 9) * 2;
	cin >> n >> k;
	int a, b;
	vector<LL> w2, h2;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		w.emplace_back(a);
		h.emplace_back(b);

		w2.emplace_back(a);
		h2.emplace_back(b);

	}
	sort(w2.begin(), w2.end());
	sort(h2.begin(), h2.end());
	for (int xi = 0; xi < n; ++xi) {
		for (int xj = xi + 1; xj < n; ++xj) {
			for (int yi = 0; yi < n; ++yi) {
				for (int yj = yi + 1; yj < n; ++yj) {
					int count = 0;
					LL lx = w2[xi], rx = w2[xj];
					LL by = h2[yi], uy = h2[yj];
					for (int i = 0; i < n; ++i) {
						if (lx <= w[i] && w[i] <= rx && by <= h[i] && h[i] <= uy) {
							count++;
						}
					}
					if (count >= k) ans = min(ans, LL(rx - lx) * LL(uy - by));
				}
			}
		}
	}
	cout << ans << endl;
	//system("pause");
}

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


int main() {
  int N, M;
  cin >> N >> M;
 vector<int> high(N);
  for(int i = 0; i < N; i++){
    cin >> high.at(i);
  }
  vector<int> ans(N);
  for(int i = 0; i < M; i++){
    int a, b;
    cin >> a >> b;
    if(high.at(a-1) >= high.at(b-1)){
      ans.at(b-1) = 1;
    }
    if(high.at(a-1) <= high.at(b-1)){
      ans.at(a-1) = 1;
    }
  }
  
  int count;
  count = 0;
  for(int i = 0; i < N; i++){
    if(ans.at(i) == 0){
      count++;
    }
  }
  cout << count;
  return 0;
}

Measured memory_bytes: 4032
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>

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


int main() {
	

	long long  A[3][3];
	cin >> A[0][0] >> A[0][1] >> A[0][2];
	cin >> A[1][0] >> A[1][1] >> A[1][2];
	cin >> A[2][0] >> A[2][1] >> A[2][2];

	long long N;
	cin >> N;

	vector<long long> v_b(N);
	rep(i, N) cin >> v_b[i];

	long long temp[3][3];

	for (long long i = 0; i < 3; i++)
	{
		for (long long j = 0; j < 3; j++)
		{
			temp[i][j] = 0;
		}
	}

	for (long long i = 0; i < 3; i++)
	{
		for (long long j = 0; j < 3; j++)
		{
			rep(k, N)
			{
				if (v_b[k] == A[i][j])
				{
					temp[i][j] += 1;
				}
			}
		}
	}

	long long f = 0;

	for (long long j = 0; j < 3; j++)
	{
		if (temp[j][0] != 0 && temp[j][1] != 0 && temp[j][2] != 0)
		{
			f += 1;
		}
	}

	for (long long i = 0; i < 3;i++)
	{
		if (temp[0][i] != 0 && temp[1][i] != 0 && temp[2][i] != 0)
		{
			f += 1;
		}
	}

	if (temp[1][1] != 0 && temp[2][2] != 0 && temp[0][0] != 0)
	{
		f += 1;
	}

	if (temp[0][2] != 0 && temp[1][1] != 0 && temp[2][0] != 0)
	{
		f += 1;
	}
	
	if (f != 0)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;

	}

	return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 1e5 + 7;
int n, a[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    reverse(a, a + n);
    int l = 2, r = 2;
    for (int i = 0; i < n; ++i) {
        l = ((l + a[i] - 1) / a[i]) * a[i];
        r = (r / a[i]) * a[i] + a[i] - 1;            
        if (r < l) {
            cout << "-1\n";
            exit(0);
        }   
    }   
    cout << l << ' ' << r << '\n';
}   

Measured memory_bytes: 1024