akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
  char SA[100]={0},SB[100]={0},SC[100]={0};
  char a=1,b=1,c=1;
  int i=0,j=0,k=0;
  char turn='a';
  int flagA=0,flagB=0,flagC=0;

  scanf("%s%s%s",SA,SB,SC);

  while(1){
      if(turn=='a'){
	if(a==0){
	  flagA++;
	  break;
	}
	i++;
	a=SA[i];
	turn=SA[i-1];
      }
      if(turn=='b'){
	if(b==0){
	  flagB++;
	  break;
	}
	j++;
	b=SB[j];
	turn=SB[j-1];
      }
      if(turn=='c'){
	if(c==0){
	  flagC++;
	  break;
	}
	k++;
	c=SC[k];
	turn=SC[k-1];
      }
  }
  if(flagA)printf("A\n");
  if(flagB)printf("B\n");
  if(flagC)printf("C\n");
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
long long int mod = (long long int)1000000007;
using namespace std;

void solve()
{
    ll k,n,m;
    int i,j;
    std::cout.precision(10);
    int yes=0;
  cin>>n>>m>>k;
  vector<ll>a(n);
  vector<ll>b(m);
  for(i=0;i<n;i++)
  {
    cin>>a[i];
  }
  for(i=0;i<m;i++)
  {
    cin>>b[i];
  }
  for(i=1;i<n;i++)
  {
      a[i]+=a[i-1];
  }
  for(j=1;j<m;j++)
  {
      b[j]+=b[j-1];
  }
  int ans=0;
  ll curr;
    for(i=0;i<n;i++)
    {
        ll find=k-a[i];
        int l=0;
        int r=b.size()-1;
        int p=-1;
        while(l<=r)
        {
            int mid=(l+(r-l)/2);
            if(b[mid]<=find)
            {
                l=mid+1;
                p=mid;
            }
            else
            {
                r=mid-1;
            }
        }
    
        if(p!=-1)
        ans=max(ans,i+1+p+1);
    }
    for(i=0;i<n;i++)
    {
        if(a[i]<=k)
        {
            ans=max(ans,i+1);
        }
    }
    for(i=0;i<m;i++)
    {
        if(b[i]<=k)
        {
            ans=max(ans,i+1);
        }
    }
    cout<<ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    int i,j,k;
    int t;
    std::cout.precision(10);
    t=1;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
}


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

    return 0;
}


Measured memory_bytes: 1932
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String[] conf = scanner.nextLine().split(" ");
		int numPoints = Integer.parseInt(conf[0]);
		long goal = Long.parseLong(conf[1]);
		int[] numProblems = new int[numPoints + 1];
		int[] achievablePoints = new int[numPoints + 1];
		int[] solved = new int[numPoints + 1];
		for(int pIdx = 1; pIdx <= numPoints; pIdx++) solved[pIdx] = (int) Math.pow(2, pIdx - 1);

		for(int pIdx = 1; pIdx <= numPoints; pIdx++) {
			String[] inputs = scanner.nextLine().split(" ");
			numProblems[pIdx] = Integer.parseInt(inputs[0]);
			achievablePoints[pIdx] = numProblems[pIdx] * pIdx * 100 + Integer.parseInt(inputs[1]);
		}

		int minNumSolved = Integer.MAX_VALUE;
		int maxSolvePlan = (int) Math.pow(2, numPoints) - 1;
LOOP:	for(int solvePlan = 0; solvePlan <= maxSolvePlan; solvePlan++) {
			long tmpTotalPoint = 0L;
			int tmpNumSolved = 0;
			for(int pIdx = 1; pIdx <= numPoints; pIdx++) {
				if((solved[pIdx] & solvePlan) != 0) {
					tmpTotalPoint += achievablePoints[pIdx];
					tmpNumSolved += numProblems[pIdx];
				}
			}
			long remainder = goal - tmpTotalPoint;
			for(int pIdx = numPoints; remainder > 0L && pIdx >= 1; pIdx--) {
				if((solved[pIdx] & solvePlan) == 0) {
					int tmpNumPartiallySolved = (int) ((remainder - 1L) / (pIdx * 100)) + 1;
					if(tmpNumPartiallySolved >= numProblems[pIdx]) continue LOOP;
					tmpNumSolved += tmpNumPartiallySolved;
					tmpTotalPoint += tmpNumPartiallySolved * pIdx * 100;
					break;
				}
			}
			if(minNumSolved > tmpNumSolved) minNumSolved = tmpNumSolved;
		}

		System.out.println(minNumSolved);
	}
}


Measured memory_bytes: 23764
inf = float("inf")
def bellman_ford(es, s):
    d[s] = 0
    for cnt in xrange(V):
        update = False
        for e in es:
            frm, to, cost = e
            if d[frm] != inf and d[to] > d[frm] + cost:
                d[to] = d[frm] + cost
                update = True
                if cnt == i - 1:
                    return True
    return False

