akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		double[] lm = new double[2];
		double r, px, py;
		int size = in.nextInt();
		for (int i = 0; i < size; i++) {
			double x1 = in.nextDouble();
			double y1 = in.nextDouble();
			double x2 = in.nextDouble();
			double y2 = in.nextDouble();
			double x3 = in.nextDouble();
			double y3 = in.nextDouble();
			double a = x1 - x2;
			double b = y1 - y2;
			double c = (-1) * (x1 * x1 + y1 * y1) + x2 * x2 + y2 * y2;
			double d = x2 - x3;
			double e = y2 - y3;
			double f = (-1) * (x2 * x2 + y2 * y2) + x3 * x3 + y3 * y3;
			lm = simulEq(a, b, c, d, e, f);
			double l = lm[0];
			double m = lm[1];
			double n = -1 * (x1 * x1 + y1 * y1 + l * x1 + m * y1);
			px = -0.5 * l;
			py = -0.5 * m;
			r = Math.sqrt((l * l + m * m) / 4.0 - n);
			//System.out.println("x^2 + y^2 + (" + l + "x) + (" + m + "y) + (" + n + ") = 0");
			System.out.printf("%.3f %.3f %.3f\n", px, py, r);
		}
	}

	static double[] simulEq(double a, double b, double c, double d, double e, double f) {
		double y = (c * d - a * f) / (b * d - a * e);
		double x = (c * e - b * f) / (a * e - b * d);
		return new double[] { x, y };
	}
}

Measured memory_bytes: 28764
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;
using ld = long double;
namespace treap {
	struct node {
		int prior, sz, dp, add;
		node *l, *r;
		node(int x) {
			prior = (rand() << 15) | rand();
			// sz = 1;
			dp = x;
			l = r = NULL;
			add = 0;
		}
	};

	typedef node * pnode;

	void push(node* T) {
		T->dp += T->add;
		if (T->l)
			T->l->add += T->add;
		if (T->r)
			T->r->add += T->add;
		T->add = 0;
	}

	node* merge(node * L, node * R) {
		if (!L) {
			return R;
		}
		if (!R) {
			return L;
		}
		if (L->prior > R->prior) {
			push(L);
			L->r = merge(L->r, R);
			return L;
		}
		else {

			push(R);
			R->l = merge(L, R->l);
			return R;

		}
	}

	pair<node*,node*> split(pnode T, int value) {
		if (!T) {
			return make_pair(nullptr,nullptr);
		}
		push(T);
		if (T->dp >= value) {
			auto p=split(T->l, value);
			T->l=p.second;
			return make_pair(p.first,T);
		}
		else {

			auto p = split(T->r, value);
			T->r = p.first;
			return make_pair(T, p.second);
		}
	}

	int findBegin(pnode T) {
		push(T);
		if (!T->l)
			return T->dp;
		return findBegin(T->l);
	}

	int findMax(pnode T, int n) {
		if (!T)
			return 0;
		push(T);
		return findMax(T->l, n) + findMax(T->r, n) + (T->dp <= 1e9 ? 1 : 0);
	}


}
#include<random>

vector<int>dfs(const vector<vector<int>>&edges, const int start) {
	vector<int>memo(edges.size(),1e9);
	memo[start]=0;
	queue<int>que;
	que.emplace(start);
	while (!que.empty()) {
		const int now=que.front();
		que.pop();
		for (auto e : edges[now]) {
			if (memo[e] > memo[now] + 1) {
				memo[e]=memo[now]+1;
				que.emplace(e);
			}
		}
	}
	return memo;
}

int main() {
	int N;
	while (cin >> N,N) {


		int S, T; cin >> S >> T;
		S--; T--;
		int M; cin >> M;
		vector<vector<int>>edges(N);
		vector<vector<int>>rev_edges(N);
		map<pair<int, int>, int>mp;
		for (int i = 0; i < M; ++i) {
			int a, b; cin >> a >> b;
			a--; b--;
			rev_edges[b].push_back(a);
			edges[a].push_back(b);
			if(mp.find(make_pair(a,b))==mp.end())mp[make_pair(a, b)] = i;
		}
		vector<int>from_ss = dfs(edges, S);
		vector<int>from_ts = dfs(rev_edges, T);

		pair<int, int>answer = make_pair(from_ss[T], -1);
		for (auto m : mp) {
			auto i = m.first.first;
			auto e = m.first.second;
			int sum = 1 + from_ss[e] + from_ts[i];
			answer = min(answer, make_pair(sum,m.second));

		}
		cout << answer.first << " " << answer.second+1 << endl;

	}
	return 0;
}




Measured memory_bytes: 3928
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans = 1;
ll a[100005];

