akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;
#define int long long
#define m_p make_pair
#define mod 1000000007
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>vec[i];
using namespace std;

int jousu(int, int);
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int kurai(int x00, int y00) {
	int z00 = (x00 % jousu(10, y00)) / jousu(10, y00 - 1);
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}




signed main() {
	int n,ans=0;
	string s;
	cin >> n;
	map<string, int>m;
	for (int i = 0; i < n; i++){
		cin >> s;
		sort(all(s));
		if (!m.count(s)) {
			m[s] = 1;
		}
		else {
			ans += m[s];
			m[s]++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 11136
#include <cstdio>

unsigned gcd(unsigned a, unsigned b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }
  while (a % b != 0) {
    unsigned t = a;
    a = b;
    b = t % b;
  }
  return b;
}

int main() {
  unsigned a, b;
  while (true) {
    if (scanf("%d %d", &a, &b) != 2) { break; }
    unsigned d = gcd(a, b);
    unsigned m = a / d * b;
    printf("%d %d\n", d, m);
  }
  return 0;
}

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

using namespace std;

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<int> > a(H + 1, vector<int>(W + 1, 0));
    vector<tuple<int, int, int, int> > res;
    for (int i = 1; i <= H; ++i) {
        for (int j = 1; j <= W; ++j) {
            int t;
            cin >> t;
            a[i][j] += t;
            if (i + 1 <= H and a[i][j] % 2 == 1) {
                a[i + 1][j]++;
                res.emplace_back(i, j, i + 1, j);
            }
        }
    }

    for (int i = 1; i <= W - 1; ++i) {
        if (i + 1 <= W && a[H][i] % 2 == 1) {
            a[H][i + 1]++;
            res.emplace_back(H, i, H, i + 1);
        }
    }

    cout << res.size() << endl;
    for (auto x : res) {
        cout << get<0>(x) << " " << get<1>(x) << " "
             << get<2>(x) << " " << get<3>(x) << endl;
    }
    return 0;
}

Measured memory_bytes: 5232
n,t=gets.split.map(&:to_i)
ab=[]
m=0
n.times do
  a,b=gets.split.map(&:to_i)
  ab << [a,b]
  m=a if a>m
end
dp=[0]*(t+m+1)
ab.sort.each do |a,b|
  (t-1).downto(0) do |j|
    if dp[j+a]<b+dp[j]
      dp[j+a]=b+dp[j]
    end
  end
end
puts dp.max


Measured memory_bytes: 2172
/// You just can't beat the person who never gives up
/// ICPC next year

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

#include<bits/stdc++.h>
using namespace std ;
const int N = 2e5+5 ;

int n ,k ,d ;
bool cant[10] ;
bool ok(int x){
    while(x){
        if(cant[x%10]) return 0;
        x /= 10 ;
    }
    return 1 ;
}
int main(){
    cin >> n >> k ;
    while(k--){
        cin >> d ;
        cant[d] = 1 ;
    }
    while(!ok(n))++n ;
    cout << n ;
    return 0;
}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long sum=1,i,n;
	cin>>n;
	for(i=1;i<=n;i++){
		sum*=i;
		sum%=1000000007;
	}
	///cout<<sum<<endl;
	printf("%lld\n",sum);
	return 0;
}

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

ans="0"
cnt=0
l=["3","5","7"]

def dfs(now):
  global cnt

  if n<int(now):
    return now
  now=str(now)
  if 1<=now.count("3") and 1<=now.count("5") and 1<=now.count("7"):
    cnt+=1

  for i in l:
    a=now+i
    dfs(a)
  
  return cnt
print(dfs(ans))



Measured memory_bytes: 75268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using lli = long long int;
lli calc(lli p, vector<long long int> &X)
{
  lli ans = 0;
  rep(i, X.size()) ans += (X[i] - p) * (X[i] - p);
  return ans;
}
void solve(long long N, std::vector<long long> X)
{
  int ans = 0;
  rep(i, X.size()) ans += X[i];
  ans /= N;
  cout << min({calc(ans, X), calc(ans + 1, X), calc(ans - 1, X)}) << endl;
}

int main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<long long> X(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &X[i]);
  }
  solve(N, std::move(X));
  return 0;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

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

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

using namespace std;
int recur(int , int );
const int MAX = 1e5 + 5;
int arr[MAX][4];
int n;
int dp[MAX][4];

