akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll n,m,x,suma=0,sumb=0;
    cin >> n >> m >> x;
    vll a(m);
    rep(i,m){
        cin >> a[i];
        if(a[i]>=0 && a[i]<x)suma++;
        else sumb++;
    }
    cout << min(suma,sumb) << endl;
    return 0;
}


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

int main() {
    double r;
    cin >> r;
    cout << fixed << setprecision(10) << M_PI * r * r << " " << 2 * M_PI * r << endl; 
    return 0;
}



Measured memory_bytes: 3200
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<math.h>
#include<map>
typedef long long int ll;
using namespace std;
#define maxn 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f3f
const int mm=1e6;
ll d[mm];
int main()
{
	ll n,m,i,j,k,kk,a,b,t;
	cin>>n;
	cin>>a>>b;
	for(i=a;i<=b;i++)
	if(i%n==0)
	{
	printf("OK\n");return 0;}
	printf("NG\n");

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define bitsz(x) int(__builtin_popcount(x))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb(x) push_back(x)
#define INF 1e9
#define LINF 1e18
#define mod 1000000007
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
const int di[4] = {1,0,-1,0};
const int dj[4] = {0,1,0,-1};


int main() {
    string n; cin >> n;
    int m = sz(n);
    if (n[m-1]=='2'||n[m-1]=='4'||n[m-1]=='5'||n[m-1]=='7'||n[m-1]=='9') cout << "hon" << endl;
    if (n[m-1]=='0'||n[m-1]=='1'||n[m-1]=='6'||n[m-1]=='8') cout << "pon" << endl;
    if (n[m-1]=='3') cout << "bon" << endl;
}

Measured memory_bytes: 3592
// Copyright 2020 Tsutomu ISHIKAWA
// Author: Tsutomu ISHIKAWA

#include <iostream>

int main() {
    int a;

    std::cin >> a;
    int mod_a = a % 2;
    if (mod_a == 0) {
        std::cout << a+1 << std::endl;
    } else {
        std::cout << a-1 << std::endl;
    }

    return 0;
}

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

int main() {
  
  int a,b;
  
  cin >> a >> b;
  
  if (a%2 == 1 && b%2 == 1)
    cout << "Odd" << endl;
  else
    cout << "Even" << endl;
    
    
    
}

Measured memory_bytes: 256
#include<iostream>

int main(){
    int W,H,x,y,r;
    std::cin>>W>>H>>x>>y>>r;
    int flag=1;
    if(x-r<0)flag=0;
    if(x+r>W)flag=0;
    if(y-r<0)flag=0;
    if(y+r>H)flag=0;
    if(flag==0)std::cout<<"No\n";
    else std::cout<<"Yes\n";

}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


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

  int k;
  cin >> k;

  int i = 0;
  while (i < int(s.size())) {
    if (s[i] != '1') break;
    i++;
  }

  if (i < k) cout << s[i] << endl;
  else cout << 1 << endl;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC113C
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var N = NM[0];
            var M = NM[1];
            
            City[] cities = new City[M];
            for (int i = 0; i < M; i++)
            {
                var PY = Console.ReadLine().Split().Select(long.Parse).ToArray();
                cities[i] = new City((int)PY[0], PY[1]);
            }

            cities = cities.OrderBy(x => x.Prefecture).ThenBy(x=>x.Year).ToArray();

            int nowPrefecture = -1;
            int nowCount = 1;
            for(int i = 0; i < M; i++)
            {
                if (cities[i].Prefecture != nowPrefecture)
                {
                    nowPrefecture = cities[i].Prefecture;
                    nowCount = 1;
                }
                cities[i].NumberInPrefecture = nowCount;
                nowCount++;
            }
            cities = cities.OrderBy(x => x.CityNumber).ToArray();
            for (int i = 0; i < M; i++)
            {
                Console.WriteLine(cities[i].CognitionNumber);
            }
            Console.ReadKey();
        }

        class City
        {
            static int CityNumberCount = 1;

            public int CityNumber;
            public long Year;
            public int Prefecture;
            public int NumberInPrefecture;
            
            public City(int prefecture, long year)
            {
                CityNumber = CityNumberCount;
                CityNumberCount++;
                Year = year;
                Prefecture = prefecture;
            }

            string P
            {
                get
                {
                    return FillZero(Prefecture);
                }
            }
            string x
            {
                get
                {
                    return FillZero(NumberInPrefecture);
                }
            }

            public string CognitionNumber
            {
                get
                {
                    return P + x;
                }
            }

            private string FillZero(int number)
            {
                return string.Format("{0:000000}", number);
            }
        }
    }
}