V, E, r = map(int, raw_input().split())
es = [map(int, raw_input().split()) for i in xrange(E)]
d = [inf for i in xrange(V)]
negative = bellman_ford(es, r)
if negative:
    print "NEGATIVE CYCLE"
else:
    for i in d:
        if i < inf:
            print i
        else:
            print "INF"

Measured memory_bytes: 4480
n,*aa = map(int, open(0).read().split())

ans = 1000

mn=mx=aa[0]

for i in range(1,n):
    if mn<=aa[i] and mx<=aa[i]:
        mx = aa[i]
    else:
        ans += (mx-mn)*(ans//mn)
        mn=mx=aa[i]
ans += (mx-mn)*(ans//mn)

print(ans)

Measured memory_bytes: 61884
#include<bits/stdc++.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define MOD 1000000007
#define EPS (1e-10)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<ll, ll>P;


ll a[10000];
signed main() {
	ll k, t; scanf("%lld%lld", &k, &t);
	ll Max = 0, sum = 0;
	rep(i, t) {
		scanf("%lld", &a[i]);
		Max = max(Max, a[i]);
		sum += a[i];
	}
	printf("%lld\n", max(0LL, Max - sum + Max - 1));
}

Measured memory_bytes: 384
import bisect

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

A,B,C = sorted(A),sorted(B),sorted(C)

a_max = 0
c_min = 0
ans = 0

for j in range(N):
    b = B[j]

    a_max = bisect.bisect_left(A,b,a_max,N)
    c_min = bisect.bisect_right(C,b,c_min,N)
    ans += (a_max) * (N-c_min)

print(ans)


Measured memory_bytes: 23360
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)


#define MAX_V 100000
vector<int> G[MAX_V];

void visit(int cur, int prev, vector<pii> &brg, vector<vector<int>> &each_bcc, stack<int> &roots, stack<int> &S, vector<bool> &inS, vector<int> &order, int &k){
	order[cur] = ++k;
	S.push(cur); inS[cur] = true;
	roots.push(cur);
	
	rep(i,G[cur].size()){
		int to = G[cur][i];
		if(order[to]==0){
			visit(to,cur,brg,each_bcc,roots,S,inS,order,k);
		}
		else if(to!=prev && inS[to]){	//?????????????????????
			while(order[roots.top()] > order[to]) roots.pop();	//cur???to?????§(to???????????????)????????????roots????????¨??????
		}
	}

	if(cur==roots.top()&&prev!=-1){
		brg.pb(pii(prev,cur));
		vector<int> bcc;
		while(1){
			int node = S.top(); S.pop(); inS[node] = false;
			bcc.pb(node);
			if(node==cur)break;
		}
		each_bcc.pb(bcc);
		roots.pop();
	}
}


void bridge(int V, vector<pii> &brg, vector<vector<int>> &each_bcc){
	vector<int> order(V);
	vector<bool> inS(V);
	stack<int> roots, S;
	int k=0;
	rep(i,V){
		if(order[i]==0){
			visit(i,-1,brg,each_bcc,roots,S,inS,order,k);
		}
	}
}



int main(){
	int v,e;
	cin>>v>>e;
	vector<pii> edges;
	rep(i,e){
		int s,t;
		cin>>s>>t;
		edges.pb(pii(s,t));
		G[s].pb(t);
		G[t].pb(s);
	}
	
	vector<pii> brg;
	vector<vector<int>> each_bcc;
	
	bridge(v,brg,each_bcc);
	
	vector<pii> ans;

	rep(i,brg.size()){
		if(brg[i].first<brg[i].second)ans.pb(pii(brg[i].first,brg[i].second));
		else ans.pb(pii(brg[i].second,brg[i].first));
	}
	
	
	sort(all(ans));
	rep(i,ans.size())cout<<ans[i].first<<" "<<ans[i].second<<endl;
}

Measured memory_bytes: 7688
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

struct Info1{
	Info1(){
		value = 0;
	}

	Info1(int arg_value){
		value = arg_value;
	}

	bool operator<(const struct Info1 &arg) const{
		return value < arg.value;
	};

	int value;
};

struct Info2{
	Info2(){
		value = 0;
	}

	Info2(int arg_value){
		value = arg_value;
	}

	bool operator<(const struct Info2 &arg) const{
		return value < arg.value;
	};

	int value;
};



int main(){

	Info1 info1[30];
	Info2 info2[30];

	priority_queue<Info1> Q1;
	priority_queue<Info2> Q2;

	int D,one_num,two_num,index_1,index_2,value;
	scanf("%d",&D);

	scanf("%d",&one_num);

	index_1 = 0;
	char buf[3];

	for(int loop = 0; loop < one_num; loop++){
		scanf("%s %d",buf,&value);

		if(buf[0] == 'D'){
			Q1.push(Info1(value));
		}
	}

	while(!Q1.empty()){
		info1[index_1++].value = Q1.top().value;
		Q1.pop();
	}

	scanf("%d",&two_num);

	index_2 = 0;

	for(int loop = 0; loop < two_num; loop++){
		scanf("%s %d",buf,&value);

		if(buf[0] == 'D' && buf[1]== 'D'){
			Q2.push(Info2(value));
		}
	}

	while(!Q2.empty()){
		info2[index_2++].value = Q2.top().value;
		Q2.pop();
	}

	int limit_1 = min(D,index_1),limit_2 = min(D/2,index_2),maximum = 0,tmp_sum;

	for(int i = 0; i <= limit_1; i++){ //?§£????¬?1???????????¨?????°
		for(int k = 0; k <= limit_2; k++){ //?§£????¬?2???????????¨?????°
			if(i + 2*k > D)break;

			tmp_sum = 0;
			for(int p = 0; p < i; p++)tmp_sum += info1[p].value;
			for(int p = 0; p < k; p++)tmp_sum += info2[p].value;
			maximum = max(maximum,tmp_sum);
		}
	}

	printf("%d\n",maximum);

	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    ll ans=0;
    for(int i=1;i<n;i++){
        ans+=a[i/2];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4820
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, " ")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func parseFloat(str string) float64 {
        n, _ := strconv.ParseFloat(str, 64)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

func bitCount(n uint) int {

        x := uint64(n)

        const m = 1<<64 - 1
        const m0 = 0x5555555555555555
        const m1 = 0x3333333333333333
        const m2 = 0x0f0f0f0f0f0f0f0f

        x = x>>1&(m0&m) + x&(m0&m)
        x = x>>2&(m1&m) + x&(m1&m)
        x = (x>>4 + x) & (m2 & m)
        x += x >> 8
        x += x >> 16
        x += x >> 32

        return int(x) & (1<<7 - 1)
}

func bitExist(n, i int) bool {
        return ((n >> uint(i)) & 1) == 1
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
        btc := 380000.0

        line := nextLine()
        N := parseInt(line)

        res := 0.0
        for i := 0; i < N; i++ {
                l := nextLine()
                s := strSprit(l)

                n := parseFloat(s[0])

                if s[1] == "JPY" {
                        res += n
                } else {
                        res += btc * n
                }
        }

        fmt.Printf("%.5f", res)
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <queue>
using namespace std;
int main()
{
    string s1;
    string s2;
    cin>>s1>>s2;
    int l1 = s1.length(),l2 = s2.length();
    if(l1 > l2){
        cout<<"GREATER"<<endl;
    }
    else if(l1 < l2){
        cout<<"LESS"<<endl;
    }
    else{
        if(s1 > s2)
        {
            cout<<"GREATER"<<endl;
        }
        else if(s1 < s2){
            cout<<"LESS"<<endl;
        }
        else{
            cout<<"EQUAL"<<endl;
        }
    }

    return 0;
}

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

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){

}

void solve(){
    ll n,k;
    cin>>n>>k;
    ll MIN = min(n%k, k-n%k);
    cout << MIN;
}

int main(){
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 256
import math

D,G = map(int,input().split())

pc = [list(map(int,input().split()))for _ in range(D)]

digit = "0"+str(D)+"b"
ans = float("INF")
for i in range(2**D):
    flags = list(str(format(i,digit)))
    points = 0
    count = 0
    last0 = -1
    for j in range(D):
        if flags[j]=="1":
            points += pc[j][0]*100*(j+1) + pc[j][1]
            count += pc[j][0]
        else:
            last0 = j
    r = G - points
    if r<=0:
        ans = min(ans,count)
    else:
        if last0 == -1:
            continue
        need = math.ceil(r/(100*(last0+1)))
        if need >= pc[last0][0]:
            continue
        else:
            count += need
            ans = min(ans,count)

print(ans)


Measured memory_bytes: 3188
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner stdin = new Scanner(System.in);
		int arr[][] = new int[300][2];
		int i = 0, j = 0, count = 0;
		for (i = 0; i < 300; i++) {
			arr[i][0] = stdin.nextInt();
			arr[i][1] = stdin.nextInt();
			if (arr[i][0] == 0 && arr[i][1] == 0) {
				count = i;
				break;
			}
		}
		for (int k = 0; k < count; k++) {
			int row = arr[k][0];
			int col = arr[k][1];
			for (i = 0; i < row; i++) {				
				for (j = 0; j < col; j++) {
					if (i==0 || i==row-1  || j==0 || j==col-1) {
						System.out.print("#");
					}else {
						System.out.print(".");
					}
				}
				System.out.print("\n");
			}
			System.out.print("\n");
		}
	}
}

Measured memory_bytes: 35924
#include<iostream>
#include<string>
#include<math.h>

using namespace std;
string calc(long n, long k){
    if(n == 0)return "0";

    if(n%long(pow(-2, k+1)) == 0) return calc(n, k+1) + "0";
    return calc(n-pow(-2, k), k+1) + "1";
}

int main(){
    int N;
    cin >> N;
    string ans =calc(N, 0);
    if(ans.size() != 1)ans.erase(ans.begin());
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>

int main(void){
    int n;
    scanf("%d",&n);
    int i,j;
    double v[n];
    for(i=0;i<n;i++){
        scanf("%lf",&v[i]);
    }
    int temp;
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            if(v[i]>v[j]){
                temp = v[i];
                v[i] = v[j];
                v[j] = temp;
            }
        }
    }
    double res;
    res=(v[0]+v[1])/2;
    i=2;
    while(i<n){
        res=(res+v[i])/2;
        i++;
    }
    printf("%lf",res);
}



Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))

