akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define INF = 1001001001
#define pi = acos(-1)
using namespace std;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return (x * y) / gcd(x, y); }


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

    cout << lcm(a, b) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int main(){
	string S;
	cin >> S;
	int n=0,w=0,s=0,e=0;
	for(int i=0;i<S.size();i++){
		if(S[i]=='N')n++;
		if(S[i]=='W')w++;
		if(S[i]=='S')s++;
		if(S[i]=='E')e++;
	}
	if((n>0&&s==0)||(s>0&&n==0)||(e>0&&w==0)||(w>0&&e==0))printf("No\n");
	else printf("Yes\n");
	return 0;
}

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

vector<int> G[200];
 
int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A[i];
    int a = 0;
    sort(A.begin(),A.end());
    long long sum = 0;
    rep(i,N-1){
        sum += A[i];
        if(2 * sum < A[i+1]){
            a = i+1;
        };
    }
    cout << N - a << endl;
 
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#define rep(i, n) for (int i = 0; i < (n); ++ i)
using namespace std;

int main()
{
  int n, k;
  cin >> n >> k;
  
  if (k >= n)
  {
    cout << 0;
    return 0;
  }
  
  vector<int> h(n);
  rep(i, n) cin >> h.at(i);
  
  sort(h.begin(), h.end(), greater<>{});
  
  int64_t sum = 0LL;
  rep(i, n)
  {
    if (i < k) continue;
    sum += h.at(i);
  }
  
  cout << sum;
  return 0;
}

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


#define ll long long
#define pb push_back

#define loop(i, a, b) for(int i = (a); i < (b); i++)
#define loopb(i, a, b) for(int i = (a); i > (b); --i)

typedef pair <int,int> ii;
typedef vector <int> vi;
typedef vector <ii> vii;
typedef vector <ll> vl;

const int mod = 1e9+7;
const ll inf = 2e18+5;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
  
    ll a,b;
    cin>>a>>b;
    if(a<=5) cout<<0<<endl;
    else if(a<=12) cout<<b/2<<endl;
    else cout<<b<<endl;
   
    return 0;
}   

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] L = new long[n+1];
		L[0] = 2;
		L[1] = 1;
		for (int i = 2; i <= n; i++) {
			L[i] = L[i - 1] + L[i - 2];
		}
		System.out.println(L[n]);
	}
}


Measured memory_bytes: 22100
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }

int edge[200000][2];

int qmem[400000];

int *e[100001];
int el[100001];

int prev[100001];

int s[100000];
int sl, sr;

int main(void){
	int n=nextint();
	int m=nextint();
	for(int i=0; i<m; i++){
		int A=nextint();
		int B=nextint();
		edge[i][0]=A;
		edge[i][1]=B;
		el[A]++;
		el[B]++;
	}
	int ne=0;
	for(int i=1; i<=n; i++){
		e[i]=&qmem[ne];
		ne+=el[i];
		el[i]=0;
	}
	for(int i=0; i<m; i++){
		int A=edge[i][0];
		int B=edge[i][1];
		e[A][el[A]++]=B;
		e[B][el[B]++]=A;
	}
	int k=0;
	prev[1]=1;
	s[sr++]=1;
	while(sl<sr){
		k++;
		int from = s[sl++];
		for(int i=0; i<el[from]; i++){
			int to = e[from][i];
			if(prev[to]==0){
				prev[to]=from;
				s[sr++]=to;
			}
		}
	}
	if(k==n){
		puts("Yes");
		for(int i=2; i<=n; i++){
			printf("%d\n", prev[i]);
		}
	}else{
		puts("No");
	}
}


Measured memory_bytes: 6624
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

bool query(int a, int b) {
    cout << "? " << a << ' ' << b << endl;
    string result;
    cin >> result;
    return result == "Y";
}

int main() {
    ios::sync_with_stdio(false);

    int A, B;
    cin >> A >> B;

    if (A <= B) {
        cout << "Impossible" << endl;
        return 0;
    }

    int N = A + B;
    vector<int> chain = {0};

    for (int i = 1; i < N; i++)
        if (chain.empty() || query(chain.back(), i))
            chain.push_back(i);
        else
            chain.pop_back();

    int honest = chain.back();
    string answer(N, '1');

    for (int i = 0; i < N; i++)
        if (i != honest)
            answer[i] = query(honest, i) ? '1' : '0';

    cout << "! " << answer << endl;
}


Measured memory_bytes: 724
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
 
public class Hello{
    public static void Main(){
        string[] input = ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int m = int.Parse(input[1]);
        int b = int.Parse(input[2]);
//        string temp = ReadLine();
//        int a = int.Parse(ReadLine());
        if(n+m-b<0){
            WriteLine("dangerous");
        }else if(m>=b){
            WriteLine("delicious");
        }else{
            WriteLine("safe");
        }
        
    }
}

Measured memory_bytes: 11092
// https://atcoder.jp/contests/arc089/tasks/arc089_a

#include "algorithm"
#include "cmath"
#include "functional"
#include "iostream"
#include "numeric"
#include "queue"
#include "set"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

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

  ll cur_t = 0;
  ll cur_x = 0;
  ll cur_y = 0;

  rep(i, N) {
    ll t, x, y;
    cin >> t >> x >> y;

    ll diff_t = t - cur_t;
    ll diff_p = abs(x - cur_x) + abs(y - cur_y);

    if (diff_p > diff_t) drop("No");
    if (diff_p % 2 != diff_t % 2) drop("No");

    cur_t = t;
    cur_x = x;
    cur_y = y;
  }

  cout << "Yes" << endl;
}

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

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

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

  return 0;
}
#endif

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

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

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

    cout << v[i];
  }

  cout << endl;
}

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


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

