akhauriyash/Code-Regression huggingface dataset:
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
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;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int k;
    string s;
    cin >> k >> s;
    if(s.size()<=k)cout<<s<<"\n";
    else{
        cout<<s.substr(0,k)<<"..."<<"\n";
    }
}


Measured memory_bytes: 3592
N, Y = map(int, input().split())

y = Y // 1000

flag = False
for i in range(N+1):
    yi = y - 10 * i
    if yi < 0: pass
    for j in range(N+1):
        k = N - i - j
        yjk = yi - 5 * j - k
        if k < 0: break
        if yjk == 0: 
            flag = True
            break
    if flag: break

if flag: print('{} {} {}'.format(i,j,k))
else: print('-1 -1 -1')

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


int main()	
{
	int n,k;
	double a,b,e[200005]={};
	vector<double>v;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		e[i]=(a+1)*a/2/a+e[i-1];
	}
	for(int i=k;i<=n;i++)
	{
		v.push_back(e[i]-e[i-k]);
	}
	sort(v.begin(),v.end());
	cout<<setprecision(15)<<v[v.size()-1]<<endl;
	return 0;
}
	

Measured memory_bytes: 3956
// Problem : E - Balanced Path
// Contest : AtCoder Beginner Contest 147
// URL : https://atcoder.jp/contests/abc147/tasks/abc147_e
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;
 
#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

bool dp[85][85][25605]; // can you get to dp[row][col][Red - Blue + 12800]

int A[85][85], B[85][85];

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, m; cin >> n >> m;
    rep1(i, n) rep1(j, m) cin >> A[i][j];
    rep1(i, n) rep1(j, m) cin >> B[i][j];
    dp[0][1][12800] = true;
    rep1(i, n) rep1(j, m) rep(nexdiff, 25601) {
        int od = nexdiff + A[i][j] - B[i][j];
        if(0 <= od && od <= 25600) dp[i][j][nexdiff] = dp[i-1][j][od] || dp[i][j-1][od];
        if(dp[i][j][nexdiff]) continue;
        od = nexdiff - A[i][j] + B[i][j];
        if(0 <= od && od <= 25600) dp[i][j][nexdiff] = dp[i-1][j][od] || dp[i][j-1][od];
    }
    int bans = 12800;
    rep(fdi, 25601) if(dp[n][m][fdi]) bans = min(bans, max(12800-fdi, fdi-12800));
    cout << bans << endl;
}



Measured memory_bytes: 172416
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
ll n;
vector<ll> vec;
bool judge(ll x){
  map<ll,ll> mp;
  for(int i=1;i<n;i++){
    if(vec[i-1]>=vec[i]){
      if(mp.find(vec[i])==mp.end()) mp[vec[i]]=1;
      else mp[vec[i]]++;
      auto itr=mp.lower_bound(vec[i]);
      itr++;
      mp.erase(itr,mp.end());
      ll pos=vec[i];
      while(1){
        if(mp[pos]>=x){
          if(pos<=1){
            return false;
          }
          mp.erase(pos);
          if(mp.find(pos-1)==mp.end()) mp[pos-1]=1;
          else mp[pos-1]++;
          pos--;
        }
        else break;
      }
    }
  /*  if(x==2){
      cout<<i<<": ";
    for(auto itr=mp.begin();itr!=mp.end();itr++){
      cout<<(itr->first)<<" "<<(itr->second)<<" /// ";
    }
    cout<<endl;
  }*/
  }
  return true;
}
signed main(){
  cin>>n;
  ll past=0;
  bool f=true;
  for(int i=0;i<n;i++){
    ll a;
    cin>>a;
    if(a<=past) f=false;
    past=a;
    vec.push_back(a);
  }
  if(f) {
    cout<<1<<endl;
    return 0;
  }
  ll lb=1,rb=1000000007;
  while(rb-lb>1){
    ll mid=(lb+rb)/2;
    if(judge(mid)) rb=mid;
    else lb=mid;
//    cout<<"M:"<<mid<<endl;
  }
  cout<<rb<<endl;
}


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