large = -float('inf')
small = float('inf')
for i, a in enumerate(A):
    if large < a:
        large = a
        idxL = i + 1
    if small > a:
        small = a
        idxS = i + 1

S = [(i + 1, i + 2) for i in range(N - 1)]
S_reverse = [(i, i - 1) for i in range(N, 1, -1)]

if small >= 0:
    ans = S
elif large <= 0:
    ans = S_reverse
elif abs(large) >= abs(small):
    ans = [(idxL, i) for i in range(1, N + 1) if i != idxL] + S
else:
    ans = [(idxS, i) for i in range(1, N + 1) if i != idxS] + S_reverse

print(len(ans))
for s in ans:
    print(*s)


Measured memory_bytes: 3064
S = input()+'T'
X,Y = map(int,input().split())

xmove = []
ymove = []

tmp = 0
flag = True
for i in range(len(S)):
    if S[i]=='F':
        tmp += 1
    elif flag and S[i]=='T':
        xmove.append(tmp*2)
        tmp = 0
        flag = False
    else:
        ymove.append(tmp*2)
        tmp = 0
        flag = True
        
if xmove:
    x0 = xmove.pop(0)//2
else:
    x0 = 0

xgoal = sum(xmove)//2+X-x0
ygoal = sum(ymove)//2+Y