Measured memory_bytes: 34720
/* include */
#include"bits/stdc++.h"
/* namespace */
using namespace std;
/* typedef */
/* long系 */
typedef long long ll;	// long long
typedef long double ld;	// long double
/* vector系 */
typedef vector<int> vint;	// intのvector
typedef vector<double> vdouble;	// doubleのvector
typedef vector<ll> vll;	// llのvector
typedef vector<ld> vld;	// ldのvector
typedef vector<pair<int, int>> vi_i;	// i_iのvector
typedef vector<pair<double, double>> vd_d;	// d_dのvector
typedef vector<pair<ll, ll>> vl_l;	// l_lのvector
typedef vector<pair<ld, ld>> vld_ld;	// ld_ldのvector
typedef vector<string> vstring;	// stringのvector
/* pair系 */
typedef pair<int, int> i_i;	// int同士のpair
typedef pair<double, double> d_d;	// double同士のpair
typedef pair<ll, ll> l_l;	// ll同士のpair
typedef pair<ld, ld> ld_ld;	// ld同士のpair
/* define */
#define pb push_back	// push_back
#define all(v) v.begin(),v.end()	// コンテナ全体
#define PI (acos(-1))  // 円周率pi
/* 変数入出力 read, write */
template <typename T>	// 1変数
void read(T& x) {
    cin >> x;
}
template <typename T, typename T0>	// 2変数
void read(T& x, T0& y) {
    cin >> x >> y;
}
template <typename T, typename T0, typename T1>	// 3変数
void read(T& x, T0& y, T1& z) {
    cin >> x >> y >> z;
}
template <typename T, typename T0, typename T1, typename T2>	// 4変数
void read(T& x, T0& y, T1& z, T2& w) {
    cin >> x >> y >> z >> w;
}
template <typename T>	// 1変数
void write(T& x) {
    cout << x << endl;
}
template <typename T, typename T0>	// 2変数
void write(T& x, T0& y) {
    cout << x << " " << y << endl;
}
template <typename T, typename T0, typename T1>	// 3変数
void write(T& x, T0& y, T1& z) {
    cout << x << " " << y << " " << z << endl;
}
template <typename T, typename T0, typename T1, typename T2>	// 4変数
void write(T& x, T0& y, T1& z, T2& w) {
    cout << x << " " << y << " " << z << " " << w << endl;
}
// vectorの出力
template <typename T>
void printvec(const vector<T> &data) {
for (const auto elm : data) {
    cout << elm << " ";
}
cout << endl;
}


int main(int argc, char const *argv[])
{
    ll k, n; read(k, n);
    vll a;
    a.resize(n);
    for (ll rv = 0; rv < n; rv++) {
        cin >> a[rv];
    }
    sort(all(a));
    ll max = 0, reg = 0;
    for (ll i = 0; i < n; i++) {
        if (i == 0) {
            reg = k - a[n - 1] + a[0];
        }
        else {
            reg = a[i] - a[i - 1];
        }
        if (max < reg) {
            max = reg;
        }
    }
    cout << k - max << endl;
    
    return 0;
}


Measured memory_bytes: 1792
/*
    JAI JAGANNATH!
*/
//@Author : zanj0
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
#define ff              first
#define ss              second
#define pb              push_back
#define mp              make_pair
#define pii             pair<lli,lli>
#define vi              vector<lli>
#define mii             map<lli,lli>
#define pqb             priority_queue<lli>
#define pqs             priority_queue<lli,vi,greater<lli> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            lli x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void zanj0()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}
lli n, m;
lli x;
lli v[15][15];
lli help(lli idx, vector <lli> cnt) {
	if (idx == n) {

		bool ok = true;
		for (lli i : cnt) {
			// cout << i << " " ;
			if (i < x) ok = false;
		}
		// cout << endl;
		return ok ? 0 : inf;
	}
	lli ret = inf;
	ret = min(ret, help(idx + 1, cnt));
	for (lli i = 0; i < m; i++) {
		cnt[i] += v[idx][i + 1];
	}
	/*for (lli i : cnt) {
		cout << i << "-- ";
	}
	cout << endl;*/
	ret = min(ret, v[idx][0] + help(idx + 1, cnt));
	for (lli i = 0; i < m; i++) {
		cnt[i] -= v[idx][i + 1];
	}
	return ret;
}
void solve() {
	cin >> n >> m >> x;
	vector <lli> cnt(m);

	for (lli i = 0; i < n; i++) {
		for (lli j = 0; j <= m; j++) {
			cin >> v[i][j];
		}
	}
	/*for (lli i = 0; i < n; i++) {
		for (lli j = 0; j <= m; j++) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << endl;*/
	lli ret = help(0, cnt);
	if (ret >= inf) {
		cout << -1 << endl;
	} else cout << ret << endl;
}
int main()
{
	zanj0();
	solve();
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define minf 0x80000000
using namespace std;

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	vector<vector<int>>c(3,vector<int>(3));
	for(auto&i:c)for(auto&j:i)cin>>j;
	vector<int>a(3,minf),b(3,minf);
	a.front()=0;
	for(int j=0;j<3;++j){
		for(int i=0;i<3;++i){
			if(a.at(i)==minf){
				a.at(i)=c.at(i).at(j)-b.at(j);
			}else if(b.at(j)==minf){
				b.at(j)=c.at(i).at(j)-a.at(i);
			}
		}
	}
	bool yes=true;
	for(int j=0;j<3;++j){
		for(int i=0;i<3;++i){
			if(c.at(i).at(j)!=a.at(i)+b.at(j)){
				yes=false;
			}
		}
	}
	cout<<(yes?"Yes"s:"No"s)<<"\n"s;
}

