akhauriyash/Code-Regression huggingface dataset:
//CODING ME ACCHHA KARNEKA HAI TERKO TO BAS PRACTICE KARTE REH
#include <bits/stdc++.h>
#define pragma
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define aisort sort(a,a+n)
#define adsort sort(a,a+n,greater<ll>())
#define PI 2 * acos(0)

typedef pair<ll, ll> pii;
typedef pair<ll, pii> piii;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<piii> viii;
typedef set<ll> Set;

const ll maxs = 1e5+3;
const ll maxs1 = 1e3+4;
const ll mod = 1e9 + 7;

//MODULO OPEARTIONS
    inline ll add(ll a, ll b) { return (mod + a + b) % mod; }
    inline ll sub(ll a, ll b) { return (a - b + mod) % mod; }
    inline ll mul(ll a, ll b) { return (1ll * a * b) % mod; }

//POWER
    ll fastpow(ll x,ll y)
    {ll res = 1;x = x % mod;while (y > 0){ if (y & 1)res = (res * x) % mod; y = y >> 1 ; x = (x * x) % mod; } return res;}

//MODULAR INVERSE
    ll inv(ll x){ return fastpow(x , mod - 2);}
    
//PRIME
    bool isPrime(ll n) { if (n <= 1)  return false; if (n <= 3)  return true;if (n%2 == 0 || n%3 == 0) return false; for (int i=5; i*i<=n; i=i+6) if (n%i == 0 || n%(i+2) == 0) return false; return true; } 




int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,m=0,dig;
    cin>>n;
    while(n>0)
    {
        dig=n%10;
        if(dig==7)
        m=1;
        n=n/10;
    }
    if(m==1)
    cout<<"Yes";
    else
    cout<<"No";
}




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

using namespace std;

void vecprint(vector<int> v) {
    for(int i = 0; i < v.size(); i++) {
        cout << v[i] << " ";
    }
    cout << endl;
}

int main(void) {
    int n, k, q;
    cin >> n >> k >> q;
    
    vector<int> v;
    v.assign(n, k-q);
    //vecprint(v);
    
    for(int i = 0; i < q; i++) {
        int ans;
        cin >> ans;
        v[ans-1] += 1;
        //vecprint(v);
    }
    
    for(int i = 0; i < n; i++) {
        cout << (v[i] > 0 ? "Yes" : "No") << endl;
    }
}

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

#define pb push_back 
#define x first 
#define y second 
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair< int , int > PII;
const int dirx[] = {-2,-1,1,2, 1, -1};
const int diry[] = {0,1,1,0, -1, -1};
inline void debugMode() {
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
    #endif
}

int n, m, x[200100], y[200100], z[200100], val[100100];
vector < int > V[100100];
bool in[100100], u = 1, done[100100], viz[100100];
map < PII, int > M;  

void dfs(int x, int fat){
	viz[x] = 1;
	for (auto it : V[x]){
		if (it == fat || viz[it]) continue;
		
		if (val[it] == 2e9){
			val[it] = val[x] + M[{x, it}];
		}else{
			if (val[x] + M[{x, it}] != val[it]) u = 0;
		}
		
		dfs(it, x);
	}
}

int main(){
	//debugMode();
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	
	if (!m) return cout << "Yes", 0;
	
	for (int i = 1; i <= m; i++){
		cin >> x[i] >> y[i] >> z[i];
		M[{x[i], y[i]}] = z[i];
		M[{y[i], x[i]}] = -z[i];
		V[x[i]].pb(y[i]);
		V[y[i]].pb(x[i]);
		
		in[y[i]] = 1;
		done[x[i]] = done[y[i]] = 1;
	}
	
	for (int i = 1; i <= n; i++){
		if (in[i]) done[i] = 0;
		val[i] = 2e9;
	}
	
	int nr = 0;
	
	for (int i = 1; i <= n; i++){
		nr += done[i] == 1;
	}
	
	if (nr == 0) return cout << "No", 0;
	
	int cnt = 0;
	
	for(int it = 1; it <= n; it++){
		if (!done[it]) continue;
		u = 1;
		if (val[it] == 2e9) val[it] = cnt++;
		dfs(it, it);
		if (!u) return cout << "No", 0;
	}
	
	for (int i = 1; i <= m; i++){
		if (val[y[i]] - val[x[i]] != z[i]) return cout << "No", 0;
	}
	
	cout << "Yes";
	
	return 0;
}



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

int main() {
  int n;
  cin >> n;
  
  int a[n];
  for (int i = 0; i < n; i ++) {
    cin >> a[i];
  }
  
  sort(a, a + n);
  
  cout << abs(a[n - 1] - a[0]) << endl;
}

Measured memory_bytes: 256
// Problem : A - Payment
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)


