akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

// AtCoder
#include <atcoder/all>
using namespace atcoder;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...)
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
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; }
#define fls(x) (64 - __builtin_clzll(x))
#define pcnt(x) __builtin_popcountll(x)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    ll ans = (ll)s.size() * (s.size() + 1) / 2;
    for (int x : lcp_array(s, suffix_array(s))) ans -= x;
    cout << ans << "\n";
    /***************************************************/
    /* Submit this code from the browser if using ACL! */
    /***************************************************/
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

void YN(bool flg){if(flg) cout << "YES" << endl; else cout << "NO" << endl;}
void Yn(bool flg){if(flg) cout << "Yes" << endl; else cout << "No" << endl;}
void yn(bool flg){if(flg) cout << "yes" << endl; else cout << "no" << endl;}

int main()
{
    int n, k;
    cin >> n >> k;
    vi p(n);
    rep(i, n) cin >> p[i];
    sort(all(p));
    int ans = 0;
    rep(i, k) ans += p[i];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612
import sys
INF=float('inf')
def Bellmanford(n,edges,r):
  d=[INF]*n
  d[r]=0
  for i in range(n):
    for u,v,c in edges:
      if d[u]!=INF and d[u]+c<d[v]:
        d[v]=d[u]+c
        if i==n-1 and v==n-1:
          return 'inf'
  return (-1)*d[n-1]
n,m=map(int,input().split())
edges=[0]*m
for i in range(m):
  a,b,c=map(int,input().split())
  edges[i]=(a-1,b-1,-c)
ans=Bellmanford(n,edges,0)
print(ans)

Measured memory_bytes: 3368
def calc(a, b, c)
  (a+b+c+1)/2
end

n, m, k = gets.split.map(&:to_i)
l1 = Array.new(n){ [0]*n }
l2 = Array.new(n){ [] }
l3 = []
m.times do
  a, b, c = gets.split.map(&:to_i)
  a -= 1; b -= 1
  l1[a][b] = l1[b][a] = c
  l2[a] << b; l2[b] << a
  l3 << [a,b,c]
end
arr = []
dist = [1<<31]*n
k.times do
  i = gets.to_i-1
  arr << i
  dist[i] = 0
end

until arr.empty?
  s = arr.min{ |a,b| dist[a] <=> dist[b] }
  arr.delete s
  l2[s].each do |t|
    d = dist[s] + l1[s][t]
    if (old = dist[t]) > d
      dist[t] = d
      arr << t if old == 1 << 31
    end
  end
end
ret = 0
m.times{ |i| ret = [ret, calc(dist[l3[i][0]], dist[l3[i][1]], l3[i][2])].max }
p ret

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

int n;
int a[100000], in[100000];
bool used[100000];

int main() {
	scanf("%d", &n);
	rep(i, n) {
		scanf("%d", &a[i]);
		a[i] = (i + a[i]) % n;
		in[a[i]]++;
	}
	int cnt = 0;
	queue<int>que;
	rep(i, n) {
		if (!in[i] && !used[i]) {
			used[i] = true;
			que.push(i);
		}
		while (!que.empty()) {
			int v = que.front(); que.pop();
			cnt++;
			in[a[v]]--;
			if (!used[a[v]] && !in[a[v]]) {
				used[a[v]] = true;
				que.push(a[v]);
			}
		}
	}
	printf("%d\n", n - cnt);
}

Measured memory_bytes: 4064
// https://atcoder.jp/contests/abc095/tasks/arc096_b

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

const int N_MAX = 1e5;
const ll C_MAX = 1e14;
const int V_I_MAX = 1e9;
const ll INF = 1e15;

int N;
ll C;
ll x[N_MAX];
ll v[N_MAX];

ll f1[N_MAX + 1];
ll f2[N_MAX + 1];
ll r1[N_MAX + 1];
ll r2[N_MAX + 1];

void solve() {
  // fill(f1, f1 + N, -INF);
  // fill(f2, f2 + N, -INF);
  ll sum = 0;
  f1[0] = f2[0] = 0;
  REP(i, N) {
    sum += v[i];
    f1[i + 1] = max(f1[i], sum - x[i]);
    f2[i + 1] = max(f2[i], sum - x[i] * 2);
  }
  ll rsum = 0;
  r1[N] = r2[N] = 0;
  for (int i = N - 1; i >= 0; i--) {
    rsum += v[i];
    r1[i] = max(r1[i + 1], rsum - (C - x[i]));
    r2[i] = max(r2[i + 1], rsum - (C - x[i]) * 2);
  }
  ll ans = 0;
  REP(i, N + 1) {
    ans = max(ans, f1[i]);
    ans = max(ans, r2[i] + f1[i]);
    ans = max(ans, r1[i]);
    ans = max(ans, f2[i] + r1[i]);
  }
  printf("%lld\n", ans);
}

void input() {
  scanf("%d%lld", &N, &C);
  REP(i, N) scanf("%lld%lld", x + i, v + i);
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<algorithm>
 
using namespace std;
typedef long long Int;
#define INF (1LL<<60)
#define rep(i,n) for(Int (i)=0;(i)<(n);(i)++)
Int dp[20][54000];
Int table[54000];

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

	Int X,A,B;
	cin >> X;
	cin >> A;
	cin >> B;

	X -= A;
	while(X-B>=0) X -=B;

	cout << X<<endl;
	return 0;
}

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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA();
            //SolveB();
            //SolveC();
            //SolveD();
        }
        private const long MOD = 1000000007;
       
        static void SolveA()
        {
            var o = ReadAndParseIntArr();
            int a = o[0];
            int b = o[1];
            int c = o[2];
            int d = o[3];

            int l = a + b;
            int r = c + d;
            if( l > r)
            {
                Console.WriteLine("Left");
            }else if( l == r)
            {
                Console.WriteLine("Balanced");
            }
            else
            {
                Console.WriteLine("Right");
            }
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if( x == 2) { return true; }
            if( x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while( i * i <= x)
            {
                if( x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }

        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 11092
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] c = new int[n - 1];
    int[] s = new int[n - 1];
    int[] f = new int[n - 1];
    for(int i = 0; i < n - 1; i++) {
      c[i] = sc.nextInt();
      s[i] = sc.nextInt();
      f[i] = sc.nextInt();
    }
    int[] ans = new int[n];
    for(int i = n - 2; i >= 0; i--) {
      int t = s[i] + c[i];
      for(int p = i + 1; p < n - 1; p++) {
        for(int j = Math.max(t, s[p]); j < Math.max(t, s[p]) + f[p]; j++) {
          if((j - s[p]) % f[p] == 0) {
            t = j + c[p];
            break;
          }
        }
      }
      ans[i] = t;
    }
    for(int i = 0; i < n; i++) {
      System.out.println(ans[i]);
    }
  }
}