Measured memory_bytes: 256
#include <stdio.h>

using namespace std;
typedef long long llong;

#define MAX
const llong mod = 1000000000 + 7;

int main()
{
  int A, B, C, D;
  scanf("%d%d", &A, &B);
  scanf("%d%d", &C, &D);

  int flag = 1;
  while (A > 0 && C > 0)
  {
    if (flag)
    {
      C -= B;
      flag = 0;
    }
    else
    {
      A -= D;
      flag = 1;
    }
  }

  if (flag)
  {
    printf("No");
  }
  else
  {
    printf("Yes");
  }

  return 0;
}

Measured memory_bytes: 1728
/*
*
* author: ian macleod
*
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef vector<long long int> vll;

#define IO                 \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
 
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i+=1)
#define rf(i,a,b) for(ll i=a;i>=b;i--)

ll power(ll x, ll y) {
    ll res = 1;     // Initialize result
    x = x ;
    if (y==0)return 1;
    if(x==0)return 0;
    while (y > 0) {
        if (y & 1)
            res = (res*x);
        y = y>>1; // y = y/2
        x = (x*x);  // Change x to x^2
    }
    return res;
}


void solve() {
    
    ll a, b;
    cin >> a >> b;
    cout << a * b << endl;
    
    return ;
}



int main() {
    solve();
}



Measured memory_bytes: 3608
import java.io.*;
import java.util.*;

public class Main {
  private static boolean debug = false;
  private static boolean elapsed = false;

  private static PrintWriter _err = new PrintWriter(System.err);

  private void solve(Scanner sc, PrintWriter out) {
    String s = sc.next();
    char ch = s.charAt(0);
    if (ch == 'a' || ch == 'i' || ch == 'u' || ch == 'e' || ch == 'o') {
      out.println("vowel");
    } else {
      out.println("consonant");
    }
  }
  private long C(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    for (long i = r; i > 1; --i) {
      res /= i;
    }
    return res;
  }
  private long P(long n, long r) {
    long res = 1;
    for (long i = n; i > n - r; --i) {
      res *= i;
    }
    return res;
  }
  private long ceil2pow(long n) {
    if (n == 0) {
      return 1;
    }
    n--;
    n |= (n >>> 1);
    n |= (n >>> 2);
    n |= (n >>> 4);
    n |= (n >>> 8);
    n |= (n >>> 16);
    n++;
    return n;
  }
  /*
   * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
   * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
   */
  public static void main(String[] args) {
    long S = System.currentTimeMillis();

    Scanner sc = new Scanner(System.in);
    PrintWriter out = new PrintWriter(System.out);
    new Main().solve(sc, out);
    out.flush();

    long G = System.currentTimeMillis();
    if (elapsed) {
      _err.println((G - S) + "ms");
    }
    _err.flush();
  }
}

Measured memory_bytes: 10192
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 99999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(150) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> M;
  DV(G,int,N,N,0);
  rep(i,0,M){
    cin >> A >> B;
    G[A-1][B-1]=1;
    G[B-1][A-1]=1;
  }
  Vec(P,int,N,0);rep(i,0,N)P[i]=i;
  do{
    if(P[0]!=0)continue;
    flag=1;
    rep(i,0,N-1)if(!G[P[i]][P[i+1]])flag=0;
    if(flag)sum++;
  }while(next_permutation(P.begin(),P.end()));
  Out(sum);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[1000000];
int main(){
    int n; cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    ll ans = a[1] - a[0], m = min(a[0], a[1]);
    for(int i = 2; i < n; i++){
    	if(m > a[i]) m = a[i];
        else if(ans <= a[i] - m) ans = a[i] - m;
    }
  //  if(ans == 0) ans = -1;
    cout << ans << endl;
}


Measured memory_bytes: 4652
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    char c;
    cin >>c;
    bool ans;
    switch(c){
        case 'a':
        case 'i':
        case 'u':
        case 'e':
        case 'o':
        ans=true;
        break;
        default:
        ans=false;
    }

    if(ans){
        cout<<"vowel"<<endl;
    }else{
        cout<<"consonant"<<endl;
    }
    return 0;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}