#include<bits/stdc++.h>
using namespace std;
#define int         long long int
#define vi           vector<int>
#define pii          pair<int,int>
#define vpp          vector<pii>
#define mii          map<int,int>
#define pb           push_back
#define rep(i,a,bb)  for(int i=a;i<bb;i++)
#define ff           first
#define ss           second
#define fast         ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define test         int T;cin>>T;while(T--)
#define __sort(v)    sort(v.begin(),v.end())
#define __rsort(v)   sort(v.rbegin(),v.rend())
#define setbits(x)   __builtin_popcount(x)
#define zrobits(x)   __builtin_ctzint(x)
#define endl '\n'
#define debug(x)  cerr<<"[ "<<#x<<" : "<<x<<" ]"<<endl
#define debugp(x) cerr<<"[ "<<#x<<".ff : "<<x.first<<", "<<#x<<".ss : "<<x.second<<" ]"<<endl
#define debugs(x) cerr<<"[ "; for(auto i:x) cerr<<i<<" "; cerr<<" ]"<<endl;
#define debugm(x) cerr<<"----------"<<endl; for(auto i:x) cerr<<i.ff<<":"<<i.ss<<endl; cerr<<"----------"; 
#define PI 3.14159265359
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int dxk[]={0,0,1,-1,1,1,-1,-1};
int dyk[]={1,-1,0,0,1,-1,1,-1};
const int inf = 1e+18;
const int mod = 1e+9 + 7;

void solve()
{
	int x;
	cin>>x;
	int q = ceil(x*1.0/1000);
	cout<<q*1000-x<<endl;
}

int32_t main()
{
  fast;
  //test
  solve();
  return 0;
}


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

int main(){
  string a; cin>>a;
  int ans=700;
  int i;
  for(i=0;i<=2;i++){
    if(a[i]=='o') ans=ans+100;
  }
  cout<<ans;
  
  
  return 0;
}


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

const ll max_n = 1000000000000001;

int main() {
	ll n;
	cin >> n;
	map<ll, ll> m;
	for (ll i = 0; i < n; ++i) {
		ll a;
		cin >> a;
		++m[a];
	}
	ll Q;
	cin >> Q;
	ll ans = 0;
	for (auto p : m) {
		ans += p.first * p.second;
	}
	for (ll q = 0; q < Q; ++q) {
		ll b, c;
		cin >> b >> c;
		ll mb = m[b];
		m[b] = 0;
		ans += mb * (c - b);
		m[c] += mb;
		cout << ans << endl;
	}
}


Measured memory_bytes: 9488
//BISMILLAH
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main( )
{
   int n,x,t,res,cnt=0,flag=0,temp=0;
   string str;
   cin>>str;
   //int len=strlen(str);
   int sum=0;
   for(int i=0;i<str.size();i++)
   {
       //int a=str[i]-'0';
       sum+=str[i]-'0';
   }
   //cout<<sum<<endl;
   if(sum%9==0) cout<< "Yes"<<endl;
   else cout<< "No"<<endl;


}