Measured memory_bytes: 27580
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector> 
using namespace std;
typedef pair<int,int> P;
typedef long long ll;

int main()
{
	int a,b;
	while(~scanf("%d %d",&a,&b))
	{
		int add=a+b;
		int sub=a-b;
		int mul=a*b;
		int ans=max(add,max(sub,mul));
		printf("%d\n",ans);
	}
	return 0;
}


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

#define ll long long int
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MOD = 1e9 + 7;
typedef unsigned long long u64;

int main()
{
    IOS;
    int t=1;
    //cin >> t;
    while (t--)
    {
        int k, a, b;
        cin >> k >> a >> b;
        bool flag = false;
        for (int i = a; i <= b; i++)
        {
            if (i % k == 0)
            {
                flag = true;
                break;
            }
        }
        if (flag) cout << "OK" << endl;
        else cout << "NG" << endl;
    }
    return 0;
}


Measured memory_bytes: 3656
#include <cstdio>
#include <iostream>
using namespace std;
int a;
int b;
int c;
int x;

int main(void){
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> x;
    int count=0;
    for(int i=0;i<=a;i++)
        for(int j=0;j<=b;j++)
            for(int k=0;k<=c;k++)
                if(i*500 + j*100 + k*50 == x)count++; 
    cout << count;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m;
int nums[1000+10];

int find(int L, int R, int vl)
{
	int l = L, r = R;
	int mid = 0;
	while(l < r)
	{
		mid = (l+r) / 2;
		if(nums[mid] < vl)
			l = mid+1;
		else
			r = mid;
	}
	return l;
}

int main()
{
	while(true)
	{
		scanf("%d%d", &n, &m);
		if(!n && !m)
			break;
		for(int i = 0 ;i < n; i++)
		{
			scanf("%d", &nums[i]);
		}
		sort(nums, nums+n);
		int ans = 0;
		for(int i = n-1; i >= 0; i--)
		{
			if(nums[i] >= m)
				continue;
//			int pos = lower_bound(nums, nums+n, m-nums[i]) - nums;
			int pos = find(0, n-1, m-nums[i]);
			for(int j = pos; j >= 0; j--)
			{
				if(m-nums[i] >= nums[j] && i != j)
				{
					pos = j;
					break;
				}
			}
			if(i == pos)
				break;
			int tmp = nums[pos];
			if(tmp+nums[i] <= m)
				ans = max(ans, nums[i]+tmp);
		}
		if(ans)
			printf("%d\n", ans);
		else
			printf("NONE\n");
	}
	return 0;
}


Measured memory_bytes: 3272
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>
using namespace std;

//char s[1003][1003];
int vis[1003][1003];
struct node
{
    int x;int y;
};

int main()
{
    int h,w;
    cin>>h>>w;
    queue<node> q;
    memset(vis,0,sizeof(vis));
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char s;cin>>s;
            if(s=='#'){
                node a;a.x=i;a.y=j;
                q.push(a);
                vis[i][j]=1;
            }
        }
    }
    while(!q.empty()){
        node a;a=q.front();q.pop();
        if(a.x>0&&!vis[a.x-1][a.y]){
            vis[a.x-1][a.y]=vis[a.x][a.y]+1;
            node b;b.x=a.x-1;b.y=a.y;
            q.push(b);
        }
        if(a.y>0&&!vis[a.x][a.y-1]){
            vis[a.x][a.y-1]=vis[a.x][a.y]+1;
            node b;b.x=a.x;b.y=a.y-1;
            q.push(b);
        }
        if(a.x<h-1&&!vis[a.x+1][a.y]){
            vis[a.x+1][a.y]=vis[a.x][a.y]+1;
            node b;b.x=a.x+1;b.y=a.y;
            q.push(b);
        }
        if(a.y<w-1&&!vis[a.x][a.y+1]){
            vis[a.x][a.y+1]=vis[a.x][a.y]+1;
            node b;b.x=a.x;b.y=a.y+1;
            q.push(b);
        }
    }
    int ans=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            ans=max(ans,vis[i][j]);
            //cout<<vis[i][j];
        }
        //cout<<endl;
    }
    cout<<ans-1<<endl;
    return 0;
}


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