Measured memory_bytes: 256
class UnionFind:
    # 各要素の親要素の番号を格納するリスト
    # 要素が根（ルート）の場合は-(そのグループの要素数)を格納する
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # 要素xが属するグループの根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # 要素xが属するグループと要素yが属するグループとを併合する
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # 要素xが属するグループのサイズ（要素数）を返す
    def size(self, x):
        return -self.parents[self.find(x)]

    # 要素x, yが同じグループに属するかどうかを返す
    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    # すべての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    # グループの数を返す
    def group_count(self):
        return len(self.roots())

    # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    # ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す (print()での表示用)
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def resolve():
    N, M, K = map(int, input().split())
    uf = UnionFind(N)
    sub_friend = [1] * N  # +1: 自分自身

    frind = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(lambda x: int(x) - 1, input().split())
        frind[a].append(b)
        frind[b].append(a)
        sub_friend[a] += 1
        sub_friend[b] += 1

    block = [[] for _ in range(N)]
    for _ in range(K):
        c, d = map(lambda x: int(x) - 1, input().split())
        block[c].append(d)
        block[d].append(c)

    for i in range(N):
        for to in frind[i]:
            uf.union(i, to)

    ans = [uf.size(i) - sub_friend[i] for i in range(N)]

    for i in range(N):
        for bl in block[i]:
            if uf.is_same(i, bl):
                ans[i] -= 1
    print(*ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 49276
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut aa: [usize; n],
    }

    aa.sort();

    let ans = if n % 2 == 0 {
        let mid = n / 2;
        let smalls = aa.iter().copied().take(mid).rev().collect::<Vec<_>>();
        let larges = aa.iter().copied().skip(mid).collect::<Vec<_>>();
        let mut ans = larges.iter().map(|&e| 2 * e).sum::<usize>();
        ans -= larges[0];
        ans += smalls[0];
        ans -= smalls.iter().map(|&e| 2 * e).sum::<usize>();
        ans
    } else {
        let mid = n / 2;
        let smalls = aa.iter().copied().take(mid).rev().collect::<Vec<_>>();
        let larges = aa.iter().copied().skip(mid+1).collect::<Vec<_>>();
        let mid = aa[mid];

        let mut temp = larges.iter().map(|&e| 2 * e).sum::<usize>();
        temp -= smalls.iter().map(|&e| 2 * e).sum::<usize>();
        let temp1 = temp + smalls[0] - mid;
        let temp2 = temp - larges[0] + mid;

        std::cmp::max(temp1, temp2)
    };

    println!("{}", ans);
}


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

int main(){
    int N,Y;
    cin>>N>>Y;
    Y/=1000;
    int x,y,z=-1;
    
    int l = max(0, (5*N-Y+3)/4);
    int r = min(min(N,Y),(int)floor((10*N-Y)/9.));
    
    for(int i=l;i<=r;i++){
        if(i%5==Y%5){
            z = i;
            break;
        }
    }
    if(z==-1)cout<<"-1 -1 -1"<<endl;
    else{
        x = (Y-z)/5 - N + z;
        y = N-z-x;
        
        cout<<x<<" "<<y<<" "<<z<<endl;
    }
}


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

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<ll, ll>
const ll  MOD = 1000000007;