Measured memory_bytes: 3736
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<memory.h>
#include<map>
#include<set>
#include<queue>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
int n,a[105],ans[105];
int main()
{
	cin>>n;
	rep(i,1,n)cin>>a[i];
	per(j,n,1)
	{
		int t=0;
		per(i,j,1)if(a[i]==i){t=i;break;}
		if(!t){puts("-1");return 0;}
		ans[j]=t;
		rep(i,t,j-1)a[i]=a[i+1];
	}
	rep(i,1,n)cout<<ans[i]<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main() {
int N, K;
scanf("%d %d", &N, &K);
int i, h, count=0;
for (i=0; i<N; i++) {
        scanf("%d", &h);
        if (h >= K) {
                count++;
        }
}
printf("%d\n", count);
return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required

using namespace __gnu_pbds; 
using namespace std;

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; 
typedef long long  ll;
typedef vector<ll> VL;
typedef vector<int> VI;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;
#define pb push_back

#define F first
#define S second
#define SZ(a) int((a).size())
#define ALL(a) a.begin(),a.end()
#define fr(i,x,y) for(ll i=x;i<y;i++)
#define frr(i,x,y) for(ll i=x-1;i>=y;i--)
#define inf 1e18+1
const ll mod=998244353;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll power(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;}a=a*a;b>>=1;}return ans;}
ll powerm(ll a,ll b){ll ans=1;while(b!=0){if(b&1){ans*=a;ans%=mod;}a=a*a;a%=mod;b>>=1;}return ans%mod;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
const int N =  2e5+5;
const int MOD = 998244353;

ll fact[N],inv[N];

void precompute()
{
    fact[0]=1;
    fr(i,1,N)
    {
        fact[i]=fact[i-1]*i;
        fact[i]%=mod;
        //cout<<fact[i]<<' ';
    }
    inv[N-1]=powerm(fact[N-1],mod-2);
    frr(i,N-1,0)
    {
        //cout<<inv[i+1]<<" ";
        inv[i]=inv[i+1]*(i+1);
        inv[i]%=mod;
    }
}
ll ncr(ll n,ll k)
{
    // if(n>k)
    //     return 0LL;
    ll ans=fact[n];
    //ans*=fact[n];
    ans*=inv[k];
    ans%=mod;
    ans*=inv[n-k];
    //cout<<"yo\n"<<ans;
    return ans%mod;
}
void solve()
{
    ll n,m,k;
    precompute();
    cin>>n>>m>>k;
    ll ans=m;
    ans%=mod;
    fr(i,1,n)
    {
        ans*=(m-1);
        ans%=mod;
    }
    //cout<<ans<<endl;
    ll sum2=0;
    fr(i,0,k+1)
    {
        //cout<<ncr(n-1,i)<<" ";

        sum2+=(powerm(m-1,n-1-i)*ncr(n-1,i));
        sum2%=mod;
    }
    //cout<<sum2<<endl;
    //ans*=sum2;
    ans%=mod;
    sum2*=m;
    sum2%=mod;
    cout<<sum2<<endl;
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 6780
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include <queue>
#include <stack>
#include<fstream>
#include<algorithm>

using namespace std;
int arr[10009];
int main() {

	int n, m;
	cin >> n >> m;
	long long sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
		sum += arr[i];
	}
	int i = 0;
	double k = (1.0 / (4.0 * m)) * 100;
	while (m > 0 && i < n)
	{
		double vote = (double(arr[i]) / sum)*100.0;
		if (vote >= k)
		{
			m--; i++;
		}
		else i++;
	}
	if (m <= 0)
		cout << "Yes";
	else
		cout << "No";

	return 0;



}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint t[105], v[105];
llint l[105], r[105];
llint ub[40005];

int main(void)
{
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	
	cin >> n;
	llint sum = 0;
	for(int i = 1; i <= n; i++) cin >> t[i];
	for(int i = 1; i <= n; i++) cin >> v[i];
	for(int i = 1; i <= n; i++){
		t[i] *= 2, v[i] *= 2;
		l[i] = sum;
		sum += t[i];
		r[i] = sum;
	}
	
	for(int i = 0; i <= sum; i++) ub[i] = inf;
	for(llint i = 0; i <= sum; i++) ub[i] = min(i, sum-i);
	
	for(int i = 1; i <= n; i++){
		for(int j = l[i]; j <= r[i]; j++) ub[j] = min(ub[j], v[i]);
		for(int j = 0; j <= l[i]; j++) ub[j] = min(ub[j], v[i]+(l[i]-j));
		for(int j = r[i]; j <= sum; j++) ub[j] = min(ub[j], v[i]+(j-r[i]));
	}
	
	double ans = 0;
	for(int i = 1; i <= sum; i++){
		if(ub[i] == ub[i-1]) ans += ub[i];
		else ans += (ub[i]+ub[i-1]) / 2.0;
	}
	ans /= 4;
	printf("%.11f\n", ans);
	
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)  ((a)*((b)/gcd(a,b)))
#define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;

//	#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//	#endif
    
    int n;
    cin>>n;
    int a[n+5];
    for(int i=1;i<=n;i++)
    {
    	cin>>a[i];
	}
	int c=0;
	for(int i=1;i<=n;i+=2)
	{
		if(a[i]&1)
		c++;
	}
	cout<<c<<endl;
	
	return 0;
}

Measured memory_bytes: 3604
a=int(input())
b=int(input())
if a==1 and b==2:
    print(3)
elif a==1 and b==3:
    print(2)
elif a==2 and b==1:
    print(3)
elif a==2 and b==3:
    print(1)
elif a==3 and b==1:
    print(2)
else:
    print(1)


Measured memory_bytes: 2940
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

S = input()

print(S if len(S)== 2 else S[::-1])


Measured memory_bytes: 10424
#include<bits/stdc++.h>
using namespace std;
char s[5][5];
int main()
{
    for(int i=0;i<3;i++)
        scanf("%s",s[i]);
    int x=0,y=0;
    for(int i=0;i<3;i++)
    {
        printf("%c",s[x+i][y+i]);
    }
    printf("\n");
}


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

using namespace std;

int main()
{
    int a, b;
    int ans = 0;

    cin >> a >> b;
    if ( b >= a ) {
        ans += a;
    } else {
        ans += a - 1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

char buf[100000+10];

int main(void) {
  scanf("%s", buf);
  for(int i = 0; buf[i]; i += 2) {
    printf("%c", buf[i]);
  }
  puts("");
 
  return 0;
}


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

#define pb push_back
#define fi first
#define se second
#define eb emplace_back

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
const int N = 1000007, inf = 0x3f3f3f3f;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
  ll a, b, c, d; cin >> a >> b >> c >> d;
  ll ans = max({a * c, a * d, b * c, b * d});
  cout << ans << endl;
}

Measured memory_bytes: 3624
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)



