akhauriyash/Code-Regression huggingface dataset:
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     ll int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d;
     cin>>k;
     cin>>a>>b;
     x=a%k;
     if(x==0){
        x=a;
     }
     else
     x=a+k-x;

     if(x<=b){
        cout<<"OK"<<endl;
     }
     else{
        cout<<"NG"<<endl;
     }

     return EXIT_SUCCESS;
}





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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP0(i, n) for (int i = (n)-1; i >= 0; --i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define RREP1(i, n) for (int i = (n); i >= 1; --i)
#define pow10(n) int(1e##n + n)

typedef long long LL;
typedef pair<int, int> P;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;

void solve()
{
    int HP1, Atk1;
    cin >> HP1 >> Atk1;
    int HP2, Atk2;
    cin >> HP2 >> Atk2;

    while (true)
    {
        HP2 -= Atk1;
        if (HP2 <= 0)
        {
            std::cout << "Yes" << endl;
            return;
        }
        HP1 -= Atk2;
        if (HP1 <= 0)
        {
            std::cout << "No" << endl;
            return;
        }
    }
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(20);
    solve();
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> pair_t;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = 1<<29;
/****** define constant end ********/


/****** define variable start ******/
string s, t, u;
ll a, b;
/******* define variable end *******/

ll solve(){
    cin >> s >> t >> a >> b >> u;
    if(s == u){
        cout << a-1 <<" " << b << endl;
    }else{
        cout << a <<" " << b-1 << endl;
    }
    return 0;
}
int main(){
    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end_solve = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */
    return (int)end_solve;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int H;
        int W;
        int x;
        int y;
        
        while(true){
            H = sc.nextInt();
            W = sc.nextInt();
            
            if(H==0 && W ==0)break;
            for(x = 0; x < H; x++){
            for(y = 0; y < W; y++){
                System.out.print("#");
            }
            System.out.println("");
                
            }
            System.out.println("");
        }
    }
}



Measured memory_bytes: 32880
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,now;
inline int read()
{
	int x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}
int main()
{
	//freopen("1.in","r",stdin);
	n=read();m=read();
	for(int i=1;i<=m;++i) 
	{
		int x=read();
		now+=(ll)x;
	}
	if(now>n) puts("-1");
	else printf("%lld\n",n-now);
	return 0;
}


Measured memory_bytes: 3752
// AUTHOR : Kishan Srivastav
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in freopen("input.txt", "r", stdin)
#define out freopen("output.txt", "w", stdout)
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main() {
	ios
#ifndef ONLINE_JUDGE
	in;
	out;
#endif
	string s,t;
	cin>>s>>t;
	ll count = 0;
	for (int i = 0; i < s.length() ; i++){
		if(s[i] != t[i]){
			count++;
		}
	}
	cout<<count<<endl;
}

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

using namespace std;

using ll = long long;

constexpr ll MOD = 1000000007;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

ll f[2000005], fi[2000005];

ll comb(int r, int c) {
    if (r < c) return 0;
    return f[r] * fi[c] % MOD * fi[r - c] % MOD;
} 

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    int maxv = r2 + c2 + 1;
    f[0] = 1;
    for (int i = 1; i <= maxv; ++i) {
        f[i] = f[i - 1] * i % MOD;
    }
    fi[maxv] = modpow(f[maxv], MOD - 2);
    for (int i = maxv; i > 0; --i) {
        fi[i - 1] = fi[i] * i % MOD;
    }

    ll ans = 0;
    for (int i = r1; i <= r2; ++i) {
        (ans += (comb(c2 + i + 1, i + 1) + MOD - comb(c1 + i, i + 1)) % MOD) %= MOD;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 31488
from collections import Counter
(N,) = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

freq = Counter(A)
if freq[1] == 1:
    print(1)
elif freq[1] >= 2:
    print(0)
else:
    bad = set()
    for k, v in freq.items():
        if v >= 2:
            bad.add(k)

    mx = max(A)

    for x in freq.keys():
        for times in range(2, 10 ** 6 + 1):
            if x * times > mx:
                break
            if x * times in freq:
                bad.add(x * times)

    count = 0
    for x in A:
        if x not in bad:
            count += 1
    print(count)


Measured memory_bytes: 123808
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,X;
  cin >> N >> X;
  vector<int> m(N);
  int M = 100000;
  for (int i = 0; i < N; i++){
    cin >> m[i];
    X -= m[i];
    M = min(M,m[i]);
  }
  cout << N + X / M;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
typedef long long ll;
using namespace std;
void abcofabc() {
	string s;
	cin >> s;
	int c[3];
	fill(c, c + 3, 0);
	for (size_t i = 0; i < 3; i++)
	{
		c[s[i] - 'a']++;
	}
	for (size_t i = 0; i < 3; i++)
	{
		if (c[i] != 1) {
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
}
int main() {
	abcofabc();
	return 0;
}

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

int main(void) {
	int n, ans = 0;
	string a, b, c;
	cin >> n >> a >> b >> c;
	
	for (int i = 0; i < n; i++) {
		if ((a[i] == b[i]) && (b[i] == c[i])) continue;
		else if ((a[i] != b[i]) && (b[i] != c[i]) && (c[i] != a[i])) ans += 2;
		else ans += 1;
	}
	
	cout << ans << endl;
}

Measured memory_bytes: 256
function main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var values = input[1].split(" ");//.map(function(v) { return parseInt(v); });


  var getType = function(a, index) {
    return a[index][0];
  };
  var getNum = function(a, index) {
    return parseInt(a[index][1]);
  };


  var values1 = values.concat();
  bubbleSort(values1, N, function(a, index) {
    return parseInt(a[index][1]);
  });
  console.log(values1.join(" "));
  if (isStable(values, values1, N, getType, getNum)) {
    console.log("Stable");
  } else {
    console.log("Not stable");
  }

  var values2 = values.concat();
  selectionSort(values2, N, function(a, index) {
    return parseInt(a[index][1]);
  });
  console.log(values2.join(" "));
  if (isStable(values, values2, N, getType, getNum)) {
    console.log("Stable");
  } else {
    console.log("Not stable");
  }
}

function isStable(org, a, N, type, num) {
  var i = 0;
  var table = {};
  for (i = 0; i < N; i++) {
    var n = num(org, i);
    if (table[n] == null) table[n] = [];
    table[n].push(type(org, i));
  }

  for (var key in table) {
    var values = table[key];
    var count = 0;
    for (i = 0; i < N; i++) {
      if (num(a, i) == key) {
        if (values[count] == type(a, i)) {
          count++;
        } else {
          return false;
        }
      }
    }
  }
  return true;
}

function bubbleSort(a, N, get) {
  var flag = true;
  while (flag) {
    flag = false;
    for (var j = N-1; j >= 1; j--) {
      if (get(a, j) < get(a, j-1)) {
        var v = a[j];
        a[j] = a[j-1];
        a[j-1] = v;
        flag = true;
      }
    }
  }
}

function selectionSort(a, N, get) {
  for (var i = 0; i < N; i++) {
    var minj = i;
    for (var j = i; j < N; j++) {
      if (get(a, j) < get(a, minj)) {
        minj = j;
      }
    }

    if (minj != i) {
      var tmp = a[i];
      a[i] = a[minj];
      a[minj] = tmp;
    }
  }
}


main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 8492
n = int(input())
s = input()
q = int(input())
C = [0]*n
for i, k in enumerate(s):
  C[i] = 1<<(ord(k)-ord("a"))

#####segfunc######
#def segfunc(x,y):
#    return 

def segfunc(a,b):
  return a | b

def init(init_val):
    #set_val
    for i in range(n):
        seg[i+num-1]=init_val[i]    
    #built
    for i in range(num-2,-1,-1) :
        seg[i]=segfunc(seg[2*i+1],seg[2*i+2]) 
    
def update(k,x):
    k += num-1
    seg[k] = 1<<x
    while k:
        k = (k-1)//2
        seg[k] = segfunc(seg[k*2+1],seg[k*2+2])
    
def query(p,q):
    if q<=p:
        return ide_ele
    p += num-1
    q += num-2
    res=ide_ele
    while q-p>1:
        if p&1 == 0:
            res = segfunc(res,seg[p])
        if q&1 == 1:
            res = segfunc(res,seg[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = segfunc(res,seg[p])
    else:
        res = segfunc(segfunc(res,seg[p]),seg[q])
    return res

#####単位元######
ide_ele = 0

#num:n以上の最小の2のべき乗
num =2**(n-1).bit_length()
seg=[ide_ele]*2*num

init(C)
for _ in range(q):
  t, a, b = input().split()
  if t == "1":
    w = ord(b) - ord("a")
    update(int(a)-1, w)
  else:
    ans = query(int(a)-1, int(b))
    print(bin(ans).count("1"))

Measured memory_bytes: 84040
//Be Name Khoda, Besmellah Rahmane Rahim, In The Name Of God;
//#include<bits/stdc++.h>
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
#include <stdio.h>
#include <string.h>
#include<iomanip>
#include<unordered_map>
#include<unordered_set>
#include <fstream>
 

 
using namespace std ;

const int N = 1e5 + 5;
long long cnt[N];
long long odd[N];
bool win = false;
int n;
vector<int> graph[N];

void dfs(int v, int par = -1)
{
    odd[v] = 0;
    for (auto u: graph[v])
    {
        if (u != par)
        {
            dfs(u, v);
            cnt[v] += cnt[u];
            odd[v] += (cnt[u] % 2);
        }
    }
    cnt[v]++;
    //cout << v << " " << odd[v] << endl;
    if (odd[v] > 1)
    {
        win = true;
    }
}

 
int main()
{
    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        int u, v;
        cin >> u >> v;
        graph[u - 1].push_back(v - 1);
        graph[v - 1].push_back(u - 1);
    }
    if (n % 2)
    {
        cout << "First" << endl;
        exit(0);
    }
    dfs(0);
    if (win)
    {
        cout << "First" << endl;
    }
    else
    {
        cout << "Second" << endl;
    }

}






Measured memory_bytes: 10768
import math

A, B, H, M = map(int, input().split())

theta_a = 2*math.pi*(H%12+1/60*M)/12
theta_b = 2*math.pi*M/60

if theta_a <= theta_b:
    theta = theta_b - theta_a
else:
    theta = theta_a - theta_b

ans = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(theta))
print(ans)


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 200005;
const int INF = 1e9 + 7;

int n, k;
int a[N], dp[N];

int main() {

	FAST;

	cin >> n >> k;
	a[n + 1] = 1;
	for (int i = n; i >= 1; i --) {
		intt maxsum = (1LL * n * (n + 1) / 2 - 1LL * (n - i) * (n - i + 1) / 2) % INF;
		intt minsum = (1LL * (i - 1) * i / 2) % INF;
		a[i] = (maxsum - minsum + 1) % INF;
		if (a[i] < 0) a[i] += INF; 
	}
	for (int i = n + 1; i >= 1; i --) {
		dp[i] = 1LL * (a[i] + dp[i + 1]) % INF;
	}
	cout << dp[k] << '\n';
	return 0;
}

Measured memory_bytes: 5156
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x[4];
  int a;

  for(int i =0; i < 5; i++){
    cin >> x[i];
  }

  for(int i =0; i < 5; i++){
    if (x[i] == 0) {
        a = i;
     }
  }

  cout << a+1 << endl;
}

Measured memory_bytes: 3596
import java.util.*;
 
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] spot = new int[n + 2];
        long total = 0;
        for(int i = 0; i < n; i++){
        	spot[i + 1] = sc.nextInt();
        }
        long x = 0;
        for(int i = 0; i < n + 2; i++){
        	total += Math.abs(spot[i] - x);
            x = spot[i];
        }
        for(int i = 1; i < n + 1; i++){
            long ans = total;
        	ans -= Math.abs(spot[i - 1] - spot[i]);
            ans -= Math.abs(spot[i + 1] - spot[i]);
            ans += Math.abs(spot[i - 1] - spot[i + 1]);
            System.out.println(ans);
        }
	}
}