int main()
{
	int a, b, c, d;

	cin >> a >> b >> c >> d;

	a = a + b;
	c = c + d;

	if (a > c)
		cout << "Left";
	else
		if (a == c)
			cout << "Balanced";
		else
			cout << "Right";

			return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>

#include <vector>
#include <algorithm>
#include <string>
using namespace std;

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


void Main()
{
	int N, K;
	cin >> N >> K;

	int m = 1;
	rep(i, N)
	{
		if (m < K) m *= 2;
		else m += K;
	}

	cout << m << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);

	Main();
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
s = input()
t = [1 if i == 'o' else 0 for i in s]
def generate(res):
    for i in range(1,n):
        if res[-1]:
            if t[i]:
                if res[-2]:
                    res.append(1)
                else:
                    res.append(0)
            else:
                if res[-2]:
                    res.append(0)
                else:
                    res.append(1)
        else:
            if t[i]:
                if res[-2]:
                    res.append(0)
                else:
                    res.append(1)
            else:
                if res[-2]:
                    res.append(1)
                else:
                    res.append(0)
    return res

def ret(ans):
    res = ["S"]*n
    for i in range(n):
        if ans[i] == 0:
            res[i] = "W"
    return ''.join(res)

ans1 = [1]
ans2 = [1]
ans3 = [1]
ans4 = [1]
if t[0]:
    ans1.append(1)
    ans2.append(0)
    res1 = generate(ans1)
    res2 = generate(ans2)
    if res1[-1] == ans1[0] and ans1[1] == res1[-2]:
        print(ret(res1[:-1]))
        quit()
    elif res2[-1] == ans2[0] and ans2[1] == res2[-2]:
        print(ret(res2[:-1]))
        quit()
else:
    ans3.append(1)
    ans4.append(0)
    res3 = generate(ans3)
    res4 = generate(ans4)
    if res3[-1] == ans3[0] and ans3[1] != res3[-2]:
        print(ret(res3[:-1]))
        quit()
    elif res4[-1] == ans4[0] and ans4[1] != res4[-2]:
        print(ret(res4[:-1])) 
        quit()


ans5 = [0]
ans6 = [0]
ans7 = [0]
ans8 = [0]
if t[0]:
    ans5.append(1)
    ans6.append(0)
    res5 = generate(ans5)
    res6 = generate(ans6)
    if res5[-1] == ans5[0] and ans5[1] != res5[-2]:
        print(ret(res5[:-1]))
        quit()
    elif res6[-1] == ans6[0] and ans6[1] != res6[-2]:
        print(ret(res6[:-1]))
        quit()

else:
    ans7.append(1)
    ans8.append(0)
    res7 = generate(ans7)
    res8 = generate(ans8)
    if res7[-1] == ans7[0] and ans7[1] == res7[-2]:
        print(ret(res7[:-1]))
        quit()
    elif res8[-1] == ans8[0] and ans8[1] == res8[-2]:
        print(ret(res8[:-1]))
        quit()

print(-1)


Measured memory_bytes: 58548
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    A = LI()
    print("bust" if sum(A)>=22 else "win")

main()



Measured memory_bytes: 27184
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int lli;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef pair <lli,lli> pii;
#define ff first
#define ss second
#define mod 1000000007
#define pb push_back
#define EPS 1e-6
typedef long long LL;

int main(){
	fast;
	lli n, k;
	cin>>n>>k;
	if(n%k==0) cout<<0;
	else{
	    lli rem = n%k;
	    cout<<min(rem, abs(rem-k));
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    vector<pair<int,int>> xy = {{1,1},{1,0},{1,-1},{0,1},{0,-1},{-1,1},{-1,0},{-1,-1}};
    int H,W;
    cin >> H >> W;
    vector<vector<char>> S(W,vector<char>(H));
    vector<vector<int>> count(W,vector<int>(H));
    
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> S.at(j).at(i);
        }
    }
    
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            if(S.at(j).at(i) == '#'){
                cout << '#';
            }else{
            
            for(int k = 0; k < 8; k++){
                if(0 <= j + xy.at(k).first && j + xy.at(k).first < W && 0 <= i + xy.at(k).second && i + xy.at(k).second < H){
                    if(S.at(j + xy.at(k).first).at(i + xy.at(k).second) == '#'){
                        count.at(j).at(i)++;
                    }   
                }
            }
            cout << count.at(j).at(i);
            
        }}
    cout << endl;
    }
    
}


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

typedef long long LL;

const LL inf = (LL)1e18;

LL n, a, b, c, d, now;

unordered_map<LL, LL> ma;
priority_queue<LL> que;

void update(LL x, LL y)
{
	if (x >= now) return;
	if (!ma[x]) ma[x] = inf / (n - x) >= d ? (n - x) * d : inf, que.push(x);
	ma[x] = min(ma[x], y);
}

int main()
{
	int T; scanf("%d", &T);
	while (T--)
	{
		scanf("%lld%lld%lld%lld%lld", &n, &a, &b, &c, &d);
		ma.clear();
		ma[n] = 0;
		que.push(n);
		while (!que.empty())
		{
			LL x = que.top(); que.pop();
			now = x;
			if (inf / d >= x) update(0, ma[x] + d * x);
			if (x % 2 != 0)
			{
				update((x + 1) / 2, ma[x] + d + a);
				update((x - 1) / 2, ma[x] + d + a);
			}
			else update(x / 2, ma[x] + a);
			if (x % 3 != 0)
			{
				update(x / 3 + 1, ma[x] + d * (3 - x % 3) + b);
				update(x / 3, ma[x] + d * (x % 3) + b);
			}
			else update(x / 3, ma[x] + b);
			if (x % 5 != 0)
			{
				update(x / 5 + 1, ma[x] + d * (5 - x % 5) + c);
				update(x / 5, ma[x] + d * (x % 5) + c);
			}
			else update(x / 5, ma[x] + c);
		}
		printf("%lld\n", ma[0]);
	}
	return 0;
}

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

void solve(){
  int x, a, b; cin >> x >> a >> b;
  cout << (x - a) % b << endl;
  return;
}

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int d = Integer.parseInt(scan.next());
        int t = Integer.parseInt(scan.next());
        int s = Integer.parseInt(scan.next());
        scan.close();

        if (t * s >= d) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}


Measured memory_bytes: 35568
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

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

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

}