int main() {
	int n;
	cin >> n;
	set<int> a;
	rep(i, n) {
		int t;
		cin >> t;
		if(a.count(t)) {
			a.erase(t);
		} else {
			a.insert(t);
		}
	}
	cout << a.size() << endl;
	return 0;
}

Measured memory_bytes: 4864
#include <stdio.h>

#define MYSCAN scanf

char u[300][20];
int n;

int match(char t[20]);

int main(void){
	int i;
	int m;
	int mat;
	char t[20];
	int door = -1;

	MYSCAN("%d", &n);
	MYSCAN("\n");
	// テァツ卍サテゥツ個イIDテ」ツ?ョテ・ツ?・テ・ツ環?
	for (i = 0; i < n; i++){
		gets(u[i]);
	}

	MYSCAN("%d", &m);
	MYSCAN("\n");
	for (i = 0; i < m; i++){
		// テ」ツつォテ」ツδシテ」ツδ嘉」ツつ津」ツ?凝」ツ?姪」ツ??
		gets(t);
		mat = match(t);
		// テァツ卍サテゥツ個イテ」ツ?陛」ツつ古」ツ?ヲテ」ツ?ェテ」ツ?凝」ツ?」テ」ツ?淌」ツつ?
		if (mat == -1){
			printf("Unknown %s\n", t);
		}
		else{
			// テ」ツδ嘉」ツつ「テ」ツ?古ゥツ鳴嘉」ツ?セテ」ツ?」テ」ツ?ヲテ」ツ?淌」ツつ嘉」ツ?づ」ツ?妥」ツつ?
			if (door == -1){
				printf("Opened by %s\n", t);
			}
			// テゥツ鳴凝」ツ??」ツ?ヲテ」ツ?淌」ツつ嘉ゥツ鳴嘉」ツつ?」ツつ?
			else{
				printf("Closed by %s\n", t);
			}
			door *= -1;
		}
	}


	return 0;
}


// テヲツ鳴?・ツュツ療・ツ按療」ツ?古」ツ?づ」ツ?」テ」ツ?ヲテ」ツつ凝」ツ?凝」ツ?ゥテ」ツ??」ツ?凝」ツつ津・ツ按、テ・ツョツ堙」ツ?凖」ツつ凝ゥツ鳴「テヲツ閉ー
// テ・ツ青暗ィツ?エテ」ツ?凖」ツつ凝ヲツ鳴?・ツュツ療・ツ按療」ツ?古」ツ?ェテ」ツ?妥」ツつ古」ツ?ー-1テ」ツつ津ィツソツ氾」ツ??
int match(char t[20]){
	int i, j;

	for (i = 0; i < n; i++){
		for (j = 0; t[j] != '\0' && u[i][j] != '\0'; j++){
			if (t[j] != u[i][j]){ break; }
		}
		if (t[j] == '\0' && u[i][j] == '\0'){
			return i;
		}
	}
	return -1;
}

Measured memory_bytes: 1032
#include <stdio.h>
#define N 100
#define inf 10000000
#define NIL -1
#define BLACK 1
#define WHITE 0

int n,k,d[N],pi[N],G[N][N],color[N];

void initializeSingleSouurse(int);
void dijkstra(int);
int main(){
  int i,j,k,u,v,c;

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j]=0;
    }
  }
  
  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      G[i][v]=c;
    }
  }
  //printf("test\n");
  dijkstra(0);
  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }
  return 0;
}

void initializeSingleSouurse(int s){
  int i,j;

  for(i=0;i<n;i++){
    d[i]=inf;
    pi[i]=NIL;
    color[i]=WHITE;
  }
  d[s]=0;
}
    
void dijkstra(int s){
  int u,mincost,v,i;
  
  initializeSingleSouurse(s);
  while(1){
    mincost=inf;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
    if(mincost==inf) break;

    color[u]=BLACK;
    for(v=0;v<n;v++){
      if(G[u][v]==0) continue;
      if(color[v]!=BLACK && d[u]+G[u][v]<d[v]){
	pi[v]=u;
	d[v]=d[u]+G[u][v];
      }
    }
  }
}
    
    



Measured memory_bytes: 1996
from itertools import permutations
import sys
input = sys.stdin.readline

def main():
    N, M, RR = map(int, input().split())
    R = list(map(int, input().split()))
    INF = float("inf")
    T = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = tuple(map(int, input().split()))
        T[a-1][b-1] = c
        T[b-1][a-1] = c
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if T[i][j] > T[i][k]+T[k][j]:
                    T[i][j] = T[i][k]+T[k][j]
    print(min(sum(T[rs[i]-1][rs[i+1]-1] for i in range(RR-1)) for rs in permutations(R)))

if __name__ == "__main__":
    main()

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

#define N 300010 

using namespace std;

int head[N], to[N << 1], nxt[N << 1], tot;

int dep[N], sz[N];

typedef long long ll;

struct Node {
    ll num;
    int id;
}a[N];

inline bool cmp(const Node &a, const Node &b) {
    return a.num > b.num;
}

char *p1, *p2, buf[100000];

#define nc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1 ++ )

ll rd() {
    ll x = 0;
    char c = nc();
    while (c < 48) {
        c = nc();
    }
    while (c > 47) {
        x = (((x << 2) + x) << 1) + (c ^ 48), c = nc();
    }
    return x;
}