#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define unq(v) sort(v.begin(),v.end()),v.erase(unique(v.begin(),v.end()),v.end())
#define ll long long
#define pb push_back
#define fill(arr) memset(arr,0,sizeof(arr))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define pi acos(-1.00)
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    _ios;
    set<string>s;
    ll n;
    cin>>n;
    while(n--)
    {
        string x;
        cin>>x;
        s.insert(x);
    }
    cout<<s.size()<<endl;
}



Measured memory_bytes: 19196
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public int[] Sarray() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var xs = Sarray();
            var sorted = xs.OrderBy(x => x).ToArray();
            var half = (N-1) / 2;
            var left = sorted[half];
            var right = sorted[half + 1];
            for(var i=0;i<N;i++)
            {
                Console.WriteLine(xs[i] <= left ? right : left);
            }
        }

    }
}


Measured memory_bytes: 41104
def partition(data, left, right):
    pivot = int(data[right][2:])
    i = left - 1
    for j in range(left, right):
        if int(data[j][2:]) <= pivot:
            i += 1
            data[i], data[j] = data[j], data[i]
    data[i+1], data[right] = data[right], data[i+1]
    return i+1

def quick_sort(data, left, right):
    if left < right:
        new_pivot = partition(data, left, right)
        quick_sort(data, left, new_pivot-1)
        quick_sort(data, new_pivot+1, right)

def main():
    num = raw_input()
    pairs_quick = []
    pairs_check = []
    for i in range(int(num)):
        pair = raw_input()
        pairs_quick.append(pair)
        pairs_check.append(pair)
    
    quick_sort(pairs_quick, 0, int(num)-1)
    pairs_check = sorted(pairs_check, key = lambda i:int(i[2:]))
    if pairs_quick == pairs_check:
        print "Stable"
    else:
        print "Not stable"

    print "\n".join(pairs_quick)

if __name__ == "__main__":
    main()

Measured memory_bytes: 19252
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    if(n>=400 && n<=599)
        cout <<8;
     else if(n>=600 && n<=799)
        cout <<7;
        else if(n>=800 && n<=999)
        cout <<6;
        else if(n>=1000 && n<=1199)
        cout <<5;
        else if(n>=1200 && n<=1399)
        cout <<4;
        else if(n>=1400 && n<=1599)
        cout <<3;
        else if(n>=1600 && n<=1799)
        cout <<2;
        else if(n>=1800 && n<=1999)
        cout <<1;

}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
 
int main() {
	double w,h,x,y;
  	cin >>w>>h>>x>>y;
    
   cout<<w*h/2<<endl;
  if(w/2==x&&h/2==y)
    cout<<"1"<<endl;
  else
    cout<<"0"<<endl;}

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

using namespace std;

typedef long long ll;

int main() {
		ll N;
		cin >> N;
		vector<ll> v(5, 0);
		for ( int i = 0; i < 5; i++ ) cin >> v[i];

		ll ans = ((N-1) / min( {v[0], v[1], v[2], v[3], v[4]} ) + 1) + 4;

		cout << ans << endl;

		return 0;
}


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

bool use[10000][1260];
int pc[1000];