int recur(int day, int flag) {
	int maximum = 0;
	if (day == n) {
		return 0;
	}
	//
	if (dp[day][flag] != 0) {
		return dp[day][flag];
	}
	//
	if (flag == 0) {
		maximum = max(maximum, arr[day][1] + recur(day + 1, 1));
		maximum = max(maximum, arr[day][2] + recur(day + 1, 2));
		maximum = max(maximum, arr[day][3] + recur(day + 1, 3));

	}
	if (flag == 1) {
		maximum = max(maximum, arr[day][2] + recur(day + 1, 2));
		maximum = max(maximum, arr[day][3] + recur(day + 1, 3));
	}
	else if (flag == 2) {
		maximum = max(maximum, arr[day][1] + recur(day + 1, 1));
		maximum = max(maximum, arr[day][3] + recur(day + 1, 3));
	}
	else {
		maximum = max(maximum, arr[day][1] + recur(day + 1, 1));
		maximum = max(maximum, arr[day][2] + recur(day + 1, 2));
	}
	return dp[day][flag] = maximum;
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		for (int j = 1; j <= 3; j++)
		{
			scanf("%d", &arr[i][j]);
		}
		
	}
	
	int result = recur(0, 0);
	cout << result;
	return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> v(n);
  REP(i, n) cin >> v[i];

  vector<double> result(n);
  REP(i, n) {
    long long p = (v[i]*(v[i]+1)/2);
    result[i]= p*1.0 / v[i];
  }
  double ans = 0.0;
  double r = 0.0;
  REP(i, k) r += result[i];
  ans = r;
  for(int i=k; i < n; i++) {
    r = r - result[i-k] + result[i];
    ans = max(ans, r);
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
#include <iostream>                                             
#include <climits>                                              
#include <cstdio>                                               
using namespace std;                                            
                                                                
int main() {                                                    
  int n;                                                        
  cin >> n;                                                     
  int R[n];                                                     
  for (int t=0; t<n; t++) {                                     
    scanf("%d", &R[t]);                                         
  }                                                             
  int minv = R[0];                                              
  int maxv = -INT_MAX;                                          
  for (int j=1; j<n; j++) {                                     
    maxv = max(maxv,R[j]-minv);                                 
    minv = min(minv,R[j]);                                      
  }                                                             
  printf("%d\n", maxv);                                         
  return 0;                                                     
}                                                               
                                                                
                          

Measured memory_bytes: 4008
# -*- coding: utf-8 -*-

N = int(input())
table = [0, 0, 0, 0]
for i in range(N):
  a = input()
  if a == "AC":
    table[0] += 1
  elif a == "WA":
    table[1] += 1
  elif a == "TLE":
    table[2] += 1
  else:
    table[3] += 1

print("AC x {}".format(table[0]))
print("WA x {}".format(table[1]))
print("TLE x {}".format(table[2]))
print("RE x {}".format(table[3]))


    

Measured memory_bytes: 9140
def makelist(n, m):
    return [[0 for i in range(m)] for j in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()


N, M = map(int, input().split())
dp = makelist(N+1, N+1)

for _ in range(M):
    a, b = map(int, input().split())
    dp[a][b] += 1
    dp[b][a] += 1

for i in range(1, N+1):
    ans = 0
    for k in range(1, N+1):
        if k != i:
            ans += dp[i][k]
    print(ans)


Measured memory_bytes: 3064
K, A, B = [int(i) for i in input().split()]

if A+3>=B:
  print(K+1)
  exit()
  
else:
  if K>=(A-1):
    print(A + ((K-(A-1))//2) * (B-A) + (K-(A-1))%2)
    exit()
    
  else:
    print(K+1)
    exit()


Measured memory_bytes: 2940
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        input_inner!{$s, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($exp_input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                let start = std::time::Instant::now();
                let input = solve($exp_input);
                let end = start.elapsed();
                assert_eq!(input, $output, "{}.{:03}", end.as_secs(), end.subsec_millis());
                assert!(end.as_secs() <= 2, "expected_sec: {}sec, actual_sec: {}sec", 2, end.as_secs());
                assert!(end.as_secs() <= 1, "expected_sec: {}sec, actual_sec: {}sec", 1, end.as_secs());
                assert!(end.subsec_millis() <= 10, "expected_ms: {}ms, actual_ms: {}ms", 10, end.subsec_millis());
                assert!(end.subsec_millis() <= 2, "expected_ms: {}ms, actual_ms: {}ms", 2, end.subsec_millis());
            )*
        }
    };
}

test! {
r#"4
10 30 40 20"# => r#"30"#,

r#"2
10 10"# => r#"0"#,

r#"6
30 10 60 10 60 50"# => r#"40"#,
}

fn solve(src: &str) -> String {
    let mut src_iter = src.split_whitespace();
    input! {
        source = src_iter,
        n: usize,
        h: [isize; n],
    }

    let mut dp = vec![0; n + 1];
    dp[1] = isize::abs(h[0] - h[1]);

    for i in 2..n {
        let a = dp[i - 2] + isize::abs(h[i] - h[i - 2]);
        let b = dp[i - 1] + isize::abs(h[i] - h[i - 1]);
        dp[i] = std::cmp::min(a, b);
    }

    dp[n - 1].to_string()
}

Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define cpy(a,b) memcpy(a,b,sizeof(a))
#define prq priority_queue
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int a,b,c;
	cin>>a>>b>>c;
	if(a==b&&b==c)cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
import numpy as np


def main():
    N = int(input())
    A = [int(x) for x in input().split()]

    from collections import Counter

    c = Counter(A)

    num = {x: n*(n-1)//2 for x, n in c.items()}
    tot = sum(num.values())

    for x in A:
        n = c[x] - 1
        ans = tot - num[x] + n*(n-1)//2
        print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 42964
m, d = map(int, input().split())
cnt = 0
for i in range(1, m+1):
    for j in range(20, d+1):
        tenth = j // 10
        oneth = j % 10
        if oneth >= 2 and i == tenth * oneth:
            cnt +=1
        else:
            pass
print(cnt)


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

using namespace std;

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

	long long x;
	cin >> x;
	for (long long i = 1; ; i++) {
		if (i * (1 + i) / 2 >= x) {
			cout << i << '\n';
			break;
		}
	}

	return 0;
}



Measured memory_bytes: 256
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
from fractions import gcd
from copy import deepcopy
import math
import queue
import numpy as np
#import sympy as syp(素因数分解とか)
Mod = 1000000007
import sys
sys.setrecursionlimit(1000000) 
  
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

def factorial(i):
    if i == 1:
        return 1
    else:
        return i*factorial(i-1)
 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[py] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)




def main(): #startline--------------------------------------------
    n,m = list(map(int,input().split()))
    graph = defaultdict(list)
    uv = [list(map(int,input().split())) for i in range(m)]
    u = [uv[i][0] for i in range(m)]
    v = [uv[i][1] for i in range(m)]
    for i in range(m):
        graph[u[i]].append(v[i]+n)
        graph[u[i]+n].append(v[i]+2*n)
        graph[u[i]+2*n].append(v[i])
    s,t = map(int,input().split())
    dist = [False]*(3*n+1)

    def bfs():
        q = deque([s])
        dist[s] = 0
        while len(q):
            cur = q.popleft()
            if cur == t:
                return dist[cur] // 3
            for to in graph[cur]:
                if dist[to] == False:
                    dist[to] = dist[cur] + 1
                    q.append(to)
        return -1

    print(bfs())

if __name__ == "__main__":
    main() 
    
#endline===============================================
    

Measured memory_bytes: 104052
#include<bits/stdc++.h>
 
using namespace std;
 
 
#define IOS ios::sync_with_stdio(0); cin.tie(0), cout.tie(0)
 
 
#define ll long long int
#define ld long double
 
#define fr first
#define se second
 
 
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) (int)v.size()
#define sunq(v) sort(all(v));v.resize(distance(v.begin(),unique(all(v))))
 
 
#define pb push_back
#define mp make_pair
 
 
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define emla(a, val) memset(a, val, sizeof(a))
#define easm(a, b) (a + b - 1) /b 
 