inline void add(int x, int y) {
    to[ ++ tot] = y;
    nxt[tot] = head[x];
    head[x] = tot;
}

void dfs(int p, int fa) {
    dep[p] = dep[fa] + 1;
    for(int i = head[p]; i; i = nxt[i]) {
        if (to[i] != fa) {
            dfs(to[i], p);
        }
    }
}

map <ll, int> MP;

map <ll, int> :: iterator it;

int u[N], v[N];

int main() {
    int n = rd();
    for (int i = 1; i <= n; i ++ ) {
        a[i].num = rd();
        MP[a[i].num] = i;
        a[i].id = i;
    }
    sort(a + 1, a + n + 1, cmp);

    for (int i = 1; i < n; i ++ ) {
        int x = a[i].id;
        it = MP.find(a[i].num - n + 2 + (sz[x] << 1));
        if (it == MP.end()) {
            puts("-1");
            return 0;
        }
        int y = it -> second;
        sz[y] += sz[x] + 1;
        add(x, y);
        add(y, x);
        u[i] = x;
        v[i] = y;
    }
    // puts("Fuck");
    dep[a[n].id] = -1;
    dfs(a[n].id, a[n].id);
    ll all = 0;
    for (int i = 1; i <= n; i ++ ) {
        all += dep[i];
    }
    if (all != a[n].num) {
        puts("-1");
        return 0;
    }
    for (int i = 1; i < n; i ++ ) {
        printf("%d %d\n", u[i], v[i]);
    }
    return 0;
}

Measured memory_bytes: 20480
import collections

N=int(input())
A=list(map(int, input().split()))
Q=int(input())
countA=collections.Counter(A)
ans=sum(A)

for i in range(Q):
    B,C=map(int, input().split())
    b=countA[B]
    ans=ans+(C-B)*b
    print(ans)
    countA[B]=0
    countA[C]+=b



Measured memory_bytes: 24012
#include "bits/stdc++.h"
using namespace std;

int main(int argc, char **argv) {
  int i, N, Wi;
  long leftsum = 0, rightsum = 0;

  cin >> N;
  vector<int> W(N);

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

  int ans = INT_MAX;
  for (int i = 0; i < N; i++) {
    int tmpans = 0;
    int j;

    for (j = 0; j < i; j++) {
      tmpans += W[j];
    }

    for (; j < N; j++) {
      tmpans -= W[j];
    }

    ans = min(ans, abs(tmpans));
  }

  cout << ans << endl;
  return 0;
}


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

#define REP(i,n) for(decltype(n) i=0; i<(n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define st first
#define nd second
#define pb push_back

typedef pair<int,int> pii;
typedef vector<int> vi;

void solve(){
    int r,g;
    cin>>r>>g;
    cout<<2*g-r<<'\n';
}

int main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

  long n;
  scanf("%ld", &n);
  long fraction[2];
  long k;
  for (long i = 1; i <= 3500; i++) {
    for (long j = 1; j <= 3500; j++) {
      fraction[0] = i+j;
      fraction[1] = i*j;
      if (4*fraction[1]-n*fraction[0] != 0 && n*fraction[1]%(4*fraction[1]-n*fraction[0]) == 0) {
        k = n*fraction[1]/(4*fraction[1]-n*fraction[0]);
        if (k <= 0) {
          continue;
        }
        printf("%ld %ld %ld\n", i, j, k);
        return 0;
      }
    }
  }

  return 0;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N, M; cin >> N >> M;
        vector<ll> A(N); cin >> A;
        priority_queue<int> que;
        rep(i, N) que.push(A[i]);

        rep(i, M) {
            int a = que.top(); que.pop();
            que.push(a / 2);
        }
        ll ans = 0;
        while(que.size()) {
            ans += que.top(); que.pop();
        }
        cout << ans << endl;

        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