Measured memory_bytes: 60680
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>

#define mod 1000000007

using namespace std;
using vi = vector<int>;
using ll = long long;

int main() {
	int n, m;
	cin >> n >> m;
	int ans = 0;
	ans = 100 * (n - m) + 1900 * m;
	ans *= (1 << m);
	cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const double pi = acos(-1.0);
int main(){
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = (n / (a+b))*a + min((n % (a+b)), a);
    cout << ans;
    return 0;   
}

Measured memory_bytes: 256
from fractions import gcd
T, *L = map(int, open(0).read().split())
for a,b,c,d in zip(*[iter(L)]*4):
  if b>d:
    print('No')
  elif b>a:
    print('No')
  elif c>=b:
    print('Yes')
  elif b==d:
    if a%b<c:
      print('Yes')
    else:
      print('No')
  else:
    m = d%b
    n = a%b
    g = gcd(b,d)
    if b-g+(a%g)>c:
      print('No')
    else:
      print('Yes')

Measured memory_bytes: 6012
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = Console.ReadLine();
            var B = Console.ReadLine();

            if (A.Length > B.Length)
            {
                Console.WriteLine("GREATER");
                return;
            }
            else if (A.Length < B.Length)
            {
                Console.WriteLine("LESS");
                return;
            }
            else
            {
                for (var i = 0; i < A.Length; i++)
                {
                    if (A[i] > B[i])
                    {
                        Console.WriteLine("GREATER");
                        return;
                    }
                    else if (A[i] < B[i])
                    {
                        Console.WriteLine("LESS");
                        return;
                    }
                }
            }

            Console.WriteLine("EQUAL");
        }
    }
}


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

