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

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    map<string, ll> anagramCount; 
    for(int i = 0; i < N; i++){
        string S;
        cin >> S;
        sort(S.begin(), S.end());
        anagramCount[S]++;
    }
    ll answer = 0;
    for(pair<string, ll> p: anagramCount)
    {
        ll value = p.second;
        if(value > 1)
        {
            answer += value * (value - 1) / 2;
        }
    }
    cout << answer << endl;
    return 0;
}

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

#define f(i, a, b, c) for(int i = a ; i < b ; i += c)
#define fr(i, a, b, c) for(int i = a ; i >= b ; i -= c)
#define fit(it, v) for(auto it = v.begin() ; it != v.end() ; ++it)
#define frit(it, v) for(auto it = v.rbegin() ; it != v.rend() ; ++it)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define NL '\n'

using namespace std;

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< lli > vli;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< char > vc;
typedef vector< string > vs;
typedef vector< bool > vb;
typedef set< int > si;
typedef set< ii > sii;

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

	#ifdef LOCAL_TEST
		ifstream h("in");
		ofstream g("out");
		clock_t z = clock();
	#else
		#define h cin
		#define g cout
	#endif//LOCAL_TEST

	int n, k;
	h >> n >> k;
	vii v(n);
	f(i, 0, n, 1)
		h >> v[i].second >> v[i].first;
	sort(allr(v));
	lli sum = 0;
	unordered_map< int, int > m;
	f(i, 0, k, 1){
		sum = sum + v[i].first;
		if (m.find(v[i].second) == m.end())
			m[v[i].second] = 1;
		else
			m[v[i].second]++;
	}
	queue< int > q;
	int cnt = m.size();
	fr(i, k - 1, 0, 1){
		if (m[v[i].second] > 1){
			q.push(i);
			m[v[i].second]--;
		}
	}
	sum = sum + (lli)cnt * cnt;
	vli temp;
	temp.eb(sum);
	f(i, k, n, 1){
		if (q.empty())
			break;
		if (m.find(v[i].second) == m.end()){
			int nd = q.front();
	//		if (sum - v[nd].first - ((lli)cnt * cnt) + v[i].first + ((lli)(cnt + 1) * (cnt + 1)) > sum){
			q.pop();
			sum = sum - v[nd].first - (lli)cnt * cnt;
			cnt++;
			sum = sum + v[i].first + (lli)cnt * cnt;
			m[v[i].second] = 1;
			temp.eb(sum);
		}
	}
	g << *max_element(all(temp));

	#ifdef LOCAL_TEST
		cerr << "Time taken is: " << double(clock() - z) / CLOCKS_PER_SEC << NL;
		h.close();
		g.close();
	#endif//LOCAL_TEST
}


Measured memory_bytes: 7716
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

const int INF = 1e9;

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

    int H, W, K;
    cin >> H >> W >> K;
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--; y1--; x2--; y2--;
    vector<string> c(H);
    REP(i, H) cin >> c[i];
    vector<set<int>> row(H, {-1, W}), col(W, {-1, H});
    REP(x, H) {
        REP(y, W) {
            row[x].insert(y);
            col[y].insert(x);
        }
    }
    row[x1].erase(y1);
    col[y1].erase(x1);
    priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<>> pq;
    pq.push({0, {x1, y1}});
    vector<vector<int>> dist(H, vector<int>(W, INF));
    dist[x1][y1] = 0;
    while (!pq.empty()) {
        auto p = pq.top(); pq.pop();
        int d = p.first, x = p.second.first, y = p.second.second;

        if (dist[x][y] < d) continue;

        auto it = row[x].lower_bound(y);
        int r = *it;
        int l = *(--it);

        for (int i = r; i <= min(y + K, W - 1); i++) {
            if (c[x][i] == '@') break;
            if (dist[x][i] <= d + 1) continue;
            dist[x][i] = d + 1;
            row[x].erase(i);
            col[i].erase(x);
            pq.push({d + 1, {x, i}});
        }

        for (int i = l; i >= max(y - K, 0); i--) {
            if (c[x][i] == '@') break;
            if (dist[x][i] <= d + 1) continue;
            dist[x][i] = d + 1;
            row[x].erase(i);
            col[i].erase(x);
            pq.push({d + 1, {x, i}});
        }

        it = col[y].lower_bound(x);
        int b = *it;
        int t = *(--it);

        for (int i = b; i <= min(x + K, H - 1); i++) {
            if (c[i][y] == '@') break;
            if (dist[i][y] <= d + 1) continue;
            dist[i][y] = d + 1;
            row[i].erase(y);
            col[y].erase(i);
            pq.push({d + 1, {i, y}});
        }

        for (int i = t; i >= max(x - K, 0); i--) {
            if (c[i][y] == '@') break;
            if (dist[i][y] <= d + 1) continue;
            dist[i][y] = d + 1;
            row[i].erase(y);
            col[y].erase(i);
            pq.push({d + 1, {i, y}});
        }
    }
    if (dist[x2][y2] == INF) cout << -1 << endl;
    else cout << dist[x2][y2] << endl;
}