Measured memory_bytes: 256
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var k = int.Parse(line[1]);
        var a = new int[n];
        for (int i = 0; i < n; i++) a[i] = int.Parse(Console.ReadLine().Trim());
        var ans = getAns(a, k);
        Console.WriteLine(ans);
    }
    static int getAns(int[] a , int k)
    {
        var ok = 1000000000;
        var ng = 0;
        while (ok - ng > 1)
        {
            var mid = ng + (ok - ng) / 2;
            if (check(a, k, mid)) ok = mid;
            else ng = mid;
        }
        return ok;
    }
    static bool check(int[] a,  int k, int b)
    {
        var aL = a.Length;
        var tcount = 0;
            var p = 0;
        for (int i = 0; i < aL; i++)
        {
            if (a[i] > b) return false;
            if (p + a[i] > b)
            {
                tcount++;
                if (tcount > k) return false;
                p = a[i];
            }
            else if (p + a[i] == b)
            {
                tcount++;
                if (tcount > k) return false;
                p = 0;
            }
            else p += a[i];
        }
        if (p > 0) tcount++;
        return tcount <= k;
    }
}




Measured memory_bytes: 20028
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define debugArray(x, n)                                      \
  cerr << __LINE__ << ": " << #x << " = {";                   \
  for (long long hoge = 0; (hoge) < (long long)(n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];                   \
  cerr << "}" << '\n'
#define debugMatrix(x, h, w)                                         \
  cerr << __LINE__ << ": " << #x << " =\n";                          \
  for (long long hoge = 0; (hoge) < (long long)(h); ++(hoge)) {      \
    cerr << ((hoge ? " {" : "{{"));                                  \
    for (long long fuga = 0; (fuga) < (long long)(w); ++(fuga))      \
      cerr << ((fuga ? ", " : "")) << x[hoge][fuga];                 \
    cerr << "}" << (hoge + 1 == (long long)(h) ? "}" : ",") << '\n'; \
  }
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#define debugMatrix(x, h, w) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  int N, A, B;
  cin >> N >> A >> B;
  if (!(__builtin_popcount(A ^ B) & 1)) {
    cout << "NO" << '\n';
    return 0;
  }
  auto f
      = [](int x, int i) { return (x >> (i + 1)) * (1 << i) ^ (x % (1 << i)); };
  auto g = [](int x, int i, bool b) {
    return (x >> (i)) * (1 << (i + 1)) ^ (b << i) ^ (x % (1 << i));
  };
  function<vector<int>(int, int, int)> rec = [&](int n, int a, int b) {
    if (n == 1) return vector<int>({a, b});
    vector<int> ret(1 << n);
    for (int i = 0; i < n; i++) {
      if (((a ^ b) >> i) & 1) {
        int aa = f(a, i);
        int bb = f(b, i);
        auto l = rec(n - 1, aa, aa ^ 1);
        auto r = rec(n - 1, aa ^ 1, bb);
        for (int j = 0; j < (1 << (n - 1)); j++) {
          ret[j] = g(l[j], i, (a >> i) & 1);
          ret[j + (1 << (n - 1))] = g(r[j], i, (b >> i) & 1);
        }
        break;
      }
    }
    return ret;
  };
  auto ans = rec(N, A, B);
  cout << "YES" << '\n';
  for (int i = 0; i < (1 << N); i++) cout << (i ? " " : "") << ans[i];
  cout << '\n';
  return 0;
}


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

const int MAX = 2e5 + 5;
int N, A[MAX], dp[MAX];
int main() {
        scanf("%d", &N);
        for (int i=0; i<N; ++i) {
                scanf("%d", &A[i]);
                dp[A[i]] = dp[A[i]-1]+1;
        }

        int m=0;
        for (int i=1; i<=N; ++i)
                m = max(m, dp[i]);

        printf("%d\n", N-m);
        return 0;

}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <queue>
#include <cmath>
#include <random>
#include <fstream>
#include <string>
#include <tuple>
#include <deque>
#include <set>
#include <map>
#include <stack>

#define REP(i, N) for(int i = 0; i< N; i++)
using namespace std;
#define ll long long
const int INF = 1 << 29;
const ll llINF = 10000000000000000;

const int MOD = 1000000007;

#define MAX_N 100100
typedef pair<int, int> P;
typedef pair<ll, ll> llP;

class UnionFindTree{
private:
    int par[MAX_N];
    int urank[MAX_N];
    int size[MAX_N];
public:
    int init(int n);
    int find(int x);
    int unite(int x, int y);
    int same(int x, int y);
    int parnum(int x){return par[x];}
    int ranknum(int x){return urank[x];}
    int sizenum(int x){return size[find(x)];}
};

int UnionFindTree::init(int n){
    REP(i, n){
        par[i] = i;
        urank[i] = 0;
        size[i] = 1;
    }
    return 0;
}

int UnionFindTree::find(int x){
    if(par[x] == x)return x;
    else return par[x] = find(par[x]);
}

int UnionFindTree::unite(int x, int y){
    x = find(x);
    y = find(y);
    
    if(x == y)return 0;
    if(urank[x] < urank[y]){
        par[x] = y;
        size[y] += size[x];
    }else{
        par[y] = x;
        size[x] += size[y];
        if(urank[x] == urank[y])urank[x] ++;
    }
    return 0;
}

int UnionFindTree::same(int x, int y){
    return find(x) == find(y);
}