int main() {
	ll n;
	cin >> n;
	vector < tuple < string, ll, ll >> sp;
	rep(i, n) {
		string s; ll p;
		cin >> s >> p;
		p = 100 - p;
		sp.push_back(make_tuple(s, p, i + 1));
	}
	sort(all(sp));
	rep(i, n) cout << get<2>(sp.at(i)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
int x;
vector<int>vec;
set<int>st;
signed main(){
    cin>>x;
    for(int i=-999;i<=999;i++){
        vec.push_back(i*i*i*i*i);
        st.insert(i*i*i*i*i);
    }
    for(int i=0;i<2000;i++){
        int dif=vec[i]-x;
        if(st.find(dif)!=st.end()){
            rep(j,2000){
                if(vec[j]==dif){
                    cout<<i-999<<" "<<j-999<<endl;
                    return 0;
                }
            }
        }
    }
    return 0;
}



Measured memory_bytes: 3764
n,i,j;
#define rep(i,a) for(i=0;i<a;i++) 
main(){
	while(scanf("%d",&n),n){
		int mi=999;
		rep(i,110)rep(j,1010)mi=fmin(mi,(n<i*i*i+j*j?999:i+j+n-i*i*i-j*j));
		printf("%d\n",mi);
	}
return 0;
}

Measured memory_bytes: 604
a=input()
a,b=a.split(" ")
a=int(a)
b=int(b)
pro=[]
temp=input().split(" ")
for i in range(a):
    pro.append(int(temp[i]))
pro.sort(reverse=True)
sumvote=sum(pro)
for i in range(b):
    if pro[i]<1/(4*b)*sumvote:
        print("No")
        quit()
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

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

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, n, m);
  vector<int> a(n), b(n);
  vector<int> c(m), d(m);
  for (int i = 0; i < n; ++i) cin >> a[i] >> b[i];
  for (int j = 0; j < m; ++j) cin >> c[j] >> d[j];

  for (int i = 0; i < n; ++i) {
    int dist = INT_MAX;
    int checkpoint = 0;
    for (int j = 0; j < m; ++j) {
      int tmp = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (tmp < dist) {
        dist = tmp;
        checkpoint = j;
      }
    }
    cout << checkpoint + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <cmath>
#define EPS 1e-9
using namespace std;
typedef complex<double> xy_t;
int n;
xy_t points[301];
int count_in(xy_t center)
{
  int ans=0;
  for(int i=0;i<n;i++)
  {
    if (abs(center-points[i])<1.0+EPS)
      ans++;
  }
  return ans;
}

xy_t ppdcl(xy_t a)
{
  return xy_t(a.imag(),-a.real());
}
xy_t delta_v(xy_t C1,xy_t C2)
{
  xy_t half=(C1-C2)*0.5;
  double l=abs(half);
  return ppdcl(half)*sqrt(1-l*l)*(1.0/l);
}

int main()
{
  while(1)
  {
    cin>>n;
    if (n==0) break;
    double x,y;
    for(int i=0;i<n;i++)
    {
      cin>>x>>y;
      points[i]=xy_t(x,y);
    }
    int maxn=1;
    for(int i=0;i<n;i++)
    {
      for(int j=i;j<n;j++)
      {
        if(abs(points[i]-points[j])<2.0+EPS)
        {
          xy_t mid_p=(points[i]+points[j])*0.5;
          maxn=max(maxn,count_in(mid_p+delta_v(points[i],points[j])));
          maxn=max(maxn,count_in(mid_p-delta_v(points[i],points[j])));
        }
        /*double d=abs(points[j]-points[i])/2;
        xy_t v=(points[j]-points[i])/(2*d);
        if(d<1)
        {
            maxn=max(maxn,count_in(points[i]+d*v+sqrt(1-d*d)*v*xy_t(0,+1)));
            maxn=max(maxn,count_in(points[i]+d*v+sqrt(1-d*d)*v*xy_t(0,-1)));
        }*/
      }
    }
    cout<<maxn<<endl;
  }

}



Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;
int main() {
	int R[MAX], n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> R[i];
	}
	int maxv = -2000000000;
	int minv = R[0];
	for (int i = 1; i < n; i++) {
		maxv = max(maxv, R[i] - minv);
		minv = min(minv, R[i]);
	}
	cout << maxv<<endl;
	return 0;
}


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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL<<60;
const ll mod = 1000000007;		



int main() {
	
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c && c == a)cout << "Yes" << endl;
	else cout << "No" << endl;
	
	
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    s = S()
    t = S()
    if s+t == t[::-1]+s[::-1]:
        print("YES")
    else:
        print("NO")

#B
def B():
    n = I()
    for i in range(int(n**0.5)+2)[::-1]:
        if i*i <= n:
            print(i*i)
            quit()
#C
def C():
    n = I()
    a = LI()
    b = LI()
    c = LI()
    q = [0 for i in range(n)]
    ans = 0
    a.sort()
    b.sort()
    c.sort()
    for i in range(n):
        j = bisect.bisect_left(a,b[i])
        q[i] = j
    for i in range(n-1):
        q[i+1] += q[i]
    q.insert(0,0)
    for i in range(n):
        j = bisect.bisect_left(b,c[i])
        ans += q[j]
    print(ans)
#D
def D():
    def dijkstra():
        d = [float("inf") for i in range(k)]
        q = [[0,1]]
        d[1] = 0
        while q:
            dx,x = heappop(q)
            for y,dy in v[x]:
                if d[y] > dx+dy:
                    d[y] = dx+dy
                    heappush(q,[d[y],y])
        print(d[0]+1)
    k = I()
    if k == 1:
        print(1)
        quit()
    v = [[] for i in range(k)]
    for i in range(1,k):
        v[i].append([(i+1)%k,1])
        v[i].append([i*10%k,0])
    dijkstra()
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()


Measured memory_bytes: 88880
use std::collections::VecDeque;
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let l = read::<i64>();
    let mut tseq = vec![0.0; n];
    let mut vseq = vec![0; n];
    for i in 0..n {
        tseq[i] = read::<f64>();
        vseq[i] = read::<i64>();
    }
    let mut anss = vec![0.0; n];
    anss[0] = tseq[0];
    let mut deq = VecDeque::<(f64, i64)>::new();
    deq.push_back((tseq[0], vseq[0]));
    let mut total_t = tseq[0] * vseq[0] as f64;
    for i in 1..n {
        let mut rest = vseq[i];
        while rest > 0 {
            if deq[0].1 <= rest {
                total_t -= deq[0].0 * deq[0].1 as f64;
                rest -= deq[0].1;
                deq.pop_front();
            } else {
                total_t -= deq[0].0 * rest as f64;
                deq[0].1 -= rest;
                rest = 0;
            }
        }
        let mut t = tseq[i];
        let mut v = vseq[i];
        total_t += t * v as f64;
        while deq.len() > 0 && deq.back().unwrap().0 > t {
            let (pt, pv) = deq.pop_back().unwrap();
            t = (pt * pv as f64 + t * v as f64) / (pv + v) as f64;
            v = pv + v;
        }
        deq.push_back((t, v));
        anss[i] = total_t / l as f64;
    }
    for i in 0..n {
        println!("{:.8}", anss[i]);
    }
}


Measured memory_bytes: 33012
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
using namespace std;