int main(void) {
    ll n;
    cin >> n;
    rep(i, 0, n) {
        cin >> a[i];
        if (a[i]==0) {
            puts("0");
            return 0;
        }
    }

    rep(i, 0, n) {
        if (__builtin_smulll_overflow(ans, a[i], &ans) || ans>(ll)1e18) {
            puts("-1");
            return 0;
        }
        
    } 
    cout << ans << "\n";
    return 0;
}



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

#define MAXN (int)(2*1e5 + 1)
#define MAXL 20
#define F first
#define endl "\n"
#define S second
#define MOD (int)(1e9 + 7)
#define lli long long int
#define sz(a) int(a.size())
#define M_PI 3.1415
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1};

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

  int n, l;
  int tot = 0;
  cin >> n >> l;
  for(int i=0;i<n;i++){
    tot += (i+l);
  }

  int ans = 0, dif = INT_MAX;

  for(int i=0;i<n;i++){
    int sum = 0;
    for(int j=0;j<n;j++){
      if(j == i) continue;
      sum += (j+l);
    }
    // cout << tot << " " << sum << endl;
    if(abs(tot - sum) <= dif) ans = sum, dif = abs(tot-sum);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
txy = [list(map(int,input().split())) for _ in [0]*N]
tc,xc,yc = 0,0,0
for tn,xn,yn in txy:
    d = abs(xc-xn) + abs(yc-yn)
    dt = tn - tc
    if d > dt or (d+dt)%2 == 1 :
        print("No")
        break
    tc,xc,yc = tn,xn,yn
else:
    print("Yes")

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

int main(){
	string s;
	cin >> s;
	int count = 0;

	for(int i = 0; i < 4; i++){
		for(int j = i + 1; j < 4; j++){
			if(s[i] == s[j]){
				count++;
			}
		}
	}
	if(count == 2){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
}


Measured memory_bytes: 256
import Data.List ( sortBy )

main :: IO ()
main = do
  _ <- getLine
  as <- map read . words <$> getLine
  print . point . alisAndBob . sort' $ as

sort' 
  :: Ord a => [a] -> [a]
sort' = sortBy (flip compare)

alisAndBob 
  :: Ord a => [a] -> ([a],[a])
alisAndBob ns = helper ns ([],[])
  where
    helper :: Ord a => [a] -> ([a],[a]) -> ([a],[a])
    helper [] ab = ab
    helper [a] ab@(as,bs) = (a:as, bs)
    helper (a:b:cs) ab@(as,bs) = helper cs (a:as, b:bs)

point
  :: ([Int],[Int]) -> Int
point (as,bs) = sum as - sum bs

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIII pair< int, pair<int,int> >
const int MaxN = 1e5+5;
vector<int> g[MaxN];
int dp[MaxN];
int N;

int dfs(int node, int pr){

    auto &ret = dp[node];
    if(ret!=-1) return ret;
    ret = 0;
    for(auto i: g[node]){
        if(i==pr) continue;
        ret = max( ret, dfs(i,node)+1 );
    }

    return ret;
}

void read(){

    int i,edge;
    memset(dp,-1,sizeof dp);
    cin>>N>>edge;
    for(i=0; i<edge; i++){
        int u,v;
        cin>>u>>v;
        g[u].push_back(v);
    }
}

void solve(){

    read();
    int res = 0;
    for(int i=1; i<=N; i++){
        res = max( res, dfs(i,0) );
    }

    cout<< res << "\n";
}

int main(){

    //freopen("input.txt","r",stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}


Measured memory_bytes: 12216
#include <cstdio>
#include <map>

using std::map;

const int
	MAXN = 500005,
	MAXLGN = 40;

int N, Q;
map< int, int > pos;
int tree[MAXN];
int cant;
struct node {
	int val, L, R, size;
} buff[2 * MAXN * MAXLGN];

int build( int lo, int hi ) {
	if ( lo > hi ) return 0;

	int idx = ++cant;

	int mid = ( lo + hi ) / 2;
	buff[idx] = (node){ mid, build( lo, mid - 1 ), build( mid + 1, hi ), 0 };
	return idx;
}

int update( int x, int val, int amount ) {

	if ( x == 0 ) return 0;

	int idx = ++cant;

	int L = buff[x].L;
	int R = buff[x].R;
	if ( val < buff[x].val ) L = update( L, val, amount );
	if ( val > buff[x].val ) R = update( R, val, amount );

	buff[idx] = (node){ buff[x].val, L, R, buff[x].size + amount };

	return idx;
}

int query( int x, int val ) {
	if ( val < buff[x].val )
		return query( buff[x].L, val ) + buff[x].size -	buff[ buff[x].L ].size;

	if ( val > buff[x].val )
		return query( buff[x].R, val );

	return buff[x].size - buff[ buff[x].L ].size;
}

int main() {

	scanf( "%d", &N );
	scanf( "%d", &Q );
	tree[0] = build( 1, N );
	for ( int i = 1; i <= N; i++ ) {
		int x, posx;
		scanf( "%d", &x ); posx = pos[x];
		if ( posx != 0 )
			tree[i] = update( update( tree[i - 1], posx, -1 ), i, +1 );
		else
			tree[i] = update( tree[i - 1], i, +1 );
		pos[x] = i;
	}
	while ( Q-- ) {
		int lo, hi;
		scanf( "%d %d", &lo, &hi );
		printf( "%d\n", query( tree[hi], lo ) );
	}

	return 0;
}


Measured memory_bytes: 293844
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
namespace Atcoder_0404
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = GetInput_int()[0];
            if (input == 0)
            {
                Console.WriteLine("1");
            }
            else
            {
                Console.WriteLine("0");
            }
        }
        #region input


        static string[] GetInput_string()
        {
            var input = Console.ReadLine().Split(' ');
            return input;
        }

        static int[] GetInput_int()
        {
            var input = GetInput_string();
            var result = new int[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = int.Parse(input[i]);
            }
            return result;
        }
        static long[] GetInput_long()
        {
            var input = GetInput_string();
            var result = new long[input.Length];
            for (int i = 0; i < result.Length; i++)
            {
                result[i] = long.Parse(input[i]);
            }
            return result;
        }
        #endregion
        #region sonota
        static void Swap_array<T>(T[] target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        static void Swap_list<T>(List<T> target, int a, int b)
        {
            T temp = target[a];
            target[a] = target[b];
            target[b] = temp;
        }
        /// <summary>
        /// 最大公約数
        /// </summary>
        public static int GCD(int a, int b)
        {

            /* 自然数 a > b を確認・入替 */
            if (a < b)
            {
                int tmp = a;
                a = b;
                b = tmp;
            }

            /* ユークリッドの互除法 */
            int r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return b;
        }
        public static long GCD(long a, long b)
        {

            /* 自然数 a > b を確認・入替 */
            if (a < b)
            {
                long tmp = a;
                a = b;
                b = tmp;
            }

            /* ユークリッドの互除法 */
            long r = a % b;
            while (r != 0)
            {
                a = b;
                b = r;
                r = a % b;
            }
            return b;
        }

        /// <summary>
        /// 最小公倍数
        /// </summary>
        public static int LCM(int a, int b)
        {
            int x = a * b;
            b = GCD(a, b);
            return x / b;

        }
        #endregion
        
    }
}

Measured memory_bytes: 27436
no_of_lines = 2
lines = ""
for i in range(no_of_lines):
    lines+=input()+"\n"

lines = lines.splitlines()
n = int(lines[0])
str = lines[1].split()
s = str[0]
t = str[1]

new_str = ""
for i in range(n):
    new_str += s[i] + t[i]

print(new_str)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a, b;
  int flag;
  cin >> a >> b;
  if( a < 0 && b < 0 ) {
    if( (b - a) % 2 == 0 ) flag = 0;
    else flag = 1;
  }
  else if( a <= 0 ) {
    flag = 2;
  } else {
    flag = 1;
  }
  if( flag == 0 ) cout << "Negative" << endl;
  if( flag == 1 ) cout << "Positive" << endl;
  if( flag == 2 ) cout << "Zero" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <stack>
#include <utility>
#include <queue>
#include <set>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long int lld;
typedef pair<int, int> pii;

const int MAXN = 100002;

int n, m;

int parent[MAXN];
int raiz(int nodo) {
  if(!parent[nodo]) return nodo;
  return parent[nodo] = raiz(parent[nodo]);
}

int outdegree[MAXN];
vector<int> adj[MAXN];

void dirige(int u, int p) {
  for (int v : adj[u]) {
    if (v == p) continue;
    dirige(v, u);
  }
  if (p == -1) return;
  if (outdegree[u] & 1) {
    cout << u << " " << p << "\n";
    outdegree[u]++;
  } else {
    cout << p << " " << u << "\n";
    outdegree[p]++;
  }
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  if (m & 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (raiz(a) == raiz(b)) {
      // Ya están unidos
      cout << a << " " << b << "\n";
      outdegree[a]++;
    } else {
      parent[raiz(a)] = raiz(b);
      adj[a].push_back(b);
      adj[b].push_back(a);
    }
  }
  dirige(1, -1);
  return 0;
}

Measured memory_bytes: 11648
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
#define endl "\n"
#define fcout cout<<fixed<<setprecision(15)
typedef pair<int, int> P;
//struct edge { int to, cost; };

int dx[8] = { 1,0,0,-1,1,1,-1,-1 };
int dy[8] = { 0,-1,1,0,-1,1,-1,1 };

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; }

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int modinv2(int a, int mod) {
    return mod_pow(a, mod - 2, mod);
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k, int mod) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= mod;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }
    return x * modinv(y, mod) % mod;
}

