akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N, Q;
//=============Segment_Tree_with_Lazy_Propagation====
const int MAX_N = 1 << 18;//要変更 2 * 10 ^ 5
int n;
vector<ll> dat1, lazy1, dat2, lazy2;//要変更

void init(ll n_) {
  n = 1;
  while (n < n_) {
    n *= 2;
  }
}

void eval(ll k, ll l, ll r, vector<ll>& lazy, vector<ll>& dat) {
  if (lazy.at(k) != INF) {
    dat.at(k) = min(lazy.at(k), dat.at(k));//要変更
    if (r - l > 1) {
      lazy.at(k * 2 + 1) = min(lazy.at(k * 2 + 1), lazy.at(k));//要変更
      lazy.at(k * 2 + 2) = min(lazy.at(k * 2 + 2), lazy.at(k));//要変更
    }
    lazy.at(k) = INF;
  }
}

void update(ll a, ll b, ll plus, vector<ll>& lazy, vector<ll>& dat, ll k = 0, ll l = 0, ll r = n) {
  if (r <= a || b <= l) {
    eval(k, l, r, lazy, dat);//子供のlazyを更新する必要がある
    return;
  }
  if (a <= l && r <= b) {
    lazy.at(k) = min(lazy.at(k), plus);//要変更
    eval(k, l, r, lazy, dat);//子供のlazyを更新する必要がある
  }
  else {
    eval(k, l, r, lazy, dat);//updateで使う子供のlazeとdat.at(k)の更新
    update(a, b, plus, lazy, dat, k * 2 + 1, l, (l + r) / 2);
    update(a, b, plus, lazy, dat, k * 2 + 2, (l + r) / 2, r);
    dat.at(k) = min(dat.at(2 * k + 1), dat.at(2 * k + 2));//要変更
  }
}

ll query(ll a, ll b, vector<ll>& lazy, vector<ll>& dat, ll k = 0, ll l = 0, ll r = n) {
  if (r <= a || b <= l) {
    return INF;//要変更
  }
  eval(k, l, r, lazy, dat);//dat.at(k)と子供のlazy更新のためreturn datとqueryに必要
  if (a <= l && r <= b) {
    return dat.at(k);
  }
  else {
    ll vl = query(a, b, lazy, dat, k * 2 + 1, l, (l + r) / 2);
    ll vr = query(a, b, lazy, dat, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);//要変更
  }
}
//=================================================