//O(S^2)はまにあわないな
//1マスずつ、最終地点をみつけていけばはやいか
//R L R R R L L
//1 -13 2 1 -1-2
int main(){
  string S; cin>>S;
  ll ssz=S.size();
  vector<ll> A(ssz,0), ans(ssz,0);
//Lうめ
  ll tmp=0;
  for(int i=0; i<ssz; i++){
    if(S[i]=='R') tmp=0;
    else{
      --tmp;
      A[i]=tmp;
    }
  }
//Rume
  tmp=0;
  for(int i=ssz-1; i>=0; i--){
    if(S[i]=='L') tmp=0;
    else{
      ++tmp;
      A[i]=tmp;
    }
  }
  for(int i=0; i<ssz; i++){
    if(abs(A[i])%2==1)
      ans[i+A[i]+A[i+A[i]]]++;
    else
      ans[i+A[i]]++;
  }
  for(int i=0; i<ssz; i++){
    cout<<ans[i];
    if(i<ssz-1)
      cout<<" ";
  }
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define pii pair<int,int>
#define fi first 
#define se second 
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define pb push_back
#define faster ios_base::sync_with_stdio(0);cin.tie(0);
#define mem(a,v) memset(a,v,sizeof(a))
const ll INF=1e18;
const int mod=1e9+7;
const int iinf=1e9+10;
const int xd[4]={1,0,-1,0},yd[4]={0,1,0,-1};
ll pp(ll a,ll n){
	ll res=1;
	while(n){
		if(n&1)
			res=(res*a)%mod;
		a=a*a%mod;
		n/=2;
	}
	return res;
}
int main()
{
	faster
	ll n;
	cin>>n;
	ll y=(pp(9,n)*2%mod-pp(8,n)%mod)%mod;
	ll x=pp(10,n)%mod;
	if(x-y<0){
		cout<<mod+(x-y);
	}
	else
	cout<<(x-y)%mod;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int a[33]={0,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
    int n;
    cin>>n;
    cout<<a[n]<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
	import sys
	from operator import itemgetter
	input = sys.stdin.readline
	N = int(input())
	AB = [list(map(int, input().split())) for _ in range(N)]
	AB.sort(key=itemgetter(1,0))
	sum = 0
	for i in range(N):
		sum += AB[i][0]
		if sum > AB[i][1]:
			print('No')
			sys.exit()
	print('Yes')


if __name__ == '__main__':
    main()

Measured memory_bytes: 66352
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n,k;
  cin>>n>>k;
  vector<ll> v;
  for(int i=0;i<n;i++){
    ll x;
    cin>>x;
    if(x==0) k--;
    else v.push_back(x);
  }
  if(k<=0){
    cout<<0<<endl;
    return 0;
  }

  ll ans=1e18;
  for(int i=0;i+k-1<v.size();i++){
    if(v[i]*v[i+k-1]<0ll){
      ans=min(ans,min(abs(v[i])*2+v[i+k-1],abs(v[i])+v[i+k-1]*2));
    }else{
      ans=min(ans,max(abs(v[i]),abs(v[i+k-1])));
    }
  }
  cout<<ans<<endl;

  return 0;
}


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

int main() {    
    /* Input */
    long long int N, M, K;
    cin >> N >> M >> K;
    
    vector<long long int> A(N);
    vector<long long int> B(M);
    rep (i, N) {
        cin >> A.at(i);
    }
    rep (i, M) {
        cin >> B.at(i);
    }

    /* Main Logic */
    vector<long long int> sumA(N+1);
    vector<long long int> sumB(M+1);
    rep (i, N+1) {
        if (i == 0) sumA.at(i) = 0;
        else sumA.at(i) = sumA.at(i-1) + A.at(i-1);
    }
    rep (i, M+1) {
        if (i == 0) sumB.at(i) = 0;
        else sumB.at(i) = sumB.at(i-1) + B.at(i-1);
    }

    int ans = 0;
    int j = M;
    for (int i = 0; i < N + 1; i++) {
        if (sumA.at(i) > K) break;
        while ( sumB.at(j) > K - sumA.at(i) ) {
            j--;
        }
        ans = max(ans, i + j);
    }

    /* Output */
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9532
#include<stdio.h>
#define m 200000
int main()
{
    int a[m],i,n,sum1=0,sum2=0,sum3=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%4==0)
            sum1++;
        if(a[i]%2==0)
            sum2++;
    }
    sum3=n-sum2;
    if(n<=3&&sum1>=1)printf("Yes");
    else if(sum2==n||((sum1>=sum3-1)&&sum2-sum1==0))printf("Yes");
    else if(sum2==n||sum1>=sum3)printf("Yes");
    else printf("No");
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;
#define ll long long
#define pb push_back

int main() {
  int n,k,m;
  cin >> n;
  vector<int> d(n);
  for(int i=0;i<n;i++){
      cin >> d.at(i);
  }
  sort(d.begin(),d.end());
  m = n/2;
  k = d.at(m) - d.at(m-1);
  
  cout << k << endl;

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long
int main()
{
  int n;
  cin>>n;
  vector<pair<int,int> >v(n);
  for(int i=0;i<n;i++)
    cin>>v[i].first>>v[i].second;
  vector<int>vf[2];
  for(int i=0;i<n;i++)
  {
    vf[0].push_back(v[i].first + v[i].second);
    vf[1].push_back(v[i].first - v[i].second);
  }
  sort(vf[0].begin(),vf[0].end());
  sort(vf[1].begin(),vf[1].end());
  
  int maxi = INT_MIN;
  maxi = max(maxi,vf[0][0]-vf[0][n-1]);
  maxi = max(maxi,-(vf[0][0]-vf[0][n-1]));
  maxi = max(maxi,-(vf[1][0]-vf[1][n-1]));
  maxi = max(maxi,(vf[1][0]-vf[1][n-1]));
  cout<<maxi<<endl;
  return 0;
}
  
    

Measured memory_bytes: 6636
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
int cnt_2(int x)
{
    int cnt = 0;
    while (x % 2 == 0)
    {
        cnt++;
        x /= 2;
    }
    return cnt;
}

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

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) a[i] /= 2;
    int num = a[0];
    Rep(i, 1, n) num = (num * a[i]) / gcd(num, a[i]);
    int cnt = cnt_2(a[0]);
    rep(i, n) if (cnt != cnt_2(a[i]))
    {
        cout << 0 << endl;
        return 0;
    }
    cout << m / num - (m / num) / 2 << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
//#include <string.h>

int main() {
    int n;

    scanf("%d\n", &n);

    char suits[n];
    char shouldBeSuits[52];
    int ranks[n];
    int shouldBeRanks[52];

    for (int i = 0; i < n; ++i) {
        if (i == n - 1)
            scanf("%c %d", &suits[i], &ranks[i]);
        else
            scanf("%c %d\n", &suits[i], &ranks[i]);
    }

    for (int j = 0; j < 52; ++j) {
        if (j / 13 == 0)
            shouldBeSuits[j] = 'S';
        else if (j / 13 == 1)
            shouldBeSuits[j] = 'H';
        else if (j / 13 == 2)
            shouldBeSuits[j] = 'C';
        else
            shouldBeSuits[j] = 'D';

        shouldBeRanks[j] = (j % 13) + 1;
    }


    for (int k = 0; k < 52; ++k) {
        for (int i = 0; i < n; ++i) {
            if(shouldBeSuits[k] == suits[i] && shouldBeRanks[k] == ranks[i]) {
                shouldBeSuits[k] = 'A';
                break;
            }
        }
    }

    for (int l = 0; l < 52; ++l) {
        if (shouldBeSuits[l] != 'A')
            printf("%c %d\n", shouldBeSuits[l], shouldBeRanks[l]);
    }

    return 0;
}


Measured memory_bytes: 2072
/*
 * @Author: BilyHurington
 * @Date: 2020-03-22 20:07:43
 * @LastEditors: BilyHurington
 * @LastEditTime: 2020-03-22 20:08:38
 */
#include<bits/stdc++.h>
using namespace std;
int n,m;
int main(){
    scanf("%d %d",&n,&m);
    printf("%d",n*(n-1)/2+m*(m-1)/2);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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 INF = 1e9;
const ll MOD = 1e9 + 7;


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

    deque<char> que;
    rep(i, s.size()) que.push_back(s[i]);

    bool r = false;
    int q;
    cin >> q;
    rep(i, q){
        int t;
        cin >> t;
        if(t == 1){
            if(r) r = false;
            else r = true;
        }
        if(t == 2){
            int f;
            cin >> f;
            char c;
            cin >> c;
            if(r == true && f == 1) que.push_back(c);
            if(r == true && f == 2) que.push_front(c);
            if(r == false && f == 1) que.push_front(c);
            if(r == false && f == 2) que.push_back(c);
        }
    }

    if(r){
        while(que.size() != 0){
            cout << que.back();
            que.pop_back();
        }
    }
    else {
        while(que.size() != 0){
            cout << que.front();
            que.pop_front();
        }
    }
    cout << endl;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
    using namespace std;
    
    //                                 (POLICY BASED DS)
    // #include <ext/pb_ds/assoc_container.hpp>
    // #include <ext/pb_ds/tree_policy.hpp>
    // using namespace __gnu_pbds;
    // template<typename T>
    // using ordered_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
    // template<typename T>
    // using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
    //                      ( find_by_order( )  ,  order_of_key( ) )
    
    typedef long long ll;
    typedef long double ld;
    typedef unsigned long long ull;
    typedef vector<int> vi;
    typedef vector<long long> vll;
    typedef pair<ll,ll> pll;
     
    const ll mod = 1e9 + 7;
    const ld PI = 3.1415926535897932384626;
    const ld eps = 1e-9;                            
     
    #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define sidha(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
    #define ulta(i,a,b) for(ll i=(ll)(a);i>=(ll)(b);--i)
    #define stl(container,itr) \
        for(auto itr = container.begin(); itr != container.end(); itr++)
    #define sab(v) v.begin(), v.end()
    #define rall(v) v.rbegin(), v.rend()            
    #define test ll t;cin>>t;while(t--)
    #define sz size()
    #define pb push_back
    #define mp make_pair
    #define fi first
    #define se second
    #define LOG2(X) (63ll - __builtin_clzll(X))
    #define endl '\n'
    #define modinv(x) power(x, mod-2)
    #define ncr(n,r) ( n >= r ? ((((fact[n]*modinv(fact[r]))%mod)*modinv(fact[n-r]))%mod) : (ll)0)
    #define MAX 100005
     
    ll power(ll x, ll y) { 
        ll ans=1;
        x=x%mod;
        while(y>0) { 
            if (y&1) 
                ans=(ans*x)%mod; 
            y=y>>1;
            x=(x*x)%mod; 
        } 
        return ans; 
    }
    
    vector<ll> adj[MAX];
    ll vst[MAX];
    void dfs(ll node){
        vst[node]=1;
        for(auto i : adj[node]){
            if(!vst[i]) dfs(i);
        }
    }
    
    // ll spf[MAX];
    // void sieve(){
    //     sidha(i,1,MAX)  spf[i]=i;
    //     for(ll i=4;i<MAX;i+=2)  spf[i]=2;
    //     for(ll i=3;i*i<=MAX;i++){
    //         if(spf[i]==i){
    //             for(ll j=i*i;j<MAX;j+=i){
    //                 if(spf[j]==j)   spf[j]=i;
    //             }
    //         }
    //     }
    // }

    int main()
    {
        boost;
        ll n,m,a,b,ans=0;
        cin>>n>>m;;
        sidha(i,0,m){
            cin>>a>>b;
            adj[a].pb(b);
            adj[b].pb(a);
        }
        memset(vst,0,sizeof(vst));
        sidha(i,1,n+1){
            if(!vst[i]){
                ans++;
                dfs(i);
            }
        }
        cout<<ans-1;
        return 0;
    }
    

Measured memory_bytes: 11112
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(long long i=0;i<(n);++i)
#define Fr(i,n) for(long long i=1;i<=(n);++i)
#define ifr(i,n) for(long long i=(n)-1;i>=0;--i)
#define iFr(i,n) for(long long i=(n);i>0;--i)

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll x,y,z,a,l,ll;
  cin>>y>>x;
  l=100000;
  ll=-1000000;
  z=max(ll,x-y+1);
  a=min(l,x+y-1);
  fr(i,a-z+1){
    cout<<z+i<<" ";
  }
}

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


void shift(vector<int> A){
    int t = 0;
    while (true){
        for (int i = 0; i < A.size(); i++){
            if (A[i] % 2 == 0){
                A[i] /= 2;
            } else {
                cout << t << endl;
                return;
            }
        }
        t++;
    }
}

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


Measured memory_bytes: 256
S=input()

ans=0
for i in range(2**(len(S)-1)):
    num=[]
    Binary=bin(i)[2:].zfill(len(S)-1)
    for j in range(len(S)):
        s=int(S[j])
        if j==0:
            num.append(s)
        else:
            if Binary[j-1]=="0":
                tmp=num.pop()*10
                num.append(tmp+s)
            else:
                num.append(s)
    ans+=sum(num)

print(ans)

Measured memory_bytes: 3064
# Problem E - Red and Green Apples

from collections import deque

# input
X, Y, A, B, C = map(int, input().split())
red_apples = sorted(list(map(int, input().split())), reverse=True)
green_apples = sorted(list(map(int, input().split())), reverse=True)
mushoku_apples = sorted(list(map(int, input().split())), reverse=True)

# initialization
red_apples = red_apples[:X]
green_apples = green_apples[:Y]
ans_list = deque([])
for r in red_apples:
    ans_list.append(r)
for g in green_apples:
    ans_list.append(g)
for m in mushoku_apples:
    ans_list.append(m)
ans_list = sorted(ans_list, reverse=True)

# output
i = X+Y
ans = sum(ans_list[:i])
print(ans)


Measured memory_bytes: 111340
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
using namespace std;
typedef long long ll;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define FOREACH(i,Itr) for(auto (i)=(Itr).begin();(i)!=(Itr).end();(i)++)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))