signed main() {
    //srand((unsigned)time(NULL));

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

    int a, b, h, m;
    cin >> a >> b >> h >> m;
    int hm = h * 60 + m;
    double x = 0.5 * hm, y = 6 * m;
    double ang = abs(x - y);
    if (a >= b) swap(a, b);
    if (ang >= 180) ang = 360 - ang;
    //fcout << ang << endl;
    fcout << sqrt((b * cos(ang * M_PI / 180.0) - a) * (b * cos(ang * M_PI / 180.0) - a) + b * sin(ang * M_PI / 180.0) * b * sin(ang * M_PI / 180.0)) << endl;

    return 0;
}


Measured memory_bytes: 4080
d, g = [int(i) for i in input().split()]

score = 0
p = []
c = []
for i in range(d):
    p_tmp, c_tmp = [int(i) for i in input().split()]
    p.append(p_tmp)
    c.append(c_tmp)

num = []
for i in range(2**d):
    num_tmp = 0
    score = 0
    not_comp = []
    for j in range(d):
        if i >> j & 1:
            score += p[j] * 100 * (j+1) + c[j]
            num_tmp += p[j]
        else:
            not_comp.append(j)

    for j in not_comp[::-1]:
        for k in range(p[j]-1):
            if score < g:
                score += 100 * (j+1)
                num_tmp += 1
            else:
                break
        else:
            continue
        break
    if score >= g:
        num.append(num_tmp)