int main(){
    int N;
    cin >> N;
    string W[110];
    bool daijoubu = true;
    REP(i, N){
        
        bool onaji = false;
        cin >> W[i];
        if(i != 0){
            REP(j, i){
                if(W[i] == W[j])onaji = true;
            }
            if(onaji || W[i][0] != W[i - 1][W[i - 1].size() - 1]){
                daijoubu = false;
            }
        }
    }
    if(daijoubu)printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 888
import itertools

def abcd(n):
  for _ in range(n):
    a,b,c,d = map(int,input().split())
    yield a,b,c,d

def main():
  N,M,Q = map(int,input().split())
  num = list(range(1,M+1))
  X = list(abcd(Q))
  for v in itertools.combinations_with_replacement(num, N):
    ans = 0
    for a,b,c,d in X:
      A,B = v[a-1],v[b-1]
      if B-A == c:
        ans += d
    yield ans

print(max(main()))

Measured memory_bytes: 68184
n = int(input())
l = sorted(list(map(int, input().split())))
base = l[-1]
ans = 0
if base % 2 == 0:
  half = base //2
else:
  half = base // 2 + 1

diff = float('Inf')
for i in l:
  if abs(half-i) < diff:
    diff = abs(half-i)
    ans = i

print(base, ans)



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

struct LIS {
	const int INF = 1e9 + 1;
	vector<int> dp;
	int last = 0;
	vector<vector<int>> hist;

	LIS(int N) {
		dp.assign(N + 1, INF);
	}
	void add(int a) {
		int pos = lower_bound(dp.begin(), dp.end(), a) - dp.begin();
		hist.push_back({ pos, dp[pos], last });
		dp[pos] = a;
		last = max(last, pos);
	}

	int ans() { return last + 1; }

	void rollback() {
		auto v = hist.back();
		hist.pop_back();
		dp[v[0]] = v[1];
		last = v[2];
	}
};

int N;
int val[220000];
int ans[220000];
vector<int> adj[220000];
LIS lis(220000);

void dfs(int nd, int prv = -1) {
	lis.add(val[nd]);
	ans[nd] = lis.ans();
	for (int nxt : adj[nd]) if (nxt != prv) dfs(nxt, nd);
	lis.rollback();
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> N;
	for (int i = 0; i < N; i++) cin >> val[i];
	for (int i = 0; i < N - 1; i++) {
		int a, b; cin >> a >> b;
		a--, b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dfs(0);
	for (int i = 0; i < N; i++) cout << ans[i] << "\n";
	return 0;
}


Measured memory_bytes: 47320
import sys
import numpy as np
MOD = 10 ** 9 + 7

n = int(sys.stdin.readline().rstrip())
a = np.array(sys.stdin.readline().split(), dtype=np.int64)

def main():
  x = a[:, None] >> np.arange(61) & 1
  x = x.sum(axis=0)
  y = n - x
  res = x * y  % MOD * ((1 << np.arange(61)) % MOD)
  print(res.sum() % MOD)

if __name__ == '__main__':
  main()

Measured memory_bytes: 303892
def main():

    K, N = map(int, input().split())
    A = list(map(int, input().split()))
    ans = K
    dist = []
    for i in range(N-1):
        dist.append(A[i+1] - A[i])
    dist.append(A[0]+K - A[N-1])

    for v in dist:
        ans = min(ans, K - v)
    return ans


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 87244
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

	long long GCD(long long a, long long b) {
		if (a < b)
			swap(a, b);
		if (b == 0) return a;
		else return GCD(b, a % b);
	}
	bool sosuu_check(int num) {
		int i;
		for (i = 2; i <= sqrt(num); ++i) {
			if (num%i == 0)
				return false;
		}
		return (num < 2) ? false : true;
	}



int main() {
	int N,M,i,j;
	cin >> N >> M;
	vector<int> X(100001),dif(100001);
	REP(i, M) {
		cin >> j;
		X[i]=j;
	}
	sort(X.begin(), X.begin() + M);
	ll sum=0;
	REP(i, M-1) 
		dif[i] = abs(X[i] - X[i + 1]);
	sort(dif.begin(), dif.begin() + M - 1);
	REP(i, M - 1 - (N - 1))
		sum += dif[i];
	cout << sum << endl;
}

Measured memory_bytes: 1024
import numpy
n, m = map(int, input().split())
a = []
b = []

value = [] 

for i in range(n):
    ta, tb = map(int, input().split())
    value.append((ta, tb))

value.sort(key=(lambda x: x[0]))

cost = 0
for i in range(n):
    if m > value[i][1]:
        cost += value[i][1] * value[i][0]
        m -= value[i][1]
    else:
        cost += value[i][0] * m
        m = 0

print(cost)

Measured memory_bytes: 27364
def ascan; gets.split.map(&:to_i);end

a,b,c,x,y = ascan

z = [x,y].min

ans = [c*2,a+b].min * z

x -= z
y -= z

if x > 0
    ans += [a,c*2].min*x
end

if y > 0
    ans += [b,c*2].min*y
end

p ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(n*a, b);
  
  return 0;
}

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

int s_i(string str){
  int ans = 0;
  int tmp = 1;
  for(int i=0;i<str.size();i++){
    if(str[i] == 'g')ans += tmp;
    else if(str[i] == 'b')ans += 2 * tmp;
    tmp *= 3;
  }
  return ans;
}
int main(){
  string worm,tmp;
  deque<string> open,open2;
  char first;
  int ans,max;
  bool flag;
  bool check[100000];

  while(1){
    cin >> worm;
    if(worm == "0")break;

    max = 1;
    for(int i=0;i<worm.size();i++)max *= 3;
    for(int i=0;i<max;i++)check[i] = false;

    open.clear();
    open2.clear();

    open.push_back(worm);
    check[s_i(worm)] = true;
    ans = 0;

    while(1){
      while(open.size()){
	worm = open[0];
	open.pop_front();
	
	flag = true;
	first = worm[0];
	for(int i=1;i<worm.size();i++){
	  if(worm[i]!=first){
	    flag = false;
	    break;
	  }
	}
	if(flag)break;
	
	for(int i=0;i<worm.size()-1;i++){
	  if(worm[i]!=worm[i+1]){
	    tmp = worm;
	    if(worm[i]!= 'r' && worm[i+1] != 'r')tmp[i] = tmp[i+1] = 'r';
	    else if(worm[i]!= 'g' && worm[i+1] != 'g')tmp[i] = tmp[i+1] = 'g';
	    else if(worm[i]!= 'b' && worm[i+1] != 'b')tmp[i] = tmp[i+1] = 'b';
	    if(!check[s_i(tmp)]){
	      check[s_i(tmp)] = true;
	      open2.push_back(tmp);
	    }
	  }
	}
      }
      if(flag)break;
      if(!open2.size())break;
      open = open2;
      open2.clear();
      ans++;
    }
    if(flag)cout << ans << endl;
    else cout << "NA" << endl;
  }
}

Measured memory_bytes: 1096
N, L = map(int, input().split())

sum = 0
min = 100000
min2 = 0
for i in range(0, N):
    aji = L+i
    sum += aji
    if(abs(aji) < min):
        min = abs(aji)
        min2 = aji

print(sum - min2)


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

int main(){
    int D;
    cin >> D;
    vector<int> c(27, 0);
    rep(j, 26){
        cin >> c[j+1];
    }
    int s[D+1][27];
    rep(i, D){
        rep(j, 26){
            cin >> s[i+1][j+1];
        }
    }
    vector<int> t(D+1, 0);
    // rep(i, D) cin >> t[i+1];
    rep(i, D) t[i+1] = (i % 26) + 1; // initial solution;

    // int M;
    // M = 0;
    // // cin >> M;
    // vector<int> d(M+1, 0);
    // vector<int> q(M+1, 0);
    // // rep(i, M) cin >> d[i+1] >> q[i+1];

    // ll ans = 0;
    // vector<int> lastday(27, 0);

    // for(int day = 1; day <= D; day++){
    //     ans += s[day][t[day]];
    //     lastday[t[day]] = day;
    //     for(int j = 1; j <= 26; j++){
    //         ans -= c[j] * (day - lastday[j]); 
    //     }
    // }

    // for(int que = 1; que <= M; que++){
    //     ans -= s[d[que]][t[d[que]]];
    //     ans += s[d[que]][q[que]];

    //     int before = 0;
    //     for(int pos = d[que] - 1; pos >= 1; pos--){
    //         if (t[pos] == t[d[que]]){
    //             before = pos;
    //             break;
    //         }
    //     }
    //     int after = D+1;
    //     for(int pos = d[que] + 1; pos <= D; pos++){
    //         if (t[pos] == t[d[que]]){
    //             after = pos;
    //             break;
    //         }
    //     }
    //     ans += c[t[d[que]]] * (after - d[que]) * (before - d[que]);

    //     before = 0;
    //     for(int pos = d[que] - 1; pos >= 1; pos--){
    //         if (t[pos] == q[que]){
    //             before = pos;
    //             break;
    //         }
    //     }
    //     after = D+1;
    //     for(int pos = d[que] + 1; pos <= D; pos++){
    //         if (t[pos] == q[que]){
    //             after = pos;
    //             break;
    //         }
    //     }
    //     ans -= c[q[que]] * (after - d[que]) * (before - d[que]);

    //     t[d[que]] = q[que];
    //     // cout << ans << endl;
    // }

    rep(i, D){
        cout << t[i+1] << endl;
    }
    // cout << ans << endl;

    return 0;

}


Measured memory_bytes: 3680
#include <stdio.h>
#include <string.h>

#define N 36

void BubbleSort(char card[N][3], int n) {
	int i, j;
	char tmp[3];
	for (i = 0; i < n; i++) {
		for (j = n - 1; j >= i + 1; j--) {
			if (card[j][1] < card[j - 1][1]) {
				strcpy(tmp, card[j]);
				strcpy(card[j], card[j - 1]);
				strcpy(card[j - 1], tmp);
			}
		}
	}
}

void SelectionSort(char card[N][3], int n) {
	int i, j, minj;
	char tmp[3];
	for (i = 0; i < n; i++) {
		minj = i;
		for (j = i; j < n; j++) {
			if (card[j][1] < card[minj][1]) {
				minj = j;
			}
		}
		strcpy(tmp, card[i]);
		strcpy(card[i], card[minj]);
		strcpy(card[minj], tmp);
	}
}

int judge(char card[N][3], char rule[N][3], int n) {
	int i, j;
	int a, b;
	int flag = 1;
	for (i = 0; i < n - 1; i++) {
		if (card[i][1] == card[i + 1][1]) {
			for (j = 0; j < n; j++) {
				if (rule[j][1] == card[i][1]) {
					if (rule[j][0] == card[i][0]) {
						a = j;
					}
					else if (rule[j][0] == card[i + 1][0]) {
						b = j;
					}
				}
			}
			if (a > b) {
				flag = 0;
				break;
			}
		}
	}
	if (flag) {
		printf("Stable\n");
	}
	else {
		printf("Not stable\n");
	}
}

int main() {
	int n;
	int i;
	char card[N][3];
	char Bcard[N][3];
	char Scard[N][3];

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s", card[i]);
		strcpy(Bcard[i], card[i]);
		strcpy(Scard[i], card[i]);
	}

	BubbleSort(Bcard, n);
	SelectionSort(Scard, n);

	for (i = 0; i < n - 1; i++) {
		printf("%s ", Bcard[i]);
	}
	printf("%s\n", Bcard[n - 1]);
	judge(Bcard, card, n);
	for (i = 0; i < n - 1; i++) {
		printf("%s ", Scard[i]);
	}
	printf("%s\n", Scard[n - 1]);
	judge(Scard, card, n);

	return 0;
}


