akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

class _Class
{
	void _Do()
	{
		//
		var _s = _stringArray();
		var n_ = int.Parse(_s[0]);

		var a_ = _intArray();

		var x = new int[3];
		for(int i=0;i<n_;i++){
			if (a_[i] % 4 == 0)
			{
				x[0]++;
			}
			else if (a_[i] % 2 == 0)
			{
				x[1]++;
			}
			else
				x[2]++;
		}
		if (x[1] == 0 && x[0]+1 >= x[2])
			Console.WriteLine("Yes");
		else if (x[0] >= x[2])
			Console.WriteLine("Yes");
		else
			Console.WriteLine("No");

	}

	static void Main(string[] args)
	{
		new _Class()._Do();
	}


	// 1
	string[] _stringArray()
	{
		return Console.ReadLine().Split();
	}

	// 2.1 -2,147,483,648 ~ +2,147,483,647
	int[] _intArray()
	{
		var _s = Console.ReadLine().Split();

		var x = new int[_s.Length];
		for (var i = 0; i < _s.Length; i++)
			x[i] = int.Parse(_s[i]);

		return x;
	}

	// 2.2 -9,223,372,036,854,775,808 ~ +9,223,372,036,854,775,807
	long[] _longArray()
	{
		var _s = Console.ReadLine().Split();

		var x = new long[_s.Length];
		for (var i = 0; i < _s.Length; i++)
			x[i] = long.Parse(_s[i]);

		return x;
	}
}

Measured memory_bytes: 18400
#include <string>
#include <vector>
#include <iostream>
using namespace std;
vector<int> x[100]; int n, t;
bool same(vector<int> a, vector<int> b) {
	for(int i = 0; i < 4; i++) {
		for(int j = 0; j < 4; j++) {
			for(int k = 0; k < 4; k++) {
				for(int l = 0; l < 4; l++) {
					string s;
					for(int m = 0; m < i; m++) s += 'N';
					for(int m = 0; m < j; m++) s += 'E';
					for(int m = 0; m < k; m++) s += 'S';
					for(int m = 0; m < l; m++) s += 'W';
					for(int i = 0; i < s.size(); i++) {
        				t = a[0];
        				switch(s[i]) {
        				case 'N':
            				a[0] = a[1];
            				a[1] = a[5];
        					a[5] = a[4];
        				    a[4] = t;
        				    break;
        				case 'E':
        				    a[0] = a[3];
        				    a[3] = a[5];
        				    a[5] = a[2];
        				    a[2] = t;
        				    break;
        				case 'S':
        				    a[0] = a[4];
        				    a[4] = a[5];
        				    a[5] = a[1];
        				    a[1] = t;
        				    break;
        				case 'W':
        				    a[0] = a[2];
        				    a[2] = a[5];
        				    a[5] = a[3];
    					    a[3] = t;
    					   	break;
	    				}
					}
					if(a == b) return true;
				}
			}
		}
	}
	return false;
}
int main() {
	scanf("%d", &n);
	for(int i = 0; i < n; i++) {
		x[i].resize(6);
		for(int j = 0; j < 6; j++) scanf("%d", &x[i][j]);
	}
	for(int i = 0; i < n; i++) {
		for(int j = i + 1; j < n; j++) {
			if(same(x[i], x[j])) {
				printf("No\n"); return 0;
			}
		}
	}
	printf("Yes\n");
	return 0;
}

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

int main(void){
    int w,h,n;
    cin >> w >> h >> n;
    int xmax = w,xmin = 0,ymax = h,ymin = 0,x,y,a;
    for(int i = 0;i < n;i++){
        cin >> x >> y >> a;
        if(a == 1){
            xmin = max(xmin,x);
        } else if(a == 2){
            xmax = min(xmax,x); 
        } else if(a == 3){
            ymin = max(ymin,y);
        } else {
            ymax = min(ymax,y);
        }
    }
    cout << max(0,xmax-xmin) * max(0,ymax-ymin) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
  int W,H,x,y,r;
  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
  if((x-r>=0) && (x+r<=W) && (y-r>=0) && (y+r<=H)) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 584
use std::cmp::{self, Ordering};
use std::collections::*;
use std::io::{self, Read};

const MOD: usize = 1000000007;

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock());

    let n: usize = sc.read().unwrap();
    let k: usize = sc.read().unwrap();

    println!("{}", if n % k == 0 { 0 } else { 1 });
}

struct Scanner<R: Read> {
    reader: R,
}

impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: std::str::FromStr>(&mut self) -> Option<T> {
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse()
            .ok()
    }

    fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Option<Vec<T>> {
        (0..n).map(|_| self.read()).collect()
    }

    fn read_vec2d<T: std::str::FromStr>(&mut self, m: usize, n: usize) -> Option<Vec<Vec<T>>> {
        (0..m).map(|_| self.read_vec(n)).collect()
    }

    fn read_board(&mut self, n: usize) -> Option<Vec<Vec<char>>> {
        (0..n)
            .map(|_| {
                self.read::<String>()
                    .map(|s| s.chars().collect::<Vec<char>>())
            })
            .collect()
    }
}