int main(){
	string str;
	cin>>str;
	int n;
	cin>>n;
	int ans=0;
	for(int i=0;i<n;i++){
		string tmp;
		cin>>tmp;
		tmp=tmp+tmp;
		if(tmp.find(str,0)!=string::npos)ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1212
#include<cstdio>
#include<algorithm>
#include<math.h>
#include<map>
#include <vector>
#include <iomanip>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
int main()
{
	int a[5],b[5];
	for (int i = 0; i < 5; i++)
	{
		cin >> a[i];
	}
	int t = 0, sum = 0,k=0;
	for (int j = 0; j < 5; j++)
	{
		t = a[j];
		while (t % 10 != 0)
		{
			t++; k++; if (t % 10 == 0) break;
		}
		b[j] = k;
		k = 0;
	}
	sort(b, b + 5);
	for (int i = 0; i < 4; i++)
	{
		sum =sum+ a[i] + b[i];
	}
cout << sum+a[4]<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
typedef long long ll;
int main(){
  ll x,y;
  cin >> x >> y;
  ll a = 0;
  a = pow(10,15);
  ll b = 0;
  b = y - x;
  if(b >= 0){
    a = min(a,b);
  }
  b = 1 + y + x;
  if(b >= 0){
    a = min(a,b);
  }
  b = 1 - y - x;
  if(b >= 0){
    a = min(a,b);
  }
  b = 2 - y + x;
  if(b >= 0){
    a = min(a,b);
  }
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
#create date: 2020-06-30 09:34

import sys
stdin = sys.stdin
from collections import Counter

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

def main():
    n = ni()
    prime_count = Counter(prime_decomposition(n))
    ans = 0
    for p in prime_count.values():
        i = 1
        while p - i >= 0:
            p -= i
            ans += 1
            i += 1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 9488
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
const int mod=1e9+7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};



int32_t main()
{

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

#ifndef ONLINE_JUDGE
freopen("input.txt","rt",stdin);
freopen("output.txt","wt",stdout);
#endif 


int n;
cin>>n;
vector<int>v(n);


for(int i=0;i<n;i++)
{
  cin>>v[i];
}

sort(v.rbegin(),v.rend());

int ans=v[0];
int cnt=n-2;
int i=1;
while(cnt>0&&i<n)
{
  if(cnt>1)
  {
    cnt-=2; ans+=v[i]*2;
  }
  else {
    cnt--; ans+=v[i];
  }
  i++;
}
cout<<ans<<"\n";



}


Measured memory_bytes: 4760
import java.util.Scanner;
class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
        if (r > x || r > y || (x + r) > W || (y + r) > H) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 26340
#include <bits/stdc++.h>
#include <math.h>
#include <cstdlib> //絶対値 abs()
using namespace std;


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

	vector<int> a(n);

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

	for(int i=0;i<n;i++){
		int v = a[i];
		int j = i-1;
		while(j>=0 && a[j]>v){
			a[j+1] = a[j];
			j--;
		}

		a[j+1] = v;

		for(int k=0;k<n;k++){
			cout << a[k];
			if(k!=n-1) cout << " ";
		}

		cout << endl;
	}


}



Measured memory_bytes: 3100
n = int(input())
a = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if a[i] == i+1:
        a[i], a[i+1] = a[i+1], a[i]
        ans += 1
if a[-1] == n:
    ans += 1
print(ans)


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

int main(){
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;
  vector<ll> dpl(n+1,0), dpr(n+2,0);
  for(int i = 1; i <= n; i++) {
    dpl[i] = dpl[i-1];
    if(s[i-1] == 'o') {
      if(i <= c) dpl[i] = 1;
      else dpl[i] = max(dpl[i],dpl[i-c-1]+1);
    } 
  }
  for(int i = n; i >= 1; i--) {
    dpr[i] = dpr[i+1];
    if(s[i-1] == 'o') {
      if(i+c+1 > n) dpr[i] = 1;
      else dpr[i] = max(dpr[i],dpr[i+c+1]+1);
    }
  }
  vector<int> ans;
  for(int i = 1; i <= n; i++) {
    if(s[i-1] == 'o' && dpl[i-1] + dpr[i+1] < k) ans.push_back(i);
  }
  for(auto x : ans) cout << x << endl;
  return 0;
}


Measured memory_bytes: 5752
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define TEST int t = 1; while(t--) solve()

vector<int> gp[200000], visited(200000), sz(200000);

void dfs(int u, int com){
	visited[u] = com;
	sz[com]++;
	for(auto v: gp[u])
		if(!visited[v])
			dfs(v, com);
}

void solve(){
    int n,m,k; cin>>n>>m>>k;
    vector<int> degree(n+1);
    for(int i=0;i<m;i++){
    	int u,v; cin>>u>>v;
    	gp[u].push_back(v);
    	gp[v].push_back(u);
    	degree[u]++;
    	degree[v]++;
    }
    int com = 0;
    for(int i=1;i<=n;i++){
    	if(!visited[i]){
    		++com;
    		dfs(i, com);
    	}
    }
    for(int i=0;i<k;i++){
    	int u,v; cin>>u>>v;
    	if(visited[u] == visited[v]){
	    	degree[u]++;
	    	degree[v]++;
	    }
    }
    for(int i=1;i<=n;i++){
    	cout<<max(0LL, sz[visited[i]] - degree[i] - 1)<<" ";
    }
}

signed main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); TEST; return 0;
}

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