ans = min(num)
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#include <algorithm>

void helper(int& A, int& B)
{
    printf("%d\n", std::max(A * B, std::max(A - B, A + B)));
}

int main()
{
    int A, B;

    scanf("%d", &A);
    scanf("%d", &B);
    
    helper(A, B);

    return 0;
}

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

int main(){
    int n;cin>>n;
    vl a(n);rep(i,n)cin>>a.at(i); 
    vl b(n);
    rep(i,n){
        b.at(i)=a.at(i);
    }
      sort(b.begin(),b.end());

    rep(i,n){
        if(b.at(n-1)==a.at(i)){
            cout<<b.at(n-2)<<endl;
        }
        else{cout<<b.at(n-1)<<endl;}
    }

return 0;
}

Measured memory_bytes: 4736
// Contest: AtCoder Beginner Contest 157 (https://atcoder.jp/contests/abc157)
// Problem: C: Guess The Number (https://atcoder.jp/contests/abc157/tasks/abc157_c)


// region {{{ boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion }}}

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

    int n, m; cin >> n >> m;
    vpi r(m);
    trav(p, r) cin >> p.first >> p.second, p.first--;
    for (int i = 0; i < 10000; ++i) {
        string s = to_string(i);
        if (sz(s) != n)
            continue;
        bool b = true;
        for (auto p : r) {
            if (s[p.first] - '0' != p.second) {
                b = false;
                break;
            }
        }
        if (b) {
            cout << s << '\n';
            return 0;
        }
    }

    cout << -1 << '\n';
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  
  private static class Edge {
    int node;
    int weight;
    public Edge(int n, int w) {
      this.node = n;
      this.weight = w;
    }
  }
  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      Map<Integer, List<Edge>> graph = new HashMap<>();
      for(int i = 1; i <= n; i++)
        graph.put(i, new ArrayList<>());

      for(int i = 0; i < n - 1; i++) {
        int v = sc.nextInt();
        int u = sc.nextInt();
        int w = sc.nextInt();
        Edge edge1 = new Edge(u, w);
        Edge edge2 = new Edge(v, w);
        graph.get(v).add(edge1);
        graph.get(u).add(edge2);
      }
      int qCnt = sc.nextInt();
      int k = sc.nextInt();
      Map<Integer, Long> distMap = new HashMap<>();
      bfs(k, graph, distMap);
      for(int i = 0; i < qCnt; i++)
        System.out.println(distMap.get(sc.nextInt()) + distMap.get(sc.nextInt()));
  }

  private static void bfs(int k, Map<Integer, List<Edge>> graph, Map<Integer, Long> distMap) {
    Queue<Integer> queue = new LinkedList<>();
    queue.add(k);
    Set<Integer> visited = new HashSet<>();
    visited.add(k);

    distMap.put(k, 0L);
    while(!queue.isEmpty()) {
      int node = queue.poll();
      long dist = distMap.get(node);
      for(Edge e : graph.get(node)) {
        if(visited.contains(e.node)) continue;
        distMap.put(e.node, e.weight + dist);
        queue.offer(e.node);
        visited.add(e.node);
      }
    }
  }
}