Measured memory_bytes: 4352
a, b, c, d, e, f = map(int, input().split())
x = set()
y = set()
for A in range(0, f + 1, 100 * a):
    for B in range(0, f + 1, 100 * b):
        if A + B > f:
            break
        if A + B:
            x.add(A + B)
for C in range(0, f + 1, c):
    for D in range(0, f + 1, d):
        if C + D > f:
            break
        y.add(C + D)
ans = 0
w = 100 * a
s = 0
for X in x:
    for Y in y:
        if X + Y <= f and 100 * Y / X <= e:
                if ans < Y / (X + Y):
                    ans = Y / (X + Y)
                    w = X
                    s = Y
print(w + s, s)

Measured memory_bytes: 3188
// In the name of God

#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>

using namespace std;

#define rep(i, n) for (int i = 0, _n = (int)(n); i < _n; ++i)
const int N = (int) 1e6 + 6, mod = (int) 0;
int a[N];
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i], a[i]--;
    int res = 0;
    for (int i = 0; i < n; ++i)
        res += (a[a[i]] == i);
    res >>= 1;
    cout << res << endl;

}


Measured memory_bytes: 640
n = int(input())
x = []
med = []
a = []
b = []
for i in range(n):
    ai, bi = map(int, input().split())
    x.append((ai, bi))
    a.append(ai)
    b.append(bi)
a.sort()
b.sort()

if n % 2 == 1:
    min_med = a[(n+1)//2 - 1]
    max_med = b[(n+1)//2 - 1]
    print(max_med - min_med + 1)
else:
    min_med = (a[n//2 - 1] + a[n//2]) / 2
    max_med = (b[n//2 - 1] + b[n//2]) / 2
    ans = (max_med - min_med) / 0.5
    ans += 1
    ans = int(ans)
    print(ans)


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


/* Raiyan Noory Rady,CSE'17,RUET
Email:raiyannooryrady@gmail.com
Smile->Desire->Unity->Effort->Struggle->Success->Again smile :)
*/

#define ll long long int
#define pf push_front
#define mod  1000000007
#define inf  1000000000000000000
#define pi  acos(-1.0)
#define maxn  1000009
#define sorted(s)  sort(s.begin(),s.end())
#define sortarr(a) sort(a,a+n)
#define slc(n) scanf("%I64d", &n)
#define sl(n)  scanf("%lld", &n)
#define sf(n)  scanf("%lf", &n)
#define si(n)  scanf("%d", &n)
#define sch(n)  scanf(" %c", &n)
#define ss(n)  scanf("%s", n)
#define prf printf
#define pb  push_back
#define fr first
#define sc second
#define all(a)  a.begin(),a.end()
#define forl(n) for(i=0;i<n;i++)
/*STL library functions

sort(first_iterator, last_iterator) – To sort the given vector.

reverse(first_iterator, last_iterator) – To reverse a vector.

*max_element (first_iterator, last_iterator) – To find the maximum element of a vector.

*min_element (first_iterator, last_iterator) – To find the minimum element of a vector.

accumulate(first_iterator, last_iterator, initial value of sum) – Does the summation of vector elements

count(first_iterator, last_iterator,x) – To count the occurrences of x in vector.

find(first_iterator, last_iterator, x) – Points to last address of vector ((name_of_vector).end())
 if element is not present in vector.

binary_search(first_iterator, last_iterator, x) – Tests whether x exists in sorted vector or not.

lower_bound(first_iterator, last_iterator, x) – returns an iterator pointing to the first element in the range [first,last)
which has a value not less than ‘x’.

upper_bound(first_iterator, last_iterator, x) – returns an iterator pointing to the first element in the range [first,last)
 which has a value greater than ‘x’.

arr.erase(position to be deleted) – This erases selected element in vector and shifts and resizes the vector elements accordingly.

arr.erase(unique(arr.begin(),arr.end()),arr.end()) – This erases the duplicate occurrences in sorted vector in a single line.

distance(first_iterator,desired_position) – It returns the distance of desired position from the first iterator.
This function is very useful while finding the index.

next_permutation(first_iterator, last_iterator) – This modified the vector to its next permutation.

prev_permutation(first_iterator, last_iterator) – This modified the vector to its previous permutation.
*/

using namespace std;

int main()
{
    string s;
    cin>>s;
    ll sz=s.size(),i,f=0;
    for(i=0;i<sz;i++)
    {
        if(i%2)
        {
            if(s[i]=='L'||s[i]=='U'||s[i]=='D')
                continue;
            else
            {
                f=1;
                break;
            }
        }
        else
        {
            if(s[i]=='R'||s[i]=='U'||s[i]=='D')
                continue;
            else
            {
                f=1;
                break;
            }
        }
    }
 if(f)
    cout<<"No"<<endl;
 else
    cout<<"Yes"<<endl;

    return 0;
}






Measured memory_bytes: 256
def comb2(n)
  if n < 2
    0
  elsif n & 1 == 0
    n / 2 * (n - 1)
  else
    (n - 1) / 2 * n
  end
end

N, M = gets.chomp.split.map(&:to_i)
A = gets.chomp.split.map(&:to_i)
sum_modM_idx = {}

sum_modM = 0
A.each do |a|
  sum_modM += a
  sum_modM %= M
  sum_modM_idx[sum_modM] = 0 unless sum_modM_idx.key?(sum_modM)
  sum_modM_idx[sum_modM] += 1
end

ans = sum_modM_idx.key?(0) ? sum_modM_idx[0] : 0
sum_modM_idx.each_value do |n|
  ans += comb2(n)
end
puts ans

Measured memory_bytes: 12676
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main() {
   string s;
	cin >> s;
	int x, y;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == 'A'){
			x = i;
			break;
		}
	}
	for (int i = s.length() - 1; i >= 0; i--)
	{
		if (s[i] == 'Z'){
			y = i;
			break;
		}
	}
	cout << (y - x) + 1 << endl;
    return 0;}




Measured memory_bytes: 3388
$%=<>;$_=[glob]for@D=<>;map{$s[$$_[1]]+=$-=$s[$$_[0]]+$$_[2]-$s[$$_[1]]for@D;$_-$%or$s=$s[-2]}2..2*(@s=(_,0,(-1e15)x$%));print$s<$s[-2]?inf:$s

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int x;
 	cin >> x;
 	for (int i = 0; i < 1145141919; i++){
 		if(i*i>x){
 			cout << (i-1)*(i-1) << endl;
 			return 0;
 		}
 	}
 }

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>


const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	lint N, H;
	cin >> N >> H;

	vector<lint> a(N), b(N);
	for (int i = 0; i < N; i++) cin >> a[i] >> b[i];

	sort(a.begin(), a.end());
	DMP(a);
	sort(b.begin(), b.end());
	DMP(b);
	lint sum = 0;
	auto x = upper_bound(b.begin(), b.end(), a.back());
	DMP(x - b.begin());
	DMP(x - b.end());
	for (auto itr = b.end(); itr != x; itr--) {
		sum += *(itr - 1);
		DMP(*(itr - 1),sum);
		if (sum >= H) {
			cout << b.end() - itr + 1 << "\n";
			return 0;
		}
	}

	H -= sum;
	cout << (b.end() - x) + (H - 1) / a.back() + 1 << "\n"; 

	return 0;
}

Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a[] = new int[3];
		for(int i = 0; i < 3; i++) a[i] = scan.nextInt();
      
		Arrays.sort(a);
      
		System.out.print(a[0] * a[1] / 2);
	}
}

