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

int main(){
  int n;
  cin >> n;
  int l[200];
  for(int i = 0; i < 2 * n; i++){
    cin >> l[i];
  }
  
  sort(l, l + 2 * n);
  
  int ans = 0;
  for(int i = 0; i < 2 * n; i += 2){
    ans += l[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,A,B=get_i
X=get_i
ans=0
(N-1).times do|i|
  ans+=min((X[i+1]-X[i])*A,B)
end
puts ans

Measured memory_bytes: 21788
import math

def gcd(x, y, z):
    ex = math.gcd(x, y)
    return math.gcd(ex, z)

def comb(x):
    num = len(set(x))
    if num == 1:
        return 1
    elif num == 2:
        return 3
    else:
        return 6

k = int(input())
ans = 0
for i in range(1, k + 1):
    for j in range(i, k + 1):
        for l in range(j, k + 1):
            g = gcd(i, j, l)
            ans += g * comb([i, j, l])
print(ans)

Measured memory_bytes: 9152
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
int main()
{
	long long A, B, C, D, GCD = 0, GMC = 0;
	scanf("%lld%lld%lld%lld", &A, &B, &C, &D);
	long long tmp = 0, tmpC, tmpD;
	tmpC = C; tmpD = D;
	if (C >= D) {
		while (tmpC % tmpD != 0) {
			tmp = tmpD;
			tmpD = tmpC % tmpD;
			tmpC = tmp;
		}
		GCD = tmpD;
	}
	else {
		while (tmpD % tmpC != 0) {
			tmp = tmpC;
			tmpC = tmpD % tmpC;
			tmpD = tmp;
		}
		GCD = tmpC;
	}
	GMC = C * D / GCD;
	long long countC, countD, countGMC;
	countC = B / C - (A - 1) / C;
	countD = B / D - (A - 1) / D;
	countGMC = B / GMC - (A - 1) / GMC;
	printf("%lld", (B - A + 1) - countC - countD + countGMC);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    int sum=1,k=0;
    int n=s.size();
    vector<int> vect(10);
    for(int i=0;i<n;i++){
        if(s.at(i)=='A'||
        s.at(i)=='C'||
        s.at(i)=='G'||
        s.at(i)=='T'){
            k++;
        }
    }
    if(k==0){
        goto exit;
    }
    if(s.size()==1){
        vect[9]=1;
        goto exit;

    }
 
    for(int i=0;i<n-1;i++){
        if((s.at(i)=='A'||
        s.at(i)=='C'||
        s.at(i)=='G'||
        s.at(i)=='T')&&(
        s.at(i+1)=='A'||
        s.at(i+1)=='C'||
        s.at(i+1)=='G'||
        s.at(i+1)=='T')){
            sum++;
            vect[i]=sum;
 
        }else{
            vect[i]=sum;
            sum=1;
        }
 
        
    }
    sort(vect.begin(),vect.end());
 
    
    exit:
 
    cout<<vect[9]<<endl;
 
 
 
 
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}



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

    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    if(n%2==0){
        ll dp[n+1]={};
        for(int i=0;i<=n;i++) dp[i]=-1e18;
        dp[0] = a[0];
        dp[1] = a[1];
        for(int i=2;i<n;i++){
            if(i%2){
                dp[i] = max(dp[i-2],dp[i-3])+a[i];
            }
            else{
                dp[i] = dp[i-2] + a[i];
            }
        }
        ll ans = max(dp[n-1],dp[n-2]);
        cout << ans << endl;
        return 0;
    }
    else{
        ll dp[n+1][2];
        for(int i=0;i<=n;i++){
            dp[i][0]=-1e18;
            dp[i][1]=-1e18;
        }
        dp[0][0] = a[0];
        dp[1][0] = a[1];
        for(int i=2;i<n;i++){
            dp[i][0] = dp[i-2][0] + a[i];
            if(i%2 && i>=3) chmax(dp[i][0],dp[i-3][0]+a[i]);
            if(i>=3){
                if(i==3) dp[i][1] = a[i];
                ll ret = dp[i-2][1];
                if(i%2==0) chmax(ret,dp[i-3][0]);
                if(i%2 && i>=4) chmax(ret,dp[i-4][0]);
                dp[i][1] = max(dp[i][1],ret + a[i]);
            }
            else dp[i][1] = a[i];
        }
        ll ans = max(dp[n-1][1],dp[n-2][0]);
        chmax(ans,dp[n-2][1]);
        if(n>=3) chmax(ans,dp[n-3][0]);
        cerr << dp[n-1][1] << " " << dp[n-2][0] << " " << dp[n-2][1] << " " << dp[n-3][0] << endl;
        cout << ans << endl;
    }


}

Measured memory_bytes: 8336
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int n;
    cin >> n;
    double x[100];
    string u[100];
    rep(i, n){
        cin >> x[i] >> u[i];
    }

    double sum_btc = 0, sum_jpy = 0;
    rep(i, n){
        if(u[i] == "JPY"){
            sum_jpy += x[i];
        }
        else{
            sum_btc += x[i];
        }
    }
    double ans = sum_jpy + 380000*sum_btc;
    cout << ans;


    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int point[5];
    int i,ave=0;
    for(i=0;i<5;i++){
	scanf("%d",&point[i]);
	if(point[i]<40){
	    point[i]=40;
	}
	ave += point[i];
    }
    ave= ave/5;
    printf("%d\n",ave);
    return 0;
}

Measured memory_bytes: 1028
program security
implicit none
character::S*4
integer::i,check
read(*,*)S
check=0
do i=1,3
	if(S(i:i)==S(i+1:i+1))then
    	check=check+1
    else
    	check=check
    end if
end do
if(check==0)then
write(*,*)'Good'
else
write(*,*)'Bad'
end if
end program security

Measured memory_bytes: 256
N = int(input())
S = input()
rs = []
gs = []
bs = []
for i,c in enumerate(S):
    if c=='R':
        rs.append(i)
    elif c=='G':
        gs.append(i)
    else:
        bs.append(i)
R,G,B = len(rs),len(gs),len(bs)
rt = set(rs)
gt = set(gs)
bt = set(bs)

ans = 0
ri = gi = bi = 0
for i in range(N):
    if ri < R and i==rs[ri]:
        ans += gi*(B-bi) + bi*(G-gi)
        for g in gs:
            if i+(i-g) in bt:
                ans -= 1
        ri += 1
    elif gi < G and i==gs[gi]:
        ans += ri*(B-bi) + bi*(R-ri)
        for r in rs:
            if i+(i-r) in bt:
                ans -= 1
        gi += 1
    else:
        ans += ri*(G-gi) + gi*(R-ri)
        for r in rs:
            if i+(i-r) in gt:
                ans -= 1
        bi += 1
print(ans)

Measured memory_bytes: 68480
n=int(input())

for i in range(1,n+1):
    x, y, z=map(int,input().split())
    if x*x==y*y+z*z or y*y==x*x+z*z or z*z==x*x+y*y:
        print("YES")
    else:
        print("NO")
        
    i =i+1


Measured memory_bytes: 5592
/*input
100 100 100
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vector<int> a(3);
    vector<int> d;
    for(int i = 0; i < 3; i++) cin >> a[i];
    for(int i = 0; i < 3; i++) for(int j = i + 1; j < 3; j++) d.push_back(abs(a[i] - a[j]));
    sort(d.begin(), d.end());
	cout << d[0] + d[1];

    return 0;
}

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

int main(){

  string op="+-";
  char a, b, c, d;
  int x, y, z, w;

  cin>>a>>b>>c>>d;
  x=a-'0';
  y=b-'0';
  z=c-'0';
  w=d-'0';

  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      for(int k=0;k<2;k++){
        int sum=x;
        if(op[i]=='+') sum+=y;
        else sum-=y;
        if(op[j]=='+') sum+=z;
        else sum-=z;
        if(op[k]=='+') sum+=w;
        else sum-=w;
        if(sum==7){
          cout<<a<<op[i]<<b<<op[j]<<c<<op[k]<<d<<"=7"<<endl;
          return 0;
        }
      }
    }
  }


  return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input!(n: usize, a: [usize; n], b: [usize; n]);

    if let Some(ans) = solve(n, &a, &b) {
        println!("Yes");
        for a in ans {
            println!("{}", a)
        }
    } else {
        println!("No")
    }
}

fn solve(n: usize, a: &[usize], b: &[usize]) -> Option<Vec<usize>> {
    let mut d = 0;
    let b = [b; 2].concat();
    for i in 0..n {
        while i + d < n && a[i] >= b[i + d] {
            d += 1;
        }
        if a[i] == b[i + d] {
            return None;
        }
    }
    Some((&b[d..d + n]).into())
}


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

using namespace std;

int main()
{
    long n;
    string s;
    string arr[4]={"AC","WA","TLE","RE"};
    map<string,int>m;
    cin>>n;
    for(int i=0;i<n;i++){
    cin>>s;
    m[s]++;
    }
    for(int i=0;i<4;i++){
    cout<<arr[i]<<" x "<<m[arr[i]]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3628
H, W = map(int, input().split())
S = [list(input().split()) for i in range(H)]

h = w = 0
for i in range(H):
    if 'snuke' in S[i]:
        h = i
        w = S[i].index('snuke')
        break
print(chr(ord('A') + w) + str(h + 1))


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

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

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

  sort(A, A + N);

  int index = 0;
  while (x >= 0 && index < N) {
    x -= A[index];
    ++index;
  }

  if (x) {
    --index;
  }

  cout << index << endl;

  return 0;
}


Measured memory_bytes: 256
using namespace std;
#include <bits/stdc++.h>
#define ll long long int
#define rep(x,y,z) for(int x=y;x<z;x++)
int main(){
	ll n, k;
	cin>>n>>k;
	vector<ll> ht(n), cost(n, LLONG_MAX);
	rep(i,0,n){
		cin>>ht[i];
	}
	ll zero=0;
	cost[0]=0;
	for(ll i=1;i<n;i++){
		for(ll j=i-1;j>=max(i-k, zero); j--){
			cost[i]=min(cost[i], cost[j]+abs(ht[j]-ht[i]));
		}
	}
	cout<<cost[n-1]<<endl;
}

Measured memory_bytes: 1792
N, M = map(int, input().split())

MOD = int(1e9) + 7

tmp = abs(N - M)
if tmp >= 2:
    print(0)
else:
    ans = 2
    if tmp == 1:
        ans = 1
    for i in range(2, N+1):
        ans *= i
        ans = ans % MOD
    for i in range(2, M+1):
        ans *= i
        ans = ans % MOD
    print(ans)


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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N, K; cin >> N >> K;
    vector<int> x(N);
    int ans = 0;
    for(int i = 0; i < N; i++) {
        cin >> x[i];
        ans += 2 * (min(x[i], abs(x[i] - K)));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
use std::io;

fn main() {
    let target_vec: Vec<i64> = vec![
        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,
    ];

    let mut buffer = String::new();

    io::stdin().read_line(&mut buffer).unwrap();
    let index = buffer.trim().parse::<usize>().unwrap();
    println!("{}", target_vec[index - 1]);
}


Measured memory_bytes: 4476
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);


    if(a+b+c==17)
    {
        printf("YES\n");
    }
        
    else
    {
         printf("NO\n");
    }
       
    return 0;
}

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



int main(){
	int A[5];
	for(int i=0;i<5;i++){
		cin>>A[i];
	}
	int ans = 0;
	int maxi = 0;
	for(int i=0;i<5;i++){
		ans+=((A[i]+9)/10)*10;
		maxi=max(maxi,(10-(A[i]%10))%10);
	}
	
	ans-=maxi;
	cout<<ans<<endl;
	
	
	
	
	return 0;
}


Measured memory_bytes: 256
#include <deque>
#include <iostream>
#include <string>
#include <vector>

struct Candidate {
  int x;
  int y;
  int bCount;
};

int main(int argc, char *argv[]) {
  int h, w;
  std::cin >> h >> w;

  int ch, cw;
  std::cin >> ch >> cw;
  --ch;
  --cw;

  int dh, dw;
  std::cin >> dh >> dw;
  --dh;
  --dw;

  std::vector<std::string> s(h);
  for (int i = 0; i < h; ++i) {
    std::cin >> s[i];
  }

  std::vector<std::vector<int>> ans(w);
  for (int i = 0; i < w; ++i) {
    ans[i].resize(h);
    for (int j = 0; j < h; ++j) {
      ans[i][j] = -1;
    }
  }

  std::deque<Candidate> dq;
  int x = cw;
  int y = ch;
  int bCount = 0;
  while (true) {
    ans[x][y] = bCount;
    if (x == dw && y == dh) {
      break;
    }

    for (int i = -2; i <= 2; ++i) {
      int nx = x + i;
      if (nx < 0 || nx >= w) {
        continue;
      }
      for (int j = -2; j <= 2; ++j) {
        if (i == 0 && j == 0) {
          continue;
        }

        int ny = y + j;
        if (ny < 0 || ny >= h) {
          continue;
        }

        if (s[ny][nx] == '#') {
          continue;
        }

        if (ans[nx][ny] >= 0) {
          continue;
        }

        if ((i == 0 && std::abs(j) == 1) || (j == 0 && std::abs(i) == 1)) {
          dq.push_front({nx, ny, bCount});
        } else {
          dq.push_back({nx, ny, bCount + 1});
        }
      }
    }

    if (dq.empty()) {
      break;
    }
    auto candidate = dq.front();
    x = candidate.x;
    y = candidate.y;
    bCount = candidate.bCount;
    dq.pop_front();
  }

  std::cout << ans[dw][dh] << std::endl;

  return 0;
}

Measured memory_bytes: 9772
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int mod=1e9+7;
const int INF = LONG_LONG_MAX;
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int pow(int a,int n,int mod){if(n==0)return 1;int p=pow(a,n/2,mod);p=(p%mod*p%mod)%mod;if(n%2) return (p%mod*a%mod)%mod;else return p;}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    vector<int>a(n+1);
    vector<int>ans;
    set<int>s;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    ans.push_back(1);
    s.insert(1);
    int x=0;
    int j=0;
    int i=1;
    while(1)
    {
        int d=a[i];
        //cout<<i<<endl;
        if(s.find(d)!=s.end()){x=d;break;}
        ans.push_back(d);
        s.insert(d);
        i=d;
    }
    int cnt=0;
   // for(int i=0;i<ans.size();i++)
     //   cout<<ans[i]<<" ";
    //cout<<endl;
    for(int i=0;i<ans.size();i++)
    {
        if(ans[i]==x){j=i;break;}
        cnt++;
    }
    //cout<<cnt<<endl;
    if(k<cnt)
    {
       cout<<ans[k]<<endl;
       return 0;
    }
    k-=cnt;
    int sz=ans.size()-cnt;
    k=k%sz;
    //cout<<sz<<" "<<k<<endl;
    cout<<ans[k+j]<<endl;


    return 0;
}


Measured memory_bytes: 15468
#include <stdio.h>

int
main (
  )
{
  for ( ; ; )
  {
    int t, n;

    scanf ( "%d", &t );
    if ( t == 0 ) break ;

    scanf ( "%d", &n );
    while ( n-- )
    {
      int s, f;

      scanf ( "%d%d", &s, &f );
      t -= f - s;
    }

    if ( t > 0 )
    {
      printf ( "%d\n", t );
    }
    else
    {
      puts ( "OK" );
    }
  }

  return ( 0 );
}

Measured memory_bytes: 0
s = list(input())

n = len(s)

res = [0]*(n+1)

p = 0
q = 0

a = -1
b = -1
judge = -1

for i in range(n):
    if s[i] == 'R':
        res[b] += p
        res[a] += q
        p = 0
        q = 0
        judge = -1
    else:
        if p > 0:
            if judge > 0:
                p += 1
            else:
                q += 1
            judge *= -1
        else:
            p += 1
            b = i
            a = i-1

res[b] += p
res[a] += q


p = 0
q = 0

judge = -1
for i in range(n-1,-1,-1):
    if s[i] == 'L':
        res[a] += p
        res[b] += q
        p = 0
        q = 0
        judge = -1
    else:
        if p > 0:
            if judge > 0:
                p += 1
            else:
                q += 1
            judge *= -1
        else:
            p += 1
            b = i+1
            a = i
res[a] += p
res[b] += q

for i in range(n):
    print(res[i],end = ' ')

    

Measured memory_bytes: 55544
#include <bits/stdc++.h>
#include<list>
#include<algorithm>
#define ll long long int
#define ld long double
#define pb push_back
#define ff first
#define ss second
#define rep(a,b,c) for(a=b;a<c;a++)
#define repj(a,b,c) for(a=b;a<c;a++)
#define repr for(i=n-1;i>=0;i--)
#define pii pair<ll,ll>
#define pll pair<ll, ll>
#define inf 100000001
const double pie  =3.141592653589793238463;
#define mod 1000000007
#define lb lower_bound
#define up upper_bound
#define rep1 for(i=1;i<=n;i++)
#define vr vector
#define POP(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define ef else if
#define all(x) (x).begin(), (x).end()
#define SORT(A) sort(A.begin(),A.end());
#define REV(A) reverse(A.begin(), A.end());
#define lenth length()
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n" 
const ll dx[4] = { -1, 1, 0, 0};
const ll dy[4] = {0, 0, -1, 1};
ll XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
ll YY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };
#define precise(x) cout<<fixed<<setprecision(x)
#define t1(x)                cerr<<#x<<": "<<x<<endl
#define t2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define t4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define t5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define t6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
using namespace std;
void SieveOfEratosthenes(ll n) 
{ 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (ll i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // for (ll p=2; p<=n; p++) 
       // if (prime[p]) 
          // cout << p << " "; 
} 

ll power(ll x, ll y) 
{ 
    ll res = 1; 
    while (y > 0) 
    { 
        if (y & 1) 
            res = res * x; 
        y = y >> 1; 
        x = x * x; 
    } 
    return res; 
}
int main()
{
    fastio
    ll t,i,j,k,l,m,n,a,x,b,y,z,c,h,d,e,p,nl,np,q,r;
    string s;
    cin>>x>>n;
    ll arr[n];
    ll ans1,ans2;
    map<int,int>mp;
    rep(i,0,n)
    {
        cin>>arr[i];
        mp[arr[i]]++;
    }
    for(int i=x;i>=-100;i--)
    {
        if(mp[i]==0)
        {
            ans1=i;
            break;
        }
    }
    for(int i=x;i<=1000;i++)
    {
        if(mp[i]==0)
        {
            ans2=i;
            break;
        }
    }
    if(abs(x-ans1)<abs(x-ans2))
    {
        cout<<ans1<<endl;
    }
    else if(abs(x-ans1)==abs(x-ans2))
    {
        cout<<min(ans1,ans2)<<endl;
    }
    else
    {
        cout<<ans2<<endl;
    }

}

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

using namespace std;

int main() {
    int N;
    int M;
    cin >> N >> M;
    long long v[N][3];
    for (int i = 0; i < N; ++i) cin >> v[i][0] >> v[i][1] >> v[i][2];

    long long ans = 0;
    for (int bit = 0; bit < (1 << 3); ++bit) {
        long long tmp[N];
        for (int i = 0; i < N; ++i) {
            tmp[i] = 0;
            for (int j = 0; j < 3; ++j) {
                if (bit & (1 << j)) {
                    tmp[i] += v[i][j];
                } else {
                    tmp[i] -= v[i][j];
                }
            }
        }
        sort(tmp, tmp + N, greater<>());
        long long sum = 0;
        for (int i = 0; i < M; ++i) {
            sum += tmp[i];
        }
        ans = max(ans, sum);
    }
    cout  << ans << endl;
}

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

int main(){
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    pappu:
        if(a>0){
            c-=b;
        }
        else{
            cout<<"No";
            return 0;
        }
        if(c>0){
            a-=d;
        }
        else{
            cout<<"Yes";
            return 0;
        }
        goto pappu;
}


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

using namespace std;

int arr[1005][1005];
int r0[1005], r1[1005], c0[1005], c1[1005];

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
	int h, w, a, b;

	while (cin >> h >> w >> a >> b) {
		for (int i = 0;i < h;i++) {
			r0[i] = 0;
			r1[i] = 0;
		}
		for (int i = 0;i < w;i++) {
			c0[i] = 0;
			c1[i] = 0;
		}
		int ok = 1;
		for (int i = 0;i < h;i++) {
			for (int j = 0;j < w;j++) {
				if (r0[i] < w-a && c0[j] < h-b) {
					r0[i]++;
					c0[j]++;
					arr[i][j] = 0;
				}
				else if (r1[i] < w-a && c1[j] < h-b) {
					r1[i]++;
					c1[j]++;
					arr[i][j] = 1;
				}
				else {
					ok = 0;
					break;
				}
			}
		}
		if (ok) {
			for (int i = 0;i < h;i++) {
				for (int j = 0;j < w;j++) {
					cout << arr[i][j];
				}
				cout << endl;
			}
		}
		else {
			cout << -1 << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 5248
from collections import Counter
n=input()[::-1]

A=[]
num,point=0,1
for i in n:
    num +=int(i)*point
    num %=2019
    A.append(num)
    point *=10
    point %=2019

count=Counter(A)
ans=0
for i,j in count.items():
    if i==0:ans +=j*(j+1)//2
    else:ans +=j*(j-1)//2
print(ans)

Measured memory_bytes: 84200
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: C (GCC 5.4.1)
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

typedef struct{
	TLong x;
	TLong h;
} XH;

// fact(n)
int fact(int n){
	if(n == 1)	return 1;
	else return (n * fact(n - 1));
}

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

// lcm(a,b)
int lcm(int a,int b){
	return (a * b) / gcd(a,b);
}

// nCr(n,r) & utility
int nCrVal[5003][5003];

void nCrSetUp(int n){
	for(int i = 0; i <= n; ++i){
		for(int j = 0; j <= i / 2 + 1; ++j){
			if(j == 0)  nCrVal[i][j] = 1;
			else  nCrVal[i][j] = nCrVal[i - 1][j - 1] + nCrVal[i - 1][j];
			nCrVal[i][i - j] = nCrVal[i][j];
		}
	}
}

int nCr(int n, int r){
	if(nCrVal[n][r] == 0)	nCrSetUp(n + 1);
	return nCrVal[n][r];
}

// swap(&a, &b);
void swap(int *a,int *b){
	int tmp;
	tmp = *a;	*a = *b;	*b = tmp;
	return;
}

// qsort(array, size, sizeof(int),comp);
int ASC(const XH *a, const XH *b){
	return ((*a).x - (*b).x);
}

int DESC(const int *a,const int *b){
	return (*b - *a);
}

int main(int argc, char const *argv[])
{
	int n;
	int j, m, l = 1, r;
	TLong d,a;
	TLong ans = 0, psum[200003] = { 0 }, temp, t;
	XH xh[200003];

	scanf("%d%lld%lld", &n,&d,&a);
	for (int i = 1; i <= n; ++i)	scanf("%lld%lld", &xh[i].x, &xh[i].h);
	qsort(xh, n + 1, sizeof(XH), ASC);

	if(xh[n].x < d * 2) d = xh[n].x;
	else d *= 2;
	
	for (int i = 1; i <= n; ++i)
	{
		psum[i] += psum[i - 1];
		temp = xh[i].h - psum[i];
		if(temp > 0){
			t = (temp - 1) / a + 1;
			ans += t;
			t *= a;
			
			r = n + 1;
			while(l < r){
				m = (l + r) >> 1;
				if(xh[m].x <= xh[i].x + d)  l = m + 1;
				else r = m;
			}
			j = l - 1;

			psum[i] += t;
			psum[j + 1] -= t;
		}
	}

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


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

int main() {
  int n;
  cin >> n;
  vector<int> fr(0), ba(0);
  for(int i = 0; i < n; i++){
    int a;
    cin >> a;
    if(i % 2) ba.push_back(a);
    else fr.push_back(a);
  }
  
  if(n % 2){
    reverse(fr.begin(), fr.end());
    for(auto a : fr) cout << a << " ";
    for(auto a : ba) cout << a << " ";
  }
  else{
    reverse(ba.begin(), ba.end());
    for(auto a : ba) cout << a << " ";
    for(auto a : fr) cout << a << " ";
  }
  cout << endl;
}

Measured memory_bytes: 4320
#include <stdio.h>
#include <string.h>
 
int max(int a, int b) {
  return a > b ? a : b;
}
 
int main(void) {
  int i, ans = 0, j, n;
  char a[110], b[110];
  scanf("%d", &n);
  for(i = 0; i < n; ++i) {
    scanf("%s\n%s", a, b);
    if(strlen(a) > 80 || strlen(b) > 80) {
      printf("overflow\n");
      continue;
    }
    for(j = 0; j < strlen(a); ++j) a[j] -= '0' - 1;
    for(j = 0; j < strlen(b); ++j) b[j] -= '0' - 1;
    /*for(j = 0; j < strlen(a); ++j) printf("%d", (int)a[j] - 1);
    printf("\n");
    for(j = 0; j < strlen(b); ++j) printf("%d", (int)b[j] - 1);
    printf("\n");*/
    if(strlen(a) < strlen(b)) {
      char t[110];
      for(j = 0; j <= strlen(a); ++j) t[j] = a[j];
      for(j = 0; j <= strlen(b); ++j) a[j] = b[j];
      for(j = 0; j <= strlen(t); ++j) b[j] = t[j];
    }
    char t[110];
    int st = 0;
    for(j = 0; j <= strlen(b); ++j) t[j] = b[j];
    for(j = 0; j <= strlen(a); ++j) b[j] = 1;
    for(j = strlen(a) - strlen(t); j <= strlen(a); ++j) b[j] = t[j - strlen(a) + strlen(t)];
    /*for(j = 0; j < strlen(a); ++j) printf("%d", (int)a[j] - 1);
    printf("\n");
    for(j = 0; j < strlen(a); ++j) printf("%d", (int)b[j] - 1);
    printf("\n");*/
    for(j = strlen(a) - 1; j >= 0; --j) {
      a[j] = a[j] + b[j] - 1;
      if(a[j] >= 11) {
        if(j) {
          a[j - 1]++;
          a[j] -= 10;
        } else {
          st = 1;
          a[j] -= 10;
        }
      }
    }
    if(st) {
      if(strlen(a) == 80) {
        printf("overflow\n");
        continue;
      } else printf("1");
    }
    for(j = 0; j < strlen(a); ++j) printf("%d", (int)a[j] - 1);
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2584
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<stack>
#include<set>
#include<map>
#include<vector>
#define pi 3.1415926536
const int maxn = 1e5 + 5;
using namespace std;

int n,y;
bool flag;
int a,b;
int main()
{
	scanf("%d %d", &n, &y);
	a = y / 10000 + 1;
	b = y / 5000; 
	//printf("%d %d \n",a,b);
	for(int i = 0; i <= a; i++){
		for(int j = 0; j <= b; j++){
			if(10000 * i + 5000 * j + 1000 * (n - i - j) == y && (n - i - j) >= 0){
				flag = 1;
				printf("%d %d %d\n", i, j, n - i - j);
				break;
			}
		}
		if(flag) break;
	}
	if(!flag) printf("-1 -1 -1");
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, M: int, X: "List[int]"):
    x = sorted(X)
    x_dif = []
    for i in range(M-1):
        x_dif.append(x[i+1]-x[i])
    x_dif.sort(reverse=True)
    print(sum(x_dif[N-1:]))


    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 15796
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    class G {
        int x, y , t;
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int [][] a = new int[n + 1][3];
        for(int i = 1; i <= n; ++i) {
            a[i][0] = sc.nextInt();
            a[i][1] = sc.nextInt();
            a[i][2] = sc.nextInt();
        }
        a[0][0] = 0;
        a[0][1] = 0;
        a[0][2] = 0;
        boolean ok = true;
        for(int i = 1; i <= n; ++i) {
            int dt = a[i][0] - a[i - 1][0];
            int dx = Math.abs (a[i][1] - a[i - 1][1]);
            int dy = Math.abs (a[i][2] - a[i - 1][2]);
            if(dx + dy > dt || (dt - dx - dy) % 2 != 0) {
                ok = false;
                System.out.println("No");
                break;
            }
        }
        if(ok)
            System.out.println("Yes");
    }
}