using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;

char c[20][20];

vector <int> dx = { 1,-1,0,0};
vector<int> dy = { 0,0,1,-1,1};

ll ans[400][400];

int main() {

	int h, w;
	cin >> h >> w;
	REP(i, h)REP(j, w)cin >> c[i][j];


	REP(i, 400)REP(j, 400)ans[i][j] = INF;

	REP(i, 400)ans[i][i] = 0;

	REP(i, h)REP(j, w) {
		if (c[i][j] == '#')continue;
		int a = i * w + j;
		REP(k, 4) {
			int ny = i + dy[k], nx = j + dx[k];
			if (ny < 0 || h <= ny || nx < 0 || w <= nx)continue;
			if (c[ny][nx] == '#')continue;
			int b = ny * w + nx;
			ans[a][b] = 1;
		}
	}

	REP(i, 400) {
		REP(j, 400) {
			REP(k, 400) {
				ans[j][k] = min(ans[j][k], ans[j][i] + ans[i][k]);
			}
		}
	}



	ll an = 0;
	REP(i, 400)REP(j, 400) {
		if (ans[i][j] == INF)continue;
		an = max(an, ans[i][j]);
	}
	cout << an << endl;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main() {
  string s,t;
  pair<char, char> gokan[26] = {};
  bool flag[26] = {};
  bool use[26] = {};

  cin >> s >> t;

  bool ok = true;

  REP(i,s.length()) {
    int c = s[i] - 'a';
    if(flag[c]) {
      if (!(gokan[c].first == s[i] && gokan[c].second == t[i])) {
        ok = false;
        break;
      }
    } else {
      flag[c] = true;
      if(use[t[i] - 'a']) {
        ok = false;
        break;
      }
      use[t[i] - 'a'] = true;
      gokan[c] = make_pair(s[i], t[i]);
    }
  }

  string result = ok ? "Yes" : "No";
  cout << result << endl;
}


Measured memory_bytes: 776
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
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 (a > b) {a = b; return 1;} return 0; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl

// gcc拡張マクロ
#define gcd __gcd
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    int n, k;
    string s;
    cin >> n >> s >> k;
    k--;
    REP(i, n) {
        cout << (s[k] == s[i] ? s[k] : '*');
    }
    cout << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <climits>
using namespace std;
#define repn(i,s,n) for (int i=int(s); i < int(n); i++)
#define rep(i,n) repn(i,0,n)
#define repd(i,n) for (int i=int(n)-1; i >= 0; i--)


struct Node {
  int val;  // この区間に足される値
  int min;  // この区間の最小値（valを含む）
  Node() : min(0), val(0) {}
};

#define LC(k) (k * 2 + 1)  // 左の子
#define RC(k) (k * 2 + 2)  // 右の子

const int INF = INT_MAX;

struct RMQRangeAddSegTree {
  vector<Node> tree;
  int n;
  RMQRangeAddSegTree(int n) : n(n), tree(n*2 - 1) {}  // nは2のべき乗とする

  void addRange(int l, int r, int val) {
    addRange(l, r, 0, 0, n, val);
  }

  int minRange(int l, int r) {
    return minRange(l, r, 0, 0, n);
  }

  // a,b: クエリ対象の範囲[a,b)
  // k: 現在のノードの番号
  // l,r: 現在のノードkの範囲[l,r)
  // val: [a,b)に追加する値
  void addRange(int a, int b, int k, int l, int r, int val) {
      if (r <= a || b <= l) return;
      process_lazy(k);
      if (a <= l && r <= b) {
        tree[k].val += val;
      }
      else {
        addRange(a, b, LC(k), l, (l + r) / 2, val);
        addRange(a, b, RC(k), (l + r) / 2, r, val);
      }
      update_node(k);
  }

  int minRange(int a, int b, int k, int l, int r) {
      if (r <= a || b <= l) return INT_MAX;
      process_lazy(k);
      if (a <= l && r <= b) {
        update_node(k);
        return tree[k].min;
      }
      int lmin = minRange(a, b, LC(k), l, (l + r) / 2);
      int rmin = minRange(a, b, RC(k), (l + r) / 2, r);
      update_node(k);
      return min(lmin, rmin);
  }

  // 頂点情報の更新
  // この処理の後、ノードkのもつ各値（ここではmin）は正しいものとなる
  void update_node(int k) {
    if (k < n - 1) {
      // k は葉でない
      tree[k].min = tree[k].val + min(tree[LC(k)].min, tree[RC(k)].min);
    }
    else {
      // k は葉
      tree[k].min = tree[k].val;
    }
  }

  // 遅延評価の実行
  void process_lazy(int k) {
    if (k < n - 1 && tree[k].val != 0) {
      tree[LC(k)].val += tree[k].val;
      tree[RC(k)].val += tree[k].val;
      tree[LC(k)].min += tree[k].val;
      tree[RC(k)].min += tree[k].val;
      tree[k].val = 0;
    }
  }
};

int main() {

  int n, q;
  cin >> n >> q;
  int nPow2 = n-1;
  nPow2 |= nPow2 >> 1;
  nPow2 |= nPow2 >> 2;
  nPow2 |= nPow2 >> 4;
  nPow2 |= nPow2 >> 8;
  nPow2 |= nPow2 >> 16;
  nPow2++;

  RMQRangeAddSegTree segtree(nPow2);
  segtree.addRange(0, n, INF);
  rep(qi, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if (com == 0) {
      // update(x,y)
      int origval = segtree.minRange(x, x+1);
      segtree.addRange(x, x+1, -origval + y);
    }
    else {
      // find(x,y)
      cout << segtree.minRange(x, y+1) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3116
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount _builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace __gnu_pbds;
using namespace std;
//typedef
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
//constants
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
//
#define forn(i, n)for(ll i=0;i<n;i++)
// gcd of a and b
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
// distance between (a,b) and (c,d)
long double dis(long long a,long long b,long long c,long long d){return sqrt( ((a)-(c))*((a)-(c))+((b)-(d))*((b)-(d)) );}
// simple prime check
bool isprime(long long a){
if(a==2)return 1;
if(!(a&1))return 0;
for(ll i=3;i*i<=a;i+=2){
	if(a%i==0)return 0;
}
return 1;
}
// fast expo
long long mpow(long long base,long long exponent,long long modulus){
if(modulus==1)return 0;
long long result = 1;
base=base%modulus;
while(exponent){
		if(exponent%2 == 1)
			result=(result*base)%modulus;
		exponent=exponent>>1;
		base=(base*base)%modulus;
	}
return result;
}
// modular inverse
ll minv(ll a,ll mod){
	ll _gcd=gcd(a,mod);
	assert(_gcd==1);
	return mpow(a,mod-2,mod);
}

/*
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*
ll dx[]={1,0,-1,0,1,1,-1,-1};
ll dy[]={0,-1,0,1,1,-1,-1,1};
*/

/*
void sieve(int N){
	for(int i=0;i<=N;i++){
		spf[i]=i;
	}
	for(int i=2;i*i<=N;i++){
		if(spf[i]==i){
			for(int j=i*i;j<=N;j+=i){
				spf[j]=min(spf[j],i);
			}
		}
	}
	return;
}
*/

/*
void nCr(ll n,ll k){
	ll i,j;
	for(i=0;i<=n;i++){
		for(j=0;j<=min(i,k);j++){

			if(j==0 or j==i)C[i][j]=1LL;
			else  C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD;

		}
	}
	return;
}
*/
/*
ll ncr(ll N,ll K){
	if(N<K)return 0;
	if(K==0)return 1;
	if(N==0)return 0;

	ll den=1;
	for(ll i=1;i<=K;i++)den*=i;
	ll num=1;
	while(K--){
		num*=N;
		if(num%den==0){
			num/=den;
			den=1;
		}
		N--;
	}

	return num;
}
*/

ll n,q;
map<ll,vll>m;
set<pll>qs;
ll ans[200005];

int main(){FAST;
cin>>n>>q;
for(ll i=0;i<n;i++){
	ll l,r;cin>>l>>r;
	r--;
	ll x;cin>>x;
	m[x].pb({l,r});
}
for(ll i=0;i<q;i++){
	ll x;cin>>x;
	qs.insert({x,i});
}
for(ll i=0;i<q;i++)ans[i]=-1;
for(auto it:m){
	ll blk = it.fi;
	for(auto is:it.se){
		ll lo = is.fi-blk;
		ll hi = is.se-blk;
		auto loo = qs.lower_bound({lo,-1});
		auto hii = qs.upper_bound({hi,1000005});
		vll ee;
		while(loo!=hii){
			ee.pb(*loo);
			loo++;
		}
		for(ll i=0;i<(ll)ee.size();i++){
			qs.erase(ee[i]);
			ans[ee[i].se]=blk;
		}
	}
}
for(ll i=0;i<q;i++)cout<<ans[i]<<'\n';
return 0;
}

Measured memory_bytes: 42144
#include<stdio.h>
#include<stdlib.h>
typedef struct{
  long pref;
  long year;
  long no;
  long cityno;
}info;

long cmp(const void *p,const void *q){
  if(((info*)p)-> pref != ((info*)q) -> pref){
    return ((info*)p)-> pref - ((info*)q) -> pref;
  }else{
    return ((info*)p)-> year - ((info*)q) -> year;
  }
}

long nocmp(const void *p,const void *q){
    return ((info*)p)-> no - ((info*)q) -> no;
}

int main(){
  long n = 0;
  long m = 0;
  info city[100000] = {};
  long i = 0;
  long cnt = 0;
  scanf("%ld %ld",&n,&m);
  
  for(i=0;i<m;i++){
    scanf("%ld %ld",&city[i].pref,&city[i].year);
  }
  for(i=0;i<m;i++){
    city[i].no = i;
  }
  
  qsort(city,m,sizeof(info),cmp);
  
  for(i=0;i<m;i++){
    if(i == 0 || city[i-1].pref != city[i].pref){
      cnt = 1;
      city[i].cityno = cnt;
    }else{
      cnt++;
      city[i].cityno = cnt;
    }
  }
  
  qsort(city,m,sizeof(info),nocmp);
  
  for(i=0;i<m;i++){
    printf("%06ld",city[i].pref);
    printf("%06ld\n",city[i].cityno);
  }
  return 0;
}
      

Measured memory_bytes: 7756
N = gets.to_i
A = gets.split.map(&:to_i)
E = Hash.new { |h, k| h[k] = [] }

(N - 1).times do
  u, v = gets.split.map(&:to_i)

  E[u] << v
  E[v] << u
end

ANS = Array.new(N + 1, -Float::INFINITY)

def dfs(v, nums, visited)
  n = nums.size
  a = A[v - 1]
  visited[v] = true

  before_v = -1
  idx = nums.bsearch_index { |x| x >= a } || n

  before_v = nums[idx]
  nums[idx] = a

  ANS[v] = nums.size

  E[v].each do |u|
    next if visited[u]

    dfs(u, nums, visited)
  end

  if before_v.nil?
    nums.pop
  else
    nums[idx] = before_v
  end
end

dfs(1, [], {})

puts (1..N).map { |u| ANS[u] }


Measured memory_bytes: 265696
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(br.readLine());
      int[] seqS = new int[n];
      String[] line = br.readLine().split(" ");
      int c=0;
      for (String s : line)
        seqS[c++] = Integer.parseInt(s);

      int q = Integer.parseInt(br.readLine());
      line = br.readLine().split(" ");
      
      int cnt=0;
      for (String ref : line) {
        if( isExistSeachByBinary(seqS, Integer.parseInt(ref)) )
          cnt++;
      }

      System.out.println(cnt);
    }
  }

  static boolean isExistSeachByBinary(int[] tar, int ref) {
    int left = 0;
    int right= tar.length;
    int mid;
    while( left < right ) {
      mid  = (left + right) / 2;
      if( tar[mid] == ref ) return true;
      else if( tar[mid] > ref ) right = mid;
      else left = mid + 1;
    }

    return false;
  }
}


Measured memory_bytes: 52016
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; ++i)  cin >> a[i];

    ll x = 0;
    ll ans = 0;
    for(int d = 40; d >= 0; --d){
        int zero = 0, one = 0;
        for(int i = 0; i < n; ++i){
            if((a[i] >> d) & 1) ++one;
            else    ++zero;
        }
        if(zero > one){
            if(x + (1LL << d) <= k){
                x += 1LL << d;
                ans += (1LL << d) * zero;
            }
            else{
                ans += (1LL << d) * one;
            }
        }
        else{
            ans += (1LL << d) * one;
        }
    }
    cout << ans << endl;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main()
{
  int x,y,z,k;
  cin >> x >> y >> z >> k;
  ll qx[1005] = {}, qy[1005] = {}, qz[1005] = {};
  vector<ll> qe;
  REP(i,x) {
    cin >> qx[i];
  }
  REP(i, y) {
    cin >> qy[i];
  }
  REP(i, z) {
    cin >> qz[i];
  }

  REP(i,x) {
    REP(j,y) {
      qe.push_back(qx[i] + qy[j]);
    }
  }
  sort(qe.begin(), qe.end(), greater<ll>());

  vector<ll> qr;
  REP(i, min(x*y, k)) {
    REP(j,z) {
      qr.push_back(qe[i] + qz[j]);
    }
  }
  sort(qr.begin(), qr.end(), greater<ll>());

  REP(i,k) {
    cout << qr[i] << endl;
  }
}