Measured memory_bytes: 21972
//https://codeforces.com/contest/1293/problem/C
//BROWNIE TK

#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()

#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en

#define le length()
#define mp make_pair
#define mt make_tuple
#define acc(v) accumulate(all(v), 0)
#define F first
#define S second

#define pll pair<lli, lli>
#define pii pair<int, int>
#define pil pair<int, lli>

#define forz(i, n) for (int i = 0; i < n; i++)
#define fore(i, m, n) for (int i = m; i <= n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rfore(i, m, n) for (int i = n; i >= m; i--)

#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define highll(n) __builtin_popcountll(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)

#define bset(a, p) ((a) | (1ll << (p)))
#define bchk(a, p) ((a) & (1ll << (p)))
#define bxor(a, p) ((a) ^ (1ll << (p)));
#define brem(a, p) (bchk(a, p) ? (bxor(a, p)) : (a))
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/

#define lb lower_bound
#define ub upper_bound
#define er equal_range

#define findnot find_first_not_of

#define maxe *max_element
#define mine *min_element

#define mod 1000000007
#define mod2 998244353
#define gcd __gcd
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements sbtriectly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;

/*STD funcions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
lli modi(lli a, lli m) { return power(a, m - 2, m); }
/*CODE BEGINS*/
int main()
{
    kira;
    lli a,b;
    cin>>a>>b;
    cout<<(a+b-1)/b;
    return 0;
}

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

int dist(int x1, int x2, int y1, int y2){
    return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
}

int main(){
    string s;
    cin >> s;
    cout << (s.substr(0, 4) == "YAKI" ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    private static int merge (int A[], int left, int mid, int right) {
        int cnt = 0;
        int n1 = mid - left;
        int n2 = right - mid;
        int L[] = new int[n1+1], R[] = new int[n2+1];
        for (int i = 0; i < n1; i++)
            L[i] = A[left + i];
        L[n1] = Integer.MAX_VALUE;
        for (int i = 0; i < n2; i++)
            R[i] = A[mid + i];
        R[n2] = Integer.MAX_VALUE;
        int i = 0;
        int j = 0;
        for (int k = left; k < right; k++) {
            cnt++;
            if (L[i] <= R[j]) {
                A[k] = L[i];
                i++;
            }
            else {
                A[k] = R[j];
                j++;
            }
        }
        return cnt;
    }

    private static int mergeSort(int A[], int left, int right) {
        int cnt = 0;
        if(left + 1 < right) {
            int mid = (left + right) / 2;
            cnt += mergeSort(A, left, mid);
            cnt += mergeSort(A, mid, right);
            cnt += merge(A, left, mid, right);
        }
        return cnt;
    }

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n, A[], cnt;
        n = sc.nextInt();
        A = new int[n];
        for (int i = 0; i < n; i++)
            A[i] = sc.nextInt();
        cnt = mergeSort(A, 0, A.length);
        for (int i = 0; i < n; i++) {
            System.out.print(A[i]);
            if (i != n - 1) System.out.print(" ");
        }
        System.out.println();
        System.out.println(cnt);
    }
}

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



