akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    vector<int> viEdge(n);
    for(int i = 0; i < n; i++){
        scanf("%d", &viEdge[i]);
    }
    
    if(viEdge.size() < 3){
        printf("0");
        return 0;
    }
    
    int nAns = 0;
    for(int i = 0; i < viEdge.size() - 2; i++){
        for(int j = i+1; j < viEdge.size() - 1; j++){
            for(int k = j+1; k < viEdge.size(); k++){
                if(viEdge[i] == viEdge[j] ||
                   viEdge[j] == viEdge[k] ||
                   viEdge[k] == viEdge[i]){
                    continue;
                }
                if(viEdge[i] < viEdge[j]+viEdge[k] &&
                   viEdge[j] < viEdge[k]+viEdge[i] &&
                   viEdge[k] < viEdge[i]+viEdge[j] ){
                    nAns++;
                }
            }
        }
    }
  
    printf("%d", nAns);
  
    return 0;
}


Measured memory_bytes: 3224
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

bool kaibun(string s) {
	string a = s;
	reverse(a.begin(), a.end());
	if (a == s) return true;
	else return false;
}

int main() {
	double L;
	cin >> L;
	double ans = (L / 3) * (L / 3) * (L / 3);
	printf("%.8f", ans);
	return 0;
}

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

int main()
{
	int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << max(h2*60-h1*60 + m2-m1 - k,0) << endl;
	return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        long n = Long.parseLong(sc.next());
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long fig=0;
        long rest = 0;
        long ans = 0;
        fig = n / (a + b);
        ans = a * fig;
        rest = n % (a + b); 


        if(rest<=a){
            ans=ans + rest;
        }
        if(rest>a && rest< a+b){
            ans=ans + a;
        }

        System.out.println(ans);


    }
}

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

#define int long long
template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}
int ans=-1e18;