#define PI 3.141592653589793238
 
 
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}

 

//bool valid(int i, int j){return i >= 0 && i < n && j >= 0 && j < m;}

string s;

int main() {
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  //clock_t z = clock();
  cin >> s;
  set<char>v(all(s));
  puts((sz(s) == sz(v)) ? "yes" : "no");
  //debug("Total Time: %.3f\n", (double)(clock() - z) / CLOCKS_PER_SEC);
  /*
  *try tricky test cases:
    -bounds
    -small input (0, 1)
    -big input
    -random tests
  */
  return 0;
}

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

using namespace std;

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

  int N,M; cin>>N>>M;
  string S; cin>>S;

  set<int> mass;
  for (int i = 0; i <= N; i++)
	if (S[i] == '0')
	  mass.insert(i);

  vector<int> most_left;
  most_left.push_back(N);
  int p = N;
  while (p > 0) {
	auto ml = *mass.lower_bound(p - M);
//    cerr << ml << endl;
	if (ml == p) {
	  cout << -1 << endl;
	  return 0;
	}
	most_left.push_back(ml);
	p = ml;
  }
  for (int i = most_left.size()-2; i >= 0; i--) {
	auto d = most_left[i] - most_left[i+1];
	cout << d << ' ';
  }
  cout << endl;

  return 0;
}


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