int main() {
  double n,m;
 cin >> n >> m;
 if (m == 1){
   cout << 0;
 }else if(m == n){
   cout << 1;
 }else{
 int ans = 0;
 int cnt = 0;
 for (int i=0;i<30;i++){
   ans += n;
   if (ans >= m){
      cnt++;
      cout << cnt;
      break;
   }else{
     ans--;
     cnt++;
   }
}
}
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		BigDecimal[] an = new BigDecimal[n];

		for (int i = 0; i < n; i++) {
			BigDecimal a = scan.nextBigDecimal();
			if (BigDecimal.ZERO.compareTo(a) == 0) {
				System.out.println(0);
				System.exit(0);
			}
			an[i] = a;
		}

		BigDecimal ans = BigDecimal.ONE;
		for (int i = 0; i < an.length; i++) {
			ans = ans.multiply(an[i]);
			if (ans.compareTo(BigDecimal.ONE.scaleByPowerOfTen(18)) > 0) {
				System.out.println(-1);
				System.exit(0);
			}
		}

		if (ans.compareTo(BigDecimal.ONE.scaleByPowerOfTen(18)) <= 0) {
			System.out.println(ans);
		} else {
			System.out.println(-1);
		}

		scan.close();
	}

}


Measured memory_bytes: 66944
import java.util.*;
import java.math.*;
import java.text.*;
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i=0; i<5; i++){
			list.add(in.nextInt());
		}
		Collections.sort(list);
		System.out.println(list.get(4)+" "+list.get(3)+" "+list.get(2)+" "+list.get(1)+" "+list.get(0));
	}
}

Measured memory_bytes: 12000
INF = 10**9+7 

n = int(input())
a = list(map(int, input().split()))
s = set()
result = [x for x in a if x in s or s.add(x)]
indexes = [i for i, x in enumerate(a) if x == result[0]]
l0 = indexes[0]+1
l1 = indexes[1] +1

def bin_pow(a,n):
    ans = 1
    mag = a
    while(n>0):
        if n%2==0:
            mag = (mag*mag)%INF
            n /= 2
        else:        
            ans = ans* mag%INF
            n -= 1
    return ans

factorial = [0]*(n+2)
inverse_factorial = [0] * (n+2)

factorial[0] = 1
for i in range(1, n+2):
    factorial[i] = factorial[i-1] * i % INF

inverse_factorial[n+1] = bin_pow(factorial[n+1], INF-2)
for i in range(n,-1,-1):
    inverse_factorial[i] = (inverse_factorial[i+1]*(i+1))%INF

def combi(n, r):
    if n < 0 or r < 0 or n < r:
        return 0
    return (factorial[n] * inverse_factorial[r] )%INF * (inverse_factorial[n-r]% INF)

for i in range(1,n+2):
    print((combi(n+1,i)-combi(n-(l1-l0), i-1) )%INF)
    

Measured memory_bytes: 20576
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 2e5+9;

template <unsigned M> struct modular {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
  static constexpr unsigned mod = M;
  using m = modular;
  unsigned v;
  modular(long long x = 0) : v((x %= mod) < 0 ? x + mod : x) {}
  m operator-() const { return m() -= *this; }
  m& operator+=(m b) { if ((int)(v += b.v - mod) < 0) v += mod; return *this; }
  m& operator-=(m b) { if ((int)(v -= b.v) < 0) v += mod; return *this; }
  m& operator*=(m b) { v = (uint64_t)v * b.v % mod; return *this; }
  m& operator/=(m b) { return *this *= power(b, mod - 2); }
  friend m operator+(m a, m b) { return a += b; }
  friend m operator-(m a, m b) { return a -= b; }
  friend m operator*(m a, m b) { return a *= b; }
  friend m operator/(m a, m b) { return a /= b; }
  friend bool operator==(m a, m b) { return a.v == b.v; }
#pragma GCC diagnostic pop
};
using mint = modular<int(1e9+7)>;

ll A[N], B[N];
int main() {
    ios_base::sync_with_stdio(0);
    ll a,b,T,cas=0;
    int n, k;
    cin>>n>>k;
    for(int i=1;i<=n+1;++i) {
        A[i]=A[i-1]+(i-1);
    }
    B[n+1]=n;
    for(int i=n;i>0;--i) {
        B[i]=B[i+1]+(i-1);
    }
    // for(int i=1;i<=n+1;++i)    cerr<<B[i]<<" ";
    mint s=0;
    for(int i=k;i<=n+1;++i) {
    	// cerr<<
    	// cerr<<i<<" "<<A[i]<<" "<<B[n+1-i+1]<<endl;
        s += B[n+1-i+1]-max(0ll, A[i]-1);
        cerr<<s.v<<endl;
        // cerr<<s.v<<endl;
    }
    if(k==1) s+=1;
    cout<<s.v<<endl;
    return 0;
}

