akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;
    vector<int> A(N + 2, 0);

    int ans = 0;
    
    rep(i, N) {
        cin >> A[i + 1];
        ans += abs(A[i] - A[i + 1]);
    }
    ans += abs(A[N] - A[N + 1]);
    rep(i, N) {
        if (A[i] < A[i + 1] && A[i + 1] > A[i + 2]) {
            int minus = min(A[i + 1] - A[i], A[i + 1] - A[i + 2]);
            cout << ans - minus * 2 << endl;
        }
        else if (A[i] > A[i + 1] && A[i + 1] < A[i + 2]) {
            int minus = min(A[i] - A[i + 1], A[i + 2] - A[i + 1]);
            cout << ans - minus * 2 << endl;
        }
        else {
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1664
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc130/tasks/abc130_c>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll W,H,x,y; cin >>  W >> H >> x >> y;
    
    cout << fixed << setprecision(12) << W*H/2.0 << " ";
    if(2*x == W && 2*y == H) cout << "1" << endl;
    else cout << "0" << endl;
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    // cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


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

#define rep(i,n) for(int i = 0;i<n;i++)
#define vv(Type,Name, n,m,d)vector<vector<Type>> vv(n, vector<Type>(m, d));

using namespace std;
using ll = long long;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll 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 { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a; }
};
istream& operator>>(istream & is, mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }



int main(void) {

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

	int n; cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(), a.end());
    vector<mint> two(n + 1);
    two[0] = 1;
    rep(i, n) two[i + 1] = two[i] * 2;

    mint ans;
    rep(i, n) {
        int l = i, r = n - 1 - i;
        mint now = two[r];
        if (r != 0) now += two[r - 1] * r;
        now *= two[l];
        now *= a[i];
        ans += now;
    }

    ans *= two[n];

    cout << ans.x << endl;

	return 0;
}


Measured memory_bytes: 5544
while True:
    try:
        dax,bx = [],[]
        m = int(raw_input())
        a = sorted([list(map(int, raw_input().split())) for i in range(m)])
        for i in range(m):
            dax.append(a[i][0]-a[0][0])
        n = int(raw_input())
        b = sorted([list(map(int, raw_input().split())) for i in range(n)])
        for i in b:
            bx.append(i[0])
        for i in range(n-m+1):
            for j in range(m):
                if bx.count(bx[i]+dax[j]) == 0:
                    break
            else:
                print b[i][0]-a[0][0],b[i][1]-a[0][1]
                break
    except:
        break

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#define N 15
#define M 1005
#define INF 1e9
int n,m,c,tp,ans,mn=INF,st[N],cnt[N],tmp[N];char a[N][M];
int main()
{
	scanf("%d %d %d",&n,&m,&c);for(int i=1;i<=n;++i) scanf("%s",a[i]+1);
	for(int i=0;i<(1<<n-1);++i)
	{
		tp=0;for(int j=1;j<n;++j) if(i&(1<<j-1)) st[++tp]=j;ans=tp;st[++tp]=n;
		for(int j=1;j<=tp;++j) cnt[j]=0;
		for(int j=1;j<=m;++j)
		{
			for(int k=1;k<=tp;++k) {tmp[k]=cnt[k];for(int l=st[k-1]+1;l<=st[k];++l) cnt[k]+=a[l][j]-'0';}
			for(int k=1;k<=tp;++k) if(cnt[k]>c) {++ans;for(int l=1;l<=tp;++l) cnt[l]-=tmp[l];break;}
			for(int k=1;k<=tp;++k) if(cnt[k]>c) {ans=INF;break;}if(ans>=INF) break;
		}mn=min(mn,ans);
	}printf("%d\n",mn);return 0;
}


Measured memory_bytes: 256
def resolve():
    import math
    a,b,x = map(int, input().split())
    area = x/a
    height = x/(a**2)
    if height == b:
        print(0)
    elif area >= (a*b/2):
        c = b-height
        angle = math.degrees(math.atan(a/(2*c)))
        print(90-angle)
    else:
        d = area*2/b
        angle = math.degrees(math.atan(d/b))
        print(90-angle)
resolve()

Measured memory_bytes: 38512
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;