int main(){
    int n, m, r, q;
    while(cin >> n >> m, n+m){
        memset(use, 0, sizeof(use));
        memset(pc, 0, sizeof(pc));

        cin >> r;
        int a, b, c, d;
        for(int i = 0; i < r; i++){
            cin >> a >> b >> c >> d;
            b--, c--;
            if(d == 1){
                pc[b] = a;
            }else if(d == 0){
                for(int i = pc[b]; i < a; i++){
                    use[c][i] = true;
                }
                pc[b] = 0;
            }
        }

        cin >> q;
        int ts, te, x;
        for(int i = 0; i < q; i++){
            cin >> ts >> te >> x;
            x--;
            int cnt = 0;
            for(int j = ts; j < te; j++)    if(use[x][j])   cnt++;
            cout << cnt << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 15384
#include <algorithm>
#include <complex>
#include <iostream>

using namespace std;

int main() {
    int W, a, b;
    cin >> W >> a >> b;

    int aw = a + W;
    if (a <= b && b <= aw) {
        cout << 0 << endl;
        return 0;
    }

    int bw = b + W;
    cout << min(min(abs(a - b), abs(a - bw)), abs(aw - b)) << endl;
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    int arr[n+5],frr[n+5];
    for(int i=0;i<n;i++)cin>>arr[i],frr[i]=arr[i];
    sort(frr,frr+n);
    int counter=0;
    for(int i=0;i<n;i++)
    {
        if(arr[i]!=frr[i])counter++;
    }
    if(counter==2||counter==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

int main() {
	string s;
	int ap=-1,zp,len,ans=0,i;
	cin>>s;
	len=s.size();
	for(i=0;i<len;i++){
		if(s[i]=='A'&&ap==-1) ap=i;
		if(s[i]=='Z') zp=i;
	}
	ans=zp-ap+1;
	cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    int ans = INT_MAX;
    for (int i = 0; i <= n - k; i++)
    {
        int temp = x[i + k - 1] - x[i] + min(abs(x[i]), abs(x[i + k - 1]));
        ans = min(ans,temp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
n = int(input())
a  = []
for i in range(n):
    s = input()
    a.append(s)

base = 0
for i in range(n):
    tar = a[i]
    for k in range(0,len(tar)-1):
        if tar[k:k+2] == "AB":
            base += 1


fir_b = []
las_a = []
b_a = []
for i in range(n):
    tar = a[i]
    if tar[0] == "B" and tar[-1] == "A":
        b_a.append(i)
    elif tar[0] == "B":
        fir_b.append(i)
    elif tar[-1] == "A":
        las_a.append(i)


addi = 0
if len(b_a) == 0:
    addi += min(len(fir_b),len(las_a))
else:
    addi += len(b_a)-1
    if len(las_a) > 0 and len(fir_b) >0:
        addi += 2+ min(len(fir_b),len(las_a))-1
    elif len(las_a) == 0 and len(fir_b) >0:
        addi += 1
    elif len(las_a) > 0 and len(fir_b) == 0:
        addi += 1


print(addi+base)


Measured memory_bytes: 46808
import sys

input = sys.stdin.readline
I = list(input())
I.pop()
A, B, C, D = list(map(int, I))

if A+B+C+D == 7:
    print("{}+{}+{}+{}=7".format(A, B, C, D))
elif A+B+C-D == 7:
    print("{}+{}+{}-{}=7".format(A, B, C, D))
elif A+B-C+D == 7:
    print("{}+{}-{}+{}=7".format(A, B, C, D))
elif A-B+C+D == 7:
    print("{}-{}+{}+{}=7".format(A, B, C, D))
elif A+B-C-D == 7:
    print("{}+{}-{}-{}=7".format(A, B, C, D))
elif A-B-C+D == 7:
    print("{}-{}-{}+{}=7".format(A, B, C, D))
elif A-B+C-D == 7:
    print("{}-{}+{}-{}=7".format(A, B, C, D))
elif A-B-C-D == 7:
    print("{}-{}-{}-{}=7".format(A, B, C, D))


Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define MOD (long long)(1e9+7)
using namespace std;
long long x,k,d;
int main()
{
	cin >> x >> k >> d;
	x=abs(x);
	if(x/d >= k) 
	{
		cout << x-k*d;
		return 0;
	}
	k-=(x/d); x-=d*(x/d);
	if(k%2) x=abs(x-d);
	cout << x;
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr int MOD = 1000000007;

ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}

ll powmod(ll a, ll n, ll m = MOD) {
    ll ret = 1;
    for (; n > 0; n >>= 1, a = a * a % m) {
        if (n % 2 == 1) {
          ret = ret * a % m;
        }
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    map<pair<ll, ll>, P> mp;
    int zero = 0;
    for (int i = 0; i < n; i++) {
        ll ai, bi;
        cin >> ai >> bi;
        if (ai == 0 && bi == 0) {
            zero++;
            continue;
        }
        ll g = abs(gcd(ai, bi));
        ai /= g;
        bi /= g;
        if (ai >= 0 && bi > 0) mp[make_pair(ai, bi)].first++;
        if (ai > 0 && bi <= 0) mp[make_pair(-bi, ai)].second++;
        if (ai < 0 && bi >= 0) mp[make_pair(bi, -ai)].second++;
        if (ai <= 0 && bi < 0) mp[make_pair(-ai, -bi)].first++;
    }
/*     
    for (auto p : mp) {
        cout << "[" << setw(2) << p.first.first << ", " << setw(2) << p.first.second << "] : " << p.second.first << " | " << p.second.second << endl;
    }
*/
    ll ans = 1;
    for (auto p : mp) {
        ll now = 1;
        int s = p.second.first;
        int t = p.second.second;
        now += powmod(2, s) - 1;
        now += powmod(2, t) - 1;
        now %= MOD;
        ans *= now;
        ans %= MOD;
    }
    
    ans = ans + zero - 1;
    ans = (ans + MOD) % MOD;
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 16052
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int main()
{
	int n = 0;

	scanf("%d", &n);

	for (int i = 0; i < 15; i++) {
		if ((n - 7 * i) >= 0) {
			if ((n - 7 * i) % 4 == 0) {
				goto YES;
			}
		}
	}

	printf("No");
	return 0;


YES:
	printf("Yes");
	return 0;


}

Measured memory_bytes: 128
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))


n,k = inpl()
a = inpl()
ok = max(a)
ng = 0
def sol(x):
    cnt = 0
    for i in range(n):
        cnt += (a[i]+x-1)//x-1
    if cnt <= k:
        return True
    return False
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    if sol(mid):
        ok = mid
    else:
        ng = mid
print(ok)

Measured memory_bytes: 108164
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int s;
 cin>>s;
 int l=s/100;
 int r=s%100;
 if(l>=1&&l<=12)
 {
     if(r>=1&&r<=12)
        cout<<"AMBIGUOUS";
     else
        cout<<"MMYY";
 }
 else if(r>=1&&r<=12)
    cout<<"YYMM";
 else
    cout<<"NA";


}


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

int main() {
  int n;
  cin >> n;
  map<string, int> m;
  rep(i,n) {
    string s;
    cin >> s;
    if (m.count(s) == 0) m[s] = 1;
    else m[s]++;
  }
  int maxi = 1;
  vector<string> v;
  for (auto p : m) {
    if (maxi < p.second) {
      v.clear();
      v.push_back(p.first);
      maxi = p.second;
    }
    else if (maxi == p.second) {
      v.push_back(p.first);
    }
  }
  for (auto x : v) {
    cout << x << endl;
  }
}

Measured memory_bytes: 26868
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vll vector <pll>
#pragma 03
using namespace std;
double dp[305][305][305];
int main(){
	cout << fixed << setprecision(10);
	double n;
	ll c[3];
	cin >> n;
	for (int i = 0; i<3; i++) c[i] = 0;
	for (int i = 0; i<n; i++){
		int a; cin >> a; c[a-1]++;
	}
	for (int k = 0; k<305; k++){
		for (int j = 0; j<305; j++){
			for (int i = 0; i<305; i++){
				if (i == 0 && j == 0 && k == 0) dp[i][j][k] = 0;
				else if (i + j + k > n) dp[i][j][k] = 0;
				else{
					double f = 0.0;
					if (i > 0) f += (i * dp[i-1][j][k]);
					if (j > 0 && i + 1 < 305) f += (j * dp[i+1][j-1][k]);
					if (k > 0 && j + 1 < 305) f += (k * dp[i][j+1][k-1]);
					f /= n; f++; f *= n; f /= (i + j + k);
					dp[i][j][k] = f;
				}
			}
		}
	}
	cout << dp[c[0]][c[1]][c[2]] << endl;
	return 0;
}
 


Measured memory_bytes: 221952
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x) memset(x,0,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 1
/*------------------------------------------------------------*/
int n,m;
ll a[301][301];
int u[301][301];
int main(){
	in(n);
	ll ans=0;
	FOR(i,1,n)
		FOR(j,1,n){
			inl(a[i][j]);
			if(j>i)ans+=a[i][j];
		}
		FOR(i,1,n)
			FOR(j,i+1,n)
			FOR(k,1,n)
			if(i!=j&&i!=k&&j!=k){
				if(a[i][k]+a[k][j]==a[i][j]&&!u[i][j]){
					ans-=a[i][j];
					u[i][j]=1;
				}
				if(a[i][k]+a[k][j]<a[i][j]){
				 	out(-1);
				 	return 0;
				 }
			}
	outl(ans);
}

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

using namespace std;

using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1000000000;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<llong> A(n);
    rep(i, n) cin >> A[i];

    llong ans = 0;
    llong tmp = A[n - 1];
    rep(i, n - 1) {
        ans += A[n - 2 - i]*tmp;
        ans %= MOD;
        tmp += A[n - 2 - i];
        tmp %= MOD;
    }

    cout << ans << endl;

    return 0;
}

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A, B;
    cin >> A >> B;
    if (A == 1 && B == 1)
    {
        cout << "1 2" << endl;
        cout << "#." << endl;
        return 0;
    }
    vector<vector<char>> map(100, vector<char>(100, '.'));
    ll blackCount = B;
    ll whiteCount = A;
    ll blockCount = 0;
    ll hidariueH = 0;
    ll hidariueW = 0;
    while (blockCount < whiteCount - 1)
    {
        map.at(hidariueH + 1).at(hidariueW) = '#';
        map.at(hidariueH).at(hidariueW + 1) = '#';
        map.at(hidariueH + 1).at(hidariueW + 1) = '#';
        hidariueW += 2;
        blockCount++;
        if (hidariueW == 100)
        {
            hidariueH += 2;
            hidariueW = 0;
        }
    }
    if(blockCount > 0)
    {
        blackCount--;
    }
    blockCount = 0;
    ll blackH = 99;
    ll blackW = 0;
    while (blockCount < blackCount)
    {
        map.at(blackH).at(blackW) = '#';
        blackW += 2;
        if (blackW == 100)
        {
            blackH -= 2;
            blackW = 0;
        }
        blockCount++;
    }
    cout << "100 100\n";
    for (int i = 0; i < 100; i++)
    {
        for (int j = 0; j < 100; j++)
        {
            cout << map.at(i).at(j);
        }
        cout << "\n";
    }
    cout.flush();
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000
#define mp make_pair
#define pb push_back

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

int main() {
  string N;
  cin >> N;
  if ((N[0] == N[1] &&
      N[1] == N[2]) ||
      (N[1] == N[2] &&
      N[2] == N[3])) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = 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; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 200005;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,p = 2,c = 0;
    cin >> n;
    string ans = "";
    if (n == 0){
        PRINT(0);
        return 0;
    }
    while(n != 0){
        c++;
        if (n%p){
            ans = '1'+ans;
            if (c%2) n -= p/2;
            else n += p/2;
        }
        else ans = '0'+ans;
        p *= 2;
    }
    PRINT(ans);
}


Measured memory_bytes: 256
N = int(input())
all = []
for i in range(N):
  tmp = []
  a,b = input().split()
  tmp.append(int(b))
  tmp.append(int(a))
  all.append(tmp)

all_sort = sorted(all)
ruikei = 0
judge = 'Yes'
for item in all_sort:
  ruikei += item[1]
  if ruikei > item[0]:
    judge = 'No'
    break;

print(judge)

Measured memory_bytes: 40328
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<P> a = new ArrayList<>();

        for(int i=0; i<n; i++) {
            a.add(new P(sc.nextLong(), sc.nextLong()));
        }
        Collections.sort(a);

        long res = 0;

        for(int i=0; i<n; i++) {
            if(i % 2 == 0) {
                res += a.get(i).a;
            } else {
                res -= a.get(i).b;
            }
        }

        System.out.println(res);
    }

    public static class P implements Comparable<P>{
        long a;
        long b;
        public P(long a, long b) {
            this.a = a;
            this.b = b;
        }
        @Override public int compareTo(P o) {
            long diff =  o.a + o.b - (a+b);
            if(diff > 0) return 1;
            if(diff < 0) return -1;
            return 0;
        }
    }

}


Measured memory_bytes: 89992
#include <stdio.h>
#include <stdlib.h>
int main(void) {
  void* m=malloc( 2*sizeof(int) );
  if(! scanf("%d%d", (int*)m, (int*)m+1) ) exit(0);
  *(double*)m= (double) *(int*)m / *((int*)m+1);
  printf("%f\n", *(double*)m);
}

Measured memory_bytes: 128
//   Author:Arturia
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cctype>
#include<ctime>
#include<cstdlib>
#include<string>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#include<bitset>
#include<vector>
#define rep(x,a,b) for (int x=a;x<=(int)b;x++)
#define drp(x,a,b) for (int x=a;x>=(int)b;x--)
#define cross(x,a) for (int x=hd[a];~x;x=nx[x])
#define ll long long
#define inf (1<<29)
#define PII pair<int,int>
#define PDD pair<double,double>
#define mk(a,b) make_pair(a,b)
#define fs first
#define sc second
#define pb push_back
#define VI vector<int>
#define VS vector<string>
#define MC(a,b) memcpy(a,b,sizeof b)
#define MS(a,b) memset(a,b,sizeof a)
using namespace std;
inline ll rd(){
	ll x=0;int ch=getchar(),f=1;
	while (!isdigit(ch)&&(ch!='-')&&(ch!=EOF)) ch=getchar();
	if (ch=='-'){f=-1;ch=getchar();}
	while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}
inline void rt(ll x){
	if (x<0) putchar('-'),x=-x;
	if (x>=10) rt(x/10),putchar(x%10+'0');
		else putchar(x+'0');
}
ll n,x,ans;
ll solve(ll a,ll b){
	if (a<b) swap(a,b);
	if (!b) return 0;
	if (a%b==0) return solve(b,a%b)+b*(a/b*2-1);
		else return solve(b,a%b)+b*(a/b*2);
}
int main(){
	n=rd(),x=rd();
	rt(n+solve(n-x,x)),putchar('\n');
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dpnapSacdp(int W, ll wt[], ll val[], int n) { 
   int i, w; 
   ll dp[n+1][W+1]; 
   for (i = 0; i <= n; i++) { 
       for (w = 0; w <= W; w++) { 
           if (i==0 || w==0) 
               dp[i][w] = 0; 
           else if (wt[i-1]<=w) 
                 dp[i][w]=max(val[i-1]+dp[i-1][w-wt[i-1]],dp[i-1][w]); 
           else
                 dp[i][w] = dp[i-1][w]; 
       } 
   } 
  
   return dp[n][W]; 
} 
int main() {
	int n,W;
	cin>>n>>W;
	ll w[n],v[n];
	for(int i=0;i<n;i++)
	cin>>w[i]>>v[i];

	cout<<dpnapSacdp(W,w,v,n)<<endl;
	// your code goes here
	return 0;
}

Measured memory_bytes: 79104
X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse = True)
q.sort(reverse = True)

ans = p[:X] + q[:Y] + r
ans.sort(reverse = True)
print(sum(ans[:X+Y]))

Measured memory_bytes: 23328
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
const int mod = 1000000007;
const int max_n = 200005;
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;
}
int main(){
    ll h,w;cin >> h >>w;
    vector<vector<char>> g(h+2,vector<char>(w+2,'#'));
    rep(i,h)rep(j,w)cin >> g[i+1][j+1];
    rep(i,h+2){
        rep(j,w+2){
            cout << g[i][j] ;
        }
        cout <<endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <iterator>
#include <math.h>
#include <cmath>
#include <stdlib.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <regex>
#include <unordered_set>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <cassert>
#include <time.h>
#include <numeric>
#include <complex>
 
using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using D = double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
 
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define makeunique(x) sort(all(x)), (x).resize(unique(all(x)) - (x).begin())
#define rep(i, x)  for(int i = 0; i < (x); i++)
#define rrep(i, x) for(int i = (x - 1); i >= 0; i--)
#define sqrt(x) sqrt(abs(x))
#define y1 y1_1234413
#define j1 j1_235
#define y0 y0_235
#define j0 j0_256
#define fi first
#define se second
#define re return
#define prev PREV
#define next next
#define sz(x) ((int)x.size())
 
template<typename T> T sqr(T a) { re a * a; }
template<typename T> T gcd(T a, T b) { re b ? gcd(b, a % b) : a; }
template<typename T> T sgn(T a) { re a > 0 ? 1 : (a < 0 ? -1 : 0); }
template<typename T> T abs(T a) { re a > 0 ? a : -a; }
 
const ld st = 0.000001;
const ld pi = acos((ld)-1);
const int mod = 1000000007;
 
 
#define FILENAME ""
 
const ll MAXN = 100002;
                          
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    //freopen("sum2.in", "r", stdin);
    //freopen("sum2.out", "w", stdout);
    ll n,m;
    cin >> n >> m;
    vector <ll> a, b;
    for (int i = 0; i < n; i++) {
     	ll x;
     	cin >> x;
     	a.pb(x);
    }
    for (int j = 0; j < n; j++) {
     	ll x;
     	cin >> x;
     	b.pb(x);
    }
    sort(all(a));
    sort(all(b));
    reverse(all(b));
    ll left = -1, right = 1e13;
    while (right - left > 1) {
    	ll mid = (left + right)/2;
    	ll temp = 0;
    	for (int i = 0; i < n; i++) {
    		if (a[i]*b[i] >= mid) {
    			temp += (a[i] - mid/b[i]); 	
    		}
    	}
    	if (temp <= m) {
    	 	right = mid;
    	}
    	else {
    	 	left = mid;
    	}
    }
    cout << right << endl;	
    re 0;
}

Measured memory_bytes: 4848
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
#define BIGP   1000000007
#define INF_I  std::numeric_limits<ll>::max()
#define INF_F  std::numeric_limits<float>::infinity()
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll K;
    cin >> K;
    ll c = 7 % K;
    std::array<bool, 1000000> done = {};
    //
    ll r = 1;
    while(c != 0)
    {
        if (done[c])
        {
            cout << -1;
            return 0;
        }
        done[c] = true;
        c = (c * 10 + 7) % K;
        ++r;
        
    }
    cout << r;
    return 0;
}

Measured memory_bytes: 4200
import java.util.Scanner;

public class Main {

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

        int[] numArray = new int[scanner.nextInt()];

        for (int i = 0; i < numArray.length; i++) {
            numArray[i] = scanner.nextInt();
        }

        int count = -1;
        boolean flg = true;
        while (flg) {
            count++;
            for(int i=0;i<numArray.length;i++){
                if(numArray[i]%2==1){
                    flg=false;
                    break;
                }else{
                    numArray[i]/=2;
                }
            }
        }

        System.out.println(count);
    }
}

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

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

	int q;cin>>q;
	while(q--){
		int b,e,t;cin>>b>>e>>t;
		swap_ranges(next(a.begin(),b), next(a.begin(),e), next(a.begin(),t));
	}

	bool isFirst=true;
	for(auto &&ai: a){
		if(!isFirst) cout<<" ";
		cout<<ai;
		isFirst &= false;
	}
	cout<<endl;
  return 0;
}



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

int main() {
	int k, a = 0;
	int n[5];
	for(int i = 0; i < 5; i++){
		cin >> n[i];
		for(int j = 0; j < i; j++){
			if(i != j){
				a = max(a, abs(n[i] - n[j]));
			}
		}
	}
	cin >> k;
	if (a > k){
		cout << ":(" << endl;
		return 0;
	}
	cout << "Yay!" << endl;
	
	return 0;
}

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

int main(){
    int i,n,count=0;
    bool ok=false;
    long long max=0,half=0,min=0;
    cin >> n;
    vector<long long> a(n),b(n);
    for(i=0;i<n;i++){
        cin >> a.at(i);
        if(max<a.at(i))max=a.at(i);
    }
    half = max/2 + max%2;
    for(i=0;i<n;i++){
        b.at(i) = abs(a.at(i)-half);  
        if(i==0){min=b.at(i);count=i;}
        if(min>=b.at(i)&&max!=a.at(i)){min=b.at(i);count=i;} 
    }
    cout << max << " " << a.at(count) << endl;
    return 0;
}

Measured memory_bytes: 1792
import itertools
n = int(input())
s = ([str(_) for _ in range(n)])
l = list(itertools.permutations(s, n))
x = []
y = []
for i in range(n):
    xi,yi = map(int,input().split())
    x.append(xi)
    y.append(yi)
c = 0.0
for j in l:
    for k in range(n-1):
        c += ((x[int(j[k])]-x[int(j[k+1])])**2 + (y[int(j[k])]-y[int(j[k+1])])**2)**0.5
print(c/len(l))

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

int64_t baisuu(const int64_t &a,const int64_t &b){
    return a/b;
}

int64_t gcd(int64_t a,int64_t b){
    if(a<b){
        a^=b;
        b^=a;
        a^=b;
    }
    if(a%b==0)return b;
    else return gcd(b,a%b);
}

int64_t gcm(int64_t a,int64_t b){
    return a*b/gcd(a,b);
}

int main(void){
    int64_t a,b,c,d;
    cin>>a>>b>>c>>d;

    int64_t ac,ad,bc,bd,acd,bcd;
    int64_t g=gcm(c,d);
    ac=baisuu(a-1,c);
    ad=baisuu(a-1,d);
    bc=baisuu(b,c);
    bd=baisuu(b,d);
    acd=baisuu(a-1,g);
    bcd=baisuu(b,g);
    int64_t bwareru=(bc+bd-bcd)-(ac+ad-acd);
    int64_t result=b-a+1-bwareru;
    cout<<result<<endl;


    return 0;
}

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

#define ll long long

int main(){
    
    int i,j;
    int N,K;
    int x,ans=0;

    cin >> N >> K;

    for(i=0;i<N;i++){
        cin >> x;
        if(K-x < x)ans+=2*(K-x);
        else ans += 2*x;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    int64_t N, M;
    cin >> N >> M;
    vector<int64_t> A(N);
    for (int64_t& a : A) {
        cin >> a;
    }
    int64_t sum = accumulate(A.begin(), A.end(), (int64_t)0);

    int64_t ok_num = 0;
    for (int64_t a : A) {
        if (a * 4 * M >= sum) {
            ok_num++;
        }
    }
    cout << (ok_num >= M ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin>>n;
  vecll v(n+2);
  REP(i,n)cin>>v[i];
  constexpr ll INF = 1e15;
  int offset = 2;
  vector<vecll> dp(3, vecll(n+3*offset, -INF));
  dp[0][0] = 0;
  REP(i,n+2) {
    REP(j,3) {
      dp[j][i+offset] = max(dp[j][i+offset], dp[j][i] + v[i]);
      if (j < 2) dp[j+1][i+offset+1] = max(dp[j+1][i+offset+1], dp[j][i] + v[i+1]);
      if (j < 1) dp[j+2][i+offset+2] = max(dp[j+2][i+offset+2], dp[j][i] + v[i+2]);
    }
  }
  ll ans = -INF;
  REP(i,3) ans = max(ans, dp[i][n+1+offset]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11120
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        k: usize
    }
    let d = 1000000007;
    let mut dp = vec![vec![vec![0; 2 * n * n]; n]; n + 1];
    dp[0][0][0] = 1;
    for i in 0..n {
        for j in 0..n {
            for k in 2 * j..2 * n * n {
                dp[i + 1][j][k] = (2 * j + 1) * dp[i][j][k - 2 * j] % d;
                if j < n - 1 {
                    dp[i + 1][j][k] += (j + 1) * (j + 1) % d * dp[i][j + 1][k - 2 * j] % d;
                }
                if j > 0 {
                    dp[i + 1][j][k] += dp[i][j - 1][k - 2 * j];
                }
                dp[i + 1][j][k] %= d;
            }
        }
    }
    println!("{}", dp[n][0][k]);
}


Measured memory_bytes: 119036
#include <bits/stdc++.h>
//#include <iostream>
//#include <string>
//#include <sstream>
//#include <vector>
//#include <algorithm>
//#include <map>
//#include <set>
//#include <math.h>
//#include <unordered_map>
//#include <queue>
//#include <stack>
//#include <iomanip>

using namespace std;

#define PI 3.141592653589793238462643383279502884
#define Max 100005
#define ll long long
#define mod 1000000007
#define EPS 1E-9



int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

    ll x,sum=0;
    cin >> x;
    for(int i=1;i<=x;i++)
    {
        sum+=i;
        if(sum>=x)
        {
            cout << i << endl;
            break;
        }
    }



	return 0;
}


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

using namespace std;


int main() {
	long long int N, A, B, C, D;
	cin >> N >> A >> B >> C >> D;
	long long int Nmin = 0, Nmax = N, Nmid = 0;
	for( long long int Nmid = 0; Nmid <= N - 1; Nmid++ ) {
		long long int ansmin = A + Nmid*C - ( N - Nmid - 1 )*D;
		long long int ansmax = A + Nmid*D - ( N - Nmid - 1 )*C;

		
		if( ansmin <= B&&B <= ansmax ) {
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 384