akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(int i=(a);i<(b);++i)

#define huge 1000000007
typedef long long ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll M = 0;
	//ll M = 0;
	ll a[200] = {};
	ll b[200] = {};
	ll v[3] = {};
	//ll *a, *b, *x;
	string S,T,U;
	ll count = 0;
	ll sum = 0;
	ll min = 100000;
	ll max = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;
	
	vector<int> c(3);
	//char p;
	cin >> c[0] >> c[1] >> c[2];
	//cin >> S;
	
	//a = (ll *)malloc(M * sizeof(ll));
	//b = (ll *)malloc(M * sizeof(ll));
	//vector<pair<int,int>> ch(N+1);
	//vector<bool> flag(N);
	
	//count--;
	//	cout << X << endl;
	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;

	if ((c[1] - c[0]) % 2 == 0 && (c[2] - c[1]) % 2 == 0) {
		count += c[1] - c[0];
		count += (c[2] - c[1])*2;
		count /= 2;

	}
	else if ((c[1] - c[0]) % 2 != 0 && (c[2] - c[1]) % 2 == 0) {
		count++;
		count += (c[2] + 1 - c[1]) / 2;
		count += (c[2] + 1 - c[0]) / 2;
	}
	else if ((c[1] - c[0]) % 2 == 0 && (c[2] - c[1]) % 2 != 0) {
		count++;
		count += (c[1] - c[0]) / 2;
		
	}
	else {
		count++;
		count++;
		count += (c[2] - (c[1]+1)) / 2;
		//cout << ((c[1] + 1) - c[0]) / 2 << endl;
		count += ((c[2]) - c[0]) / 2;
		//cout << count << endl;
	}

	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/

	
	cout << count << endl;


	return 0;

}

ll gcd(ll a, ll b) {
	ll c;
	c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}

	return b;
}



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

int main() {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	int todo = min(c, a-b);
	c-=todo;
	printf("%d\n", c);
	
	return 0;
}

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

using namespace std;

int main() {
	int a, res;
	char op;

	cin >> a;
	res = a;
	while (true) {
		cin >> op;
		if (op == '=') {
			break;
		}
		cin >> a;
		switch (op) {
		    case '+':res += a; break;
		    case '-':res -= a; break;
		    case '*':res *= a; break;
		    case '/':res /= a; break;
		}
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 3100
n=int(input())
s=[]
ha={}

for i in range (n):
    s.append(input())
    if (s[i] not in ha.keys()):
        ha[s[i]]=1
    else:
        ha[s[i]]=ha[s[i]]+1

ans=sorted(ha.items(),key=lambda x:x[1], reverse=True)

k=ans[0][1]
i=0
while (i< len(ans) and ans[i][1]==k):
    i+=1

ans=ans[:i]
ans.sort()
for ss in ans:
    print(ss[0])


Measured memory_bytes: 46468
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
   
//#include <x86intrin.h>
#include <bits/stdc++.h>   
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define al 0x3F3F3F3F
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;

const double pi = acos (-1.0);
const double eps = 1e-7;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n;
ll a[N], res, sum;
bool used[N], is[61];

inline void boost () {                    
   ios_base :: sync_with_stdio (NULL);
   cin.tie (NULL), cout.tie (NULL);          
}                                                     

inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> a[i], sum ^= a[i];   
   for (int bit = 60; bit >= 0; bit --) {
      if (is[bit]) continue;
      if (!(sum & (1ll << bit))) continue;
      for (int i = 1; i <= n; i ++)
         if (a[i] & (1ll << bit))
            a[i] -= (1ll << bit);
   }                                               
   for (int bit = 60; bit >= 0; bit --) {
      int pos = -1;
      for (int i = 1; i <= n; i ++) {
         if (used[i]) continue;
         if (a[i] & (1ll << bit)) {
            if (pos == -1 || a[pos] < a[i])
               pos = i;
         }
      }
      if (pos != -1) {
         used[pos] = 1;
         for (int z = bit; z >= 0; z --)
            if ((1ll << z) & a[pos])
               is[z] = 1;
         for (int i = 1; i <= n; i ++)
            if (i != pos && ((a[i] & (1ll << bit)) > 0))
               a[i] ^= a[pos];
      }
   }
   for (int i = 1; i <= n; i ++) res ^= a[i];
   cout << res + (sum ^ res);
}

main () {                                       
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}
                          

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
const ll INF = 1<<30;
const ll MOD = 1e9+7;
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; }

vector<vector<ll> > dp(3030,vector<ll>(3030,0));

int main(){
    ll N, T; cin >> N >> T;
    vector<pair<ll,ll> > AB(N);
    rep(i,N){ ll a,b; cin >> a >> b; AB[i] = make_pair(a,b); }
    sort(AB.begin(),AB.end());

    dp[0][0] = 0;
    ll res = 0;
    rep(i,N){
        rep(j,T){
            chmax(dp[i+1][j], dp[i][j]);
            if(j-AB[i].first>=0){
                chmax(dp[i+1][j], dp[i][j-AB[i].first]+AB[i].second);
            }
        }
        if(i!=N-1) chmax(res, dp[i+1][T-1] + AB[i+1].second);
    }
    cout << res << endl;
}

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int t; cin>>t; while(t--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const uint64_t linf= 1000000000000000000;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n;
    cin>> n;
    uint64_t a[n], sum=1;

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


    sort(a, a+n);

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

        if(sum== 0)
        {
            cout<< 0<< '\n';
            return 0;
        }

        if(a[i]> (linf/ sum))
        {
            cout<< -1<< '\n';
            return 0;

        }

        sum*= a[i];

    }

    cout<< sum << '\n';

    return 0;
}