int main(){
  int n;
  cin>>n;
  long long a[n],ans=0;
  cin>>a[0];
  for(int i=1;i<n;i++){
    cin>>a[i];
  }

  long long tmp=0;
  int l=0,r=0;
  while(l<n){
    while(r<n&&(tmp^a[r])==tmp+a[r]){
      tmp^=a[r];
      r++;
      ans++;
    }
    ans+=r-l-1;
    tmp^=a[l];
    l++;
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

int main() {
    int w, h, n;
    cin >> w >> h >> n;
    int a, b;
    cin >> a >> b;
    int nowx = a, nowy = b;
    int ans = 0;
    for (int i = 0; i < n - 1; ++i) {
        int x, y;
        cin >> x >> y;
        if (nowx < x && nowy < y) {
            ans += max(x - nowx, y - nowy);
        } else if (nowx > x && nowy > y){
            ans += max(nowx - x, nowy - y);
        } else {
            ans += abs(x - nowx) + abs (y - nowy);
        }
        nowx = x;
        nowy = y;
    }
    cout << ans << '\n';
}


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

typedef long double LD;
typedef long long ll;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef vector<pii> vpii;

#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second
#define INF             2147483647
#define endl            "\n"
#define FasterIO        ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0) ;
#define precision(a)    cout << fixed << setprecision(a)
#define bug(a,b)        cout<<a<<"\t"<<b<<"\n";
#define Case(a,b)       cout<<"Case "<<a<<": "<<b<<"\n";
#define reset(a,b)      memset(a,b,sizeof(a));
#define For(x,n)        for(int i=x; i<n; i++)

const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const int mod = 1e9+7;
const double PI=acos(-1);

int strtoint(string str){
    stringstream ss(str);
    int x = 0;
    ss >> x ;
    return x ;
}
string intostr(int x){
    stringstream ss;
    ss << x;
    string str = ss.str();
    return str;
}
void rem(string &s, const string &c) {
	auto pos = s.find(c);
	if (pos == string::npos) {
		cout << -1 << endl;
		exit(0);
	}
	s.erase(0, pos + 1);
}
void println (int n){
    cout<<n<<"\n";
}
void printvec(vector <int> &a){
    for (int i=0;i<a.size();i++){
        cout<<a[i]<<" ";
    }
    cout<<"\n";
}

void printgraph(vector <int> g[],int e){
    for (int i=0;i<e;i++){
        cout<<i<<" --> ";
        for (int j=0;j<g[i].size();j++){
            cout<<g[i][j]<<" ";
        }
        cout<<"\n";
    }
}

void printmap (map <int,int> &mymap){
    for (auto itr = mymap.begin(); itr != mymap.end(); ++itr) {
        cout << '\t' << itr->first
             << '\t' << itr->second << '\n';
    }
    cout << "\n";
}

char grid[1005][1005];
int dp[1005][1005];


void solve(){
    int n,m;
    cin>>n>>m;
    for (int i=0;i<n;i++){
        cin>>grid[i];
    }

    for (int i=0;i<n;i++){
        for (int j=0;j<m;j++){
            if (grid[i][j]=='#')continue;

            if (i==0 && j==0){
                dp[i][j]=1;
                continue;
            }

            if (i>0)dp[i][j]+=dp[i-1][j];
            if (j>0)dp[i][j]+=dp[i][j-1];

            dp[i][j]=dp[i][j]%mod;
        }
    }
    cout<<dp[n-1][m-1]<<endl;

}


int main(){
    //FasterIO;

    solve();
    return 0;
}


Measured memory_bytes: 8516
n=int(input())
a=list(map(int,input().split()))
p=[0,abs(a[1]-a[0])]
for i in range(1,n-1):
    t=p[:]
    p[0]=min(p[1],abs(a[i]-a[i-1])+p[0])
    p[1]=min(t[1]+abs(a[i+1]-a[i]),t[0]+abs(a[i+1]-a[i-1]))
p[0]+=abs(a[n-1]-a[n-2])
print(min(p))

Measured memory_bytes: 13928
#include<bits/stdc++.h>
/* #define int long long */
/* #define double long double */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;
#define rrep(i,a,b) for(int i=a;i>=b;i--)

signed main(){
    int n;
    cin >> n;
    set<string> s;
    int ans = 0;
    rep(i, n){
        string tmp;
        cin >> tmp;
        auto itr = s.find(tmp);
        if(itr == s.end()){
            ans++;
            s.insert(tmp);
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 19156
use std::collections::{BTreeSet, HashSet};
use std::error::Error;
use std::io;

pub fn main() {
    if let Err(_e) = run() {
        panic!("failed.");
    }
}

fn run() -> Result<(), Box<dyn Error>> {
    let mut input = String::new();
    io::stdin().read_line(&mut input)?;
    input.clear();
    io::stdin().read_line(&mut input)?;
    let mut nums: Vec<i64> = input
        .trim()
        .split_whitespace()
        .map(|s| s.parse::<i64>().unwrap())
        .collect();
    input.clear();

    nums.sort();

    let mut dp = vec![0; 1_000_001];
    for &x in &nums {
        let index = x as usize;
        dp[index] += 1;
        if dp[index] == 1 {
            let mut from = index + x as usize;
            while from < 1_000_001 {
                dp[from] += 1;
                from = from + x as usize;
            }
        }
    }
    // println!("{:?}", dp);

    let mut count = 0;
    for &x in &nums {
        if dp[x as usize] == 1 {
            count += 1;
        }
    }
    println!("{}", count);

    Ok(())
}


Measured memory_bytes: 8756
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int b,n=0,m;
	char a[100001];
	cin>>a;
    b=strlen(a);
    m=b/2;
    for(int i=0;i<=b-1;i++)
    {
    	if(a[i]=='p'||a[i]=='P')
        n++;
	}
	cout<<m-n;
	return 0;
 } 

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
//-----------------------------------------

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

  string s, t;
  cin >> s >> t;
  s = s + s;
  int n = SZ(s);
  int m = SZ(t);
  REP(i,n){
    if(s.substr(i,m)==t){
      yes();
      return 0;
    }
  }
  no();




  return 0;
}



Measured memory_bytes: 3248
import sys
from heapq import heappush, heappop

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *P = map(int, read().split())

    idx = [0] * (N + 1)
    for i, p in enumerate(P):
        idx[p] = i

    left = list(range(-1, N)) + [-1]
    right = list(range(1, N + 1)) + [N, N]

    ans = 0
    for n in range(1, N + 1):
        i = idx[n]
        l1 = left[i]
        l2 = left[l1]
        r1 = right[i]
        r2 = right[r1]

        ans += n * ((l1 - l2) * (r1 - i) + (r2 - r1) * (i - l1))

        left[r1] = l1
        right[l1] = r1

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 92072
#include<stdio.h>

int main(void) {
  int n, i, j, count=0, ans=0;
  int *d, *regen;
  scanf("%d", &n);
  d = (int*)malloc(n*sizeof(int));
  for(i=0; i<n; i++) {
    scanf("%d", &d[i]);
  }
  regen = (int*)malloc(n*(n-1)/2 * sizeof(int));
  for(i=0; i<n; i++) {
    for(j=i+1; j<n; j++) {
      regen[count] = d[i] * d[j];
      count++;
    }
  }
  for(i=0; i<count; i++) {
    ans += regen[i];
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define vll vector<pair<ll, ll>
using namespace std;


int main(){
    ios_base::sync_with_stdio(true);
    cin.tie(NULL);
    ll n, ans = 0;
    cin >> n;
    string x;
    cin >> x;
    
    if(n%2 == 1){
        cout << "No" << endl;
    }
    else{
        bool f = true;
        ll temp = n/2;
        for(ll i=0; i<temp; i++){
            if(x[i] == x[i+temp]){
                continue;
            }
            else{
                f = false;
                break;
            }
        }
        
        if(f){
            cout << "Yes" << endl;
        }
        else{
            cout << "No" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3632
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from heapq import heapify,heappop,heappush
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    P=[None]*(n+1); S=[None]*(n+1)

    # prefix
    Q=A[:n]
    P[0]=sum(Q)
    heapify(Q)
    for i in range(1,n+1):
        a=heappop(Q)
        b=A[n+i-1]
        P[i]=P[i-1]-a+max(a,b)
        heappush(Q,max(a,b))

    # suffix
    Q=[-a for a in A[2*n:]]
    S[-1]=sum(Q)
    heapify(Q)
    for i in range(n-1,-1,-1):
        a=heappop(Q)
        b=-A[n+i]
        S[i]=S[i+1]-a+max(a,b)
        heappush(Q,max(a,b))

    print(max(*(p+s for p,s in zip(P,S))))
resolve()

Measured memory_bytes: 120812
#include <iostream>
#include <math.h>
#include <stdio.h>
using namespace std;

int main(void)
{
    //string a,b;
    int a,b,c,d;
    //char a,b,c;
    int i=0,sum=0;
    //char a,b='.';
    cin>>a;
    b=a/2;
    cout<<b*(a-b);
    return 0;
}



Measured memory_bytes: 256
n = int(input())
nt = []

board = [["." for _ in range(8)] for _ in range(8)]

for i in range(n):
    y, x = map(int, input().split())
    board[y][x] = "Q"
    nt.append(y)

def output():
    for row in board:
        print("".join(row), sep=None)

def check(x, y):
    for i in range(8):
        for j in range(8):
            if i == y and j == x:
                continue
            elif i == y and board[i][j] == "Q":
                return False
            elif j == x and board[i][j] == "Q":
                return False
            elif abs(i-y) == abs(j-x) and board[i][j] == "Q":
                return False
    return True

def dfs(row):
    if row == 8:
        output()
        return
    if row in nt:
        dfs(row+1)
        return

    for i in range(8):
        board[row][i] = "Q"
        if not check(i, row):
            board[row][i] = "."
            continue
        else:
            dfs(row+1)
            board[row][i] = "."


dfs(0)

Measured memory_bytes: 7844
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 99999999
const long int M = 1000000007;

int allmask;
map<int,vector<int> > m;
int dp[(1<<21) + 1][22];
lli solve(int mask, int i, int n)
{
    if(mask == allmask) return 1;
    if(i > n) return 0;
    if(dp[mask][i] != -1) return dp[mask][i];
    lli ways = 0;
    int si = m[i].size();
    for(int j = 0;j < si;j++)
    {
        if(mask & (1 << m[i][j])) continue;
        else ways += solve(mask |(1<<m[i][j]),i+1,n);
        ways %= M;
    }
    return dp[mask][i] = ways;
}

int main()
{
    int n;
    cin >> n;
    int i,j;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            int a;
            cin >> a;
            if(a)
            {
                m[i+1].push_back(j);
            }
        }
    }
    allmask = (1 << n) - 1;
    memset(dp,-1,sizeof(dp));
    cout << solve(0,1,n);
    /*for(i=1;i<=3;i++)
    {
        cout << i<< ": ";
        for(j=0;j<m[i].size();j++)
        {
            cout  << m[i][j] << ",";
        }
        cout << endl;
    }*/
}



Measured memory_bytes: 183860
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

bool comp(pair<string, int> a, pair<string, int> b){
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return (a.second - (a.second/1000)*1000 ) > (b.second - (b.second/1000)*1000 );
    }
}

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

    vector<pair<string, int>> pair(n);

    for(int i = 0;i < n;i++){
        string s;
        int p;

        cin >> s >> p;
        p += 1000*i;

        pair[i] = make_pair(s, p);
    }

    
    sort(pair.begin(), pair.end(), comp);

    for(int i = 0;i < n;i++){
        cout << pair[i].second/1000 + 1 <<endl;
    }

    return 0;
}

Measured memory_bytes: 256
// 解き直し.
// ARC 102解説.
// https://img.atcoder.jp/arc102/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define p1 first
#define p2 second
const int MAX_N = 21;
typedef pair<int, int> pii;

vector<vector<pii>> graph(MAX_N);
int pow2[MAX_N];

int main(){
    
    // 1. 入力情報取得.
    int L;
    scanf("%d", &L);
    
    // 2. 解説通り.
    // 2-1. 頂点 i から 頂点 i + 1 へ, 長さ 0, pow2[i - 1] の 辺を, 1本ずつ張る.
    int r = 0, M = 0;
    pow2[0] = 1;
    for(int i = 1; i < MAX_N; i++){
        pow2[i] = pow2[i - 1] * 2;
        if(pow2[i] <= L) r++;
    }
    int N = r + 1;
    for(int i = 1; i < N; i++){
        graph[i].pb({i + 1, 0});
        graph[i].pb({i + 1, pow2[i - 1]});
        M += 2;
    }
    
    // 2-2. 条件を確認しながら, 頂点 t から 頂点 N に, 長さ L - pow2[t - 1] の 辺を, 1本ずつ張る.
    for(int t = N - 1; t >= 1; t--){
        if(L - pow2[t - 1] >= pow2[r]){
            graph[t].pb({N, L - pow2[t - 1]});
            L -= pow2[t - 1];
            M++;
        }
    }
    
    // 3. 出力.
    printf("%d %d\n", N, M);
    for(int i = 1; i <= N; i++){
        for(auto &o : graph[i]) printf("%d %d %d\n", i, o.p1, o.p2);
    }
    return 0;
}

Measured memory_bytes: 256
def keta_sum(n):
	a = int(n*0.001)
	b = int(n*0.01) % 10
	c = int(n*0.1) % 10
	d = n % 10
	return a+b+c+d

while 2>1:
	try:
		n_try = int(raw_input())
		count = 0
		for n in range(10000):
			if n_try == keta_sum(n):
				count += 1
		print count
	except EOFError:
		break
	except ValueError:
		break
	

Measured memory_bytes: 38000
n = int(input())
for i in range(0, n):
    if n % 4 == 0:
        print("Yes")
        exit()
    else:
        n -= 7
        if n < 0:
            break
for i in range(0, n):
    if n % 7 == 0:
        print("Yes")
        exit()
    else:
        n -= 4
        if n < 0:
            break
print("No")

Measured memory_bytes: 9192
# %
n, x, m = map(int, input().split())
import sys

result = [x]
pat = set()
pat.add(x)
flg = False
for _ in range(n - 1):
    tmp = pow(result[-1], 2, m)
    if tmp in pat:
        flg = True
        break
    elif tmp == 0:
        print(sum(result))
        sys.exit()
    else:
        result.append(tmp)
        pat.add(tmp)
        
if not flg:
    print(sum(result))

else:
    cnt = result.index(tmp)
    cycle = result[-(len(result) - cnt):]
    rest = (n - cnt)
    print(sum(result[:cnt]) + (rest // len(cycle)) * sum(cycle) + sum(cycle[:rest % len(cycle)]))

Measured memory_bytes: 13432