Measured memory_bytes: 246360
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>

#define MOD (1000000007)
#define N_MAX 100000

using namespace std;
typedef long long int Int;


int main(void) {
    Int N;

    vector<Int> cousine;

    cin>>N;
    Int sum = 0;
    for(int i = 0;i < N;i++) {
        Int a,b;
        cin>>a>>b;
        cousine.push_back(a+b);
        sum += -b;
    }

    sort(cousine.begin(),cousine.end(),greater<Int>());
    for(int i = 0;i < N;i += 2)
        sum += cousine[i];

    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1400
#include<cstdio>
#include<algorithm>
using namespace std;
int b[100001];
bool cmp(int a,int b)
{
    return a>b;
}
int main()
{
    int n,m,c=0,tmp2,maxa=0;
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++)
    {
        scanf("%d %d",&tmp2,b+i);
        maxa=max(maxa, tmp2);
    }
    sort(b, b+n,cmp);
    for(int i=0;i<n;i++)
    {
        if(maxa<=b[i])
        {
            m-=b[i];
            c++;
            if(m<=0)
            {
                printf("%d",c);
                return 0;
            }
        }
    }
    if(m%maxa==0)
        c+=m/maxa;
    else
        c+=(m/maxa)+1;
    printf("%d",c);
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <iterator>
#include <algorithm>
#include <map>
#include <string>
using namespace std;

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

  int n, r;
  cin >> n >> r;
  if(n < 10){
    cout << r + (100*(10 - n));
  }else{
    cout << r;
  }


  return 0;
}


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

int main(){
 string t,w;
 int cnt=0;

 cin >> w ;
 for(int i=0;i<w.length();i++){
  w[i]=tolower(w[i]);
 }

 while (1){
  cin >> t ;
  if(t == "END_OF_TEXT")break;
  for(int i=0;i<t.length();i++){
   t[i]=tolower(t[i]);
  }

  if(t==w)cnt++;
 }
 
 cout << cnt << endl;

 return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

ll calc(ll A, ll C, ll D){
    ll cur = A / C + A / D - A / ((C * D) / __gcd(C, D));
    return A - cur;
}

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

    ll A, B; cin >> A >> B;
    ll C, D; cin >> C >> D;

    cout << calc(B, C, D) - calc(A-1, C, D) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int n; cin>>n;
	int a[n];
	int t=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		t^=a[i];
	}
	for(int i=0;i<n;i++)
	{
		cout<<(t^a[i])<<" ";
	}
		
}

Measured memory_bytes: 4360
N=int(input())
C=[0]*4
S=['AC','WA','TLE','RE']
for _ in range(N):
  s=input()
  if s==S[0]:
    C[0]+=1
  elif s==S[1]:
    C[1]+=1
  elif s==S[2]:
    C[2]+=1
  else:
    C[3]+=1
for i in range(4):
  print(S[i],'x',C[i])

Measured memory_bytes: 9148
function Main(input){
	input = ~~input.split("\n")[0];
  var arr = ["0","3","5","7"];
  var count = 0;
  for(var a of arr){
  for(var b of arr){
  for(var c of arr){
  for(var d of arr){
  for(var e of arr){
  for(var f of arr){
  for(var g of arr){
  for(var h of arr){
  for(var i of arr){
  	var hoge = [a,b,c,d,e,f,g,h,i];
    hoge = (""+~~(hoge.join(""))).split("");
    if(hoge.length < 3)continue;
    if(hoge.find((j)=>j==0) !== undefined)continue;
   	if(hoge.find((j)=>j==3) && hoge.find((j)=>j==5) && hoge.find((j)=>j==7)){
    	var value = ~~hoge.join("");
      if(value > input)return count;
      count++;
    }
  }
  }
  }
  }
  }
  }
  }
  }
  }
  return count;
}

// If you are interested in the algorithms I used, 
// there is no need to read down from this line.

((b,c,d)=>"undefined"!=typeof require?console.log(Main(require("fs").readFileSync("/dev/stdin","utf8"))):[b=b.split("\n").slice(1,-1).join("\n"),c=function(){try{return Main(b)}catch(f){return f.stack||f.message}}(),d=typeof c,"string"==d||(c=JSON.stringify(c)),$("<form>").append([[10,b],0,[1,d],0,[10,c]].map(f=>$(f?"<textarea>":"<br>",f&&{rows:f[0],cols:40,text:f[1]}))).appendTo("body")])(`
999999999
`);

Measured memory_bytes: 21448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define arrlen(arr) (sizeof(arr)/sizeof(arr[0]))
#define Sort(arr) sort(arr, arr+arrlen(arr))
#define For(i,s,n) for(int i=s;i<n;i++)
	