#define rep(i,n) for( (i)=0;(i)<(n);++(i) )
#define repr(i,n) for( (i)=(n);(i)>0;==(i) )
#define FOR(i,j,n) for( (i)=(j);(i)<(n);++(i) )
#define forr(i,j,n) for( (i)=(j);(i)>(n);--(i) )
#define debg(a) cout<<(a)<<endl;
#define INF 9999999
#define int long long 
#define str string
#define elif else if

int i,j,k;
int dx,dy;
int a,b,c,x,y,n,m,cnt=0,ans=0;
str s,t;

signed main(){ 
  cin>>n>>m;
  int ans=m;
  rep(i,n-1){
    ans*=(m-1);
  }
  debg(ans);
  return 0;
}


Measured memory_bytes: 256
#include<iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <bitset>
 
using namespace std;
typedef long long ll;
 
int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
 
 
    ll ans=0;
    ll anss =0;
    ll count=0;
    ll i,j;
  
    long double x;
    vector<ll> aa;
 
    ll Q,N;
    long double a, b;
    string S;
    cin >> a >> b >> x;
    ll flag=0;
    ll t1=0;
    ll t2=0;
  	
 
    if(x>=a*a*b/2){
      
     	long double dans = (atan2((2*b-2*x/a/a),a))*180/M_PI;
        cout <<std::setprecision(12)<< dans  << endl;
        return 0;
      
    }else{
     
     	long double dans =(atan2(b,(2*x/a/b)))*180/M_PI ;
        cout <<std::setprecision(12)<< dans << endl;
      	return 0;
      
    }
   
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

typedef unsigned long long ll;

int N;
vector<int> T[100003];
vector<int> C[100003];

ll depth[100003];

void dfs(int n, int pre, ll c) {
	//printf("%2d", n);
	depth[n] = c;
	for (int i = 0; i < T[n].size(); ++i) {
		if (pre == T[n][i])
			continue;
		dfs(T[n][i], n, c + C[n][i]);
	}
}

int main() {
	cin >> N;
	for (int i = 0; i < N-1; ++i)
	{
		int a,b,c;
		cin >> a >> b >> c;
		T[a].push_back(b);
		T[b].push_back(a);
		C[a].push_back(c);
		C[b].push_back(c);
	}
	int Q, K;
	cin >> Q >> K;
	dfs(K, 0, 0);
	for (int j = 0; j < Q; ++j) {
		int s, g;
		cin >> s >> g;
		cout << depth[s] + depth[g] << endl;
	}

}