bool dp[5010][5010] = {}; // dp[i][j] = i枚まで選んで総和yを作れるか？
bool need(int index, const VL& a_list, int k){ // 0index
    fill_n((bool*)dp, 5010 * 5010, false);
    dp[0][0] = true;
    FOR(i, 1, a_list.size()){
        FOR(j, 0, k){
            if(j - a_list[i - 1] >= 0 && i - 1 != index)
                dp[i][j] = dp[i - 1][j] | dp[i - 1][j - a_list[i - 1]];
            else
                dp[i][j] = dp[i - 1][j];
        }
    }

    FOR(i, max(k - (int)a_list[index], 0), k - 1)
        if(dp[a_list.size()][i]) return true;
    return false;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    VL av(n);
    REP(i, n) cin >> av[i];
    sort(av.begin(), av.end());

    int min = -1;
    int max = n;
    while(max - min > 1){
        int mid = (max + min) / 2;
        if(need(mid, av, k))
            max = mid;
        else
            min = mid;
    }

    cout << min + 1 << "\n";
    return 0;
}


Measured memory_bytes: 24832
#include<cstdio>
#include<iostream>
using namespace std;
string s;
int main()
{
	cin>>s;
	for(int i=1;i<s.size();i++)
        if(s[i-1]==s[i])
        {
            printf("%d %d",i,i+1);
            return 0;
        }
    for(int i=1;i<s.size()-1;i++)
        if(s[i-1]==s[i+1])
        {
            printf("%d %d",i,i+2);
            return 0;
        }
    printf("-1 -1");
}


Measured memory_bytes: 512
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N, A, B = map(int, readline().split())

    print(min(N * A, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61856
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>

#include <iomanip> //小数点以下を表示させる(setprecision())

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

typedef long long ll; //64bit型
using namespace std;
const ll INF = 1LL << 20;

int main()
{
        int A, B, T;
        cin >> A >> B >> T;

        cout << (T / A) * B << endl;

        return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        double l = in.nd();
        out.println(Math.pow(l/3,3));
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

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

using namespace std;
using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vvs = vector<vector<string>>;
template<typename T> using vv = vector<vector<T>>;
template<typename T> using vvv = vector<vector<vector<T>>>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using pqg = priority_queue<T, vector<T>, greater<T>>;

const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
const int DX[4] = {1, 0, -1, 0};
const int DY[4] = {0, 1, 0, -1};

#define _sel(_1, _2, x, ...) x
#define repn(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, ...) _sel(__VA_ARGS__, reps, repn)(i, __VA_ARGS__)
#define reppn(i, n) for (ll i = 1; i <= (n); i++)
#define repps(i, a, b) for (ll i = (a); i <= (b); i++)
#define repp(i, ...) _sel(__VA_ARGS__, repps, reppn)(i, __VA_ARGS__)
#define rrepn(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, a, b) for (ll i = (b) - 1; i >= (a); i--)
#define rrep(i, ...) _sel(__VA_ARGS__, rreps, rrepn)(i, __VA_ARGS__)
#define rreppn(i, n) for (ll i = (n); i >= 1; i--)
#define rrepps(i, a, b) for (ll i = (b); i >= (a); i--)
#define rrepp(i, ...) _sel(__VA_ARGS__, rrepps, rreppn)(i, __VA_ARGS__)

#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define rng(v) (v).begin(), (v).end()
#define rrng(v) (v).rbegin(), (v).rend()
#define siz(x) int((x).size())
#define pow2(x) (1ll << (x))
#define bit(x, n) ((x) >> (n) & 1)
#define prt(x) cout << (x) << endl
#define dbg(x) dbgn(#x, x)

template<typename T, typename U> inline bool umax(T& m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U> inline bool umin(T& m, U x) { if (m > x) { m = x; return true; } return false; }
template<typename T> inline void errv(T& v) { for (auto x: v) cerr << x << " "; cerr << endl; }
inline void errv(vb& v) { for (auto x: v) cerr << (x ? 1 : 0) << " "; cerr << endl; }
template<typename T> inline void dbgn(string n, T x) { cerr << n << ": " << x << endl; }
template<typename T> inline void dbgn(string n, vector<T>& v) { cerr << n << ": "; errv(v); }
template<typename T> inline void dbgn(string n, vv<T>& m) { cerr << n << ":" << endl; for (auto& v: m) errv(v); }


int main() {
    int a;
    cin >> a;
    prt(a + a * a + a * a * a);

    return 0;
}


Measured memory_bytes: 3620
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var M = cin.ReadInt;

            var tenbou = new int[N];
            var height = new int[N];

            for (int i = 0; i < N; i++)
            {
                height[i] = cin.ReadInt;
            }

            for (int i = 0; i < M; i++)
            {
                var a = cin.ReadInt;
                var b = cin.ReadInt;

                if (height[a - 1] == height[b - 1]) 
                {
                    tenbou[a - 1] = 1;
                    tenbou[b - 1] = 1;
                }
                if (height[a - 1] > height[b - 1]) 
                {
                    tenbou[b - 1] = 1;
                }
                if (height[a - 1] < height[b - 1]) 
                {
                    tenbou[a - 1] = 1;
                }
            }

            var ans = tenbou.Where(_ => _ == 0).Count();
            WriteLine(ans);
        }

    }


    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; i++)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }


        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 50864