main :: IO ()
main = do
    _ <- getLine
    as <- map fst <$> sortOn snd <$> zip [1..] <$> r'
    putStrLn $ unwords $ map show as



Measured memory_bytes: 35452
N, M, X = map(int, input().split())
C = [list(map(int, input().split())) for i in range(N)]

cost = []

for i in range(2 ** N):
    skill = [0] * M
    total = 0
    for j in range(N):
        if (i >> j) & 1:
            for k in range(M):
                skill[k] += C[j][k + 1]
            total += C[j][0]
    flg = 1
    for sk in skill:
        if sk < X:
            flg = 0
    if flg == 1:
        cost.append(total)

if cost == []:
    print("-1")
else:
    print(min(cost))

Measured memory_bytes: 9136
#include<stdio.h>
#define MAX 100005
#define NIL -1
int heap_size;
struct Node{
  int p; //parent
  int l; //left-child
  int r; //right sibiling
  int k;
};
struct Node T[MAX];

int main(void){
  int i;
  int d;
  scanf("%d", &heap_size);
  for ( i=1; i<=heap_size; i++ ) T[i].p=T[i].l=T[i].r=NIL;
  for ( i=1; i<=heap_size; i++ ){
    scanf("%d", &T[i].k);
  }
  for( i=1; i<=heap_size; i++ ){
    T[i].p=T[i/2].k;
    T[i].l=T[2*i].k;
    T[i].r=T[2*i+1].k;
  }
  for ( i=1; i<=heap_size; i++ ){
    printf("node %d: key = %d, ",i, T[i].k);
    if(T[i].p!=0) printf("parent key = %d, ", T[i].p);
    if(T[i].l!=0)printf("left key = %d, ",T[i].l); 
    if(T[i].r!=0)printf("right key = %d, ",T[i].r);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, l, r) for (int i = l; i <= (int)(r); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define all(v) v.begin(), v.end()
#define MOD (int) (1e9+7)
#define INF (int) 1e9
#define LLINF (ll) 1e18

ll mpow(ll a, ll n) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

int main(){
    ll x;
    cin >> x;
    
    ll a=0;
    while(true){
        a++;
        repr(b, -(a-1), a-1){
            if(mpow(a, 5)-mpow(b, 5)==x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
    }
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int N = 200005;
const int M = 1000 * 1000 * 1000 + 7;
using namespace std;
int gcd(int f , int s){if(s==0)return f;else return gcd(s,f%s);}
int arr[2022], arr1[2222];
int main(){
	
	int a, b;
	cin >> a >> b;
	arr[1] = 300000;
	arr[2] = 200000;
	arr[3] = 100000;
	ll sum = arr[a] + arr[b];
	if(a == 1 && b == 1)sum += 400000;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
A = [int(x) for x in input().split()]

# A = sorted(A, reverse=True)
# 破壊ソートの方が高速
A.sort(reverse=True)
alip = sum(A[i] for i in range(len(A)) if i % 2 == 0)
bobp = sum(A[i] for i in range(len(A)) if i % 2 == 1)
diff = alip - bobp
print(diff)

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


int main(){
  int n,k,i;
  cin >> n >> k;
  vector<int> a(n);
  map<int,int> mp;
  for(i=0;i<n;++i){
    cin >> a[i];
    mp[a[i]]++;
  }
  int ans=0;
  if(mp.size()>k){
    int si=mp.size();
    vector<int> m(si);
    i=0;
    for(auto p : mp){
      m[i]=p.second;
      i++;
    }
    sort(m.begin(),m.end());
    for(i=si-k-1;i>=0;--i){
      ans+=m[i];
    }
    cout << ans << endl;
  }else{
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 11136
object Main extends App {
  val in = new java.util.Scanner(System.in)
  val n, m = in.nextInt
  val xs = Array.fill(m)(in.nextInt).sorted
  val spaces = xs.zip(xs.tail).map(s => s._2 - s._1)
  println(spaces.sorted.reverse.drop(n - 1).sum)
}

Measured memory_bytes: 64296
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
using namespace std;
int main()
{
    int n, a=0, b=0, c=0, d, i;
    cin >> n;
    vector <int> ba(n);
    for(int i=0; i<n; i++)
    {
        cin >> ba[i];
        a+=ba[i];
    }
    d=a;
    for(i=0; i<n; i++)
    {
        c+=ba[i];
        d=min(d, abs((a-c)-c));
    }
    cout << d << '\n';
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import math
a,b,c = map(int,input().split())
# a + b + 2r(ab) < c
# a + b - c < -2r(ab)
# c - a - b > 2r(ab)
# (c - a - b)**2 > 4ab
if c - a - b > 0 and (c - a - b)**2 > 4*a*b:
    print("Yes")
    exit()
print("No")


Measured memory_bytes: 2940
#![allow(unused_mut)]
#![allow(non_snake_case)]

#![allow(unused_imports)]
use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        d: [i64; n],
    }
    let mut d = d;
    d.sort();
    let s = n / 2;
    if d[(s as i64 - 1) as usize] == d[s] {
        println!("{}", 0);
        return;
    }
    println!("{}",d[s] - d[(s as i64 - 1) as usize]);
}

Measured memory_bytes: 6396
import math

def main():
    A, B, H, M = map(int, input().split())
    h_angle = 30 * H + 0.5 * M
    if h_angle <= 90:
        h_angle = math.radians(90 - h_angle)
    else:
        h_angle = math.radians(360 - (h_angle - 90))

    m_angle = 6 * M
    if m_angle <= 90:
        m_angle = math.radians(90 - m_angle)
    else:
        m_angle = math.radians(360 - (m_angle - 90))

    h_x = A * math.cos(h_angle)
    h_y = A * math.sin(h_angle)
    m_x = B * math.cos(m_angle)
    m_y = B * math.sin(m_angle)
    print(math.sqrt(abs(h_x - m_x)**2 + abs(h_y - m_y)**2))

if __name__ == '__main__':
    main()


Measured memory_bytes: 62236
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int H,W,K; cin>>H>>W>>K;
  vector<string> maze(H);
  int black = 0;
  rep(i,H) cin >> maze[i];
  rep(i,H) rep(j,W) if (maze[i][j] == '#') black++;

  int ans =0;
  rep(h, 1<<H) {
    rep(w, 1<<W) {
      int black2 = black;
      vector<string> maze2 = maze;
      rep(i, H) {
        if ((h>>i)&1) {
          rep(x, W) {
            if (maze2[i][x] == '#') {
              maze2[i][x] = '.';
              black2--;
            }
          }
        }
      }
      
      rep(j, W) {
        if ((w>>j)&1) {
          rep(y, H) {
            if (maze2[y][j] == '#') {
              maze2[y][j] = '.';
              black2--;
            }
          }
        }
      }

      if (black2==K) {
        ans++;
      }

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
typedef pair<lint, lint> P;

signed main(){
	lint N; cin >> N;
	vector<vector<lint> > G(N);
	vector<P> vec;
	for(lint i = 1; i < N; i++){
		lint a, b; cin >> a >> b; --a; --b;
		G[a].push_back(b); G[b].push_back(a);
		vec.push_back(P(a, b));
	}
	vector<lint> color(N, 0), used(N, -1);
	lint MAX_COLOR = 0;
	queue<lint> que;
	used[0] = 1; que.push(0);
	map<P, lint> MAP;
	while(que.size()){
		lint now = que.front(); que.pop();
		lint num = 1;
		MAX_COLOR = max(MAX_COLOR, lint(G[now].size()));
		for(lint i = 0; i < G[now].size(); i++){
			lint next = G[now][i];
			if(used[next] != -1) continue;
			if(color[now] == num) num++;
			color[next] = num;
			MAP[P(now, next)] = num;
			MAP[P(next, now)] = num;
			num++;
			used[next] = 1;
			que.push(next);
		}
	}
	cout << MAX_COLOR << endl;
	for(auto value : vec) cout << MAP[value] << endl;
}

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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For (i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
template <typename T>
void print(const vector<vector<T>> matrix);
template <typename T>
void print(const vector<T> vec);
template <typename Arg>
void print(const Arg arg);
template <typename Head, typename... Args>
void print(const Head head, const Args... args);
template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;

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

    int n, k;
    cin >> n >> k;
    vector<int> vec(n + 1);
    For (i, 1, n)
        cin >> vec[i], vec[i] += vec[i - 1];

    vector<int> li;
    rep (i, n)
        For (j, i + 1, n)
            li.pb(vec[j] - vec[i]);
    sort(all(li), greater<int>());

    int ans = 0;
    Forr (i, 40, 0) {
        int cnt = 0, bit = ans + (1ll << i);
        repall (j, li)
            cnt += (j & bit) == bit;

        if (cnt >= k) ans = bit;
    }

    print(ans);

    return 0;
}

//---------------------------------------------
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}


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

#define INF 100100100
#define MOD 1000000007

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

#define FOR(i,n) for(ll i=0;i<n;i++)

struct edge{ll to,cost;};

int main(int argc, char const* argv[]){
   ios::sync_with_stdio(false);
   cin.tie(0);
   string S;
   cin >> S;
   for(ll i=S.size()-1;i>=0;i--){
      if(i-6 >= 0 && S.substr(i-6,7) == "dreamer"){
         i-=6;
      }
      else if(i-4 >= 0 && S.substr(i-4,5) == "dream"){
         i-=4;
      }
      else if(i-5 >= 0 && S.substr(i-5,6) == "eraser"){
         i-=5;
      }
      else if(i-4 >= 0 && S.substr(i-4,5) == "erase"){
         i-=4;
      }
      else{
         cout << "NO" << endl;
         return 0;
      }
   }
   cout << "YES" << endl;
   return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
ll const MOD=1'000'000'007;

int N;
int A[100];

int main(){
    cin>>N;
    rep(i,N) cin>>A[i];

    int ans=1001001001;
    for(int i=-100;i<=100;i++){
        int sum=0;
        rep(j,N){
            sum+=(A[j]-i)*(A[j]-i);
        }
        ans=min(ans,sum);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3568
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int main(){
    int n;cin>>n;
    vector<vector<int>>v(n,vector<int>(26));
    rep(i,n)rep(j,26)v[i][j] = 0;
    rep(i,n){
        string s;cin>>s;
        rep(j,s.size()){
            v[i][s[j]-'a']++;
        }
    }
    vector<int>vv(26,INF);
    rep(i,n){
        rep(j,26)vv[j] = min(v[i][j],vv[j]);
    }
    rep(i,26){
        if(vv[i]==0)continue;
        while(vv[i]--)cout<<(char)('a'+i);
    }
}



Measured memory_bytes: 256
<?php
list($member, $sweets_count) = explode(' ', trim(fgets(STDIN)));

$count_array = [];
for ($i = 0; $i < (int)$sweets_count; $i++) {
    $sweet_type = trim(fgets(STDIN));
    $have_array = explode(' ', trim(fgets(STDIN)));

    foreach ($have_array as $have_human) {
        $count_array[(int)$have_human] = $sweet_type;
    }
}

echo (int)$member - count($count_array);

Measured memory_bytes: 16132
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){

  while(x->right!=NIL){
    x=x->right;
  }
  return x;
}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  //code
  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;

  if(y==NIL){
    root=z;
  }
  else if(z->key < y->key){
    y->left=z;
  }
  else{
    y->right=z;
  }
}

void inorder(Node u){

  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  
  if(u==NIL) return;  
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25132
I=lambda:map(int,input().split())
n,m=I()
r=range(n)
y=[[] for i in r]
z=[None for i in r]

for _ in [0]*m:
  i,j,k=I()
  y[i-1]+=[[j-1, k]]
  y[j-1]+=[[i-1,-k]]

for i in r:
  if z[i]==None:
    z[i]=0 
  q=[i]
  while q:
    p=q.pop()
    for j,k in y[p]:
      if z[j]==None:
        q+=[j]
        z[j]=z[p]+k
      elif z[j]!=z[p]+k:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 109824
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
double f(int x,int y){
  if (x==1000 and y==3) return 1000.0;
  return pow(floor(pow(x,1.0/y)),y);
}
int main(){
  int x;
  cin>>x;
  cout<<max({f(x,2),f(x,3),f(x,4),f(x,5),f(x,6),f(x,7),f(x,8),f(x,9),f(x,10)})<<endl;
}


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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


int mod(int a, int b){return (a%b+b)%b;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};




template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}


vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.pb(buffer);
    }
    return v;
}


bool is_prime(ll n){
    if(n == 2) return true;
    if(n == 1 or !(n & 1)) return false;

    random_device rnd;
    ll d = (n-1) >> 1;
    while(!(d&1))
        d >>= 1;

    rep(k, 100){

        ll a = rnd() % (n-1) + 1;
        ll t = d;
        ll y = powMod(a, t, n);

        while(t != (n-1) and y != 1 and y != (n-1)){
            y = powMod(y,2,n);
            t <<= 1;
        }

        if(y != n-1 and !(t & 1)){
            return false;
        }
    }

    return true;
}



int main(){

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

    int n;
    cin >> n;
    
    pll m = make_pair(0, 0);

    rep(i, n){
        int a, b;
        cin >> a >> b;


        if(m.first < a)
            m = make_pair(a, b);
    }


    ppp(m.first+m.second);




    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fop(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
int main() {
  ll n, k;
  cin >> n >> k;
  ll h[n],dp[n];
  fop(i,0,n) cin>>h[i];
  dp[0] = 0;
  fop(i,1,n){
    dp[i]=2e9;
    fop(j,0,min(i,k)){
      dp[i]=min(dp[i],dp[i-j-1]+abs(h[i]-h[i-j-1]));
    }
  }
  cout << dp[n-1] << '\n';
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    int A, B;
    cin >> A >> B;
    cout << max({A+B, A-B, A*B}) << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int K,X;
    cin>>X>>K;
  for(int i=1;i<X;i++){
      cout<<K-(X-i)<<endl;
  }
  cout<<K<<endl;
   for(int i=1;i<X;i++){
      cout<<K+i<<endl;
  }

    return 0;
}

Measured memory_bytes: 3568
//
// Binary Indexed Tree
//
// verified:
//   AOJ Course DSL_2_B Range Query - Range Sum Query (RSQ)
//     http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_B&lang=jp
//

#include <iostream>
#include <vector>
using namespace std;


template <class Abel> struct BIT {
	vector<Abel> dat;
	Abel UNITY_SUM = 0;						// to be set

	/* [1, n] */
	BIT(int n) : dat(n, UNITY_SUM) { }
	void init(int n) { dat.sssign(n + 1, UNITY_SUM); }

	/* a is 1-indexed */
	inline void add(int a, Abel x) {
		for (int i = a; i < (int)dat.size(); i += i & -i)
			dat[i] = dat[i] + x;
	}

	/* [1, a], a is 1-indexed */
	inline Abel sum(int a) {
		Abel res = UNITY_SUM;
		for (int i = a; i > 0; i -= i & -i)
			res = res + dat[i];
		return res;
	}

	/* [a, b), a and b are 1-indexed */
	inline Abel sum(int a, int b) {
		return sum(b - 1) - sum(a - 1);
	}

    /* debug */
	void print() {
		for (int i = 1; i < (int)dat.size(); ++i) cout << sum(i, i + 1) << ",";
		cout << endl;
	}
};



int main() {
    int N, Q; cin >> N >> Q;
    BIT<int> bit(N+1);
    for (int query = 0; query < Q; ++query) {
        int com, x, y; cin >> com >> x >> y;
        if (com == 0) bit.add(x, y);
        else cout << bit.sum(x, y+1) << endl;
    }
}



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

int main() {
 long long n,a,b;
  cin >> n >> a >> b;
  if((n==1 && a!=b) || a>b){
    cout << 0 << endl;
    return 0;
  }
  cout << (b-a)*(n-2)+1 << endl;
}
 

Measured memory_bytes: 3628
x,y = map(int,input().split())
di = 10**9+7

def pow_k(xx, n):
    """
    O(log n)
    """
    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K = (K*xx)%di
        xx = (xx*xx)%di
        n //= 2

    return (K * xx)%di

if (2*y-x)%3>0 and (2*x-y)%3>0:
    print(0)
else:
    a = (2*y-x)//3
    b = (2*x-y)//3
    if a<0 or b<0:
        print(0)
    else:
        lis = [i for i in range(a+b+1)]
        lis[0]=1
        for i in range(1,a+b+1):
            lis[i] = (lis[i-1]*lis[i])%di
        lisr = [pow_k(i,di-2) for i in range(max(a,b)+1)]
        lisr[0]=1
        #print(lis,lisr)
        for i in range(1,max(a,b)+1):
            lisr[i] = (lisr[i-1]*lisr[i])%di
        tmp = (lis[a+b]*lisr[a])%di
        print((tmp*lisr[b])%di)


Measured memory_bytes: 85360
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>
#define ll long long
#define rint register int
#define N 200005
using namespace std; 
inline char get(){
	const int TOP=1000000;
	static char T[TOP],*x=T,*y=T;
	return x==y&&(y=(x=T)+fread(T,1,TOP,stdin),x==y)?EOF:*x++;
}
inline int read (){
	register int num,sign=1;register char c;
	while (((c=get())<'0'||c>'9')&&c!='-');c=='-'?num=sign=0:num=c-48;
	while ((c=get())>='0'&&c<='9')num=(num<<3)+(num<<1)+(c-48);
	return sign?num:-num;
}
int n,l;
int B[N],A[N];
ll ans;
void solve(){
	B[n]=l-A[n];B[n-1]=A[n-1];
	ll s=B[n]+B[n-1];
	ans=max(ans,max(1ll*A[n],s*2-B[n]));
	for(rint i=n-2;i>=1;--i){
		rint len=n-i+1,id;
		B[i]=A[i];s+=A[i];
		if(len&1)id=n-len/2;
		else{
			id=n-len/2+1;
			s-=B[id];B[id]=l-A[id];s+=B[id]; 
		}
		ans=max(ans,s*2-B[id]);
	} 
} 
int main(){
	l=read();n=read();
	for(rint i=1;i<=n;++i)A[i]=read(); 
	solve();reverse(A+1,A+1+n);
	for(rint i=1;i<=n;++i)A[i]=l-A[i];
	solve();printf("%lld\n",ans);
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
 
using namespace std;
 
int type, n, x;
int rates[9];
 
int main(){
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> x;
        if(x < 3200) rates[x/400]++;
        else rates[8]++;
	}
 
	for(int i = 0; i < 8; ++i) type += (rates[i] > 0);
	int mi = type + (type == 0 && rates[8] > 0);
	if(type == 0 && rates[8] > 0) mi = 1;
	else mi = type;
	int ma = type + rates[8];
	printf("%d %d\n", mi, ma);
}

Measured memory_bytes: 256
package main

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

func main() {
	N := nextInt()
	c := make([]int, 10001)

	for x := 1; x <= 100; x++ {
		for y := 1; y <= 100; y++ {
			for z := 1; z <= 100; z++ {
				n := x*x + y*y + z*z + x*y + y*z + z*x

				if n <= 10000 {
					c[n]++
				}
			}
		}
	}

	for i := 1; i <= N; i++ {
		fmt.Println(c[i])
	}

	fmt.Println()
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)
	return i
}

func debug(args ...interface{}) {
	fmt.Fprintln(os.Stderr, args)
}


Measured memory_bytes: 1960
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cmath>     // pow
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }
// cout << fixed << setprecision(10);
// vector<vector<int>> vec(H, vector<int>(W))    // int H*W

int main() {
    int N;
    cin >> N;
    cout << pow(N,3) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
                using namespace std;
                typedef long long ll;
                #define INPUT()              freopen("input.txt", "r", stdin)
                #define OUTPUT()             freopen("output.txt", "w", stdout)
                #define F                    first
                #define S                    second
            //Templatefunctions
                template<typename T>T gcd(T x, T y) { if (y == 0)return x; else return gcd(y, x%y);}
                template <class T> T euclideanDistance(T x1 , T x2 , T y1 , T y2){return sqrt(( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ));}
                template <class T> T digitSum(T n){T sum = 0;while(n > 0)sum += n % 10,n /= 10;return sum;}
           



                int main()
                {
                        int w , h , n;
                        scanf("%d%d%d",&w,&h,&n);
                        int x0 = 0,xn = w , y0 = 0, yn = h;
                        for(int i = 0 ; i < n ;i++)
                        {
                            int x , y , a;
                            scanf("%d%d%d",&x, &y ,&a);

                            if(a == 1)
                            {
                                if(x0 < x)x0 = x;
                            }else if(a == 2)
                            {
                                if(xn > x)xn = x;
                            }else if(a == 3)
                            {
                                if(y0 < y)y0 = y;
                            }else
                            {
                                if(yn > y)yn = y;
                            }
                        }
                        int a , b;
                        if(y0 > yn)b = 0;
                        else if(x0 > xn)a = 0;
                        else
                        {
                            a = (xn - x0);
                            b = (yn - y0);
                        }
                        printf("%d\n",a*b);
                }


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int n, m, ans = 0;

	scanf("%d%d", &n, &m);
	if(n > 1){
		ans += n * (n - 1) / 2;
	}
	if(m > 1){
		ans += m * (m - 1) / 2;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        int nouse = scan.nextInt();
        String s = scan.next();
        
        int x = 0;
        int max = 0;
        
        for(int i=0;i<s.length();i++)
        {
            if(s.charAt(i) == 'I')
            {
                x++;
                if(x>max)
                {
                    max = x;
                }
            }
            else
            {
                x--;
            }
        }
        System.out.println(max);
    }
}

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

ARR = [int(s) for s in input().split(" ")]

def calculate(n,arr):

    brr = []
    for index,ar in enumerate(arr):
        obj = {}
        obj.__setitem__("index",index)
        obj.__setitem__("value",arr[index])
        brr.append(obj)

    brr = sorted(brr,key=lambda x:x.get("value"))

    dict = {}

    for index,br in enumerate(brr):
        dict.__setitem__(br.get("index"),index)

    midIndexMin = (N - 1) // 2
    midIndexMax =  N // 2
    midIndexMinValue = brr[midIndexMin].get("value")
    midIndexMaxValue = brr[midIndexMax].get("value")

    for index,arr in enumerate(arr):
        m = dict.get(index)
        if m <= n // 2 - 1:
            print(midIndexMaxValue)
        else:
            print(midIndexMinValue)



calculate(N,ARR)

Measured memory_bytes: 107020
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);

    var(i64, X, Y, A, B, C);

    vector<i64> a(A), b(B);
    priority_queue<i64> c;
    rep(i, 0, A) {
        read(a[i]);
    }
    rep(i, 0, B) {
        read(b[i]);
    }
    rep(i, 0, C) {
        var(i64, v);
        c.push(v);
    }

    sort(all(a), greater<>());
    sort(all(b), greater<>());

    vector<i64> hoge;
    hoge.reserve(X + Y);
    rep(i, 0, X) hoge.push_back(a[i]);
    rep(i, 0, Y) hoge.push_back(b[i]);

    sort(all(hoge));
    for (auto &e : hoge) {
        if (c.empty()) break;
        const i64 v = c.top();
        if (v > e) {
            e = v;
            c.pop();
        }
    }

    print(accumulate(all(hoge), 0LL));



    return 0;
}


Measured memory_bytes: 4212