Measured memory_bytes: 21376
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    private static Scanner sc;

    public static void main(String[] args) {
        Main instance = new Main();
        sc = instance.new Scanner();
        instance.solve();
    }

    private void solve() {
        try {
        	int a = sc.nextInt();
        	int b = sc.nextInt();
        	int k = sc.nextInt();
        	int pos = 0;
        	List<Integer> list = new ArrayList<>();
        	while(true) {
        		if(k != 0 && (b-a)/2 >= pos) {
        			if(a + pos == b - pos) {
        				list.add(pos, a + pos);
        				break;
        			}else {
        				list.add(pos, a + pos);
            			list.add(list.size()-pos, b - pos);
        			}
        			pos++;
        			k--;
        		}else {
        			break;
        		}
        	}
        	for(Integer num : list ) {
        		System.out.println(num);
        	}
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private class Scanner {
        String[] s;
        int i;
        BufferedReader br;
        String regex = " ";

        public Scanner() {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        @Override
        protected void finalize() throws Throwable {
            try {
                super.finalize();
            } finally {
                destruction();
            }
        }

        private void destruction() throws IOException {
            if (br != null) br.close();
        }

        public String next() throws IOException {
            if (i < s.length) return s[i++];
            String st = br.readLine();
            while (st == "") st = br.readLine();
            s = st.split(regex, 0);
            i = 0;
            return s[i++];
        }

        public int nextInt() throws NumberFormatException, IOException {
            return Integer.parseInt(next());
        }

        public Long nextLong() throws NumberFormatException, IOException {
            return Long.parseLong(next());
        }

        public Double nextDouble() throws NumberFormatException, IOException {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 21204
# -*- coding: utf-8 -*-
S = input()
Q = int(input())

reverse = False # 反転しているか

list_first =  []
list_last = []

for i in range(Q):
  query = input().split()
  if query[0] == '1':
    reverse = not reverse
  elif (query[1]=='1') == reverse: # query[0]==2 and ...
    list_last.append(query[2])
  else: # query[0]==2 and (query[1]==1) != reverse
    list_first.append(query[2])

if not reverse:
  for c in list_first[::-1] + list(S) + list_last:
    print(c, end='')
else:
  for c in list_last[::-1] + list(S)[::-1] + list_first:
    print(c, end='')

print('')

Measured memory_bytes: 9240
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int cnt[2][100005];

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		cnt[i%2][a]++;
	}
	P a1=P(-1,0),a2=P(-1,0);
	for(int i=0;i<=100000;i++){
		if(a1.first<cnt[0][i]){
			a1=P(cnt[0][i],i);
		}
		if(a2.first<cnt[1][i]){
			a2=P(cnt[1][i],i);
		}
	}
	if(a1.second==a2.second){
		P aa1=P(-1,0),aa2=P(-1,0);
		for(int i=0;i<=100000;i++){
			if(aa1.first<cnt[0][i] && i!=a1.second){
				aa1=P(cnt[0][i],i);
			}
			if(aa2.first<cnt[1][i] && i!=a2.second){
				aa2=P(cnt[1][i],i);
			}
		}
		if(a1.first-aa1.first>a2.first-aa2.first){
			a2=aa2;
		}else{
			a1=aa1;
		}
	}

	printf("%d\n",n-a1.first-a2.first);
	return 0;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

int N;
map<int, int> M;

int main(){
    int x;
    scanf("%d", &N);
    for (int i=1; i<=N; i++){
        scanf("%d", &x);
        M[x]++;
    }
    if (M.size() == 1 && M[0] == N){
        puts("Yes");
        return 0;
    }
    if (N % 3) {
        puts("No");
        return 0;
    }
    if (M.size() == 2 && M[0] == N / 3){
        puts("Yes");
        return 0;
    }
    if (M.size() == 3){
        for (pii k : M){
            if (k.second != N/3){
                puts("No");
                return 0;
            }
        }
        if ((M.begin()->first ^ (++M.begin())->first) != (++(++M.begin()))->first) puts("No");
        else puts("Yes");
    }
    else puts("No");
    return 0;
}


Measured memory_bytes: 3840
#include<iostream>
using namespace std;
int main(){
  int R;
  cin>>R;
  if(R<1200){
    cout<<"ABC"<<endl;
    return 0;
  }
  if(R>=1200 && R<2800){
    cout<<"ARC"<<endl;
  }else{
    cout<<"AGC"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define all(a) a.begin(), a.end()
#define pi acos(-1)
#define eps 1e-6
#define inf 1e14
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
 
const int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
const int dy[8] = {-1, 0, 1, -1, 1, 0, 1, -1};
const int maxn = 1e5; 
const int mod = 1e9 + 7;
const int maxa = 1e9 + 1;
 
int maxs(int &a, int b) { return a = max(a, b);}
int mins(int &a, int b) { return a = min(a, b);}
int mul(int a, int b) { return a * 1LL * b % mod;}
int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b;}
int sub(int a, int b) { return a >= b ? a - b : a - b + mod;}

int n, k;
ll sum1[maxn + 1], sum2[maxn + 1];
vector<ll> A[maxn + 1], mx1, mx2;

int P[25] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53,
           59, 61, 67, 71, 73, 79, 83, 89, 97};

int cnt[25], num[5];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 2; i <= n; ++i)
    {
        int tmp = i;
        for (int j = 0; j < 25; ++j)
            while (!(tmp % P[j]))
                tmp /= P[j], cnt[j]++;
    }

    for (int i = 0; i < 25; ++i)
    {
        int tmp[] = {2, 4, 14, 24, 74};
        for (int j = 0; j < 5; ++j)
            if (cnt[i] >= tmp[j])
                num[j]++;
    }
    
    ll res = num[3] * (num[0] - 1) +
        num[1] * (num[1] - 1) * (num[0] - 2) / 2 +
        num[2] * (num[1] - 1) +
        num[4];

    cout << res;
}


Measured memory_bytes: 2560
// includes
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
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(a > b){a = b; return 1;} return 0;}

typedef struct UnionFind_ {
  vector<int> par;
  vector<int> rank_;
  vector<int> size_;
  UnionFind_(int n): rank_(n, 0), size_(n, 1) {
    for(int i = 0; i < n; i++)par.push_back(i);
  }
  int find(int x) {
    if(par[x] == x)return x;
    else return par[x] = find(par[x]);
  }
  bool same(int x, int y) {
    if(find(x) == find(y))return true;
    else return false;
  }
  bool unite(int x, int y){
    int xp = find(x);
    int yp = find(y);
    if(xp == yp)return false;
    if(rank_[xp] > rank_[yp]){
      par[yp] = xp;
      size_[xp] += size_[yp];
    }
    else if(rank_[xp] < rank_[yp]){
      par[xp] = yp;
      size_[yp] += size_[xp];
    }
    else {
      par[yp] = xp;
      rank_[xp]++;
      size_[xp] += size_[yp];
    }
    return true;
  }
} UnionFind;

int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<P> edge(m);
  rep(i, m)cin >> edge[i].first >> edge[i].second, edge[i].first--, edge[i].second--;
  vector<ll> ans(m);
  ll curr = (ll)n * (ll)(n - 1) / 2;
  UnionFind uf(n);
  for(int i = m - 1; i >= 0; i--){
    ans[i] = curr;
    int a = edge[i].first, b = edge[i].second;
    if(!uf.same(a, b)){
      curr -= (ll)uf.size_[uf.find(a)] * (ll)uf.size_[uf.find(b)];
      uf.unite(a, b);
    }
  }
  assert(curr == 0);
  for(int i = 0; i < m; i++){
    cout << ans[i] << endl;
  }
	return 0;
}


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