Measured memory_bytes: 2124
N = int(input())
A = [int(input()) for i in range(N)]

A_ = sorted(A)
A_r = list(reversed(A_))

n = (A_[0], A_r[0])
sum = abs(n[0] - n[1])
for i, (x, y) in enumerate(zip(A_[1:N//2], A_r[1:N//2])):
    sum += abs(n[0] - y) + abs(n[1] - x)
    n = (x, y)

if N%2 != 0:
    m = A_[N//2]
    sum += max(abs(n[0] - m), abs(n[1] - m))

print(sum)


Measured memory_bytes: 9312
#include <stdio.h>

int N; long long C,X[100100],V[100100],L[3][100100],R[3][100100];

int main()
{
	scanf ("%d %lld",&N,&C);
	for (int i=1;i<=N;i++) scanf ("%lld %lld",&X[i],&V[i]);

	long long s = 0;
	for (int i=1;i<=N;i++){
		s += V[i];
		for (int k=1;k<=2;k++){
			long long n = s - X[i] * k;
			L[k][i] = L[k][i-1];
			if (L[k][i] < n)
				L[k][i] = n;
		}
	}

	long long t = 0;
	for (int i=N;i>=1;i--){
		t += V[i];
		for (int k=1;k<=2;k++){
			long long n = t - (C - X[i]) * k;
			R[k][i] = R[k][i+1];
			if (R[k][i] < n)
				R[k][i] = n;
		}
	}

	long long ans = 0;
	for (int i=0;i<=N;i++){
		for (int k=1;k<=2;k++){
			long long n = L[k][i] + R[3-k][i+1];
			if (ans < n)
				ans = n;
		}
	}

	printf ("%lld\n",ans);

	return 0;
}

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

int main(){
  while(1){
    int a,b; char op; cin>>a>>op>>b;
    int r;
    bool fin = false;
    switch(op){
      case('+'):
        r = a+b; break;
      case('-'):
        r = a-b; break;
      case('*'):
        r = a*b; break;
      case('/'):
        r = a/b; break;
      default:
        fin = true; break;
    }
    if(fin){break;}
    cout << r <<"\n";
  }
  
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll H, W;
	cin >> H >> W;
	ll bomb[H][W];
	REP(i, H){
		string S;
		cin >> S;
		REP(j, W){
			bomb[i][j] = (S[j]=='.'?0:1);
		}
	}
	ll res[H][W];
	vector<pll> move{{-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}, {1, 0}, {1, -1}, {0, -1}};
	REP(i, H){
		REP(j, W){
			ll tmp = 0;
			REP(k, 8){
				ll ii = i + move[k].first;
				ll jj = j + move[k].second;
				if(jj>-1 && jj<W && ii>-1 && ii<H){
					tmp += bomb[ii][jj];
				}
			}
			res[i][j] = tmp;
		}
	}
	REP(i, H){
		REP(j, W){
			if(bomb[i][j]==1){
				cout << '#';
			}else{
				cout << res[i][j];
			}
		}
		cout << endl;
	}
    return 0;
}

Measured memory_bytes: 256
def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)

def main():
	n, *a = map(int, open(0).read().split())
	mod = 10 ** 9 + 7
	lcm = 1
	for x in a:
		lcm = lcm * x // gcd(lcm, x)
	lcm %= mod
	ans = sum(pow(x, mod - 2, mod) for x in a) % mod
	print(ans * lcm % mod)

if __name__ == "__main__":
	main()


Measured memory_bytes: 4084
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;

public class Don
{
    public Don() { }
    private Reader r = new Reader();

    public void Solve()
    {
        var N = r.nextInt();
        r.nextInt();
        var list = new List<string>();
        for(var i = 0; i < N; i++)
        {
            list.Add(r.next());
        }
        list.Sort();
        for(var i = 0; i < N; i++)
        {
            Console.Write(list[i]);
        }

        Console.WriteLine();
    }

    public static void Main(string[] args)
    {
        new Don().Solve();
    }

}

class Reader
{
    string[] s;
    int i;
    char[] cs = new char[] { ' ' };

    public Reader()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length)
            return s[i++];
        var input = Console.ReadLine();
        while (input == "")
            input = Console.ReadLine();
        s = input.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return next();
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}


Measured memory_bytes: 3288
/*
 * a.c
 *
 *  Created on: 2017/06/13
 *      Author: AWV060608
 */

#include	<stdio.h>
#include	<string.h>
//#include	<math.h>

int		main(void)
{
	int		n;
	int		a;
	int		i;
	int		min, max;
	double	sum;

	min = 1000000;
	max = -1000000;

	sum = 0;
	scanf("%d",&n);
	for(i=0; i<n; i++)
	{
		scanf("%d",&a);
		if( a < min )
		{
			min = a;
		}
		if( max < a )
		{
			max = a;
		}
		sum = sum+a;
	}
	printf("%d %d %.0lf\n",min, max, sum);

	return 0;
}

Measured memory_bytes: 632
#include <iostream>
#include <map>
using namespace std;
bool ans[3][3];

int main() {
    int num, N;
    map<int, pair<int, int> > m;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> num;
            m.insert(make_pair(num, make_pair(i, j)));
        }
    }
    int b;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> b;
        if (m.count(b)) {
            ans[m[b].first][m[b].second] = 1;
        }
    }
    for (int i = 0; i < 3; i++) {
        int sum = ans[i][0] && ans[i][1] && ans[i][2];
        if (sum) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    for (int i = 0; i < 3; i++) {
        int sum = ans[0][i] && ans[1][i] && ans[2][i];
        if (sum) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    int sum = ans[0][0] && ans[1][1] && ans[2][2];
    if (sum) {
        cout << "Yes" << endl;
        return 0;
    }
    sum = ans[0][2] && ans[1][1] && ans[2][0];
    if (sum) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  int n;
  cin>>n;
  string s;
  int mx=0;
  map<string,int>dic;
  rep(i,n){
    cin>>s;
    dic[s]++;
    mx=max(mx,dic[s]);
  }
  for(auto mp:dic){
    if(mx==mp.sc)
    cout<<mp.fs<<endl;
  }
}

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

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
    return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    mint ans = 2;
    if(n%2==0){
        for(int i = 0;i<=n-2;i+=2){
            if(a[i]!=a[i+1] || a[i] != i+1){
                cout << 0 << endl;
                return 0;
            }
        }
        cout << ans.pow(n/2) << endl;
    }else{
        if(a[0] != 0){
            cout << 0 << endl;
            return 0;
        } 
        for(int i = 1;i<=n-2;i+=2){
            if(a[i]!=a[i+1] || a[i] != i+1){
                cout << 0 << endl;
                return 0;
            }
        }
        cout << ans.pow(n/2) << endl;
    }

}