Measured memory_bytes: 43364
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
#include <numeric>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<P> vp;
typedef vector<bool> vb;
#define rep(i, a, n) for (ll i = (a); i < (n); ++i)
#define rrep(i, a, n) for (ll i = (a); i > (n); --i)
#define erep(i, a, n) for (ll i = (a); i <= (n); ++i)
#define rerep(i, a, n) for (ll i = (a); i >= (n); --i)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define mp make_pair
#define sz(x) ((int)x.size())
#define vec_max(V) *max_element(all(V))
#define vec_min(V) *min_element(all(V))
#define vec_sum(V) accumulate(all(V), 0LL)
#define print(X) cout << (X) << "\n"
#define _ << " " <<
#define Yes print("Yes")
#define No print("No")
static const int INF = 1e+9+7;

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  if(A+B < N) cout << min(A,B) _ 0 << "\n";
  else if(A == B && A == N) cout << min(A,B) _ A << "\n";
  else cout << min(A,B) _ A+B-N << "\n";

  return 0;
}


Measured memory_bytes: 256
n,*a=map(int,open(0).read().split())
ma=1001001
nums=[0]*ma

for q in a:
  nums[q]+=1
  if nums[q]==1:
    for j in range(2*q,ma,q):
      nums[j]+=2

cnt=0
for elem in nums:
  if elem==1:
    cnt+=1
    
