akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n) for (int i=1; i < (int)(n); i++)
#define rrep(i, n) for (int i=((int)(n)-1); i>=0; i--)
#define rreps(i, n) for (int i=((int)(n)-1); i>0; i--)
#define ALL(x) (X).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
using lint = long long;
using p = pair<int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int N; cin >> N;
  vector<int> d(N);
  lint sum = 0;
  rep (i, N) {
    cin >> d[i];
    sum -= (int)pow(d[i], 2);
  }
  rep (i, N) {
    rep (j, N) {
      sum += d[i] * d[j];
    }
  }
  cout << sum / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
typedef long long ll;
using namespace std;

int main()
{
	ll X;
	cin >> X;

	if (X / 500 > 0)
	{

		ll Y = X % 500;
		if (Y / 5 < 0)
		{
			cout << X / 500 * 1000 << endl;
		}
		else
		{
			cout << X / 500 * 1000 + Y / 5 * 5 << endl;
		}
	}

	else if (X / 5 > 0)
	{
		cout << X / 5 * 5 << endl;
	}
	else
		cout << 0;
	return 0;
}

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

int main() {
    ll n;
    std::cin >> n;
    vector<ll> a(n+1);
    vector<ll> asum(n+2,0);
    for (int i = 0; i < n+1; i++) {
        std::cin >> a[i];
        asum[i+1] = asum[i]+a[i];
    }
    
    vector<ll> cnt(n+1,0);
    cnt[0] = 1;
    ll sum = 1;
    cnt[0]-=a[0];
    if(n==0&&a[0]!=1){
        std::cout << -1 << std::endl;
        return 0;
    }
    for (int i = 1; i < n+1; i++) {
        cnt[i] = min(asum[n+1]-asum[i+1],cnt[i-1]*2-a[i]);
        sum += a[i];
        if((cnt[i]<=0&&i!=n)||cnt[i]<0){
            std::cout << -1 << std::endl;
            return 0;
        }
        if(i!=n)sum += cnt[i];
    }
    std::cout << sum << std::endl;
}


Measured memory_bytes: 5560
#include<stdio.h>
int  main()
 {  
int n, m, x, y, a, b, p, q;
  scanf("%d%d%d%d", &n, &m, &x, &y);
  p=-300;
  while (n--)
  {   
scanf("%d", &a);
   if (a>p)
   {
    p=a;
   } 
 }
  q=300; 
 while (m--) 
 {  
 scanf("%d", &b);
   if (b<q)
   {
    q=b; 
  }
  }
  if (q>p && p>x && q<=y)
  {
   printf("No War\n");
  }
  else 
 { 
  printf("War\n"); 
 } 
 return 0;
 }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long INF = 1LL << 60;

int main()
{
  int N, D; cin >> N >> D;
  cout << (N+D*2)/(D*2+1) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,a[100]= {0},k;
    char s[1000];
    gets(s);
    while(s[i])
    {
        k=s[i]-97;
        a[k]++;
        i++;
    }
    for(i=0; i<26; i++)
    {
        if(a[i]%2==1)
        {
            printf("No\n");
            return 0;
        }

    }
    printf("Yes\n");
    return 0;

}


Measured memory_bytes: 128
# TLE 1/13 corner0
x = input()
while 'ST' in x:
    x = x.replace('ST', '')
    # 以下の4行を加えて AC  'SSS..STTTTT..T' みたいなやつを検出
    n = len(x) // 2
    if ('T' not in x[:n]) and ('S' not in x[n:]):
        x = ''
        break
print(len(x))


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

const double PI=acos(-1.0);


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

    int lower = max(a, c);
    int upper = min(b, d);

    cout << max(0, upper - lower) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int data[4];
    int i, j;
    scanf("%d %d %d", &data[1], &data[2], &data[3]);
    for(i = 1; i < 4; i++){
        for(j = 1; j < 4; j++){
            if(data[i] < data[j]){
                data[0] = data[j];
                data[j] = data[i];
                data[i] = data[0];
            }
        }
    }
    printf("%d %d %d\n", data[1], data[2], data[3]);
}

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

using namespace std;

long n,kq[100010],t=0,a[100010];

int main()
{
    cin >> n;
    for (long i=1;i<=n;i++)
        cin >> a[i];
        //a[i].vt=i;

    if (a[1]==1) kq[1]=1;
    long cs=1;
    for (long i=2;i<=n;i++){
        if (a[i]==i) {
            if (a[i-1]==i-1)
                kq[cs]++;
            else {
                    cs++;
                    kq[cs]++;
            }
        }
    }
   // cout << cs <<" ";
    //for (int i=1;i<=cs;i++) cout << kq[i] << " ";
    for (long i=1;i<=cs;i++)
        if (kq[i]==1) t=t+1;
        else {if (kq[i]>1) t=t+kq[i]/2;
            if (kq[i]%2!=0) t++;
        }

    //if (t<0) t=0;
    cout << t;
    return 0;
}


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