signed main(){
  int n,k;cin>>n>>k;
  vector<int> v(n),c(n);
  for(int i=0;i<n;i++){cin>>v[i];v[i]--;}
  for(int i=0;i<n;i++)cin>>c[i];
  vector<vector<int>>w;
  vector<int>used(n,0);
  for(int i=0;i<n;i++){
    if(used[i])continue;
    int tmp=0,sum=0;
    w.push_back(vector<int>(0));
    while(!used[i]){
      used[i]=1;
      w.back().push_back(c[i]);
      sum+=c[i];
      i=v[i];
    }
    int K=k,S=w.back().size();
    if(sum>0&&K/S>0)tmp+=(K/S-1)*sum;
    if(K>S)K=K%S+S;
    for(int j=0;j<S;j++){
      int tmp2=0;
      for(int l=0;l<K;l++){
        tmp2+=w.back()[(j+l)%S];
        chmax(ans,tmp+tmp2);
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int l = s.size(), i, j;
  for(i=0; i<l; ++i) if(s[i] == 'A') break;
  for(j=l-1; j>0; --j) if(s[j] == 'Z') break;
  cout << j-i+1 << endl;
}

Measured memory_bytes: 3748
NN, MM = list(map(int,input().split()))
ARR = [list(input().split()) for l in range(MM)]

bin = [0]*NN
done = [0]*NN

for ind in range(MM):
    if done[int(ARR[ind][0])-1] == 0:
        if ARR[ind][1] == 'WA':
            bin[int(ARR[ind][0])-1] += 1
        else:
            done[int(ARR[ind][0])-1] = 1

cbin = [x * y for (x,y) in zip(done,bin)]
print(sum(done), sum(cbin))

Measured memory_bytes: 101436
N=int(input())
H=list(map(int,input().split()))
count=0
a=[]
for i in range(1,N):
    if(H[i]<=H[i-1]):
        count+=1
    else:
        a.append(count)
        count=0
a.append(count)
a.sort(reverse=True)
print(a[0])

Measured memory_bytes: 15020
//Even Relation

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<P>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

graph g;

vector<int>ans;

//現在・一個前・色
void dfs(int v,int p,int c){
    ans[v]=c;
    for(auto i:g[v]){
        if(i.first==p)continue;
        else if(1 & i.second)dfs(i.first,v,c^1);
        else dfs(i.first,v,c);
    }
}

signed main (){
    int n;cin>>n;
    g.resize(n);
    ans.resize(n,0);
    rep(i,0,n-1){
        int a,b,c;cin>>a>>b>>c;
        a--;b--;
        g[a].pb(mp(b,c));
        g[b].pb(mp(a,c));
    }
    dfs(0,-1,0);
    rep(i,0,n)cout<<ans[i]<<nnn;
    return 0;
}

Measured memory_bytes: 13376
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int r = stdIn.nextInt();
		int d = stdIn.nextInt();
		int x = stdIn.nextInt();
		
		int[] reki = new int[11];
		reki[0] = x;
		
		for(int i = 1; i < reki.length; i++) {
			reki[i] = r*reki[i-1] - d;
		}
		
		for(int i = 1; i < reki.length; i++) {
			System.out.println(reki[i]);
		}
		
		
		
		
	}

}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  ll n;
  cin >> n;
  if(n%2==1){
    puts("0");
    return 0;
  }
  ll ans = 0;
  n /= 2;
  while (n > 0) {
    n /= 5;
    ans+=n;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3600
w, h, n = map(int, input().split())

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


f = [[0] * w for _ in range(h)]

for i in range(n):
    for x in range(w):
        for y in range(h):
            if xya[i][2] == 1 and x < xya[i][0]:
                f[y][x] = 1
            elif xya[i][2] == 2 and x >= xya[i][0]:
                f[y][x] = 1
            elif xya[i][2] == 3 and y < xya[i][1]:
                f[y][x] = 1
            elif xya[i][2] == 4 and y >= xya[i][1]:
                f[y][x] = 1

ans = 0
for i in range(h):
    for j in range(w):
        if f[i][j]:
            ans += 1
print(w * h - ans)


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

void solve() {
  int n, m;
  cin >> n >> m;
  vi a(n);
  rep(i, n) cin >> a[i];
  vl cum(n + 1);
  rep(i, n) cum[i + 1] = cum[i] + a[i];
  map<int, int> mp;
  rep(i, n + 1) mp[cum[i] % m]++;
  dump(mp);
  ll ans = 0;
  for (auto m : mp) {
    ans += ((ll)m.second * (m.second - 1) / 2);
  }
  cout << ans << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 4352
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

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

func readInt64() int64 {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return int64(i)
}

func readfloat64() float64 {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return float64(i)
}

func abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	sc.Split(bufio.ScanWords)

	n := readInt()
	d := make([]int, n)
	for i := 0; i < n; i++ {
		d[i] = readInt()
	}

	total := 0
	for i := 0; i < n-1; i++ {
		for j := i + 1; j < n; j++ {
			total += d[i] * d[j]
		}
	}
	fmt.Println(total)
}


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

int main(){
   string s;
   cin >> s;
   ll n,count=0,ans=0;
   n=s.size();
   while(count<n-1){
       if(s[count]==s[count+1]){
           if(count+1==n-1){
               break;
           }else{
               ans+=2;
               count+=3;
           }
        }else{
           ans++;
           count++;
       }
   }
   if(count!=n)
    ans++;
   cout << ans;
}

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

typedef long long int ll;

using namespace std;

char lowCaseAlpha[] = {' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
void fast() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
int main()
{
    fast();

    //freopen("out.txt", "w", stdout);

    ll n, m;
    cin >> n >> m;
    n--;m--;
    cout << n * m;
    
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <algorithm>

using std::cin;
using std::cout;
using std::vector;
using std::for_each;
using std::generate;
using std::next_permutation;

int main() {
	int n;
	cin >> n;
	vector<int> v(n);
	generate(v.begin(),v.end(),[](){
		static int i = 1;
		return i++;
	});
	for_each(v.begin(),v.end(),[n](int _e){
		static int j = 1;
		cout << _e << (j++ == n ? "\n" : " ");
	});
	while (next_permutation(v.begin(),v.end())) {
		int k = 1;
		for_each(v.begin(),v.end(),[&k,n](int _e){cout << _e << (k++ == n ? "\n" : " ");});
	}
}


Measured memory_bytes: 3088
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair

/*int P[10010];
void init(int n){//Union-find
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？
//セグメント木？？
*/

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

#define mod 1000000007
/*ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination//ただしfは用意してね
*/


/*
// 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;
*/

//cerrはコメントアウトしなくても通る

int s[52][52];

int main(){
    int h,w;
    cin >> h>>w;

    rep2(i,h){
        rep2(j,w){
            char d;
            cin >> d;
            if(d=='#'){
                s[i][j]=1;
            }else{
                s[i][j]=0;
            }
        }
    }
    rep2(i,h){
        rep2(j,w){
            if(s[i][j]==1){
                if(s[i][j-1]==1||s[i][j+1]==1||s[i-1][j]==1||s[i+1][j]==1){
                    continue;
                }else{
                    cout<<"No"<<endl;
                    //cerr<<i<<' '<< j<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int h,w,n;
char s1[200100],s2[200100];
int main(){
	scanf("%d%d%d",&h,&w,&n);
	int x,y;
	scanf("%d%d",&x,&y);
	int xmi=x,xma=x,ymi=y,yma=y;
	scanf("%s%s",s1,s2);
	int fg=0;
	for(int i=0;i<n;i++){
		if(s1[i]=='L'){
			ymi-=1;
		}
		else if(s1[i]=='R'){
			yma+=1;
		}
		else if(s1[i]=='U'){
			xmi-=1;
		}
		else if(s1[i]=='D'){
			xma+=1;
		}
		if(xmi<=0 || xma>h || ymi<=0 || yma>w){
			fg=1;
			break;
		}
		if(s2[i]=='L'){
			if(yma>1)yma-=1;
		}
		else if(s2[i]=='R'){
			if(ymi<=w-1)ymi+=1;
		}
		else if(s2[i]=='U'){
			if(xma>1)xma-=1;
		}
		else if(s2[i]=='D'){
			if(xmi<=h-1)xmi+=1;
		}
	}
	if(fg) printf("NO\n");
	else printf("YES\n");
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

void func(double a ,double b,double c,double d,double e,double f,double* x,double* y){
	double temp;
	*y=(c*d-a*f)/(b*d-a*e)+0.00001;
	temp=*y;
	*x=(c-b*temp)/a+0.00001;
}

int main(void){
	double a,b,c,d,e,f,j,k;
	double *x=&j;
	double *y=&k;
	while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f) != EOF){
		//y=func(a,b,c,d,e,f);
		//x=(c-b*y)/a+0.00001;
		func(a,b,c,d,e,f,x,y);
		printf("%.3lf %.3lf\n",*x,*y);
	}
	return 0;
}

Measured memory_bytes: 656
# -*- coding: utf-8 -*-
a, b, c = map(int, raw_input().split())
k = int(raw_input())

num = [a, b, c]
max_number = max(num)

for i in range(len(num)):
    if max_number == num[i]:
        key = i

for i in range(k):
    num[key] *= 2

print sum(num)


Measured memory_bytes: 2568
#include<stdio.h>
int main(){
    char s[3+1];
    scanf("%s",s);
    if((s[0]=='S')&&(s[1]=='U')&&(s[2]=='N')){
        printf("7\n");
    }else if((s[0]=='M')&&(s[1]=='O')&&(s[2]=='N')){
        printf("6\n");
    }else if((s[0]=='T')&&(s[1]=='U')&&(s[2]=='E')){
        printf("5\n");
    }else if((s[0]=='W')&&(s[1]=='E')&&(s[2]=='D')){
        printf("4\n");
    }else if((s[0]=='T')&&(s[1]=='H')&&(s[2]=='U')){
        printf("3\n");
    }else if((s[0]=='F')&&(s[1]=='R')&&(s[2]=='I')){
        printf("2\n");
    }else if((s[0]=='S')&&(s[1]=='A')&&(s[2]=='T')){
        printf("1\n");
    }
}

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

pll A[100005];

int main()
{
    ll N;
    cin >> N;
    REP(i, N)
    {
        ll a;
        cin >> a;
        A[i] = pll(a, i);
    }
    sort(A, A + N, [](pll a, pll b) { return a.first < b.first; });

    ll ans = 0;
    REP(i, N)
    {
        if (i % 2 == A[i].second % 2)
            continue;
        ans++;
    }
    cout << ans / 2 << endl;
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
a = list(map(int,input().split()))
d = max(a)
f = d
for v in a:
  if abs(v-d/2) < abs(f-d/2):
    f = v
  elif abs(v-d/2) == abs(f-d/2):
    f = min(f,v)
print(d,f)

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

int main(){
  long long T;
  cin >> T;
  
  for(int i=0;i<T;i++){
    long long N,M,A,B;
    cin >> N >> M >> A >> B;
    cout << floor_sum(N,M,A,B) << endl;
  }
  return 0;
}


Measured memory_bytes: 3640
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
# from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

n,x = MI()

def mycalc(n,x):
    M = 4*(2**n) - 3
    m = (M//2) + 1
    if n==0:
        return 1
    if x==1:
        return 0
    elif x>=2 and x<m:
        return mycalc(n-1,x-1)
    elif x==m:
        return mycalc(n-1,x-2) + 1
    elif x>m and x<M:
        return mycalc(n-1,x-m) + ( 2**(n+1) - 2 )//2 + 1
    elif x==M:
        return 2**(n+1) - 1
    else:
        print("E")
ans = mycalc(n,x)
print(ans)

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

namespace AtTest.ABC_165
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int k = ReadInt();
            int[] ab = ReadInts();
            int a = ab[0];
            int b = ab[1];
            if (a % k == 0 || b % k == 0)
            {
                WriteLine("OK");
            }
            else
            {
                int aDiv = a / k;
                int bDiv = b / k;
                WriteLine(aDiv < bDiv ? "OK" : "NG");
            }
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 27544
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.ByteString.Char8 as B
import Data.Bool
import Data.Char
import Data.Maybe

main :: IO ()
main = B.interact $ squared . conn

conn :: B.ByteString -> Int
conn = fst . fromJust . B.readInt . B.filter isDigit

squared :: Int -> B.ByteString
squared n = bool "No" "Yes" $ go n 0 n

go :: Int -> Int -> Int -> Bool
go n l u
  | m ^ 2 == n || (m + 1) ^ 2 == n = True
  | u - l <= 1 = False
  | m ^ 2 < n = go n m u
  | m ^ 2 > n = go n l m
  where m = (l + u) `div` 2
  


Measured memory_bytes: 380
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

nn  = inputs[0][0]
lst = inputs[1]

# body
if $debugFlag
  p nn
  p lst
end

dp = [0]

for i in 1..nn-1
  cand = []
  if i >= 2
    cand << ((lst[i] - lst[i-2]).abs + dp[i-2])
  end
  cand << ((lst[i] - lst[i-1]).abs + dp[i-1])
  dp[i] = cand.min
end

puts dp[-1]


Measured memory_bytes: 11924
n = int(input())
lst = [ int(i) for i in input().split() ]

visited = {}

for d in lst:
  if d in visited.keys():
    visited[d] += 1
  else:
    visited[d] = 1
count = 0
for d in visited.keys():
  count += int(visited[d]*(visited[d]-1)/2)
for d in lst:
  v = visited[d] - 1
  ans = count - v
  print(ans)

Measured memory_bytes: 32232
rr = raw_input
rri = lambda: int(raw_input())
rrm = lambda: map(int, raw_input().split())


def solve(N, A):
    cur = 0
    ans = bns = 0
    for x in reversed(A):
        if x >= cur:
            cur = x
            bns += 1
            ans = max(ans, bns)
        else:
            cur = x
            bns = 1
            ans = max(ans, bns)
    return max(ans-1, 0)

print solve(rri(),rrm())


Measured memory_bytes: 42476
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
int m=-2;
void p(int n)
{
int k=n%m;n=n/m;
if (k<0) k-=m,n++;
if (n!=0) p(n);
putchar(k>9?k+55:k+48);
}

int main(){
int n=read();
p(n);
}


Measured memory_bytes: 256
def main():
    X, Y, A, B, C = map(int, input().split())
    *P, = map(int, input().split())
    *Q, = map(int, input().split())
    *R, = map(int, input().split())

    P.sort(reverse=True)
    Q.sort(reverse=True)

    ans = sum(sorted(P[:X] + Q[:Y] + R, reverse=True)[:X + Y])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 29448
#!/usr/bin/env python3
import bisect

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

p_list = [0]*100

for i in p:
    p_list[i-1] = 1

p_list = [0]+p_list+[0]

dis = 100
index = -1
for i, j in enumerate(p_list):
    if j == 1:
        continue
    # print(i+1, abs(x-(i+1)))
    if dis > abs(x-i):
        dis = abs(x-i)
        index = i
        # index=i

print(index)


Measured memory_bytes: 9068
#include <stdio.h>
int main(void)
{
  int N, a[10003], max=0, min=1000, i;
  scanf("%d", &N);
  for(i = 0; i < N; i++){
    scanf("%d", &a[i]);
    if(max < a[i]) max = a[i];
    if(min > a[i]) min = a[i];
  }
  printf("%d\n", max-min);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int main()
{
	int n,m,k;
	ios::sync_with_stdio(false);
	int a[4];
	cin>>a[1]>>a[2]>>a[3];
	sort(a+1,a+4);
	cout<<a[2]-a[1]+a[3]-a[2]<<endl;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>

using namespace std;
typedef char CHAR;
typedef unsigned char UCHAR;
typedef short SHORT;
typedef unsigned short USHORT;
typedef int INT;
typedef unsigned int UINT;
typedef long long LLONG;
typedef unsigned long long ULLONG;

#define LengthOf(x)    (sizeof(x) / sizeof(x[0]))

#if 1
//No.4
void swap(int *a, int *b)
{
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int check(int x, int y, int z) 
{
	if (x > y) { swap(x, y); }
	if (x > z) { swap(x, z); }
	if (y > z) { swap(y, z); }

	if (y - x != z - y) {
		return 1;
	}
	else {
		return 0;
	}
}

int main()
{
	int N;
	char S[4000+16];
	int ansCount = 0;
	int* R = new int[4000];
	int R_cnt = 0;
	int* G = new int[4000];
	int G_cnt = 0;
	int* B = new int[4000];
	int B_cnt = 0;
//	int* RGB = new int[4000];

	cin >> N;
	cin >> S;

	for (int i = 0; i < N; ++i) {
		if (S[i] == 'R') { R[R_cnt++] = i; /*RGB[i] = 0;*/ }
		else if (S[i] == 'G') { G[G_cnt++] = i; /*RGB[i] = 1;*/ }
		else { B[B_cnt++] = i; /*RGB[i] = 2;*/ }
	}

/*
	for (int r = 0; r < R_cnt; ++r) {
		for (int g = 0; g < G_cnt; ++g) {
			for (int b = 0; b < B_cnt; ++b) {
				if (check(R[r], G[g], B[b])) {
					ansCount++;
				}
			}
		}
	}

	cout << ansCount;
*/
	int NG_cnt = 0;
	for (int i = 0; i < N - 2; ++i) {
		for (int j = i + 1; j < N - 1; ++j) {
			int k = j + (j - i);
			if (k >= N) { break; }
			if (S[i] != S[j] && S[i] != S[k] && S[j] != S[k]) {
				NG_cnt++;
			}
		}
	}

	cout << ((LLONG)R_cnt * G_cnt * B_cnt - NG_cnt);

	delete[] R;
	delete[] G;
	delete[] B;
//	delete[] RGB;

	return 0;
}
#endif

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

int main() {
    ll N,x[50],y[50];
    cin>>N;
    for (int i(0);i<N;i++) cin>>x[i]>>y[i];
    ll ans(10000000000);
    for (int i(0);i<N-1;i++){ // i is first selectd
      for (int j(i+1);j<N;j++){ // j is second selected
        ll p = x[j]-x[i],q=y[j]-y[i];
        ll cnt(0);
        for (int in(0);in<N-1;in++){
          for (int jn(in+1);jn<N;jn++){
            if ((x[in]-x[jn]==p&&y[in]-y[jn]==q)||(x[jn]-x[in]==p&&y[jn]-y[in]==q))cnt++;
          }
        }
        ll tmp=N-cnt;
        ans=min(ans,tmp);
      }
    }
    if (N==1){
      cout<<1;
      return 0;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define INF -1000000001
using namespace std;
int N, F[100][10], P[100][11], s[10] = {0};
int dfs(int dpt, int cnt) {
  if(dpt > 9) {
    if(!cnt) return INF;
    int sum = 0, m[100] = {0};
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < 10; j++) {
        if(!s[j]) continue;
        m[i] += F[i][j];
      }
      sum += P[i][m[i]];
    }
    return sum;
  }
  s[dpt] = 0; int sum0 = dfs(dpt+1, cnt);
  s[dpt] = 1; int sum1 = dfs(dpt+1, cnt+1);
  return max(sum0, sum1);
}
int main() {
  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < 10; j++) scanf("%d", &F[i][j]);
  }
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < 11; j++) scanf("%d", &P[i][j]);
  }
  printf("%d", dfs(0, 0));
}

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

using namespace std;

const int maxn=2e5+5;

pair<int,int> p[maxn];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		p[i].first=x;p[i].second=i;
	}
	sort(p+1,p+1+n);
	for(int i=1;i<=n;i++){
		printf("%d ",p[i].second); 	
	}
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)

#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int h[1010];

signed main() {
	ios::sync_with_stdio(false);
	int n, i, t, a,ans,dif = INF;
	cin >> n >> t >> a;
	int cc = 1<<30;
	rep(i, n) {
		int x;
		cin >> x;
		int d = abs((t * 1000 - x * 6) - a * 1000);
		if (d < cc) {
			cc = d;
			ans = i;
		}
	}
	cout << ans+1 << endl;
	return 0;
}

Measured memory_bytes: 256
import copy

n = int(input())
p = list(map(int, input().split()))
t = copy.deepcopy(p)

for i in range(n):
    for j in range(n):
        t[i], t[j] = t[j], t[i]
        if sorted(t) == t:
            print("YES")
            exit()
        t[j], t[i] = t[i], t[j]
        #t = p


print("NO")

Measured memory_bytes: 40048
import java.util.*;

//input a b c is a < b < c?
public class Main {
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		String[] input = sc.nextLine().split(" ");
		int [] abc = new int[input.length];
		for(int i = 0;i<abc.length;i++)
		{
			abc[i] = Integer.parseInt(input[i]);
		}
		String str;
		if(abc[0] < abc[2])
		{
			if(abc[1] < abc[2])
			{
				if(abc[0] < abc[1])
				{
					str = "Yes";
				}
				else
				{
					str = "No";
				}
			}
			else
			{
				str = "No";
			}
		}
		else
		{
			str = "No";
		}
		System.out.println(str);

		sc.close();
	}
}



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

#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

using ll = long long;
#define INF (1LL<<62)

auto dijkstra(vector<vector<pair<int, ll>>> const & graph, int start){
  vector<ll> dist(graph.size(), INF);
  priority_queue<pair<ll, int>,vector<pair<ll, int>>, greater<pair<ll, int>>> que;
  que.push({0, start});
  while(!que.empty()){
    ll d; int crr; tie(d, crr) = que.top(); que.pop();
    if(dist[crr] <= d) continue;
    dist[crr] = d;
    for(auto pair : graph[crr]){
      ll cost; int nxt; tie(nxt, cost) = pair;
      if(dist[nxt] - d <= cost) continue;
      que.push({d+cost, nxt});
    }
  }
  return dist;
}

int main(){ 
  int n, m, s, t;
  cin >> n >> m >> s >> t;
  s--, t--;
  vector<vector<pair<int,ll>>> graph_yen(n), graph_s(n);
  REP(i, m){
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    u--, v--;
    graph_yen[u].push_back({v, a});
    graph_yen[v].push_back({u, a});
    graph_s[u].push_back({v, b});
    graph_s[v].push_back({u, b});
  }
  vector<ll> dist_yen, dist_s;
  dist_yen = dijkstra(graph_yen, s);
  dist_s = dijkstra(graph_s, t);
  vector<ll> ans(n, 0);
  ll cost = INF;
  REPR(i, n-1){
    cost = min(cost, dist_yen[i] + dist_s[i]);
    ans[i] = cost;
  }
  REP(i, n){
    cout << ll(1e15 -ans[i]) << endl;
  }
  return 0;
}



Measured memory_bytes: 19712
MOD = 10 ** 9 + 7

def mod_pow(a, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return mod_pow(a, p // 2) ** 2 % MOD
    else:
        return a * mod_pow(a, p - 1) % MOD

def calc_comb(a, b):
    if b > a - b:
        return calc_comb(a, a - b)
    ans_mul, ans_div = 1, 1
    for i in range(b):
        ans_mul *= a - i
        ans_div *= i + 1
        ans_mul %= MOD
        ans_div %= MOD
    return ans_mul * mod_pow(ans_div, MOD - 2) % MOD

def main():
    N, M = map(int, input().split())
    i = 2
    ans = 1
    while i * i <= M:
        if M % i == 0:
            cnt = 0
            while M % i == 0:
                cnt += 1
                M //= i
            ans *= calc_comb(N + cnt - 1, N - 1)
            ans %= MOD
        i += 1
    if M > 1:
        ans *= calc_comb(N + 1 - 1, N - 1)
        ans %= MOD
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;
#define DEBUG(X) cerr<<__LINE__<<" "<<#X<<": "<<X<<endl;
#define REP(i,y) for(int i=0;i<(int)(y);i++)
#define REPP(i,y) for(int i=1;i<=(int)(y);i++)
#define sci(x) int x;scanf("%d",&x);
#define scii(x, y) int x,y;scanf("%d%d",&x,&y);
typedef long long ll;
vector<int> v;

void solve() {
  sci(N);
  REP(i,3*N) {
    sci(a);
    v.push_back(a);
  }
  sort(v.rbegin(), v.rend());
  ll sum=0;
  REP(i,N) {
    sum+=v[i*2+1];
  }
  printf("%lld\n",sum);
}

int main() {
  solve();
}

Measured memory_bytes: 2420
from collections import deque
s = input()
q = int(input())
right_side = deque()
left_side = deque()
is_reversed = False
for i in range(q):
    l = list(input().split())
    if l[0] == '1':
        is_reversed = not is_reversed
    else:
        if l[1] == '2':
            if is_reversed == False:
                right_side.append(l[2])
            else:
                left_side.appendleft(l[2])
        else:
            if is_reversed == False:
                left_side.appendleft(l[2])
            else:
                right_side.append(l[2])
ans = ''.join([''.join(left_side),s ,''.join(right_side)])
if is_reversed :
    ans = ans[::-1]
print(ans)
            

Measured memory_bytes: 6516
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int t = sc.nextInt();
			int p = sc.nextInt();
			int r = sc.nextInt();
			if( (t|p|r) == 0 ) break;
			
			int[][] wa = new int[t][p];
			Pair[] results = new Pair[t];
			for(int i=0;i<t;i++) results[i] = new Pair(i+1, 0, 0);
			for(int i=0;i<r;i++) {
				int tid = sc.nextInt()-1;
				int pid = sc.nextInt()-1;
				int time = sc.nextInt();
				String str = sc.next();
				if( str.equals("CORRECT")) {
					results[tid].penalty += time + wa[tid][pid] * 1200;
					results[tid].solved++;
				}
				else {
					wa[tid][pid]++;
				}
			}
			sort(results);
			for(Pair pairs: results) 
				System.out.println( pairs.id + " " + pairs.solved + " " + pairs.penalty );
			
		}
	}
	
	class Pair implements  Comparable<Pair> {
		int id, solved, penalty;
		Pair(int id, int solved, int penalty) {
			this.id = id;
			this.solved = solved;
			this.penalty = solved;
		}
		
		@Override
		public int compareTo(Pair p) {
			// TODO 自動生成されたメソッド・スタブ
			if( solved != p.solved ) return p.solved - solved;
			else {
				if( penalty != p.penalty ) return penalty - p.penalty;
			}
			return id - p.id;
		}
		
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 13000
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;


void solve()
{
   
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    int ans=a*c;
    ans=max(ans,a*d);
    ans=max(ans,b*c);
    ans=max(ans,b*d);
    cout<<ans<<endl;
    
    
    
}

int32_t main()
{
    IOS;
    
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}







Measured memory_bytes: 3652
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i,k;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>k;
  std::vector<ll> c(n);
  rep(i,n) cin>>c[i];
  ll ans = 0;
  rep(i,n) ans+=min(c[i],k-c[i])*2;
  cout<<ans<<endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
string s,s1;
ll ar[250007],cr[200098],a,b, test, sum,t,x=0,p,q,y,i,j,k=0,l,cnteven=0,w=0,cnt,br[200008];
int main()
{
    ll test;
ll m=9999999999;
cin>>a>>b;
cnt=0;
for(i=1;i<=a;i++)
{cin>>p;
for(j=1;j<=p;j++)
{
    cin>>ar[i];
    br[ar[i]]++;
    }
}
for(i=1;i<=b;i++)
    if(br[i]==a)
    cnt++;

cout<<cnt<<endl;

}





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

int main(){
int a,b,c,d;
cin >> a>>b>>c>>d;
while(a>0 || c>0 ){
	c -= b;
	if(c<=0) break;
	a -= d;
	if(a<=0) break;
}
if(c<=0) cout << "Yes" << endl;
else cout << "No" << endl;
}

Measured memory_bytes: 3544
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int a,b; cin>>a>>b;
    vector<vector<char>> bm(50,vector<char>(100,'#'));
    vector<vector<char>> wm(50,vector<char>(100,'.'));
    rep(i,a-1){
        bm[(i/50)*2][(i%50)*2]='.';
    }
    rep(i,b-1){
        wm[(i/50)*2+1][(i%50)*2]='#';
    }
    cout<<100<<" "<<100<<endl;
    rep(i,50){
        rep(j,100){
            cout<<bm[i][j];
        }
        cout<<endl;
    }
    rep(i,50){
        rep(j,100){
            cout<<wm[i][j];
        }
        cout<<endl;
    }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]

class Util():
    def round_up(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x

C = [[int(x)for x in cin.string().split()]  for y in range(3)]
for a1 in range(0,100 + 1):
    b1 = C[0][0] - a1
    b2 = C[0][1] - a1
    b3 = C[0][2] - a1
    a2 = C[1][0] - b1
    a3 = C[2][0] - b1
    m = [[a1 + b1,a1 + b2,a1 + b3],[a2 + b1,a2 + b2,a2 + b3],[a3 + b1,a3 + b2,a3 + b3]]
    if m == C:
        print("Yes")
        sys.exit()
print("No")

Measured memory_bytes: 38384
#include <iostream>

using namespace std;

int main () {
    int a, b, c, cnt = 0;

    cin >> a >> b >> c;

    for ( int x = a; x <= b; x++ ) {
        if ( c % x == 0 ) {
            cnt++;    // c????´???° : c???x??§????????¨?????????0?????????x
            // cout << "debug : " << x << '\n';
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 
#define PI 3.141592653589793238

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;
typedef gp_hash_table<long int,long int> HashTable;

int main(){
   IOS;
 /*    #ifndef ONLINE_JUDGE
         freopen("in.txt",  "r",  stdin);
         freopen("out.txt", "w", stdout);
     #endif */
   
  long int a,b,c;
  cin>>a>>b>>c;

  long int k;
  cin>>k;

  while(a >= b && k > 0){
    k--;
    b *= 2;
  }

  while(b >= c && k > 0){
    k--;
    c *= 2;
  }


  if(b > a && c > b)
    cout<<"Yes";
  else
    cout<<"No";

}

Measured memory_bytes: 3624
#include<iostream>
using namespace std;
int main()
{
  int A = 0, B = 0, C = 0, D = 0;
  cin >> A >> B >> C >> D;
  
  bool tkh_attack = true;
  
  while(A > 0 && C > 0)
  {
	if(tkh_attack)
	{
		C -= B;
		tkh_attack = false;
	}else{
		A -= D;
		tkh_attack = true;
	}
  }
  if(A > C)
  {
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3624
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll x, ll y){return x / gcd(x, y) * y % MOD;};

ll disit(ll N){
  ll res = 0;
  while(N > 0){
    res += N % 10;
    N /= 10;
  }
  return res;
}

int main(){
  int N, A, B; cin >> N >> A >> B;
  if(abs(A - B) % 2) cout << "Borys" << endl;
  else cout << "Alice" << endl;
}


Measured memory_bytes: 256