Measured memory_bytes: 6684
K, N = map(int, input().split())

A = [int(_) for _ in input().split()]


B = []
for i in range(N):
    if i == N - 1:
        B.append(A[0] + K - A[i])
    else:
        B.append(A[i + 1] - A[i])
print(K - max(B))

Measured memory_bytes: 26444
import Foundation

let string = readLine()!.split(separator: " ")
let N = Int(string[0])!
let K = Int(string[1])!

func pow(_ x: Int, _ y: Int) -> Int {
    NSDecimalNumber(decimal: pow(Decimal(x), y)).intValue
}
func powmod(_ base: Int, _ exponent: Int, _ mod: Int = 1_000_000_007) -> Int {
    guard exponent != 0 else { return 1 }

    var temporary = 1
    var b = base
    var p = exponent

    while p > 1 {
        if p % 2 == 1 {
            temporary = temporary * b % mod
            p -= 1
        }
        if p != 0 {
            b = b * b % mod
            p /= 2
        }
    }

    return temporary * b % mod
}

let mod = pow(10, 9) + 7

var memory = Array(repeating: 0, count: K + 1)
for i in (1 ... K).reversed() {
    var result: Int = powmod(K / i, N) % mod

    guard K / i >= 2 else {
        memory[i] = result
        continue
    }
    for j in 2 ... K / i {
        result -= memory[j * i]
    }
    memory[i] = result
}

var sum = 0
for i in 1 ... K {
    sum += (memory[i] * i % mod)
    sum %= mod
}

print(sum)


Measured memory_bytes: 14408
import sys
s = sys.stdin.readlines()
 
N,M,Q = map(int,s[0].split())
 
Section = [[0]*N for _ in [0]*N]
for L,R in (map(int, e.split()) for e in s[1:M+1]):
    Section[L-1][R-1] += 1
 
Sum = [[0]*(N+1) for _ in [0]*(N+1)]
for i in range(N):
    for j in range(N):
        Sum[i+1][j+1] = Sum[i][j+1]+Sum[i+1][j]-Sum[i][j]+Section[i][j]
 
for p,q in (map(int, e.split()) for e in s[M+1:]):
    print(Sum[q][q]-Sum[p-1][q])

Measured memory_bytes: 36864
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScan in = new MyScan(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, MyScan in, PrintWriter out) {
            long[] t1 = new long[6];
            t1[0] = in.nextInt();
            t1[1] = in.nextInt();
            t1[2] = in.nextInt();

            long res = t1[0] - t1[1];

            if (in.nextLong() % 2 == 1) {
                res = -res;
            }
            out.println(res);
        }

    }

    static class MyScan {
        private final InputStream in;
        private byte[] inbuf = new byte[1024];
        public int lenbuf = 0;
        public int ptrbuf = 0;

        public MyScan(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = in.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

    }
}



Measured memory_bytes: 22740
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<iomanip>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
	double a,b;
	cin>>a>>b;
	cout<<fixed<<setprecision(10)<<1/(1/a+1/b)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  string s, t;
  bool flag = false;
  cin >> s >> t;
  for(int i = 0; i < s.size(); i++){
    if(s == t){
      flag = true;
      break;
    }
    s = s[s.size() - 1] + s.substr(0, s.size() - 1);
  }
  cout << (flag ? "Yes" : "No") << endl;
  return 0;
}

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

using namespace std;

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

const int INF = 1001001001;

int main(){
    int N;
    cin >> N;
    vector<P> x(N), y(N);
    
    for(int i = 0; i < N; ++i){
        int temp;
        cin >> temp;
        x[i] = P(temp, i);
        cin >> temp;
        y[i] = P(temp, i);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    
    vector<vector<P>> graph(N);     // (cost, to)
    for(int i = 0; i < N - 1; ++i){
        P p1 = x[i];
        P p2 = x[i + 1];
        int temp = p2.first - p1.first;
        graph[p1.second].push_back(P(temp, p2.second));
        graph[p2.second].push_back(P(temp, p1.second));
        
        p1 = y[i];
        p2 = y[i + 1];
        temp = p2.first - p1.first;
        graph[p1.second].push_back(P(temp, p2.second));
        graph[p2.second].push_back(P(temp, p1.second));
    }
    
    ll res = 0;
    vector<int> mincost(N, INF);
    vector<bool> used(N, false);
    priority_queue<P, vector<P>, greater<P>> que;
    que.push(P(0, 0));          // (現在の部分最小全域木からのcost, coord)
    
    while(!que.empty()){
        P p = que.top();
        que.pop();
        
        if(used[p.second])      continue;
        
        used[p.second] = true;
        mincost[p.second] = p.first;
        res += p.first;
        
        for(int i = 0; i < graph[p.second].size(); ++i){
            P t = graph[p.second][i];
            que.push(P(t.first, t.second));
        }
    }
    
    cout << res << endl;
}

Measured memory_bytes: 12020
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(500000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))