int main() {
	int n, a, b, i;
	cin >> n >> a >> b;
	int sum;
	int ans = 0;
	for (i = 1; i <= n; i++) {
		sum = i % 10 + (i / 10) % 10 + (i / 100) % 10 + (i / 1000) % 10 + (i / 10000);
		if (sum >= a && sum <= b)ans += i;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;


int main() {
	ll n, m, x[1001], y[1001], z[1001];
	cin >> n >> m;
	for (int i = 0;i < n;i++) { cin >> x[i] >> y[i] >> z[i]; }

	ll ans = 0;
	int sel1[8] = { 0,0,0,0,1,1,1,1 }, sel2[8] = { 0,0,1,1,0,0,1,1 }, sel3[8] = {0, 1, 0, 1, 0, 1, 0, 1};
	for (int i = 0;i < 8;i++) {
	ll ansn = 0;
		vector<ll> vec;
		for (int j = 0;j < n;j++) {
			ll a=0;
			if (sel1[i] == 0) a += x[j]; else a -= x[j];
			if (sel2[i] == 0) a += y[j]; else a -= y[j];
			if (sel3[i] == 0) a += z[j]; else a -= z[j];
			vec.push_back(a);
		}
		sort(vec.begin(), vec.end(),greater<ll>());
		for (int j = 0;j < m;j++) ansn += vec[j];
		ans = max(ans, ansn);
	}

	cout << ans << endl;

	return 0;
}

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

int main(void){
  int X,Y;
  scanf("%d %d",&X,&Y);
  if(Y%2==0){
    if((X*2<=Y)&&(X*4>=Y)){
      printf("Yes");
    }else{
      printf("No");
    }
  }else{
    printf("No");
  }
   return 0;
}


Measured memory_bytes: 1732
(defun get-max (data start end)
  (if (zerop start)
      (aref data (1- end))
      (- (aref data (1- end))
         (aref data (1- start)))))

(defun get-diff (data start-point second-point end-point)
  (abs (- (get-max data second-point end-point)
          (get-max data start-point second-point))))

(defun equal-cut ()
  (declare (optimize (speed 3) (safety 0) (debug 0) (space 0)))
  (let* ((n (read))
         (data (make-array n :initial-contents (loop repeat n
                                                     sum (read) into summed-a
                                                     collect summed-a))))
    (loop for second-separator from 2 below (1- n)
          with first-separator = 1
          with third-separator = 3
          with minimized-diff = #.(* (* 2 (expt 10 5)) (expt 10 9))
          when (>= second-separator third-separator)
            do (setq third-separator (1+ second-separator))
          do (loop (if (and (< first-separator (1- second-separator))
                            (< (get-diff data 0 (1+ first-separator) second-separator)
                               (get-diff data 0 first-separator second-separator)))
                       (incf first-separator)
                       (return)))
             (loop (if (and (< third-separator (1- n))
                            (< (get-diff data second-separator (1+ third-separator) n)
                               (get-diff data second-separator third-separator n)))
                       (incf third-separator)
                       (return)))
             (let* ((max-list (list (get-max data 0 first-separator)
                                    (get-max data first-separator second-separator)
                                    (get-max data second-separator third-separator)
                                    (get-max data third-separator n)))
                    (diff (- (apply #'max max-list) (apply #'min max-list))))
               (if (< diff minimized-diff)
                   (setq minimized-diff diff)))
          finally (princ minimized-diff))))

(equal-cut)

Measured memory_bytes: 61928
#include <iostream>
#include <string>
int main(){
    int N;
    std::cin >> N;
    std::string W[100];
    for(int i=0;i<N;i++){
        std::cin >> W[i];
    }
    bool f=true;
    for(int i=0;i<N-1;i++){
        std::cerr << W[i][W[i].length()-1] << " " << W[i+1][0] << "\t";
        if(W[i][W[i].length()-1]!=W[i+1][0]){
            f = false;
            break;
        }
        for(int j=i+1;j<N;j++){

            if(W[i].compare(W[j])==0){
                f = false;
                break;
            }
        }
        if(!f) break;
    }
    if(f)   std::cout << "Yes" << std::endl;
    else    std::cout << "No" << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
const int N=100005;
int n,m,a[N],b[N],tot,w[N],top;
int read()
{
	int r=0,f=1;
	char p=getchar();
	while(p>'9'||p<'0')
	{
		if(p=='-')
			f=-1;
		p=getchar();
	}
	while(p>='0'&&p<='9')
	{
		r=r*10+p-48;
		p=getchar();
	}
	return r*f;
}
int main()
{
	n=read(),m=read();
	for(int i=1;i<=m;i++)
	{
		a[i]=read();
		if(a[i]&1)
			w[++top]=i;
	}
	if(top>2)
	{
		puts("Impossible");
		return 0;
	}
	if(top==0)
	{
		b[++tot]=1;
		for(int i=1;i<m;i++)
			b[++tot]=a[i];
		for(int i=1;i<=(a[m]-1)/2/2;i++)
			b[++tot]=2;
		b[++tot]=1;
		for(int i=(a[m]-1)/2/2+1;i<=(a[m]-1)/2;i++)
			b[++tot]=2;
	}
	if(top==1)
	{
		swap(a[w[1]],a[m]);
		b[++tot]=1;
		for(int i=1;i<m;i++)
			b[++tot]=a[i];
		for(int i=1;i<=(a[m]-1)/2;i++)
			b[++tot]=2;
	}
	if(top==2)
	{
		swap(a[w[1]],a[m]);
		swap(a[w[2]],a[1]);
		b[++tot]=a[1]+1;
		for(int i=2;i<m;i++)
			b[++tot]=a[i];
		for(int i=1;i<=(a[m]-1)/2;i++)
			b[++tot]=2;
	}
	for(int i=1;i<=m;i++)
		printf("%d ",a[i]);
	printf("\n%d\n",tot);
	for(int i=1;i<=tot;i++)
		printf("%d ",b[i]);
	return 0;
}

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

using namespace std;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 998244353;
const LL INF = LLONG_MAX;
const LL N = 1e6+1;

#define F first
#define S second

int main() {
	fastio();
	
	LL n, k;
	cin >> n >> k;

	vector<pair<LL, LL>> vp(k);
	vector<pair<LL, LL>> pt(k);
	vector<LL> sum(k, 0);

	for (LL i = 0; i < k; ++i) {
		cin >> vp[i].F >> vp[i].S;
		pt[i].F = -vp[i].S;
		pt[i].S = -vp[i].F;
	}

	// now we need k range sums
	// can maintain k - 2pointers

	vector<LL> dp(n, 0);
	dp[0] = 1;

	for (LL i = 0; i < n; ++i) {
		for (LL j = 0; j < k; ++j) {
			if (pt[j].S >= 0) {
				sum[j] = (sum[j] + dp[pt[j].S]) % MOD;
			}

			if (pt[j].F > 0) {
				sum[j] = (sum[j] - dp[pt[j].F-1] + MOD) % MOD;
			}
			pt[j].S++;
			pt[j].F++;
			dp[i] = (dp[i] + sum[j]) % MOD;
		}
	}
	cout << dp[n-1] << "\n";
}

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

enum{
  FREE,
  NOT_FREE
};

int D[8][8], row[8], col[8], dpos[15], dneg[15];

void print(){
  for(int i = 0; i < 8; i++){
    for(int j = 0; j < 8; j++) cout << (D[i][j] ? 'Q' : '.');
    cout << endl;
  }
}

void putQ(int i){
  if(i == 8){
    print();
    return;
  }
  if(row[i] == FREE){
    for(int j = 0; j < 8; j++){
      if(col[j] == NOT_FREE || dpos[i+j] == NOT_FREE || dneg[i-j+7] == NOT_FREE) continue;
      D[i][j] = 1;
      row[i] = col[j] = dpos[i+j] = dneg[i-j+7] = NOT_FREE;
      putQ(i+1);
      D[i][j] = 0;
      row[i] = col[j] = dpos[i+j] = dneg[i-j+7] = FREE;
    }
  }
  else putQ(i+1);
}

int main(){
  int n, r, c;
  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> r >> c;
    D[r][c] = 1;
    row[r] = col[c] = dpos[r+c] = dneg[r-c+7] = NOT_FREE;
  }
  putQ(0);
  return 0;
}



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

using ll = long long;
using ld  = long double;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
// int lcm(int a, int b){return a / gcd(a, b) * b;}
#define b_e(a) a.begin(),a.end() //sort(b_e(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll)(n) ; i++ )
#define DREP(i,m,n) for(ll i=(ll)(m) ; i > (ll)(n) ; i-- )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define p_b push_back
#define SZ(x) ((ll)(x).size()) //size()がunsignedなのでエラー避けに
#define endk '\n'


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //




// --------- library end - //

using mint = modint998244353;


int main(){

  ll N, M;
  cin >> N >> M;

  vector<mint> as(N);
  vector<mint> bs(M);

  rep(i, N) as[i] = il();
  rep(i, M) bs[i] = il();

  vector<mint> res = convolution(as, bs);

  rep(i, N+M-1){
    if (i) cout << " ";
    cout << res[i].val();
  }

  cout << endk;


}



Measured memory_bytes: 19004
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; cin >> n;
    vi a(n);
    vector<P> ap(n);
    rep(i, n) {
        cin >> a[i];
        ap[i] = {a[i], i};
    }
    sort(all(ap));
    int cnt = 0;
    rep(i, n){
        if((i + ap[i].se) % 2) cnt++;
    }
    cout << cnt / 2 << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 4516
#include <algorithm>
#include <cassert>
// #include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
// #include <random>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

/*
unsigned seed1 = std::chrono::system_clock::now().time_since_epoch().count();
mt19937 g1.seed(seed1);
*/
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<pii, pii> ppiipii;
typedef pair<int, ppiipii> pippiipii;
typedef pair<int, pii> pipii;
typedef pair<pii, int> ppiii;
typedef pair<int, ppiii> pippiii;
typedef pair<int, ll> pill;
typedef pair<int, double> pid;
typedef pair<string, string> pss;
// note to self, the below two triggers someone
typedef pair<ll, ll> pll;
typedef pair<ll, int> plli;
typedef long double ld;

ll n, m;

ll solve(ll inc) {
  ll nn = n + inc;
  ll mm = m - 2*inc;
  return min(nn, mm/2);
}

int main() {
  scanf("%lld %lld", &n, &m);
  ll low = 0;
  ll high = m/2;
  while(high - low > 5) {
    ll lhs = (2*low+high)/3;
    ll rhs = (2*high+low)/3;
    if(solve(lhs) > solve(rhs)) {
      high = rhs;
    }
    else {
      low = lhs;
    }
  }
  ll ret = 0;
  for(ll i = low; i <= high; i++) {
    ret = max(ret, solve(i));
  }
  printf("%lld\n", ret);
}


Measured memory_bytes: 256
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
#include<set>
#include <cstdint>
using namespace std;
using ll = __int64_t;
using lll = __int128_t;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;
const ll mod=1e9+7;


//II→factorialを計算するrange
constexpr ll MOD = 998244353;
template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};


int main(void){
      int n;
      cin>>n;
      int a[n];
      rep0(i,n) cin>>a[i];
      constexpr int V=1e6+3;
      vector<modint<MOD>> w(V+2,0);
      vector<modint<MOD>> c(V+3,0);
      vector<modint<MOD>> s(V+3,0);
      vector<modint<MOD>> sum1(V+3,0);
      vector<modint<MOD>> sum2(V+3,0);
      constexpr modint<MOD> I=1;
      constexpr modint<MOD> II=2;
      w[0]=0;
      for(int i=1;i<V;i++){
            modint<MOD> j=i;
            w[i]=I/j;
      }
      for(int i=1; i<V;i++){
            for(int j=2*i;j<V;j+=i){
                  w[j]-=w[i];
            }
      }
      for(int i=0;i<n;i++){
            c[a[i]]+=I;
      }
      for(int d=1;d<V;d++){
            for(int j=d;j<V;j+=d){
              if(c[j].a==0) continue;
                  modint<MOD> l=j;
                  sum1[d]+=(l*c[j]);
            }
      }
      for(int d=1;d<V;d++){
            for(int j=d;j<V;j+=d){
              if(c[j].a==0) continue;
                  modint<MOD> l=j;
                  sum2[d]+=(l*l*c[j]);
            }
      }
      for(int d=1;d<V;d++){
            s[d]=((sum1[d]*sum1[d])-sum2[d]);
      }
      modint<MOD> ans=0;
      for(int d=1;d<V;d++){
            ans+=w[d]*s[d];
      }
      cout<<(ans/II).a<<endl;
      return 0;
}


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

vector<long long> g[200000];
vector<int> f1[200000];
long long f2[200000];
long long ans[200000];

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int n;

void COMinit() {
    fac[0] = fac[1] = 1; finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int dfs1(int cur, int p) {
  int tmp = 0;
  for (int to: g[cur]) {
    if (to == p) {
      continue;
    }
    long long tmp2 = dfs1(to, cur);
    f1[cur].push_back(tmp2);
    tmp += tmp2;
  }
  return tmp + 1;
}
long long dfs2(int cur, int p) {
  long long tmp = 1;
  for (int to: g[cur]) {
    if (to == p) {
      continue;
    }
    tmp *= dfs2(to, cur);
    tmp %= MOD;
  }
  int sum = 0;
  for (int x: f1[cur]) {
    sum += x;
  }
  for (int x: f1[cur]) {
    tmp *= COM(sum, x);
    tmp %= MOD;
    sum -= x;
  }
  f2[cur] = tmp;
  return tmp;
}
long long calc_inv(long long n) {
  if (n < MAX) {
    return inv[n];
  }
  return  MOD - calc_inv(MOD%n) * (MOD / n) % MOD;
}
void dfs3(int cur, int p) {
  if (p != - 1) {
    long long tmp = f2[cur];
    ans[cur] = f2[cur];
    long long sum = 0;
    for (int x: f1[cur]) {
      sum += x;
    }
    ans[cur] *= COM(n - 1, sum);
    ans[cur] %= MOD;
    ans[cur] *= ans[p];
    ans[cur] %= MOD;
    ans[cur] *= calc_inv(f2[cur]);
    ans[cur] %= MOD;
    ans[cur] *= calc_inv(COM(n-1, sum+1));
    ans[cur] %= MOD;
  }
  for (int to: g[cur]) {
    if (p != to) {
      dfs3(to, cur);
    }
  }
}

int main() {
  cin>>n;
  for (int i=0; i<n-1; i++) {
    int a, b;
    cin>>a>>b;
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  COMinit();
  dfs1(0, -1);
  dfs2(0, -1);
  ans[0] = f2[0];
  dfs3(0, -1);
  for (int i=0; i<n; i++) {
    cout<<ans[i]<<endl;
  }
}

Measured memory_bytes: 37888
<?php
$input = trim(fgets(STDIN));
$splited = explode(" ", $input);

while ($input){
$array[] = $splited;
$input = trim(fgets(STDIN));
$splited = explode(" ", $input);
};

$n = $array[0][0];
$m = $array[0][1];

$days = array_sum($array[1]);

if($days > $n){
  echo -1;
} else {
  echo $n - $days;
}

?>

Measured memory_bytes: 16912
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Obj[] arr = new Obj[n];
		Map<Integer, List<Obj>> mapx = new HashMap<>();
		Map<Integer, List<Obj>> mapy = new HashMap<>();
		for (int i = 0; i < n; i++) {
			Obj o = new Obj();
			o.x = sc.nextInt();
			o.y = sc.nextInt();
			arr[i] = o;

			List<Obj> listx = mapx.get(o.x);
			if (listx == null) {
				listx = new ArrayList<>();
				mapx.put(o.x, listx);
			}
			listx.add(o);

			List<Obj> listy = mapy.get(o.y);
			if (listy == null) {
				listy = new ArrayList<>();
				mapy.put(o.y, listy);
			}
			listy.add(o);
		}
		sc.close();

		long ans = 0;
		for (int i = 0; i < n; i++) {
			if (!arr[i].used) {
				Queue<Obj> que = new ArrayDeque<>();
				que.add(arr[i]);
				arr[i].used = true;
				Set<Integer> setx = new HashSet<>();
				Set<Integer> sety = new HashSet<>();
				setx.add(arr[i].x);
				sety.add(arr[i].y);
				while (!que.isEmpty()) {
					Obj cur = que.poll();
					for (Obj next : mapx.get(cur.x)) {
						if (!next.used) {
							que.add(next);
							next.used = true;
							sety.add(next.y);
						}
					}
					for (Obj next : mapy.get(cur.y)) {
						if (!next.used) {
							que.add(next);
							next.used = true;
							setx.add(next.x);
						}
					}
				}
				ans += (long) setx.size() * sety.size();
			}
		}
		System.out.println(ans - n);
	}

	static class Obj {
		int x, y;
		boolean used;
	}
}


Measured memory_bytes: 107832
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main() {
	int n,cou=0,ans=0; 
	cin >> n;
	for(int i = 1; i <= n; ++i) {
		if(i % 2 == 1) {
			for(int j = 1; j <= i; ++j) {
				if(i % j == 0)
					++cou;
			}
			if(cou == 8)
				++ans;
			cou = 0;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
  int N;
  int a[10000];
  cin >> N;

  int cnt = 0;
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  for(int i = 0; i < N; i++){
    while(a[i] % 2 == 0){
      if(a[i] % 2 == 0){
        cnt++;
        a[i] /= 2;
      }
    }
  }

  cout << cnt << endl;
  return 0;

}


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

int main(){
    int a,b,c,t;
    cin >> a >> b >> c;
    if(a>b){
         t=a;a=b;b=t; 
    }
    if(b>c){
         t=b;b=c;c=t;
    }
    if(a>b){
         t=a;a=b;b=t; 
    }
    cout <<a<<" "<<b<<" "<<c<<endl;
    return 0;
}


Measured memory_bytes: 3084
#include<stdio.h>

int x;
int parent[100001],sibling[100001],degree[100001];


int Height(int);
int Depth(int);

int main(){
  int i,j,id,left,right;

  scanf("%d",&x);

  for(i = 0; i < x; i++){
    parent[i] = -1;
    sibling[i] = -1;
    degree[i] = 0;
  }

  for(i = 0;i < x; i++){

    

    scanf("%d%d%d",&id,&left,&right);

    if(left != -1){
      parent[left] = id;
      sibling[left] = right;
      degree[id]++;

    }

    if(right != -1){
      parent[right] = id;
      sibling[right] = left;
      degree[id]++;
    }
  }

  for(i = 0; i < x; i++){

    int depth = Depth(i);

    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",i,parent[i],sibling[i],degree[i],depth,Height(i));

    if(depth == 0) printf("root\n");

    else if(degree[i] == 0) printf("leaf\n");

    else printf("internal node\n");

  }

  return 0;
}


int Height(int i){

  int j,h = 0,a;

  for(j = 0; j < x ; j++){

    if(parent[j] == i){
       a = Height(j)+1;

      if(a > h) h = a;
    }
  }

  return h;
}


int Depth(int i){

  if(parent[i] == -1) return 0;

  return Depth(parent[i])+1;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a;
	cin>>a;
	string s;
	cin>>s;
	int len=s.length();
	for(int i=0;i<len;i++)
	{
		int b=(s[i]-65+a)%26;
		printf("%c",b+65);
	}
} 

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N, Q =map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N-1)]
 
g = [[] for _ in range(N+1)]
for a, b in ab:
    g[b].append(a)
    g[a].append(b)
cnt = [0]*(N+1)
 
for _ in range(Q):
    p, x = map(int, input().split())
    cnt[p] += x
 
temp = [1]
visited = [0]*(N+1)
visited[1] = 1
 
while temp:
    q = temp.pop()   
    for i in g[q]:
        if visited[i] == 0:
            temp.append(i)
            visited[i] = 1
            cnt[i] += cnt[q]
print(*cnt[1:])

Measured memory_bytes: 82560
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
#include<numeric>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;


//最大公約数
template<class T> T gcd(T a, T b)
{
	while (true)
	{
		T r;
		if (a%b == 0) return b;
		else
		{
			r = a % b;
			a = b;
			b = r;
		}
	}
}
//最小公倍数
template<class T> T lcm(T a, T b)
{
	return a / gcd(a, b)*b;
}
//文字0~9をint型0~9に変換
int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}
//a^b mod MODを計算
long long int ModPower(long long int a, long long int b, long long int MOD)
{
	if (b == 0) return 1;
	else if (b % 2 == 0)
	{
		long long int d = ModPower(a, b / 2, MOD);
		return (d*d) % MOD;
	}
	else
	{
		return (a*ModPower(a, b - 1, MOD)) % MOD;
	}
}
//nCr mod MODを計算
long long int ModCombi(long long int n, long long int r, long long int MOD)
{
	if (n == 0 || r == 0) return 1;

	long long int Kn = 1, Kr = 1, Knr = 1;

	long long int temp = 1;
	for (long long int i = 1; i <= n; i++)
	{
		temp *= i;
		temp %= MOD;
		if (i == n) Kn = temp;
		if (i == r) Kr = temp;
		if (i == n - r) Knr = temp;
	}

	long long int x = ModPower(Kr, MOD - 2, MOD);
	long long int y = ModPower(Knr, MOD - 2, MOD);

	long long int ans;
	ans = Kn * x;
	ans %= MOD;
	ans *= y;
	ans %= MOD;

	return ans;
}
//int型10進数をord桁のstring型2進数に変換する
string binary(int x, int ord)
{
	int y;
	string ans = "";
	for (int i = 0; i < ord; i++)
	{
		y = x / (int)pow(2, ord - 1 - i);
		y %= 2;
		if (y == 0) ans += "0";
		else ans += "1";
	}

	return ans;
}
//ord桁のstring型2進数をint型10進数に変換する
int rep_binary(string x, int ord)
{
	int res = 0;
	for (int i = 0; i < ord; i++)
	{
		if (x[i] == '1') res += (int)pow(2, ord - 1 - i);
	}
	return res;
}


/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/



int main()
{
	int N;
	double A[105];
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	double S = 0;

	for (int i = 0; i < N; i++)
	{
		S += 1 / A[i];
	}

	S = 1 / S;

	cout << fixed << setprecision(10) << S;

	return 0;
}


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

int64_t gcd(int64_t A,int64_t B){
  if(B==0){return A;}
  return gcd(B,A%B);
}



int main(){
  int N;
  cin>>N;
  vector<int64_t> A(N);
  for(int i=0;i<N;++i){
    cin>>A.at(i);
  }

  vector<int64_t> L(N+1),R(N+1);
  L.at(0)=0;
  R.at(N)=0;
  for(int i=0;i<N;++i){
    L.at(i+1)=gcd(L.at(i),A.at(i));
    R.at(N-i-1)=gcd(R.at(N-i),A.at(N-i-1));
  }
  
  int64_t M=0;
  for(int i=0;i<N;++i){
    M=max(M,gcd(L.at(i),R.at(i+1)));
  }

  cout<<M<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>     // [PRIMES]               1777 ~2^10.80  
using namespace std;                     //                       10333 ~2^13.33
using ll=long long;                      // seq 1 128 | factor   100333 ~2^16.61
using vl=vector<ll>;                     //   | grep -v ' .* '  1300111 ~2^20.31
using vvl=vector<vl>;                    //                    10300777 ~2^23.30
using vb=vector<bool>;                   //                   100400999 ~2^26.58
using vs=vector<string>;                 //                  1300400999 ~2^30.28
using pll=pair<ll,ll>;                   //                 10200500333 ~2^33.25
const ll oo =0x3f3f3f3f3f3f3f3fLL;       //                100200400777 ~2^36.54
const double eps=1e-9;                   //               1200300700111 ~2^40.13
#define sz(c) ll((c).size())             //              10200300500777 ~2^43.21
#define all(c) begin(c),end(c)           //             100200300400777 ~2^46.51
#define mp make_pair                     //            1200300400600999 ~2^50.09
#define mt make_tuple                    //           10200300400600111 ~2^53.18
#define pb push_back                     //          100200300400600333 ~2^56.48
#define eb emplace_back                  //         1200300400500800999 ~2^60.06
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })
int main(){ 
	cin.sync_with_stdio(0);
	
	int n;
	cin >> n;

	double ing[n];
	FOR(i, 0, n) cin >> ing[i];

	sort(ing, ing + n);

	double fV = (ing[0] + ing[1]) / 2;

	FOR(i, 2, n) {
		fV = (fV + ing[i]) / 2;
	}
	

	cout << setprecision(15) << fV << endl;


} //cin.tie(0) bei schnellem Wechseln

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

int main()
{
	int H, W, b[51][51] = {-1};
	string S;

	cin >> H >> W;

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			cin >> S[0];
			if (S[0] == '#')b[i][j] = 1;
			else b[i][j] = 0;
		}
	}

	for (int i = 1; i <= H; i++) {
		for (int j = 1; j <= W; j++) {
			if (b[i][j] == 1) {
				int k = 0;
				if (b[i][j - 1] == 1)k = 1;
				if (b[i][j + 1] == 1)k = 1;
				if (b[i+1][j] == 1)k = 1;
				if (b[i-1][j] == 1)k = 1;
				if (k == 0) {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

int main() {
  int n;
  cin >> n;
  vl a(n, 0), b(n, 0), c(n, 0), cumb(n, 0);
  REP(i, n) { cin >> a[i]; }
  REP(i, n) { cin >> b[i]; }
  REP(i, n) { cin >> c[i]; }

  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());

  for (int i = n - 1; i >= 0; i--) {
    cumb[i] = cumb[min(n - 1, i + 1)] +
              (c.end() - upper_bound(c.begin(), c.end(), b[i]));
  }

  ll ans = 0;
  REP(i, n) {
    int idx = upper_bound(b.begin(), b.end(), a[i]) - b.begin();
    ans += cumb[idx];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
int x,n;
cin>>x>>n;
int a[n],cnt[101]={0};
for(int i=0;i<n;i++)
{
	cin>>a[i];
	cnt[a[i]]=1;
}
int ans=0,diff=-1;
for(int i=-101;i<=101;i+=1)
{
	if(cnt[i]==1)
	{
		continue;
	}
	if(diff==-1)
	{
		diff=abs(x-i);
		ans=i;
	}
	else
	{
		if(diff>abs(x-i))
		{
			diff=abs(x-i);
			ans=i;
		}
	}
}
cout<<ans;

}


Measured memory_bytes: 3652
#include <stdio.h>
#include <string.h>
int main (){
	int input;
	scanf ("%d",&input);getchar();
	int como=input;
	int tempat=0;
	while(input>0){
		tempat+=input%10;
		tempat*=10;
		input/=10;
	}
	if(tempat/10==como){
		printf("Yes\n");
	}
	else printf ("No\n");
}

Measured memory_bytes: 128
//
// Created by kuribohkute on 29/12/2018.
//

#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long cc;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b >= c) cout << b + c; else {
        cout << b + c - (c - (a + b)) + 1;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 100000000;

int main() {
  string s; cin >> s;
  int a[26] = {0};
  rep(i, s.size()) {
    a[s[i] - 'a']++;
  }
  rep(i, 26) {
    if (!a[i]) {
      char ans = i + 'a';
      cout << ans << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

Measured memory_bytes: 512
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var n,q;

console.log(main());
function main(){
  n = o.a();
  q = o.m(n);
  q.sort((a,b)=>a[1]>b[1]?1:a[1]<b[1]?-1:a[0]-b[0]);
  var ans = solve();
  q.sort((a,b)=>a[0]>b[0]?1:a[0]<b[0]?-1:a[1]-b[1]);
  ans = Math.max(ans,solve());
  var x = xArray("[0,1e9]",n);
  var y = xArray("[0,1e9]",n);
  var l = q[0][0], r = q[0][1];
  for(var i = 1; i < n; i++){
    if(l < q[i-1][0])l = q[i-1][0];
    if(r > q[i-1][1])r = q[i-1][1];
    x[i][0] = l, x[i][1] = r;
  }
  var l = q[n-1][0], r = q[n-1][1];
  for(var i = n-2; i >= 0; i--){
    if(l < q[i+1][0])l = q[i+1][0];
    if(r > q[i+1][1])r = q[i+1][1];
    y[i][0] = l, y[i][1] = r;
  }
  for(var i = 0; i < n; i++){
    var t = q[i][1]-q[i][0]+1;
    var l = Math.max(x[i][0], y[i][0]);
    var r = Math.min(x[i][1], y[i][1]);
    if(l <= r)t += r-l+1;
    if(ans < t)ans = t;
  }
  return ans;
}

function solve(){
  var l = 0, r = 1e9, x = xArray(0,n);
  for(var i = n-1; i; i--){
    if(l < q[i][0])l = q[i][0];
    if(r > q[i][1])r = q[i][1];
    if(l > r)break;
    x[i] = r-l+1;
  }
  l = 0, r = 1e9;
  var res = 0;
  for(var i = 0; i < n-1; i++){
    if(l < q[i][0])l = q[i][0];
    if(r > q[i][1])r = q[i][1];
    if(l > r)break;
    var t = r-l+1 + x[i+1];
    if(res < t)res = t;
  }
  return res
}

Measured memory_bytes: 76428
// #include<iostream>
// #include<vector>
// #include<algorithm>
// #include<map>
// #include<cstring>
// #include<math.h>
// #include<bitset>
// #include<queue>
// #include<set>
// #include<iomanip>
// #include<math.h>
// #include<assert.h>
// #include<string>
// #include<cstdlib>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------


int main(){
  ll N,K;
  cin >> N >> K;
  while(1){
    if(N==0 && K==0){
      break;
    }
    vector<ll> a(N);
    for(int i=0; i<N; i++){
      cin >> a[i];
    }
    vector<ll> S(N+1,0);
    for(int i=1; i<N; i++){
      S[i+1] = S[i] + a[i];
    }
    ll ans=0;
    for(int i=K; i<=N; i++){
      chmax(ans, S[i]-S[i-K]);
    }
    cout << ans << endl;
    cin >> N >> K;
  }
  return 0;
}



Measured memory_bytes: 4372
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const ll INF = 1LL << 60;
int N, M;
ll x[1010], y[1010], z[1010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }
  ll ans = -INF;
  for (int i = 0; i < 1 << 3; i++) {
    vector<ll> p;
    for (int j = 0; j < N; j++) {
      ll tmp = 0;
      tmp += (i >> 0 & 1 ? x[j] : -x[j]);
      tmp += (i >> 1 & 1 ? y[j] : -y[j]);
      tmp += (i >> 2 & 1 ? z[j] : -z[j]);
      p.emplace_back(tmp);
    }
    sort(p.rbegin(), p.rend());
    ll sum = 0;
    for (int j = 0; j < M; j++) {
      sum += p[j];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};

int main()
{
  string str;
  while(getline(cin,str)){
    for(int i = 0;i < 26;i++){
      for(int i = 0;i <str.size();i++){
	if(isalpha(str[i]))
	  str[i] = (str[i]=='z')? 'a' : str[i] + 1;
      }
    if(str.find("the") !=string::npos||str.find("that") !=string::npos||
       str.find("this") !=string::npos){
      cout <<str<<endl;
      break;
    }
  }
  }


  return 0;
}

Measured memory_bytes: 1180
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cmath>
#include<stack>
#include<vector>

using namespace std;

struct City
{
	string id;
	int year;
	int prefecture;
	int order;
};

string createPaddingID(int x)
{
	int padding = 5;
	int t = x / 10;
	while (t > 0)
	{
		padding--;
		t /= 10;
	}

	string r;
	for (int i = 0; i < padding; i++)
	{
		r += "0";
	}
	r += to_string(x);

	return r;
}

string createID(int p, int x)
{
	string r;
	r += createPaddingID(p);
	r += createPaddingID(x);
	return r;
}

int N, M;
City cities[100009];

int main()
{
	cin >> N >> M;
	for (int i = 0; i < M; i++)
	{
		cin >> cities[i].prefecture >> cities[i].year;
		cities[i].order = i;
	}

	sort(begin(cities), begin(cities) + M, [](City c1, City c2) {
		if (c1.prefecture == c2.prefecture)
		{
			return c1.year < c2.year;
		}
		return c1.prefecture < c2.prefecture;
	});

	int id = 1;
	int p = cities[0].prefecture;
	cities[0].id = createID(p, id);
	for (int i = 1; i < M; i++)
	{
		if (p == cities[i].prefecture)
		{
			id++;
		}
		else
		{
			id = 1;
		}

		p = cities[i].prefecture;

		cities[i].id = createID(cities[i].prefecture, id);
	}

	sort(begin(cities), begin(cities) + M, [](City c1, City c2) {
		return c1.order < c2.order;
	});

	for (int i = 0; i < M; i++)
	{
		cout << cities[i].id << endl;
	}

	return 0;
}


Measured memory_bytes: 8576
n, a, b, c = gets.split.map{|t|t.to_s.to_i}
l = Array.new(n){ gets.to_s.to_i }
 
ans = n * 10 + 1000 * 3
[-1, 0, 1, 2].repeated_permutation(n) do |per|
  
  # a = b = c = 0
  mp = -10 * 3
  kadomatsu = [0] * 3
  l.each_with_index do |take, i|
    next if (idx = per[i]) < 0
    kadomatsu[idx] += take
    mp += 10
  end
  next if kadomatsu.include?(0)
  
  mp += (kadomatsu[0] - a).abs + (kadomatsu[1] - b).abs + (kadomatsu[2] - c).abs
  ans = mp if ans > mp
end

puts ans

Measured memory_bytes: 1788
//
// Created by kuroneko on 2019-07-06.
//

#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>

typedef long long ll;
using namespace std;

int main() {
    string s; cin >> s;
    int ans = 0;
    for (int i = 0; i < int(s.size())-1; i++) {
        if ((s[i] == '0' && s[i+1] == '0') || (s[i] == '1' && s[i+1] == '1')) {
            if (s[i+1] == '0') s[i+1] = '1';
            else s[i+1] = '0';
            ans++;
        }
    }

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

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
int main (){
  int i;
  int a,b,m,x,y,c,dis=100000000;
  cin>>a>>b>>m;
  vector<int>aa(a),bb(b);
  int mn1=100000000,mn2=100000000;
  for(i=0;i<a;i++){
    cin>>aa[i];
    mn1=min(aa[i],mn1);
  }
  for(i=0;i<b;i++){
    cin>>bb[i];
    mn2=min(bb[i],mn2);
  }
  for(i=0;i<m;i++){
    cin>>x>>y>>c;
    dis=min(dis,aa[x-1]+bb[y-1]-c);
  }
  dis=min(dis,mn1+mn2);
  cout<<dis<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
void chmin(int& a, int b){
    a = min(a, b);
}
 
int main(){
    int H, N;
    cin >> H >> N;
    vector<int> A(N), B(N);
    for(int i=0; i<N; i++) cin >> A[i] >> B[i];
 
    vector<int> dp(100000, 1e9);
    dp[0] = 0;
    for(int h=0; h<H; h++) for(int i=0; i<N; i++){
        chmin(dp[min(h+A[i], H)], dp[h] + B[i]);
    }
    cout << dp[H] << endl;
    return 0;}

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

using namespace std;

char str[100005][13];
string str2[100005];

int main(){
	int N;
	scanf("%d", &N);
	
	for(int i = 0; i < N; i ++){
		scanf(" %s", str[i]);
		sort(str[i], str[i]+strlen(str[i]));
		str2[i] = str[i];
	}
	sort(str2, str2+N);
	
	long long ans = 0;
	long long streak = 1;
	for(int i = 1; i <= N; i ++){
		if(str2[i] == str2[i-1]){
			streak ++;
		}else{
			ans += (streak-1)*streak/2;
			streak = 1;
		}
	}
	printf("%lld", ans);
}


Measured memory_bytes: 7040
#include<stdio.h>
#include<string.h>
#define MAX(x,y) ((x>y)?x:y)
#define Min(x,y) ((x<y)?x:y)

int t[10005];
int dp[3][5005][3];
int main(){
	int i,j,k,n,x,y,z;
	
	scanf("%d",&n);
	for(i=1;i<=n-1;i++)scanf("%d",&t[i]);
	for(i=0;i<2;i++)for(j=0;j<=n/2;j++)for(k=0;k<2;k++)dp[i][j][k]=100000000;
	dp[1][1][0]=0;
	dp[1][1][1]=0;
	for(i=2;i<=n;i++){
		x=i%2;
		y=(i+1)%2;
		z=Min(i-1,n/2);
		for(j=1;j<=z;j++){
			//not-cut
			dp[x][j+1][0]=Min(dp[x][j+1][0],dp[y][j][0]);
			dp[x][j+1][1]=Min(dp[x][j+1][1],dp[y][j][1]);
			//cut
			if(i-j<=n/2){
				dp[x][i-j][1]=Min(dp[x][i-j][1],dp[y][j][0]+t[i-1]);
				dp[x][i-j][0]=Min(dp[x][i-j][0],dp[y][j][1]+t[i-1]);
			}
		}
		for(j=0;j<=n/2;j++){
			dp[y][j][0]=100000000;
			dp[y][j][1]=100000000;
		}
	}
	printf("%d\n",dp[n%2][n/2][0]);
	
	return 0;
}

Measured memory_bytes: 520
n, k = map(int, input().split())
a = [int(x)-1 for x in input().split()]

visited = [0] * n
visited[0] = 1
visit_list = [0]
visit = 0
while True:
    new_visit = a[visit]
    if visited[new_visit] == 1:
        break
    visited[new_visit] = 1
    visit_list.append(new_visit)
    visit = new_visit

period_first_index = visit_list.index(a[visit_list[-1]])
period_list = visit_list[period_first_index:]

if k < len(visit_list):
    print(visit_list[k]+1)
elif k == len(visit_list):
    print(a[visit_list[-1]]+1)
else:
    print(period_list[(k-period_first_index)%len(period_list)]+1)

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

//#define int long long
#define reps(i,s,n) for(ll (i)=(s);(i)<(ll)(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) reps(i,0,n+1)
#define repst(i,s,n) reps(i,s,n+1)
#define reprt(i,n,t) for(ll (i)=(n);(i)>=t;--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) cout<<#x" : "<<ln,for(int (i)=0;i<n;++i){cout<<x[i]<<(i==n-1?'\n':' ');}

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

/*
 * 少なくとも片方の点が盤面の周上にない組は無視していい ↓こんな感じで変形すればないのと同じ
 * https://drive.google.com/open?id=11LEYHGAANXY512nmcvHTOI3528ufQdvz
 * 両方の点が盤面の周上にある場合、それらを繋ぐとどうやっても盤面を2分するので繋げないペアが生まれる可能性がある
 * 点を(0,0)から周上の時計回りの距離の昇順に点を並べて、2点i,jについてi,j,i,jとなっていたらどうやっても交差する
 */

int h, w, n, xa, ya, xb, yb, m;
vpii p;
stack<int> s;

// (x,y)が周上にあるかどうか
bool online(int x, int y) {return x%w==0 || y%h==0;}

// 周上の原点からの距離
int d(int x, int y) {
	if (y==0) return x;
	if (x==w) return w+y;
	if (y==h) return w+h+(w-x);
	return w+h+w+(h-y);
}

signed main() {
	cin >> w >> h >> n;
	rep(i,n) {
		cin >> xa >> ya >> xb >> yb;
		if (online(xa,ya) && online(xb,yb)) {
			int da = d(xa,ya), db = d(xb,yb);
			p.pb({da,m}), p.pb({db,m++});
		}
	}
	sort(all(p));
	s.push(-1);
	each(i,p) {
		if (s.top()==i.se) s.pop();
		else s.push(i.se);
	}
	cout << (s.size()==1 ? "YES" : "NO") << ln;
}

Measured memory_bytes: 2420