print(cnt)

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

int main(){
	unsigned long long n;
	cin >> n;
	int count = 0;
	bool seven,five,three;
	for(unsigned long long i = 357; i <= n; i += 2){
		if(i == 77777753 + 2)i = 333333357 - 2; 
		if(i == 377777775 + 2)i = 533333337 - 2;
		if(i == 577777773 + 2)i = 733333335 - 2;
		if(i == 777777753 + 2)break;
		seven = 0;
		five = 0;
		three = 0;
		unsigned long long num = i;
		while(num > 0){
			if(num % 10 == 7)seven = 1;
			else if(num % 10 == 5)five = 1;
			else if(num % 10 == 3)three = 1;
			else{
				goto label;
			}
			num /= 10;
		}
		if(seven == 1 && five == 1 && three == 1){
			count++;
		}
		label:;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long W, a, b;
  cin >> W >> a >> b;
  if (a > b) swap(a, b);

  cout << max(b - a - W, 0l) << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include<queue>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,P> PP;
int a[505][505];
vector<PP> ans;
int dx[4] = {-1,0,0,1};
int dy[4] = {0,-1,1,0};
int main() {
  int h,w;
  cin >> h >> w;
  for(int i = 0; i < h; i++) {
      for(int j = 0; j < w; j++) {
	cin >> a[i][j];
      }
  }

  
  for(int i = 0; i < h; i++) {
    if(i % 2 == 0) {
      for(int j = 0; j < w; j++) {
	int nx = i, ny = j + 1;
	if(ny == w) {
	  nx = i+1;
	  ny = w-1;
	}
	if(nx == h) break;
	
      if(a[i][j] & 1) {
	a[i][j]--;
	a[nx][ny]++;
	ans.push_back(PP(P(i,j),P(nx,ny)));
      }
      }
    }
    else {
         for(int j = w-1; j >= 0; j--) {
	int nx = i, ny = j - 1;
	if(ny == -1) {
	  nx = i+1;
	  ny = 0;
	}
	if(nx == h) break;
	
      if(a[i][j] & 1) {
	a[i][j]--;
	a[nx][ny]++;
	ans.push_back(PP(P(i,j),P(nx,ny)));
      }
      }
    }
  }
  
  cout << ans.size() << endl;
  
  for(int i = 0; i < ans.size(); i++) {
    cout << ans[i].first.first + 1 <<" "<<ans[i].first.second + 1<<" "<<ans[i].second.first + 1<<" "<<ans[i].second.second + 1<<endl;
  }
}
      
  
      
  

 
	
	  
  

  


Measured memory_bytes: 5232
from sys import stdin

def main():
    N = int(input())
    A = list(map(int, stdin.read().splitlines()))

    if N == 2:
        print(abs(A[1] - A[0]))
        return

    k = [2] * N; k[0] = 1; k[-1] = 1
    i = -1
    for j in range(N):
        k[j] *= i
        i *= -1
    k.sort()

    A.sort()
    ans1 = 0
    for i, j in zip(A, k):
        ans1 += i * j

    ans2 = 0
    for i, j in zip(A[::-1], k):
        ans2 += i * (j * -1)

    print(max(ans1, ans2))

input = lambda: stdin.readline()
main()


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

using namespace std;

using ll = long long int;
using vi = vector<int>;
#define f(n) for(int i = 0; i < n; i++)
#define fj(n) for(int j = 0; j < n; j++)
#define fk(n) for(int k = 0; k < n; k++)
#define ci(n) cin >> n;
#define ic(n) int n; cin >> n;
#define lc(n) int n; cin >> n;
#define all(a) a.begin(), a.end()
#define pri(a, n) for(int i = 0; i < n; i++) cout << a[i] << " "; cout << "\n";
#define scl(a, n) ll a[n] = {0}; for(int i = 0; i < n; i++) cin >> a[i];
#define pb push_back
#define eb emplace_back
#define int long long
#define sc second
#define ft first
void prip(int a[], int n){f(n) cout << a[i] << ' '; cout << '\n';}
const int inf = 4e18, maxn = 100000, mod = 1000000000 + 7;

int bp(int a, int n)
{
    if(n == 0ll) return 1ll;
    if(n & 1ll) return (a * bp(a, n - 1ll)) % mod;
    int res = bp(a, n >> 1ll);
    return (res * res) % mod;
}


int gcd(int a, int b)
{
    if(b == 0) return a;
    return gcd(b, a % b);
}
main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ic(n)
    int a[n], b[n];
    int a0 = 0, b0 = 0;
    map<pair<int, int>, int> mp, usd;
    int am = 0;
    f(n)
    {
        cin >> a[i] >> b[i];
        if(a[i] == 0ll && b[i] != 0ll) a0++;
        if(a[i] != 0ll && b[i] == 0ll) b0++;
        if(a[i] != 0ll && b[i] != 0ll)
        {
            int g = gcd(abs(a[i]), abs(b[i]));
            a[i] /= g, b[i] /= g;
            if(b[i] < 0) a[i] *= -1ll, b[i] *= -1ll;
            mp[{a[i], b[i]}]++;
        }
        if(a[i] == 0 && b[i] == 0) am++;

    }
    int ans = (bp(2ll, a0) + bp(2ll, b0) - 1) % mod;
    for(pair<pair<int, int>, int> p : mp)
    {
        if(usd[p.ft]) continue;
        pair<int, int> cp = p.ft;
        //cout << cp.ft << ' ' << cp.sc << '\n';
        pair<int, int> u = {-cp.sc, cp.ft};
        if(u.sc < 0) u.sc *= -1ll, u.ft *= -1ll;
        ans = (ans * ((bp(2ll, p.sc) + bp(2ll, mp[u]) - 1ll) % mod)) % mod;
        usd[u] = 1ll;
        usd[cp] = 1ll;
    }
    cout << (ans - 1ll + am + mod) % mod;
}


Measured memory_bytes: 56772
s = input()
K = int(input())

def cord(c):
    return ord(c)-97

def cchr(n):
    return chr(n+97)

def smcheck(c, k):
    return 26-cord(c) <= k

def smcnt(c, k):
    return 26-cord(c)

ans = ''
for c in s:
    sc = smcnt(c, K)
    if sc <= K and sc < 26:
        K -= sc
        ans += cchr((cord(c) + sc)%26)
        # print(K,ans)
    else:
        ans += c
if K>26:
    K = K%26
if K>0:
    lc = ans[-1]
    ans = ans[:-1]
    ans += cchr((cord(lc)+K)%26)

print(ans)


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

using namespace std;

#define MAX_E 100000

class DisjointSet {
public:
  vector <int> rank, p;
  DisjointSet() {}
  DisjointSet(int size) {
    rank.resize(size, 0);
    p.resize(size, 0);
    for (int i = 0; i < size; i++) makeSet(i);
  }
  void makeSet(int x) {
    p[x] = x;
    rank[x] = 0;
  }
  bool same(int x, int y) {
    return findSet(x) == findSet(y);
  }
  void unite(int x, int y) {
    link(findSet(x), findSet(y));
  }
  void link(int x, int y) {
    if (rank[x] > rank[y]) {
      p[y] = x;
    }else {
      p[x] = y;
      if (rank[x] == rank[y]) {
	rank[y]++;
      }
    }
  }
  int findSet(int x) {
    if (x != p[x]) {
      p[x] = findSet(p[x]);
    }
    return p[x];
  }
};

class edge {
public:
  int from, to, cost;
  edge(int from = 0, int to = 0, int cost = 0): from(from), to(to), cost(cost) {}
  bool operator < (const edge &e) const {
    return cost < e.cost;
  }
};

edge es[MAX_E];
int V, E;

int kruskal() {
  sort(es, es+E);
  DisjointSet ds = DisjointSet(V);
  int ret = 0;
  for (int i = 0; i < E; i++) {
    edge e = es[i];
    if (!ds.same(e.from, e.to)) {
      ds.unite(e.from, e.to);
      ret += e.cost;
    }
  }
  return ret;
}

int main() {
  cin >> V >> E;
  for (int i = 0; i < E; i++) {
    int s, t, w;
    cin >> s >> t >> w;
    es[i] = edge(s, t, w);
  }
  cout << kruskal() << endl;
}

Measured memory_bytes: 4324
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;

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

int main(void){
  int N;
  cin >> N;

  vector<long>num(N,0);

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

  long ans = num[0];

  for(int i=1;i<N;i++){
    ans = gcd(ans,num[i]);
  }

  cout << ans << endl;

  return 0;


}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x)
{
  char c=getchar();
  bool f=0;
  x=0;
  while(!isdigit(c)) f|=c=='-',c=getchar();
  while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
  if(f) x=-x;
  return x;
}
template<class t> inline void write(t x)
{
  if(x<0) putchar('-'),write(-x);
  else
  {
    if(x>9) write(x/10);
    putchar('0'+x%10);
  }
}