Measured memory_bytes: 96840
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

const int maxn=3e5+1e2;
const int inf=0x3f3f3f3f;
int n;
int Ans=inf;
int sum1[maxn],sum2[maxn];
char s[maxn];

inline void file() {
	freopen("ARC098C.in","r",stdin);
	freopen("ARC098C.out","w",stdout);
}

int main() {
//	file();
	scanf("%d",&n);
	scanf("%s",s+1);
	For (i,1,n) {
		sum1[i]=sum1[i-1]; sum2[i]=sum2[i-1];
		if (s[i]=='W') ++sum1[i];
		if (s[i]=='E') ++sum2[i];
	}
	For (i,1,n)
		chkmin(Ans,sum1[i-1]+sum2[n]-sum2[i]);
	printf("%d",Ans);
	return 0;
}

Measured memory_bytes: 2944
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s=sc.next().toCharArray();
		long k=sc.nextLong();
		int i=0;
		while(i<s.length){
			if(s[i]=='1'){
				i++;
			}else{
				break;
			}
		}
		if(k<=i){
			System.out.println(1);
		}else{
			System.out.println(s[i]);
		}
		
	}
}

Measured memory_bytes: 23892
x, k, d = map(int, input().split())

x = abs(x)

cnt = x//d
amari = x%d