dic={}

for i in range(n):
    if a[i] in dic:
        dic[a[i]]+=1
    else:
        dic[a[i]]=1

lst=list(dic.keys())
lst.sort(reverse=True)
# print(lst)
anslst=[]
for i in lst:
    if dic[i]>=2:
        anslst.append(i)
    if dic[i]>=4:
        anslst.append(i)
    if len(anslst)>=2:
        print(anslst[0]*anslst[1])
        break
else:
    print(0)
# print(anslst)

Measured memory_bytes: 104148
import java.util.Scanner;

public class Main {

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

		int K = sc.nextInt();
		int S = sc.nextInt();
		int ans = 0;

		for (int x = 0; x <= K; x++) {
			for (int y = 0; y <= K; y++) {
				int z = S-x-y;
				if (0 <= z && z <= K) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	int N;  cin >> N;
	V A(N);
	M mp;
	for(int i = 0 ; i < N ; i++){
	 cin >> A[i];
	 if(A[i] <= 100000)
	  mp[A[i]] += 1;
	 else
	  mp[100001] += 1;
	}

	ll ans = 0;
	for(int i = 1 ; i <= 100001 ; i++){
	 if(mp[i] >= i)  ans += mp[i] - i;
	 else            ans += mp[i];
	}

	cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<ll,ll>
#define poly vector<ll>
#define mem(a) memset((a),0,sizeof(a))
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x.size()))
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
ll rnd(){
	ull ans=0;
	For(i,0,4)ans=ans<<15^rand();
	return ans%((ull)1<<63);
}
const int N=100005;
void GG(){
	puts("-1"); exit(0);
}
int n,k;
set<int> s;
vector<pair<pair<int,int>,int> > ans;
int main(){
	#ifdef Brollan
		//freopen("1.in","r",stdin);
	#endif
	n=read(); k=read();
	For(i,k,k+2*n-1)s.insert(i);
	int dq=k+2*n-1;
	for(int i=k+3*n-1;i>=k+2*n;i-=2){
		if(!s.count(i-dq))GG();
		ans.pb(mp(mp(i-dq,dq),i));
		s.erase(i-dq); s.erase(dq); dq--;
	}
	for(int i=k+3*n-2;i>=k+2*n;i-=2){
		while(!s.count(dq))dq--;
		if(s.count(dq))s.erase(dq); else GG();
		auto it=s.upper_bound(i-dq);
		if(it==s.begin())GG();
		it--;
		ans.pb(mp(mp(*it,dq),i)); dq--;
		s.erase(it);
	}
	for(auto i:ans){
		wri(i.fi.fi); wri(i.fi.se); writeln(i.se);
	}
}
/*
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

5 6 7 8
*/

Measured memory_bytes: 12964
//#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <vector>
#include <string>

//Some constants don't work
#ifndef INT_MAX
#define INT_MAX 2147483647
#endif
#ifndef INT_MIN
#define INT_MIN -2147483648
#endif
//short hand tricks
typedef long long ll;

using namespace std;

bool allsevens(ll n) {
    if(n==0) return false;
    while(n>0) {
        ll d = n%10;
        if(d!=7) return false;
        d/=10;
    }
    return true;
}

ll prime = 1e9+7;

int main(int argc, char * argv[]) {
    ios_base::sync_with_stdio(false);
    ll K;
    cin >> K;
    //check digits
    //7, 77, 777
    ll m = 7;
    // go to 20 digits
    ll digits = 1;
    while(digits<=K) {
        //modulo arithmetic
        //m * inv(K) == 0
        if(m%K==0) {
            cout << digits << "\n";
            return 0;
        }
        m = (m%K)*10+7;
        digits++;
    }
    cout << "-1\n";
    return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define vl vector
using namespace std;
int main()
{
    ll n,m,a=0,i,j;
    cin>>n>>m;
    ll arr[n];
    for(i=0;i<n;i++) cin>>arr[i];
    sort(arr,arr+n);
    if(m>=n) cout<<"0";
    else
    {
        j=n-m;
        for(i=0;i<j;i++) a+=arr[i];
        cout<<a;
    }
}

Measured memory_bytes: 5116
#include<bits/stdc++.h>
using namespace std;
const int N = 100001;
struct str{
    long long s,g;
}f[N];
long long n,z,c;
long long a[N];
void chong()
{
    f[1].s=a[1];f[1].g=1;c=1;
    for(int i = 2;i<=n;i++)
    {
        if(a[i] != a[i-1])
        	f[++c].s=a[i],f[c].g=1;
        else f[c].g++;
    }
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
		cin>>a[i];
	}
    sort(a+1,a+n+1);
    chong();
    for(int i=1;i<=c;i++){
    	if(f[i].g%2==1){
    		z++;
    	}
    }
    cout<<z<<endl;
    return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,(n)-1,0)
#define all(v) v.begin(), v.end()
#define endk '\n'
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b){if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b){if(a<b) a=b;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<ll> A(n), sum(n+1), sumb(n+1);
  rep(i, n) {
    cin >> A[i];
    sum[i+1] = sum[i] + A[i];
    sumb[i+1] = sumb[i] ^ A[i];
  }
  int l=0, r=0;
  ll ans = 0;
  rep(l, n+1) {
    while(r < n+1 && sum[r]-sum[l]==(sumb[r]^sumb[l])) r++;
    ans += r-l-1;
  }
  cout << ans << endk;
  return 0;
}


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

