akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
bool f[100001];
int c[100002];
int N,L,R;

int main() {
  
  for(int i=2;i<=100000;i++){
    if(!f[i]){
      for(int j=i+i;j<=100000;j+=i){
        f[j]=true;
      }
    }
  }
  
  for(int i=3;i<=100000;i+=2){
    if(!f[i] && !f[(i+1)/2]){
c[i]++;
    }
  }
  for(int i=3;i<=100000;i++){
    c[i]+=c[i-1];
  }
  cin >> N;
  while(N--){
    cin >> L >> R;
    cout << c[R]-c[L-1] <<endl;
  }
  
  
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
char c[3]={'R','G','B'};
string s;
int n;
int a[4005][1000];
int f[4005][1000];
int main()
{
    cin>>n;
    cin>>s;s=" "+s;


    for(int i=1;i<=n;++i)
    {
        a[i][int(s[i])]=1;
    }

    for(int id=0;id<3;++id) for(int i=1;i<=n;++i)
    f[i][c[id]]=f[i-1][c[id]]+a[i][c[id]];

    long long  Res=0;

    for(int i=1;i<n;++i) for(int k=i+2;k<=n;++k)
    {
        if(s[i]!=s[k])
        {
            int ans=0;
            if((i+k)%2==0)
            {
                int j=(i+k)/2;
                if(s[i]!=s[j]&&s[j]!=s[k]) ans--;
            }

            for(int id=0;id<3;++id) if(c[id]!=s[i]&&c[id]!=s[k])
            {
                ans+=f[k-1][c[id]]-f[i][c[id]];
            }
            if(ans>0) Res=Res+1ll*ans;
        }
    }
    cout<<Res;

}


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

int main()
{
	int N;
	long long T;
	cin >> N >> T;
	vector<long long> t( N );
	for( int i = 0; i < N; i++ ) {
		cin >> t[i];
	}

	long long ans = 0;
	long long st;
	long long end;
	for( int i = 0; i < N; i++ ) {
		if( i == 0 ) {
			long long tm = t[i];
			st = tm;
			end = tm + T;
		}
		else {
			long long tm = t[i];
			if( tm > end ) {
				ans += end - st;
				st = tm;
				end = tm + T;
			}
			else end = tm + T;
		}
	}
	ans += end - st;

	cout << ans << endl;
}


Measured memory_bytes: 4840
def suuji(S):
    for i in range(len(S)):
        if S[i]=="-":
            return False
    return True

def func(S,a,b):
    if S[a]=="-":
        S.pop(a)
        if suuji(S) and len(S)==a+b:
            return "Yes"
    return "No"


a,b=map(int, input().split())

S=list(input())

print(func(S,a,b))


Measured memory_bytes: 3060
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    Map<Integer,Integer> m=new HashMap<>();
    for(int i=0;i<n;i++){
      int a=sc.nextInt();
      m.put(a,m.getOrDefault(a,0)+1);
    }
    int sum=0;
    for(Map.Entry<Integer,Integer> e:m.entrySet()){
      if(e.getValue()>=e.getKey()){
        sum+=e.getValue()-e.getKey();;
      }else{
        sum+=e.getValue();
      }
    }
    System.out.println(sum);
  }
}

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

using namespace std;
typedef pair<int,int> P;
int n;
int t[55];
int m;
int j;
vector<P> ans;
int main() {
  cin >> n;

  bool flag = false;
  for(int i = 0; i < n; i++) {
    cin >> t[i];

    if(m < abs(t[i])) {
      m = abs(t[i]);
      j = i;
      if(t[i] > 0) flag = true;
      else flag = false;
    }
  }


  for(int i = 0; i < n; i++) {
    if(flag) t[i] += m;
    else t[i] -= m;
    ans.push_back(P(j,i));
  }
  
  

  if(flag) {
    for(int i = 1; i < n; i++) {
      ans.push_back(P(i-1,i));
    }
  }
  else {
    for(int i = n-1; i > 0; i--) {
      ans.push_back(P(i,i-1));
    }
  }

  cout << ans.size() << endl;

  for(int i = 0; i < ans.size(); i++) {
    cout << ans[i].first + 1 <<" " << ans[i].second + 1 << endl;
  }
}
  


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