nokori = k-cnt

if nokori < 0:
  ans = x - d*k
else:
  if nokori%2 == 0:
    ans = amari - d + d
  else:
    ans = amari - d

print(abs(ans))

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

int main() {
 int r, g, b;
 cin >> r >> g >> b;
 
 int num=(r*100)+(g*10)+b;
 
 if(num%4==0){
     cout << "YES" << endl;
 }
 else{
     cout << "NO" << endl;
 }
 
}
  

Measured memory_bytes: 3548
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // fixed, setprecision 
#include <math.h> // double sqrt
#define rep(i,n) for(int i=0;i<(n);++i)
#define ll long long
using namespace std;

int main(){
    ll n,x;
    cin>>n>>x;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    ll c=0;
    sort(a.begin(),a.end());
    ll d=0;
    rep(i,n){
        d+=a[i];
        c++;
        if(d>x){cout<<c-1;return 0;}
        if(i==n-1&&d==x){cout<<c;return 0;}
        if(i==n-1&&d<x){cout<<c-1;return 0;}
        if(d==x){cout<<c;return 0;}
    
    }

}

Measured memory_bytes: 3156
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
bool minimize(T)(ref T x, T y) { if (x > y) { x = y; return true; } else { return false; } }
bool maximize(T)(ref T x, T y) { if (x < y) { x = y; return true; } else { return false; } }