Measured memory_bytes: 3720
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto M = RD;
	auto S = RD!string;

	long[] ans;
	auto pos = N;
	while (pos != 0)
	{
		if (pos <= M)
		{
			ans ~= pos;
			break;
		}

		bool ok;
		foreach (i; 0..M)
		{
			auto p = pos-M+i;
			if (S[p] == '0')
			{
				ans ~= M-i;
				pos = p;
				ok = true;
				break;
			}
		}
		if (!ok)
		{
			ans = [];
			break;
		}
	}

	if (ans.empty)
		writeln(-1);
	else
	{
		ans.reverse();
		ans.map!(to!string).join(" ").writeln;
	}
	stdout.flush();
	debug readln();
}

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

int main()
{
  string S;
  cin >> S;
  
  if ((S[2] == S[3]) && (S[4] == S[5]))
  {
    printf("Yes");
  }
  else
  {
    printf("No");
  }

  return 0;
}

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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> L(N);
  for (int i = 0; i < N; i++)
    cin >> L.at(i);

  int d = 0;
  int ans = 1;
  for (int i = 0; i < N; i++) {
    d += L.at(i);
    if (d <= X)
      ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
signed main(){
  int N;
  cin>>N;
  vi A(N);
  int ans=0;
  rep(i,0,N) cin>>A[i];
  sort(ALL(A));
  for(int i=N-1;1<=i;i-=2)
    ans+=A[i]-A[i-1];
  if(N%2==1)
    ans+=A[0];
  cout<<ans;
  }


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

using namespace std;
#define MOD 1000000007
#define pi 3.1415926535897932384626433832795028841971693993751058209749445923078164062
#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define vl vector<ll>
#define vi vector<int>
#define vs vector<string>
#define vll vector< pair<ll,ll> >
#define vii vector< pair<int,int> >
#define viii vector< tuple <int,int,int> >
#define vlll vector< tuple <ll,ll,ll> >
#define vvl vector<vector<ll>>
#define vv vector<vector<int>>
#define all(v) v.begin(),v.end()
#define sqrt sqrtl
#define cbrt cbrtl
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mapcl map<char,ll>
#define mapci map<char,int>
#define mapll map<ll,ll>
#define mapii map<int,int>
#define seti set<int>
ifstream fin("input.txt");
ofstream fout("output.txt");

int gcd(int a,int b){while (a&&b)a>b?a%=b:b%=a;return a+b;}
ll pows(int a , int b){ll res=1;for(int i=0; i<b; ++i){res*=a;}return res;}
ll logx(ll base, ll num){int cnt=0;while(num!=1){num/=base; ++cnt;}return cnt;}

vi vis(100001,0);
vi adj[100001];

int main()
{	
    std::ios::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    int x;
    cin>>x;
    vi vec;
    for(int i=0; i<x; ++i)
    {
    	int n;
    	cin>>n;
    	vec.pb(n);
    }
    vi vec2;
    vec2=vec;
    sort(all(vec2));
    int flag=0;
    for(int i=0; i<x; ++i)
    {
    	if(vec[i]!=i+1)
    	{
    		for(int j=0; j<x; ++j)
    		{
    			if(vec[j]==(i+1))
    			{
    				swap(vec[i],vec[j]);
    				++flag;
    				break;
    			}
    		}
    	}
    	if(flag==1)
    		break;
    }
    if(vec2==vec)
    	cout<<"YES"<<"\n";
    else
    	cout<<"NO"<<"\n";

}

Measured memory_bytes: 2944
from bisect import *
n,m,v,p=map(int,input().split())
it=list(map(int,input().split()))
it.sort()
pre=[it[0]]
for i in range(1,n):
    pre.append(pre[i-1]+it[i])
ans=0
par=[i for i in range(n)]
for i in range(n-2,-1,-1):
    if it[i]==it[i+1]:
        par[i]=par[i+1]
#print(it)

for i in range(n):
    
    if it[i]+m<it[-p]:
        continue
    ind=n-(p-1)
    ind2=par[i]
    if ind2>=ind-1:
        ans+=1
        continue

    tot=m*v
    
    tot-=(n-ind)*m
    tot-=(ind2)*m
    tot-=m
    #print(tot)
    co=pre[ind-1]-pre[ind2]
    co=((it[i]+m)*(ind-1-ind2)-co)
    
    #print(ind,ind2,tot,co)
    if co>=tot:
        ans+=1
print(ans)


Measured memory_bytes: 64536
# -*- coding: utf-8 -*-
import sys
from statistics import median_low, median_high
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N = int(lines.pop(0))
    X = list(map(int, lines.pop(0).split(' ')))
    low = median_low(X)
    high = median_high(X)
    for i in X:
        if i <= low:
            print(high)
        else:
            print(low)

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Measured memory_bytes: 27168
/*
    quid-pro-quo: LOGIC for AC
    written by: codercell07
    LANG: C++ 11
    Problem: random
*/
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false); cin.tie(NULL)
#define testcases freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
#define ui unsigned int
#define ll long long
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define sz(x) (int)x.size()
#define pq priority_queue /*maxim at top(max-heap)*/
#define pqmax priority_queue<int, vector<int>, greater<int>> /*minim at top(min-heap)*/
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define asc(x) sort(all(x))
#define desc(x) sort(all(x), greater<int>())
#define time_el (double)time/CLOCKS_PER_SEC
using namespace std;
const int MAX=2e6; //dummy, make sure change as per constraints
const ll M=1e9+7, inf=1e18;
const char nl='\n';
 