namespace ConsoleApplication1
{
    struct State
    {
        internal int x, y, cnt;

        public State(int x, int y, int cnt)
        {
            this.x = x;
            this.y = y;
            this.cnt = cnt;
        }
    }

    class Problem
    {
        readonly int[] moveX = new int[] { -1, 0, 1, 0 };
        readonly int[] moveY = new int[] { 0, -1, 0, 1 };
        readonly int INF = 1 << 20;
        readonly int w, h;

        int[,] map, memo;
        int sx, sy;

        public Problem(int w, int h)
        {
            this.w = w;
            this.h = h;
            map = new int[h, w];
            memo = new int[h, w];
            MakeMap();
        }

        public int Solve()
        {
            int ret = INF;

            Stack<State> stk = new Stack<State>();
            stk.Push(new State(sx, sy, 0));

            while (stk.Count > 0)
            {
                State cur = stk.Pop();
                memo[cur.y, cur.x] = cur.cnt;

                for (int i = 0; i < 4; i++)
                {
                    int nextX = cur.x + moveX[i];
                    int nextY = cur.y + moveY[i];

                    if (IsValid(nextX, nextY))
                    {
                        int tempCnt = cur.cnt + (map[cur.y, cur.x] == 1 ? 0 : map[nextY, nextX]);

                        if (memo[nextY, nextX] > tempCnt && tempCnt < ret)
                        {
                            stk.Push(new State(nextX, nextY, tempCnt));
                        }
                    }
                    else ret = Math.Min(ret, cur.cnt);
                }
            }
            return ret;
        }

        private bool IsValid(int x, int y)
        {
            if (x < 0 || x >= w || y < 0 || y >= h) return false;
            return true;
        }