long mod = 10^^9 + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto T = RD;
	auto t = RDR.ARR;
	long loss;
	foreach (i; 1..N)
	{
		loss += max(0, T - (t[i] - t[i-1]));
	}
	writeln(T * N - loss);
	stdout.flush();
}

Measured memory_bytes: 11608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=n-1;i>=(0);i--)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(int argc, char const *argv[])
{
	int d; cin >> d;
	if (d == 25) printf("Christmas\n");
	else if (d == 24) printf("Christmas Eve\n");
	else if (d == 23) printf("Christmas Eve Eve\n");
	else if (d == 22) printf("Christmas Eve Eve Eve\n");
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,m;
void solve()
{
    int ans1=0,ans2=0;
    if(n<1)
        ans1=0;
    else
        ans1=n*(n-1)/2;
    if(m<1)
        ans2=0;
    else
        ans2=m*(m-1)/2;
    cout<<ans1+ans2;
}
int main()
{
    cin>>n>>m;
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int x,y,z,ar[10000005],ans;
int main()
{
	scanf("%lld",&x);
	for(int i=1;i<=x*3;i++)
	{
		scanf("%lld",&ar[i]);
	}
	sort(ar+1,ar+1+(x*3));
	for(int i=((x*3)-1);i>x;i-=2)
	{
		ans+=ar[i];
	}
	printf("%lld",ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int M1, D1;
  cin>>M1>>D1;
  Int M2, D2;
  cin>>M2>>D2;

  if(M1 != M2) cout<<"1"<<endl;
  else cout<<"0"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int ans(int x)
{int d=0;
 while(x)
 {d+=(x%10);
  x/=10;}
 return d;}
int main()
{
int xxx;
cin>>xxx;
if(xxx % ans(xxx)==0)
cout<<"Yes";
else
cout<<"No";
system("pause"); 
return 0;
}

Measured memory_bytes: 504
N=int(input())
S=input()
ans=0
for i in range(1000):
  l=[]
  for j in range(3):
    l.append(i//10**(2-j)%10)
  k=0
  for j in range(N):
    if int(S[j])==l[k]:
      k+=1
      if k==3:
        ans += 1
        break
print(ans)

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

int main(){
	double n,sum=0,d;
	cin>>n>>d;
	for(int i=0;i<n;i++){
		double x1,x2,dis=0.0;
		cin>>x1>>x2;
		dis = sqrt(x1*x1+x2*x2);
		if(dis<=d)
		 sum++;
		 
	}
	cout<<sum;
	
	 return 0;
}

Measured memory_bytes: 3836
#include<iostream>
#include<queue>
using namespace std;
long B,l,r;
int Q;
priority_queue<int>L,R;
main()
{
	cin>>Q;
	for(;Q--;)
	{
		int id;cin>>id;
		if(id==1)
		{
			int a,b;cin>>a>>b;
			B+=b;
			if(R.size()<L.size())
			{
				L.push(a);
				l+=a;
				a=L.top();
				l-=a;
				r+=a;
				L.pop();
				R.push(-a);
			}
			else
			{
				R.push(-a);
				r+=a;
				a=-R.top();
				r-=a;
				l+=a;
				R.pop();
				L.push(a);
			}
		}
		else
		{
			long w=L.top();
			cout<<w<<" "<<B+r-l+w*((int)L.size()-(int)R.size())<<endl;
		}
	}
}

Measured memory_bytes: 3452
import Control.Monad
import Control.Applicative
import Data.List
import qualified Data.Map as Map
import Data.Array
import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import qualified Data.Set as Set
import qualified Data.Sequence as Sq
import qualified Data.IntMap as IMap
import qualified Data.Vector as V
import Data.Sequence (ViewL(..),ViewR(..),(><),(<|),(|>),Seq)

bsreadInt :: BC.ByteString -> Int
bsreadInt = fst . fromJust . BC.readInt

sqleft :: Seq a -> a
sqleft q = sqleft_(Sq.viewl q)
sqleft_ :: ViewL a -> a
sqleft_ (x :< xs) = x
sqright :: Seq a -> a
sqright q = sqright_(Sq.viewr q)
sqright_ :: ViewR a -> a
sqright_ (xs :> x) = x
-------------------------------------------------------------

main = do
    n <- readLn :: IO Int
    anin <- map bsreadInt . BC.words <$> BC.getLine
    let an = listArray (0,n+1) (0:anin ++ [0])
    let all = sum [abs(an!(i+1) - an!i) | i <- [0..n]]
    let ans = [all + abs( an!(i-1) - an!(i+1)) - abs( an!(i-1) - an!i) - abs(an!i - an!(i+1)) | i <-[1..n]]
    mapM_ print ans

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

using namespace std;

const long long MOD = 1000000007;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}

vector<pair<int, int>> events;

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);

    int n, q, s, t, x;
    cin >> n >> q;

    for(int i = 0; i < n; ++i){
        cin >> s >> t >> x;
        events.push_back(make_pair(s - x, x));
        events.push_back(make_pair(t - x, -x));
    }

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

    int left = 0;

    set<int> best;

    for(int i = 0; i < q; ++i){

        cin >> x;

        while(left < n * 2 && events[left].first <= x){
            if(events[left].second >= 0){
                best.insert(events[left].second);
            } else {
                best.erase(-events[left].second);
            }
            ++left;
        }

        if(best.empty())
            cout << "-1 \n";
        else
            cout << (*best.begin()) << "\n";

    }

    return 0;
}


Measured memory_bytes: 13804
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define INF 1000000000000
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))