import math
import fractions
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))




N=input1()
a=input_array()
num=1
broken=[]
flag=False
for i in range(N):
	if a[i]!=num:
		broken.append(a[i])
	else:
		num+=1
		flag=True

if flag:
	print(len(broken))
else:
	print(-1)




Measured memory_bytes: 28164
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <cmath>
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 int INF=1001001001;
vector<pair<int64_t,int64_t>>func(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p;
}

int main(){
  string s;
  cin>>s;
  int n=s.size();
  reverse(s.begin(),s.end());
  vector<int>MOD(2019);
  int64_t x=1;
  int64_t sum=0,ans=0;
  for(int i=0;i<n;i++){
   MOD[sum]++;
   sum+=(s[i]-'0')*x;
   sum%=2019;
   ans+=MOD[sum];
   x=x*10%2019;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3720
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
int n, a[N];
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n;
 	double ans = 0.0;
 	for(int i=1; i<=n; i++)
 	{
 		cin >> a[i];
 		ans += 1.0/a[i];
 	}
 	ans = 1.0/ans;
 	cout << fixed << setprecision(12) << ans;
	return 0;
}


Measured memory_bytes: 256
// AOJ 2511 Sinking islands
// 2018.2.28 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 202

/* UNION-FIND library */
int id[MAX], size[MAX]; int cnt;
void init(int n) { int i; for (i = 0; i < n; i++) id[i] = i, size[i] = 1; }
int root(int i) { while (i != id[i]) id[i] = id[id[i]], i = id[i]; return i; }
int connected(int p, int q) { return root(p) == root(q); }
void unite(int p, int q) { int i = root(p), j = root(q); if (i == j) return;
cnt++; if (size[i] < size[j]) id[i] = j, size[j] += size[i]; else id[j] = i, size[i] += size[j];
}

int N, M;
int h[MAX], t[MAX], t2[MAX], s[MAX];
typedef struct { int a, b, c; } C;
C c[20000];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int tcmp(int *a, int *b) { return *a - *b; }
int ccmp(C *a, C *b) { return a->c - b->c; }

int uniq(int *a, int n)
{
	int i, j, k;

	s[0] = N;
	for (i = 0, j = 1; j < n; j++) {
		k = j; while (j < n && a[j] == a[i]) j++;
		s[i+1] = s[i] - (j-k+1);
		if (j < n) if (++i != j) a[i] = a[j];
	}
	return i+1;
}

int check(int id)
{
	int i, a, b, tm;

	init(N); cnt = 1;
	for (i = 0; i < M; i++) {
		a = c[i].a, b = c[i].b;
		if (h[a] >= t[id] && h[b] >= t[id] && !connected(a, b)) unite(a, b);
		if (cnt == s[id]) return 0;
	}
	return 1;
}

int main()
{
	int i, j, k, tsz, tm, ans;
	int a, b;

	while (N = in()) {
		init(N); cnt = 1;

		M = in();
		for (i = 0; i < N; i++) h[i] = t[i] = in();
		for (i = 0; i < M; i++) {
			c[i].a = a = in()-1, c[i].b = b = in()-1, c[i].c = in();
			unite(a, b);
		}
		if (cnt < N) { puts("0"); continue; }

		qsort(t, N, sizeof(int), tcmp);
		tsz = uniq(t, N);
		qsort(c, M, sizeof(C), ccmp);

		for (i = 1; i < tsz; i++) if (check(i)) break;
		k = i-1, tm = t[k];

		ans = 0;
		init(N);
		for (i = 0; i < M; i++) {
			a = c[i].a, b = c[i].b;
			if (h[a] >= tm && h[b] >= tm &&	!connected(a, b))
				ans += c[i].c, unite(a, b);
		}
		for (j = k-1; j >= 0; j--) {
			for (i = 0; i < M; i++) {
				a = c[i].a, b = c[i].b;
				if (h[a] >= t[j] && h[b] >= t[j] && !connected(a, b))
					ans += c[i].c, unite(a, b);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2244
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d,i,j,k,l;
    cin>>a;
    int a1[a];
    int sum=0;
    for(i=0;i<a;i++)
       {

        cin>>a1[i];
        sum+=a1[i];
       }
       if(a<2)
        cout<<"No";
       sort(a1,a1+a);

       for(i=0;i<a;i++)
       {
           if(sum-a1[i]<=a1[i])
           {
               cout<<"No";
               return 0;
           }
       }

       cout<<"Yes";

}


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

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

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

  int A, B;
  cin >> A >> B;
  cout << (A-1)*(B-1) << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define MOD ((int)1e9+7)
#define INF ((int)1e9+7)
#define INFLL ((LL)1e18)
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
using namespace std;

LL modinv(LL a){
	LL b = MOD, u = 1, v = 0;
	while(b){
		LL t = a / b;
		a -= t * b;swap(a, b);
		u -= t * v;swap(u, v);
	}
	u%=MOD;
	if(u < 0) u += MOD;
	return u;

}
LL exp(LL a, LL b){
	LL res = 1;
	LL sum = a;
	while(b){
		if(b&1)res = (res * sum) % MOD;
		sum = (sum * sum) % MOD;
		b>>=1;
	}
	return res;
}

LL factorial(LL x){
	static LL memo[100001]={0};
	if(x<=1)return 1;
	if(memo[x])return memo[x];
	return memo[x] = x * factorial(x-1) % MOD;
}

LL C(LL a, LL b){
	return factorial(a) * exp(factorial(b)*factorial(a-b)%MOD, MOD-2)%MOD;
}

int main(){
	LL N, M;
	cin >> N >> M;
	LL ans = 1;
	for(LL i=2;i*i<=M;++i){
		int count = 0;
		while(M%i==0){
			M/=i;
			++count;
		}
		if(count==0)continue;
		ans  = ans * C(N+count-1, count) % MOD;
	}
	if(M!=1)ans = ans * N % MOD;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;

int main(){
	string s, op, t;
  	cin >> s;
    int q, a, b;
    cin >> q;
  	for (int i = 0; i < q; i++){
      cin >> op;
      if (op == "replace"){
      	  cin >> a >> b >> t;
        for (int j = a; j <= b; j++){
          s[j] = t[j-a];
        }
      }
      else if (op == "reverse") {
        cin >> a >> b;
        reverse(s.begin()+a,s.begin()+b+1);
      }
      else {
        cin >> a >> b;
        for (int j = a; j <= b; j++){
        	cout << s[j];
        }
        cout << endl;
      }
	
    }
    return 0;
}


Measured memory_bytes: 3212
//arc074_c.cpp
//Sat Jun  9 08:12:50 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;

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

	int a[n];
	cin >> a[0];
	ll ans = 0;
	for (int i=1;i<n;i++){
		cin >> a[i];
		if (a[i]-a[i-1]<t){
			ans = ans + a[i] - a[i-1]; 
		}else {
			ans = ans + t;
		}
	}


	cout << ans + t << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long int;

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

    ll sum = 0;
    for (size_t i = 1; i <= n; i++)
    {
        if (i % 3 != 0 && i % 5 != 0) {
            sum += i;
        }
    }
    cout << sum << endl;
       
}

Measured memory_bytes: 3652
fun main(args: Array<String>){
    val _500Coins = readLine()!!.toInt()
    val _100Coins = readLine()!!.toInt()
    val _50Coins = readLine()!!.toInt()
    val x = readLine()!!.toInt()
    var result = 0

    for(i in 0.._500Coins){
        for(j in 0.._100Coins){
            for(k in 0.._50Coins){
                val sum = 500 * i + 100 * j + 50 * k
                if(sum == x) result++
            }
        }
    }

    print(result)
}


Measured memory_bytes: 31744
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, A;
    cin >> N >> A;
    if(N%500<=A) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);


// n以下の素数を返す
vector<bool> sieve(ll n) {
    vector<ll> prime;
    vector<bool> is_prime;
    is_prime.resize(n + 1);
    prime.resize(n);
    ll p = 0;
    rep(i, n + 1) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    FOR(i, 2, n + 1) {
        if (is_prime[i]) {
            prime[p++] = i;
            for (ll j = 2 * i; j <= n; j += i) is_prime[j] = false;
        }
    }
    return is_prime;
}


ll q;
vector<ll> l, r;
vector<ll> prime_count(half_inf + 1, 0);

void solve() {
    vector<bool> is_prime = sieve(half_inf);
    repone(i, half_inf) {
        if (is_prime[i] && is_prime[(i + 1) / 2]) prime_count[i] = prime_count[i - 1] + 1;
        else prime_count[i] = prime_count[i - 1];
    }
    rep(i, q) {
        cout << prime_count[r[i]] - prime_count[l[i] - 1] << endl;
    }
}

int main() {
    cin >> q;
    l.resize(q), r.resize(q);
    rep(i, q) cin >> l[i] >> r[i];
    solve();
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int K;
    string S;
    cin >> K >> S;

    if (S.size() <= K) {
        cout << S << endl;
    } else {
        string Q = S.substr(0, K) + "...";
        cout << Q << endl;
    }

    return 0;
}

Measured memory_bytes: 3656
N = int(input())
M = [list(map(int, input().split())) for i in range(N)]
INF = 2001
MAX = 100
d = [INF for i in range(N)]
d[0] = 0
p = [MAX for i in range(N)]
p[0] = -1
mst = [False for i in range(N)]

while True:
  min_w = INF
  for i in range(N):
    if not mst[i] and d[i] < min_w:
      min_w = d[i]
      u = i
  if min_w == INF:
    break
  mst[u] = True
  for v in range(N):
    if not mst[v] and M[u][v] != -1:
      if M[u][v] < d[v]:
        d[v] = M[u][v]
        p[v] = u

print(sum(d))



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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    string a,b;
    cin>>a>>b;
    cout<<b+a;


    return 0;
}


Measured memory_bytes: 3616
#include <iostream>

using namespace std;

long long f(long long x){
    if(x%4==0) return x;
    if(x%4==1) return 1;
    if(x%4==2) return x+1;
    return 0;
}

int main(){
    
    
    long long nim = 0,x,m;
    
  
        cin>>x>>m;
        nim = f(m)^f(x-1);
        cout<<nim;
    
    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 A = scan.nextInt();
		int B = scan.nextInt();
		int C = scan.nextInt();

		boolean flag = false;

		if (A == B && B != C) {
			flag = true;
		}
		if (B == C && C != A) {
			flag = true;
		}
		if (A == C && B != A) {
			flag = true;
		}

		if (flag) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}


Measured memory_bytes: 23124
def main():
  N = int(input())
  xyh = [[int(_) for _ in input().split()] for __ in range(N)]
  for cx in range(0, 101):
    for cy in range(0, 101):
      H = set()
      for x, y, h in xyh:
        if h == 0:
          continue
        H.add(abs(cx - x) + abs(cy - y) + h)
      if len(H) == 1:
        ok = True
        hh = list(H)[0]
        for x, y, h in xyh:
          if h == 0:
            if max(hh - abs(cx - x) - abs(cy - y), 0) == 0:
              continue
            else:
              ok = False
        if ok:
          print(cx, cy, *H)
          break
    else:
      continue
    break
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 41708
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourd; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Mfor(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, d[2000], a[600000], b[60000];
string str, ss;
bool f[202000];
char c,ch[100][100];
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
vector<Edge>vec[200000];
vector<LL>v;
map<LL, LL>ma;
multiset<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n >> m;
	cin >> c;
	rep(i, m)rep(j, n)ch[i][j] = '.';
	ch[m / 2][n / 2] = c;
	rep(i, n) {
		ch[0][i] = '-';
		ch[m - 1][i] = '-';
	}
	rep(i, m) {
		ch[i][0] = '|';
		ch[i][n-1] = '|';
	}
	ch[0][0] = '+';
	ch[0][n - 1] = '+';
	ch[m - 1][0] = '+';
	ch[m - 1][n - 1] = '+';
	rep(i, m) {
		rep(j, n)cout << ch[i][j];
		cout << endl;
	}
	return 0;
}



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

using namespace std;

int main()
{
    int n, m, c;
    cin >> n >> m >> c ;
    int b[m];
    int i,j;
    for(i=0; i<m; i++){
        cin >> b[i];
    }
    int d =0;
    for(i=0; i<n; i++){
        int a[m];
        int sum = 0;
        for(j=0; j<m; j++){
            cin >> a[j];
            sum += a[j]*b[j];
        }
        //cout << sum << endl;
        if(sum+c > 0){
            d++;
        }
    }
    cout << d << endl;
}


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

#define IOS {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define ll long long 

ll powermod(ll x,ll ex,ll md){ll ans=1ll;while(ex>0){if(ex&1ll) ans=(ans*x)%md; ex>>=1ll;x=(x*x)%md;}return ans;}
inline ll gcd(ll a,ll b) {if(b==0)return a;a%=b;return gcd(b,a);}
inline ll max(ll a,ll b) {return((a>b)?a:b);}
inline ll min(ll a,ll b) {return((a>b)?b:a);}

// finding shortest prime factor//SPF -- Nlog(n)
const ll mX = 1e6+2;
ll spf[mX];
void sieve (){
    spf[1]=1;
    for(ll i=2;i<mX;i++){
        if(spf[i]==0){
            spf[i]=i;
            for (ll j=1ll*i*i;j<mX;j+=i){
                if(spf[j]==0) spf[j]=i;
            }
        }
    }
}
map<ll,ll> m;
int main(){
        IOS;
        sieve();
        ll n;
        cin>>n;
        ll a[n];
        for(ll i=0;i<n;i++){
                cin>>a[i];
        }

        bool ok=1;
        for(ll i=0;i<n;i++){
                ll x=a[i];
                while(x>1){
                        ll div=spf[x];
                        if(div > 1){
                                auto it=m.find(div);
                                if(it!=m.end()){
                                        ok=0;
                                        break;
                                }
                                else m[div]++;
                                while(x%div==0) x/=div;
                        }
                }
                if(!ok) break;
        }
        if(ok) cout<<"pairwise coprime\n";
        else{
                ll g=0;
                for(ll i=0;i<n;i++) g=gcd(g,a[i]);
                if(g==1) cout<<"setwise coprime\n";
                else cout<<"not coprime\n";
        }
}


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

#define cst() int __t;scanf("%d",&__t);while(__t--)
#define rep(i,s,e) for(int i=s;i<e;++i)
#define repb(i,s,e) for(int i=s;i<=e;++i)
#define lep(i,s,e) for(int i=s;i>e;--i)
#define lepb(i,s,e) for(int i=s;i>=e;--i)
#define mst(a,b) memset(a,b,sizeof(a))
#define mcpy(des,sor) memcpy(des,sor,sizeof(sor))
#define pow2(x) ((x)*(x))
#define pt(x) cout<<#x<<"="<<x<<endl;


#define maxn 100006

typedef long long ll;
const int inf = 0x3f3f3f3f;

typedef pair<int,int> pii;

set<int> N[maxn];

int main()
{
	int n,a,b;
	queue<int> q;
	set<int> s;
	cin>>n;
	repb(i,1,n-1)
	{
		cin>>a>>b;
		N[a].insert(b);
		N[b].insert(a);
	}
	repb(i,1,n)
	{
		s.insert(i);
		if(N[i].size()==1)q.push(i);
	}
	while(!q.empty())
	{
		a=q.front();q.pop();
		if(s.find(a)==s.end())continue;
		for(auto u:N[a])if(N[u].size()<=2)
		{
			s.erase(a);s.erase(u);
			for(auto v:N[u])if(v!=a)
			{
				N[v].erase(u);
				if(N[v].size()==1)q.push(v);
				else if(N[v].size()==2)
				{
					for(auto b:N[v])if(N[b].size()==1)q.push(b);
				}
			}
		}
	}
	if(s.size()==0)cout<<"Second"<<endl;
	else cout<<"First"<<endl;

}


Measured memory_bytes: 19200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

ll calc(ll x){
    if(x <= 1) return 0;
    return x * (x-1) /2;
}

int mainsolve(){

    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) {
        ll tmp;
        cin >> tmp;
        a[i] = --tmp;
    }

    vector<ll> cnt(n);
    rep(i,n) cnt[a[i]]++;

    ll tmp = 0;
    rep(i,n) tmp += calc(cnt[i]); 

    rep(i,n){
        cout << tmp - calc(cnt[a[i]]) + calc(cnt[a[i]]-1) << endl;
    }

	return 0;
}

int main(){

	return mainsolve();
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
bool used[10001];
int n,a,b,m;
string ans;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)ans+='0';
	ans[0]='1';
	while(m--)
	{
		scanf("%d%d",&a,&b);
		--a;
		if(used[a]&&b!=ans[a]-48)
		{
			puts("-1");
			return 0;
		}
		used[a]=1;
		ans[a]=b+48;
	}
	if(n==1&&used[0]==0)
	{
		puts("0");
		return 0;
	 } 
	if(ans[0]=='0'&&used[0]==1)
	{
		if(n!=1)puts("-1");
		else puts("0");
		return 0;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
// #include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <cstdlib>
#include <cmath>
#define debug(x) cout << '>' << #x << ':' << x << endl;
 
#define nitro ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

using namespace std;
using ll = long long int;
const ll mod = 1e9+7;
const ll invmod = 998244353; 
const int N = 5*(int)(1e5) + 1;
const int MAXN = 1e5+10;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);freopen("out.txt", "w", stdout);
	#endif   

	ll n;
	cin >> n;
	string ans;

	while(n>0)
	{
		ll temp = n%26;
		if(temp == 0) 
		{
			ans.push_back('z');
			n--;
			n /= 26;
		}
		else 
		{		
			n /= 26;
			ans.push_back(char((temp+'a'-1)));
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans << '\n';
	


	return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<vector>
int main(){
	int a=0;
	std::vector<int> vec(10);
	for(int i=0;i<10;i++){
		std::cin>>vec[i];
	}
	
	while(1){
		bool f=true;
		for(int i=0;i<9;i++){
			if(vec[i]<vec[i+1]){
				a=vec[i];
				vec[i]=vec[i+1];
				vec[i+1]=a;
				a=0;
				f=false;
			}
		}
		if(f)break;
	}
	std::cout<<vec[0]<<std::endl<<vec[1]<<std::endl<<vec[2]<<std::endl;
	
	return 0;
}

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

using namespace std;

int main(void)
{
    int day_length;
    vector<int> values;

    cin >> day_length;
    
    for(int i = 0; i < day_length; i++){
        int v;
        cin >> v;
        values.push_back(v);
    }

    long long money = 1000;

    for(int i = 1; i < day_length; i++){
        if(values[i] > values[i - 1]){
            long long buy_count = money / values[i - 1];
            money += (long long)buy_count * (values[i] - values[i - 1]);
        }
    }

    cout << money << endl;

    return 0;
}

Measured memory_bytes: 3620
s = input()
t = input()

ans = 1001
for i in range(len(s) - len(t) + 1):
    num = 0
    x = s[i : i + len(t)]

    for j in range(len(t)):
        if x[j] != t[j]:
            num += 1

    ans = min(ans, num)

print(ans)

Measured memory_bytes: 9120
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) { cin >> A[i]; }
    sort(A.begin(), A.end(), greater<ll>());
    if(N % 2 == 0) {
        //+2と-2が同じ数
        ll res = 0;
        REP(i, N / 2 - 1) { res += A[i] * 2; }
        res += A[N / 2 - 1];
        res -= A[N / 2];
        for(int i = N / 2 + 1; i < N; i++) {
            res -= A[i] * 2;
        }
        cout << res << endl;
    } else {
        ll res1 = 0;
        for(int i = 0; i < N / 2 - 1; i++) {
            res1 += A[i] * 2;
        }
        res1 += A[N / 2 - 1] + A[N / 2];
        for(int i = N / 2 + 1; i < N; i++) {
            res1 -= A[i] * 2;
        }
        ll res2 = 0;
        for(int i = 0; i < N / 2; i++) {
            res2 += A[i] * 2;
        }
        res2 -= A[N / 2] + A[N / 2 + 1];
        for(int i = N / 2 + 2; i < N; i++) {
            res2 -= A[i] * 2;
        }
        cout << max(res1, res2) << endl;
    }
    return 0;
}

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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int nt = (c + b - 1) / b;
    int nt1 = (a + d - 1) / d;
    if (nt <= nt1)
        cout << "Yes";
    else
        cout << "No";
}