Measured memory_bytes: 4428
function main()
    A, B, H, M = [parse(Int, s) for s in split.(readline())]
    minutes = 60 * H + M
    theta0_A = (minutes / 60) / 12 * 2pi
    theta0_B = (minutes % 60) / 60 * 2pi
    theta_A = mod2pi(pi/2 - theta0_A)
    theta_B = mod2pi(pi/2 - theta0_B)
    x_A, y_A = A*cos(theta_A), A*sin(theta_A)
    x_B, y_B = B*cos(theta_B), B*sin(theta_B)

    println(sqrt((x_A - x_B)^2 + (y_A - y_B)^2))
end

main()


Measured memory_bytes: 211572
N = gets.to_i
as = gets.split.map(&:to_i)

ans = 0
loop do
    changed = false
    N.times do |i|
        if as[i] >= N
            t = as[i]/N
            ans += t
            changed = true
            as[i] -= t*N
            N.times do |j|
                as[j] += t if i != j
            end
        end
    end
    break unless changed
end
puts ans

Measured memory_bytes: 1788
#!/usr/bin/python3
# -*- coding:utf-8 -*-

from collections import Counter

def main():
  counts = Counter(list(input().strip()))
  if len(counts) == 2 and all([v==2 for k, v in counts.items()]):
    print('Yes')
  else:
    print('No')

if __name__=='__main__':
  main()



Measured memory_bytes: 3316
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    H=list(map(int,input().split()))
    dp=[-1]*n #足湯iに着くまでに支払うコストの総和の最小値
    dp[0]=0
    for i in range(n):
        for j in (1,2):
            ni=i+j
            if ni>=n:continue
            if dp[ni]==-1:
                dp[ni]=dp[i]+abs(H[ni]-H[i])
            else:
                dp[ni]=min(dp[ni],dp[i]+abs(H[ni]-H[i]))
    print(dp[n-1])


if __name__=='__main__':
    main()

Measured memory_bytes: 13924
import java.util.*;
import java.util.function.*;
import java.lang.*;
import java.io.*;
class MathLib{
    static long gcd(long a, long b){
        if(a<0) a = -a;
        if(b<0) b = -b;
        if(a>b){
            long t = a;
            a = b;
            b = t;
        }
        while(a>0){
            long r = b%a;
            b = a;
            a = r;            
        }
        return b;
    }
    
    static boolean isPrime(long N){
        if(N%2==0) return false;
        for(long i=3; i*i<=N; i+=2){
            if(N%i==0) return false;
        }
        return true;
    }
    static List<Long> divisorList(long N){
        LinkedList<Long> ans = new LinkedList<>();
        for(long i=3 + (long)(Math.sqrt(N)); i>0; i--){
            if(i*i>N) continue;
            if(i*i==N) ans.add(i);
            else if(N%i==0){
                ans.addFirst(i);
                ans.addLast(N/i);
            }
        }
        return ans;
    }
    static List<Integer> primeList(int max){
        boolean[] prime = new boolean[max+1];
        Arrays.fill(prime, true); prime[0]=false; prime[1]=false;
        ArrayList<Integer> list = new ArrayList<>();
        for(int n=2; n<=max; n++) if(prime[n]){
            list.add(n);
            if(n*n<=max) for(int m=2*n; m<=max; m+=n) prime[m]=false;
        }
        return list;
    }
}
public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for(int n=0; n<N; n++) A[n]=sc.nextInt();
        Arrays.sort(A);

        int ans = 0;
        boolean[] canBeUsed = new boolean[1000001];
        Arrays.fill(canBeUsed, true);
        for(int n=0; n<N; n++){
            boolean proper = true;
            if(n-1>=0 && A[n]==A[n-1]) proper = false;
            if(n+1<N && A[n]==A[n+1]) proper = false;
            proper &= canBeUsed[A[n]];
            if(proper){
                ans++;                
            }
            if(canBeUsed[A[n]]){
                for(int d=1; A[n]*d<=1000000; d++) canBeUsed[A[n]*d]=false;
            }
        }
        
        System.out.println(ans);
    }
}


