akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1000000005
#define MOD 1000000007
#define FF first
#define SS second
#define int long long int

using namespace std;
typedef long long ll;

ll gcd(ll loc, ll b)
{
    if(loc == 0LL)
        return b;
    if(b == 0LL)
        return loc;
    return gcd(b, loc%b);
}

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll modx(ll Base, ll exponent)
{
  ll ans = 1;
  if(Base == 1)
    return Base;
  while(exponent)
  {
    if(exponent & 1)
      ans = (ans * Base)%MOD;
    Base = (Base * Base)%MOD;
    exponent = exponent >> 1;
  }
  return ans;
}

ll inmodx(ll num)
{
  return (modx(num, MOD-2LL));
}

bool cmp(pii loc, pii b)//true for loc before b
{
  if(loc.SS < b.SS)
    return 1;
  if(loc.SS > b.SS)
    return 0;
  if(loc.FF <= b.FF)
    return 1;
  return 0;
}
int dp[500005],inp[500005];
signed main()
{   
    
  
   // freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(0); 
    cin.tie(0);
    cout.tie(0);
    
        int n,k;
        cin>>n;
        k=2;
        for(int i=1;i<=n;i++)
        {
          cin>>inp[i];
        }
        for(int i=2;i<=k+1;i++)
        {
          dp[i]=abs(inp[i]-inp[1]);
        }
        if(k<=n-2)
        {
          for(int i=k+2;i<=n;i++)
          {
            dp[i]=INF;
            for(int j=i-1;j>=(i-k);j--)
            {
              dp[i]=min(dp[i],dp[j]+abs(inp[i]-inp[j]));
            }
          }
        }
        cout<<dp[n]<<endl;
        return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll ans;

ll min(ll a, ll b, ll c)
{
    if(a<b)
    {
        return a<c?a:c;
    }
    else
    {
        return b<c?b:c;
    }
}

ll max(ll a, ll b, ll c)
{
    if(a>b)
    {
        return a>c?a:c;
    }
    else
    {
        return b>c?b:c;
    }
}

void cmp(ll ding,ll fanwei)
{
    for(ll i = 1 ; i < fanwei - 1 ; i++)
    {
        ll s1 = i * ding;
        ll shengxiadebian = fanwei - i;
        ll s_1 = (shengxiadebian / 2 + shengxiadebian % 2) * ding ;
        ll s_2 = (shengxiadebian / 2) * ding ;
        ans = min( ans, max(s1,s_1,s_2) - min(s1,s_1,s_2) );
        ll dingdeyiban_1 = ding / 2 + ding % 2;
        ll dingdeyiban_2 = ding / 2;
        ll ss_1 = dingdeyiban_1 * shengxiadebian;
        ll ss_2 = dingdeyiban_2 * shengxiadebian;
        ans = min( ans, max(s1,ss_1,ss_2) - min(s1,ss_1,ss_2) );
    }
}

int main()
{
    ll a,b;
    cin >> a >> b;
    if(a == 2 && b == 2 )
    {
        puts("1");
        return 0;
    }
    ans = 1e18;
    cmp(b,a);
    cmp(a,b);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 100005
using namespace std;
ull A;
int main() {
  ull k, n;
  cin >> n >> k;
  for(int i=0;i<n;i++) {cin >> A;}
  if((n-1)%(k-1) == 0)cout << (n-1)/(k-1) << endl;
  else cout << (n-1)/(k-1)+1 << endl;
  return 0;
}

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

ll n, m;

int main()
{
    cin >> n >> m;
    if(n * 2 >= m){
        cout << m / 2 << endl;
        return 0;
    }
    cout << (n * 2 + m) / 4 << endl;

    return 0;
}


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

const int MOD = 1000000007;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
const long long INF = 1LL<<60;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll N; cin >> N;
    string S1, S2; cin >> S1 >> S2;

    ll i;
    ll cnt;
    bool tate;
    if (S1[0] == S2[0]) {
        i = 1;
        cnt = 3;
        tate = true;
    } else {
        i = 2;
        cnt = 6;
        tate = false;
    }
    
    while (i < N) {
        if (S1[i] != S2[i]) {
            if (tate) {
                cnt = cnt * 2 % MOD;
                i += 2;
                tate = false;
            } else {
                cnt = cnt * 3 % MOD;
                i += 2;
                tate = false;
            }
        } else if (S1[i] == S2[i]) {
            if (tate) {
                cnt = cnt * 2 % MOD;
                i++;
                tate = true;
            } else {
                i++;
                tate = true;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string a,b;
    cin >> a >> b;
    map<char,char> trk;
    int n,m;
    n=a.size();
    m=b.size();
    char ch='.';
    int dp[n+1][m+1];
  
    
    for(int i=n;i>=0;i--){
        for(int j=m;j>=0;j--){
            
                if(i==n || j==m) dp[i][j]=0;
            else if(a[i]==b[j]){
                dp[i][j]=dp[i+1][j+1]+1;
              
            }
            else{
                dp[i][j]=max(dp[i+1][j],dp[i][j+1]);
            }
        
        }
    }
    vector<char> cc;
    int i=0,j=0;
    while(dp[i][j]!=0){
        int x;
            x=max(dp[i+1][j],dp[i][j+1]);
            if(dp[i][j]!=x){
                 cc.push_back(a[i]);
                 i++;j++;
            }
            else{
                if(dp[i+1][j]==dp[i][j]) i++;
                else j++;
            }
    }
            
        
    for(int i=0;i<cc.size();i++) cout << cc[i];
    cout << endl;
    
   
   // cout << dp[0][0] << endl;
}

Measured memory_bytes: 38792
n = int(input())
h = [int(i) for i in input().split()]
t = 0
for i in range(n-1):
	if h[i+1]-h[i] < -1:
		print('No')
		exit()
	elif h[i+1]-h[i] == -1:
		if t == 1:
			print('No')
			exit()
		else:
			t = 1
	elif h[i+1]-h[i] == 0:
		continue
	elif h[i+1]-h[i] > 0:
		if t == 1:
			t = 0
		else:
			continue
print('Yes')

Measured memory_bytes: 14396
#include <stdio.h>

int main()
{
  int i;
  int in;
  int map[100]={};
  int max=0;

  while(scanf("%d", &in) != EOF)
    map[in - 1]++;

  for(i = 0; i < 100; i++)
    if(max < map[i])
      max = map[i];

  for(i = 0; i < 100; i++)
    if(map[i] == max)
      printf("%d\n", i + 1);

  return 0;
}

Measured memory_bytes: 596
def main():
    while True:
        x, y = map(lambda n: int(n), input().split(' '))
        if x == 0 and y == 0:
            break

        print("#" * y)
        for i in range(x-2):
            print("#"+"."*(y-2)+"#")
        print("#" * y)
        print("")


def get_input():
    while True:
        try:
            line = input()
            if line == '':
                break
            else: 
                yield line
        except EOFError:
            break


if __name__ == "__main__":
    main()


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

using namespace std;

int main () {
	int n; cin >> n;
	vector<int> L(n);
	for (int& a : L) cin >> a;
	sort(L.begin(), L.end());
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (L[i] == L[j]) continue;
			for (int k = j + 1; k < n; ++k) {
				if (L[i] == L[k] || L[j] == L[k]) continue;
				if (L[k] < L[i] + L[j]) ++ans;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;

int main()
{
   int s;
   cin >> s;
   int front = s/100;
   int back = s%100;
   bool b_front = true;
   bool b_back = true;

   if(back==0 || 12< back) b_back = false;
   if(front ==0 || 12 < front) b_front = false;

   if(b_back==true && b_front==true) cout << "AMBIGUOUS" << endl;
   else if(b_back==true && b_front == false) cout << "YYMM" << endl;
   else if(b_back==false && b_front == true) cout << "MMYY" << endl;
   else cout << "NA" << endl;

   return 0;

}


Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner s=new Scanner(System.in);
		String p[]={"101","000000","000011","10010001","010001","000001","100101","10011010","0101","0001","110"
		,"01001","10011011","010000","0111","10011000","0110","00100","10011001","10011110","00101","111","10011111"
		,"1000","00110","00111","10011100","10011101","000010","10010010","10010011","10010000"};
		String c=" ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		String q[]={"11010","11110","11100","11101","11011","11111","00000","00001","00010","00011","00100"
		,"00101","00110","00111","01000","01001","01010","01011","01100","01101","01110","01111","10000","10001"
		,"10010","10011","10100","10101","10110","10111","11000","11001"};
		while(s.hasNext()){
			String k=s.nextLine();
			String a="";
			for(int i=0;i<k.length();i++)
				for(int j=0;j<32;j++)if(k.charAt(i)==c.charAt(j))a+=q[j];
		//	while(a.length()%5!=0)a+="0";
			String e="";
			int at=0;
			for(int i=0;i<a.length()/5;i++){
				for(int j=0;j<32;j++){
					if(at+p[j].length()<=a.length()&&a.substring(at,at+p[j].length()).equals(p[j])){
						e+=c.charAt(j);
						at+=p[j].length();
					}
				}
			}
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 12000
#include "bits/stdc++.h"
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define PI acos(-1)
typedef long long ll;

int main() {
    string S;
    cin >> S;
    Reverse(S);
    while (true) {
        if (S.substr(0, 5) == "maerd") S = S.substr(5);
        else if (S.substr(0, 7) == "remaerd") S = S.substr(7);
        else if (S.substr(0, 5) == "esare") S = S.substr(5);
        else if (S.substr(0, 6) == "resare") S = S.substr(6);
        else break;
    }
    cout << (S.size() == 0 ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 3752
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 10000
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end
using namespace std;
typedef pair<int, int> P;
int main(){

    int n,n1;
    cin >> n >> n1;
    cout << (n1*(int)pow((double)n1-1, (double)n-1))<< endl;
}


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

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

	int a,b;

	cin >> a >> b;

	if(a>=13)
	{
		cout << b << '\n';
	}
	else if(a>5)
	{
		cout << b/2 << '\n';
	}
	else
	{
		cout << 0 << '\n';
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
	int a, b;
	char op;
	while(true){
		cin >> a >> op >> b;
		switch(op){
			case '+':
				cout << a + b << '\n';
				break;
			case '-':
				cout << a - b << '\n';
				break;
			case '/':
				cout << a / b << '\n';
				break;
			case '*':
				cout << a * b << '\n';
				break;
			case '?':
				return EXIT_SUCCESS;
		}
	}
}



Measured memory_bytes: 3092
N = int(input())

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

dp = [0 for _ in range(N)]

for i in range(1, N):
    if i == 1:
        dp[i] = dp[i-1] + abs(H[i-1] - H[i])
    else:
        dp[i] = min(dp[i-1] + abs(H[i-1] - H[i]), dp[i-2] + abs(H[i-2] - H[i]))

print(dp[N-1])

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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

signed main() {
	int n, ans = 0;
	cin >> n;
	int a[114514], f[114514], e[114514];
	rep(i, n) cin >> a[i];
	f[0] = a[0], e[n - 1] = a[n - 1];
	for (int i = 1; i < n; i++) {
		f[i] = gcd(f[i - 1], a[i]);
	}
	for (int i = n - 2; i >= 0; i--) {
		e[i] = gcd(e[i + 1], a[i]);
	}
	ans = max(e[1], ans);
	for (int i = 1; i < n - 1; i++) {
		ans = max(ans, gcd(e[i + 1], f[i - 1]));
	}
	ans = max(f[n - 2], ans);
	cout << ans << endl;

	return 0;
}


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

int main() {
	ll n;
	cin>>n;
	if(n%2!=0){
		cout <<0;
		return 0;
	}
	ll now=5;
	ll ans=0;
	while(now<n){
		ans+=(n/now)/2;
		now*=5;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
N = int(input())
big_count = 0
for i in range(1,N+1):
    if i % 2 == 0:
        continue
    count = 0
    for j in range(1,i+1):
        if i % j == 0: count += 1
    if count == 8  : big_count+= 1
print(big_count)

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.begin(), a.end(), greater<int>()
#define ROT(a) a.begin(), a.begin() + 1, a.end()
#define RROT(a) a.begin(), a.end() - 1, a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9 + 7;
const int MAX = 10000000;
template <typename T1, typename T2>
inline bool chmin(T1& a, T2 b)
{
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T1, typename T2>
inline bool chmax(T1& a, T2 b)
{
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
T gcd(T a, T b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
//cout << 'H' << endl;
/*--------------------------------------------*/

int main()
{
    //cout << fixed << setprecision(10)
    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    if (s == "ARC") {
        cout << "ABC" << endl;
    } else {
        cout << "ARC" << endl;
    }
}


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

#define ll long long

vector<ll> v;
map<ll,ll> mp;

void gen(ll n, ll last)
{
	if(n>10000000000) return;

	v.push_back(n);
	if(last+1!=10)
		gen(n*10 + (last+1), last+1);
	if(last-1 >= 0 && n!=0)
		gen(n*10 + (last-1), last-1);

	gen(n*10 + (last), last);
}

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

    for(int i=1;i<10;i++) gen(i,i);

	sort(v.begin(),v.end());
	v.resize(unique(v.begin(),v.end())-v.begin());

    ll n;
    cin >> n;

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

    return 0;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
using ll = long long;
typedef priority_queue <  tuple <int,int,int> , vector <tuple <int,int,int> > , greater <tuple <int,int,int> > > pqtapu;
struct UnionFind {
    vector<int> par; 

    UnionFind(int N) : par(N) { 
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { 
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { 
        int rx = root(x); 
        int ry = root(y); 
        if (rx == ry) return; 
        par[rx] = ry; 
    }

    bool same(int x, int y) { 
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main(void){
    int n; cin>>n;
   
    vector <tuple<int,int,int>> city1(n), city2(n) ;
    for(int i=0;i<n;i++){
         int a,b; cin>>a>>b;
         a--; b--;
         city1[i] = make_tuple(a,b,i);
         city2[i] = make_tuple(b,a,i);
    }
    sort(city1.begin(),city1.end());
    sort(city2.begin(),city2.end());
    pqtapu q;
    for(int i=0;i<n-1;i++){
    int x1 = get<0>(city1[i]),x2 = get<0>(city1[i+1]);
    int y1 = get<1>(city1[i]),y2 = get<1>(city1[i+1]);
    int cost1 = abs(x1-x2), cost2 = abs(y1-y2);
    int c = min(cost1,cost2);
    //cout<<c<<endl;
    int cn1 = get<2>(city1[i]), cn2 = get<2>(city1[i+1]);
    q.push(make_tuple(c,cn1,cn2));
    }
    city1 = city2;
    for(int i=0;i<n-1;i++){
    int x1 = get<0>(city1[i]),x2 = get<0>(city1[i+1]);
    int y1 = get<1>(city1[i]),y2 = get<1>(city1[i+1]);
    int cost1 = abs(x1-x2), cost2 = abs(y1-y2);
    int c = min(cost1,cost2);
    //cout<<c<<endl;
    int cn1 = get<2>(city1[i]), cn2 = get<2>(city1[i+1]);
    q.push(make_tuple(c, cn1, cn2));
    }
    struct UnionFind tree(n);
    int weight=0;
    while(!q.empty()){
        tuple <int,int,int> tmp = q.top(); q.pop();
        if(tree.root(get<1>(tmp)) != tree.root(get<2>(tmp))){
            tree.unite(get<1>(tmp),get<2>(tmp)); weight+= get<0>(tmp);
        }
    }
    //uf#でunionfind 作ってください
    // typedef priority_queue <  tuple <int,int,int> , vector <tuple <int,int,int> > , greater <tuple <int,int,int> > > pqtapu;
    //tuple で 重さ, 頂点, 頂点と取って上のpriority queueに入れてください
    cout<<weight<<endl;
}


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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define MP make_pair
#define PB push_back
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int INF = 1e9 + 7;

int w, h;

int main(){
	scanf("%d%d", &w, &h);
	if(w == 1 || h == 1)
		puts("1");
	else
		printf("%lld\n", (1ll * w * h + 1) / 2);
	return 0;
}


Measured memory_bytes: 256
#%%
import copy
N = int(input())
# 桁数を取得
keta = len(str(N))
# 桁数以内で3,5,7で構成される数を生成
l = ['3', '5', '7']
kotae = set()
kotae.add('0')

for i in range(keta):
    kari = copy.copy(kotae)
    for m in kari:
        for n in l:
            k = m + n
            if int(k) <= N:
                kotae.add(k)

count = 0
for s in kotae:
    count += 1 if all(s.count(c) > 0 for c in '753') else 0

print(count)


Measured memory_bytes: 8048
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define szxb 100010
#define F(a,b) for(register int (a)(0);(a)^(b);(a)++)
using namespace std;
int n;
struct ele{int x,y;inline static bool cmp(ele first,ele second){return (first.x<second.x);}}a[szxb];
signed main()
{
	scanf("%d",&n);int ans(0);
	F(i,n){scanf("%d",&a[i].x),a[i].y=i;}sort(a,a+n,ele::cmp);F(i,n){ans+=((abs(a[i].y-i))&1);}
	printf("%d",(ans>>1));
	return putchar(10),0;
}

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

cnt4=0
cnt2=0
cnt1=0
for i in range(N):
    if(a[i]%4==0):
        cnt4+=1
    elif(a[i]%2==0):
        cnt2+=1
    elif(a[i]%2==1):
        cnt1+=1
if(cnt2==0):
    if(cnt4+1>=cnt1):
        print("Yes")
    else:
        print("No")
        
elif(cnt2!=0):
    if(cnt4>=cnt1):
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
int main(){
	int k;
	cin>>k;
	if(k%2){
		cout<<(k/2+1)*(k/2)<<endl;
		return 0;
	}
	cout<<(k/2)*(k/2)<<endl;
	return 0;
}


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

using namespace std;

int main() {
  long long N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (auto &a : A) {
    cin >> a;
  }
  sort(A.begin(), A.end());

  long long l = 0, r = 1e9;
  while (r - l > 1) {
    long long m = (l + r) / 2;
    long long count = 0;
    for (int a : A) {
      auto iter = lower_bound(A.begin(), A.end(), m - a);
      count += A.end() - iter;
    }
    if (count >= M) {
      l = m;
    } else {
      r = m;
    }
  }

  vector<long long> AS(N + 1);
  for (int i = 0; i < N; i++) {
    AS[i + 1] = AS[i] + A[i];
  }

  long long count = 0;
  long long happiness = 0;
  for (int a : A) {
    auto iter = lower_bound(A.begin(), A.end(), l - a);
    int i = iter - A.begin();
    count += N - i;
    happiness += AS[N] - AS[i] + a * (N - i);
  }
  happiness -= l * (count - M);
  cout << happiness << endl;

  return 0;
}


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

int main(int argc, char* argv[]) {
	int W, H;

	while(1){

		cin >> H >> W;

		if(W == 0 && H == 0) break;

		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if((i == 0) || (i == H - 1) || (j == 0) || (j == W - 1)) printf("#");
				else printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 1112
#include <bits/stdc++.h>
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrepi(i,a,b) for(int i=((int)(b)-1);i>=(a);--i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) rrepi(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define ZERO(x) memset(x,0,sizeof(x))
#define MINUS(x) memset(x,-1,sizeof(x))
#define UNIQUE(x) (x).erase(unique(ALL(x)), (x).end())
#define TOUPPER(x) transform(ALL(x), (x).begin(), ::toupper)
#define TOLOWER(x) transform(ALL(x), (x).begin(), ::tolower)
#define debug(var)  do{std::cout << #var << " : "; view(var);}while(0)
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){for(const auto& v : vv){ view(v); } }
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void viewarr(T arr[], int n) { for(int i = 0; i < n; ++i) std::cout << arr[i] << " "; std::cout << std::endl; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll qp(ll a,ll b){ll ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
ll qp(ll a,ll b,ll mo){ll ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const int INF = 1e9;
const ll INFL = 1e18;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5;

int main() {
    int X, N; cin >> X >> N;
    set<int> p;
    rep(i,N) {
        int n; cin >> n;
        p.insert(n);
    }
    int d = 0;
    int ans = 0;
    while(1) {
        if(p.find(X-d) == p.end()) {
            ans = X-d;
            break;
        } else if(p.find(X+d) == p.end()) {
            ans = X+d;
            break;
        } else {
            d++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
N = int(input())
l = {}
ans = 0
for _ in range(N):
  s = input()
  if s in l:
    l[s] = l[s] + 1
  else:
    l[s] = 1
M = int(input())
for _ in range(M):
  s = input()
  if s in l:
    l[s] = l[s] - 1
for v in l.values():
  ans = max(ans, v)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
  ll n, T;
  cin >> n >> T;
  vector<ll> t(n);
  for(int i=0; i<n; i++) cin >> t[i];
  
  ll ans=0;
  for(int i=0; i<n-1; i++){
    ans+=min(t[i+1]-t[i],T);
  }
  cout << ans+T << endl;
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
bool a[101];
int main()
{
	int n,k,d,x,ans;
	cin>>n>>k;
	for (int i=0;i<k;i++)
	{
		cin>>d;
		for (int j=0;j<d;j++)
		{
			cin>>x;
			a[x]=true;
		}
	}
	for (int i=1;i<=n;i++) ans+=a[i];
	cout<<n-ans;
	return 0;
}

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

using ll = long long;
using pii = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;

int main() {
    int N;
    cin >> N;
    map<int, int> cnt;
    for(int i = 0; i < N; ++i) {
        int a; cin >> a;
        cnt[a]++;
    }
    ll ans = 0;
    for(auto& p : cnt) {
        if(p.first <= p.second) {
            ans += p.second - p.first;
        } else {
            ans += p.second;
        }
    }
    cout << ans << endl;
}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	string str;cin >> str;
	sort(ALL(str));

	if(str[0] == str[1] && str[2] == str[3] && str[1] != str[2]){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


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

int main()
{
	int x = 0, y = 0;

	cin >> x >> y;

	while ((x != 0) | (y != 0)) {
		if (x <= y)
			cout << x << " " << y << endl;
		else
			cout << y << " " << x << endl;

		cin >> x >> y;
	}
    return 0;
}

Measured memory_bytes: 3096
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
typedef struct Node* NodePointer;
 
typedef struct Node {
  int key;
  NodePointer next, pre;
} Node;
 
NodePointer head, last;
 
NodePointer make_node(int key) {
  NodePointer tmp = malloc(sizeof(Node));
  tmp->next = tmp->pre = NULL;
  tmp->key = key;
  return tmp;
}
 
void init() {
  head = malloc(sizeof(Node));
  last = malloc(sizeof(Node));
  head->next = last;
  last->pre = head;
}
 
void insert(NodePointer s, int key) {
  NodePointer node = make_node(key);
  NodePointer t = s->next;
  s->next = node;
  node->pre = s;
  node->next = t;
  t->pre = node;
}
 
void delete(NodePointer p) {
  NodePointer s = p->pre;
  NodePointer t = p->next;
  s->next = t;
  t->pre = s;
  free(p);
}
 
int main() {
  int N, num;
  char str[30];
  NodePointer p;
  init();
  scanf(" %d ", &N);
  while(N--) {
    scanf(" %s ", str);
    if(!strcmp(str,"insert")) {
      scanf(" %d ", &num);
      insert(head,num);
    } else if(!strcmp(str,"delete")) {
      scanf(" %d ", &num);
      for(p = head->next; p != last; p = p->next) {
        if(p->key == num) {
          delete(p);
          break;
        }
      }
    } else if(!strcmp(str,"deleteFirst")) {
      delete(head->next);
    } else if(!strcmp(str,"deleteLast")) {
      delete(last->pre);
    }
  }
 
  for(p = head->next; p != last; p = p->next) {
    printf(p == head->next? "%d":" %d", p->key);
  }
  printf("\n");
 
  return 0;
}


Measured memory_bytes: 32956
/**********************************************************/
/**            Bismillahir-rahmanir-rahim                **/
/**  In the name of Allah, the Beneficent, the Merciful. **/
/**********************************************************/
/**@author: Sayed Sohan, CSE 13th batch(2016), MBSTU*/
/**status : */
/**url: */
/* Generate with Contest-Helper **/
/* https://github.com/goldenbijoy/Contest_Helper */
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define clr(arr,value) memset(arr,value,sizeof(arr))
#define MOD 1000000007
#define PI acos(-1)
#define PB push_back
#define MP make_pair
#define SP " "
#define NL "\n"
#define DE cout<<"HERE"<<endl;
#define INF 1e18
#define __FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr2V(x,sz) for(int iii=0;i<=sz;iii++) x[iii].clear();
#define NUM1(x) __builtin_popcount(x)
#define Pause system("pause");
#define MAX 100050/** can increase another 0 */

//** your code goes from here


int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    __FAST_IO;
    ll i,j,k,arr[MAX],l,m,n,x,y,coun,sum,ans,T,check;
    vector<ll> v;
    string s;

    ll a,b,c;
    cin>>a>>b>>c;
    ans = 0;
    while(a%2==0&&b%2==0&&c%2==0){
        ans++;
        if(ans==1e6){
            ans = -1;
            break;
        }
        ll x = a/2;
        ll y = b/2;
        ll z = c/2;
        a = y+z;
        b = x+z;
        c = x+y;
    }
    cout<<ans<<NL;


    /// Don't forget to initialize array....
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	char mozi[1];

	scanf("%c", &mozi[0]);

	if (mozi[0] == 'A') {
		putchar('T');
	}
	else if (mozi[0] == 'T') {
		putchar('A');
	}
	else if (mozi[0] == 'C') {
		putchar('G');
	}
	else {
		putchar('C');
	}
	return 0;
}

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

int main(){
  int a,b,c,n;
  int ent,flag;

  while(1){
    cin >> a >> b >> c;
    if(!a && !b && !c)break;

    cin >> n;
    for(int i=0;i<n;i++){
      cin >> ent;
      ent *= 2;
      flag = 0;
      if(a*a + b*b < ent*ent)flag = 1;
      if(b*b + c*c < ent*ent)flag = 1;
      if(c*c + a*a < ent*ent)flag = 1;
      if(flag)cout << "OK" << endl;
      else cout << "NA" << endl;
    }

  }
}

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

/*
static int x = [](){
    std::ios::sync_with_stdio(false);
    std::cin.tie(NULL);
    std::cout.tie(NULL);
    return NULL;
}();
*/

int main() {
  	int n;
  	std::cin >> n;
  	std::vector<int> a(n), b(n), c(n-1);
  
  	for(int i = 0; i < n; ++i)
    	std::cin >> a[i];
  	for(int i = 0; i < n; ++i)
    	std::cin >> b[i];
  	for(int i = 0; i < n-1; ++i)
    	std::cin >> c[i];
      
    int prev_dish = -1;
    int points = 0; 
    for(int i = 0; i < n; ++i) {
    	points += b[a[i] - 1];
      	if(prev_dish != -1 && a[i] == prev_dish + 1)
          points += c[prev_dish-1];
      	prev_dish = a[i];
    }
    
    std::cout << points << "\n";
}


Measured memory_bytes: 256
_, K = map(int, input().split())
S = input()

offset = not (int(S[0]) ^ (K & 1))
runs = []

prev = S[0]
run = 0
for c in S:
    if c != prev:
        runs.append(run)
        run = 0
    prev = c
    run += 1
runs.append(run)

L = len(runs)
candidates = []

prev = sum(runs[max(0, offset - K): min(L, offset + K + 1)])
answer = prev

for i in range(offset + 2, L, 2):
    now = prev
    old_left = i - 2 - K
    new_right = i + K
    if old_left >= 0:
        now -= runs[old_left]
    if old_left + 1 >= 0:
        now -= runs[old_left + 1]
    if new_right - 1 < L:
        now += runs[new_right - 1]
    if new_right < L:
        now += runs[new_right]
    prev = now
    answer = max(answer, prev)

print(answer)


Measured memory_bytes: 4340
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=998244353;
const LL LINF=1LL<<62;
const int INF=1<<20;



int main(){
    int n,m;cin >> n >> m;
    vector<int> x(m,0);
    for (int i = 0; i < n; i++) {
        int a;cin >> a;
        for (int j = 0; j < a; j++) {
            int k;
            cin >> k;
            x[k-1]++;
        }
    }
    int ans=0;
    for (int i = 0; i < m; i++) {
        if(x[i]==n) ans++;
    }
    cout << ans << endl;
    return 0;
}



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

// Definitions
#define MAXN 200010
#define MOD (int64)1000000007
#define elif else if
typedef long long int64;
typedef long double num128;
typedef unsigned long long uint64;

#define PUTLINE printf("[%d] current line.\n", __LINE__)
#define STARTFUNC printf("[%s] function start.\n", __FUNCTION__)
#define File(s) freopen(#s".in", "r", stdin), freopen(#s".out","w", stdout)

// Improve the speed of read-in.
inline bool IsNum(char x) { return ('0' <= x) && (x <= '9'); }
inline int64 ReadNum() {
  int64 sign = 1, val = 0; char tmp = getchar();
  while (!IsNum(tmp)) { if (tmp == '-') {sign = -sign;} tmp = getchar(); }
  while (IsNum(tmp)) { val = val * 10 + tmp - 48; tmp = getchar(); }
  return val * sign;
}

// Variables
int n;
int64 ans,
      a[MAXN], pfxsum[MAXN];

// Functions
inline void Initialize(bool prgmsta) {
  if (!prgmsta) {
    
  } else {
    
  }
}
inline void Process() {
  for (int i = 1; i < n; i++)
    ans += a[i] * pfxsum[i + 1] % MOD,
    ans %= MOD;
}
inline void ReadIn() {
  n = ReadNum();
  for (int i = 1; i <= n; i++)
    a[i] = ReadNum() % MOD;
  for (int i = n; i; i--)
    pfxsum[i] = pfxsum[i + 1] + a[i],
    pfxsum[i] %= MOD;
}
inline void PrintAns() {
  printf("%lld\n", ans % MOD);
}

int main() {
  #ifndef ONLINE_JUDGE
    File(data);
  #endif
  Initialize(0);
  ReadIn();
  Initialize(1);
  Process();
  PrintAns();
  return 0;
}
/*

*/


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

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

	int s_len = s.length();
	vector<int> s_num(s_len);
	for (int i = 0; i < s_len; ++i) {
		s_num[i] = s[i] - '0';
	}

	int repeat = s_len - 1;
	for (int bit = 0; bit < (1 << repeat); ++bit) {
		vector<int> flag(repeat);
		for (int i = 0; i < s_len; ++i) {
			if (bit & (1 << i)) {
				flag.at(i) = 1;
			}
		}
		
		string str = "";
		int answer = 0;
		for (int i = 0; i < s_len; ++i) {
			if (i == 0) {
				str += to_string(s_num[i]);
				answer += s_num[i];
			}
			else {
				if (flag[i - 1] == 1) {
					str += "+" + to_string(s_num[i]);
					answer += s_num[i];
				}
				else {
					str += "-" + to_string(s_num[i]);
					answer -= s_num[i];
				}
			}
		}
		
		if (answer == 7) {
			cout << str << "=7" << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long long i=0; i<(long long)(n); i++)
#define REP(i, k, n) for(long long i=(long long)(k); i<(long long)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const ll inf = 1020304050607080910;
const int INF = 1073741823;
const ll mod = 1000000007;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x,ll y){if(x>y)swap(x, y);while(x!=0){y%=x;swap(x, y);}return y;}
ll mpow(ll x,ll r){if(r==0)return 1;if(r%2==1){return x*mpow(x,r-1)%mod;}else{ll aa=mpow(x,r/2);return aa*aa%mod;}}

int used[50];

int main(){
	ll N; cin >> N;
	vector<int> aa;
	ll A[N], c = 0;
	ll t[50];
	t[0] = 1;
	for(int i=1; i<50; i++) t[i] = t[i-1]*2;
	rep(i, N){
		cin >> A[i];
		if(i>1) c = (c^A[i]);
	}
	ll sum = A[0] + A[1];
	ll p = 0;
	rep(i, 50){
		if(c & (1LL<<i)){ p += t[i]; aa.pb(i); }
		else used[i+1] = 1;
	}
	if(p > sum){
		cout << -1 << endl;
		return 0;
	}
	ll q = sum - p, ans = 0;
	rep(i, 50){
		if(q & (1LL<<i)){
			ans += t[i-1];
			if(!used[i]){
				cout << -1 << endl;
				return 0;
			}
		}
	}
	if(ans > A[0]){
		cout << -1 << endl;
		return 0;
	}
	rep(i, aa.size()){
		int now = aa.size()-1-i;
		if(ans + t[aa[now]] < A[0]) ans += t[aa[now]];
	}
	if(ans==0) cout << -1 << endl;
	else cout << A[0] - ans << endl;
	return 0;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <map>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int main(void) {
  ll n, m;
  vector<ll> v;
  vector<ll> s;
  vector<pair<ll, ll>> vp;
  cin>>n>>m;
  for(int i=0; i<n; i++) {
    ll x;
    cin>>x;
    v.push_back(x);
  }
  for(int i=0; i<m; i++) {
    ll b, c;
    cin>>b>>c;
    vp.push_back(make_pair(c, b));
  }
  sort(v.begin(), v.end());
  sort(vp.rbegin(), vp.rend());
  s.push_back(0);
  for(int i=0; i<n; i++) {
    if(i==0)
      s.push_back(v[i]);
    else
      s.push_back(s[i]+v[i]);
  }

  ll sum = s[n];
  auto left = v.begin();
  for(int i=0; i<m; i++) {
    ll b = vp[i].second;
    ll c = vp[i].first;
    auto it = upper_bound(left, v.end(), c);
    int num = it - left;
    if(num < b) {
      sum = sum - (s[it-v.begin()]-s[left-v.begin()]) + c*num;
      left = it;
    } else {
      sum = sum - (s[(left-v.begin())+b]-s[left-v.begin()]) + c*b;
      left += b;
    }
    if(left == v.end())
      break;
  }
  std::cout << sum << std::endl;
  return 0;
}



Measured memory_bytes: 4464
#include <stdio.h>

int main()
{
  int a, b, c;
  int day, week;
  int sum = 0;
  int count = 0;

  scanf("%d%d%d",&a,&b,&c);

  day = c/a;

  while(sum < c){
    day = (c-sum)/a;
    week = day/7;

    if(week){
      sum += a*7 + b;
      count += 7;
    }
    else if((c-sum)%a != 0){
      count += day + 1;
      break;
    }
    else{
      count += day;
      break;
    }
  }

  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 2120
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int data[] = new int[n];
		for(int i = 0;i < n;i++) data[i] = sc.nextInt();
		int min , max,ans;
		min = max =data[0];
		for(int i = 1;i < n;i++) {
			if(max < data[i])max = data[i];
			if(min > data[i])min = data[i];
		}
		ans = max - min;
		System.out.println(ans);
	}

}


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

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); ++i){
		if (s[i] == '7'){
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}



Measured memory_bytes: 3652
n = int(input())
s = []
for i in range(n):
    tmp = int(input())
    s.append(tmp)
s.sort()
max_s = sum(s)
 
if max_s % 10 != 0:
    print(max_s)
else:
    for j in range(n):
        if s[j] % 10 != 0:
            print(max_s - s[j])
            break
        elif j == n-1:
            print(0)

Measured memory_bytes: 3060
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  if(n<1000)cout<<"ABC"<<endl;
  else cout<<"ABD"<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>

int Solve()
{
	int n, a[ 100002 ], total = 0;
	scanf("%d", &n);
	a[ 0 ] = a[ n + 1 ] = 0;
	for(int iPlace = 1; iPlace <= n; ++iPlace) {
		scanf("%d", &a[ iPlace ]);
		total += abs(a[ iPlace ] - a[ iPlace - 1 ]);
	}
	total += abs(a[ n ]);
	for(int iSkipPlace = 1; iSkipPlace <= n; ++iSkipPlace) {
		int cost = total;
		cost -= abs(a[ iSkipPlace ] - a[ iSkipPlace - 1 ]);
		cost -= abs(a[ iSkipPlace + 1 ] - a[ iSkipPlace ]);
		cost += abs(a[ iSkipPlace + 1 ] - a[ iSkipPlace - 1 ]);
		printf("%d\n", cost);
	}
	return 0;
}

int main() {
	return Solve();
}


Measured memory_bytes: 1536
//C
//#ifndef _GLIBCXX_NO_ASSERT
#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>


#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#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>

#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>

//Hang in there!

using namespace std;


int main() {
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	for (int i = 0; i <= N - 3; i++) {
		if (S.substr(i, 3) == "ABC") {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import itertools


n, m = map(int, input().split())

if n >= 2:
    ans1 = len(list(itertools.combinations(range(n), 2)))
else:
    ans1 = 0

if m >= 2:
    ans2 = len(list(itertools.combinations(range(m), 2)))
else:
    ans2 = 0
print(int(ans1 + ans2))


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

string s, t, u;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> s >> t >> u;
	cout << (char)(s[0]-'a'+'A') << (char)(t[0]-'a'+'A') << (char)(u[0]-'a'+'A') << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define rep(i,n) for (int i = 0; i< (n); i++)
#define Rep(i,n,m) for (int i = (n); i< (m); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
using namespace std;



int main() {
    ll n, m, sum = 0, ans = 0;
    
    cin>>n>>m;
    vector<ll> a(m);
    
    rep(i, m) cin>>a[i];
    
    rep(i, m) sum+=a[i];
    
    ans = n - sum;
    
    if(ans<0) ans = -1;
    
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
#define ll long long
#define ljc 924844033
using namespace std;
#ifdef Fading
#define gc getchar
#endif
#ifndef Fading
inline char gc(){
    static char now[1<<16],*S,*T;
    if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
    return *S++;
}
#endif
inline ll read(){
    register ll x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if(ch=='-')f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
struct edge{
	int to,nxt;
}e[400001];
ll sz[400001],tot,head[2200001];
inline void made(int from,int to){
	e[++tot].to=to;e[tot].nxt=head[from];head[from]=tot;
}
ll n,w[2200001],C[1000001],inv[1000001],fac[1000001],r[2200001],f[2200001],g[2200001];
inline ll fast_pow(ll a,ll b,ll p){
	ll t=1;a%=p;
	while (b){
		if (b&1LL) t=t*a%p;
		b>>=1LL;a=a*a%p;
	}
	return t;
}
inline void NTT(ll *f,ll lim,ll id){
	w[0]=1;
	for (int i=0;i<lim;i++){
		if (i>r[i]) swap(f[i],f[r[i]]);
	}
	for (int len=1;len<lim;len<<=1){
		ll gen=fast_pow(5,(ljc-1)/(len<<1)*id+ljc-1,ljc);
		for (int i=1;i<len;i++) w[i]=w[i-1]*gen%ljc;
		for (int i=0;i<lim;i+=len<<1){
			ll *f1=f+i,*f2=f1+len;
			for (int j=0;j<len;j++){
				ll x=f1[j],y=f2[j]*w[j]%ljc;
				f1[j]=(x+y)%ljc;
				f2[j]=(x-y+ljc)%ljc;
			}
		}
	}
	if (id==1) return;
	ll INV=fast_pow(lim,ljc-2,ljc);
	for (int i=0;i<lim;i++) f[i]=f[i]*INV%ljc;
}
void dfs(int u,int fa){
	sz[u]=1;
	for (int i=head[u];i;i=e[i].nxt){
		int v=e[i].to;
		if (v==fa) continue;
		dfs(v,u);sz[u]+=sz[v];g[sz[v]]++;
	}
	g[n-sz[u]]++;
}
inline ll getC(ll n,ll m){
	return fac[n]*inv[m]%ljc*inv[n-m]%ljc;
}
signed main(){
	n=read();
    fac[0]=inv[0]=inv[1]=1;
    for (ll i=1;i<=n;i++) fac[i]=fac[i-1]*i%ljc;
    for (ll i=2;i<=n;i++) inv[i]=(ljc-(ljc/i)*inv[ljc%i]%ljc)%ljc;
    for (ll i=1;i<=n;i++) inv[i]=inv[i-1]*inv[i]%ljc;
    for (int i=1;i<n;i++){
    	int x=read(),y=read();
    	made(x,y);made(y,x);
	}
	dfs(1,0);
	g[0]=0;
	for (int i=1;i<=n;i++) C[i]=n*getC(n,i)%ljc;
	for (int i=1;i<=n;i++) g[i]=g[i]*fac[i]%ljc;
	for (int i=0;i<=n;i++) f[i]=inv[i];
	reverse(g,g+1+n);
	ll lim=1,len=0;
	n++;
	while (lim<=(n<<1)) lim<<=1,len++;
	for (int i=0;i<lim;i++) r[i]=(r[i>>1]>>1)|((i&1)<<(len-1));
	NTT(f,lim,1);NTT(g,lim,1);
	for (int i=0;i<lim;i++) f[i]=f[i]*g[i]%ljc;
	NTT(f,lim,-1);
	n--;
	for (int i=1;i<=n;i++) f[i]=f[i]*inv[n-i]%ljc;
	for (int i=1;i<=n;i++) printf("%lld\n",(C[i]-f[n-i]+ljc)%ljc);
    return 0;
}


Measured memory_bytes: 42216
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
// Welcome to my source code!

int main() {
    string s;
    cin >> s;
    int n = s.size(), x, y;
    bool flag = true;
    for (int i = 0; i < n; i++) {
        if (flag && s[i] == 'A') {
            x = i;
            flag = false;
        }
        if (s[i] == 'Z') {
            y = i;
        }
    }
    cout << y - x + 1 << endl;
}

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

float p = 0;
int w, s;
int a, b, c, d, e, f;

int main()
{
	cin >> a >> b >> c >> d >> e >> f;

	int na = 30;
	int nb = 30;
	int nc = f / c + 1;
	int nd = f / d + 1;
	for( int i = 0; i < na; i++ ) {
		for( int j = 0; j < nb; j++ ) {
			for( int k = 0; k < nc; k++ ) {
				for( int l = 0; l < nd; l++ ) {
					if( (k*c + l*d) > e * (i*a + j*b) ) {
						continue;
					}
					if( k*c + l*d + i*a*100 + j*b*100 > f ) {
						continue;
					}
					if( k*c + l*d + i*a*100 + j*b*100 == 0 ) {
						continue;
					}
					float pp = (k*c + l*d) * 100.0 / ( k*c + l*d + i*a*100 + j*b*100 );
					if( pp > p ) {
						p = pp;
						w = i*a*100 + j*b*100;
						s = k*c + l*d;
					}
				}
			}
		}
	}
	if( p == 0 ) {
		w = a*100;
	}
	cout << w + s << " " << s << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai arccos(-1);
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int main(){
  int n;
  cin>>n;
  long long  a[86];
   a[0]=2;
    a[1]=1;
  for(int i=2;i<=n;i++){
    a[i]=a[i-1]+a[i-2];

  }
  cout<<a[n];
  

}


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

int main(){
  int N, T, H[1000];
  double A;
  cin >> N >> T >> A;
  for(int i=0;i<N;i++)	cin >> H[i];
  
  double mini = 1000000000;
  int ans;
  for(int i=0;i<N;i++){
    double a = T - H[i] * 0.006;
    if(abs(A - a) < mini){
      mini = abs(A - a);
      ans = i + 1;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256