typedef pair<long long,long long> P;

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

    vector<long long> man;
    vector<P> pack;

    for(int i=0; i<M; ++i) {
        long long temp;
        cin >> temp;
        man.push_back(temp);
    }

    sort(man.rbegin(),man.rend());

    for(int i=1; i<M; ++i) {
        man[i]+=man[i-1];
    }

    for(int i=0; i<N; ++i) {
        long long c,e;
        cin >> c >> e;
        pack.push_back(make_pair(e,c));
    }

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

    long long dp[2][M];

    for(int j=0; j<M; ++j) {
        dp[0][j]=INF;
        dp[1][j]=INF;
    }

    for(int i=0; i<M; ++i) {
        if(i<pack[0].second) dp[0][i]=pack[0].first;
    }

    for(int i=1; i<N; ++i) {
        for(int j=0; j<M; ++j) {
            if(j<pack[i].second) {
                dp[i%2][j]=MIN(dp[i%2][j],dp[(i-1)%2][j]);
                dp[i%2][j]=MIN(dp[i%2][j],pack[i].first);
            }
            if(j+pack[i].second<M) {
                dp[i%2][j+pack[i].second]=MIN(dp[(i-1)%2][j+pack[i].second],dp[(i-1)%2][j]+pack[i].first);
            }
        }
    }

    long long ans=0;
    for(int i=0; i<M; ++i) {
        ans=MAX(ans,man[i]-dp[(N-1)%2][i]);
    }

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 3448
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

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

    int n;
    cin >> n;
    vector<vector<int>> a(n, vector<int>(n - 1));
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n - 1; ++j){
            cin >> a[i][j];
            --a[i][j];
        }
        reverse(a[i].begin(), a[i].end());
    }
    vector<P> games;
    auto check = [&](int i) -> void {
        if(a[i].size() == 0)    return;
        int j = a[i].back();
        if(a[j].back() == i){
            games.push_back(minmax(i, j));
        }
    };
    for(int i = 0; i < n; ++i)  check(i);
    int day = 0;
    while(games.size() > 0){
        ++day;
        sort(games.begin(), games.end());
        games.erase(unique(games.begin(), games.end()), games.end());
        vector<P> foo;
        swap(foo, games);
        for(auto p : foo){
            int i = p.first, j = p.second;
            a[i].pop_back();
            a[j].pop_back();
        }
        for(auto p : foo){
            int i = p.first, j = p.second;
            check(i);
            check(j);
        }
    }
    for(int i = 0; i < n; ++i){
        if(a[i].size()){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << day << endl;
}

Measured memory_bytes: 4224
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scn = new Scanner(System.in);

        long a = scn.nextLong(), b = scn.nextLong(), x = scn.nextLong();
        long ans = 0;

        ans = (b / x) - (a / x);

        if(a % x == 0){
            ans++;
        }

        System.out.println(ans);

    }

}

