akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int compute(int st, int en) {
    if (st <= 0 && en >= 0) {
        return en - st + min(-st, en);
    } else if (en <= 0) {
        return -st;
    } else if (st >= 0) {
        return en;
    } else {
        while (1);
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = INT_MAX;
    for (int i = 0; i + k - 1 < n; i++) {
        ans = min(ans, compute(a[i], a[i + k - 1]));
    }
    cout << ans << endl;


}



Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll nmax=2*100000+1;

ll lis[9];

int main(){
    ll n,a,tmp,amin,amax;
    cin>>n;
    for(ll i=0;i<n;i++){
        cin>>a;
        for(ll j=0;j<8;j++){
            if(400*j<=a && a<=400*(j+1)-1) lis[j]=1;
        }
        if(400*8<=a) lis[8]++;
    }

    amin=accumulate(lis,lis+8,0);
    amax=accumulate(lis,lis+9,0);
    if(lis[8]>0&&amin==0){
        amin=1;
    }
    cout<<amin<<" "<<amax<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#define N 100005
using namespace std;
int f[N][35];//2的30次方 
int a[N];
int n,wl,jd;
char z;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%d",&a[i]);
	scanf("%d%d",&wl,&jd);
	for(int i=1;i<=n;i++)
	{
        int nowd = (int)(upper_bound(a,a+n, a[i]+wl)-a-1);
		if(a[i]+wl>=a[n])//过了这个点 
		f[i][0]=n;
		else
		f[i][0]=nowd;
	}
	for(int j=1;j<=30;j++)
	for(int i=1;i<=n;i++)
	f[i][j]=f[f[i][j-1]][j-1];
	for(int q=0;q<jd;q++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		if(x>y)
		swap(x,y);
		int ans=0,cur=x;
		for(int i=30;i>=0;i--)
		{
			if(f[cur][i]<y)
			{
			ans+=(1<<i);
			cur=f[cur][i];
			}
		}
		printf("%d\n",ans+1);
	}
}

Measured memory_bytes: 14848
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    cout << max(A * B, C * D) << endl;

    return 0;
}


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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    
    if (a < b && b < c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3100
def main():
    N = int(input())
    T, A = map(int, input().split())
    *H, = map(int, input().split())

    ts = []
    x = float("inf")
    ans = -1
    for i, h in enumerate(H, 1):
        t = T - h * 0.006
        diff = abs(A - t)
        if diff < x:
            x = diff
            ans = i

    print(ans)


if __name__ == '__main__':
    main()


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

using F = double;

const F EPS = 1e-6;

int N;
vector<F> x, r;

bool ok(auto y) {
  F left = -1e6;
  F right = 1e6;
  for(auto i = 0; i < N; ++i) {
    if(r[i] < y) return false;
    F d = sqrt(r[i] * r[i] - y * y);
    left  = max(left,  x[i] - d);
    right = min(right, x[i] + d);
  }
  return left <= right;
}

int main() {
  cin >> N;
  x.resize(N);
  r.resize(N);
  for(auto i = 0; i < N; ++i) cin >> x[i] >> r[i];

  F low = 0, high = 1e6;
  while(EPS < high - low) {
    auto middle = (low + high) / 2;
    if(ok(middle)) low  = middle;
    else           high = middle;
  }
  cout << setprecision(8) << fixed << low << endl;
}

Measured memory_bytes: 4396
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

# 0^0 = 1

def main():
    N,M,K = map(int, readline().split())

    MOD = 998244353

    if M == 1:
        if K == N - 1:
            print(1)
        else:
            print(0)
        exit()

    m = pow(M-1, N-1, MOD)
    m_1_inv = pow(M-1, MOD-2, MOD)
    comb = 1
    ans = comb * m
    for k in range(1,K+1):
        m *= m_1_inv
        m %= MOD
        comb *= N - k
        comb %= MOD
        comb *= pow(k, MOD-2, MOD)
        
        ans += (m * comb) % MOD
        ans %= MOD

    print(ans * M % MOD)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9220
import java.util.Scanner;
public class Main{
  	public static void main (String [] args){
      	Scanner scanner = new Scanner (System.in);
      	int A = scanner.nextInt();
      	int B = scanner.nextInt();
      	int sum = Math.max(A,B);
      	if (A > B) A--;
        else B--;
      	sum += Math.max(A,B);
      	System.out.println(sum);
    }
}

Measured memory_bytes: 35748
#include<iostream>
#include<functional>
#include<vector>
#include<functional>
using namespace std;
int main(){
  int n,x;
  cin>>n>>x;
  pair<long int,int> m[100010];
  for(int i=0;i<n;i++){
    cin>>m[i].first>>m[i].second;
  }
  sort(m,m+n);
  long long int ans=0;
  for(int j=0;j<n;j++){
    if(m[j].second>x){
      ans+=x*m[j].first;
      break;
    }
    else{
      ans+=m[j].first*m[j].second;
      x-=m[j].second;
    }
  }
  cout<<ans<<endl;
}

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

using namespace std;

int a[5];

int main()
{
    for (int i=1;i<=3;++i)
        cin>>a[i];
    sort(a+1,a+1+3);
    if ((a[1]==a[2] && a[1]!=a[3]) || (a[3]==a[2] && a[1]!=a[3]))
        cout<<"Yes";
    else cout<<"No";
    return 0;
}


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

namespace ABC176A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NXT = Console.ReadLine().Split(' ');
            int N = int.Parse(NXT[0]);
            int X = int.Parse(NXT[1]);
            int T = int.Parse(NXT[2]);
            if (N % X == 0)
            {
                Console.WriteLine(T * N / X);
            }
            else
            {
                Console.WriteLine(((N / X)+1)*T);
            }
        }
    }
}


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