int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int>vec;
    int cnt1 = 0, cnt2 = 0, cnt4 = 0;
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        vec.push_back(x);
        if(vec[i] % 4 == 0) cnt4 ++;
        else if(vec[i] % 2 != 0)    cnt1++;
        else if(vec[i] % 2 == 0)    cnt2++;
    }
    if(cnt2 == 0)
    {
        if(cnt4 + (n & 1) >= cnt1)  puts("Yes");
        else puts("No");
    }
    else
    {
        if(cnt4 >= cnt1)    puts("Yes");
        else puts("No");
    }

    return 0;
}


Measured memory_bytes: 892
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
int N, M;
char a[51][51];
char b[51][51];
bool check(int y, int x) {
  if (y + M > N || x + M > N) {
    return false;
  }
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (a[y + i][x + j] != b[i][j]) {
        return false;
      }
    }
  }
  return true;
}

int main(int argc, const char * argv[]) {
  cin >> N >> M;
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> a[i][j];
    }
  }
  
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      cin >> b[i][j];
    }
  }
  
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if(check(i, j)) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define INF 2000000000
#define INFL 9000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

int main() {
	/*
	ifstream ifs(".in");
	ofstream ofs("A1.txt");
	cin.rdbuf(ifs.rdbuf());
	cout.rdbuf(ofs.rdbuf());
	*/
	ll N, K;
	cin >> N >> K;
	vP p(N);
	rep(i, N) {
		int a, b;
		cin >> a >> b;
		p[i] = mp(a, b);
	}
	sort(all(p));
	ll num = 0;
	rep(i, N) {
		num += p[i].second;
		if (num >= K) {
			cout << p[i].first << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<double> vd;
typedef vector<vd> vvd;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())
int num[3][3];
int main(){
  int n,sum=0;bool ok=true;
  cin>>n;
  vll l(n);
  REP(i,n){
    cin>>l[i];sum+=l[i];
  }
  REP(i,n){
    if(l[i]*2>=sum){ok=false;}
  }
  if(ok){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

// マクロ
/// ループ
#define FOR(i,a,b) for(ll i=a;i<(ll)(b);++i)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);--i)
#define REP(i,n) FOR(i,0,n) 
#define REPD(i,n) FORD(i,n,0)
/// コンテナ用
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
/// 定数
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //10^5 配列の最大のRANGE
/// 略記
#define PB push_back
#define MP make_pair
#define F first
#define S second

auto main(int argc, char *argv[]) -> signed {
    int n;
    cin >> n;
    vector<ll> a;
    REP(i,n) {
        ll x;
        cin >> x;
        a.PB(x);
    }


    ll cnt = 0;
    while(true) {
        vector<ll> b;
        for (ll x : a) {
            if (x % 2 == 0)
                b.PB(x >> 1);
        }
        if (SIZE(a) == SIZE(b)) {
            a = b;
            cnt++;
        }
        else break;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>

using namespace std;

#define FAST       			ios_base :: sync_with_stdio(false); cin.tie(NULL); 
#define endl "\n"

typedef long long int  ll;
typedef unsigned long long int ull;


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

	    for(int i=0 ; 4*i<=n ; i++)
	    {
	        int temp = n - 4*i;
	        if(temp%7 == 0)
	        {
	            cout << "Yes";
	            return 0;
	        }
	    }
	cout << "No";
	return 0;
}


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

void cout_vector(vector <int> v){
	for(vector<int>::iterator it = v.begin(); it !=prev(v.end()); it++) cout<<*it<<" ";
	cout<<*prev(v.end());
	cout<<endl;	
}

int sum_vector(vector <int> v){
	return accumulate(v.begin(), v.end(),0);
}

void solve(){
	
}

int main()
{
	int n,k,c;
	cin>>n>>k;
	while(n--){
		cin>>c;
		a.push_back(c);
	}
	sort(a.begin(),a.end());
	int left = 1;
	int right= a.back();
	while (right>left){
		int mid=(left+right)/2;
		int need = 0;
		
		for(int num:a){
			need+=ceil(((double)num)/mid)-1;
			/*int ne = num/mid;
			if(num%mid) ne++;
			ne--;
			need+=ne;*/
		}
		//cout<<left<<" "<<right<<" "<<mid<<" "<<need<<endl;
		if(need>k) left=mid+1;
		if(need<=k) right=mid;
		
		 
		
	}
	cout<<right;
	
	
	
	return 0;
}



Measured memory_bytes: 4228
#include <bits/stdc++.h>
#define mod 1000000007
#define F first
#define S second
#define PB push_back
#define MP make_pair

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    cin >> k;
    string s;
    cin >> s;
    if (s.length() <= k)
    {
        cout << s;
    }
    else
    {
        cout << s.substr(0, k) << "...";
    }
    return 0;
}

Measured memory_bytes: 3644
let charl_of_string s =
  let rec exp i l =
    if i < 0 then l else exp (i - 1) (s.[i] :: l) in
  exp (String.length s - 1) []

let tabulate n f =
  let rec loop acc cnt =
    if cnt = n then List.rev acc
    else loop (f () :: acc) (cnt + 1)
  in loop [] 0

(* let l = tabulate n (fun () -> Scanf.scanf "%d\n" (fun a -> a)) *)


(* let sl = Str.split (Str.regexp " ") @@ read_line () *)
(* let il = List.map int_of_string sl *)
(* let ar = Array.of_list il *)

(* let a, b = Scanf.scanf "%d %d\n" (fun a b -> a, b) *)
(* let () = Printf.printf "%d %f\n" 2 3.5 *)


let rec calc a b c = function
    'a' -> (
    match a with
      [] -> "A"
    | h :: a' -> calc a' b c h
    )
  | 'b' -> (
      match b with
        [] -> "B"
      | h :: b' -> calc a b' c h
    )
  | 'c' -> (
      match c with
        [] -> "C"
      | h :: c' -> calc a b c' h
    )
  | _ -> "error"


let () =
  let a = charl_of_string @@ read_line () in
  let b = charl_of_string @@ read_line () in
  let c = charl_of_string @@ read_line () in
  print_endline @@ calc a b c 'a'


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18

int main() {
    int N;
    cin >> N;
    unordered_map<int, int> mp;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        mp[a]++;
    }
    string ans;
    if (mp.size() == 1) {
        int X = mp.begin()->first;
        if ((1 <= X && X <= N / 2) || X == N - 1)
            ans = "Yes";
        else
            ans = "No";
    }
    if (mp.size() > 2) ans = "No";
    if (mp.size() == 2) {
        pair<int, int> p1 = *mp.begin();
        pair<int, int> p2 = *(++mp.begin());
        if (p1.first < p2.first) swap(p1, p2);
        if (p1.first - p2.first > 1 || p1.second == 1)
            ans = "No";
        else {
            int m = p1.second / 2, x = p2.second, X = p1.first;
            ans = (x + 1 <= X && X <= x + m ? "Yes" : "No");
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4388
program jihanki
  implicit none
  integer :: d

  read(*,*)d
  if (d==25) then
     write(*,*)'Christmas'
  elseif (d==24) then
     write(*,*)'Christmas Eve'
  elseif (d==23) then
     write(*,*)'Christmas Eve Eve'
  else
     write(*,*)'Christmas Eve Eve Eve'
  end if
  
end program jihanki


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <string.h>
using namespace std;

const int INF = 1e+9;
typedef pair<int, int> P;

int memo[50010];
int N, M, d[50];

int rec(int sum){
	if(sum == 0)
		return 0;
	if(sum < 0)
		return INF;
	if(memo[sum] != -1)
		return memo[sum];
		
	int res = INF;
	for(int i = 0; i < M; ++i)
		res = min(res, rec(sum - d[i]) + 1);
	return memo[sum] = res;
}

int main() {
	memset(memo, -1, sizeof(memo));
	cin >> N >> M;
	
	for(int i = 0; i < M; ++i)
		cin >> d[i];
	
	cout << rec(N) << endl;
	return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
int main() {
    ios::sync_with_stdio(false);
    double a,b,x;
    cin>>a>>b>>x;


    if(x*2<=a*a*b){
        double y=x*2/a/b;
        cout<<fixed<<setprecision(15)<<90-atan(y/b)/acos(-1)*180;
        return 0;
    }
    double y=x*2/a/a-b;
    cout<<fixed<<setprecision(15)<<90-atan(a/(b-y))/acos(-1)*180;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <iterator>
#include <functional>
#include <vector>
#include <iomanip>
#include <numeric>
using namespace std;

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

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

	int cnt = 0;
	int half = N / 2;
	if (d[half] == d[half - 1])
	{
	}
	else
	{
		cnt = d[half] - d[half - 1];
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a,b;
    char str[2];
    scanf("%d %s %d", &a,&str,&b);

    if (str[0] == '+'){
        printf("%d", a+b);
    }
    if (str[0] == '-'){
        printf("%d", a-b);
    }

    return 0;
}


Measured memory_bytes: 128
#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,a;
double dp[3030],ans;
int main()
{
	cin>>n;
	dp[0]=1.0;
	for(int i=0;i<n;i++)
	{
		while(getchar()!='.');
		cin>>a;
		for(int j=i;j>=0;j--)
		{
			dp[j+1]+=dp[j]*a/100.0;
			dp[j]=dp[j]*(100-a)/100.0;
		}
	}
	for(int i=n/2+1;i<=n;i++)
	{
		ans+=dp[i];
	}
	printf("%.10f\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
using namespace std;
int main(){
    char num[1001];
    while(1){
        int sum = 0;
        scanf("%s",num);
        if(num[0]=='0') break;
        for(int i=0;i<strlen(num);i++){
            sum+=num[i]-'0';
        }
        printf("%d\n",sum);
    }
    return 0;
}

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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    complex<double> x = polar(a, (M_PI / 6.0) * h + (M_PI / 360.0) * m);
    complex<double> y = polar(b, (M_PI / 30) * m);
    print(abs(x - y));
    return 0;
}

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

int main() {
	int room[10][10][20]={0};
	int n,b,f,r,v;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>b>>f>>r>>v;
		room[b][f][r]=room[b][f][r]+v;
	}
	for(int i=1;i<5;i++){
		for(int j=1;j<4;j++){
			for(int k=1;k<11;k++){
				cout<<" "<<room[i][j][k];
			}
			cout<<endl;
		}
		if(i<4){
		cout<<"####################"<<endl;
		}

		}
	return 0;
}




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

#define pb push_back
typedef long long int ll;
typedef vector<ll> vl;
typedef map<ll,ll> ii;
typedef vector<vl> vvl;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll t;cin>>t;
    map<ll,vl> d;
    ll p=0;
    ll w;
    vector<pair<ll,ll>> lol;
    t--;
    while(t--){
        ll a,b;cin>>a>>b;
        d[a].pb(b);
        d[b].pb(a);
        lol.pb({a,b});
        ll x=d[a].size();
        ll y=d[b].size();
        ll c=max(x,y);
        if(c>p){
            if(x>y) w=a;
            else w=b;
            p=c;    
        }
    }
    queue<ll> q;q.push(w);
    ii vis;
    vis[w]=1;
    map<pair<ll,ll>,ll> m;
    vl r;
    for(ll i=1;i<=p;i++){
        r.pb(i);
    }
    queue<ll> v;v.push(0);
    while(!q.empty()){
        ll a=q.front();q.pop();
        ll b=v.front();v.pop();
        for(ll i:d[a]){
            if(!vis[i]){
                q.push(i);
                m[{a,i}]=r[b];
                m[{i,a}]=r[b];
                b++;
              	b%=p;
                v.push(b);
                vis[i]=1;
            }
        }
    }
    cout<<p<<"\n";
    
    for(pair<ll,ll> i:lol){
        cout<<m[{i.first,i.second}]<<"\n";
    }
    return 0;
}
    


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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

int A[15], n, m;
struct t{int a, c, d;};
vector<t> inv[15];
int cb = -1;
int cur = 0;
void dfs(int l, int at) {
	if(at == n+1) {
		cb = max(cb, cur);
		return;
	}
	for(int i=l; i<=m; i++) {
		int pc = cur;
		for(auto& k:inv[at]) {
			if(i - A[k.a] == k.c) cur += k.d;
		}
		A[at] = i;
		dfs(i, at+1);
		cur = pc;
	}
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int Q; gi(n), gi(m), gi(Q);
	while(Q--) {
		int a, b, c, d; gi(a), gi(b), gi(c), gi(d);
		inv[b].pb({a, c, d});
	}
	dfs(1, 1);
	print(cb);
}


Measured memory_bytes: 3660