int main() {
  cin >> N >> Q;
  init(N);
  dat1 = vector<ll>(2 * MAX_N - 1, N - 2);//要変更
  lazy1 = vector<ll>(2 * MAX_N - 1, INF);//要変更
  dat2 = vector<ll>(2 * MAX_N - 1, N - 2);//要変更
  lazy2 = vector<ll>(2 * MAX_N - 1, INF);//要変更
  //dat1 = x, dat2 = y
  ll ans = (N - 2) * (N - 2);
  for (ll i = 0; i < Q; ++i) {
    ll q, x;
    cin >> q >> x;
    if (q == 1) {
      ll y = query(x, x + 1, dat1, lazy1);
      update(2, y + 2, x - 2, dat2, lazy2);
      // cout << "y" << y << "\n";
      ans -= y;
    }
    else {
      ll x1 = query(x, x + 1, dat2, lazy2);
      // cout << "x1" << x1 << "\n";
      update(2, x1 + 2, x - 2, dat1, lazy1);
      ans -= x1;
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 19592
#include <stdio.h>
int main (void)
{
  char b;
  
  scanf("%c",&b);
  
  if(b=='A')
    puts("T");
  else if(b=='T')
  	puts("A");
  else if(b=='G')
    puts("C");
  else
    puts("G");
  
  return 0;
}

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

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

    string S;
    cin >> S;

    int a1 = 0;
    int a2 = 0;
    for(int i = 0; i < N; ++i){
        if(S[i] == '('){
            ++a1;
        }
        else {
            if(a1 > 0){
                --a1;
            }
            else {
                ++a2;
            }
        }
    }
    cout << string(a2, '(') << S << string(a1, ')') << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/dp/tasks/dp_a

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

using namespace std;

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

    int h[n], dp[n];
    rep(i, n) cin >> h[i];

    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; ++i) {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }

    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int arr[5005],nxt[5005],vis[5005]={};
	int n,k;
	cin >> n >> k;
	for(int i=1;i<=n;i++)
		cin >> nxt[i];
	for(int i=1;i<=n;i++)
		cin >> arr[i];
		
	long long ans = -1000000000;
	for(int i=1;i<=n;i++) {
		int j = i;
		while(vis[j] != i) {
			vis[j] = i;
			j = nxt[j];
		}
		int st = j , k2 = k;
		j = i;
		long long sum = 0;
		for(int t=0;;t++) {
			if(j == st || t == k) {
				k2 -= t;
				break;
			}
			j = nxt[j];
			sum += arr[j];
			ans = max(ans, sum);
		}
		if(k2 > 0) {
			j = st;
			long long cyc_sum = 0;
			int cyc_len = 0;
			while(vis[j] == i) {
				vis[j] = -1;
				j = nxt[j];
				cyc_sum += arr[j];
				cyc_len++;
			}
			long long tmp = 0;
			for(int t=1;t<=min(k2,cyc_len);t++) {
				j = nxt[j];
				tmp += arr[j];
				long long now = sum + tmp;
				if(cyc_sum > 0)
					now += cyc_sum * ((k2 - t) / cyc_len);
				ans = max(ans, now);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3708
#include<iostream>
int i,v[2][5];main(){float a;for(;std::cin>>a;) v[i^=1][(a<0.2)+(a<0.6)+(a<1.1)+1]++;for(;i++<4;)printf("%d %d\n",v[1][i],v[0][i]);return 0;}

Measured memory_bytes: 0
#input
N = int(input())
A = list(map(int, input().split()))

#output
from collections import  Counter
L = Counter(A)

original_answer = 0
for v in L.values():
    original_answer += ( v * (v-1) )// 2

for i in range(N):
    print(original_answer - (L[A[i]]*(L[A[i]]-1))//2 + ((L[A[i]]-1)*(L[A[i]]-2))//2)

Measured memory_bytes: 24748
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cstdio>

#define rg register
#define il inline
#define MX (200000 + 233)
#define LL long long

int head[MX] ,tot;
struct edge{
	int node ,next;
}h[MX << 1];
void addedge(int u ,int v ,int flg = true){
	h[++tot] = (edge){v ,head[u]} ,head[u] = tot;
	if(flg) addedge(v ,u ,false);
}

struct node{
	int l ,r;
	LL sum ,add;
	node *lch ,*rch;
}*root;
void pushup(node *x){
	x->sum = 0;
	if(x->lch != nullptr) x->sum += x->lch->sum;
	if(x->rch != nullptr) x->sum += x->rch->sum;
}

void doadd(node *x ,LL v){
	x->sum += (x->r - x->l + 1) * v;
	x->add += v;
}
void pushdown(node *x){
	if(x->add){
		doadd(x->lch ,x->add);
		doadd(x->rch ,x->add);
		x->add = 0;
	}
}

node *newnode(int l ,int r){
	node *x = new node;
	x->l = l ,x->r = r ,x->sum = x->add = 0;
	return x;
}

void spread(node *x){
	int mid = (x->l + x->r) >> 1;
	if(x->lch == nullptr){
		x->lch = newnode(x->l ,mid);
		x->rch = newnode(mid + 1 ,x->r);
	}
}

int query(node *x ,int p){
	if(x->l == x->r) return x->sum;
	spread(x) ,pushdown(x);
	int mid = (x->l + x->r) >> 1;
	if(p <= mid) return query(x->lch ,p);
	return query(x->rch ,p);
}

void cov(node *x ,int p ,int v){
	if(x->l == x->r){x->sum = v; return;}
	spread(x) ,pushdown(x);
	int mid = (x->l + x->r) >> 1;
	if(p <= mid) cov(x->lch ,p ,v);
	else cov(x->rch ,p ,v);
	return pushup(x);
}

node *merge(node *x ,node *y){
	if(x == nullptr)	return y;
	if(y == nullptr)	return x;
	if(x->l == x->r){
		return x->sum += y->sum ,x;
	}
	x->add += y->add;
	x->lch = merge(x->lch ,y->lch);
	x->rch = merge(x->rch ,y->rch);
	return pushup(x) ,x;
}

int n;
LL cnt(LL a){
	return a * (a - 1) / 2 + a;
}
int c[MX]; LL Ans[MX];
node *solve(int x ,int f){
	node *now = newnode(1 ,n);
	for(int i = head[x] ,d ; i ; i = h[i].next){
		if((d = h[i].node) == f) continue;
		merge(now ,solve(d ,x));
		LL qwq = query(now ,c[x]);
		Ans[c[x]] -= cnt(qwq);
		cov(now ,c[x] ,0);
	}
	now->add += 1;
	cov(now ,c[x] ,0);
	return now;
}

int main(){
	scanf("%d" ,&n);
	for(int i = 1 ; i <= n ; ++i){
		scanf("%d" ,c + i);
		Ans[i] = cnt(n);
	}
	for(int i = 1 ,u ,v ; i < n ; ++i){
		scanf("%d%d" ,&u ,&v);
		addedge(u ,v);
	}
	root = solve(1 ,0);
	for(int i = 1 ; i <= n ; ++i){
		Ans[i] -= cnt(query(root ,i));
		printf("%lld\n" ,Ans[i]);
	}
	return 0;
}


Measured memory_bytes: 375476
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> as;
  for (int i = 0; i < N; ++i) {
    int ai;
    cin >> ai;
    as.push_back(ai);
  }

  int ans = *min_element(as.begin(), as.end());
  for (int i = 0; i < N; ++i) {
    int num = as[i];
    while (num % ans != 0) {
      int tmp = ans;
      ans = num % ans;
      num = tmp;
    }
  }

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

Measured memory_bytes: 892
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    string S;
    cin >> S;

    int* nums = new int[4];
    for(int i=0; i <4; ++i) {
        nums[i] = S[i] - '0';
    }

    for(int operator_seq = 0; operator_seq < (1<<3); operator_seq++) {
        int ans = nums[0];
        for (int dig = 0; dig < 3; ++dig) {

            // op_seq = b001
            // op1 = -
            // op2 = +
            // op3 = +

            if ((operator_seq>>dig)&1) { 
                ans -= nums[dig+1];
            } else {
                ans += nums[dig+1];
            }
        }

        if (ans == 7) {

            cout << nums[0];
            for(int i = 0; i < 3; ++i) {
                cout << ((operator_seq>>i)&1? '-':'+') << nums[i+1] ;
            }
            cout << "=7" << endl;
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int L[]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1};
int main(){
	int a;
	scanf("%d",&a);
	while(a--){
		int b,c;
		scanf("%d%d",&b,&c);
		int at=0;
		int dist=99999999;
		for(int i=0;i<15;i++){
			if(L[i]==b){
				int now=i;
				int t=0;
				while(L[now]!=c){
					now++;
					now%=15;
					t++;
				}
				if(t<dist){
					dist=t;
					at=i;
				}
			}
		}
		int now=at;
		while(1){
			if(now!=at)printf(" ");
			printf("%d",L[now]);
			if(L[now]==c)break;
			now++;
			now%=15;
		}
		printf("\n");
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<bitset>
#include<cstring>
using namespace std;
int n,a[2010],sum;
bitset<4000010> f[2];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
	}
	f[0][0]=1;
	for(int i=1,v=1;i<=n;i++,v^=1)
		f[v]=f[v^1]|(f[v^1]<<a[i]);
//	for(int i=0;i<=10;i++)
//		cout<<f[n&1][i];
//	cout<<endl;		
	for(int i=(sum+1)/2;i<=sum;i++)
		if(f[n&1][i]) {printf("%d",i);return 0;}	
	return 0;
}

Measured memory_bytes: 2688
n,a,b,c=map(int,input().split())
l=[int(input()) for i in range(n)]
choice=[]
for i in range(4**n):
    now=i
    cho=[]
    for j in range(n):
        cho.append(now%4)
        now//=4
    choice.append(cho)
ans=10**10
def calc(xl,x):
    if len(xl)==0:return  10**10
    cost=10*(len(xl)-1)
    cost+=abs(x-sum(xl))
    return cost
for x in choice:
    al=[]
    bl=[]
    cl=[]
    for i in range(len(x)):
        if x[i]==1:
            al.append(l[i])
        elif x[i]==2:
            bl.append(l[i])
        elif x[i]==3:
            cl.append(l[i])
    now=calc(al,a)+calc(bl,b)+calc(cl,c)
    if now<ans:ans=now
print(ans)

Measured memory_bytes: 14836
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Map;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int n = Integer.parseInt(br.readLine());
        String s;
        Map<String, Integer> map = new TreeMap<>();
        int max = 0;
        for (int i = 0; i < n; i++) {
            s = br.readLine();
            int val = map.containsKey(s) ? map.get(s) + 1 : 1;
            map.put(s, val);
            max = Math.max(max, val);
        }

        br.close();
        
        final int mx = max;
        map.forEach((key, val) -> {
            try {
                if (val == mx) {
                    bw.write(key + "\n");
                }
            } catch (Exception e) {
            }
        });

        bw.flush();

    }
}

Measured memory_bytes: 70220
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    ll n;
    cin >> n;
    vector<ll> a(2);
    priority_queue<vector<ll>, vector<vector<ll> >, greater<vector<ll> > > q;
    rep1(i, n){
        cin >> a[1] >> a[0];
        q.push(a);
    }
    ll cnt = 0;
    while (!q.empty()){
        auto now = q.top(); q.pop();
        if (cnt + now[1] > now[0]){
            cout << "No" << endl;
            return 0;
        }
        cnt += now[1];
    }
    cout << "Yes" << endl;
    //printf("%.12f", ans);
}

Measured memory_bytes: 14260
n = int(input())
x = 0
y = 0
t = 0
a = 0
def trav(a,b,c,d,e,f):
    if abs(a-b) + abs(c-d) <= e - f and ((a-b) % 2 + (c-d) % 2)%2 == (e-f) % 2:
        return 0
    else:
        return 1
for i in range(n):
    tn,xn,yn = map(int,input().split())
    if trav(xn,x,yn,y,tn,t) == 0:
        x = xn
        y = yn
        t = tn
    else:
        a = 1
if a == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
signed main(){
    int h,r;
    cin>>h>>r;
    if(h<0){
        if(h+r==0){
            cout<<"0"<<"\n";
        }else if(h+r<0){
            cout<<"-1"<<"\n";
        }
    }else{
        cout<<"1"<<"\n";
    }
    return(0);
}


Measured memory_bytes: 3108
uses crt;
var a,b,c:array[1..100000] of longint;
    i,n:longint;
function max(a,b:longint):longint;
begin
    if a>b then exit(a) else exit(b);
end;
begin
    clrscr;
    readln(n);
    for i := 1 to n do readln(a[i],b[i],c[i]);
    for i:=2 to n do 
      begin
          a[i]:=max(a[i-1],max(b[i-1],c[i-1])+a[i]);
          b[i]:=max(b[i-1],max(a[i-1],c[i-1])+b[i]);
          c[i]:=max(c[i-1],max(a[i-1],b[i-1])+c[i]);
      end;
      writeln(max(a[n],max(c[n],b[n])));
      readln;
end.

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

int main() {
  
  ll n;
  cin >> n;
  
  vector<ll> bipa(n);
  rep(i,n) cin >> bipa[i];
  
  sort(bipa.begin(), bipa.end());
  
  bool ans = true;
  
  rep(i,n-1) {
    if (bipa.at(i) == bipa.at(i+1)) {
      ans = false;
      break;
    }
  }
  
  cout << (ans ? "YES" : "NO") << endl;
  
  
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod=998244353;
ll tree[200005];
vector<pair<ll,ll> > w;
ll n,k;

void update(ll i,ll val)
{
   for(;i<=n;i+=(i&-i))
   tree[i]=(tree[i]%mod+val%mod)%mod;
}


void add(ll i,ll j,ll val)
{
   update(i,val);
   update(j+1,-val);
}

ll sum(ll i)
{
   ll s=0;
   for(;i>0;i-=(i&-i))
   s=(s%mod+tree[i]%mod)%mod;
   
   return s;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);

ll x,y;

cin>>n>>k;
for(ll i=0;i<k;i++)
{
  cin>>x>>y;
  w.push_back({x,y});
}

sort(w.begin(),w.end());

memset(tree,0,sizeof(tree));


tree[1]=1;

ll val;

for(int i=1;i<n;i++)
{
   val=sum(i)%mod;
   
   for(int j=0;j<k;j++)
   {
    if(i+w[j].first>n)
    break;
    
    add(i+w[j].first,min(n,i+w[j].second),val);
   }
   
}

cout<<(sum(n)+mod)%mod<<endl;

return 0;
}



Measured memory_bytes: 5180
using System;
using System.Linq;

namespace ABC172
{
    class C
    {
        static void Main(string[] args)
        {
            // var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            var NMK = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var B = Console.ReadLine().Split().Select(long.Parse).ToArray();

            var N = NMK[0]; var M = NMK[1]; var K = NMK[2];

            var Acs = new long[N + 1];
            for (int i = 0; i < N; i++)
            {
                Acs[i + 1] = A[i] + Acs[i];
            }
            var Bcs = new long[M + 1];
            for (int i = 0; i < M; i++)
            {
                Bcs[i + 1] = B[i] + Bcs[i];
            }

            var max = 0;
            var tmpmax = 0;
            for (int i = 0; i < N + 1; i++)
            {
                if (K < Acs[i]) continue;
                tmpmax = i;
                var tmp = K - Acs[i];
                if (0 <= Array.BinarySearch(Bcs, tmp))
                {
                    tmpmax += Array.BinarySearch(Bcs, tmp);
                }
                else
                {
                    tmpmax += ~Array.BinarySearch(Bcs, tmp) - 1;
                }
                max = Math.Max(max, tmpmax);
            }
            Console.WriteLine(max);
        }
    }
}


Measured memory_bytes: 73448
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}


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

  int n;
  cin>>n;
  priority_queue<int,vi,greater<int>> plus;
  priority_queue<int> minus;

  vector<P> res;

  rep(i,n){
    int a;
    cin>>a;
    if(a>0) plus.push(a);
    else minus.push(a);
  }

  if(minus.empty()){
    int s=plus.top(); plus.pop();
    int t=plus.top(); plus.pop();
    if(n==2){
      cout<<t-s<<endl;
      cout<<t<<' '<<s<<endl;
      return 0;
    }
    res.PB(P(t,s));
    minus.push(t-s);
  }

  if(plus.empty()){
    int s=minus.top(); minus.pop();
    int t=minus.top(); minus.pop();
    if(n==2){
      cout<<t-s<<endl;
      cout<<t<<' '<<s<<endl;
      return 0;
    }
    res.PB(P(t,s));
    plus.push(t-s);
  }

  while(plus.size()>1){
    int s=plus.top(); plus.pop();
    int t=minus.top(); minus.pop();
    res.PB(P(t,s));
    minus.push(t-s);
  }

  int ans=plus.top();

  while(minus.size()){
    int s=minus.top(); minus.pop();
    res.PB(P(ans,s));
    ans-=s;
  }

  cout<<ans<<endl;
  for(P p:res){
    cout<<p.F<<' '<<p.S<<endl;
  }

}

Measured memory_bytes: 5104
// cities to vapori-
// corner cases // int vs ll // cin vs scanf // clear structures // statement // doublesz // math is your friend
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define sz(x) int(x.size())
#define fill(x,v) memset(x,v,sizeof(x))
#define REP(i,a,b) for(int i = int(a); i < int(b); ++i)
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){
	
	fastio;
	string cad;
	cin >> cad;
	bool ok = true;
	for(int i = 0; i < sz(cad); i += 2){
		ok = ok && (i+1<sz(cad) && cad[i] == 'h' && cad[i+1] == 'i');
	}
	cout << (ok ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
using namespace std;
const int maxn = 1e5+10;
int n;
long long save[maxn];
long long eat[maxn];
bool check(int pos){
    int i,j;
    long long now = save[pos];
    for(i=1;i<=n;i++){
        if(i==pos){
            continue;
        }
        if(save[i]<=now*2){
            now += save[i];
        }
        if(now*2>=save[n]){
            return true;
        }
        if(save[i]>now*2){
            return false;
        }
    }
    return true;
}
int main(){
    scanf("%d",&n);
    int i,j;
    eat[0] = 0;
    for(i=1;i<=n;i++){
        scanf("%lld",&save[i]);
        eat[i] = eat[i-1]+save[i];
    }
    sort(save+1, save+1+n);
    int left = 1,right = n;
    while(right-left>1){
        int middle = (left+right)/2;
        if(check(middle)){
            right = middle;
        }else{
            left = middle;
        }
    }
    int res = right;
    if(check(left)){
        res = left;
    }
    cout<<n-res+1<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>

int gcd(int a, int b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
int main()
{
    int a,b;
    scanf("%d %d",&a,&b);
    printf("%d\n",gcd(a,b));
    return 0;
    
}


Measured memory_bytes: 2140
n, x = map(int, input().split())
m = []
min = 1001
cnt = 0
for i in range(n):
    m.append(int(input()))

for i in m: # 1コずつ作る
    if min > i:
        min = i
    x -= i
    cnt += 1

print(cnt + int(x/min))


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <sstream>      // std::ostringstream
std::vector<std::string> split(const std::string &str, char sep)
{
    std::vector<std::string> v;
    std::stringstream ss(str);
    std::string buffer;
    while( std::getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

using namespace std;

int main(void){
  string s = "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;
  vector<string> v;
  v = split(s,',');
  if(K==1){
    cout << v[K-1] << endl;
  }else{
    v[K-1].erase(v[K-1].begin());
    cout << v[K-1] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef string str;
typedef std::pair<ll,ll> pl;
typedef std::map<str, ll> msl;
typedef std::map<char, ll> mcl;
typedef std::map<ll, ll> mll;
typedef std::vector<ll> vl;
const long double EPS = 1e-9;

#define rep(i, n) for(ll (i) = 0; (i) < (n) ; (i)++ )
#define For(i, a, b) for(ll (i) = (a); (i) < (b) ; (i)++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define tol(c) char((c)+0x20)
#define tou(c) char((c)-0x20)
#define pb push_back
#define mp make_pair
#define pr(a) cout << (a)
#define prl(a) cout << (a) << endl
#define prs(a) cout << (a) << " "
#define yn(condition) if ((condition)) prl("Yes"); else prl("No");
#define YN(condition) if ((condition)) prl("YES"); else prl("NO");
#define rpr(i,n,ans) rep((i),(n)) prs((ans[(i)]))
#define cpr(i,n,ans) rep((i),(n)) prl((ans[(i)]))
#define in1(a) cin >> (a)
#define in2(a,b) cin >> (a) >> (b)
#define in3(a,b,c) cin >> (a) >> (b) >> (c)
#define in4(a,b,c,d) cin >> (a) >> (b) >> (c) >> (d)
#define rin1(i,n,a) rep((i),(n)) cin >> (a[(i)])
#define rin2(i,n,a,b) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)])
#define rin3(i,n,a,b,c) rep((i),(n)) cin >> (a[(i)]) >> (b[(i)]) >> (c[(i)])
#define e1 first
#define e2 second
#define ctol(c) ll((c)) - ll('0')
#define ltos(n) to_string((n))
#define items(kv, v) for(auto &(kv): (v))
#define ndig(N, n) ctol(ll(ltos((N))[ll(ltos((N)).length()) - (n)]))

const ll mod = 1e9 + 7;
const ll INF = mod * mod;
const ll MAX_N = 100;

int main(void){
    ll n,x;
    ll m[MAX_N];
    ll mm = INF;

    in2(n,x);
    ll answer = n;
    rin1(i,n,m);
    rep(i,n) x -= m[i];
    rep(i,n) mm = min(mm,m[i]);
    
    prl(answer+x/mm);

    return 0;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    S = input().rstrip()

    ans = 0
    for i in range(1, N):
        X, Y = S[:i], S[i:]
        x = set(X)
        y = set(Y)
        num = len(x & y)
        if num > ans:
            ans = num

    print(ans)


if __name__ == "__main__":
    main()


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

#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)

#define X first
#define Y second

template<typename T>bool maxup(T& a, T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T& b) { if (a > b) { a = b; return true; }; }

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

struct BIT {
	int N;
	V v;
	BIT(int n) : N(n + 1), v(n + 1) {}
	void add(int idx, int x) {
		for (int i = idx + 1; i < N; i += i & -i) v[i] += x;
	}
	int sum(int idx) {
		int sum = 0;
		for (int i = idx + 1; i > 0; i -= i & -i) sum += v[i];
		return sum;
	}
};

signed main() {
	int n, m; cin >> n >> m;
	using T = tuple<int, int, int>;
	vector<T> v(n);
	rep(i, n) {
		int l, r; cin >> l >> r;
		v[i] = T(r - l + 1, l, r);
	}
	sort(all(v));
	V anses(m);
	BIT bit(m + 2);
	int pre = 0;
	rep(d, 1, m + 1) {
		int num = lower_bound(all(v), T(d, 0, 0)) - v.begin();
		anses[d - 1] = n - num;
		rep(i, pre, num) {
			int l, r;
			tie(ignore, l, r) = v[i];
			bit.add(l, 1);
			bit.add(r + 1, -1);
		}
		for (int i = 0; i <= m; i += d) {
			anses[d - 1] += bit.sum(i);
		}
		pre = num;
	}

	for (int x : anses) cout << x << endl;

	system("pause");
}

Measured memory_bytes: 9720
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a, b = LI()
    if (a * b) % 2:
        print("Yes")
    else:
        print("No")
    return

#B
def B():
    n = II()
    w = SR(n)
    d = []
    for i in w:
        d.append("".join(i))
    if len(set(d)) != n:
        print("No")
        return
    for i in range(n - 1):
        if w[i][-1] != w[i + 1][0]:
            print("No")
            return
    print("Yes")
    return

#C
def C():
    def gcd(a, b):
        a, b = max(a, b), min(a, b)
        while b:
            a, b = b, a % b
        return a
    n, x = LI()
    xn = LI()+[x]
    xn.sort()
    ans = xn[1] - xn[0]
    for i in range(1, n):
        ans = gcd(ans, xn[i + 1] - xn[i])
    print(ans)
    return

#D
def D():
    return

#Solve
if __name__ == '__main__':
    C()


Measured memory_bytes: 59248
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt()
  val uft = new UnionFindTree(n)

  for (_ <- 1 to m) {
    val a, b = sc.nextInt() - 1
    uft.unite(a, b)
  }

  val ans = (0 until n).map(uft.size).max
  println(ans)
}

class UnionFindTree(n: Int) {
  private val par = Array.tabulate(n)(identity)
  private val rank = Array.fill(n)(1)
  private val size0 = Array.fill(n)(1)

  def root(x: Int): Int = {
    var res = x
    var children = List[Int]()
    while (par(res) != res) {
      children ::= res
      res = par(res)
    }

    for (y <- children) {
      par(y) = res
    }
    res
  }

  def unite(x: Int, y: Int): Unit = {
    val xr = root(x)
    val yr = root(y)
    if (xr != yr) {
      if (rank(xr) < rank(yr)) {
        par(xr) = yr
        size0(yr) += size0(xr)
      } else {
        par(yr) = xr
        size0(xr) += size0(yr)
        if (rank(xr) == rank(yr)) {
          rank(xr) += 1
        }
      }
    }
  }

  def size(x: Int): Int = size0(root(x))
}


Measured memory_bytes: 65088
#include <bits/stdc++.h>
      
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define YYS(x,arr) for(auto& x:arr)
#define PW(x) (1LL<<(x))
#define SZ(x) ((ll)(x).size())

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

using namespace std;

using ld = long double;
using ll = long long int;

const ll INF = (ll)1e9 + 10;
const ll INFLL = (ll)1e18 + 10;
const ll MOD = 1e9+7;
     
template<class T> T &chmin( T &a , const T &b ){ return a = min(a,b); }
template<class T> T &chmax( T &a , const T &b ){ return a = max(a,b); }
template<class T> void UNIQUE(vector<T> &a){ a.erase(unique(a.begin(), a.end()), a.end()); }

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

ll in(){long long int x; scanf("%lld", &x); return x;}
ld fin(){double x; scanf("%lf", &x); return x;}
char yuyushiki[1000010]; string stin(){scanf( "%s", yuyushiki ); return yuyushiki;}

// head

int main(){
  
  ll m = in();
  string s = stin();

  ll ans = 0;
  
  REP(mask, PW(m)){
    string a = "";
    string b = "";
    REP(i, m){
      if(mask & PW(i)){
        a += s[i];
      } else {
        b += s[i];
      }
    }
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());
    vector<vector<ll>> dp(m+1, vector<ll>(SZ(a) + 1, 0));
    dp[0][0] = 1;
    REP(i, m){
      REP(j, min(i+1, SZ(a)+1)){
        int k = i - j;
        if(j < SZ(a) && s[m+i] == a[j]){
          dp[i+1][j+1] += dp[i][j];
        }
        if(k < SZ(b) && s[m+i] == b[k]){
          dp[i+1][j] += dp[i][j];
        }
      }
    }
    ans += dp[m][SZ(a)];
    /*
    cout << mask << " " << dp[m][SZ(a)] << endl;
    cout << a << endl;
    cout << b << endl;
    cout << dp << endl;
    */
  }

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

Measured memory_bytes: 256
# 入力
N = int(input())
A = list(map(int, input().split()))

# 上限を決める
NowNode = 2**0
NextNode = (NowNode - A[0])*2
UpperLimit = [0] * (N+1)
UpperLimit[0] = 1
if A[0] == 1:
    if N == 0:
        print(1)
        exit()
    print(-1)
    exit()
for d in range(1, N+1, 1):
    NowNode = NextNode
    NextNode = (NowNode - A[d]) * 2
    UpperLimit[d] = NowNode
# print(UpperLimit)
UpperLimit[-1] = min(A[-1], UpperLimit[-1])
# 下から見ていく
NowNode = A[-1]
ans = 0

for d in range(N, -1, -1):
    PrevNode = NowNode
    if UpperLimit[d] < A[d]:
        print(-1)
        exit()
    if NowNode + A[d] <= UpperLimit[d]:
        NowNode += A[d]
    else:
        NowNode = UpperLimit[d]
    ans += NowNode
    # print(d, NowNode)
print(ans)


Measured memory_bytes: 674364
#include <iostream>
#include <math.h>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
    int n;
    int *x;
    int *y;

    cin >> n;                       // データ数
    if (n >= 1 && n <= 100) {
        try {
           x = new int[n];
           y = new int[n];

           for (int i = 0; i < n; i++) {
               cin >> x[i];
           }

           for (int i = 0; i < n; i++) {
               cin >> y[i];
           }
        }
        catch (...) {
             return -1;
        }

        double d1;
        double d2;
        double d3;
        double d4;
        double tmp;

        d1 = d2 = d3 = d4 = 0;
    
        for (int i = 0; i < n; i++) {
            tmp = abs(x[i] - y[i]);

            d1 += tmp;                      // p = 1 マンハッタン距離

            d2 += tmp * tmp; 
        
            d3 += (tmp * tmp * tmp);         // p=3

            if (d4 < tmp) d4 = tmp;         // p = ∞
        }

        tmp = d3;                           // Debug

        d2 = sqrt(d2);
        d3 = pow(d3, 1.0/3.0);
   
        delete [] x;
        delete [] y;

        cout << showpoint << setprecision(11) << d1 << endl;
        cout << showpoint << setprecision(11) << d2 << endl;
        cout << showpoint << setprecision(11) << d3 << endl;
        cout << showpoint << setprecision(11) << d4 << endl;
     }

    return 0;
}


Measured memory_bytes: 3456
#include "bits/stdc++.h"
#include <chrono> 
 
using namespace std;
using namespace std::chrono; 
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
#define gcd(a,b) __gcd(a,b)
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define pb(n) push_back(n)
#define pp pop_back()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define type(a) typeid(a).name();
#define print(arr) cout << "[" ;for(unsigned int i=0;i<(unsigned int) arr.size();i++){ (i==arr.size()-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define Arr(arr,l) cout << "[" ;for(unsigned int i=0;i<(unsigned int) l;i++){ (i==l-1)?cout << arr[i]:cout << arr[i] << ",";}cout << "]" << endl
#define console(arr) cout << "["<<endl; for(ll i=0;i<(ll)arr.size();++i){cout << " [";for(ll j=0;j<(ll)arr[i].size();++j){(j==(int)arr[i].size()-1)?cout << arr[i][j]:cout << arr[i][j] << ",";}cout << "]"<<endl;} cout << "]"<<endl
#define starting() auto start = high_resolution_clock::now()
#define ending() auto stop = high_resolution_clock::now();auto duration = duration_cast<microseconds>(stop - start);cout << endl << endl << "Execution Time : "<<duration.count()/1000 << " ms" << endl
 
template <typename T1,typename T2>
void mapped(map<T1,T2>m){for(auto ite=m.begin();ite!=m.end();++ite){cout << "'" << ite->first << "'"<<" : "<<ite->second <<endl;}}
 
template <typename T1 , typename T2>
void mappedArr(map<T1,vector<T2>>m){for(auto ity=m.begin();ity!=m.end();++ity){cout << "'"<< ity->first <<"'"<<" : "<<"[";
for(int i=0;i<(int)ity->second.size();++i){(i==(int)ity->second.size()-1)?cout << ity->second[i]:cout << ity->second[i] << ",";}cout << "]"<<endl;}}
 
string int_to_string(int x){ stringstream ss; ss << x; string ni = ss.str(); return ni;}
int char_to_int(char c){ int n = (int)c - 48; return n; }
int string_to_int(string x){ int n; stringstream s(x); s >> n; return n; }
char upperCase(char a){int d = (int)a - 97 + 65;char c = (char)d;return c;} 
char lowerCase(char a){int d = (int)a - 65 + 97;char c = (char)d;return c;}  
bool isInt(char a){int d = (int)a - 48;if(d>=0 && d<=9){return true;}return false;}
//string char_to_string(char a){string d = (1,a);return d;}
 
template <typename T1,typename T2>
void ArrPair(vector<pair<T1,T2>>vp){for(int i=0;i<(int)vp.size();++i){
cout << "(" << vp[i].first << "," << vp[i].second << ")"<<endl ;}}
 
const int MOD = 1e9 + 7;
const ll INF = 1e18L + 5;
 
unordered_map<int,int> um;
unordered_set<int> us;
set<int> s;
// v.front() gives the first element of vector 
// v.back()  gives the last element of vector
// insert erase substr

//bool bySecond(pair<int,int> a,pair<int,int> b){
//  return a.second < b.second;
//} 

bool f(vector<ll> a,vector<ll> b){
	return a[1] > b[1];
}

 
 
int main(){
 int x ,y;
 cin >> x >> y;
 int v[4] = {0,300000,200000,100000};
 int summed = 0;
 if(x<=3){
	 summed += v[x];
 }
 if(y<=3){
	 summed += v[y];
 }
 if(x==1 && y==1){
	 summed += 400000;
 }
 cout << summed;
 
}







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

typedef long long ll;
typedef vector<ll> vl;      typedef vector<int> vi;
typedef vector<vl> vvl;     typedef vector<vi> vvi;
typedef pair<ll, ll> pll;   typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF ll(1e18)
#ifdef SHUBHAM107
#include "../trace.h"
#else
#define trace(args...)
#endif

void solve() {
    int n;
    string s;
    cin >> n >> s;

    int l = 0, r = n - 1, cost = 0;
    while (l < r) {
        if (s[l] == 'R')
            l++;
        else if (s[r] == 'W')
            r--;
        else {
            cost++;
            l++, r--;
        }
    }

    cout << cost;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef SHUBHAM107
    freopen("inp.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("err.txt", "w", stderr);
#endif
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
}


Measured memory_bytes: 3724
#include <stdio.h>

int main(){
  int t;
  scanf("%d", &t);
  int h,m,s;
  s = t % 60;
  m = ((t-s) / 60) % 60;
  h = (t-s-60*m) / 60 / 60;
  printf("%d:%d:%d\n", h,m,s);
}


Measured memory_bytes: 2736
#include <stdio.h>
#include <inttypes.h>

int main(void)
{
    size_t n;
    scanf("%zu", &n);
    char s[n];
    scanf("%s", s);
    int_fast8_t m = 0;
    int_fast8_t max = 0;
    for (size_t i = 0; i < n; ++i) {
        (s[i] == 'I') ? ++m : --m;
        if (max < m) {
            max = m;
        }
    }
    printf("%" PRIdFAST8 "\n", max);

    return 0;
}


Measured memory_bytes: 128
H, W = map(int,input().split())
a = []
for i in range(H):
  a1 = input()
  if "#" in a1:
    a.append(a1)

b = []
for i in range(W):
  for j in range(len(a)):
    if a[j][i] == "#":
      break
  else:
      b.append(i)

for i in range(len(a)):
  ans = ""
  for j in range(W):
    if not j in b:
      ans += a[i][j]
  print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

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

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	int k;
	cin>>k;
	long long res = 0;
	for(int i=1;i<=k;i++)for(int j=1;j<=k;j++)for(int l =1;l<=k;l++)res+=gcd(gcd(i,j),l);
	cout<<res<<endl;
	
	return 0;
}

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<map>
#include<set>
#include<bitset>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//Library
/*Union-Find木
int par[1000010], rankh[1000010];
void init(int n) {
	for (int i = 0; i <= n; i++) {
		par[i] = i;
		rankh[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x)return x;
	else return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rankh[x] < rankh[y])par[x] = y;
	else {
		par[y] = x;
		if (rankh[x] == rankh[y])rankh[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
template<typename t>
t GCD(t a, t b) {
	while (max(a, b) % min(a, b)) {
		if (a > b)a %= b;
		else b %= a;
	}
	return min(a, b);
}
Union-Find木end*/
//Library end
struct cake { ll x; ll y; ll z; };
int n, m;
ll cnt, ans;
cake a[1010];
ll f[1010];
int main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++)cin >> a[i].x >> a[i].y >> a[i].z;
	for (int i = 0; i < n; i++)f[i] = a[i].x + a[i].y + a[i].z;
	sort(f, f + n);
	for (int i = n - 1; i > n - 1 - m; i--)cnt += f[i];
	ans = max(ans, cnt);
	cnt = 0;
	for (int i = 0; i < n; i++)f[i] = a[i].x + a[i].y - a[i].z;
	sort(f, f + n);
	for (int i = n - 1; i > n - 1 - m; i--)cnt += f[i];
	ans = max(ans, cnt);
	cnt = 0;
	for (int i = 0; i < n; i++)f[i] = a[i].x - a[i].y + a[i].z;
	sort(f, f + n);
	for (int i = n - 1; i > n - 1 - m; i--)cnt += f[i];
	ans = max(ans, cnt);
	cnt = 0;
	for (int i = 0; i < n; i++)f[i] = a[i].x - a[i].y - a[i].z;
	sort(f, f + n);
	for (int i = n - 1; i > n - 1 - m; i--)cnt += f[i];
	ans = max(ans, cnt);
	cnt = 0;
	for (int i = 0; i < n; i++)f[i] = -a[i].x + a[i].y + a[i].z;
	sort(f, f + n);
	for (int i = n - 1; i > n - 1 - m; i--)cnt += f[i];
	ans = max(ans, cnt);
	cnt = 0;
	for (int i = 0; i < n; i++)f[i] = -a[i].x + a[i].y - a[i].z;
	sort(f, f + n);
	for (int i = n - 1; i > n - 1 - m; i--)cnt += f[i];
	ans = max(ans, cnt);
	cnt = 0;
	for (int i = 0; i < n; i++)f[i] = -a[i].x - a[i].y + a[i].z;
	sort(f, f + n);
	for (int i = n - 1; i > n - 1 - m; i--)cnt += f[i];
	ans = max(ans, cnt);
	cnt = 0;
	for (int i = 0; i < n; i++)f[i] = -a[i].x - a[i].y - a[i].z;
	sort(f, f + n);
	for (int i = n - 1; i > n - 1 - m; i--)cnt += f[i];
	ans = max(ans, cnt);
	cnt = 0;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import bisect
A, B, Q = map(int, input().split())
S = list(int(input()) for _ in range(A)) 
T = list(int(input()) for _ in range(B))


for _ in range(Q):
    x = int(input())
    s = bisect.bisect_right(S, x)
    t = bisect.bisect_right(T, x)
    s %= A
    t %= B
    ans = 2*10**10
    for i in range(2):
        for j in range(2):
            ans = min(ans, min(abs(x-S[s-i])+abs(S[s-i]-T[t-j]), abs(x-T[t-j])+abs(T[t-j]-S[s-i])))
    print(ans)


Measured memory_bytes: 90168
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

int main() {
    LL n, m;
    cin >> n >> m;
    vector<pair<LL, LL> > gates;
    rep(i, m) {
        LL l, r;
        cin >> l >> r;
        gates.push_back(make_pair(l, r));
    }
    LL max_left = 0;
    LL min_right = 1e9;
    rep(i, m) {
        auto lr = gates[i];
        max_left = max(max_left, lr.first);
        min_right = min(min_right, lr.second);
    }
    if (min_right - max_left + 1 >= 0) {
        cout << min_right - max_left + 1 << endl;
    } else {
        cout << 0 << endl;
    }

    return 0;
}


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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    if (A + B == C + D){
        cout << "Balanced" << endl;
    }
    else if (A + B > C + D){
        cout << "Left" << endl;
    }
    else if (A + B < C + D){
        cout << "Right" << endl;
    }
}


Measured memory_bytes: 256
/* 累積和に書き換え */
#include <iostream>
using namespace std;

int main(){
    int n;
    cin >> n;
    int a[3][n+1];
    int sum[3][n+1];
    for(int i = 1; i < 3; i++){for(int j = 1; j <= n; j++){ cin >> a[i][j]; } }
    for(int i = 1; i < 3; i++){
        for(int j = 0; j <= n; j++){
            if(j == 0) sum[i][j] = 0;
            else sum[i][j] = sum[i][j-1] + a[i][j];
        }
    }
    int max = 0;
    for(int i = 1; i <= n; i++){
        int num = sum[1][i] + sum[2][n] - sum[2][i-1];
        if(max < num) max = num;
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=998244353;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    vector<pair<int,int> > v;
    cin>>n;
    int a;
    for(int i=0;i<n;i++){
        cin>>a;
        v.pb(make_pair(a,i+1));
    }
    sort(be(v));
    for(int i=0;i<n;i++){
        cout << v[i].second<<" ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1780
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

int MOD_BIG = 1000000007;
int MOD_BIG2 = 998244353;
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using std::vector;

#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

//////////////////////////////////////

//////////////////////////////////////

int main() {
    
    int N;
    ll D;
    cin >> N >> D;
    int ans = 0;
    FOR(i, 0, N) {
        ll x, y;
        cin >> x >> y;
        if (x*x+y*y <= D*D) {
            ans++;
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int n,m=0,s=0;
cin >> n;
int a[n],b[n];
for(int i=0;i<n;i++){
    cin >> a[i];
    b[i] = a[i];
}
sort(b,b+n);
m=b[n-1];
s=b[n-2];
for(int i=0;i<n;i++){
    if(a[i]!=m){
        cout << m << endl;
    }
    else if(a[i]==m){
        cout << s << endl;
    }
}
////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 3200
n,m=map(int,input().split())
h=[]
p=[]
def man(a,c,b,d):
    s=abs(a-c)+abs(b-d)
    return s
for i in range(n):
    h.append(list(map(int,input().split())))
for j in range(m):
    p.append(list(map(int,input().split())))
for k in range(n):
    l=float("inf")
    for v in range(m):
        x=man(h[k][0],p[v][0],h[k][1],p[v][1])
        if x<l:
            l=x
            y=v+1
    print(y)

    



Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define fill fill_n
#define pb push_back
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int l;
	cin>>l;
	ld a,b,c;
	a=b=c=(ld)l/3;
	ld ans=a*b*c;
	cout<<fixed<<setprecision(12)<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 256