Measured memory_bytes: 185944
using System;

namespace AtCoder.Abc
{
    public class QuestionA
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            string s = Console.ReadLine();
            string t = Console.ReadLine();

            Console.WriteLine(t.StartsWith(s)?"Yes":"No");

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 26168
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional> // std::function<void(int)>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 111111;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<pair<int,int>> v(n);
    for(int i=0;i<n;i++)cin>>v[i].second>>v[i].first;
    sort(All(v));
    bool done=true;
    int time=0;
    for(auto it:v){
        time+=it.second;
        if(time>it.first){
            done=false;
            break;
        }
    }
    if(done)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

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

int main(void){
   int a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
   int K;
   cin>>K;
   cout<<a[K-1]<<endl;
   return 0;
}


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

#ifdef DEBUG
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...)
#endif

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair

#define PQ(T) priority_queue<T>
#define RPQ(T) priority_queue<T,vector<T>,greater<T>>

template<class T> inline void amin(T & a, T const & b) { a = min(a, b); }
template<class T> inline void amax(T & a, T const & b) { a = max(a, b); }

inline ll square(ll x) { return x * x; }
// ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
inline ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }
template <typename T>
inline T mod(T a, T b) { return ((a % b) + b) % b; }


const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

ll solve(int N, string& s) {
    vi cnt(26, 0);
    rep(i,N){
        ++cnt[ s[i]-'a' ];
    }
    ll ans = 1;
    rep(i,26) {
        ans = MUL(ans, 1+cnt[i]);
    }
    return SUB(ans, 1);
}

int main() {
    int N; cin >> N;
    string s; cin >> s;
    cout << solve(N,s) << endl;
    return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdint>
#include <unordered_set>
#include <unordered_map>
using namespace std;
typedef long long i64;
typedef vector<int> ivec;
typedef vector<string> svec;

int main()
{
    int n;
    int inNum;
    char inCommand[20];
    list<int> ans;

    scanf("%d", &n);

    for (int i=0; i<n; i++){
        scanf("%s", inCommand);
        if (inCommand[0] == 'i'){
            scanf("%d", &inNum);
            ans.push_front(inNum);
        } else if (inCommand[6] == 'L'){
            ans.pop_back();
        } else if (inCommand[6] == 'F'){
            ans.pop_front();
        } else if (inCommand[0] == 'd'){
            scanf("%d", &inNum);
            for (list<int>::iterator it = ans.begin(); it != ans.end(); it++){
                if (*it == inNum){
                    ans.erase(it);
                    break;
                }
            }
        }

    }

    for (list<int>::iterator it = ans.begin(); it != ans.end(); it++){
        if (it != ans.begin()) printf(" ");
        printf("%d", *it);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 32360
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int cmp_upper(const void *a, const void *b)
{
	const char *x = a;
	const char *y = b;

	return (*x - *y);
}

int cmp_lowwer(const void *a, const void *b)
{
	const char *x = a;
	const char *y = b;

	return (*y - *x);
}

int main(void)
{
	char str[1028];
	char max[1028];
	char min[1028];
	int len;
	int n, i;

	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%s", str);
		len = strlen(str);
		
		strcpy(max, str);
		qsort(max, len, sizeof(char), cmp_lowwer);

		strcpy(min, str);
		qsort(min, len, sizeof(char), cmp_upper);

		printf("%d\n", atoi(max) - atoi(min));
	}

	return (0);
}

Measured memory_bytes: 616
memo = [0]*100
memo[0] = 2
memo[1] = 1
def lucas(n):
     if memo[n] != 0:
         return memo[n]
     else:
         memo[n] = lucas(n-1)+lucas(n-2)
         return memo[n] 
n = int(input().strip())
print(lucas(n))


Measured memory_bytes: 3064
import scala.io.StdIn._
object Main extends App {
  val Array(x, y) = readLine.split(" ").map(_.toInt)
  val Mod = 1000000007
  if (((x + y) % 3 != 0) || (x * 2 < y || y * 2 < x)) {
    println(0)
  } else {
    val n = (x + y) / 3
    val r = x - n
    println(nCr(n, r))
  }

  def nCr(n: Int, r: Int): BigInt = {
    val m = (n - r + 1 to n).foldLeft(1L){(z, l) => z * l % Mod}
    val BIMod = BigInt(Mod)
    (BigInt(2) to BigInt(r)).foldLeft(BigInt(m)){(z, l) => l.modInverse(BIMod) * z % Mod}
  }
}

Measured memory_bytes: 108940
n = int(input())
H = [int(i) for i in input().split()]

count = 0
for _ in range(100):
    flag = 1
    for i in range(n):
        if H[i] > 0:
            H[i] -= 1
            if flag:
                count += 1
                flag = 0
        else:
            flag = 1
            
print(count)

Measured memory_bytes: 3060
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define pb push_back
    #define sz size()
     
    using namespace std;
    using ll = long long int;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
    using Vl = vector<ll>;
     
const int MOD = 1e9 + 7;
const ll ZER = 0;

//最大公約数
ll gcd(ll a, ll b){
    if(a % b == 0)return b;
    else return gcd(b, a % b);
}

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n + 2);
    ll sum = 0;
    rep(i, n){
        cin >> a[i + 1];
    }
    a[0] = 0;
    a[n + 1] = 0;
    rep(i, n + 1){
        sum += abs(a[i + 1] - a[i]);
    }
    rep(i, n){
        ll res = sum + abs(a[i] - a[i + 2]) - abs(a[i + 1] - a[i]) - abs(a[i + 1] - a[i + 2]);
        cout << res << endl;
    }
}