int main(){
    
    ll N,x; cin>>N>>x;
    vector<ll> a(N);
    REP(i,N)cin>>a[i];
    vector<ll> b=a;
    
    ll anst=0;
    REP(i,N){
        if(a[i]>x){
            anst+=a[i]-x;
            a[i]=x;
        }
        if(b[i]>x){
            b[i]=x;
        }
    }
    
    ll ans1=anst;
    REP(i,N-1){
        ll sum=a[i]+a[i+1];
        if(sum>x){
            a[i+1]-=sum-x;
            ans1+=sum-x;
        }
    }
    
    ll ans2=anst;
    reverse(b.begin(),b.end());
    REP(i,N-1){
        ll sum=b[i]+b[i+1];
        if(sum>x){
            b[i+1]-=sum-x;
            ans2+=sum-x;
        }
    }
    
    cout<<min(ans1,ans2)<<endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
#define MAXSIZE 200
#define MAXL 100
typedef long long int lli;

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

    int k[a];
    int x[a][b];
    int found[a][b + 1] = {};
    for(int i = 0; i < a; i++){
        cin >> k[i];
        for(int j = 0; j < k[i]; j++){
            cin >> x[i][j];
            if(!found[i][x[i][j]]){
                found[i][x[i][j]] = 1;
            }
        }
    }

    int ans = 0, add_flag;
    for(int column = 1; column < b + 1; column++){
        add_flag = 1;
        for(int i = 0; i < a; i++){
            if(found[i][column] == 0){
                add_flag = 0;
                break;
            }
        }
        ans += (add_flag);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, count = 1, judge = 0; cin >> N;
  ll A; cin >> A;
  for(int i = 0; i < N - 1; i++) {
    ll a; cin >> a;
    if(A == a) continue;
    if(judge) {
      if(judge * (A - a) > 0) {
        count++;
        judge = 0;
      }
      A = a;
    } else {
      judge = ((a > A) ? 1 : -1);
      A = a;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
	int H, W; cin >> H >> W;
	int U = 0;
	vector<vector<char>> vec(H, vector<char>(W));
	for (int X = 0; X < H; X++) {
		for (int Y = 0; Y < W; Y++) {
			cin >> vec[X][Y];
			if (vec[X][Y] == '#') {
				U++;
			}
		}
	}
	if (U == H + W - 1) {
		cout << "Possible" << endl;
	}
	else {
		cout << "Impossible" << endl;
	}
}

Measured memory_bytes: 3596
#include <stdio.h>
int main(){
	int a,b,c,s;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
	s=b;
	b=a;
	a=s;
	}
	if(a>c){
		s=c;
		c=a;
		a=s;
	}
	if(b>c){
		s=c;
		c=b;
		b=s;
	}
	printf("%d %d %d\n",a, b, c);
}
	
	

Measured memory_bytes: 1852
(* O(1) *)
let get_wait_time cook_time = let m = cook_time mod 10 in if m = 0 then 0 else 10 - m
let get_next_time cook_time = cook_time + get_wait_time cook_time

(* O(|dishes|) *)
let solve dishes =
  let max_wait = List.map get_wait_time dishes |> List.fold_left max 0 in
  let sum = List.map get_next_time dishes |> List.fold_left (+) 0 in
  sum - max_wait

let read_int_array n = Array.init n (fun _ -> read_int ())
let read_ints n = read_int_array n |> Array.to_list

let _ = read_ints 5 |> solve |> string_of_int |> print_endline

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

int main() {
  long long X,K,D;
  cin >> X >> K >> D;
  long long ans;
  X=abs(X);
    if(X/D>=K) ans=X-K*D;
    else if((X/D-K)%2==0) ans=X%D;
    else ans=D-X%D;

  cout << ans << endl;

  return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

vll G[55];

bool visited[55];
ll x,y;
void dfs(ll v, ll p){
  for(auto nv: G[v]){
    if(v==x&&nv==y || v==y&&nv==x) continue;
    if(nv==p) continue;
    if(visited[nv]) continue;
    visited[nv]=1;
    dfs(nv,p);
  }
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,m; cin>>n>>m;
  vpll xy(m);
  rep(i,m){
    ll a,b; cin>>a>>b; a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
    xy[i]={a,b};
  }
  
  ll ans=0;
  rep(i,m){
    rep(j,n) visited[j]=0;
    x=xy[i].first, y=xy[i].second;
    dfs(0,-1);
    rep(j,n) if(visited[j]==0) {ans++; break;}
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3600
import sys
N, M = map(int, sys.stdin.readline().split())
lst = []
for i in range(M):
    a, b = map(int, sys.stdin.readline().split())
    lst.append((a, 1, i))
    lst.append((b, 0, i))
lst.sort()
open_set = set()
cnt = 0
for pos, t, idx in lst:
    if t == 0:
        if idx in open_set:
            cnt += 1
            open_set = set()
    else:
        open_set.add(idx)
print(cnt)


Measured memory_bytes: 31152
/**
 *    author:  tourist
 *    created: 27.01.2020 05:40:27       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long inner = 0;
  for (int i = 0; i < k; i++) {
    inner += a[i];
  }
  long long outer = 0;
  for (int i = k; i < n; i++) {
    outer += max(a[i], 0);
  }
  long long ans = max(inner, 0LL) + outer;
  for (int i = k; i < n; i++) {
    inner += a[i] - a[i - k];
    outer += max(a[i - k], 0) - max(a[i], 0);
    ans = max(ans, max(inner, 0LL) + outer);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
 	int a , b, c , d ; 
  cin >> a >> b >> c >> d ;
  if(a+b > c+d)cout << "Left" ; 
  else if(a+b == c+d)cout << "Balanced" ; 
  else cout << "Right" ; 
}

Measured memory_bytes: 3592
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let n=read::<i32>();
    let k=read::<i32>();
    let mut a=(0..n).map(|_|read::<i32>()).collect::<Vec<i32>>();
    a.sort();
    let mut ans=0;
    for i in 0..k{
        ans+=a[(n-i-1)as usize];
    }
    println!("{}",ans)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    ll n; ll k;
    cin >> n >> k;
    vector<ll> ap,an;
    rep(i,n){
        ll a; cin >> a;
        if(a>=0) ap.push_back(a);
        else an.push_back(a);
    }
    ll l,r;
    l=-1000000000000000001;
    r=1000000000000000001;
    ll pairs=(n*(n-1))/2;
    ll pl=ap.size();
    ll nl=an.size();
    ll ppairs=((pl*(pl-1))/2)+((nl*(nl-1))/2);

    sort(all(ap));
    sort(all(an));
    vector<ll> an2=an;
    reverse(all(an2));

    while(l+1<r){
        //cout << l << ' ' << r << endl;
        ll c = (r+l)/2;
        ll num=0;
        if(c>=0){
            rep(i,pl){
                ll f=ap[i];
                //if(f==0) continue;
                ll R,L;
                L=-1;
                R=pl;
                while(L+1<R){
                    ll C = (R+L)/2;
                    if(ap[C]*f>c) R=C;
                    else L=C;
                }
                num+=pl-R;
                if(f*f>c) num--;
            }
            rep(i,nl){
                ll f=an2[i];
                ll R,L;
                L=-1;
                R=nl;
                while(L+1<R){
                    ll C = (R+L)/2;
                    if(an2[C]*f>c) R=C;
                    else L=C;
                }
                num+=nl-R;
                if(f*f>c) num--;
            }
            num/=2;
        }
        else{
            rep(i,pl){
                ll f=ap[i];
                ll R,L;
                L=-1;
                R=nl;
                while(L+1<R){
                    ll C = (R+L)/2;
                    if(an[C]*f>c) R=C;
                    else L=C;
                }
                num+=nl-R;
            }
            num+=ppairs;
        }
        //cout << num << endl;
        //if(l<0){
            if(pairs-num<k) l=c;
            else r=c;
        /*}
        else{
            if(pairs-num<k) l=c+1;
            else r=c;
        }*/
    }
    cout << r << endl;

return 0;
}

Measured memory_bytes: 6264
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

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

    string s = "CODEFESTIVAL2016";
    string st;
    cin >> st;
    int ans = 0;
    REP(i, 16) if(s[i] != st[i]) ans++;
    cout << ans << "\n";
    return 0;
}

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

int main() {
  
  int a, b, mod, result;
  double ave;
  int c;
  
  cin >> a >> b;
  
  ave = (a + b) / 2.0;
  c = (int)(ave * 10);
  if((c % 10) > 4) {
     result = ((a + b) / 2) + 1;
  } else {
     result =  ((a + b) / 2);
  }
  
  cout << result << endl;
  
  return 0;
}

Measured memory_bytes: 256
N,M = tuple(map(int,input().split()))
# matchlist = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]
#最大のグループの大きさを出す
friendlist = list(range(N))
# [所属先,[所属メンバー]]
gplist = [[i] for i in range(N)]

def getgroup(a):
    A = friendlist[a]
    if A == a:
        return a
    else:
        return getgroup(A)

def match(ab):
    A = getgroup(ab[0])
    B = getgroup(ab[1])
    if A==B:
        return
    elif len(gplist[A])<len(gplist[B]):
        gplist[B].extend(gplist[A])
        friendlist[A] = B
    else:
        gplist[A].extend(gplist[B])
        friendlist[B] = A

for i in range(M):
    # print(friendlist)
    # print(gplist)
    match(tuple(map(lambda x:int(x)-1,input().split())))

# print(friendlist)
# print(gplist)

print(max([len(item) for item in gplist]))

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

int main(){ 
  int N;
  vector<int> X(100);
 
  cin >> N;
  for(int i=0; i<N; i++) cin >> X[i];
 
  int ans = 1e7;
  for(int P=1; P<=100; P++){
    int HP = 0;
    for(int i=0; i<N; i++){
      HP += (X[i]-P)*(X[i]-P);
    }
    ans = min(ans, HP);
  }
 
  cout << ans << endl;
}

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

int n, h;
#define maxn 100000
class sword {
public:
	//挥动攻击力
	int a;
	//投掷攻击力
	int b;
	bool operator<(sword& as) {
		return b < as.b;
	}

}s[maxn+5];

int maxa;
int main() {
	maxa = 0;
	int dmg=0;
	int att=0;
	cin>>n>>h;
	for (int i = 0; i < n; ++i) {
		cin>>s[i].a>>s[i].b;
		
	}

	//按投掷攻击力的大小排序（重载<运算符）
	sort(s, s + n);

	//找到挥动攻击力最大的那把
	for (int i = 0; i < n; ++i) {
		maxa = s[maxa].a < s[i].a ? i : maxa;
	}
	//把投掷攻击力大于最大挥动攻击力的剑从大到小依次扔出去
	for (int i = n - 1; dmg < h&&s[i].b> s[maxa].a;--i) {
		if (i == maxa)continue;//不能把最大挥动攻击的剑扔了
		dmg += s[i].b; ++att;
	}

	//投掷攻击力更大的剑都扔出去了，剩下的伤害用最大挥动攻击的剑完成
	if (dmg < h) {
		if (s[maxa].a > s[maxa].b) {//挥动攻击力比投掷攻击力高，最后一下仍是挥动攻击
			att +=  (h - dmg) / s[maxa].a;
			//向上取整
			if ((h - dmg) % s[maxa].a != 0) 
				++att;
			
		}
		else {//挥动攻击力比投掷攻击力低，最后一下可以投掷攻击
			//提前把投掷攻击的伤害算上
			att += 1; dmg += s[maxa].b;
			if (dmg < h) {
				att += (h - dmg) / s[maxa].a;
				//向上取整
				if ((h - dmg) % s[maxa].a != 0) 
					++att;
				
			}
		}
	}
	cout << att;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  
  vector<int> d(N);
  
  for(int i = 0;i < N;i++) {
    cin >> d.at(i);     
  }
  
  int answer = N;
  
  for(int i = 0;i < N;i++) {
    for(int j = i + 1;j < N;j++) {
     if(d.at(i) == d.at(j) && d.at(j) != 0) {
       answer--;
       d.at(j) = 0;
     }
    }
  }
  
  cout << answer << endl;
}

Measured memory_bytes: 256
N = int(input())
a = list(map(int, input().split()))

min_diff = float('inf')
a_sum = sum(a)
l_sum = 0

for i in range(N - 1):
  l_sum += a[i]
  min_diff = min(min_diff, abs(l_sum * 2 - a_sum))

print(min_diff)


Measured memory_bytes: 24832
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    string s[3];
    for (int i = 0; i < 3; i++) {
        cin >> s[i];
    }

    int r = 0;
    for (int j = 0; j < n; j++) {
        if (s[0][j] == s[1][j] || s[1][j] == s[2][j] || s[2][j] == s[0][j]) {
            if (s[0][j] == s[1][j] && s[1][j] == s[2][j]) r += 0; else r += 1;
        } else {
            r += 2;
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
#define endl "\n"

using namespace std;

//ll const N = 32000;

int main()
{
    int x;
    cin >> x;
    
    if(x >= 400 && x <= 599)cout << 8;
    if(x >= 600 && x <= 799)cout << 7;
    if(x >= 800 && x <= 999)cout << 6;
    if(x >= 1000 && x <= 1199)cout << 5;
    if(x >= 1200 && x <= 1399)cout << 4;
    if(x >= 1400 && x <= 1599)cout << 3;
    if(x >= 1600 && x <= 1799)cout << 2;
    if(x >= 1800 && x <= 1999)cout << 1;
    
    return 0;
}


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

namespace _20180307_AOJ
{
    class ALDS1_6B
    {
        static void Main(string[] args)
        {
            for (;;)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                int n = int.Parse(line);
                int[] A = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                int p = Partition(A, 0, n - 1);
                Console.Write(string.Join(" ", A.Take(p).Select(x=>x.ToString()).ToArray()));
                Console.Write(string.Format(" [{0}] ", A[p]));
                Console.WriteLine(string.Join(" ", A.Skip(p + 1).Select(x => x.ToString()).ToArray()));
            }
        }

        static int Partition(int[] A, int p, int r)
        {
            int x = A[r];
            int i = p - 1;
            int t;
            for (int j=p; j<r;j++)
            {
                if(A[j] <= x)
                {
                    i++;
                    t = A[i];
                    A[i] = A[j];
                    A[j] = t;
                }
            }

            i++;
            t = A[i];
            A[i] = A[r];
            A[r] = t;

            return i;
        }
    }
}



Measured memory_bytes: 19244