ll apbmc(ll a, ll b, ll c){ a%=c; ll res=1; while(b){ if(b&1) res=res*a%c; a=a*a%c; b>>=1; } return res;}
ll apb(ll x, ll y){ ll temp; if(y==0) return 1;  temp=apb(x, y/2); if(y%2==0) return temp*temp;  else return temp*temp*x;}
 

void solve(){   
    //clock_t time;
    int n, k; cin>>n>>k;
    vi v(n);
    for(int &i: v) cin>>i;
    vll dp(n, M);
    dp[0]=0;
    for(int i=0; i<n; i++){
        for(int j=1; j<=k; j++){
            if(i-j>=0){
                dp[i]=min(abs(v[i]-v[i-j]) + dp[i-j], dp[i]);
            }
        }
    }
    cout<<dp[n-1];
}
int main(){
    fastio;
    // #ifndef ONLINE_JUDGE
    //     testcases;
    // #endif // !DEBUG
    cout<<fixed<<setprecision(9);
    
    //int t; cin>>t; while(t--) solve();    
    solve();

    return 0;
}
//points to check:
//  * check for constraints, mainly array!
//  * EDGE CASES
//  * check for integer overflow, use long long!
//  * learn, do, solve, share something, NOW!

Measured memory_bytes: 4480
let () = Scanf.scanf "%d %d\n" @@ fun n t ->
    Array.init n (fun _ -> Scanf.scanf " %d" (fun t -> t))
    |> Array.fold_left (fun (t1, sum) t2 -> (t2, sum+min (t2-t1) t)) (0, t)
    |> snd
    |> Printf.printf "%d"