int main(){
	int N,sum=0;
	cin >> N;
	int W[N];
	For(i,0,N){
		cin >> W[i];
		sum+=W[i];
	}
	
	int ans=sum;
	For(i,0,N){
		int s=0;
		for(int j=0;j<=i;j++){
			s+=W[j];
		}
		ans=min(ans,abs(sum-2*s));
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<iostream>
#include<numeric>
using namespace std;

int main() {
	int n;
	cin >> n;
	if (n % 2 == 1)
		n += n;
	cout << n;
}

Measured memory_bytes: 256
#素因数分解
def primefact(x0):
    tmp_l = [1]
    if x0 == 1:
        return tmp_l
    i = 2
    while 1:
        if i > pow(x0,1/2):
            if x0 == 1:
                break
            tmp_l.append(x0)
            break
        if x0 % i == 0:
            tmp_l.append(i)
            while x0 % i == 0:
                x0 //= i   
        i+=1
    return tmp_l

#最大公約数
def gcd(x0, y0):
    if x0<y0:
        tmp0 = x0
        x0 = y0
        y0 = tmp0
    if y0 == 0:
        return x0
    else:
        return gcd(y0, x0 % y0)
        
a,b=map(int,input().split())

g = gcd(a,b)
print(len(primefact(g)))

Measured memory_bytes: 3064
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (int)1000000007
#define DBLINF (DBL_MAX)/10
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
using namespace std;
inline int gcd(int a, int b) {
	while (b) {
		int c = a;
		a = b; b = c % b;
	}
	return a;
}
inline int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
bool isprime(int n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
int mypow(int a, int b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	int memo = mypow(a, b >> 1);
	return memo * memo;
}
int modpow(int a, int b, int m = mod) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	int memo = modpow(a, b / 2, m);
	return memo * memo % m;
}
int n, a, b;
P p[200010];
multiset<int> st1, st2;
signed main() {
	cin >> n;
	rep(i, n) {
		cin >> a >> b;
		p[i] = make_pair(max(a, b), min(a, b));
		st1.insert(min(a, b));
		st2.insert(max(a, b));
	}
	sort(p, p + n);
	int now = 0;
	while (now != n && p[now].first < *st1.rbegin()) {
		st1.erase(st1.find(p[now].second));
		st2.erase(st2.find(p[now].first));
		st1.insert(p[now].first);
		st2.insert(p[now].second);
		now++;
	}
	int ans = (*st1.rbegin() - *st1.begin()) * (*st2.rbegin() - *st2.begin());
	for (; now < n; now++) {
		st1.erase(st1.find(p[now].second));
		st2.erase(st2.find(p[now].first));
		st1.insert(p[now].first);
		st2.insert(p[now].second);
		chmin(ans, (*st1.rbegin() - *st1.begin())* (*st2.rbegin() - *st2.begin()));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 22144
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
long long n, k, a, ans1, ans2, c[45], c0, c1;
int main(){
    scanf("%lld%lld", &n, &k);
    rep(i,n){
        scanf("%lld", &a);
        rep(j,41) if(a>>j&1) c[j]++;
    }
    rep(i,41){
        c1 = c[i] << i; c0 = (n<<i) - c1;
        ans1 = (k>>i&1 ? max(c0 + ans1, c1 + ans2) : ans1 + c1);
        ans2 += max(c0, c1);
    }
    printf("%lld\n", ans1);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;

int main() {
    ll H, W;
    cin >> H >> W;
    ll sh, sw, gh, gw;
    cin >> sh >> sw;
    cin >> gh >> gw;
    sh--;
    sw--;
    gh--;
    gw--;

    // 道の一覧
    vector<vector<bool>> roads(H, vector<bool>(W, false));
    for (ll h = 0; h < H; h++) {
        for (ll w = 0; w < W; w++) {
            char c;
            cin >> c;
            while (c != '.' && c != '#') {
                cin >> c;
            }
            if (c == '.') {
                roads[h][w] = true;
            }
        }
    }

    vector<vector<bool>> done(H, vector<bool>(W, false));
    vector<stack<pair<ll, ll>>> diststack(1 + (H * W) / 2);
    ll d = 0;
    diststack[0].push(make_pair(sh, sw));
    while (d < (ll)diststack.size()) {
        if (diststack[d].empty()) {
            d++;
            continue;
        }
        auto src = diststack[d].top();
        diststack[d].pop();
        ll h = src.first;
        ll w = src.second;
        if (h == gh && w == gw) {
            cout << d << endl;
            return 0;
        }
        if (done[h][w]) {
            continue;
        }
        done[h][w] = true;
        for (ll y = h - 2; y <= h + 2; y++) {
            for (ll x = w - 2; x <= w + 2; x++) {
                if (y >= 0 && y < H && x >= 0 && x < W && roads[y][x] && !done[y][x]) {
                    if (abs(x - w) + abs(y - h) == 1) {
                        diststack[d].push(make_pair(y, x));
                    } else {
                        diststack[d + 1].push(make_pair(y, x));
                    }
                }
            }
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 341484
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let B = read![[i64]];

    let mut sum = B[0]; // A[0]
    for i in 1..N - 1 {
        // A[i]
        let a = min(B[i - 1], B[i]);
        sum += a;
    }
    // A[N - 1]
    sum += B[N - 2];

    println!("{}", sum)
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  string s; cin >> s;
  int Q; cin >> Q;
  deque<char> q;
  for(int i = 0; i < s.size(); i++){
    q.push_back(s[i]);
  }
  int p = 0;
  for(int i = 0; i < Q; i++){
    int com; cin >> com;
    if(com == 1){
      p ^= 1;
    }else{
      int f;
      char c;
      cin >> f >> c;
      f--;
      if(f ^ p){
        q.push_back(c);
      }else{
        q.push_front(c);
      }
    }
  }
  if(p == 1) reverse(q.begin(),q.end());
  for(auto &c : q){
    cout << c;
  }

  return 0;
}


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

int main(){
  ll n;
  cin>>n;
  vector<ll> v(n+10,0);
  for (int i = 1;i<=n;i++){
    cin>>v.at(i);
  }
  ll sum = 0;
  for (int i = 0;i<=n;i++){
    sum = sum + abs(v.at(i) - v.at(i+1));
  }
  for (int i = 1;i<=n;i++){
    cout << sum + abs(v.at(i-1) - v.at(i+1)) - (abs(v.at(i)-v.at(i+1)) + abs(v.at(i)-v.at(i-1))) << endl;
  }
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int a[200005],b[200005];

int main(){
    int k,n,res=0,i;
    cin>>k>>n;
    
    for(i=1;i<=n;i++)
    cin>>a[i];
    b[1]=a[1]+k-a[n];
    
    for(i=2;i<=n;i++)
    b[i]=a[i]-a[i-1];
    
    for(i=1;i<=n;i++)
    res=max(res,b[i]);
    
    cout<<k-res;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int A[3][3];
    for(int i = 0; i < 3; i++)
        for(int j = 0; j < 3; j++) cin >> A[i][j];
    int N;
    cin >> N;
    for(int i = 0; i < N; i++) {
        int b;
        cin >> b;
        for(int h = 0; h < 3; h++)
            for(int w = 0; w < 3; w++)
                if(A[h][w] == b) A[h][w] = -1;
    }

    bool ok = false;

    for(int h = 0; h < 3; h++) {
        int tmp = 0;
        for(int w = 0; w < 3; w++) {
            tmp += A[h][w];
        }
        if(tmp == -3) ok = true;
    }

    for(int h = 0; h < 3; h++) {
        int tmp = 0;
        for(int w = 0; w < 3; w++) {
            tmp += A[w][h];
        }
        if(tmp == -3) ok = true;
    }
    if(A[0][0] + A[1][1] + A[2][2] == -3) ok = true;
    if(A[0][2] + A[1][1] + A[2][0] == -3) ok = true;
    if(ok)
        cout << "Yes";
    else
        cout << "No";
    return 0;
}

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

/*Starry Sky Tree*/
/*Range Add Min(Max) Query*/
/*区間加算、区間Min,区間Max*/

class RMAQ{
public: 
  
  //遅延用の型  
  struct T{
    bool type; //0 - empty   , 1 - update
    int value;
    T():type(0),value(0){}
    T(bool type,int value):type(type),value(value){}
  };

  //比較可能な主データ型
  struct D{
    int value;
    D():value(0){} /*適切な値にする!!!!!!*/
    D(int value):value(value){}
    bool operator < (D a)const {return value < a.value;} //merge用
  };
  
  D INF = D(1LL<<55); /*!!!!!!!!!!!!!!!!!!!!!!!!*/

  int n;
  vector<D> dat;
  vector<T> td;
  int toMax; //0 -> RangeMin, 1 -> RangeMax
  
  RMAQ(){n=-1;}
  RMAQ(int n_,int toMax = 0){
    this->toMax = toMax;
    n=1;
    while(n<n_)n*=2;
    td.resize(2*n-1,T());
    dat.resize(2*n-1,D());
  }
  
  D merge(D a,D b){return min(a,b);}
  
  void delay(int k){
    if(td[k].type==0) return;
    int v = td[k].value;
    td[k].type = 0;
    td[k].value = 0;
    
    int l = k*2+1,r = k*2+2;
    dat[l].value += v; td[l].type = 1; td[l].value += v;
    dat[r].value += v; td[r].type = 1; td[r].value += v;
  }

  D update(int k,int x){
    td[k].type = 1;
    td[k].value += x;
    dat[k].value += x;
    return dat[k];
  }
  
  //[a,b)の値をx加算　add(a,b,x)
  D add(int a,int b,int x,bool flg=true,int k=0,int l=0,int r=-1){
    if(r==-1 && toMax) x *= -1; 
    if(r==-1) r=n, assert(a < n && b <= n);
    if(r<=a||b<=l) return flg? dat[k]:INF;
    if(a<=l&&r<=b) return flg? update(k,x):dat[k];
    
    delay(k);
    D vl = add(a,b,x,flg,k*2+1,l,(l+r)/2);
    D vr = add(a,b,x,flg,k*2+2,(l+r)/2,r);
    if(flg) dat[k] = merge(vl,vr);
    return merge(vl,vr);
  }
  
  //[a,b)の最小値を得る　find(a,b);
  int find(int a,int b){
    D res = add(a,b,0,false);
    if(toMax) res.value *= -1; 
    return res.value;
  }
};


signed main(){
  int n,q;
  cin>>n>>q;
  
  RMAQ rmaq(n,1);
  while(q--){
    int ord;
    cin>>ord;
    if(ord == 0){
      int s,t,x;
      cin>>s>>t>>x;
      rmaq.add(s,t+1,-x);
    }
    if(ord == 1){
      int s,t;
      cin>>s>>t;
      cout<<-rmaq.find(s,t+1)<<endl;
    }
  }
  
  return 0;
}



Measured memory_bytes: 8920
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
typedef tuple< int, int, int > State;
struct edge
{
  int to, cost;
};

int main()
{
  int N, M, cap;
  while(cin >> N >> M >> cap, N) {
    string src, dest;
    cin >> src >> dest;
  
    map< string, int > comb;
    vector< edge > graph[50000];
    bool flag[50000] = {};
    
    while(N--) {
      string a, b;
      int d;
      cin >> a >> b >> d;
      if(comb.find(a) == comb.end()) comb[a] = comb.size() - 1;
      if(comb.find(b) == comb.end()) comb[b] = comb.size() - 1;
      graph[comb[a]].push_back((edge){comb[b], d});
      graph[comb[b]].push_back((edge){comb[a], d});
    }

    while(M--) {
      string s;
      cin >> s;
      flag[comb[s]] = true;
    }
    
    cap *= 10;
    int s = comb[src], g = comb[dest];

    priority_queue< State, vector< State >, greater< State > > que;   
    vector< vector< int > > min_cost(comb.size(), vector< int >(cap + 1, INF));
    que.emplace(0, s, cap);
    min_cost[0][cap] = 0;
    int ret = -1;
    while(!que.empty()) {
      int cost, now, gas;
      tie(cost, now, gas) = que.top(); que.pop();
      if(cost > min_cost[now][gas]) continue;
      if(now == g) { ret = cost; break; }
      if(flag[now]) gas = cap;
      for(auto e : graph[now]) {
        int nextgas = gas - e.cost;
        if(nextgas < 0) continue;
        if(cost + e.cost >= min_cost[e.to][nextgas]) continue;
        min_cost[e.to][nextgas] = cost + e.cost;
        que.emplace(cost + e.cost, e.to, nextgas);
      }
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 53188
#include <stdio.h>
	#include <iostream>
	#include <vector>
	#include <algorithm>
	using namespace std;
	typedef long long ll;
	typedef std::vector<ll> lls;
	#define MIN(a, b) ( ((a)<(b)) ? (a) : (b) )
	#define MAX(a, b) ( ((a)>(b)) ? (a) : (b) )

	void cinv(lls& llVec, ll n) {
		ll val;
		llVec.reserve((size_t)(n));
		for (ll i = 0; i < n; i++) {
			cin >> val;
			llVec.push_back(val);
		}
	}


	int main()
	{
		ll N;
		lls A;

		cin >> N;
		cinv(A, N);

		double sum = 0;
		for (auto aOne : A) {
			sum += 1.0 / aOne;
		}
		cout << 1.0 / sum;

		return 0;
	}



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

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() {
    int a, b, c;
    cin >> a >> b >> c;
    bool flag = false;
    for (int i = a, n = b * a; i <= n; i += a) {
        if (i % b == c) flag = true;
    }
    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
typedef pair<int,int> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int a,b,c;
int main(){
    cin >> a >> b >> c;
    cout << (((100*a+10*b+c)%4)? "NO" : "YES") << endl;
}


Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
/*************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef long long ijt;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void) {
	ijt n,m;cin >> n >> m;
	priority_queue<double> q;
	
	for (int i = 0; i < n; i++)
	{
		double x;cin >> x;
		q.push(x);
	}
	for (int i = 0; i < m; i++)
	{
		double y = q.top();
		q.pop();
		q.push(y/(double)2);

	}

	ijt sum = 0;
	for (int i = 0; i < n; i++) {
		ijt x = (ijt)q.top();
		q.pop();
		sum += x;
	}
	cout <<sum << endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

ll LCM(ll a,ll b){
    return a / GCD(a,b) * b;
}

const int MOD = 1000000007;



int main() {
    int n,h; cin >> n >> h;
    ll total = 0;
    for(int i = 0;i < h;i++){
        int x; cin >> x;
        total += x;
    }
    n <= total ? cout << "Yes" : cout << "No";
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c) { return b / c - (a - 1) / c; }

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}
#define REP(i, n) for (long long i = 0; i < (n); i++)
vector<int> h, memo;

// int dp(int n) {
//     if (memo[n] != -1) {
//         return memo[n];
//     }
//     if (n == 0) {
//         return 0;
//     }
//     if (n == 1) {
//         return abs(h[1] - h[0]);
//     }
//     memo[n] = min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
//     return min(dp(n - 1) + abs(h[n] - h[n - 1]), dp(n - 2) + abs(h[n] - h[n - 2]));
// }

int main() {
    long long n;
    cin >> n;
    vector<vector<int>> dp(n, vector<int>(3));
    vector<vector<int>> a(n, vector<int>(3));
    REP(i, n) {
        cin >> a[i][0];
        cin >> a[i][1];
        cin >> a[i][2];
    }
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    for (int i = 1; i < n; i++) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i][0];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + a[i][1];
        dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + a[i][2];
    }
    cout << max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}) << endl;
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

template<class T> struct edge{
	int to;
	T wt;
	edge(int to,const T& wt):to(to),wt(wt){}
};
template<class T> using weighted_graph=vector<vector<edge<T>>>;

template<class T>
void add_directed_edge(weighted_graph<T>& G,int u,int v,const T& wt){
	G[u].emplace_back(v,wt);
}

template<class T>
vector<T> Dijkstra(const weighted_graph<T>& G,int s){
	constexpr T INF=numeric_limits<T>::max();
	int n=G.size();
	vector<T> d(n,INF); d[s]=0;
	priority_queue<pair<T,int>> Q; Q.emplace(0,s);
	while(!Q.empty()){
		T d0=-Q.top().first;
		int u=Q.top().second; Q.pop();
		if(d0>d[u]) continue;
		for(const auto& e:G[u]){
			int v=e.to;
			if(d[v]>d[u]+e.wt){
				d[v]=d[u]+e.wt;
				Q.emplace(-d[v],v);
			}
		}
	}
	return d;
}

const int INF=1<<29;

class segment_tree_dual{
	int n;
	vector<int> seg;

	void update(int l,int r,int a,int b,int u,int x){
		if(l<=a && b<=r){ seg[u]=min(seg[u],x); return; }
		int c=(a+b+1)/2;
		if(l<c && a<r) update(l,r,a,c,2*u  ,x);
		if(l<b && c<r) update(l,r,c,b,2*u+1,x);
	}

public:
	segment_tree_dual(int N){
		for(n=1;n<N;n*=2);
		seg.assign(2*n,INF);
	}

	void update(int l,int r,int x){ update(l,r,0,n,1,x); }

	int get(int u){
		u+=n;
		int res=seg[u];
		for(u/=2;u>=1;u/=2) res=min(res,seg[u]);
		return res;
	}
};

int main(){
	int h,w; scanf("%d%d",&h,&w);
	vector<int> l(h),r(h);
	rep(i,h) scanf("%d%d",&l[i],&r[i]), l[i]--;

	segment_tree_dual S(w);
	S.update(0,w,h);

	vector pos(h+1,vector<int>());
	for(int i=h-1;i>=0;i--){
		if(i==0){
			rep(x,w) pos[0].emplace_back(x);
		}
		else if(r[i]<w){
			pos[i].emplace_back(r[i]);
		}

		for(int x:pos[i]) if(!(l[i]<=x && x<r[i])) {
			pos[S.get(x)].emplace_back(x);
		}
		S.update(l[i],r[i],i);
	}
	rep(i,h+1){
		sort(pos[i].begin(),pos[i].end());
		pos[i].erase(unique(pos[i].begin(),pos[i].end()),pos[i].end());
	}

	int N=0;
	vector f(h+1,vector<int>());
	rep(i,h+1){
		f[i].resize(pos[i].size());
		rep(j,pos[i].size()) f[i][j]=N++;
	}

	int src=N;
	N++;
	weighted_graph<int> G(N);
	vector<int> next(w,-1);
	for(int i=h;i>=0;i--) rep(j,pos[i].size()) {
		int x=pos[i][j],u=f[i][j];
		if(i<h){
			if(j+1<pos[i].size()){
				add_directed_edge(G,u,u+1,pos[i][j+1]-x);
			}
			if(!(l[i]<=x && x<r[i]) && next[x]!=-1){
				add_directed_edge(G,u,next[x],0);
			}
		}
		next[x]=u;
	}
	rep(j,pos[0].size()){
		add_directed_edge(G,src,pos[0][j],0);
	}

	auto d=Dijkstra(G,src);

	vector<int> ans(h+1,INF);
	rep(i,h+1) rep(j,pos[i].size()) {
		int u=f[i][j];
		ans[i]=min(ans[i],d[u]);
	}
	for(int i=h;i>0;i--){
		ans[i-1]=min(ans[i-1],ans[i]);
	}
	for(int i=1;i<=h;i++) printf("%d\n",ans[i]<INF?ans[i]+i:-1);

	return 0;
}


Measured memory_bytes: 83912
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int>a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    int64_t ans = 0;
    for(int i=1; i<n; i++){
        if(a[i-1]>a[i]){
            ans += a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4044
#include <iostream>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;

int n, c;
int a[400];
int b[400];
int xc[401][401];
int nc[401][401];

int add(int a, int b){
	return (a + b) % mod;
}

int sub(int a, int b){
	return a >= b ? a - b : a - b + mod;
}

int mul(int a, int b){
	return ll(a) * b % mod;
}

int main() {
	cin >> n >> c;
	rep(i, n){
		cin >> a[i];
	}
	rep(i, n){
		cin >> b[i];
	}

	for(int i = 1; i <= 400; ++i){
		xc[i][0] = 1;
		for(int j = 1; j <= c; ++j){
			xc[i][j] = mul(xc[i][j - 1], i);
		}
	}
	rep(j, c + 1){
		for(int i = 1; i <= 400; ++i){
			xc[i][j] = add(xc[i][j], xc[i - 1][j]);
		}
	}

	nc[0][0] = 1;
	for(int i = 1; i <= n; ++i){
		rep(j, c + 1){
			rep(k, j + 1){
				nc[i][j] = add(nc[i][j], mul(nc[i - 1][j - k], sub(xc[b[i - 1]][k], xc[a[i - 1] - 1][k])));
			}
		}
	}
	cout << nc[n][c] << endl;
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  bool flag = true;
  REP(i,N){
    ll A;
    IN(A);
    if(A%2==0){
      if(A%3!=0 && A%5!=0) flag = false;
    }
  }

  if(flag){
    OUT("APPROVED");
  }else{
    OUT("DENIED");
  }

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

int main() {
    int sm = 0, x = 10, a;
    for (int i = 0; i < 5; i++) {
        cin >> a;
        sm += (int)((a + 9) / 10);
        if (a % 10 == 0) continue;
        x = min(x, a % 10);
    }

    cout << sm * 10 - 10 + x << endl;
    return 0;
}


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

void print(int x) {
    cout << (x ? "Yes\n" : "No\n");
    exit(0); }

int main() {
#ifdef HOME
    freopen("dat.in", "r", stdin);
    freopen("dat.out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    vector<int> v;
    int n, d, a(0), b(0);

    cin >> n;
    v.resize(n);
    for (auto &i: v)
        cin >> i;

    sort(begin(v), end(v));
    d = v.back();

    if (d - v[0] > 1)
        print(0);
    if (d > n)
        print(0);

    if (v[0] == d)
        print(n / (v[0] * 2) || n == v[0] + 1);

    for (auto i: v)
        (i == v[0]) ? ++a : ++b;

    if (b == 1)
        print(0);

    d-= a;
    print(d - b / 2 == 0);

    return 0; }


Measured memory_bytes: 640
c = [tuple(map(int, input().split())) for i in range(3)]

if (c[0][0] + c[0][1] - (c[0][2])*2 == c[1][0] + c[1][1] - (c[1][2])*2) and (c[0][0] + c[0][1] - (c[0][2])*2 == c[2][0] + c[2][1] - (c[2][2])*2):
    if (c[0][0] + c[1][0] - (c[2][0])*2 == c[0][1] + c[1][1] - (c[2][1])*2) and (c[0][0] + c[1][0] - (c[2][0])*2 == c[0][2] + c[1][2] - (c[2][2])*2):
        print("Yes")
        exit(0)

print("No")


Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for(i=1;i<=n;i++) scanf("%d",&A[i]);
  
  for(i=0;i<VMAX;i++) C[i]=0;

  for(i=1;i<=n;i++) C[A[i]]++;

  for(i=1;i<=VMAX;i++) C[i]=C[i-1]+C[i];
  
  for(i=n;i>0;i--){
    B[C[A[i]]]=A[i];
    C[A[i]]--;
  }

  printf("%d",B[1]);
  for(i=2;i<=n;i++) printf(" %d",B[i]);
  printf("\n");


  return 0;
}



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

int main() {
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        n /= 4;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int count;
            cin >> count;
            sum += count;
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
)

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

func min(a, b int) int {
	if a <= b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var a, b int
	fmt.Fscan(read, &a, &b)
	c := (a + b) / 2
	if math.Abs(float64(a-c)) == math.Abs(float64(b-c)) {
		fmt.Fprintln(write, c)
	} else {
		fmt.Fprintln(write, "IMPOSSIBLE")
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
using ll = long long;
int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll res = 0;

    if (b <= 0)
    {
        if (d <= 0)
            res = a * c;
        else if (c <= 0 && d >= 0)
            res = a * c;
        else if (c >= 0)
            res = b * c;
    }
    else if (a <= 0 && b >= 0)
    {
        if (d <= 0)
            res = a * c;
        else if (c <= 0 && d >= 0)
            res = max(a * c, b * d);
        else if (c >= 0)
            res = b * d;
    }
    else if (a >= 0)
    {
        if (d <= 0)
            res = d * a;
        else if (c <= 0 && d >= 0)
            res = b * d;
        else if (c >= 0)
            res = b * d;
    }

    printf("%lld\n", res);



    return 0;
}

Measured memory_bytes: 3756
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
inf = 10**17
mod = 10**9 + 7

x,a,b=MI()
ans=min(min(a+b,a+x),b+x)
print(ans)

Measured memory_bytes: 3316
import sys,math,collections,itertools
input = sys.stdin.readline

N=int(input())
tree = [[] for i in range(N+1)]

for _ in range(N-1):
    a,b,c=list(map(int,input().split()))
    tree[a].append([b,c])
    tree[b].append([a,c])
Q,K=list(map(int,input().split()))
    
memo = [-1]*(N+1)
q = collections.deque([K])
memo[K]=0
while q:
    now = q.pop()
    for direct,cost in tree[now]:
        if memo[direct]== -1:
            memo[direct]=memo[now]+cost
            q.append(direct)
for _ in range(Q):
    a,b=map(int,input().split())
    ans =memo[a]+memo[b]
    print(ans)


Measured memory_bytes: 50536
program AGC027A
    implicit none
    integer(8)::N,x,i,ans
    integer(8),allocatable,dimension(:)::A
    read*,N,x
    allocate(A(N))
    read*,A
    ans=0
    call heapsort(N,A)

    do i=1,N
        if(x>=A(i))then
            if(i==N)then
                if(x==A(i))ans=ans+1
            else
                x=x-A(i)
                ans=ans+1
            end if
        else
            exit
        end if
    end do

    print'(i0)',ans
end program AGC027A

subroutine heapsort(n,array)
    implicit none
    integer(8),intent(in) :: n
    integer(8),intent(inout) :: array(1:n)
   
    integer(8) ::i,k,j,l
    integer(8) :: t
   
    if(n.eq.1)return
  
    l=n/2+1
    k=n
    do while(k.ne.1)
       if(l.gt.1)then
          l=l-1
          t=array(L)
       else
          t=array(k)
          array(k)=array(1)
          k=k-1
          if(k.eq.1) then
             array(1)=t
             exit
          endif
       endif
       i=l
       j=l+l
       do while(j.le.k)
          if(j.lt.k)then
             if(array(j).lt.array(j+1))j=j+1
          endif
          if (t.lt.array(j))then
             array(i)=array(j)
             i=j
             j=j+j
          else
             j=k+1
          endif
       enddo
       array(i)=t
    enddo
  
    return
  end subroutine heapsort

Measured memory_bytes: 768
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;

 
const ll INF = (1001001001);
const ll N =(200+5); // TODO : change value as per problem
const ll MOD = 1e9+7;

int a[N];
int adj[N][N];
void solve(){
	int n,m,r;
	cin >> n >> m >> r;	
	vector<int> v(r);
	for(int i =1;i<=r;i++){
		cin >> v[i-1];
	}
	for(int i =1;i<=n;i++){
		for(int j =1;j<=n;j++){
			adj[i][j]=INF;
		}
		adj[i][i]=0;
	}
	for(int i =1;i<=m;i++){
		int u,vv,c;
		cin >> u >> vv >> c;
		adj[u][vv] = c;
		adj[vv][u] = c;
	}
	for(int k=1;k<=n;k++){
		for(int i =1;i<=n;i++){
			for(int j =1;j<=n;j++){
				
				adj[i][j] = min(adj[i][j],adj[i][k] + adj[k][j]);
			}	
		}
	}
	sort(v.begin(),v.end());
	int ans = INF;
	do{
		int co = 0;
		for(int i = 1;i<v.size();i++){
			co += adj[v[i-1]][v[i]];
		}
		ans = min(ans,co);
	}while(next_permutation(v.begin(),v.end()));
	cout << ans << endl;
}
signed main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     // freopen(".in","r",stdin);freopen(".out","w",stdout);
    
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}

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

int main() {
	int i,n,m,x,y;
	cin>>n>>m>>x>>y;
	int a[n],b[m],max1=INT_MIN,min1=INT_MAX;
	for(i=0;i<n;i++)
	  {cin>>a[i];
	    max1=max(max1,a[i]);	
	  }
	for(i=0;i<m;i++)
	  {cin>>b[i];
	    min1=min(min1,b[i]);	
	  }
	 int m1,m2,m3,m4; 
	 m1=x+1;
	 m2=y;
	 m3=max1+1;
	 m4=min1;
	 //cout<<m1<<m2<<m3<<m4;
	 if(m2<m3 || m1>m4 || m1>m2 || m3>m4)
	   {
	   	cout<<"War";
	   }
	 else
	   cout<<"No War"<<'\n';
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

int main() {
    int N;cin>>N;
    vector<ll> a(N);
    ll sum = 0,sum2 = 0;
    rep(i,N) {
        cin>>a[i];
        sum+=a[i];
        if(i%2==1) sum2+=2*a[i];
    }
    vector<ll> x(N);
    x[0] = sum - sum2;
    rep(i,N-1) {
        x[i+1] = 2 * a[i] - x[i];
    }
    rep(i,N) {
        cout<<x[i]<<" ";
        if(i==N-1) cout<<endl;
    }
}

Measured memory_bytes: 4780