def subsetsum(arr,s):
    if not arr or s < 0:
        if s==0:
            return True
        else:
            return False
    dp = [[0 for j in range(s+1)] for i in range(len(arr)+1)]
    dp[0][0] = 1
    for i in range(1,len(arr)+1):
        for j in range(s+1):
            if j-arr[i-1]>=0:
                dp[i][j] = (dp[i-1][j-arr[i-1]] | dp[i-1][j])
            else:
                dp[i][j] = dp[i-1][j]
    return dp[-1][s]
    
if subsetsum(xmove,xgoal) and subsetsum(ymove,ygoal):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 168968
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
#define FOR(I,A,B) for(int I=int(A);I<int(B);++I)
#define FORR(I,A,B) for(int I=int(B-1);I>=int(A);--I)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	set<int> s,h,c,d;
	FOR(i,1,14){
		s.insert(i);
		h.insert(i);
		c.insert(i);
		d.insert(i);
	}
	FOR(i,0,n){
		char ch;
		int x;
		cin >> ch >> x;
		if(ch=='S')s.erase(x);
		if(ch=='H')h.erase(x);
		if(ch=='C')c.erase(x);
		if(ch=='D')d.erase(x);
	}
	for(int x:s)cout << "S " << x << endl;
	for(int x:h)cout << "H " << x << endl;
	for(int x:c)cout << "C " << x << endl;
	for(int x:d)cout << "D " << x << endl;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
#include <iostream>
//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;
ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
 
int main(){
    
    ll a,b,ans=1;
    cin>>a>>b;
    
    while(ans!=0){
        ans=a%b;
        a=b;
        b=ans;
    }
    cout<<a<<endl;
    
}


Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
static const int MAX=100000;
static const int NIL=-1;

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r,int c){
    stack<int>S;
    S.push(r);
    color[r]=c;
    while(!S.empty()){
        int u=S.top();
        S.pop();
        for(int i=0;i<G[u].size();i++){
            int v=G[u][i];
            if(color[v] == NIL){
                color[v]=c;
                S.push(v);
            }
        }
    }
}
void assignColor(){
    int id=1;
    for(int i=0;i<n;i++)
        color[i]=NIL;
    for(int u=0;u<n;u++)
        if(color[u]==NIL)
            dfs(u,id++);
}
int main(void){
    int s,t,m,q;
    scanf("%d %d",&n,&m);
    for(int i=0;i<m;i++){
        scanf("%d %d",&s,&t);
        G[s].push_back(t);
        G[t].push_back(s);
    }
    assignColor();
    scanf("%d",&q);
    for(int i=0;i<q;i++){
        scanf("%d %d",&s,&t);
        if(color[s] == color[t])
            puts("yes");
        else
            puts("no");
    }
    return 0;
}

Measured memory_bytes: 9060
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,0,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
 
int modFac(int x){
    if(x==1)return 1;
    else return x%MOD*modFac(x-1)%MOD;
}