Measured memory_bytes: 5760
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Data.Bits
import Data.List
import Control.Monad

update :: VUM.IOVector Int -> B.ByteString -> IO () 
update vec bs
    | h == 'M' = VUM.modify vec (+1) 0
    | h == 'A' = VUM.modify vec (+1) 1
    | h == 'R' = VUM.modify vec (+1) 2
    | h == 'C' = VUM.modify vec (+1) 3
    | h == 'H' = VUM.modify vec (+1) 4
    | otherwise = VUM.modify vec (+1) 5
    where
        h = B.head bs

enum :: Int -> Int -> [Int]
enum n l
    | l == 0 = []
    | otherwise = (n .&. 1) : enum (shiftR n 1) (l - 1)

solve :: VU.Vector Int -> Int
solve vec = sum $ map (\i -> comb vec (enum i 5)) [0..2^len-1]
    where
        len = VU.length vec
        comb :: VU.Vector Int -> [Int] -> Int
        comb vec es
            | ones /=3 = 0
            | otherwise = foldl' step 1 (zip (VU.toList vec) es)
                where
                    ones = length $ filter (==1) es
                    step acc (v,b)
                        | b == 1 = acc * v
                        | otherwise = acc

main = do
    n <- readLn :: IO Int
    vec <- VUM.replicate 6 0
    forM_ [1..n] $ \i -> do
        bs <- B.getLine
        update vec bs 
    vec' <- VU.freeze vec
    print $ solve (VU.init vec')

Measured memory_bytes: 1020
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<map>
using namespace std;



int main() {

	int X;
	cin >> X;

	if (X == 3 || X == 5 || X == 7) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

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

string s;
int main()
{
	cin >> s;
	int l = s.size();
	int count = 0;
	bool f = 0;
	for (int i = 0; i < l; i ++)
	{
		if (s[i] - '0' == f) count ++;
		f = !f;
	}
	cout << min(count, l - count) << endl;
}

Measured memory_bytes: 512