void no() { printf("No\n"), exit(0); }

int an[200000];
bool dn[200000];

int main(){
	int n, x;
	scanf("%d%d", &n, &x);
	n = (n << 1) - 1;
	if (x == 1 || x == n)no();
	int z = n + 1 >> 1;
	an[z] = x;
	an[z + 1] = x + 1;
	an[z - 1] = x - 1;
	dn[x] = dn[x - 1] = dn[x + 1] = true;
	if (x + 1 == n)an[z + 2] = x - 2, dn[x - 2] = true;
	else an[z - 2] = x + 2, dn[x + 2] = true;
	int j = 1;
	f(i, 1, n + 1)if (!an[i]){
		while (dn[j])++j;
		an[i] = j++;
	}
	printf("Yes\n");
	f(i, 1, n + 1)printf("%d\n", an[i]);
}


Measured memory_bytes: 2304
{-# LANGUAGE OverloadedStrings #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.Map.Strict               as M
import           Data.Char
import Data.Bits

modN = 1000000007


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

pow :: Int -> Int -> Int -> Int
pow base 1 modNum = base `mod` modNum
pow base time modNum
    | odd time = let 
        a = pow base (time `div` 2) modNum `mod` modNum
        in
        a * a * base `mod` modNum
    | otherwise = let
        a = pow base (time `div` 2) modNum `mod` modNum
        in
        a * a `mod` modNum

solve :: Int -> [Int] -> [Int]
solve n as = let
    updater :: Maybe Int -> Maybe Int
    updater n = case n of
        Just a -> Just $ a+1
        Nothing -> Just 1
    m = foldl' (\m i -> IM.alter updater i m) IM.empty as
    in
    do
        i <- [1..n]
        pure $ IM.findWithDefault 0 i m 
main = do
    n <- readInt
    as <- readInts
    forM_ (solve n as) $ print







Measured memory_bytes: 34076
x = list(map(int, input().split()))
ans = 0
for xi in x:
    if xi == 1:
        ans += 300000
    elif xi == 2:
        ans += 200000
    elif xi == 3:
        ans += 100000

if x[0] == x[1] == 1:
    ans += 400000

print(ans)




Measured memory_bytes: 3316
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    ll n = 0, m = 0;
    cin >> n >> m;
    if (n == 1 && m == 1) {
        cout << 1 << endl;
    }
    else if (n == 1) {
        cout << m-2 << endl;
    }
    else if (m == 1) {
        cout << n-2 << endl;
    }
    else if (n == 2 || m == 2) {
        cout << 0 << endl;
    }
    else {
        cout << (m-2)*(n-2) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pii_ pair<int,int>
#define mp_ make_pair
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define show1(a) cout<<#a<<" = "<<a<<endl
#define show2(a,b) cout<<#a<<" = "<<a<<"; "<<#b<<" = "<<b<<endl
using namespace std;
const ll INF = 1LL<<60;
const int inf = 1<<30;
const int maxn = 2e5+5;
inline void fastio() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}

ll a[maxn],b[maxn],sa[maxn],sb[maxn];
int n,m,k;

int main()
{
    fastio();
    cin>>n>>m>>k;
    rep(i,1,n) cin>>a[i];
    rep(i,1,m) cin>>b[i];
    rep(i,1,n){
        sa[i] = sa[i-1] + a[i];
    }
    rep(i,1,m){
        sb[i] = sb[i-1] + b[i];
    }
    int ans = 0;
    rep(i,0,n){
        if(k-sa[i]<0) break;
        int tmp = upper_bound(sb+1,sb+m+1,k-sa[i]) - sb - 1;
        ans = max(ans,tmp+i);
    }
    rep(i,0,m){
        if(k-sb[i]<0) break;
        int tmp = upper_bound(sa+1,sa+n+1,k-sb[i]) - sa - 1;
        ans = max(ans,tmp+i);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9888
N, K, Q = [int(i) for i in input().split()]
A = []
for _ in range(Q):
    A.append(int(input()))

get_points = [0]*N
for a in A:
    get_points[a-1] += 1

rest_points = [K]*N
for i in range(N):
    rest_points[i] -= Q - get_points[i]

for rest_point in rest_points:
    if rest_point > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 12648
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
typedef unordered_map<ll,ll> umap;
#define pb emplace_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main() {
    // your code goes here
    ll n, rui[200005]={0}, ct[2050]={0}, p, ts=1, m=2019, ans=0;
    string s;
    cin >> s;
    n = s.size();
    ct[0] = 1;
    repr(i,n-1,0){
        p = s[i] - '0';
        rui[n-i] = (rui[n-i-1] + p * ts % m) % m;
        ts = ts * 10 % m;
        ct[rui[n-i]]++;
    }
    rep(i,0,2018){
        ans += ct[i] * (ct[i] - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, a[101010];
void solve(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		a[i]--;
	}
	
	int cnt = 0;
	for(int i = 0; i < n; i++){
		if(i == a[a[i]]) cnt++;
	}
	cout << cnt/2 << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


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

int main()
{
	string s;
	cin >> s;

	bool e[26];

	for (int i = 0; i < 26; i++)
	{
		e[i] = false;
	}
	for (int i = 0; i < s.size(); i++)
	{
		e[s[i] - 'a'] = true;
	}
	int c = -1;
	for (int i = 0; i < 26; i++)
	{
		if (!e[i])
		{
			c = i;
			break;
		}
	}
	if (c == -1) {
		cout << "None" << endl;
	}
	else {
		cout << (char)(c + 'a') << endl;
	}

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erase(unique(all(v)),v.end());
#define pvec(v) rep(i,v.size()){ cout << v[i] << " ";}
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
#define mod 1e9 + 7;
ll dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}





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

	ll a=0, b=0, c=0, ans = 0, n, ret = 0, m, d;
	string s;
	cin >> a >> b >> c >> d;
	bool x = false, y = false;

		rep(i, c - a) cout << "R";

		rep(i, d - b) cout << "U";

		rep(i, c - a) cout << "L";

		rep(i, d - b) cout << "D";

		cout << "L";
		
		rep(i, d - b + 1) cout << "U";

		rep(i, c - a + 1) cout << "R";

		cout << "DR";

		rep(i, d - b + 1) cout << "D";

		rep(i, c - a + 1) cout << "L";
		cout << "U" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int A[500][500],N;
int x[500];
void f(vector<int>x,int id)
{
	if(x.size()<=1)return;
	int N=x.size();
	vector<int>L,R;
	for(int i=0;i<N;i++)(i<N/2?L:R).push_back(x[i]);
	for(int u:L)for(int v:R)A[u][v]=id;
	f(L,id+1);
	f(R,id+1);
}
main()
{
	cin>>N;
	vector<int>now;
	for(int i=0;i<N;i++)now.push_back(i);
	f(now,1);
	for(int i=0;i<N;i++)
	{
		for(int j=i+1;j<N;j++)cout<<A[i][j]<<(j==N-1?"\n":" ");
	}
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
typedef long long ll;
int A[maxn];
int main(void)
{
    int N;
    ll K;
    scanf("%d%lld",&N,&K);
    for(int i =1 ;i <= N;i ++)
    {
        scanf("%d",&A[i]);
    }
    int i = 1;
    map<int,int> _map;
    map<int,bool> cir;
    ll len =0;
    bool one = true;
    int fc = -1;
    while(K)
    {
        _map[i]++;
        if(_map[i]==2)
        {
            one = false;
            cir[i]=true;
            len ++;
        }
        if(_map[i]==3)
        {
            break;
        }
        if(one) K--;
        else if(fc==-1)
        {
            fc = i;
        }
        i = A[i];
    }
    if(!K)
    {
        printf("%d\n",i);
        return 0;
    }
    i = fc;
    K = K % len;
    while(K--)
        i = A[i];
    printf("%d\n",i);
    return 0;
}


Measured memory_bytes: 16932
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	ll n;
	cin >> n;
	vector<ll> a(n);
	REP(i,n) cin >> a[i];
	
	// ans[i] = sum + diff[i];
	ll sum=0;
	vector<ll> diff(n);
	REP(i,n){
		if(i==0){
			sum += abs(a[0]);
		}else if(i==n-1){
			sum += abs(a[i]-a[i-1]);
			sum += abs(a[n-1]);
		}else{
			sum += abs(a[i]-a[i-1]);
		}
		
		if(i==0){
			diff[i] = abs(a[1]);
			diff[i] -= abs(a[0]) + abs(a[1]-a[0]); 
		}else if(i==n-1){
			diff[i] = abs(a[n-2]);
			diff[i] -= abs(a[n-1]-a[n-2]) + abs(a[n-1]);
		}else{
			diff[i] = abs(a[i+1]-a[i-1]);
			diff[i] -=  abs(a[i]-a[i-1])+abs(a[i+1]-a[i]);
		}
	}
	
	REP(i,n){
		cout << sum + diff[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define inrange(a, x, b) (a <= x && x <= b)
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print(T x,bool cl=1){cout<<(cl?"\x1b[36m":"")<<x<<(cl?"\x1b[39m":"")<<'\n';}
template<class T> void print1d(T x,ll n=-1,bool cl=true){if(n==-1)n=x.size();rep(i,0,n){cout<<(cl?"\x1b[36m":"")<<x[i]<<(i==n-1?'\n':' ');}cout<<(cl?"\x1b[39m":"");}
template<class T> void print2d(T x,ll r=-1,ll c=-1,bool cl=1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c,cl);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod)
{
        a %= _mod; b %= _mod; ll res = 1;
        switch (op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
        } 
        if (res < 0) { res += _mod; } return res;
}

int main()
{
        ll N;
        cin >> N;
        vll A(N), B(N);
        rep(i, 0, N) cin >> A[i] >> B[i];

        sort(all(A));
        sort(all(B));

        if (odd(N)) {
                ll mn = A[N/2];
                ll mx = B[N/2];
                cout << mx - mn + 1 << endl; 
        } else {
                ll mn = A[N/2-1] + A[N/2];
                ll mx = B[N/2-1] + B[N/2];
                cout << mx - mn + 1 << endl;
        }
}


Measured memory_bytes: 6408
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include<climits>
#include <string>
#include <map>
#include <set>
#include <list>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)

using namespace std;

/////////////////////////////////////////////////////

ll N,K,h;
vector<ll> hv;
ll i,ans;

int main(){
    scanf("%lld%lld",&N,&K);
    fornum(i,0,N){
        ll h;
        scanf("%lld", &h);
        hv.push_back(h);
    }
    sort(hv.begin(), hv.end());

    ans = (ll)1e18;
    fornum(i,0,N-K+1){
        ans = hv[i + K-1] - hv[i] < ans ? hv[i + K-1] - hv[i] : ans;
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 1400
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll mod=1e9+7;

int main()
{
    ll n,k;
    cin >> n >> k;
    vector<ll> v(n);
    rep(i,n){
        cin >> v[i];
    }
    ll ans=0;
    for(ll l=0;l<=k;l++){
        for(ll r=0;r<=k-l;r++){
            if(r+l>n) break;
            ll d=k-l-r;
            ll now=0;
            vector<ll> s;
            rep(i,l){
                now+=v[i];
                s.push_back(v[i]);
            }
            rep(i,r){
                now+=v[n-1-i];
                s.push_back(v[n-1-i]);
            }
            sort(s.begin(),s.end());
            rep(i,d){
                if(i>=l+r) break;
                if(s[i]>0) break;
                
                now-=s[i];
            }
            ans=max(ans,now);
        }
    }
    cout << ans << endl;
    return 0;
} 

Measured memory_bytes: 256
#include<iostream>

using namespace std;
typedef unsigned long long ULL;
typedef long long LL;

int main(){
    int H;
    int N;
    int a;
    int i;
    int sum;
    cin >> H >> N;
    sum = 0;
    for(i=0;i<N;i++){
        cin >> a;
        sum += a;
    }
    if( sum >= H ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop

INF = 1e18

# star, goal, 隣接リスト
def dijkstra(st, g):
    n = len(g)
    dis = [INF] * n
    dis[st] = 0
    que = []
    heappush(que,(0,st))

    while que:
        d, u = heappop(que)
        for v, cost in g[u]:
            if dis[v] > d + cost:
                dis[v] = d + cost
                heappush(que,(dis[v],v))
    return dis

def main():
    n, m, st = map(int, input().split())
    g = [[] for _ in range(n)]
    
    for _ in range(m):
        u, v, cost = map(int, input().split())
        g[u].append((v,cost))

    res = dijkstra(st, g)
    for ans in res:
        if ans == INF:
            print("INF")
        else:
            print(ans)


main()


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

int main(){
  int n,ans = 1e9;
  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  sort(v.begin(),v.end());
  
  for(int i = v[0]; i <= v[n-1]; i++){
    int mi = 0;
    rep(j,n){
      mi += (v[j]-i)*(v[j]-i);
    }
    if(mi < ans)
      ans = mi;
  }
  cout << ans << endl;
  return 0;
}


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

int n;
int floor[100][100];
int x[100][100],y[100][100];

bool rec(int h,int w, int c){

  floor[h][w] = c;

  int tmp = floor[y[h][w]][x[h][w]];
  if(tmp == c)return true;
  else if(tmp < c){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(floor[i][j] == c)floor[i][j] = tmp;
      }
    }
    return false;
  }else{
    return rec(y[h][w],x[h][w],c);
  }
}

int main(){
  while(1){
    cin >> n;
    if(!n)break;

    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	cin >> x[i][j] >> y[i][j];
	floor[i][j] = 10000;
      }
    }

    int ans = 0;

    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(floor[i][j] > ans){
	  if(rec(i,j,ans))ans++;
	}
      }
    }

    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
#define rep(i, n) for(int i=0; i<(n); ++i)
 
int H, W, size;
char map[101][101];
int owner[101][101];
void dfs(int i, int j, int size) {
    char c = map[i][j];
    owner[i][j] = size;
    if(j+1<W && map[i][j+1]==c && owner[i][j+1]==-1) dfs(i, j+1, size);
    if(j>0 && map[i][j-1]==c && owner[i][j-1]==-1) dfs(i, j-1, size);
    if(i+1<H && map[i+1][j]==c && owner[i+1][j]==-1) dfs(i+1, j, size);
    if(i>0 && map[i-1][j]==c && owner[i-1][j]==-1) dfs(i-1, j, size);
}
int main() {
    while(cin >> H >> W && H!=0 && W!=0) {
        rep(i, H) {
            rep(j, W) {
                cin >> map[i][j];
                owner[i][j]=-1;
            }
        }
        bool isFinished = false;
        size = -1;
        while(isFinished==false) {
            isFinished = true;
            rep(i, H) {
                rep(j, W) {
                    if(owner[i][j]==-1) {
                        dfs(i, j, ++size);
                        isFinished = false;
                    }
                }
            }
        }
        cout << size+1 << endl;
        }
    return 0;
}

Measured memory_bytes: 2140
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    x,y,z = map(int, input().split())
    
    x = x-z
    y = y+z
    print(x//y)
            	
if __name__ == "__main__":
	main()


Measured memory_bytes: 38256
<?php
function puts($str = ""){
    echo $str, "\n";
}

$input = trim(fgets(STDIN));
$input = preg_split('/\s/', $input);

$n = intval($input[0]);
$m = intval($input[1]);
$counts = array();
$all_counts = 0;
while($input = trim(fgets(STDIN))){
    $line = preg_split('/\s/', $input);
    foreach(range(1, intval($line[0])) as $k){
        if(!isset($counts[$line[$k]])){
            $counts[$line[$k]] = 0;
        }
        $counts[$line[$k]]++;
        if($counts[$line[$k]] === $n){
            $all_counts++;
        }
    }
}
puts($all_counts);



Measured memory_bytes: 3828
#include<bits/stdc++.h>
#define ll      long long
#define pii     pair<int, int>
#define f       first
#define s       second

using namespace std;
int main()
{
    string t, s, rev, r2;
    cin>>s;
    int n = s.size();

    t = s.substr(0, (n-1)/2);
//    cout<<t<<endl;
    rev = t;
    reverse(rev.begin(), rev.end());

    string t2 = s.substr((n+3)/2 - 1, n - ((n+3)/2) + 1);
//        cout<<t2<<endl;

    string rev2 = t2;
    reverse(rev2.begin(), rev2.end());

    r2 = s;
    reverse(r2.begin(), r2.end());

//    cout<<t.size()<<" "<<rev.size()<<endl;
//    cout<<t2.size()<<" "<<rev2.size()<<endl;
    if(t == rev && t2 == rev2 && s == r2){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }

}




Measured memory_bytes: 256
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int n = scanner.nextInt();

        Set<Integer> set = new HashSet<>();
        for (int i = 0; i < n; i++) {
            set.add(scanner.nextInt());
        }

        int diff = 0;
        int ans;

        while (true) {

            int left = x - diff;
            if (!set.contains(left)) {
                ans = left;
                break;
            }

            int right = x + diff;
            if (!set.contains(right)) {
                ans = right;
                break;
            }

            diff++;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 27064
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<lld> vi;
typedef pair<lld,lld> pi;
#define F first
#define S second
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (lld i = a; i < b; i++)
lld r,j,l,x,y,m,b,n,s,f,q,i,z,p,k,d,t,u,e,g;string s1,s2,s3,s4;
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);lld a,c,h;
  cin>>n;m=a=r=c=h=0;
  rep(i,0,n)
  {
    cin>>s1;
    if(s1[0]=='M')
      m++;
    else if(s1[0]=='A')
      a++;
    else if(s1[0]=='R')
      r++;
    else if(s1[0]=='C')
      c++;
    else if(s1[0]=='H')
      h++; 
  }
  n=5;
  if(m==0)
    n--;
  if(a==0)
    n--;
  if(r==0)
    n--;
  if(c==0)
    n--;
  if(h==0)
    n--;
  if(n<=2)
  {
    cout<<0;
  }
  else
  {
    if(n==3)
    {l=1;
      if(m!=0)
        l=l*m;
      if(a!=0)
        l=l*a;
      if(r!=0)
        l=l*r;
      if(c!=0)
        l=l*c;
      if(h!=0)
        l=l*h;
      cout<<l;
    }
    else if(n==4)
    {
      if(m==0)
      {
        cout<<a*r*c+a*r*h+a*c*h+r*c*h;
      }
      else if(a==0)
      {
        cout<<m*r*c+m*r*h+m*c*h+r*c*h;
      }
      else if(r==0)
      {
        cout<<m*a*c+m*a*h+a*c*h+m*c*h;
      }
      else if(c==0)
      {
        cout<<m*a*r+m*a*h+m*r*h+a*r*h;
      }
      else
      {
        cout<<m*a*r+m*r*c+a*r*c+m*a*c;
      }
    }
    else
    {
      cout<<m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+r*c*h+a*c*h;
    }
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int board[10][10];

int f(string &s) {
	ll res = 0;
	for (int i = 0; i < s.size(); i++) {
		res = board[res][s[i] - '0'];
	}
	return res;
}
bool check(string &s) {
	ll res = 0;
	return f(s) == 0;
}
int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	for (int i = 0; i < 10; i++) for (int j = 0; j < 10; j++) scanf("%d", &board[i][j]);

	ll res = 0;
	for (int i = 0; i <= 9999; i++) {
		string s = to_string(i);
		ll tmp = f(s);
		s += (char)('0' + tmp);
		bool flag = false;
		while (s.size() < 5) s = '0' + s;
		for (int i = 0; i + 1 < s.size(); i++) {
			if (s[i] != s[i + 1]) {
				swap(s[i], s[i + 1]);
				if (f(s) == 0) flag = true;
				swap(s[i], s[i + 1]);
			}
		}
		for (int i = 0; i < s.size(); i++) {
			for (char j = '0'; j <= '9'; j++) {
				if (s[i] == j) continue;
				char c = s[i];
				s[i] = j;
				if (f(s) == 0) flag = true;
				s[i] = c;
			}
		}
		if (flag) res++;
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 3360
// Author : Mohamed Sameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std ;
int n , w ;
int a[100][2];
ll dp[100][100001];
ll solve (int i  = 0 , int sum =0 )
{
    if (sum > w )return -1e12 ;
    if (i == n )return 0 ;
    ll &ret = dp[i][sum];
    if (~ret)return ret ;
    ret = solve(i + 1 , sum );
    ret = max (ret , a[i][1] + solve(i + 1 , sum + a[i][0]) );
    return ret ;
}
int main()
{
    scanf ("%d%d" , &n ,&w );
    for (int i =0 ; i < n ;i++)for (int j =0 ; j < 2; j++)scanf ("%d" , a[i] + j );
    memset(dp , -1 ,sizeof dp );
    printf ("%lld\n" , solve());
}


Measured memory_bytes: 78336
/* */

#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;

#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
#else
	#define errp(...)
#endif
#define dbg(x) errp("%s = %s\n", #x, to_string(x).data())
#define dbg_al(s, x) for(auto e:x)s+=to_string(e)+" "
#define dbg_rt(x) string s="[ ";dbg_al(s,x);s+="]";return s;
#define dbg_fd1 template<typename T>string to_string
#define dbg_fd2 template<typename U, typename V>string to_string
#define dbg_d1(c) dbg_fd1(c<T>);
#define dbg_d2(c) dbg_fd2(c<U, V>);
#define dbg_f1(c) dbg_fd1(c<T> v){dbg_rt(v);}
#define dbg_f2(c) dbg_fd2(c<U, V> v){dbg_rt(v);}
string to_string (char s) { return "\'"+string(1, s)+"\'"; }
string to_string (string s) { return "\"" + s + "\""; }
dbg_d1(vector) dbg_d1(set) dbg_d2(map)
dbg_fd2(pair<U, V> p) { return "("+to_string(p.first)+", "+to_string(p.second)+")"; }
dbg_f1(vector) dbg_f1(set) dbg_f2(map)
/* ==================== */ 

int solve (int h, int w) {
	if (h % 3 == 0 || w % 3 == 0) return 0;
	int a, b, c, x, y;
	if (h % 3 == 1) {
		a = (h / 3) * w;
		x = h - h / 3;
	}
	else {
		a = (h / 3 + 1) * w;
		x = h - (h / 3 + 1);
	}
	y = w;
	if (x > y) swap(x, y);
	if (x % 2 == 0) {
		b = (x / 2) * y;
		c = (x / 2) * y;
	}
	else {
		b = x * (y / 2);
		c = x * ((y - 1) / 2 + 1);
	}
	if (a > b) swap(a, b);
	if (b > c) swap(b, c);
	if (a > b) swap(a, b);
	return c - a;
}

int main() {
	int h, w;
	scanf("%d%d", &h, &w);
	printf("%d\n", min(solve(h, w), solve(w, h)));
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

vector<pair<ll, ll>>prime_factorize(ll n) {
	vector<pair<ll, ll>>res;
	for (ll p = 2; p*p <= n; ++p) {
		if (n%p != 0)continue;
		int num = 0;
		while (n%p == 0) { ++num; n /= p; }
		res.push_back(make_pair(p, num));
	}
	if (n != 1)res.push_back(make_pair(n, 1));
	return res;
}
const int MAX = 210000;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; ++i) {
		fac[i] = fac[i - 1] * i%INF;
		inv[i] = INF - inv[INF%i] * (INF / i) % INF;
		finv[i] = finv[i - 1] * inv[i] % INF;
	}
}
ll COM(int n, int k) {
	if (n < k)return 0;
	if (n < 0 || k < 0)return 0;
	return fac[n] * (finv[k] * finv[n - k] % INF) % INF;
}
int main() {
	int n, m; cin >> n >> m;
	COMinit();
	vector<pair<ll, ll>>key = prime_factorize(m);
	ll ans = 1;
	for (int i = 0; i < key.size(); ++i) {
		ans *= COM(n+key[i].second-1, key[i].second);
		ans %= INF;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5120
// D - Friend Suggestions
// UnionFinde version
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

class UnionFind{
	vector<int> parent_or_size;// <0: root&-(size), >=0: parent number
	public:
	UnionFind(int n): parent_or_size(n,-1) {}
	int root(int v){return parent_or_size[v] < 0? v: parent_or_size[v] = root(parent_or_size[v]);}
	bool unite(int v, int u){
		int large_root = root(v), small_root = root(u);
		if(large_root == small_root) return false;// same root: no execute
		if(size(large_root) < size(small_root)) swap(large_root, small_root);
		parent_or_size[large_root] += parent_or_size[small_root];// large_root <- small_root unite
		parent_or_size[small_root] = large_root;
		return true;// executed
	}
	bool same(int v, int u){return root(v)==root(u);}//v & u the same set
	int size(int v){return -parent_or_size[root(v)];}// -(-size)
};

int main(){
	int N,M,K; scanf("%d%d%d",&N,&M,&K);
	UnionFind uf(N);
	vi C(N+1);//count: friend, block
	int s,t;
	rp(i,0,M){
		scanf("%d%d",&s,&t); s--; t--;
		uf.unite(s,t);
		C[s]++; C[t]++;
	}
	rp(i,0,K){
		scanf("%d%d",&s,&t); s--; t--;
		if(uf.same(s,t)) C[s]++, C[t]++;
	}
	rp(i,0,N) printf("%d ", uf.size(i)-C[i]-1);
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF ((1LL<<61) + (1<<29))
#define YesNo(x) {std::cout << ((x)?"Yes":"No") << std::endl;}
#define YESNO(x) {std::cout << ((x)?"YES":"NO") << std::endl;}
#define OddEven(x) {std::cout << ((x)%2?"Odd":"Even") << std::endl;}
#define ODDEVEN(x) {std::cout << ((x)%2?"ODD":"EVEN") << std::endl;}
typedef long long int ll;
ll my_gcd(ll a, ll b) { return b ? my_gcd(b, a%b) : a; };
void _INPUT_IMPL_() {};
template <class T, class... Args> void _INPUT_IMPL_(T& dest, Args&... args) { cin >> dest; _INPUT_IMPL_(args...); }
void _OUTPUT_IMPL_() {};
template <class T, class... Args> void _OUTPUT_IMPL_(T dest, Args... args) { cout<< dest << (sizeof...(Args)?" ":""); _OUTPUT_IMPL_(args...); }
#define in(type, ...) type __VA_ARGS__; _INPUT_IMPL_(__VA_ARGS__)
#define in_v(type, name, cnt) vector<type> name(cnt); loop(i, cnt) cin >> name[i];
#define sort_v(v) std::sort(v.begin(), v.end())
#define out(...) (_OUTPUT_IMPL_(__VA_ARGS__), std::cout<<std::endl)
//小さい方に寄る
#define space_op(x, y, a, b, c) ([](auto x_, auto y_, auto a_, auto b_, auto c_){if(x_<y_)return a_;if(x_>y_)return c_;return b_;}(x,y,a,b,c))
#define space_out(x, y, a, b, c) out(space_op(x, y, a, b, c))

int main() {
	in(int, N, X);
	ll m = -1;
	loop(i, N) {
		ll x; cin >> x;
		x = abs(X-x);
		m = (m > 0 ? my_gcd(m, x) : x);
	}
	out(m);
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll N;
string S;
map<char, ll> mp;
char lis[5] = {'M','A','R','C','H'};

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

	ll ans = 0;

	for (int i = 0;i < N;i++){
		cin >> S;
		mp[S[0]]++;
	}

	for (int i = 0;i < 5;i++){
		for (int j = i+1;j < 5;j++){
			for (int k = j+1;k < 5;k++){
				ans += mp[lis[i]]*mp[lis[j]]*mp[lis[k]];
			}
		}
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n, a, b;
	int sum = 0;
	cin >> n >> a >> b;
	for (int i = 1; i <= n; i++) {
		int c, d, e, f,g;
		c = i / 10000;
		d = (i - c * 10000) / 1000;
		e = (i - c * 10000 - d * 1000) / 100;
		f = (i - c * 10000 - d * 1000 - e * 100) / 10;
		g = i - c * 10000 - d * 1000 - e * 100 - f * 10;
		if (a <= c + d + e + f + g && c + d + e + f + g <=b) {
			sum += i;
		}
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 764
h = int(input())
f = [0] * 100
f[0] = 1
for i in range(1, 100):
  f[i] = 1 + f[i-1] * 2
  
num = 1
while h >= 2 ** (num):
  num += 1
  
ans = f[num - 1]

print(ans)

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

using namespace std;
using ll = long long;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;

void solve(long long N, long long K, std::vector<long long> A){
  ll ans = 0;
  for(ll i=0; i<N; i++) {
    ll cnt = 0;
    for(ll j=i; j<N; j++) {
      if(A[j]<A[i]) {
	cnt++;
      }
    }
    ans += (cnt*K)%MOD;
    ans %= MOD;
    //ans = ans % MOD;
  }
  for(ll i=0; i<N; i++) {
    ll cnt = 0;
    for(ll j=0; j<N; j++) {
      if(A[j]<A[i]) {
	cnt++;
      }
    }
    // ll tmp = ((2+(K-2))/2)%MOD;
    ll tmp = (cnt*(((K-1)*(K-2)/2)%MOD))%MOD;
    ans += (tmp+(((K-1)*cnt)%MOD))%MOD;
    //ans += (cnt*((K*(K-1)/2)%MOD))%MOD;
    //ans += ((((K*(K-1))%MOD)*cnt)/2)%MOD;
    ans %= MOD;
  }
  std::cout << ans << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long K;
  scanf("%lld",&K);
  std::vector<long long> A(N-1-0+1);
  for(int i = 0 ; i < N-1-0+1 ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, K, std::move(A));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
int main() {
  int n;
  cin >> n;
  vector<int> a(n+2);
  for(int i=1; i<n+1; i++) cin >> a[i];
  vector<int> num(n);
  vector<int> num2(n);
  vector<int> sp(n);
  for(int i=1; i<n; i++){
    num[i] = num[i-1] + abs(a[i] - a[i-1]);
  }
  for(int i=1; i<n; i++){
    num2[i] = num2[i-1] + abs(a[n+1-i] - a[n+2-i]);
  }
  for(int i=0; i<n; i++){
    sp[i] = abs(a[i+2] - a[i]);
  }
  for(int i=0; i<n; i++){
    cout << num[i] + sp[i] + num2[n-i-1] << endl;
  }
}

Measured memory_bytes: 2816
import collections

num = int(input())
values = [int(i) for i in input().split()]

odd = []  # kisuu
even = []  # gusu

for n, i in enumerate(values):
    if (n + 1) % 2 == 0:
        even.append(i)
    else:
        odd.append(i)

odd_counts = collections.Counter(odd)
even_counts = collections.Counter(even)

# print(odd_counts.most_common())
# print(even_counts.most_common())

odd_most_common = odd_counts.most_common()
even_most_common = even_counts.most_common()

half_num = int(num / 2)

if odd_most_common[0][0] != even_most_common[0][0]:
    odd_replace_num = half_num - odd_most_common[0][1]
    even_replace_num = half_num - even_most_common[0][1]
    print(odd_replace_num + even_replace_num)
else:
    answers = []
    odd_replace_num = half_num - odd_most_common[0][1]
    if len(even_most_common) == 1:
        even_replace_num = half_num
    else:
        even_replace_num = half_num - even_most_common[1][1]
    answers.append(odd_replace_num + even_replace_num)

    if len(odd_most_common) == 1:
        odd_replace_num = half_num
    else:
        odd_replace_num = half_num - odd_most_common[1][1]
    even_replace_num = half_num - even_most_common[0][1]
    answers.append(odd_replace_num + even_replace_num)

    print(min(answers))


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

using namespace std;

int main(){
	string S;
	int len, min = 1000, num;
	cin >> S;
	len = strlen(S.c_str());
	for(int i = 0; i < len - 2; i++){
		num = atoi(S.substr(i, 3).c_str());
		num = abs(753 - num);
		if(min > num){
			min = num;
		}
	}
	cout << min;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);


int main(){
    IOS;
    ll n,k;cin>>n>>k;
    ll a[n];
    f(i,0,n)cin>>a[i];
    sort(a,a+n);
    ll sum=0;
    f(i,0,k)sum+=a[i];
    cout<<sum;
    return 0;  
} 





Measured memory_bytes: 3584
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define print(X) cout << (X) << "\n"
#define _ << " " <<
static const int INF = 1e+9+7;


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

  int m = S/60;
  int h = m/60;

  cout << h << ":" << m - h*60 << ":" << S%60 << "\n";

  return 0;
}





Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define rint register int
#define gc() getchar()
inline int read(int r=0,int s=0,int c=gc()){for(;c<48||c>57;s=c,c=gc());for(;c>=48&&c<=57;(r*=10)+=c-48,c=gc());return s^'-'?r:-r;}
string s[15], S, R; unordered_set<string> g; int o[15], n, m, c; bool book[15];
inline void Check()
{
	for(rint i, j = 0; j < m; R = S, reverse(R.begin(),R.end()), g.count(R)?g.erase(R),0:(g.insert(S),0), j++) for(S = "", i = 1; i <= n; S += s[o[i++]][j]);
	if(!g.size()||(m&1&&g.size()==1&&(S=R=*g.begin(),reverse(R.begin(),R.end()),R==S))) return puts("YES"),exit(0); g.clear();
}
void DFS(int i, bool mid)
{
	if(c+1 >= -~n>>1){for(int j = 1, t = c; j <= n; !book[j] ? o[++t] = j : 0, j++); Check(); return;} if(book[i]){DFS(i+1,mid); return;} if(mid) DFS(i+1,0); 
	o[++c] = i, book[i] = true; for(int j = i+1; j <= n; !book[j] ? o[n-c+1] = j, book[j] = true, DFS(i+1,mid), book[j] = false : 0, j++); book[i] = false, --c;
}
int main(){n = read(), m = read(); for(rint i = 1; i <= n; cin >> s[i++]); DFS(1,n&1); return puts("NO"),0;}

Measured memory_bytes: 256