Measured memory_bytes: 3636
a,b,c=list(map(int,input().split()))
n=0
H=[]
while True:
  S=[a,b,c]
  if S in H:
    print("-1")
    exit()
  H.append(S)
  if a%2!=0 or b%2!=0 or c%2!=0:
    print(n)
    exit()
  else:
    A=a/2
    B=b/2
    C=c/2
    a=int(B+C)
    b=int(A+C)
    c=int(A+B)
    n+=1

Measured memory_bytes: 9192
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	string S;
	cin >> S;
	map<char, int>m;
	for (auto i : S)
	{
		m[i]++;
	}
	for (auto i : m)
	{
		if (i.second != 2)
		{
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n;
ll a[200005];
ll tmp[200005];
ll dp[200005];
int main()
{
        cin >> n;
        for(ll i=1;i<=n;i++)
        {
                cin >> a[i];
                dp[i] = n+2;
        }
        for(ll i = 0 ; i<= 22;i++)
        {
                for(ll j=1;j<=n;j++) {
                        if(a[j]&(1LL << i)) tmp[j] = 1;
                        else tmp[j] = 0;
                }
                ll last = 0;
                ll last2 = 0;
                for(ll j =1 ; j <= n ; j++) {
                        ll yo;
                        if(tmp[j] == 1) {
                                yo = j - last;
                                dp[j] = min(dp[j] , yo);
                                last2 = last;
                                last = j;
                        }else{
                                yo = j - last2;
                                //if(last2 > 0) yo++;
                                dp[j] = min(dp[j] , yo);
                        }
                }
        }
        ll ret = 0;
        for(ll i=1;i<=n;i++) ret += dp[i];
        //for(ll i=1;i<=n;i++) cout << dp[i] << " "; cout << endl;
        cout << ret << endl;
        return 0;
}


Measured memory_bytes: 4992
N,M = map(int,input().split())

related_switch = [[] for _ in range(M)]
for i in range(M):
    s = list(map(lambda x: int(x)-1,input().split()))
    related_switch[i] = s[1:]

p = list(map(int,input().split()))

ans = 0
for status in range(1<<N):#スイッチのon/offの状態
    on = []#onになってるスイッチの番号
    for mask in range(N):
        if (1<<mask)&status:
            on.append(mask)
    for i,s in enumerate(related_switch):
        if len(set(s)&set(on))%2 != p[i]:
            break
    else:
        ans += 1

print(ans)

Measured memory_bytes: 41328
# coding:utf-8

import sys
from collections import deque

INF = float('inf')
MOD = 10 ** 9 + 7
dy, dx = (0, -1, 0, 1), (1, 0, -1, 0)

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def main():
    n, k = LI()
    print(n - k + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <iostream>
#include <cstring>
using namespace std;
long long n, ans, mx, a[55], b[55], v[55];

int f() {
	int i, j, k, x[55];
	for(i=0; i<n; i++) {
		memset(x, 0, sizeof(x));
		x[a[i]] = 1;
		for(j=a[i]; j>b[i]; j--) if(x[j]) {
			for(k=1; k<=j; k++) if(v[k]) x[j%k] = 1;
		}
		if(!x[b[i]]) return 0;
	}
	return 1;
}

int main(){
	int i;
	cin>>n;
	for(i=0; i<n; i++) cin>>a[i], mx = max(mx, a[i]);
	for(i=0; i<n; i++) cin>>b[i];
	for(i=1; i<=mx; i++) v[i] = 1;
	if(!f()) {cout<<-1; return 0;}
	for(i=mx; i; i--) {
		v[i] = 0;
		if(!f()) v[i] = 1;
	}
	for(i=mx; i; i--) if(v[i]) ans += 1LL<<i;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>



int main()
{
	double n ;

	while( 1 )
	{
		scanf( "%lf" ,&n ) ;


		if( n < 0 )
		{
			return 0 ;
		}


		n *= 2 * 2 * 2 * 2 ;


		int m = ( int )n ;


		if( n - ( double )m == 0 && ( m >> 12 ) == 0 )
		{
			int i = 0 ;
			for( ; i < 12 ; ++i )
			{
				if( i == 8 )
				{
					printf( "." ) ;
				}


				printf( "%d" ,( m >> ( 12 - i - 1 ) & 1 ) ) ;
			}


			puts( "" ) ;
		}

		else
		{
			puts( "NA" ) ;
		}
	}
}

Measured memory_bytes: 1772