Measured memory_bytes: 4052
(let ((lucas '(1 2))
      (n (read)))
  (defun lp ()
    (push (+ (first lucas) (second lucas)) lucas))
  (cond ((= 0 n) (princ 2))
        ((= 1 n) (princ 1))
        (t (loop :repeat (1- n) do(lp)) (princ (first lucas)))))

Measured memory_bytes: 4072
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
int n;
vector<vector<int>> adj;
int f(int s)
{
    int i = 0;
    while(!(s & (1 << i))) 
    {
        i++;
    }
    return i;
}
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    adj.assign(n, vector<int>(n, 0));
    F0R(i, n)
    {
        F0R(j, n)
        {
            if(i == j) continue;
            adj[i][j] = f((i + 1) ^ (j + 1)) + 1;
        }
    }
    F0R(i, n)
    {
        FOR(j, i + 1, n) cout << adj[i][j] << " ";
        cout << "\n";
    }
    return 0;
}

Measured memory_bytes: 1536
import java.util.Scanner;

public class Main{
  public static void main(String[] args)
  {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int[] a = new int[n];
    int i;
    for(i=0; i<n;i++){
      a[i] = scanner.nextInt();
    }

    for(; i>0; i--){
                System.out.print(a[i-1]);
                if(i-1 != 0) System.out.print(" ");
                else System.out.println();
  }
}
}

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