Measured memory_bytes: 27104
#include<iostream>
using namespace std;
const int maxn=1e5+5;	
int n,a[maxn];
bool flag = false;
int main() {
	cin>>n;
	for(int i=0; i<n; i++) {
		cin>>a[i];
		if(a[i]%2) flag = true;
	}
	cout<<(flag ? "first":"second")<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;

int32_t main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	vector<int> a(n);
	multiset<int> s;
	f(i,0,n){
		cin >> a[i];
		s.insert(a[i]);
	}
	auto kk = s.end();
	kk--;
	f(i,0,n){
		auto k = s.find(a[i]);
		if(k==kk){
			k--;
			cout << *k << '\n';
		}else{
			cout << *kk << '\n';
		}
	}
	return 0;
} 

Measured memory_bytes: 13528
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,mx,x[55],y[55];
map<pair<int,int>,int>mp;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>x[i]>>y[i];
	}
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i==j)
			{
				continue;
			}
			int p=x[j]-x[i],q=y[j]-y[i];
			mp[make_pair(p,q)]++;
			mx=max(mx,mp[make_pair(p,q)]);
		}
	}
	cout<<n-mx<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,x,p=0;cin>>n>>m>>x;
  for(int i=0;i<m;i++){
    int a;cin>>a;
    if(a<x)p++;
  }
  cout<<min(p,m-p)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
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 long long INF = 1LL << 60;
using Graph=vector<vector<int>>;

int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){

  int count=0;
  int l[2020];
  for(int i=0;i<2000;i++){
    int n;
    cin>>n;
    if(n==-1){
      break;
    }
    else{
      l[i]=n;
      count++;
    }
  }
  rep(i,count){
    string t;
    int r=l[i];
    if(r<4) {
      cout<<r<<endl;
      continue;
    }
    while(r>=4){
      t+=to_string(r%4);
      r=r/4;
      if(r<4) t+=to_string(r);
    }
    reverse(all(t));
    cout<<t<<endl;
  }
  return 0;
}


Measured memory_bytes: 3112