#define int __int128

const int mod=1e9+7;
const int N=1e5+5;
int n,k,ans,pre[N],a[N],fac[N],inv[N];

int calc(int l,int r)
{
  return pre[r]-pre[l-1];
}

int C(int n,int m)
{
  return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

int fpow(int x,int y)
{
  int res=1;
  for(; y; y>>=1,x=x*x%mod) if(y&1) res=res*x%mod;
  return res;
}

signed main()
{
  read(n);
  read(k);
  for(int i=1; i<=n; i++)
    read(a[i]);
  if(k==1)
  {
    write(0);
    return 0;
  }
  sort(a+1,a+1+n);
  for(int i=1; i<=n; i++) pre[i]=pre[i-1]+a[i];
  fac[0]=1;
  for(int i=1; i<=n; i++) fac[i]=fac[i-1]*i%mod;
  inv[n]=fpow(fac[n],mod-2);
  for(int i=n-1; i>=0; i--) inv[i]=inv[i+1]*(i+1)%mod;
  for(int i=k; i<=n; i++)
    ans=(ans+C(i-2,k-2)*(calc(i,n)-calc(1,n-i+1))%mod)%mod;
  write(ans);
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};
int main() {
    combination C(200005);
    ll H, W, A, B; cin >> H >> W >> A >> B;
    mint pre = 0;
    mint ans = C((H-1)+(W-1), W-1);
    for(ll i=1;i<=B;i++) {
        ll h = H - A + 1;
        ll w = i;
        mint ban = C((h-1)+(w-1), w-1) - pre;
        pre += ban;
        ban = ban*C((H-h)+(W-w), H-h);
        ans -= ban;
    }
    cout << ans.x;
}


Measured memory_bytes: 3328
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int N = Integer.parseInt(sc.nextLine());
			int[] A = new int[N];
			int[] B = Arrays.stream(sc.nextLine().split(" ")).mapToInt(r -> Integer.parseInt(r)).toArray();
			A[0] = B[0];
			for (int i = 1; i < N - 1; i++) {
				A[i] = Math.min(B[i - 1], B[i]);
			}
			A[N - 1] = B[N - 2];
			System.out.println(Arrays.stream(A).sum());
		}
	}
}

Measured memory_bytes: 28752