map <string,int > m;
string str[120];
int main(){
int ma=0,n,i; string st;
scanf("%d",&n);
for(i=1;i<=n;i++){
	char s[100];
	scanf("%s",s);
	str[i]=s;
	m[ str[i] ]++;
}	
scanf("%d",&n);
for(i=1;i<=n;i++){
	char s[100];
	scanf("%s",s);
	st=s;
	m[st]--; 
	
}		
for(i=1;i<=n;i++){
	if(m[ str[i] ]>ma) ma= m [str[i]] ;
	
}		
printf("%d",ma);
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	double x1,y1,x2,y2,x3,y3,x4,y4;
	int n,i;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4);
		if((y1-y2)/(x1-x2)==(y3-y4)/(x3-x4)) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 620
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	string s;
	cin >> s;
	s = s.substr(0, 4) + " " + s.substr(4);
	cout << s << "\n";

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
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; }
const string MINUSINF = "-";
/*void chmax(string &a, string b) {
    if (a == MINUSINF) a = b;
    else if (a.size() < b.size()) a = b;
    else if (a.size() == b.size()) {
        if (a < b) a = b;
    }
}*/
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1001001001001001LL;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> a(N);
    for (int i = 0; i < N; ++i) {
        cin >> a[i];
    }
    vector<vector<ll>> dp(100, vector<ll>(2, -1));
    dp[0][0] = 0;

    for (int d = 0; d < 50; ++d) {
        ll mask = 1LL << (50 - d - 1);

        int num = 0;
        for (int i = 0; i < N; ++i) if (a[i] & mask) ++num;

        ll cost0 = mask * num;
        ll cost1 = mask * (N - num);

        if (dp[d][1] != -1) {
            chmax(dp[d + 1][1], dp[d][1] + max(cost0, cost1));
        }

        if (dp[d][0] != -1) {
            if (K&mask) chmax(dp[d + 1][1], dp[d][0] + cost0);
        }

        if (dp[d][0] != -1) {
            if (K&mask) chmax(dp[d + 1][0], dp[d][0] + cost1);
            else chmax(dp[d + 1][0], dp[d][0] + cost0);
        }
    }
    cout << max(dp[50][0], dp[50][1]) << endl;
    return 0;
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
N = int(input())
A = sorted([int(input()) for _ in range(N)])
ans = 0
if N%2 == 0:
    B = []
    for i in range(N//2)[::-1]:
        if i%2:
            B.append(-i-1)
        else:
            B.append(i)
    for i in range(N//2):
        if i%2:
            B.append(i)
        else:
            B.append(-i-1)
    S = [A[b] for b in B]
    for i in range(N-1):
        ans += abs(S[i+1] - S[i])
else:
    M = N//2
    B = list(range(1, M+2))[::-1] + list(range(1, M+1))
    S = []
    for i, b in enumerate(B):
        if i%2:
            S.append(A[-b])
        else:
            S.append(A[b-1])
    for i in range(N-1):
        ans += abs(S[i+1] - S[i])

    S = []
    for i, b in enumerate(B):
        if i%2:
            S.append(A[b-1])
        else:
            S.append(A[-b])
    tmp = 0
    for i in range(N-1):
        tmp += abs(S[i+1] - S[i])
    ans = max(ans, tmp)
print(ans)

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

int Partition(vector<int> &A, int p, int r)
{
	int x = A[r];
	int i = p-1;
	for(int j = p; j < r; j++){
		if(A[j] <= x){
			i++;
			swap(A[i], A[j]);
		}
	}
	swap(A[i+1], A[r]);
	return i+1;
}

void OutputWithSpace(int C){
	cout << C << ' ';
}
void OutputWithEndl(int C){
	cout << C << endl;
}
void OutputWithSpaceAndBracket(int C){
	cout << '[' << C << "] ";
}
void OutputWithSpaceAndEndl(int C){
	cout << '[' << C << ']' << endl;
}

int main()
{
	int n;
	cin >> n;
	vector<int> A(n);
	for(int i = 0; i < n; i++){
		cin >> A[i];
	}
	int q = Partition(A, 0, n-1);
	for(int i = 0; i < n; i++){
		if(i != q && i != n-1){
			cout << A[i] << ' ';
		}else if(i == q && i != n-1){
			cout << '[' << A[i] << "] ";
		}else if(i != q && i == n-1){
			cout << A[i] << endl;
		}else{
			cout << '[' << A[i] << ']' << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
ll f[2009],ans=0;
ll pow1(ll a,int b)
{
    ll res=1;
    while(b)
    {
        if(b%2)
            res=res*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return res;
}
int main()
{
    int s;
    ll ans=0;
    cin>>s;
    f[0]=1;
    for(int i=1;i<=s;i++)
        f[i]=f[i-1]*i%mod;
    for(int i=1;i<=s/3;i++)
    {
        ans=(ans+f[s-2*i-1]*pow1(f[i-1],mod-2)%mod*pow1(f[s-3*i],mod-2))%mod;
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 3748
#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

/*
前後の移動の符号が同じ時には変わりません。
異なるときには小さい方の 2 倍だけ省略できます。
*/

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n; std::cin >> n;
  std::vector<lint> a(n); std::cin>>a;
  a.emplace_back(0);
  std::adjacent_difference(all(a), a.begin());
  debug(a);

  lint sum = 0;
  for (lint x : a) {
    if (x < 0) x = -x;
    sum += x;
  }
  debug(sum);

  std::vector<lint> ans;
  rep(i,0,n) {
    lint x = a.at(i);
    lint y = a.at(i+1);
    if (0 < x*y) {
      ans.emplace_back(sum);
      continue;
    }
    if (x < 0) x = -x;
    if (y < 0) y = -y;
    debug(x,y);
    ans.emplace_back(sum - std::min(x,y) * 2);
  }

  for (int x : ans) {
    std::cout << x << std::endl;
  }
  return 0;
}

Measured memory_bytes: 3952
#include<stdio.h>

int main(void){
  int s1[5],s2[5];
  int sum,max,max_i;

  while(1){
    sum=0;
    max=0;
    for(int i=0;i<5;i++){
      scanf("%d %d",&s1[i],&s2[i]);
      if(s1[0]==0 && s2[0]==0) break;//
      sum=s1[i]+s2[i];
      if(max<sum){ max=sum; max_i=i; }
    }
    if(s1[0]==0 && s2[0]==0) break;//
    printf("%c %d\n",'A'+max_i,max);
  }

  return 0;
}



Measured memory_bytes: 1920
#include <cstdio>
#include <algorithm>

int main() {

	int a[6];
	int i;
	int ans = 0;

	for (i = 0; i < 4; ++i) scanf("%d",&a[i]);

	std::sort(a, a + 4);
	ans += a[3] + a[2] + a[1];

	scanf("%d%d", &a[4], &a[5]);
	a[4] >= a[5] ? ans += a[4] : ans += a[5];

	printf("%d\n", ans);
	return 0;
}


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

using namespace std;

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

  sort(begin(p), end(p));
  int ans = accumulate(begin(p), end(p), 0);
  cout << ans - p[N - 1] / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(void){
    int N, fir=0, fir_i=0, sec=0, sec_i=0;
    std::cin >> N;
    for (int i=0; i<N; ++i){
        int tmp;
        std::cin >> tmp;
        if (tmp > fir){
            sec = fir;
            sec_i = fir_i;
            fir = tmp;
            fir_i = i;
        } else if (tmp > sec){
            sec = tmp;
            sec_i = i;
        }
    }

    for (int i=0; i<N; ++i){
        if (i != fir_i){
            std::cout << fir << std::endl;
        } else {
            std::cout << sec << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3596
def main() :
    N, K    = list(map(int, input().split()))
    sunukes = []
    for itr in range(N) :
        #お菓子もち・・・True
        sunukes.append(False)
    itr = 0

    for itr in range(K) :
        d = int(input())
        A = list(map(int, input().split()))
        for inner_itr in range(d) :
            sunukes[A[inner_itr] - 1] = True
        A = None
    
    count = 0
    for itr in range(N) :
        if sunukes[itr] == False :
            count+=1
    
    print(count)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 9140
n = int(input())
book = [[0] * 9 for i in range(9)]

ans = 0

for i in range(1, n+1) :
    reverse = 0
    tmp = i
    time = 0
    flag = False
    end = -1
    while(tmp!=0) :
        remind = tmp % 10
        if time == 0 :
            if remind == 0 :
                flag = True
                break
            pre = remind
        tmp = tmp // 10
        time += 1
    if flag == True :
        continue
    if remind != 0 :
        book[remind-1][pre-1] += 1

for i in range(9) :
    for j in range(i, 9) :
        if i == j :
            ans += book[i][j] * book[j][i]
            #print('=', i, j, book[i][j] * book[j][i])
            continue
        if book[i][j] != 0 and book[j][i] != 0 :
            ans += book[i][j] * book[j][i] * 2
            #print('!', i, j, book[i][j] * book[j][i] * 2)

#for i in range(9) :
#    print(book[i])

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int N,X,Y;
int ans[2005];
void get(int i,int j){
    int d1=j-i;
    int d2=abs(X-i)+1+abs(Y-j);
    ans[min(d1,d2)]++;
}
int main() {
    cin>>N>>X>>Y;
    for(int i=1;i<N;i++){
        for(int j=i+1;j<=N;j++){
            get(i,j);
        }
    }
    for(int i=1;i<N;i++){
        cout<<ans[i]<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


#define CNT_MAX 300000
int main(void) {
    int num;
    cin >> num;
    vector<int> arr(num+1);
    for(int i = 1; i <= num; i++) {
        int val;
        cin >> val;
        arr[i] = val;
    }

    int cnt = -1;
    int cur = 1;
    for(int k = 1; k <= CNT_MAX; k++) {
        cur = arr[cur];
        if(cur == 2) {
            cnt = k;
            break;
        }
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){
int N;
cin >> N;
if(N / 100 == 7){
    cout << "Yes" << endl;
}
else if((N / 10) % 10 == 7){
    cout << "Yes" << endl;
}
else if(N % 10 == 7){
    cout << "Yes" << endl;
}
else{cout << "No" << endl;}
}

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

int main(){
    int h,n;
    cin >> h >> n;
    int a[n],b[n];
    int s = 0;
    int t = 1;
    int index = -1;
    for(int i=0; i<n; i++){
        cin >> a[i] >> b[i];
    }
    int dp[h+1];
    fill(dp,dp+h+1,1000000000);
    dp[0] = 0;
    for(int i=1; i<h+1; i++){
        for(int j=0; j<n; j++){
            if(i-a[j] < 0) dp[i] = min(b[j],dp[i]);
            else dp[i] = min(dp[i-a[j]]+b[j],dp[i]);
        }
    }
    cout << dp[h] << endl;
    return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<int> cnt(N + 1, 0);
  cnt.at(0) = 3;
  ll ans = 1;
  rep(i, N)
  {
    int a;
    cin >> a;
    a++;
    ans = (ans * (cnt.at(a - 1) - cnt.at(a))) % MOD;
    cnt.at(a)++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 640