        private void MakeMap()
        {
            for (int i = 0; i < h; i++)
            {
                string input = Console.ReadLine();

                for (int j = 0; j < w; j++)
                {
                    switch (input[j])
                    {
                        case '#':
                            map[i, j] = 1;
                            break;
                        case '&':
                            sx = j;
                            sy = i;
                            break;
                    }
                    memo[i, j] = INF;
                }
            }
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                string[] input = Console.ReadLine().Split(' ');
                int w = int.Parse(input[0]);
                int h = int.Parse(input[1]);

                if (w == 0 && h == 0) break;

                Problem pb = new Problem(w, h);
                sb.AppendLine(pb.Solve().ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 10572
#include <bits/stdc++.h>
using namespace std;
#define LL long long 
#define LLU long long unsigned
#define rarr(arr, n) for(int aab = 0; aab < n; aab++){cin >> arr[aab];}
#define parr(arr, n) for(int aab = 0; aab < n; aab++){cout << arr[aab] << " ";}
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n";

#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);ios_base::sync_with_stdio(0);cin.tie(0);

int main(){
    
    long long int x, k, d, ans;
    cin >> x >> k >> d;

    long long int way = abs(x);

    if(way / d <= k){
    	ans = way - (d * (way / d));
    	k -= way / d;
    	if(k > 0){
    		if(k % 2 == 1){
    			ans = min(ans + d, abs(ans - d));
    		}
    	}
    }
  
    else{
    	ans = way - (k * d);
    }

    cout << ans;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <queue>
#include <cctype>
#include <climits>
#include <stack>

using namespace std;

typedef long long LL;

template <typename T>
class Edge
{
public:

	LL from,to;
	T cost;
	
	Edge(LL _from,LL _to,T _cost){
		from=_from;
		to=_to;
		cost=_cost;
	}
	
	bool operator<(const Edge& e) const {
		return cost<e.cost;
	}
};

template <typename T>
class UF{
public:
	vector<T> par,rank;

	UF(T n){
		par.resize(n);
		rank.resize(n);
		for(T i=0;i<n;i++){
			par[i]=i;
			rank[i]=0;
		}
	}

	T find(T x){
		if(par[x]==x)
			return x;
		else
			return par[x]=find(par[x]);
	}

	void unite(T x, T y){
		x=find(x);
		y=find(y);
		if(x==y) return;

		if(rank[x]<rank[y])
			par[x]=y;
		else{
			par[y]=x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(T x, T y){

		return find(x)==find(y);
	}
};

template <typename T>
class Graph
{
public:
	long long n;
	vector<Edge<T> > ve;
	Graph(vector<Edge<T> > _ve,LL _n){
		ve=_ve;
		n=_n;

	}
	
	vector<Edge<T> > kruskal(){
		
		vector<Edge<T> > res;
		sort(ve.begin(),ve.end());
		
		UF<LL> uf(n);
		
		for(LL i=0;i<ve.size();i++){
			Edge<T> e=ve[i];
			if(!uf.same(e.from,e.to)){
				res.push_back(e);
				uf.unite(e.from,e.to);
			}
		}
		
		return res;
	}
};

int main()
{
	int n;
	while(cin>>n,n){
		vector<double> x(n),y(n),z(n),r(n);
		for(int i=0;i<n;i++){
			cin>>x[i]>>y[i]>>z[i]>>r[i];
		}
		
		vector<Edge<double> > ve;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				double d=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])+(z[i]-z[j])*(z[i]-z[j]);
				ve.push_back(Edge<double>(i,j,max(0.0,sqrt(d)-r[i]-r[j])));
			}
		}
		
		Graph<double> G(ve,n);

		vector<Edge<double> > MST=G.kruskal();
		
		double res=0;
		for(int i=0;i<MST.size();i++) res+=MST[i].cost;
		printf("%.3f\n",res);
	}
	
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

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

int main () {
	int N, X; cin >> N >> X;
	vector<int> d(N);
	rep(i, N) {
		int x; cin >> x;
		d[i] = abs(X - x);
	}

	int ans = d[0];
	REP(i, 1, N) {
		ans = gcd(ans, d[i]);
	}
	cout << ans << endl;
}


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

int main(){
    int M, N;
    cin>>N>>M; 
    vector<int> vec(N);
    float postSum;
    int popular = 0;
    for(int i = 0; i < N; i++){
        cin>>vec.at(i);
        postSum += vec.at(i);
    }
    for(int i = 0; i < N; i++){
        if (1.0/(4.0*M) < vec.at(i)/postSum){
            popular ++;
        }
    }
    if (M <= popular){
            cout<<"Yes"<<endl;
        }
    else{
            cout<<"No"<<endl;
        }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<(x)<<endl
#define fi first
#define se second

#define INF 2147483600

int main(){
  int n;
  cin>>n;
  vector<long> vec(n);
  rep(i,n) scanf("%ld", &vec[i]);
  int m; long k;
  cin>>m>>k;

  vector<long> d(n-1);
  rep(i,n-1) d[i] = vec[i+1] -vec[i];

  vector<int> ref(n-1);
  rep(i,n-1) ref[i]=i;

  rep(i,m) {
    int a;
    scanf("%d", &a);
    a--;
    swap(ref[a], ref[a-1]);
  }

  // ref[i] := 規定間のswapにより最後にi番目にいるものは，もともとは何番目にいたものか．

  vector<int> acc(n-1);
  rep(i,n-1) acc[i]=i;
  while(k>0){
    if(k&1){
      vector<int> tmp(n-1);
      rep(i,n-1) tmp[i] = acc[ref[i]];
      swap(acc, tmp);
    }
    vector<int> nxt(n-1);
    rep(i,n-1) nxt[i] = ref[ref[i]];
    swap(ref, nxt);
    k/=2L;
  }

  printf("%ld\n", vec[0]);
  long sum = vec[0];
  rep(i,n-1){
    sum += d[acc[i]];
    printf("%ld\n", sum);
  }
  assert(sum == vec[n-1]);

  return 0;
}


Measured memory_bytes: 3944
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */
 
    //#pragma comment(linker, ack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(ll i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(ll i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    #define te  ll ti;   cin >> ti;  while(ti--) solve();  
    typedef long double ld;
    typedef long long ll;
    typedef unsigned long long ull;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 200100;

    void solve(){
        ll n, k;
        ull area=1e19;
        cin >> n >> k;
        pii a[n]; --k;
        rep(i, n) cin >> a[i].fst >> a[i].snd;
        rep(i, n) repA(j, i+1, n-1) {
            ll cnt = 0;
            vector<pii> f;
            rep(k, n) if( min(a[i].fst, a[j].fst) <= a[k].fst && a[k].fst <= max(a[i].fst, a[j].fst)) f.pb({a[k].snd, a[k].fst});
            
            sort(all(f));
            if(f.size() < k+1) continue;
            //cout << f.size() <<" "<< i << " " << j << endl;
            
            rep(ki, f.size()-k) area = min(area, (ull)abs((a[i].fst - a[j].fst)*(f[ki+k].fst - f[ki].fst)));
            //cout <<f[ki].fst <<" "<< f[ki+k].fst << " " <<(ull)abs((a[i].fst - a[j].fst)*(f[ki+k].fst - f[ki].fst)) << endl;
        }

        cout << area << endl;
        }
 
    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
     /*
      #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
      #endif
     */
      //te
      solve();
      return 0;
    } 


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

using ll=long long;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  ll k;
  cin >> s >> k;
  ll cnt;
  int num = s[0]-'0';
  ll res;
  rep(i,s.size()){
    if(s[i]!='1') {
      res = s[i]-'0';
      break;
    }else cnt++;
  }
  if(cnt!=0)if(cnt<k)num = res;
  cout << num << endl;
}

Measured memory_bytes: 256