Measured memory_bytes: 61116
#include "bits/stdc++.h"
using namespace std;
const int maxn = 200100;
long long x[maxn], s[maxn], ps[maxn];
int main(){
    int n;
    scanf("%d", &n);
    for(int e = 1; e <= n; e++) scanf("%lld %lld", x + e, s + e);
    for(int e = 1; e <= n; e++) ps[e] = ps[e-1] + s[e];
    set<long long> values;
    long long ans = 0;
    for(int e = 1; e <= n; e++){
        values.insert(-ps[e-1] + x[e]);
        long long match = *(--values.end());
        ans = max(ans, ps[e] - x[e] + match);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 14336
#include <iostream>
using namespace std;
int main(void){
        string s;
        int c = 0;
        cin >> s;
        if(s[0] == '1') ++c;
        if(s[1] == '1') ++c;
        if(s[2] == '1') ++c;
        cout << c << endl;
        return 0;
}

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

int main() {
	int N, K; cin >> N >> K;
	vector<int>A(K);
	for (int i = 0; i < K; i++) cin >> A.at(i);
	sort(A.begin(), A.end(), greater<int>());
	for (int i = 1; i < K; i++) {
		A.at(0) -= A.at(i);
	}
	if (A.at(0) <= 0) cout << 0 << endl;
	else cout << A.at(0) - 1 << endl;
}

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

c0 = 0
c1 = 0
c2 = 0
c3 = 0

for i in range(n):
    judge = input()
    if judge == "AC":
        c0 += 1
    elif judge == "WA":
        c1 += 1
    elif judge == "TLE":
        c2 += 1
    else:
        c3 += 1

print("AC x" ,c0)
print("WA x" ,c1)
print("TLE x" ,c2)
print("RE x" ,c3)

Measured memory_bytes: 9212
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;
const ll LL_MAX (1LL<<60);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

int main()
{
    ll a, b, k;
    cin >> a >> b >> k;
    k--;

    ll d ((a > b)? a : b); 
    vector<ll> factors;
    rep(i, 1, d+1)
    {
        if (a%i == 0 && b%i == 0)
            factors.push_back(i);
    }

    reverse(factors.begin(), factors.end());

    cout << factors[k] << endl;

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> cnt(100010, 0);
  for(int i=0; i<N; ++i) {
    int tmp;
    cin >> tmp;
    cnt[tmp] += 1;
  }
  int ans = 0;
  for(int i=0; i<100005; ++i) {
      int tmp = cnt[i] + cnt[i+1] + cnt[i+2];
      if(tmp > ans) ans = tmp;
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 640
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Char
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Debug.Trace

solve :: Int -> Int -> Int -> Int -> Int
solve !a !b !c !d = calc b - calc (a - 1)
  where calc t = t - t `div` c - t `div` d + t `div` (lcm c d)

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  (a, b, c, d) <-
    (\vec -> (vec VU.! 0, vec VU.! 1, vec VU.! 2, vec VU.! 3))
    .   VU.unfoldrN 4 readInt
    <$> B.getLine
  print $ solve a b c d


Measured memory_bytes: 380
fn main() {
    let _ = read::<usize>();
    let (t, a) = {
        let v = read_vec::<f64>();
        (v[0], v[1])
    };
    let heights = read_vec::<f64>();

    let mut mi: (usize, f64) = (usize::max_value(), 100000.0);
    for (i, h) in heights.iter().enumerate() {
        let ave = t - h * 0.006;
        let d = (a - ave).abs();
        if mi.1 > d {
            mi = (i+1, d);
        }
    }

    println!("{}", mi.0);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
#define all(v) v.begin(),v.end()
typedef vector<int> vi;
typedef vector<ll> vl;
ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
ll com(ll n,ll r){
    ll x=1,y=1;
    ll tmp=n;
    while(tmp>=n-r+1){
        x=x*tmp%mod;
        tmp--;
    }
    while(r>0){
        y=y*r%mod;
        r--;
    }
    return x*rep_jijo(y,mod-2)%mod;
}
struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }

  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

vector<int>bro[100001];

int main (){
    int n,m,k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    vi fri(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        fri[a]++;fri[b]++;
        uf.unite(a,b);
    }
    rep(i,k){
        int c,d;
        cin >> c >> d;
        c--;d--;
        bro[c].push_back(d);
        bro[d].push_back(c);
    }
    rep(i,n){
        int ans=uf.size(i)-fri[i]-1;
        for(int x:bro[i]){
            if(uf.same(i,x)) ans--;
        }
        cout << ans;
        if(i!=n-1) cout << " ";
        else cout << endl;
    }

    return 0;
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
 
int main() {
 
    int n;
    cin >> n;
    int h[n];
    rep(i, n) cin >> h[i];
    
    int max = 0;
    int count = 0;
    rep(i, n)
    {
        if (n-i < max)
            break;
            
      count = 0;
        for ( int j = i; j < n-1; j++)
        {
            if ( h[j] >= h[j+1])
                count++;
            else
                break;
        }
        if (max < count)
            max = count;
    }
    cout << max;
    return 0;
}

Measured memory_bytes: 640
//AC済 バチャ用再提出
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
    int n, h;
    vector<int> a;
    vector<int> b;
    cin >> n >> h;
    int amax = 0;
    for(int i = 0; i < n; i++){
        int in1, in2;
        cin >> in1 >> in2;
        a.push_back(in1);
        b.push_back(in2);
        if(a[amax] < a[i]){
            amax = i;
        }
        if(a[amax] == a[i] && b[amax] > b[i]){
            amax = i;
        }
    }
    int last = b[amax];
    b[amax] = 0;
    int answer = 0;
    sort(b.begin(), b.end());
    while(b[b.size() - 1] > a[amax]){
        h -= b[b.size() - 1];
        answer++;
        b.pop_back();
        if(h <= 0){
            cout << answer << endl;
            return 0;
        }
    }
    if(h <= last){
        answer++;
        cout << answer << endl;
        return 0;
    }
    if(last > a[amax]){
        answer += (h - last) / a[amax];
        if((h - last) % a[amax] != 0){
            answer++;
        }
        answer++;
    } else {
        answer += h / a[amax];
        if(h % a[amax] != 0){
            answer ++;
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 1276
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<vector>
using namespace std;

const int maxn=1005+20;
int visit[2000505],n;
double x[2000505],y[2000055];
double r[2000505];
double dist[2000550],z[maxn][maxn];

void SPFA(int s)
{
	queue<int>q;
	for(int i=1;i<=n;i++)
		dist[i]=1e10;
	memset(visit,0,sizeof(visit));
	while(!q.empty()) 
		q.pop();
	dist[s]=0;
	visit[s]=1;
	q.push(s);
	while(!q.empty())
	{
		int v=q.front();
		q.pop();
		visit[v]=0;
		for(int i=1;i<=n;i++)
		{
			if(dist[i]>dist[v]+z[v][i])
			{
				dist[i]=dist[v]+z[v][i];
				if(!visit[i])
				{
					visit[i]=1;
					q.push(i);
				}
			}
		}
	}
}
int main()
{
	while(scanf("%lf%lf%lf%lf",&x[1],&y[1],&x[2],&y[2])!=EOF)
	{
		scanf("%d",&n);
		n+=2;
		r[1]=r[2]=0;
		z[1][2]=z[2][1]=sqrt((x[1]-x[2])*(x[1]-x[2])+(y[1]-y[2])*(y[1]-y[2]));
		for(int i=3;i<=n;i++)
			scanf("%lf%lf%lf",&x[i],&y[i],&r[i]);
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				z[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
				z[i][j]-=r[i]+r[j];
				if(z[i][j]<0)
					z[i][j]=0;
			}
		}
		SPFA(1);
		printf("%.10f\n",dist[2]);
	}
	return 0;
}

Measured memory_bytes: 25472
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  vii data(3,vi(3));
  vii ans(3,vi(3,0));
  rep(i,3) {
    rep(j,3) cin >> data[i][j];
  }
  int n;
  cin >> n;
  rep(i,n) {
    int a;
    cin >> a;
    rep(j,3) {
      rep(k,3) {
        if(data[j][k] == a) ans[j][k] = 1;
      }
    }
  }
  int check = 0;
  rep(i,3) {
    int count = 0;
    rep(j,3) {
      count += ans[i][j];
    }
    if(count == 3) check++;
  }
  rep(i,3) {
    int count = 0;
    rep(j,3) {
      count += ans[j][i];
    }
    if(count == 3) check++;
  }
  if(ans[0][0] == 1 && ans[1][1] == 1 && ans[2][2] == 1) check++;
  if(ans[2][0] == 1 && ans[1][1] == 1 && ans[0][2] == 1) check++;
  if(check > 0) cout << "Yes" << "\n";
  else if(check == 0) cout << "No" << "\n";
}

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

int main(){
	int n,x;
	cin >> n;
	for(int i=1;i<=n;i++){
		if(i % 3 == 0){
			cout << " " << i;
			continue;
		}
		x = i;
		while(x > 0){
			if(x % 10 == 3){
				cout << " " << i;
				break;
			}
			x = x / 10;
		}
	}
	cout << endl;
}

Measured memory_bytes: 1160
#include<stdio.h>

int main(void){
    int i,j,n,m,max=0,f,sum;
    int a[1000];

    while(1){
        scanf("%d %d",&n,&m);
        if(n==0&&m==0) break;
        for(i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        for(i=0;i<n-1;i++){
            for(j=i+1;j<n;j++){
                sum=a[i]+a[j];
                if(sum<=m&&sum>max){
                    max=sum;
                    f=1;
                }
            }
        }
        if(f==1){
            printf("%d\n",max);
            max=0;
            f=0;
        }else{
            printf("NONE\n");
            max=0;
        }
    }

    return 0;
}


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

#define all(a)  (a).begin(),(a).end()
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define exist(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define range(i,a,b) for(int (i)=(a);(i)<(b);++(i))
#define rep(i,n)  range(i,0,n)
#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef vector<int> vi;
typedef long long ll;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

random_device rd;
mt19937 mt(rd());
//uniform_int_distribution<int> dice(1,6);
//uniform_real_distribution<double> score(0.0,10.0);

const int vmax=362880;
int dist[vmax];

map<int,int> convert;
vector<int> graph[vmax];

typedef tuple<int,int> state;

int dijkstra(int s,int t,int w,int h){
	rep(i,vmax) dist[i]=inf;
	priority_queue<state,vector<state>,greater<state>> q;
	q.push(state(0,s));
	dist[s]=0;
	while(!q.empty()){
		int cost,v;tie(cost,v)=q.top();q.pop();
		if(v==t) break;
		rep(i,4){
			int ncost=cost,nv=graph[v][i];
			if(i<2)
				ncost+=w;
			else
				ncost+=h;
			if(dist[nv]>ncost) dist[nv]=ncost,q.push(state(ncost,nv));
		}
	}
	return dist[t];
}

int main(void){
	int a[9];
	rep(i,9) a[i]=i;
	int counter=0;
	do{
		int idx=0;
		rep(i,9) idx=9*idx+a[i];
		convert[idx]=counter++;
	}while(next_permutation(a,a+9));

	rep(i,9) a[i]=i;
	do{
		int idx=0;
		rep(i,9) idx=9*idx+a[i];
		rep(d,4){
			int b[9],p,q;
			rep(i,9) b[i]=a[i];
			rep(i,9) if(b[i]==0) p=i;
			switch(d){
				case 0:
					q=(p+8)%9;
					break;
				case 1:
					q=(p+1)%9;
					break;
				case 2:
					q=(p/3+2)%3*3+p%3;
					break;
				case 3:
					q=(p/3+1)%3*3+p%3;
					break;
			}
			swap(b[p],b[q]);
			int nidx=0;
			rep(i,9) nidx=9*nidx+b[i];
			graph[convert[idx]].push_back(convert[nidx]);
		}
	}while(next_permutation(a,a+9));

	int w,h;
	while(cin >> w >> h,w|h){
		int s=0,t=0;
		rep(i,9){
			int in;
			cin >> in;
			s=9*s+in;
		}
		rep(i,9){
			int in;
			cin >> in;
			t=9*t+in;
		}
		cout << dijkstra(convert[s],convert[t],w,h) << endl;
	}
	return 0;
}

Measured memory_bytes: 44276
#include <iostream>

int memo[101][101] = {-1};
int x[3][5] = {{1,2,6,5,1}, {1,3,6,4,1}, {2,3,5,4,2}};
int sides[3][2] = {{4, 3}, {2, 5}, {6, 1}};


int main() {
  int dice_a[7], dice_b[7];
  int top, front, q;
  char command;

  for (int i = 1; i < 7; i ++) 
    std::cin >> dice_a[i];
  for (int i = 1; i < 7; i ++) 
    std::cin >> dice_b[i];

  for (int j = 0; j < 3; j ++) {
    for (int i = 1; i < 5; i ++) {
      memo[dice_a[x[j][i]]][dice_a[x[j][i-1]]] = dice_a[sides[j][0]]; 
      memo[dice_a[x[j][i-1]]][dice_a[x[j][i]]] = dice_a[sides[j][1]]; 
    }
  }


  if (memo[dice_b[1]][dice_b[2]] == dice_b[3]
    && memo[dice_b[2]][dice_b[1]] == dice_b[4]) {
    std::cout << "Yes" << std::endl;
  } else {
    std::cout << "No" << std::endl;
  }
  return 0;
}



Measured memory_bytes: 3140
n,d = gets.chomp.split.collect{ |item| item.to_i}
xlist = Array.new()
n.times do |ni|
  xlist[ni] = gets.chomp.split.collect{ |item| item.to_i}
end

def calc_dis(xi,xj)
  result = 0
  xi.size.times do |i|
    result += (xi[i] - xj[i]) **2
  end
  if((Math.sqrt(result)) % 1 == 0)
    return 1
  else
    return 0
  end
end

pair = 0
n.times do |ni|
  (ni+1).upto(n-1) do |nii|
    pair += calc_dis(xlist[ni],xlist[nii])
  end
end

puts pair


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define ll long long
#define P ((ll)(1e9+7))
#define MAX 500005
using namespace std;

template<typename T>
void read(T &n){
    n = 0;
    T f = 1;
    char c = getchar();
    while(!isdigit(c) && c != '-') c = getchar();
    if(c == '-') f = -1, c = getchar();
    while(isdigit(c)) n = n*10+c-'0', c = getchar();
    n *= f;
}
template<typename T>
void write(T n){
    if(n < 0) putchar('-'), n = -n;
    if(n > 9) write(n/10);
    putchar(n%10+'0');
}

ll n, a, b;

ll qpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n&1) res = res*a%P;
        a = a*a%P;
        n >>= 1;
    }
    return res;
}

ll fac[MAX], inv[MAX];
void init(){
    fac[0] = 1;
    for(int i = 1; i < MAX; i++){
        fac[i] = fac[i-1]*i%P;
    }
    inv[MAX-1] = qpow(fac[MAX-1], P-2);
    for(int i = MAX-2; i >= 0; i--){
        inv[i] = inv[i+1]*(i+1)%P;
    }
}

ll C(ll n, ll m){
    ll res = 1;
    for(int i = n; i >= n-m+1; i--){
        res = res*i%P;
    }
    res = res*inv[m]%P;
    return res;
}

int main()
{
    init();
    cin >> n >> a >> b;
    ll ans = qpow(2, n)-1;
    ans = (ans-C(n, a)-C(n, b))%P+P;
    cout << ans%P << endl;

    return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#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 irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

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

signed main() {
  ll a,b,c; cin >> a >> b >> c;
  ll ans = c-a-b;
  ans = ans*ans;
  ans -= 4*a*b;

  if(ans > 0 && (c-(a+b)) > 0 ){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
 
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
 
        if(y >= r && y <= H-r && x >=r && x <= W-r){
            System.out.printf("Yes\n");
        }else{
            System.out.printf("No\n");
        }
    }
}


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

using namespace std;

int d[100005];

int main()
{
	int n;
	cin >> n;
	int tmp;
	cin >> tmp;
	if (tmp != 0)
	{
		cout << 0 << endl;
		return 0;
	}
	if (n == 1)
	{
		cout << 1 << endl;
		return 0;
	}
	int max_i = 0;
	for (int i = 1; i < n; i++)
	{

		cin >> tmp;
		if (tmp == 0)
		{
			cout << 0 << endl;
			return 0;
		}
		d[tmp]++;
		max_i = max(max_i, tmp);
	}
	if (d[1] == 0)
	{
		cout << 0 << endl;
		return 0;
	}
	long long ans = 1;
	for (int i = 2; i <= max_i; i++)
	{
		if (d[i] == 0)
		{
			cout << 0 << endl;
			return 0;
		}
		long long this_ans = 1ll;
		for (int j = 0; j < d[i]; j++)
		{
			this_ans *= d[i - 1];
			this_ans %= 998244353;
		}
		ans *= this_ans;
		ans %= 998244353;
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
    string w;
    cin >> w;

    for (int i = 0; i < w.length(); ++i) {
        if (count(w.begin(), w.end(), w[i]) % 2 != 0) {
            cout << "No" << '\n';
            exit(0);
        }
    }

    cout << "Yes" << '\n';
    
    return 0;
}

Measured memory_bytes: 3544
#include<stdio.h>

int main(void){
    int N,K,X,Y;
    int sum;

    scanf("%d",&N);
    scanf("%d",&K);
    scanf("%d",&X);
    scanf("%d",&Y);

    if(N>=K)
        sum = K * X + (N-K) * Y;
    else 
        sum = N * X;

    printf("%d",sum);

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int X;
int M[100];
int main(){
  int res;
  rd(N);
  rd(X);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<N;Lj4PdHRW++){
      rd(M[Lj4PdHRW]);
    }
  }
  {
    int KL2GvlyY, Q5VJL1cS;
    if(N==0){
      Q5VJL1cS = 0;
    }
    else{
      Q5VJL1cS = M[0];
      for(KL2GvlyY=1;KL2GvlyY<N;KL2GvlyY++){
        Q5VJL1cS += M[KL2GvlyY];
      }
    }
    X -=Q5VJL1cS;
  }
  {
    int cTE1_r3A, e98WHCEY;
    if(N==0){
      cTE1_r3A = 0;
    }
    else{
      cTE1_r3A = M[0];
      for(e98WHCEY=1;e98WHCEY<N;e98WHCEY++){
        cTE1_r3A = min_L(cTE1_r3A, M[e98WHCEY]);
      }
    }
    res = N + X /cTE1_r3A;
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190721-1

// --- original code ---
// int N, X, M[100];
// {
//   int res;
//   rd(N,X,M(N));
//   X -= sum(M(N));
//   res = N + X / min(M(N));
//   wt(res);
// }


Measured memory_bytes: 256
a, b = [int(item) for item in input().split()]
size = 100

grid = [["."] * size for _ in range(size//2)] + [["#"] * size for _ in range(size//2)]

for i in range(b-1):
  grid[(i//49)*2 + 1][(i%49)*2 + 1] = "#"
for i in range(a-1):
  grid[(i//49)*2 + 51][(i%49)*2 + 1] = "."

print(100, 100)
for line in grid:
  for item in line:
    print(item, end="")
  print("")

Measured memory_bytes: 4468
#include <bits/stdc++.h>
#include <ctime>
#include <unordered_map>
#include <stdlib.h>
using namespace std;
#define ll  long long int
#define mod 1000000007
#define modd 998244353
#define com(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define pri(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<endl;
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
/*__builtin_clz();
__builtin_ctz();
__builtin_popcount();*/
int main()
{
    boost;
    ll a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if((a[0]==a[1] && a[1] != a[2]) || (a[1]==a[2] && a[0] != a[1])) 
    cout<<"Yes"<<"\n";
    else
    {
        cout<<"No"<<"\n";
    }
    
    cerr << "\nTime elapsed: " << 1000 * clock()/CLOCKS_PER_SEC << "ms\n";
}
 
 
// bool prime[100000];
 
// // int gcdExtended(int a, int b, int *x, int *y) ;
// ll modInverse(int a, int m) 
// { 
//     int x, y; 
//     int g = gcdExtended(a, m, &x, &y); 
//     // if (g != 1) 
//     //     cout << "Inverse doesn't exist"; 
//     // else
//     // { 
//         // m is added to handle negative x 
//         int res = (x%m + m) % m; 
//         return res; 
//     // } 
// } 
  
// // // C function for extended Euclidean Algorithm 
// int gcdExtended(int a, int b, int *x, int *y) 
// { 
//     // Base Case 
//     if (a == 0) 
//     { 
//         *x = 0, *y = 1; 
//         return b; 
//     } 
  
//     int x1, y1; // To store results of recursive call 
//     int gcd = gcdExtended(b%a, a, &x1, &y1); 
  
//     // Update x and y using results of recursive 
//     // call 
//     *x = y1 - (b/a) * x1; 
//     *y = x1; 
  
//     return gcd; 
// } 
// ll modu(ll x)
// {
//     if(x<0)
//     {
//         x+=mod;
//     }
//     else 
//     {
//         x=x%mod;
//     }
//     return x;
// }
 
// void SieveOfEratosthenes(int n) 
// { 
//     // Create a boolean aay "prime[0..n]" and initialize 
//     // all entries it as true. A value in prime[i] will 
//     // finally be false if i is Not a prime, else true. 
     
//     memset(prime, true, sizeof(prime)); 
  
//     for (int p=2; p*p<=n; p++) 
//     { 
//         // If prime[p] is not changed, then it is a prime 
//         if (prime[p] == true) 
//         { 
//             // Update all multiples of p greater than or  
//             // equal to the square of it 
//             // numbers which are multiple of p and are 
//             // less than p^2 are already been marked.  
//             for (int i=p*p; i<=n; i += p) 
//                 prime[i] = false; 
//         } 
//     } 
//     prime[1]=false;
  
//     // Print all prime numbers 
//     // for (int p=2; p<=n; p++) 
//     //    if (prime[p]) 
//     //       cout << p << " "; 
// } 
// ll power(ll x, unsigned ll y, ll p) 
// { 
//     ll res = 1;      // Initialize result 
  
//     x = x % p;  // Update x if it is more than or  
//                 // equal to p 
  
//     while (y > 0) 
//     { 
//         // If y is odd, multiply x with result 
//         if (y & 1) 
//             res = (res*x) % p; 
  
//         // y must be even now 
//         y = y>>1; // y = y/2 
//         x = (x*x) % p;   
//     } 
//     return res; 
// } 


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

using namespace std;

int main() {
  int n, d;
  scanf("%d %d", &n, &d);

  vector<vector<int>> points(n);
  for (int i = 0; i < n; i++) {
    vector<int> new_point(d);
    for (int i = 0; i < d; i++) {
      scanf("%d", &new_point[i]);
    }

    points[i] = new_point;
  }

  int r = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      auto point1 = points[i];
      auto point2 = points[j];

      int sum = 0;
      for (int k = 0; k < d; k++) {
        int n = abs(point1[k] - point2[k]);
        sum += n * n;
      }

      int s = int(sqrt(sum));
      if (sum == s * s) {
        r += 1;
      }
    }
  }

  cout << r << endl;
}


Measured memory_bytes: 256
n, m, x = map(int,input().split())
c = [list(map(int, input().split())) for i in range(n)]
ans = float('inf')
money = [float('inf')]

for i in range(2**n):
  temp_money = 0
  temp_skill = [0]*m
  for j in range(n):
    if (i >> j) & 1:
      temp_money += c[j][0]
      temp_skill = [a + b for a, b in zip(temp_skill, c[j][1:m+1])]
    if all([i >= x for i in temp_skill])==True:
      money.append(temp_money)

ans = min(ans,min(money))
if ans == float("inf"):
  ans = -1

print(ans)

Measured memory_bytes: 10172
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int N, K;
    int A[100005], B[100005];
    int maxv = 0;

    cin >> N >> K;

    for(int i = 0; i < N; i++) {
        cin >> A[i] >> B[i];
    }
    int g = 1;
    while(g <= K) g <<= 1;
    g >>= 1;
    while(g > 0) {
        int sum = 0;
        for(int i = 0; i < N; i++) {
            if(g > A[i]) sum += B[i];
            A[i] &= ~g;
        }
        maxv = max(sum, maxv);
        K -= g;
        while(g > K) g >>= 1;
    }
    int sum = 0;
    for(int i = 0; i < N; i++) {
        if(A[i] == 0) sum += B[i];
    }
    maxv = max(sum, maxv);
    cout << maxv << endl;
    return (0);
}
    


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

using namespace std;

int main(){
	int n,x;
	while(true){
		cin >> n >> x;
		if(n == 0 && x == 0)
			break;
		int sol = 0;
		for(int i = 1; i <= n;i++)
			for(int j = i + 1; j <= n;j++)
				for(int k = j + 1; k <= n;k++){
					if((i + j + k) == x)
						sol++;
					//cout << i << " " << j << " " << k << endl;
				}
		cout << sol << endl;
	}
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(void){
    int a[3][3]={0};for(int i=0;i<9;i++)cin>>a[i/3][i%3];
    int n;cin>>n;
    for(int i=0;i<n;i++){int tmp;cin>>tmp;for(int j=0;j<9;j++)if(a[j/3][j%3]==tmp)a[j/3][j%3]=0;}
    int ans=1;
    ans*=a[0][0]+a[0][1]+a[0][2];
    ans*=a[1][0]+a[1][1]+a[1][2];
    ans*=a[2][0]+a[2][1]+a[2][2];
    ans*=a[0][0]+a[1][0]+a[2][0];
    ans*=a[0][1]+a[1][1]+a[2][1];
    ans*=a[0][2]+a[1][2]+a[2][2];
    ans*=a[0][0]+a[1][1]+a[2][2];
    ans*=a[0][2]+a[1][1]+a[2][0];
    if(!ans)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
const int limit=100010;
using edge=struct {int to;ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v,int p,ll d){
    depth[v]=d;
    for(auto &e : tree[v]){
        if(e.to==p) continue;
        dfs(e.to,v,d+e.cost);
    }
}

int main() {
    int n;
    cin>>n;
    
    for(int i=0;i<n-1;i++){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        tree[a].push_back({b,c});
        tree[b].push_back({a,c});
    }
    
    int q,k;
    cin>>q>>k;
    k--;
    dfs(k,-1,0);
    for(int i=0;i<q;i++){
        int x,y;
        cin>>x>>y;
        x--;y--;
        cout<<depth[x]+depth[y]<<endl;
    }
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
struct bun{
    ll si, bo;
    bun() {
        si = 1; bo = 1;
    }
    bun(ll a, ll b) {
        ll sign = 1;
        if (a < 0) {
            sign *= -1;
            a = -a;
        }
        if (b < 0) {
            sign *= -1;
            b = -b;
        } 
        ll gcd = __gcd(a,b);
        si = sign * a / gcd;
        bo = b / gcd;
    }
    const bool operator <(const bun &b) const {
        if (si == b.si) {
            return bo < b.bo;
        } else {
            return si < b.si;
        }
    }
};

map<bun, ll> mp, mpr;
set<bun> used;
int n;
ll b0,a0,both0,no0;

ll p[200010];

int main() {
    p[0] = 1;
    for (int i = 1; i < 200010; i++) {
        p[i] = p[i-1] * 2;
        p[i] %= mod;
    }

    cin >> n;
    for (int i = 0; i < n; i++) {
        ll a,b;
        cin >> a >> b;
        if (b != 0 && a != 0) {
            mp[bun(a,b)]++;
        } else if (a == 0 && b == 0)
            both0++;
        else if (a == 0)
            a0++;
        else if (b == 0)
            b0++;
    }
    no0 = n - b0 - a0 - both0;
    
    ll sum = 1;
    for (auto mpp: mp) {
        bun b = mpp.first;
        if (used.count(b)) continue;
        used.insert(b);
        bun rb = bun(-b.bo,b.si);
        if (mp.count(rb)) {
            used.insert(rb);
            sum *= (p[mpp.second] + p[mp[rb]] - 1 + mod) % mod;
            sum %= mod;
        } else {
            sum *= p[mpp.second];
            sum %= mod;
        }
    }
    sum = (sum - 1 + mod) % mod;

    ll ans = both0;
    ans += (p[b0] - 1 + mod) % mod * (sum + 1) % mod;
    ans %= mod;
    ans += (p[a0] - 1 + mod) % mod * (sum + 1) % mod;
    ans %= mod;
    ans += sum;
    ans %= mod;

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

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

using namespace std;

int main(void){
    string S;
    string T;
    int N;

    cin >> S >> T;
    
    cin >> N;

    int s_s, s_e, t_s, t_e;

    int S_asum[100005];
    S_asum[0] = 0;
    for(int j=1;j<=S.length();j++){
        S_asum[j] = (S_asum[j-1] + S[j -1] - 'A' + 1) % 3;
    }
    int T_asum[100005];
    T_asum[0] = 0;
    for(int j=1;j<=T.length();j++){
        T_asum[j] = (T_asum[j-1] + T[j -1] - 'A' + 1) % 3;
    }

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

        cin >> s_s >> s_e >> t_s >> t_e;
        int s_tmp = 0;
        int t_tmp = 0;

        s_tmp = S_asum[s_e] - S_asum[s_s-1] + 3;
        t_tmp = T_asum[t_e] - T_asum[t_s-1] + 3;

        string ans = "NO";
        if((s_tmp - t_tmp) % 3 == 0){
            ans = "YES";
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
package main

import (
	"math/rand"
	"time"
	"os"
	"bufio"
	"fmt"
	"strconv"
	"strings"
)

var(
	sc = bufio.NewScanner(os.Stdin)
	stdin = bufio.NewReader(os.Stdin)
	mod = 1000000007
	mod9 = 1000000009
)

func init()  {
	rand.Seed(time.Now().UnixNano())
	buf := make([]byte, 0) //ここのサイズは何でもよさそう
	sc.Buffer(buf, 1000000009)
}


//||||||||||||||||||||||||||入力|||||||||||||||||||||||||||||||||||||||\
//数字一文字入力
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

//文字列を一行入力
func nextLine() string {
	sc.Scan()
	return sc.Text()
}

//空白区切りの文字列の入力
func spaceLine() []string {
	sc.Scan()
	return strings.Split(sc.Text()," ")
}

//数字を一行入力
func intLine() []int {
	str := spaceLine()
	buf := make([]int,len(str))
	for i,s:=range str{
		buf[i],_ = strconv.Atoi(s)
	}
	return buf
}

//次のスペースか改行まで読み込む
func gostring() string {
	byte_ls := make([]byte,0)
	for  {
		b, _ := stdin.ReadByte()
		if b == 32 || b == 10 || b == 0{
			return string(byte_ls)
		} else if b == 13 {
			continue
		} else {
			byte_ls = append(byte_ls,b)
		}
	}
}

//上の関数のintバージョン
func goint() int {
	n,_ := strconv.Atoi(gostring())
	return n
}

//|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

//ソートする
//sは最初のインデックス fは最後のインデックス
func Sort(ls []int,l int,r int)  {
	if r - l <= 0{return}
	pipot := l + rand.Intn(r-l+1)
	ls[r],ls[pipot] = ls[pipot],ls[r]
	i := l
	for j:=l;j<r;j++{
		if ls[j] < ls[r]{
			ls[i],ls[j] = ls[j],ls[i]
			i ++
		}
	}
	ls[i],ls[r] = ls[r],ls[i]
	Sort(ls,l,i-1)
	Sort(ls,i+1,r)
}

//配列の大小を指定した要素で比較
//a < bならtrue
func sizeCheck(a []int,b []int,ls []int) bool {
	for _,i:= range ls{
		if a[i] < b[i]{
			return true
		} else if a[i] > b[i] {
			return false
		}
	}
	return false
}

//二次元配列のソート
func Sort2D(ls [][]int,l int,r int,index ...int)  {
	if r - l <= 0{return}
	pipot := l + rand.Intn(r-l+1)
	ls[r],ls[pipot] = ls[pipot],ls[r]
	i := l
	for j:=l;j<r;j++{
		if sizeCheck(ls[j],ls[r],index){
			ls[i],ls[j] = ls[j],ls[i]
			i ++
		}
	}
	ls[i],ls[r] = ls[r],ls[i]
	Sort2D(ls,l,i-1,index ...)
	Sort2D(ls,i+1,r,index ...)
}

func main() {
	n,m := goint(),goint()
	a := make([]int,n)
	for i:=0;i<n;i++{
		a[i] = goint()
	}
	cost := make(map[int]int)
	for _,v:=range a{
		if _,check := cost[v];check {
			cost[v] ++
		} else {
			cost[v] = 1
		}
	}
	for i:= 0;i<m;i++{
		bc := make([]int,2)
		bc[0],bc[1] = goint(),goint()
		if _,check := cost[bc[1]];check {
			cost[bc[1]] += bc[0]
		} else {
			cost[bc[1]] = bc[0]
		}
	}
	i := 0
	ls := make([][]int,len(cost))
	for key,value := range cost{
		ls[i] = make([]int,2)
		ls[i][0] = key
		ls[i][1] = value
		i ++
	}
	Sort2D(ls,0,len(ls)-1,0)
	ans := 0
	for i:=len(ls)-1;i>=0;i--{
		b,c := ls[i][1],ls[i][0]
		if n >= b{
			ans += b*c
			n -= b
		} else {
			ans += n * c
			break
		}
		if n <= 0{break}
	}
	fmt.Println(ans)
}

func min(a ...int) int {
	ans := a[0]
	for i:=1;i<len(a);i++{
		if ans > a[i]{
			ans = a[i]
		}
	}
	return ans
}

Measured memory_bytes: 19840
import math
N, D = map(int, input().split())
x = [list(map(int,input().split())) for i in range(N)]
tmp = 0
ans = 0
for i in range(N):
    for j in range(i + 1,N):
        for d in range(D):
            tmp += (x[i][d] - x[j][d])**2
        tmp = math.sqrt(tmp)
        if tmp.is_integer():
            ans += 1
        tmp = 0
print(ans)

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

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

  	int count = 0;
  	int ans = 0;
  	int j = 0;
  	for(int i=0; i<s.size(); i++){
    	if(s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T'){
        	count++;
        }else{
        	ans = count > ans ? count : ans;
          	count = 0;
        }
    }
  	ans = count > ans ? count : ans;
  	cout << ans << endl;
	return 0;
}

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

using namespace std;

inline bool next(const vector<long long>& a, int N, int from) {
        bool f;
        for (int i = from; i < N - 1; ++i) {
                if (a[i] - a[i+1] != 0) {
                        f = a[i] - a[i+1] < 0 ? true : false;
                        break;
                }
        }
        return f;
}

inline int test1(const vector<long long>& a, int N) {
        int counter = 0;
        bool f = next(a, N, 0);
        /*
        for (int i = 0; i < N - 1; ++i) {
                if (a[i] - a[i+1] != 0) {
                        f = a[i] - a[i+1] < 0 ? true : false;
                        break;
                }
        }
        */
        for (int i = 1; i < N; ++i) {
                if (f == true && a[i-1] - a[i] <= 0) {
                        //cout << "[up]" << endl;
                } else if (f == false && a[i-1] - a[i] >= 0) {
                        //cout << "[down]" << endl;
                } else {
                        //cout << "[change]" << endl;
                        //f = a[i] - a[i+1] < 0 ? true : false;
                        f = next(a, N, i);
                        ++counter;
                }
        }
        return counter+1;
}

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

        //int ans = min(test1(a, N), test2(a, N));
        //ans = min(ans, test3(a, N));
        int ans = test1(a, N);
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 1152