int main() {
  int n;
  cin >> n;
  int a[2][110] = {};
  int b[2][110] = {};

  for(int i = 0; i < 2; i++){
    int sum = 0;
    for(int j = 0; j < n; j++){
      cin >> a[i][j];
      sum += a[i][j];
      b[i][j] = sum;
    }
  }
  int ans = 0;
  for(int i = 0; i < n; i++){
    ans = max(ans , b[0][i] + b[1][n-1] - b[1][i-1]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
// #include "prettyprint.hpp"

int main() {
  int N;
  cin >> N;
  long A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  multiset<long, less<long>> bst;

  bst.insert(A[0]);
  for (int i = 1; i < N; i++) {
    if (A[i] <= *bst.begin()) {
      bst.insert(A[i]);
    } else {
      set<long>::iterator it = bst.lower_bound(A[i]);
      it--;
      // cout << *it << endl;
      // cout << "low of " << A[i] << " : " << *it << endl;
      bst.erase(it);
      bst.insert(A[i]);
    }
    // cout << bst << endl;
  }

  cout << bst.size() << endl;

  return 0;
}

Measured memory_bytes: 5760
#include <iostream>

using namespace std;

int n, x;
int a[111];
int c;

int main() {
	cin >> n >> x;
	for (int i = 1; i <= n; i++) cin >> a[i];
	while (true) {
		int pi = 0;
		for (int i = 1; i <= n; i++) {
			if (a[i] > 0 && (pi == 0 || a[i] < a[pi])) pi = i;
		}
		if (pi == 0 || a[pi] > x) break;
		x -= a[pi];
		a[pi] = 0;
		c++;
	}
	if (x > 0) {
		bool ok = false;
		for (int i = 1; i <= n; i++) {
			if (a[i]) ok = true;
		}
		if (!ok) c--;
	}
	cout << c << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	if(c-a-b<0){
		cout << "No";
		return 0;
	}
	ll sum=a*a+b*b+c*c-2*(a*b+b*c+c*a);
	if(sum>0){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
	return 0;
}

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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define rep(i, x, y) for(decltype(y) i = (x) - ((x) > (y)); i != (y) - ((x) > (y)); i += 1 - 2 * ((x) > (y)))
#define trav(i,a) for(auto& (i) : (a))
#define all(a) (a).begin(),(a).end()
#define sz(a) int((a).size())
#define clr(a,x) memset((a),(x),sizeof(a)) // array (0,-1)
#define dbg(x) cerr << "STDERR => " << __LINE__ << ": " << #x << " = " << (x) << "  :(\n";
#define pb push_back
#define mp make_pair
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline void cpuTime() { cerr << "cpu time : " << double(clock())/CLOCKS_PER_SEC << "\n"; return; }
using ll = long long;
using ull = unsigned long long;
using F = float;
using D = double;
using vi = vector<int>;
using pii = pair<int,int>;



void solve(){

    ull n, k;
    cin >> n >> k;

    cout << min(k-n%k, n%k) << "\n";
    return;
}

/*
 read the question carefully ( what're the exact constraints? )
 look out for SPECIAL CASES (n=1?) and OVERFLOW (ll vs int?) ARRAY OUT OF BOUNDS
 Check datatypes
*/
int main(){

    fast_io;
    int t=1;
    // cin >> t;

    while(t--){
        solve();
    }

    cpuTime();
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct S {//辺の情報を入れる変数
	int from, to, cost;
};
struct H {
	int x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad＝座標上の2点間の距離
int ari(int a, int b, int c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int r, g;
	cin >> r >> g;
	cout << g * 2 - r << endl;
	getchar(); getchar();
}

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

using namespace std;

int main()
{
  string s;
  cin >> s;
  
  int n = 0;
  if (s.length() > 1) {
    for (int i = 1; i < s.length(); i++) {
      if (s[i - 1] == s[i]) {
        (s[i] == '0') ? (s[i] = '1') : (s[i] = '0');
        n++;
      }
    }
  }
  
  cout << n << endl;
  
  return 0;
}

Measured memory_bytes: 512
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type RuneSlice []rune

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

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	N, M := sc.nextInt(), sc.nextInt()
	nS := M / 2
	ans := 0
	if N <= nS {
		ans += N
		nS -= N
		ans += nS / 2
	} else {
		ans += nS
	}

	fmt.Fprintln(wtr, ans)
	wtr.Flush()
}


Measured memory_bytes: 640
import java.io.IOException; 
import java.io.InputStream; 
import java.io.PrintWriter; 
import java.util.*;
class Main{ 

	static class SegmentTree{
		int n;
		long[] data;
		SegmentTree(int _n){
			n=1;
			while(n<_n)n*=2;
			data = new long[n*2+1];
		}

		void add(int i, long x){
			i+=n;
			data[i]+=x;
			for(i/=2;i>0;i/=2)data[i]=data[2*i]+data[2*i+1];
		}

		long get(int a, int b){
			return get(a,b, 1, 0, n);
		}
		long get(int a, int b, int k, int l, int r){
			if(r<=a || b<=l)return 0;
			if(a<=l&&r<=b)return data[k];
			return get(a,b,2*k, l,(l+r)/2) + get(a,b,2*k+1,(l+r)/2,r);
		}
	}

	static void solve(){
		int n = ni();
		int[] a = nia(n);
		int[] b = new int[n];
		for(int i=0;i<n;++i)b[i]=a[i];
		Arrays.sort(b);
		int left=-1, right=n-1;
		while(right-left>1){
			int center =(right+left)/2;
			SegmentTree st = new SegmentTree(2*n+1);
			long sum = 0;
			int t = n;
			st.add(n, 1);
			for(int i=0;i<n;++i){
				if(a[i]<=b[center]){
					--t;
				}else{
					++t;
				}
				st.add(t, 1);
				sum+=st.get(t+1, 2*n+1);
			}

			if(sum>=(long)((n*((long)n+1))/4l)+1)right=center;
			else left=center;
		}
		out.println(b[right]);
 
	} 
 
 
 
 
	public static void main(String[] args){ 
		 solve(); 
		 out.flush(); 
	 } 
	 private static InputStream in = System.in; 
	 private static PrintWriter out = new PrintWriter(System.out); 
 
	 private static final byte[] buffer = new byte[1<<15]; 
	 private static int ptr = 0; 
	 private static int buflen = 0; 
	 private static boolean hasNextByte(){ 
		 if(ptr<buflen)return true; 
		 ptr = 0; 
		 try{ 
			 buflen = in.read(buffer); 
		 } catch (IOException e){ 
			 e.printStackTrace(); 
		 } 
		 return buflen>0; 
	 } 
	 private static int readByte(){ if(hasNextByte()) return buffer[ptr++]; else return -1;} 
	 private static boolean isSpaceChar(int c){ return !(33<=c && c<=126);} 
	 private static int skip(){int res; while((res=readByte())!=-1 && isSpaceChar(res)); return res;} 
 
	 private static double nd(){ return Double.parseDouble(ns()); } 
	 private static char nc(){ return (char)skip(); } 
	 private static String ns(){ 
		 StringBuilder sb = new StringBuilder(); 
		 for(int b=skip();!isSpaceChar(b);b=readByte())sb.append((char)b); 
		 return sb.toString(); 
	 } 
	 private static int[] nia(int n){ 
		 int[] res = new int[n]; 
		 for(int i=0;i<n;++i)res[i]=ni(); 
		 return res; 
	 } 
	 private static long[] nla(int n){ 
		 long[] res = new long[n]; 
		 for(int i=0;i<n;++i)res[i]=nl(); 
		 return res; 
	 } 
	 private static int ni(){ 
		 int res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	 } 
	 private static long nl(){ 
		 long res=0,b; 
		 boolean minus=false; 
		 while((b=readByte())!=-1 && !((b>='0'&&b<='9') || b=='-')); 
		 if(b=='-'){ 
			 minus=true; 
			 b=readByte(); 
		 } 
		 for(;'0'<=b&&b<='9';b=readByte())res=res*10+(b-'0'); 
		 return minus ? -res:res; 
	} 
} 



Measured memory_bytes: 61376
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;

int main() {
  ll A,B;
  scanf("%ld%ld", &A, &B);
  ll eA = A, eB = B;
  while (1) {
    if (eA > eB && eB != 0)  eA = eA % eB;
    if (eB > eA && eA != 0)  eB = eB % eA;
    if (eA == eB || eA == 0 || eB == 0)  break;
  }
  ll gcd = max(eA,eB);
  int sq = sqrt(gcd), ans = 1;
  for (int i=2; i < sq + 2; i++) {
    if (gcd % i == 0) {
      while (gcd % i == 0)  gcd /= i;
      ans++;
    }
  }
  if (gcd > 1)  ans++;
  cout << ans << endl;
}

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

typedef long long lint;

using namespace std;

int main(){
  lint n,i,m,k,ans;
  const lint mod = 1e9 + 7;
  queue<lint> a;
  cin >> n >> m;
  for(i = 0; i < m; i++){
    cin >> k;
    a.push(k);
  }
  //mが0のときを考えておく
  if(a.empty()){
    k = n + 1;
  }else{
    k = a.front();
    a.pop();
  }
  //dpテーブル
  lint dp[n + 1] = {};
  //初期化
  dp[0] = 1;
  for(i = 1; i <= n; i++){
    if(i >= 2){
      if(i - 2 != k){
        dp[i] += dp[i - 2];
        dp[i] %= mod;
      }else{
        k = a.front();
        a.pop();
      }
    }
    if(i - 1 != k){
      dp[i] += dp[i - 1];
      dp[i] %= mod;
    }
    dp[i] %= mod;
  }
  ans = dp[n];
  cout << ans;
}


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

int main(){
  int n;
  cin >> n;
  if (n < 2) cout << 1 << endl;
  else if (2 <= n && n < 4) cout << 2 << endl;
  else if (4 <= n && n < 8) cout << 4 << endl;
  else if (8 <= n && n < 16) cout << 8 << endl;
  else if (16 <= n && n < 32) cout << 16 << endl;
  else if (32 <= n && n < 64) cout << 32 << endl;
  else if (64 <= n && n < 128) cout << 64 << endl;
}

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

#define ll long long
using namespace std;

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

    int minus = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] < 0)minus++;
        a[i] = abs(a[i]);
    }

    sort(a.begin(), a.end());
    ll ret = 0;
    for (int i = 0; i < minus % 2; i++)ret -= a[i];
    for (int i = minus % 2; i < n; i++)ret += a[i];

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1024
while True:
    H,W = map(int,input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            if (i+j)%2 == 0:
                print('#',end='')
            else:
                print('.',end='')
        print()
        
    print()
            


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

using namespace std;

int main(){
  int n; cin>>n;
  string s; cin>>s;
  int cnt = 1;
  for(int i = 1; i < n; i++){
    if(s[i] != s[i-1]) cnt++;
  }
  cout<<cnt<<"\n";
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    vector<ll> v(3*n);
    REP(i,3*n) cin>>v[i];
    priority_queue<ll, vector<ll>,greater<ll>> lque;
    priority_queue<ll, vector<ll>> sque;
    ll ls=0,ss=0;
    vector<ll> lv;
    vector<ll> sv;
    REP(i,n){
        lque.push(v[i]);
        sque.push(v[2*n+i]);
        ls+=v[i];
        ss+=v[2*n+i];
    }
    lv.push_back(ls);
    sv.push_back(ss);
    ll ans = -1e18;
    ans = max(ans,ls-ss);
    REP(i,n){
        lque.push(v[n+i]);
        sque.push(v[2*n-i-1]);
        ls += v[n+i] - lque.top();
        ss += v[2*n - i - 1] - sque.top();
        lv.push_back(ls);
        sv.push_back(ss);
        sque.pop();
        lque.pop();
    }
    REP(i,lv.size()) ans=max(ans,lv[i]-sv[n-i]);
    cout<<ans<<endl;

}

Measured memory_bytes: 6636
// https://ynucpc.github.io/blog/2018/04/15/cp_vscode/
// http://www.atmarkit.co.jp/ait/articles/1509/08/news019.html

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rep3(i,n,m) for(ll i=(n);i<(ll)(m);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
// #define max(a, b) ((a) > (b) ? (a) : (b))
// #define min(a, b) ((a) < (b) ? (a) : (b)) 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int _stoi(string s, int tmp=10){
	istringstream stm(s);
	int res;
	stm >> res;
	return res;
}
double _stod(string s, int tmp=10){
	istringstream stm(s);
	double res;
	stm >> res;
	return res;
}
template<typename T>string to_string(const T& n){
	std::ostringstream stm;
	stm << n;
	return stm.str();
}

// 降順ソート: sort(A, A+N, greater<>());
// min: *min_element(A, A+N)
// argmin: min_element(A, A+N)-A

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


int main(){	
	// ll A; cin >> A;
	// cout << "hello" << _stoi("14") << max({1,3}) << endl;
	ll A, B, Q;
	cin >> A >> B >> Q;
	ll S[A], T[B], X[Q];
	rep(i, A)cin >> S[i];
	rep(i, B)cin >> T[i];
	rep(i, Q)cin >> X[i];
	rep(i, Q){
		ll x=X[i];
		ll ans = 1ll<<60;
		ll _is = lower_bound(S, S+A, x)-S;
		if (_is != A){
			ll s = S[_is];
			ll it = lower_bound(T, T+B, s)-T;
			if (it!=B)chmin(ans, abs(s-x) + abs(s-T[it]));
			if (it!=0)chmin(ans, abs(s-x) + abs(s-T[it-1]));
		}
		if(_is!=0){
			ll s = S[_is-1];
			ll it = lower_bound(T, T+B, s)-T;
			if (it!=B)chmin(ans, abs(s-x) + abs(s-T[it]));
			if (it!=0)chmin(ans, abs(s-x) + abs(s-T[it-1]));
		}
		ll _it = lower_bound(T, T+B, x)-T;
		if (_it != B){
			ll t = T[_it];
			ll is = lower_bound(S, S+A, t)-S;
			if (is!=A)chmin(ans, abs(t-x) + abs(t-S[is]));
			if (is!=0)chmin(ans, abs(t-x) + abs(t-S[is-1]));
		}
		if(_it!=0){
			ll t = T[_it-1];
			ll is = lower_bound(S, S+A, t)-S;
			if (is!=A)chmin(ans, abs(t-x) + abs(t-S[is]));
			if (is!=0)chmin(ans, abs(t-x) + abs(t-S[is-1]));
		}

		cout << ans << endl;
	}

}








Measured memory_bytes: 3712
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
using namespace std;

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

unordered_map<string, set<string>> memo;
set<string> f(map<string, string> &mp, const string &g){
  if(memo.count(g)) return memo[g];
  set<string> ret;
  if(mp.count(g)==0){
    ret.insert(g);
  }else{
    string ms=mp[g];
    string member="";
    rep(i, (int)(ms.size())){
      if(ms[i]==',' || ms[i]=='.'){
        auto retret=f(mp, member);
        for(auto e: retret) ret.insert(e);
        member="";
      }else{
        member+=ms[i];
      }
    }
  }
  return memo[g]=ret;
}

int main(){

  int n;
  while(true){
    cin>> n;
    if(n==0) break;
    memo.clear();
    map<string, string> mp;
    vector<string> gs;
    string root="";
    rep(i, n){
      string s; cin>> s;
      int _i=(int)s.find(":");
      string group=s.substr(0, _i);
      if(i==0) root=group;
      gs.push_back(group);
      mp[group]=s.substr(_i+1);
    }
    auto ret=f(mp, root);
    cout<< ret.size()<< endl;
    // for(auto s: ret) cout<< s<< endl;
  }

  return 0;
}


Measured memory_bytes: 3408
// https://atcoder.jp/contests/abc143/tasks/abc143_d

#include "algorithm"
#include "iostream"
#include "set"
#include "vector"
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

void solve() {
  ll N;
  cin >> N;

  VL ls(N);

  rep(i, 0, N) { cin >> ls[i]; }

  sort(ls.begin(), ls.end());

  ll res = 0;

  rep(i, 0, N) rep(j, i + 1, N) {
    ll min = abs(ls[i] - ls[j]);
    ll max = ls[i] + ls[j];
    // min < c < max

    auto sep = lower_bound(ls.begin(), ls.end(), max) - ls.begin();
    res += sep - j - 1;
  }

  cout << res << endl;
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, 0, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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

using namespace std;

class DisjointSet{
  public:
    vector<int> rank, p;

    DisjointSet(){}
    DisjointSet(int size){
        rank.resize(size, 0);
        p.resize(size, 0);
        for(int i = 0; i < size; i++) makeSet(i);
    }

    void makeSet(int x){
        p[x] = x;
        rank[x] = 0;
    }

    bool same(int x, int y){
        return findSet(x) == findSet(y);
    }
    
    bool unite(int x, int y){
        link(findSet(x), findSet(y));
    }

    void link(int x, int y){
        if(rank[x] > rank[y]){
            p[y] = x;
        }else{
            p[x] = y;
            if(rank[x] == rank[y]){
                rank[y]++;
            }
        }
    }

    int findSet(int x){
        if(x != p[x]){
            // path compression
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};

int main(){
    int n, q, com, x, y;
    cin >> n >> q;

    DisjointSet ds = DisjointSet(n);
    for(int i = 0; i < q; i++){
        cin >> com >> x >> y;

        if(com == 0){
            ds.unite(x,y);
        }else if(com == 1){
            if(ds.same(x, y))   cout << 1 << endl;
            else                cout << 0 << endl;
        }
    }

    return 0;
}


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

using namespace std;

int main() {
  char b;
  cin >> b;
  if (b == 'A') {
    cout << 'T' << endl;
  } else if (b == 'T') {
    cout << 'A' << endl;
  } else if (b == 'C') {
    cout << 'G' << endl;
  } else {
    cout << 'C' << endl;
  }
  return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
def main():    
    x, n = map(int, input().split())
    if n == 0:
        print(x)
        return
    p = list(map(int, input().split()))
    check = 0
    while(1):
        s = check//2
        if check%2 == 0:
            ans = x-s
        else:
            ans = x+s
        if not ans in p:
            print(ans)
            return
        check += 1
main()

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

using namespace std;

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

  auto gcd = [](long x, long y) {
	if (x < y) swap(x, y);
	while (y) {
	  x %= y;
	  swap(x, y);
	}
	return x;
  };

  long A, B; cin>>A>>B;
  auto gab = gcd(A, B);

  set<long> candidates;

  candidates.insert(1);
  candidates.insert(gab);
  for (long i = 2; i <= sqrt(gab); i++) {
	if (gab % i == 0) {
	  candidates.insert(i);
	  candidates.insert(gab/i);
	}
  }
  auto maxp = *(--candidates.end());
  set<long> dellist;
  for (auto p : candidates) {
	if (p == 1)
	  continue;
	for (auto q : candidates) {
	  if (p >= q)
	    continue;
	  if (q % p == 0)
	    dellist.insert(q);
	}
  }
  for (auto d : dellist)
	candidates.erase(d);
  cout << candidates.size() << endl;

  return 0;
}


Measured memory_bytes: 896
l, r = map(int, input().split())
x = 2018

if r - l >=2019:
  x = 0
  
else:
  for i in range(l,r):
    for j in range(i+1, r+1):
      if (i * j) % 2019 < x:
        x = (i * j) % 2019
        
print(x)

Measured memory_bytes: 9108
#include <cstdio>
#include <cmath>
#include <algorithm>	//

using namespace std;

#define MAX_N 	101	// エンジン個数の最大値
#define MP(x,y) make_pair((x), (y))

#define INF (1 << 30)

/* -----------------------------------------------------------------------------
	型とクラス定義
----------------------------------------------------------------------------- */
typedef pair<double,double> pdw;
typedef pair<double,pdw> tdw;

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int 	N;				// エンジン個数
tdw 	dist[2*MAX_N];	// 距離関数(距離，最短路数)


int main () {
	double x,y,xs,ys;
	double pi = atan(1.0) * 4;
	int s,t;
	double dist_max;

	// 
	scanf("%d", &N);
	// 
	for(int i = 1; i <= N; i++) {
		scanf("%lf %lf", &x,&y);
		if(x >= 0 && y == 0) dist[i] = MP(0,MP(x,y));
		else if(x > 0 && y > 0) dist[i] =MP(atan(y/x), MP(x,y));
		else if(x == 0 && y > 0) dist[i] = MP(pi /2, MP(x,y));
		else if(x < 0 && y > 0) dist[i] = MP(atan(y/x)+pi, MP(x,y));
		else if(x < 0 && y == 0) dist[i] = MP(pi, MP(x,y));
		else if(x < 0 && y < 0) dist[i] = MP(atan(y/x)+pi, MP(x,y));
		else if(x == 0 && y < 0) dist[i] = MP(3 * pi / 2, MP(x,y));				
		else if(x > 0 && y < 0) dist[i] = MP(atan(y/x)+2*pi, MP(x,y));
	}

	std::sort(dist + 1, dist + 1 + N);
	for(int i = 1; i <= N; i++) dist[i+N] = dist[i];
	
/*
	for(int i = 1; i <= N; i++) {
		printf("%f,%d,%d\n", 
			dist[i].first, dist[i].second.first, dist[i].second.second);
	}
*/
	t = 1;
	dist_max = 0;

	while(t <= N) {
		x = y = 0;
		for(int s = t; s < t + N; s++) {
			x = x + dist[s].second.first;	
			y = y + dist[s].second.second;
			// 最大値の更新
			if(x*x + y*y > dist_max) dist_max = x*x + y*y;
		}
		t++;
	}
	printf("%.50lf\n", sqrt(dist_max));

	return 0;
}

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

#お菓子を持っていない : 1
#お菓子を持っている   : 0
#持っていない人を最終的に導くから
S = [1] * N 

for i in range(K):
    d = int(input())
    t = map(int, input().split())
    for i in t:
        #i-1なのは添字と要素tが1ぶんずれているから
        S[i-1] = 0
print(sum(S))

Measured memory_bytes: 9180
using System;
namespace q1
{
    class q2
    {
        static void Main()
        {
            string[] nyuuryoku = Console.ReadLine().Split();
          	int sanka =int.Parse(nyuuryoku[0]);
          	int Rating =int.Parse(nyuuryoku[1]);
          	if(sanka<10)
            {
              Console.WriteLine(Rating+100*(10-sanka));
            }
          	else
            {
              Console.WriteLine(Rating);
            }
        }
    }
}


Measured memory_bytes: 27520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// typedef __int128 ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#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(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll t1,t2;cin >> t1>>t2;
    ll a1,a2,b1,b2;
    cin >> a1 >> a2 >> b1 >> b2;

    ll ichiban = t1 * (a1 - b1);
    ll niban = t2 * (a2 - b2);
    ll gokei = ichiban + niban;
    // cout << ichiban << endl;
    // cout << niban << endl;
    // cout << gokei << endl;
    if(gokei==0 || ichiban == 0)
    // if(gokei==0)
    {
        cout << "infinity" << endl;
    }
    else
    {
        if (gokei < 0)
        {
            ichiban *= -1;
            niban *= -1;
            gokei *= -1;
        }
        if (gokei > 0 && ichiban > 0)
        {
            cout << 0 << endl;
        }
        else
        {
            ll tmp_num = floor(abs(ichiban)/abs(gokei));
            // cout << tmp_num << endl;
            if (tmp_num*gokei==-1 * ichiban)
            {
                cout << tmp_num * 2 << endl;
            }
            else
            {
                cout << tmp_num * 2 + 1 << endl;
            }
        }
        



    }
}




Measured memory_bytes: 256
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T> using vv=vector<vector<T>>;
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"<<endl; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
#define out(args...){vector<string> a_r_g_s=s_p_l_i_t(#args, ','); e_r_r(a_r_g_s.begin(), args); }
vector<string> s_p_l_i_t(const string& s, char c) { vector<string> v; stringstream ss(s); string x; while(getline(ss,x,c)) v.emplace_back(x); return move(v);}
void e_r_r(vector<string>::iterator it) {}
template<typename T, typename... Args> void e_r_r(vector<string>::iterator it, T a, Args... args){ if(*it==" 1"||*it=="1") cerr<<endl; else cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; e_r_r(++it, args...);}
const ll MOD=1e9+7;

int main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);
  int x,y,X,Y;
  cin>>x>>y>>X>>Y;
  int dx=X-x,dy=Y-y;
  cout<<"LU"<<string(dy,'U')<<string(dx,'R')<<"RD"<<
    "RD"<<string(dy,'D')<<string(dx,'L')<<"LU"<<
    string(dy,'U')<<string(dx,'R')<<string(dy,'D')<<string(dx,'L')<<endl;
  return 0;
}


Measured memory_bytes: 256
// Problem : A - Five Variables
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
#define dbp(x) cout<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define dbv(v) {cout<<#v<<" : ";for (auto x:v) cout<<x<<' ';cout<<endl;}
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define rep2(i,a,b) for(int i = a; i >= b; i--)
#define die(x) return cout<<x<<'\n', 0;

using namespace std;

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

int32_t main()
{
fastio;

int testcases;
testcases=1;
//cin>>testcases;

while(testcases--)
{
	vector<int> vec(5);
	rep(i,0,4)
		cin>>vec[i];
	rep(i,0,4)
		{
			if(vec[i]==0)
			{
				cout<<i+1<<'\n';
				return 0;
				}
		}
}

return 0;
}


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

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

  int a[m][n] = {};
  for(int i = 0; i < m; ++i) {
    for(int j = 0; j < n; ++j) {
      cin >> a[i][j];
    }
  }

  int b[n];
  for(int i = 0; i < n; ++i) {
    cin >> b[i];
  }

  int sigma[m] = {};
  for(int i = 0; i < m; ++i) {
    for(int j = 0; j < n; ++j) {
      sigma[i] += a[i][j] * b[j];
    }
  }

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

Measured memory_bytes: 3120
import bisect
import itertools

n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a.sort()
b.sort()
c.sort()
bc = []
ans = 0
count = 0


for i in b:
  indc = bisect.bisect_right(c,i)
  bc.append((n - indc))
  count += 1

BC = [0] + list(itertools.accumulate(bc))

for i in a:
  indb = bisect.bisect_right(b,i)
  ans += BC[-1] - BC[indb]
   
print(ans)

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

int main(){
  string s,s2;
  ll k;
  ll ans;
  cin>>s>>k;
  s2=s+s;
  bool all=1;
  rep(si,s.size()-1){
    if(s[si]!=s[si+1]) all=0; 
  }
  if(all){
    ans=(ll)s.size() * k / 2;
  }else{
    vector<int> vec_s,vec_s2;
    int tmp=1;
    rep(si,s.size()-1){
      if(s[si]==s[si+1]){
        tmp++;
      }else if(tmp!=1){
        vec_s.push_back(tmp);
        tmp=1;
      }
    }
    if(tmp!=1){
      vec_s.push_back(tmp);
    }
    tmp=1;
    rep(si,s2.size()-1){
      if(s2[si]==s2[si+1]){
        tmp++;
      }else if(tmp!=1){
        vec_s2.push_back(tmp);
        tmp=1;
      }
    }
    if(tmp!=1){
      vec_s2.push_back(tmp);
    }
    int ch1=0,ch2=0;
    for(auto x : vec_s){
      ch1+=x/2;
    }
    for(auto x : vec_s2){
      ch2+=x/2;
    }
    ans=ch1+(ch2-ch1) * (k-1);
  }
  cout<<ans<<endl;
}



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

int main(){
  int n;
  string s;
  ll ans = 0;
  cin >> n;
  unordered_map<string,int> mp;
  rep(i,n){
    cin >> s;
    sort(s.begin(),s.end());
    mp[s]++;
  }
  for(auto& au:mp){
    ll s = au.second;
    ans += s*(s-1)/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 10308
extern crate core;

use std::io::{self, Read};

#[macro_export]
macro_rules! input {
  ($s:expr=>$($t:tt)*) => {
    let mut lines=$s.split("\n");
    $(
        line_parse!(lines,$t);
    )*
  };
}

macro_rules! line_parse {
  ($lines:expr,($($name:ident:$t:tt)*)) => {
    let mut line=$lines.next().unwrap().split_whitespace();
    $(value_def!(line,$name,$t);)*
  };

  //複数行
  ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
    values_def!($lines,$n,$name,$t);
  };
}

macro_rules! value_def {
    ($line:expr, $name:ident, $t:tt) => {
        let $name = value!($line, $t);
    };
}

macro_rules! values_def {
    ($lines:expr, $n:expr, $name:ident, $t:tt) => {
        let $name = {
            let mut vec = Vec::new();
            for i in 0..$n {
                let mut next = $lines.next().unwrap().split_whitespace();
                vec.push(value!(next, $t));
            }
            vec
        };
    };
}

macro_rules! value {
  //配列
  ($line:expr,[$t:tt]) => {
    $line.map(|x|{
      let mut iter=::std::iter::once(x);
      value!(iter,$t)
    }).collect::<Vec<_>>()
  };
  //タプル
  ($line:expr,($($t:tt),*)) => {
    ($(value!($line,$t),)*)
  };
  //文字列
  ($line:expr,#) => {
    $line.next().unwrap()
  };
  //インデックス(-1)
  ($line:expr,@) => {
    $line.next().unwrap().parse::<usize>().unwrap()-1
  };
  //単一値
  ($line:expr,$t:ty) => {
    $line.next().unwrap().parse::<$t>().unwrap()
  };
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(s: String) -> String {
    let s = s.chars().collect::<Vec<_>>();
    format!("{}{}{}", s[0], s.len() - 2, s[s.len() - 1]).to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "internationalization" => "i18n",
    test2: "smiles" => "s4s",
    test3: "xyz" => "x1z",
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d[51],f,g,h,i,j;
	scanf("%d %d",&a,&s);
	for(i=0;i<a;i++) scanf("%d",&d[i]);
	for(i=0;i<a;i++){
		for(j=i+1;j<a;j++){
			if(d[i]<d[j]){
				f=d[i];
				d[i]=d[j];
				d[j]=f;
			}
		}
	}
	g=0;
	for(i=0;i<s;i++) g+=d[i];
	printf("%d\n",g);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

class Solution{

public:
    int mincost(const vector<int>& nums){

        int a = nums.size();
        int b = -2 * accumulate(nums.begin(), nums.end(), 0);
        int c = 0;
        for(int e: nums) c += e * e;

        if((-b) % (2 * a) == 0)return (4 * a * c - b * b) / (4 * a);

        int x1 = (-b) / (2 * a), x2 = x1 + 1;
        return min(a * x1 * x1 + b * x1 + c, a * x2 * x2 + b * x2 + c);
    }
};

int main() {

//    vector<int> nums1 = {4, 8};
//    cout << Solution().mincost(nums1) << endl;
//    // 8
//
//    vector<int> nums2 = {1, 1, 3};
//    cout << Solution().mincost(nums2) << endl;
//    // 3
//
//    vector<int> nums3 = {4, 2, 5};
//    cout << Solution().mincost(nums3) << endl;
//    // 5
//
//    vector<int> nums4 = {-100, -100, -100, -100};
//    cout << Solution().mincost(nums4) << endl;
//    // 0

    int N;
    scanf("%d", &N);

    vector<int> nums(N);
    for(int i = 0; i < N; i ++) scanf("%d", &nums[i]);
    printf("%d\n", Solution().mincost(nums));

    return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n,m; cin >> n >> m;
    vl x(m);
    rep(i,m) cin >> x[i];
    sort(all(x));
    if(m == 1) cout << 0 << endl;
    else{
        vl y(m-1);
        rep(i,m-1) y[i] = x[i+1] - x[i];
        sort(y.rbegin(), y.rend());
        rep(i,min(n-1,m-1)) y[i] = 0;
        ll sum = 0;
        rep(i,m-1) sum += y[i];
        cout << sum << endl;
    }
}


Measured memory_bytes: 1792
#include <iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>

using namespace std;
map<unsigned int,long long int> np;
long long int a[500010];
int main()
{
    long long int lp,l,mp,i,n,m,j=0,k,z=0,ll,mm;
    char p;
    scanf("%lld %c %lld",&lp,&p,&mp);
    if(p=='+')
        cout<<lp+mp;
    else
        cout<<lp-mp;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define pb push_back
#define F first
#define S second

#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define int long long
#define ll long long
const int M=1e9+7;

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

int expo(int x, int y) {int res=1;x=x%M;while(y>0){if(y&1)res=(1ll*res*x)%M;
	y=y>>1;x=(1ll*x*x)%M;} return res;}
	
vector<vector<int>> v(2005);
bool visited[2005];
int dp[2005][2005];
		

void bfs(int n, int call){
	if(visited[n])
		return;
	queue<int> q;
	q.push(n);
	visited[n] = true;
	while(!q.empty()){
		int s = q.front();
		q.pop();
		for(auto it : v[s]){
			dp[call][it] = min(dp[call][it], dp[call][s] + 1);
			if(!visited[it]){
				q.push(it);
				visited[it] = true;
			}
		}
	}
}
signed main(){
	gearup;
	int t = 1;
	//cin >> t;
	while(t--){
		int n, x, y;
		cin >> n >> x >> y;
		for(int i = 1 ; i < n ; i++){
			v[i].pb(i + 1);
			v[i + 1].pb(i);
		}
		v[x].pb(y);
		v[y].pb(x);
		for(int i = 1 ; i <= n ; i++){
			for(int j = 1 ; j <= n ; j++){
				dp[i][j] = LLONG_MAX;
			}
		}
		for(int i = 1 ; i <= n ; i++){
			dp[i][i] = 0;
			memset(visited, false, sizeof visited);
			bfs(i, i);
		}
		map<int, int> mp;
		for(int i = 1; i <= n ; i++){
			for(int j = 1 ; j <= n ; j++){
				mp[dp[i][j]]++;//
				// cout << dp[i][j] << " ";
			}
			// cout << "\n";
		}
		for(int i = 1 ; i < n ; i++){
			cout << mp[i] / 2 << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 31872
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
ll m;
ll md=1e9+7;
bool ok[60][60];
ll res;
map< PLL,pair<vector<ll>,ll> > mp;
pair<vector<ll>,ll> dfs(ll x,ll y)
{
	if (mp.count(MP(x,y))) return mp[MP(x,y)];
	//cout <<y<<" ##\n";
	if (y==1)
	{
		vector<ll> vr(50);
		ll r=0;
		for (int i=0;i<n;i++) if (ok[x][i]) r++,vr[i]++;
		mp[MP(x,y)]=MP(vr,r);
		return MP(vr,r);
	}
	ll ri=0;
	vector<ll> vi=dfs(x,y/2).Fst,vri(50);
	for (int i=0;i<n;i++)
	{
		if (!vi[i]) continue;
		vector<ll> vj=dfs(i,y/2).Fst,vrj(50);
		ll rj=0;
		for (int j=0;j<n;j++)
		{
			if (!vj[j]) continue;
			else
			{
				rj=(rj+vj[j])%md;
				vrj[j]=(vrj[j]+vj[j])%md;
			} 
		}
		ri=(ri+vi[i]*rj)%md;
		for (int j=0;j<n;j++) vri[j]=(vri[j]+vrj[j]*vi[i])%md;
	}
	if (y%2)
	{
		vector<ll> vrj(50);
		ll rj=0;
		for (int i=0;i<n;i++)
		{
			for (int j=0;j<n;j++)
			{
				rj=(rj+ok[i][j]*vri[i])%md;
				vrj[j]=(vrj[j]+ok[i][j]*vri[i])%md;
			}
		}
		ri=rj,vri=vrj;
	}
	mp[MP(x,y)]=MP(vri,ri);
	return MP(vri,ri);
}
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++)
			cin >>ok[i][j];
	for (int i=0;i<n;i++) res=(res+dfs(i,m).Snd)%md;
	cout <<res;
	return 0;
} 

Measured memory_bytes: 1920
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 1000005

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
int POW(int a,int n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}


int main(){
  comi();
  int X,Y,a,b,i;
  scanf("%d%d",&X,&Y);
  if((X+Y)%3!=0){
    printf("0\n");
  	return 0;
  }
  a=(X+Y)/3;
  b=X-a;

  printf("%d\n",com(a,b));
	return 0;
}


Measured memory_bytes: 23552
#include <bits/stdc++.h>
 
using namespace std;
 
#define xx         first
#define yy         second
#define pb         push_back
#define mp         make_pair
#define LL         long long
#define inf        INT_MAX/3
#define mod        1000000007ll
#define PI         acos(-1.0)
#define linf       (1ll<<60)-1
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define REP(I,N)   FOR(I,0,N)
#define For(I,N)   for(int I=1;I<=(N);I++)
#define ALL(A)     ((A).begin(), (A).end())
#define set0(ar)   memset(ar,0,sizeof ar)
#define vsort(v)   sort(v.begin(),v.end())
#define setinf(ar) memset(ar,126,sizeof ar)
#define SZ(X) ((int)(X.size()))
#define LG(X) ((int)(X.length()))
#define CL(X) (X).clear()
#define MAXEL(A,B) (*max_element(A,B))
#define MINEL(A,B) (*min_element(A,B))
#define ROPEN(X) freopen(X,"r",stdin)
#define WOPEN(X) freopen(X,"w",stdout)
#define BG(X) (X.begin())
#define EN(X) (X.end())
#define VI vector<int>
#define PII pair<int,int>
 
//cout << fixed << setprecision(20) << p << endl;
 
template <class T> inline T bigmod(T p,T e,T M){
    LL ret = 1;
    for(; e > 0; e >>= 1){
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    } return (T)ret;
}
template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	LL n,m;
	cin>>n>>m;
	n%=m;
	cout<<min(n,m-n)<<endl;
	return 0;
}


Measured memory_bytes: 256