akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

#define MAX_V 200000

typedef pair<long long int, long long int> P;
long long int INF = 1e18;

struct edge{
	int to;
	long long int cost;
};

vector<edge> G[MAX_V];
long long int d[MAX_V];

// 速さはO(|E|log|V|)

void shortest_path(int s, int V){ // Vは頂点数
	
	priority_queue<P, vector<P>, greater<P> > que;
	
	for(int i = 0; i < V; i++){
		d[i] = INF;
	}
	d[s] = 0;
	
	que.push(P(0, s));
	
	while(!que.empty()){
		
		P p = que.top();
		que.pop();
		
		int v = p.second;
		
		if(d[v] < p.first){
			continue;
		}
		
		for(int i = 0; i < G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] > e.cost + d[v]){
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		} // 頂点への最小コストを更新
	}
}

int main(){
	
	int V;
	cin >> V;
	
	for(int i = 0; i < V; i++){
		int u, num;
		cin >> u >> num;
		for(int j = 0; j < num; j++){
			edge e;
			cin >> e.to >> e.cost;
			G[u].push_back(e);
		}
	}
	
	shortest_path(0, V);
	
	for(int i = 0; i < V; i++){
		cout << i << " " << d[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 7968
#include <iostream>
using namespace std ;
int main ()
{
	int x=0 , y=0 ;
	while(1)
	{
		cin >> x >> y ;
		if(x==0&&y==0)
		{
			break ;
		}
		else if(x>y)
		{
			cout << y << " " << x << endl ;
		}
		else
		{
			cout <<x << " " << y << endl ;
		}
	}
	return 0 ;
}


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

 using namespace std;

 int main() {
   int A, B, i;
   string S, ans = "Yes";
   cin >> A >> B >> S;

   if (S.at(A) != '-') ans = "No";

   else {
     for (i = 0; i < A; i++) {
       if (S.at(i) == '-') {
         ans = "No";
         break;
       }
     }
     if (ans == "Yes") {
       for (i = A + 1; i < A + B + 1; i++) {
         if (S.at(i) == '-') {
           ans = "No";
           break;
         }
       }
     }
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
H = [int(i) for i in input().split()]

t_list = []

for i in range(N):
    t_list.append(T-H[i]*0.006)

max = 0
for i in range(N):
    if abs(A-t_list[max]) > abs(A-t_list[i]):
        max = i
        
print(max+1)

Measured memory_bytes: 3064
#include <iostream>
#include <time.h>
#include <math.h>



using namespace std;
int main()
{

	int K, S;
	cin >> K >> S;
	int count = 0, z=0;
	for (int i = 0; i <= K; i++) {

		for (int j = 0; j <= K; j++) {

			z = S - i - j;
			if (z >= 0 && z <= K) {
				count++;
			}
		}
	}

	cout << count;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    int N, K;
    cin >> N >> K;
    string s;
    cin >> s;

    vector< pair<int, int> > islands;
    int b = 0, w = 0;
    rep(i, N){
        if(s[i] == '0'){
            if(w == 0) b++;
            else{
                pair<int, int> p(w, 1);
                islands.push_back(p);
                b++;
                w = 0;
            }
        }else{
            if(b == 0) w++;
            else{
                pair<int, int> p(b, 0);
                islands.push_back(p);
                w++;
                b = 0;
            }
        }

        if(i == N-1){
            if(b != 0){
                pair<int, int> p(b, 0);
                islands.push_back(p);
            }else{
                pair<int, int> p(w, 1);
                islands.push_back(p);
            }
        }
    }

    int r = 0, ans = 0, sum = 0, kk = 0;
    for(int l = 0; l < islands.size(); l++){
        while(kk < K && r < islands.size()){
            if(islands[r].second == 0){
                kk++;
                sum += islands[r].first;
            }else{
                sum += islands[r].first;
            }
            r++;
        }
        if(r < islands.size()) sum += islands[r].first;
        ans = max(ans, sum);
        if(islands[l].second == 0) kk--;
        sum -= islands[l].first;
        if(r < islands.size()) sum -= islands[r].first;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1528
import sys

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def popcount(n):
    if n == 0:
        return 0
    return 1 + popcount(n % bin(n).count("1"))


def main():
    N = int(input())
    X = input().strip()

    x1 = 0
    xc = bin(int(X, 2)).count("1")
    if xc == 1:
        x2 = -1
    else:
        x2 = 0
    for i in range(N):
        if X[-1 - i] == '1':
            x1 += pow(2, i, xc + 1)
            if x2 != -1:
                x2 += pow(2, i, xc - 1)
    for i in range(N):
        if X[i] == '0':
            print(1 + popcount((x1 + pow(2, N - i - 1, xc + 1)) % (xc + 1)))
        else:
            if x2 == -1:
                print(0)
            else:
                print(1 + popcount((x2 - pow(2, N - i - 1, xc - 1) + xc - 1) % (xc - 1)))


if __name__ == '__main__':
    main()


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


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

    int popx=0;
    rep(i,n){
        if(s[i]=='1') popx++;
    }
    int px1 = popx+1, px2 = popx-1;

    vector<ll> x1(n+1,0);
    vector<ll> x2(n+1,0);
    ll x1sum = 0;
    ll x2sum = 0;
    ll tmp1 = 1;
    ll tmp2 = 1;
    rep(i,n){
        if(popx <= 1) break;
        x1[n-i-1] = tmp1;
        x2[n-i-1] = tmp2;

        tmp1 *= 2;
        tmp1 %= px1;
        tmp2 *= 2;
        tmp2 %= px2;
    }
    rep(i,n){
        if(popx <= 1) break;
        if(s[i]=='1'){
            x1sum += x1[i];
            x2sum += x2[i];
        }
    }

    rep(i,n){
        if(popx==0){
            cout << 1 << endl;
            continue;
        }else if(popx==1){
            if(s[i]=='1') cout << 0 << endl;
            else if(i==n-1) cout << 2 << endl;
            else cout << 1 << endl;
            continue;
        }

        ll res = 1;
        ll sum=0;
        if(s[i]=='0'){
            sum += (x1sum + x1[i]) % px1;
        }else{
            sum += (x2sum - x2[i]) % px2;
        }

        while(sum > 0){
            res++;
            sum %= __builtin_popcount(sum);
        }
        cout << res << endl;
    }

}

Measured memory_bytes: 6808
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;

int main() {
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  if (a + b + c > 21) {
    printf("bust\n");
  } else {
    printf("win\n");
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, l, r) for(register int i = l; i < r; i++)
#define hrp(i, l, r) for(register int i = l; i <= r; i++)
#define rev(i, r, l) for(register int i = r; i >= l; i--)
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...)
#define R(x, l)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn> inline tn next(void);
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v);
signed main(void)
{
	#ifdef JOEON
//		freopen("C:\Users\Joeon\Desktop\IN.txt", "r", stdin);
//		freopen("C:\Users\Joeon\Desktop\OUT.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a, b;
	cin>>n>>a>>b;
	hrp(i, a, b) if (!(i%n)) { cout<<"OK"<<endl; return 0;}
	cout<<"NG"<<endl;
	return 0;
}
template<typename tn> inline tn next(void)
{
	tn k;
	cin>>k;
	return k;
}
template<typename tn> inline ostream& operator << (ostream& os, const vector<tn>& v)
{
	rep(i, 0, v.size()) os<<v[i]<<' ';
	return os;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e5, maxX = 1e6 + 1; int n;
int a[maxN];
bool valid[maxX];
int cnt[maxX];

int main()
{
  while (scanf("%d", &n) != EOF)
  {
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);

    memset(cnt, 0, sizeof(cnt));
    fill(valid, valid+maxX, true);
    for (int i = 0; i < n; i++)
      cnt[a[i]]++;

    for (int i = 1; i < maxX; i++)
      if (cnt[i])
      {
        if (cnt[i] > 1) valid[i] = false;
        for (int j = 2; i*j < maxX; j++)
          valid[i*j] = false;
      }
    int ans = 0;
    for (int i = 1; i < maxX; i++)
      if (cnt[i])
        ans += valid[i];
    printf("%d\n", ans);
  }
  return 0;
}

Measured memory_bytes: 9480
#import random
import numpy as np
d=int(input())
c=np.array(list(map(int,input().split())))
s=[None]*d
r0=[None]*d
r1=[None]*d
cm=np.array([0]*26)
cd=np.array([0]*26)
t=[None]*d
for i in range(d):
  s[i]=list(map(int,input().split()))
s=np.array(s)
for i in range(d):
  t[i]=int(input())-1
"""
for j in range(d):  
  #rand = np.random.randint(26, size = 10) 
  #print(np.argmax(s[j])+1)
  r_i=np.argmax(s[j])
  cd=c*cm
  if np.max(cd>s[i][r_i]):
    r_i=np.argmax(cd)
  r0[j]=r_i
  for k in range(26):
    cm[k]+=1
  cm[r_i]=0
  #r_i+=1
  #print(r_i)
cm=np.array([0]*26)
cd=np.array([0]*26)  
rand = np.random.randint(100, size = d) 
for j in range(d):  
  #print(np.argmax(s[j])+1)
  r_i=r0[j]
  cd=c*cm
  if rand[j]>80:
    r_i=np.argmax(cd)
  r1[j]=r_i
  for k in range(26):
    cm[k]+=1
  cm[r_i]=0
"""
r0=t
score=0
cm=np.array([0]*26)
cd=np.array([0]*26)  
for j in range(d):
  r0_j=r0[j]
  score+=s[j][r0_j]
  for k in range(26):
    cm[k]+=1
    cm[r0_j]=0
  cd=c*cm
  score+=-np.sum(cd)
  print(score)
  
    



Measured memory_bytes: 27156
import java.util.*;
import static java.lang.Integer.*;
//import static java.lang.Long.*;
//import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int j;
		Scanner sc = new Scanner(in);
		int r = parseInt(sc.next());
		sc.close();
		out.println(r<1200?"ABC":(r<2800?"ARC":"AGC"));
	}
}


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

using str = string;
using ss = stringstream;

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

    str s;cin>>s;

    for(int i=0;i<8;i++)
    {
        int ans=s[0]-'0';
        ss makeans;
        makeans<<s[0]-'0';
        for(int j=0,k=i;j<3;j++,k=k>>1)
        {
            if(k%2)
            {
                ans+=s[j+1]-'0';
                makeans<<"+"<<s[j+1]-'0';
            }
            else
            {
                ans-=s[j+1]-'0';
                makeans<<"-"<<s[j+1]-'0';
            }            
        }
        makeans<<"=7";
        if(ans==7)
        {
            cout<<makeans.str()<<"\n";
            break;
        }
    }

    return 0;
}


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

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    
    ll sum = 0;
    ll n_count = 0;
    ll minimum = 1000000001;
    ll a;
    for(ll i=0; i<n; i++){
        cin >> a;
        if(a > 0){
            sum += a;
            minimum = min(minimum, a);
        }else{
            sum -= a;
            ++n_count;
            minimum = min(minimum, -a);
        }
    }
        
    if(n_count % 2 == 0)
        cout << sum << endl;
    else
        cout << sum - 2 * minimum << endl;
    
    return 0;
}


Measured memory_bytes: 256
import string
import sys

a = string.ascii_lowercase
key = str.maketrans(a, a[1:] + a[:1])

for s in sys.stdin:
    for i in range(26):
        s = s.translate(key)
        if 'the' in s or 'this' in s or 'that' in s:
            break
    print(s, end="")

Measured memory_bytes: 7980
import sys

def LCM(a, b):
    m = a * b
    a, b = min(a, b), max(a, b)
    while a % b > 0:
        a, b = b, a % b
    return m // b

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    A = [int(a) for a in input().split()]
    div = 0
    d = A[0]
    while d % 2 == 0:
        div += 1
        d //= 2
    for i in range(1, N):
        d = A[i]
        di = 0
        while d % 2 == 0:
            di += 1
            d //= 2
        if di != div: 
            print(0)
            break
    else:
        if N > 2:
            lcm = LCM(A[0] // 2, A[1] // 2)
            for i in range(2, N):
                lcm = LCM(lcm, A[i] // 2)
        elif N == 2:
            lcm = LCM(A[0] // 2, A[1] // 2)
        else: lcm = A[0] // 2

        print((1 + (M // lcm)) // 2)

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 14244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int mod = 1e9 + 7;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
int prime[maxn];
int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	for(int i=2;i<maxn;i++) {
		if(!prime[i]) prime[++prime[0]]=i;
		for(int j=1;j<=prime[0]&&prime[j]<=maxn/i;j++) {
			prime[i*prime[j]]=1;
			if(i%prime[j]==0) break;
		}
	}
	int n;
	cin>>n;
	cout<<n<<":";
	vi ans;
	for(int i=1;i<=prime[0];i++) {
		while(n%prime[i]==0) {
			ans.pb(prime[i]);
			n/=prime[i];
		}
	}
	if(n!=1) ans.pb(n);
	for(int x:ans) cout<<" "<<x;
	cout<<'\n';
	return 0;
}



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

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

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


int main() {
  int H,W;
  cin>>H>>W;
  
  vector<vector<char>> grid(H, vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>grid.at(i).at(j);
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(grid.at(i).at(j)=='.') continue;
      else{
        if(j>=1&&grid.at(i).at(j-1)=='#') continue;
        if(j<=W-2&&grid.at(i).at(j+1)=='#') continue;
        if(i>=1&&grid.at(i-1).at(j)=='#') continue;
        if(i<=H-2&&grid.at(i+1).at(j)=='#') continue;
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
    
  
}

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

int main(void){
	int n;
	double len,rad;

	while(scanf("%d",&n) && n != -1){
		len = 1.0;
		rad = 0.0;
		n--;
		while(n--){
			rad += atan(1/len);
			len = sqrt(len * len + 1);
		}

		printf("%.2lf\n%.2lf\n",len*cos(rad),len*sin(rad));
	}

	return 0;
}

Measured memory_bytes: 0
use proconio::input;
use num::Complex;
use std::f64::consts::PI;

fn main() {
    input! {
        n: usize,
        mut m: isize,
        p: [usize; n],
    }

    let max = *p.iter().max().unwrap();
    let mut a = vec![0; max * 2 + 1];
    for &np in &p {
        a[np] += 1;
    }
    let b = a.clone();

    let v = multiply(a, b);

    let mut ans = 0;
    for i in (0..=max*2).rev() {
        //println!("i {} v[{}] {}",i , i, v[i]);
        if m > v[i] {
            m -= v[i];
            ans += i as isize * v[i];
        } else {
            ans += m * i as isize;
            break;
        }
    }
    println!("{}", ans);
}

fn multiply(g: Vec<usize>, h: Vec<usize>) -> Vec<isize> {
    let n = pow_2_at_least(g.len() + h.len() + 1);

    let mut a = vec![Complex::new(0.0, 0.0); n];
    let mut b = vec![Complex::new(0.0, 0.0); n];

    for i in 0..g.len() {
        a[i] = Complex::new(g[i] as f64, 0.0);
    }
    for i in 0..h.len() {
        b[i] = Complex::new(h[i] as f64, 0.0);
    }

    let gg = dft(a, n);
    let hh = dft(b, n);

    let mut ff = vec![];
    for i in 0..n {
        ff.push(gg[i] * hh[i]);
    }
    let ff = inverse_dft(ff, n);
    let mut res = vec![];
    for &c in &ff {
        res.push((c.re / n as f64).round() as isize);
    }
    res
}

fn dft(mut f: Vec<Complex<f64>>, n: usize) -> Vec<Complex<f64>> {
    if n == 1 {
        return f;
    }
    let mut f0 = vec![];
    let mut f1 = vec![];
    for i in 0..n / 2 {
        f0.push(f[2 * i + 0]);
        f1.push(f[2 * i + 1]);
    }
    f0 = dft(f0, n / 2);
    f1 = dft(f1, n / 2);
    let zeta = Complex::new((2.0 * PI / n as f64).cos(), (2.0 * PI / n as f64).sin());
    let mut pow_zeta = Complex::new(1.0, 0.0);

    for i in 0..n {
        f[i] = f0[i % (n / 2)] + pow_zeta * f1[i % (n / 2)];
        pow_zeta *= zeta;
    }
    f
}

fn inverse_dft(f: Vec<Complex<f64>>, n: usize) -> Vec<Complex<f64>> {
    if n == 1 {
        return f;
    }
    let mut f0 = vec![];
    let mut f1 = vec![];
    for i in 0..n / 2 {
        f0.push(f[2 * i + 0]);
        f1.push(f[2 * i + 1]);
    }
    f0 = inverse_dft(f0, n / 2);
    f1 = inverse_dft(f1, n / 2);
    let zeta = Complex::new((2.0 * PI / n as f64).cos(), (2.0 * PI / n as f64).sin());
    let zeta = zeta.inv();
    let mut pow_zeta = Complex::new(1.0, 0.0);

    let mut res = vec![];
    for i in 0..n {
        res.push(f0[i % (n / 2)] + pow_zeta * f1[i % (n / 2)]);
        pow_zeta *= zeta;
    }
    res
}


fn pow_2_at_least(n: usize) -> usize {
    let mut sz = 1;
    while sz <= n {
        sz *= 2;
    }
    sz
}


Measured memory_bytes: 64848
def find_card():
    n = int(input())
    sute = ['S', 'H', 'C', 'D']
    cards = []
    for s in sute:
        for i in range(1, 14):
            cards.append('{} {}'.format(s,i))
    for i in range(n):
        x,y = input().split()
        l = ' '.join([x,y])
        if l in cards:
            cards.remove(l)
    for i in cards:
        print(i)
        
if __name__ == '__main__':
    find_card()


Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
int main(void){
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> c(n);
  rep(i,n){
    cin >> v.at(i);
  }
  rep(i,n){
    cin >> c.at(i);
  }
  int ans = 0;
  rep(i,n){
      if(v.at(i) > c.at(i)){
        ans += v.at(i) - c.at(i);
      }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll INF = 1LL<<60;
/////////////////////////////////
int main(){
    int n;
    cin >> n;
    bool can = false;
    for (int i = 1; i < 10;i++)
        for (int j = 1; j < 10;j++)
        if(n==i*j)
            can = true;
            
            if (can)
                cout << "Yes" << endl;
            else
                cout << "No" << endl;
}

Measured memory_bytes: 3596
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);

void main()
{
    long l, r, d;
    scan(l, r, d);
    long cnt;
    foreach (i; l .. r + 1)
    {
        if (i % d == 0)
        {
            cnt += 1;
        }
    }
    writeln(cnt);

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}


Measured memory_bytes: 3592
//#include <bits/stdc++.h>
#include<iostream>
#include <iosfwd>
#include<limits.h>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <limits>
#include<stdio.h>
#include <queue>
#include <stack>
#include <math.h>
#include<string.h>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include<vector>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;
#define fr(i,j,n)   for(lli i=j;i<(n);++i)
#define bk(i,j,n)   for(lli i=j;i>=n&&j>=n;--i)
#define pb push_back
#define F first
#define S second
#define endl "\n"
#define mem(p,v) memset(p,v,sizeof(p))
#define present(c,x)    ((c).find(x) != (c).end())
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define debug4(x,y,z,a) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<" "<<#a<<" "<<a<<endl;
#define ub upper_bound
#define lb lower_bound
typedef long long int lli;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<lli> vl;
typedef pair<lli,lli> pl;
inline lli max(lli a,lli b){ return a>b?a:b;}
inline lli min(lli a,lli b){ return a<b?a:b;}
const long long inf = 1e18;
const lli MOD =998244353 ;
void show(vector<lli> v){fr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;}
void show(vector<int> v){fr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;}
void show(int a[], int arraysize){for (int i = 0; i < arraysize; ++i)cout << a[i] << " ";cout<<endl;}
void show(lli a[], lli arraysize){for (lli i = 0; i < arraysize; ++i)cout << a[i] << " ";cout<<endl;}
void show(bool a[], lli arraysize){for (lli i = 0; i < arraysize; ++i)cout << a[i] << " ";cout<<endl;}
void show(set<int> s){for (auto it = s.begin(); it != s.end(); it++){cout << *it << " ";}cout<<endl;}
void show(map<lli,lli> mp){for (auto it = mp.begin(); it != mp.end(); it++){cout << it->first << " "<<it->second<<endl;}cout<<endl;}
//Pair hashing is done using std::map ;
lli modpow(lli x,lli n){lli res=1;while(n>0){if(n&1) res=((res%MOD)*(x%MOD))%MOD;x=((x%MOD)*(x%MOD))%MOD;n>>=1;}return res;}
lli power(lli x, lli n){lli res=1;while(n>0){if(n&1) res=res*x;x=x*x;n>>=1;}return res;}

/////// ------ Main code starts here ------ /////
void solve()
{
    lli n;
    cin>>n;
    lli a[n];
    fr(i,0,n)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    lli ans=0;
    fr(i,0,n)
    {
        fr(j,i+1,n)
        {
            fr(k,j+1,n)
            {
                if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]&&(a[i]+a[j]>a[k]))
                    ans++;
                    
            }
        }
    }
    cout<<ans<<endl;
}
int main()
{
    run;cout<<fixed<<setprecision(12);
    int t;
    t=1;
    while(t){solve();t--;}
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int n; cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];

    vector<ll> s(n + 1);
    for (int i = 0; i < n; i++) s[i + 1] = s[i] + a[i];

    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, linf));
    for (int i = 0; i < n; i++) dp[i][i + 1] = 0;
    for (int len = 2; len <= n; len++) {
        for (int i = 0; i <= n - len; i++) {
        int j = i + len;
            for (int k = i + 1; k < j; k++) {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j] + s[j] - s[i]);
            }
        }
    }
    cout << dp[0][n] << endl;
    return 0;
}


Measured memory_bytes: 1536
n=int(input())
arr=[int(input()) for _ in range(n)]
dp=[0]*(sum(arr)+1)
l=len(dp)
for i in range(n):
  tmp=arr[i]
  for j in range(l-1,-1,-1):
    if j-tmp>=0 and dp[j-tmp]!=0:
      dp[j]=1
  dp[tmp]=1
for i in range(l-1,-1,-1):
  if dp[i]==1 and i%10!=0:
    print(i)
    break
else:
  print(0)

Measured memory_bytes: 3064
#! python3
# dictionary.py - 簡易辞書をつくる

n = int(input())

strings = set()
for i in range(n):
    order, string = input().split()
    # print(order, string)
    if order == 'insert':
        strings.add(string)
    else:
        if string in strings:
          print('yes')
        else :
          print('no')



Measured memory_bytes: 30992
a=input().split(' ')
b=input().split(' ')
c=0
for i in range(int(a[1])):
    if i != int(a[1])-1:
        if int(b[i+1]) - int(b[i]) > c:
            c = int(b[i+1]) - int(b[i])
    else:
        if int(a[0]) - int(b[-1])+ int(b[0]) > c:
            c = int(a[0]) - int(b[-1])+ int(b[0])
print(int(a[0])-c)


Measured memory_bytes: 18508
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void)
{
	int K, A, B;
	cin >> K >> A >> B;
	bool judge = false;
	repd(i,A,B+1)
	{
		if(i%K==0) judge = true;
	}
	if(judge) cout << "OK" << endl;
	else cout << "NG" << endl;
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)

#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;

bool v[26];
int main() {
	ll a, b, c, k; cin >> a >> b >> c >> k;

	if (k & 1) {
		cout << b - a << endl;
	}
	else {
		cout << a - b << endl;
	}

	return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int count = 0;
  for(int i = A; i < B + 1; i++){//AからBまで実行するコマン
    if((i - i % 10000) / 10000 == i % 10 && (i % 10000 - i % 1000) / 1000 == (i % 100 - i % 10)/ 10){
    count++;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 3632
use std::io;

fn input() -> (i64, i64) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();
    let a: i64 = iter.next().unwrap().parse().unwrap();
    let b: i64 = iter.next().unwrap().parse().unwrap();
    (a, b)
}

fn main() {
    loop {
        let (H, M) = input();
        if H == 0 && M == 0 {
            break;
        }
        for i in 0..H{
            for j in 0..M{
                if (i+j)%2==0{
                    print!("#");
                }
                if (i+j)%2==1{
                    print!(".");
                }
            }
            print!("\n");
        }
        print!("\n");
    }
}


Measured memory_bytes: 5020
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
a, b = M()
print(math.ceil((a+b)/2))

Measured memory_bytes: 3896
#include <stdio.h>
#include <stdlib.h>
int asc(const int *a, const int *b) {
  return *a - *b;
}

int main() {
  int number_n, i;
  scanf("%d", &number_n);
  int point[number_n];
  for(i = 0; i < number_n; i++) {
    scanf("%d", &point[i]);
  }
  qsort(point, number_n, sizeof(int), asc);
  printf("%d\n", point[number_n-1] - point[0]);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long int ll;
const int N=1e5+5,MAX=1e9+2;
int n,W,w[105],v[105];
ll dp[105][N],ans;
int main(){
    cin.tie(NULL);
    cout.tie(NULL);
    ios_base::sync_with_stdio(false);
    cin>>n>>W;
    for(int i=0;i<n;i++)
        cin>>w[i]>>v[i];
    memset(dp,-1,sizeof dp);
    dp[0][0]=0; dp[0][w[0]]=v[0];
    for(int i=1;i<n;i++){
        for(int j=0;j<N;j++){
            if(~dp[i-1][j]&&j+w[i]<=W){
                dp[i][j+w[i]]=max(dp[i][j+w[i]],dp[i-1][j]+v[i]);
            }
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
        }
    }
    for(int i=0;i<N;i++)
        ans=max(ans,dp[n-1][i]);
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 82304
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(int argc,char** argv) {
	int n;
	cin >> n;
	int *a = new int[n];
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int j = 0;j < n - 1;j++) cout << a[j] << " ";
	cout << a[n-1] << endl;
	for(int i = 1;i < n;i++) {
		int v = a[i];
		int j = i - 1;
		while(j >= 0 && a[j] > v){ a[j+1] = a[j]; j--;}
		a[j+1] = v;
		for(int j = 0;j < n - 1;j++) cout << a[j] << " ";
		cout << a[n-1] << endl;
	}
	delete a;
}



Measured memory_bytes: 3104
#include <iostream>
#include <vector>
#include <algorithm>
#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, k;
    cin >> n;
    cin >> k;
    vector<int> nums(n);
    for (int i = 0; i < n; i++) {
      cin >> nums[i];
    }

    vector<int> costs(n);
    costs[0] = 0;
    costs[1] = abs(nums[1] - nums[0]);
    for (int i = 2; i < n; i++) {
      costs[i] = INT_MAX;
      for (int j = 1; j <= k && i - j >= 0; j++) {
        costs[i] = min(costs[i], abs(nums[i] - nums[i-j]) + costs[i-j]);
      }
    }
    cout << costs[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            final int a = in.nextInt();
            final int b = in.nextInt();
            out.println((a + (b - a) * 2));
        }

    }
}



Measured memory_bytes: 21844
#include <iostream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using namespace std;

const ll BIG = 1000000007LL;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

template<typename T>
void inputArray(T* p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

template<typename T>
void inputVector(vector<T> * p, int a){
    rep(i, a){
        T input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision = 0) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    char c;
    cin >> c;
    if (c == 'A') {
        output('T');
    } else if ( c == 'C') {
        output('G');
    } else if ( c == 'G') {
        output('C');
    } else if ( c == 'T') {
        output('A');
    }

    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let s = read::<String>().chars().collect::<Vec<char>>();
    let mut sum = 0;
    for i in 1..n {
        if s[i] == 'E' {
            sum += 1;
        }
    }
    let mut ans = sum;
    for i in 0..n - 1 {
        if s[i] == 'W' {
            sum += 1;
        }
        if s[i + 1] == 'E' {
            sum -= 1;
        }
        ans = std::cmp::min(ans, sum);
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	ll n;
	cin>>n;
	ll a[n],b[n],c[n];
	for(int i=0;i<n;i++)
	cin>>a[i]>>b[i]>>c[i];
	ll dp1[n],dp2[n],dp3[n];
	dp1[0]=a[0];
	dp2[0]=b[0];
	dp3[0]=c[0];
	for(int i=1;i<n;i++)
	{
		dp1[i]=max(dp2[i-1],dp3[i-1])+a[i];
		dp2[i]=max(dp1[i-1],dp3[i-1])+b[i];
		dp3[i]=max(dp2[i-1],dp1[i-1])+c[i];
	}
	cout<<max(dp3[n-1],max(dp2[n-1],dp1[n-1]));
}

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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

map<ll, ll> prime_factor(ll n){
	map<ll, ll> res;

	for(ll i = 2; i * i <= n; i++){
		while(n % i == 0){
			++res[i];
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;

	return res;
}

int main()
{
	int n;
	cin>>n;
	vector<ll> a(n);
	rep(i,n)cin>>a[i];

	map<ll,ll> mp;

	rep(i,n){
		map<ll,ll> cur = prime_factor(a[i]);
		for(auto elm:cur){
			ll val=elm.first;
			ll cnt=elm.second;
			mp[val]=max(mp[val],cnt);
		}
	}

	ll lcm=1;
	for(auto elm:mp){
		lcm*=power(elm.first,elm.second);
		lcm%=mod;
	}

	ll ans = 0;
	rep(i,n){
		ans += (lcm*power(a[i],mod-2))%mod;
		ans%=mod;
	}

	cout<<ans<<endl;

	return 0;
}

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

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,popcnt,abm,mmx,tune=native")   */


//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back

const int N = 3e5 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 2e12;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int x, y, n, m, nn;
    cin >> x >> y >> n >> m >> nn;
    vi a(n), b(m), c(nn);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];
    for (int i = 0; i < nn; i++) cin >> c[i];
    sort(a.rbegin(), a.rend()), sort(b.rbegin(), b.rend()), sort(c.rbegin(), c.rend());
    int i = 0, j = 0, j1 = 0, tek = 0;
    while (i < x) {
        tek += a[i];
        if (i + 1 < x) i++;
        else break;
    }
    int o = 0;
    while (o < y) {
        if (j == m) {
           o++;
           tek += c[j1];
           j1++;
           continue;
        }
        if (j1 == nn) {
            o++; tek += b[j];
            j++;
            continue;
        }
        if (b[j] > c[j1]) {
            tek += b[j];
            j++;
        }
        else {
            tek += c[j1];
            j1++;
        }
        o++;
    }
    int ans = tek;
    for (int kol = 0; kol < min(nn, x); kol++) {
        if (a[i] >= c[kol]) break;
        if (kol >= j1) {
            tek -= a[i];
            tek += c[kol];
            i--;
        }
        else {
            tek -= a[i];
            i--;
            if (j == m && j1 == nn) break;
            if (j1 == nn) {
                tek += b[j];
                j++;
            }
            else {
                if (j == m) {
                    tek += c[j1];
                    j1++;
                }
                else {
                    if (c[j1] < b[j]) {
                        tek += b[j];
                        j++;
                    }
                    else {
                        tek += c[j1];
                        j1++;
                    }
                }
            }
        }
        ans = max(ans, tek);
    }
    cout << ans;
}


Measured memory_bytes: 2560
#include<iostream>
using namespace std;
 
int main(){
  int a, b, c;
  int numDivisor = 0;
  
  cin >> a >> b >> c;
  
  for(int i = a; i < b + 1; i++) {
    if(c % i == 0) {
      numDivisor++;
    }
  }
  
  cout << numDivisor << endl;
  
  return 0;
}

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define ll long long
#define P pair<int, int>
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define LAST(x) (x)[(x).size() - 1]
#define GI(name) \
  int(name);     \
  scanf("%d", &(name))
#define GI2(name1, name2) \
  int(name1), (name2);    \
  scanf("%d %d", &(name1), &(name2))
#define GI3(name1, name2, name3) \
  int(name1), (name2), (name3);  \
  scanf("%d %d %d", &(name1), &(name2), &(name3))
#define GVI(name, size)    \
  vector<int>(name)(size); \
  FOR(i, (size)) scanf("%d", &(name)[i])
#define GS(name) \
  string(name);  \
  cin >> (name);
#define MOD 1000000007
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

string to_string(string s) {
  return s;
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  FOR(i, v.size() - 1) { ret += to_string(v[i]) + ","; }
  if (v.size() > 0) {
    ret += to_string(LAST(v));
  }
  ret += "}";
  return ret;
}

void debug() {
  cerr << endl;
}

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() {
  cout << endl;
}

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

int main() {
  GI2(N, K);
  vector<ll> V(N);
  FOR(i, N) { cin >> V[i]; }
  ll ans = 0LL;
  for (int l = 0; l <= min(N, K); ++l) {
    vector<ll> vl(l, 0);
    for (int x = 0; x < l; ++x)
      vl[x] = V[x];
    for (int r = 0; r <= min(N - l, K - l); ++r) {
      if (l + r == 0)
        continue;
      vector<ll> vr(r, 0);
      for (int x = 0; x < r; ++x)
        vr[x] = V[N - 1 - x];
      if (l > 0)
        vr.insert(vr.begin(), vl.begin(), vl.end());
      sort(ALL(vr));
      int bound = upper_bound(ALL(vr), 0LL) - vr.begin();
      bound = min(bound, K - l - r);
      ll s = accumulate(vr.begin() + bound, vr.end(), 0LL);
      if (ans < s)
        ans = s;
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#include <string.h>
using namespace std;
// std::ios::sync_with_stdio(false);
typedef long long LL;
const int N = 150000;
const int M = 12;
const int INF = 0x3f3f3f3f;
const LL MOD = 1e9+7;
const double Pi = acos(-1);
int n,m;
char s[N],t[N];
int x;
bool pa(char *s)
{
    int l = strlen(s);
    for (int i=0;i+i<l;i++)
        if (s[i]!=s[l-1-i])
            return false;
    return true;
}
int tmp[N];
int solve(int l)
{
    int ans = 0;
    int p = 0;
    int q = l-1;
    while (p<q)
    {
        if (s[p]!=s[q])
        {
            ans++;
            if (s[p]=='x')
                p++;
            else if (s[q]=='x')
                q--;
            else
                return -1;
        }
        else
        {
            p++;
            q--;
        }
    }
    return ans;
}
int main()
{
    while (~scanf("%s",s))
    {
        int l = strlen(s);
        int pos = 0;
        for (int i=0;i<l;i++)
            if (s[i]!='x')
                t[pos++] = s[i];
        t[pos] = '\0';
        if (!pa(t))
            printf("-1\n");
        else
        {
            int ans = solve(l);
            printf("%d\n", ans);
        }
    }
    return 0;
}

/*


xabxa
a
ab
oxxx

*/

Measured memory_bytes: 384
n, q = gets.split.map(&:to_i)

t = Array.new(n) { [] }
(n-1).times do
  a, b = gets.split.map { |i| i.to_i - 1 }
  t[a] << b
  t[b] << a
end

c = Array.new(n) { 0 }
q.times do
  p, x = gets.split.map(&:to_i)
  c[p-1] += x
end

stk = [[0, -1]]
until stk.empty?
  i, p = stk.pop
  t[i].each do |j|
    next if j == p
    c[j] += c[i]
    stk << [j, i]
  end
end

puts c * " "

Measured memory_bytes: 32356
n = gets.to_i
heigths = gets.split.map(&:to_i)
heigths << 0
count = 0
until heigths.uniq.count == 1
  # p heigths # for debug
  # p count # for debug

  previous = false
  heigths.map! { |e|
    if e == 0
      count += 1 if previous
      previous = false
      e
    else
      previous = true
      e - 1
    end
  }
end
# p heigths # for debug
puts count


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

int main() {
    ll X, K, D;
    cin >> X >> K >> D;
    X = abs(X);
    ll tmp = X / D;
    if (tmp >= K) {
        X -= D * K;
        cout << X << endl;
        return 0;
    }
    X -= D * tmp;
    K -= tmp;
    if (K % 2 == 0) {
        cout << X << endl;
    } else {
        X -= D;
        cout << abs(X) << endl;
    }
}

Measured memory_bytes: 3560
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

#define BUF_SIZE 0x100

int buf[BUF_SIZE];

int compute_path(int n, int x)
{
  int right_cost = 0;
  int left_cost = 0;
  for(int i = x + 1; i <= n; i++) {
    right_cost += buf[i];
  }
  for(int i = x - 1; 0 <= i; i--) {
    left_cost += buf[i];
  }
  return min(left_cost, right_cost);
}

int main()
{
  memset(buf, 0, sizeof(buf));

  int n, m, x;
  int index;
  scanf("%d%d%d", &n, &m, &x);
  for(int i = 0; i < m; i++) {
    scanf("%d", &index);
    buf[index] = 1;
  }
  printf("%d\n", compute_path(n, x));
  return 0;
}


Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    deque<int> dq;
    int r = 0;
    rep(i,n){
        if (r) dq.push_front(a[i]);
        else dq.push_back(a[i]);
        r = !r;
    }
    rep(i,n){
        if (r){
            printf("%d%c", dq.back(), i == n-1? '\n': ' ');
            dq.pop_back();
        }else{
            printf("%d%c", dq.front(), i == n-1? '\n': ' ');
            dq.pop_front();
        }
    }
    return 0;
}

Measured memory_bytes: 4764
#include <stdio.h>
int main(void) {
  int W, H, x, y, r;
  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);

  if(!(0 <= x - r && x + r <= W)){
    puts("No");
    return 0;
  } else if (!(0 <= y - r && y + r <= H)) {
    puts("No");
    return 0;
  } else {
    puts("Yes");
  }

  return 0;
}

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

#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define MOD 1000000007

//cout << (c)?"Yay!":":(" << endl;

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n;
    cin >> n;
    long long int ans = 0;
    REP(i, 1, n + 1)
    {

        if (i % 5 == 0 || i % 3 == 0)
        {
        }
        else
        {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
import java.io.*;

class Dice {
	private int[] nums;
	public static final int DICEMAX = 6;
	public static final int TOP = 0;
	public static final int FRONT = 1;
	public static final int RIGHT = 2;
	public static final int LEFT = 3;
	public static final int BACK = 4;
	public static final int BOTTOM = 5;

	public static final int[] E = { TOP, LEFT, BOTTOM, RIGHT };
	public static final int[] N = { TOP, FRONT, BOTTOM, BACK };
	public static final int[] S = { TOP, BACK, BOTTOM, FRONT };
	public static final int[] W = { TOP, RIGHT, BOTTOM, LEFT };
	public static final int[] M = { FRONT, RIGHT, BACK, LEFT };
	public Dice( int nums[] ) {
		this.nums = new int[DICEMAX];
		for( int i=0; i<DICEMAX; i++ ) {
			this.nums[i] = nums[i];
		}
	}
	public int getDiceNum( int num ) {
		return this.nums[ num ];
	}
	public void toTop( int from ) {
		if( TOP == from ) {
			;
		} else if( FRONT == from ) {
			this.rotate( 'N' );
		} else if( RIGHT == from ) {
			this.rotate( 'W' );
		} else if( LEFT == from ) {
			this.rotate( 'E' );
		} else if( BACK == from ) {
			this.rotate( 'S' );
		} else if( BOTTOM == from ) {
			this.rotate( 'N' );
			this.rotate( 'N' );							
		}
		return;
	}

	public void rotate( char c ) {
		int tmp = 0;
		if( 'E' == c ) {
			tmp = this.nums[ E[0] ];
			for( int i=0; i<3; i++ ) {
				this.nums[ E[i] ] = this.nums[ E[i+1] ];
			}
			this.nums[ E[3] ] = tmp;
		} else if( 'N' == c ) {
			tmp = this.nums[ N[0] ];
			for( int i=0; i<3; i++ ) {
				this.nums[ N[i] ] = this.nums[ N[i+1] ];
			}
			this.nums[ N[3] ] = tmp;
		} else if( 'S' == c ) {
			tmp = this.nums[ S[0] ];
			for( int i=0; i<3; i++ ) {
				this.nums[ S[i] ] = this.nums[ S[i+1] ];
			}
			this.nums[ S[3] ] = tmp;
		} else if( 'W' == c ) {
			tmp = this.nums[ W[0] ];
			for( int i=0; i<3; i++ ) {
				this.nums[ W[i] ] = this.nums[ W[i+1] ];
			}
			this.nums[ W[3] ] = tmp;
		} else {
			tmp = this.nums[ M[0] ];
			for( int i=0; i<3; i++ ) {
				this.nums[ M[i] ] = this.nums[ M[i+1] ];
			}
			this.nums[ M[3] ] = tmp;
		
		}
		return;
	}
	
}

class Main {
	public static void main(String[] args) {
		BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
		try {
			int[] nums = new int[ 6 ];
			int i;
			i = 0;
			for( String num:  kb.readLine().split( " " ) ) {
				nums[i++] = Integer.parseInt( num );
			}
			Dice dice = new Dice( nums );

			int q = Integer.parseInt( kb.readLine() );
			for( i=0; i<q; i++ ) {
				String[] strs = kb.readLine().split( " " );
				int[] topfront = new int[2];	
				for( int j=0; j<2; j++ ) {
					topfront[j] = Integer.parseInt( strs[j] );
				}
				for( int j=0; j<6; j++ ) {
					if( topfront[ dice.TOP ] == dice.getDiceNum( j ) ) {
						dice.toTop( j );
						while( topfront[ dice.FRONT ] != dice.getDiceNum( dice.FRONT ) ) {
							dice.rotate( 'M' );
						}
						break;
					}
				}
				System.out.println( dice.getDiceNum( dice.RIGHT ) );
			}

		} catch( IOException e ) {
			System.err.println( e );
		}
	}
}

Measured memory_bytes: 16924