signed main(){
    int N,M;cin>>N>>M;
    if(M<N)swap(N,M);
    if(M-N>1)cout<<0<<endl;
    else{
        int ans=modFac(M)%MOD*modFac(N)%MOD;
      	if(M==N)ans=ans*2%MOD;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 1792
let id x = x

let n = Scanf.scanf "%d\n" id

let a = Array.init n (fun _ -> Scanf.scanf " %d" id)

let () = 
  let ans = Array.fold_left (fun v i -> if i = (v + 1) then v + 1 else v) 0 a in
  print_int @@ if ans = 0 then -1 else n - ans

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

using namespace std;

int main()
{
    string O;
    string E;
    string res;
    int num;
    cin >> O >> E;
    for(int i = 0; i < E.length(); i++)
    {
        //cout << O[i] << E[i];
        res += O[i];
        res += E[i];
        num = i;
    }
    if(O.length() != E.length())
    {
        //cout << O[num+1];
        res += O[num+1];
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
struct Node{
	int key;
	Node *prev,*next;
};

Node *nil;

void init(){
	nil=(Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void insert(int key){
	Node *x=(Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev= x;
	x->prev = nil;
	nil->next =x; 
}

void deleteFirst(){
	Node *f = nil->next;
	nil->next = f->next;
	f->next->prev = nil;
	free(f);
}

void deleteLast(){
	Node *l = nil->prev;
	l->prev->next = nil;
	nil->prev = l->prev;
	free(l);
}
void deleteNode(int key){
	Node *cur = nil->next;
	while(cur->key != key && cur != nil){
		cur =cur->next;
	}
	if(cur == nil) return;
	cur->prev->next = cur->next;
	cur->next->prev = cur->prev;
	free(cur);
}

int main(){
	init();
	int o,n;
	char s[20];
	scanf("%d",&o);
	//getchar();
	while(o--){
		scanf("%s%d",s,&n);
		if(s[0]=='i'){
		//	scanf("%d",&n);
		//	getchar();
			insert(n);
		}
		else if(s[0]=='d'&&s[6]=='F'){
			deleteFirst();
	//		getchar();
		}
		else if(s[0]=='d'&&s[6]=='L'){
			deleteLast();
		//	getchar();
		}
		else if(s[0]=='d'){
		//	scanf("%d",&n);
	//		getchar();
			deleteNode(n);
		}
	}
	Node *cur=nil->next;
	while(cur != nil){
		printf("%d",cur->key);
		cur = cur->next;
		if(cur != nil) printf(" ");
	}
	printf("\n");
} 


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

int main(){
    string ans="Yes";
    int n;
    cin >> n;
    vector<string> w(n);
    rep(i,n) cin >> w[i];
    rep(i,n-1){
        if(w[i+1][0]!=w[i][w[i].size()-1]){
            ans="No";
        }
    }
    sort(w.begin(),w.end());
    rep(i,n-1){
        if(w[i]==w[i+1])
            ans="No";
    }
    cout << ans << endl;
    return 0;
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int N;
    cin >> N;

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

    vector<array<ll, 2>> dp(N);
    dp[0][0] = a[0];
    dp[0][1] = LLONG_MIN / 2;

    for (int i = 1; i < N; i++) {
        dp[i][0] = max(dp[i-1][0], dp[i-1][1]) + a[i];
        dp[i][1] = max(dp[i-1][0] - 2 * a[i-1], dp[i-1][1] + 2 * a[i-1]) - a[i];
    }

    cout << max(dp[N - 1][0], dp[N - 1][1]) << endl;

    return 0;
}



Measured memory_bytes: 2176
#include <stdio.h>

int main()
{
	int i, H, W, C[2], D[2];
	char S[1010][1010] = {};
	scanf("%d %d", &H, &W);
	scanf("%d %d", &(C[0]), &(C[1]));
	scanf("%d %d", &(D[0]), &(D[1]));
	for (i = 5; i < H + 5; i++) scanf("%s", &(S[i][5]));
	
	short q[5000001][2];
	int j, k, l, dist[1010][1010], head, tail;
	for (i = 5; i < H + 5; i++) {
		for (j = 5; j < W + 5; j++) dist[i][j] = 1000000;
	}
	dist[C[0]+4][C[1]+4] = 0;
	q[2500000][0] = C[0] + 4;
	q[2500000][1] = C[1] + 4;
	for (head = 2500000, tail = 2500001; head < tail; head++) {
		i = q[head][0];
		j = q[head][1];
		
		if (S[i-1][j] == '.' && dist[i-1][j] > dist[i][j]) {
			dist[i-1][j] = dist[i][j];
			q[head][0] = i - 1;
			q[head--][1] = j;
		}
		if (S[i+1][j] == '.' && dist[i+1][j] > dist[i][j]) {
			dist[i+1][j] = dist[i][j];
			q[head][0] = i + 1;
			q[head--][1] = j;
		}
		if (S[i][j-1] == '.' && dist[i][j-1] > dist[i][j]) {
			dist[i][j-1] = dist[i][j];
			q[head][0] = i;
			q[head--][1] = j - 1;
		}
		if (S[i][j+1] == '.' && dist[i][j+1] > dist[i][j]) {
			dist[i][j+1] = dist[i][j];
			q[head][0] = i;
			q[head--][1] = j + 1;
		}

		for (k = i - 2; k <= i + 2; k++) {
			for (l = j - 2; l <= j + 2; l++) {
				if (S[k][l] == '.' && dist[k][l] > dist[i][j] + 1) {
					dist[k][l] = dist[i][j] + 1;
					q[tail][0] = k;
					q[tail++][1] = l;
				}
			}
		}
	}
	
	if (dist[D[0]+4][D[1]+4] < 1000000) printf("%d\n", dist[D[0]+4][D[1]+4]);
	else printf("-1\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 8568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
ll a[200010];
int main() {
	ll n,t;
	cin>>n>>t;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	ll ans=0;
	ll s=a[0],e=s+t;
	for(int i=1;i<n;i++){
		ll now=a[i];
		if(now<e){
			e=now+t;
			continue;
		}
		ans+=e-s;
		s=now,e=s+t;
	}
	ans+=e-s;
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }

int main(void){
    // Your code here!
    string s,t;
    cin >> s >> t;
    int a,b;
    cin >> a >> b;
    string u;
    cin >> u;
    if (u == s) cout << a-1 << ' ' << b << endl;
    else cout << a << ' ' << b-1 << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
using namespace std;
int a[13],b[13],c[13],flag;
void dfs(int step,int bn,int cn)
{
    if(step==10){
        flag=1;
        return ;
    }
    if(flag) return ;
    if(a[step]>b[bn-1]){
    	b[bn]=a[step];
    	dfs(step+1,bn+1,cn);
	}
    if(a[step]>c[cn-1]){
    	c[cn]=a[step];
    	dfs(step+1,bn,cn+1);
	}
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        flag=0;
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        for(int i=0;i<10;i++)
            scanf("%d",&a[i]);
        dfs(0,1,1);
        if(flag) printf("YES\n");
        else printf("NO\n");
    }
	return 0;
}

Measured memory_bytes: 2552
from datetime import datetime
while True:
    y1,m1,d1,y2,m2,d2 = map(int,raw_input().split())
    if any(i<0 for i in (y1,m1,d1,y2,m2,d2)):
        break
    print (datetime(y2,m2,d2) - datetime(y1,m1,d1)).days

Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define FOR(i,a,b) for(int i=(a); i<=(b); i++)
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define chmin(a,b) if((a)>(b)) (a)=(b);
#define chmax(a,b) if((a)<(b)) (a)=(b);
#define vi vector<int>
#define pii pair<int,int>
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define pb push_back
#define pf push_front
int gcd(int a,int b){/*a>=0,b>=0,￢(a=b=0)*/
  while(min(a,b)>0){if(a<b)swap(a,b);a%=b;}return max(a,b);
}
int dx[]={1,0,-1,0,1,-1,-1,1};
int dy[]={0,1,0,-1,1,1,-1,-1};
const int MOD = 1e9+7;
const long long INF = 1e18+10;

/*--------------------------------------------------------------------*/

signed main(){
	string s;
	cin>>s;
	int n=s.size()+1;

	vi a;
	if(s[0]=='>'){
		a.pb(0);
	}

	int tmp=1;
	rep(i,n-2){
		if(s[i]==s[i+1]) tmp++;
		else{
			a.pb(tmp);
			tmp=1;
		}
	}
	a.pb(tmp);
	if(a.size()%2==1) a.pb(0);



	int ans=0;

	rep(i,a.size()/2){
		int ma=max(a[2*i],a[2*i+1]);
		int mi=min(a[2*i],a[2*i+1]);

		ans+=ma*(ma+1)/2;
		if(mi>0) ans+=mi*(mi-1)/2;
	}
	cout<<ans<<endl;

	// rep(i,a.size()){
	// 	cout<<' '<<a[i];
	// }
	// cout<<endl;


	return 0;
}


Measured memory_bytes: 6184
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1000000007;

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

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

int main() {
	int a,b;
	cin >> a >> b;
	int add = a+b, sub = a-b, mul = a*b;
	cout << max(max(add,sub),mul);
	return 0;
}



Measured memory_bytes: 256
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  a = list(map(int, readline().split()))
  a.sort(reverse=True)
  ans = 0
  for i in range(len(a)-1):
    ans += a[i]-a[i+1]
  print(ans)
  
  
  
if __name__ == '__main__':
  main()

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

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    string s[h];
    for (int i = 0; i < h; i++) {
        cin >> s[i];
    }

    int ans = h * w;
    for (int i = 0; i < (1<<(h - 1)); i++) {
        int cnt = 0;
        bool ok = true;
        vector<int> d;
        for (int j = 0; j < h - 1; j++) {
            if ((i & (1<<j)) != 0) {
                cnt++;
                d.push_back(j);
            }
        }
        d.push_back(h - 1);
        int m = d.size();

        int pre[m], cur[m];
        for (int i = 0; i < m; i++) {
            pre[i] = cur[i] = 0;
        }
        for (int j = 0; j < w; j++) {
            int start = 0;
            for (int x = 0; x < m; x++) {
                for (int y = start; y <= d.at(x); y++) {
                    if (s[y][j] == '1') cur[x]++;
                }
                start = d.at(x) + 1;
            }
            for (int x = 0; x < m; x++) {
                if (cur[x] > k) {
                    ok = false;
                }
            }
            if (!ok) break;

            bool cut = false;
            for (int x = 0; x < m; x++) {
                if (pre[x] + cur[x] > k) {
                    cut = true;
                }
            }
            if (cut) {
                cnt++;
                for (int x = 0; x < m; x++) {
                    pre[x] = cur[x];
                    cur[x] = 0;
                }
            } else {
                for (int x = 0; x < m; x++) {
                    pre[x] += cur[x];
                    cur[x] = 0;
                }
            }
        }

        if (ok) ans = min(ans, cnt);
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, n) for(int i=n; i>=0; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    int n;
    int g[110][2];
    cin >> n;
    rep(y, 2){
        rep(x, n){
            cin >> g[x][y];
        }
    }

    ll res = 0;
    rep(i, n){
        ll cnt = 0;
        rep(j, i+1){
            cnt += g[j][0];
        }
        reps(k, i, n){
            cnt += g[k][1];
        }
        res = max(res, cnt);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set> 
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <iomanip>
using namespace std;
#define assem99 ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define ld long double
#define ii pair<int, int>
#define vii vector<ii>
#define f(i,a,b) for(int i=a; i<b; i++)
#define F first
#define S second
#define sz(a) (int)(a).size()
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
int x[] = { 0, -1, 0, 1, -1, 1, -1, 1 };
int y[] = { -1, 0, 1, 0, 1, -1, -1, 1 };
const int MOD = 1e9 + 7, N = 2e5 + 5;
const double pi = acos(-1);

int main()
{
	assem99;

	int arr[N];
	int n, k; cin >> n >> k;
	f(i, 0, n) cin >> arr[i];
	int ans = 1e9;
	sort(arr, arr + n);
	f(i, k - 1, n) ans = min(ans, arr[i] - arr[i - (k - 1)]);
	cout << ans;

	return 0;
}

Measured memory_bytes: 640
#include<iostream>

int main(){
  int n;
  std::cin>>n;
  int res = n%10;
  if(res==2 || res==4 || res==5 || res==7 || res==9)
    std::cout<<"hon";
  else if(res==0 || res==1 || res==6 || res==8)
    std::cout<<"pon";
  else if(res==3)
    std::cout<<"bon";
}


Measured memory_bytes: 3628
N = int(input())
A = input()
B = input()
C = input()

ans = 0

for i in range(N):
    if A[i] == B[i] and B[i] != C[i]:
        ans += 1
    elif A[i] != B[i] and B[i] == C[i]:
        ans += 1
    elif A[i] == C[i] and B[i] != C[i]:
        ans += 1
    elif A[i] != B[i] and B[i] != C[i]:
        ans += 2
print(ans)

Measured memory_bytes: 3064
import sys

sys.setrecursionlimit(10**9)

def dps(road,dist,node,d):
    for x in road[node]:
        if dist[x]<0:
            dist[x]=d
            dps(road,dist,x,d+1)
    
N=int(input())
road=[[] for _ in range(N)]
f_d=[-1 for _ in range(N)]
s_d=[-1 for _ in range(N)]
f_d[0]=0
s_d[-1]=0

for i in range(N-1):
    a,b=list(map(int,input().split()))
    road[a-1].append(b-1)
    road[b-1].append(a-1)

dps(road,f_d,0,1)
dps(road,s_d,N-1,1)

white=0
black=0

for i in range(N):
    if f_d[i]<=s_d[i]:
        black+=1
    else:
        white+=1

if black>white:
    print('Fennec')
else:
    print('Snuke')

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

int main() {
	ll n;
	cin>>n;
	vector<ll>a,ans;
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		a.push_back(now);
	}
	while(a.size()){
		bool ch=false;
		for(ll i=a.size()-1;i>=0;i--){
		//	cout << "K"<<endl;
			if(a[i]==i+1){
				ans.push_back(a[i]);
				a.erase(a.begin()+i);
				ch=true;
				break;
			}
		}
		if(ch==false){
			cout << -1;
			return 0;
		}
	}
	reverse(ans.begin(),ans.end());
	for(ll i=0;i<n;i++){
		cout << ans[i]<<endl;
	}
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;

bool C(ll X, ll M, vll &A){
    ll N = A.size();
    ll cnt = 0;
    REP(i, N){
        cnt += A.end() - lower_bound(ALL(A), X-A[i]);
    }
    if(cnt >=M)
        return true;
    else
        return false;
}

void solve(long long N, long long M, std::vector<long long> A){
    sort(ALL(A));
    ll lo = 0, hi = 2*A.back()+1;
    while(hi - lo > 1){
        ll mid = (lo + hi)/2;
        if(C(mid, M, A))
            lo = mid;
        else
            hi = mid;
    }
    ll X= lo;

    ll cnt = 0, res = 0;
    vll S(N+1, 0);
    REP(i, N){
        S[i+1] = S[i]+A[i];
    }
    //* find >= X+1 and sum them all/ count them all
    REP(i, N){
        auto it = upper_bound(ALL(A), X-A[i]);
        ll tmp = A.end()-it;
        cnt += tmp;
        res += S[N] - S[it-A.begin()];    
        res += tmp * A[i];
    }

    res += X * (M - cnt);
    cout << res << endl;
}

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


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

vector<string>v;
string str;
map<string, int>mp;

int main()
{
    int k;
    string temp;

    cin >> str;
    cin >> k;


    for ( int i = 0; i < str.size(); i++) {
        temp = "";

        for ( int j = 0; i + j < str.size() && j < k; j++) {
            temp += str[i + j];
            if ( mp.count(temp) == 0 ) {
                mp[temp] = 1;
                v.push_back(temp);
            }
        }
    }

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

    
    cout << v[k - 1] << endl;

    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string s;
    int shf;
    int tmp;
    while (1) {
        int sum = 0;
        cin >> s;
        if (s == "-") break;
        cin >> shf;
        for (int i = 0; i < shf; i++) {
            cin >> tmp;
            sum += tmp;
        }
        tmp = sum % s.length();
        string ans = s.substr(tmp, s.length()) + s.substr(0, tmp);
        cout << ans << endl;
    }
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int last = -1;
	int N; cin >> N;
	ll total = 0;
	F0R(i, N) {
		int x; cin >> x;
		if (x > last) {
			last = x;
		} else {
			total += last - x;
		}
	}
	print(total);
}

Measured memory_bytes: 3652
K,N = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
dist = []
for i in range(N-1):
    dist.append([A[i+1]-A[i],i])
dist.sort()
ind = dist[-1][1]
ans = min(A[-1]-A[0],A[ind]+abs(K-A[ind+1]))

print(ans)

Measured memory_bytes: 38732
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++) 
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int lcm( int a, int b )
{
	int temp = __gcd( a, b );

	return temp ? ( a / temp * b ) : 0;
}
int main()
{
	int a, b;
	while( cin >> a >> b )
	{
		cout << __gcd( a, b ) << " " << lcm( a, b ) << endl;
	}
	return 0;
}

Measured memory_bytes: 3016
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main() {
    int N; cin >> N;
    int x[N], y[N];
    for (int i = 0; i < N; i++) cin >> x[i] >> y[i];

    double d = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            double dx = x[j] - x[i], dy = y[j] - y[i];
            d += pow(dx*dx + dy*dy, 0.5) * 2 / N;
        }
    }
    cout << fixed << setprecision(10) << d << endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Map<Integer, Integer> eMap = new HashMap<>();
        Map<Integer, Integer> oMap = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            if ((i + 1) % 2 == 0) {
                eMap.merge(temp, 1, Integer::sum);
            } else {
                oMap.merge(temp, 1, Integer::sum);
            }
        }
        List<Map.Entry<Integer, Integer>> eList = new ArrayList<>(eMap.entrySet());
        List<Map.Entry<Integer, Integer>> oList = new ArrayList<>(oMap.entrySet());
        eList.sort(Map.Entry.comparingByValue());
        oList.sort(Map.Entry.comparingByValue());
        int eMax = eList.get(eList.size() - 1).getKey();
        int oMax = oList.get(oList.size() - 1).getKey();
        int ans = 0;
        if (eMax == oMax) {
            if (eMap.get(eMax).compareTo(oMap.get(oMax)) > 0) {
                ans += (n / 2) - eMap.get(eMax);
                if (oList.size() == 1) {
                    ans += oMap.get(oMax);
                } else {
                    ans += (n / 2) - oList.get(oList.size() - 2).getValue();
                }
            } else if (eMap.get(eMax).compareTo(oMap.get(oMax)) < 0) {
                ans += (n / 2) - oMap.get(oMax);
                if (eList.size() == 1) {
                    ans += eMap.get(eMax);
                } else {
                    ans += (n / 2) - eList.get(eList.size() - 2).getValue();
                }
            } else {
                ans += (n / 2) - oMap.get(oMax);
                if (eList.size() == 1) {
                    ans += eMap.get(eMax);
                } else if (eList.get(eList.size() - 2).getValue().compareTo(oList.get(oList.size() - 2).getValue()) > 0) {
                    ans += (n / 2) - eList.get(eList.size() - 2).getValue();
                } else {
                    ans += (n / 2) - oList.get(oList.size() - 2).getValue();
                }
            }
        } else {
            ans += (n / 2) - oList.get(oList.size() - 1).getValue();
            ans += (n / 2) - eList.get(eList.size() - 1).getValue();
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 52448
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef multiset<int> MS;
typedef queue<int> Q;

int main(){
    int n; cin>>n;
    int p[n];
    for(int i=0; i<n; i++)
        cin >> p[i];
    int cnt = 0;
    for(int i=1; i<n-1; i++){
        int x = max(p[i-1], p[i+1]);
        int y = min(p[i-1], p[i+1]);
        if(p[i] < x && p[i] > y)
            cnt++;
    }
    OUT(cnt);
}

Measured memory_bytes: 256