akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(vec, s) vec.find(s) != vec.end()

int main() {
	map<string, int> M;
	int q;
	cin >> q;
	Rep(i, q) {
		int n;
		string key;
		cin >> n >> key;
		if (n == 0) {
			int x;
			cin >> x;
			M[key] = x;
		}
		else if (n == 1) {
			cout << M.at(key) << endl;
		}
	}
	return 0;
}


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

#include <algorithm>
#include <cstdio>
using namespace std;

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

  for(int i=1; i<=n; ++i) {
    x = i;
    if(i%3==0) {
      cout << " " <<i;
      continue;
    }

    while(x) {
      if(x%10 == 3) {
        cout << " " << i;
        break;
      }
      x /= 10;
    }

  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}

int main() {
    int x,a,b;
    cin >> x >> a >> b;
    x -= a;
    int c = x / b;
    cout << x - (c * b) << endl;
}



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

typedef long long ll;
const ll MAXN = 1e5 + 10;
const ll INF = 1e18;
ll N, M, P;
vector<ll> ADJ[MAXN], C[MAXN];
vector<ll> D;
ll f(int src, int sink){
    D = vector<ll>(N + 1, INF);
    D[src] = 0;
    long long ret1, ret2;
    for(int t = 1 ; t <= N ; t++){
        for(int i = 1 ; i <= N ; i++){
            if(D[i] == INF) continue;
            for(int j = 0  ; j < ADJ[i].size() ; j++){
                int there = ADJ[i][j];
                long long c = C[i][j];

                if(D[there] > D[i] + c) D[there] = D[i] + c;
            }
        }
    }
    ret1 = D[sink];

    for(int t = 1 ; t <= N ; t++){
        for(int i = 1 ; i <= N ; i++){
            if(D[i] == INF) continue;
            for(int j = 0  ; j < ADJ[i].size() ; j++){
                int there = ADJ[i][j];
                long long c = C[i][j];

                if(D[there] > D[i] + c) D[there] = D[i] + c;
            }
        }
    }
    ret2 = D[sink];

    if(D[sink] != INF && ret1 == ret2) return max(0LL, -D[sink]);
    return -1;
}

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

    cin >> N >> M >> P;
    for(int i = 0 ; i < M ; i++){
        ll a, b, c;
        cin >> a >> b >> c;
        ADJ[a].push_back(b); C[a].push_back(P - c);
    }

    cout << f(1, N) << '\n';
    return 0;
}

Measured memory_bytes: 5120
import itertools
import math
import fractions
import functools
n = int(input())
k = list(map(int, input().split()))

minimum = 1000
maximum = 0

for i in range(n):
    minimum = min(minimum,k[i])
    maximum = max(maximum,k[i])

minimum_ans = 10**9
for i in range(minimum, maximum + 1):
    sum = 0
    for j in range(n):
        sum += (k[j] - i)**2
    minimum_ans = min(minimum_ans,sum)

print(minimum_ans)

Measured memory_bytes: 64108
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, W;
  cin >> H >> W;
  for(int h = 0; h < (H+2); h++){
    
    if(h == 0 || h == (H+1)){
      for(int w = 0; w < (W+2); w++){
        cout << "#";
      }
      cout << endl;
    }
    else{
      string str;
      cin >> str;
      cout << "#" << str << "#" << endl;
    }
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Programming Contest
 * PCK2013
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			StringTokenizer st = new StringTokenizer(line);

			int N, R, L;
			N = parseInt(st.nextToken());
			R = parseInt(st.nextToken());
			L = parseInt(st.nextToken());

			Team[] team = new Team[N + 1];

			Queue<Team> pq = new PriorityQueue<>((x, y) -> {
				if (x.point == y.point) {
					return Integer.compare(x.id, y.id);
				} else {
					return Integer.compare(y.point, x.point);
				}
			});

			for (int i = 1; i <= N; i++) {
				team[i] = new Team(i);
			}

			int elapsed = 0;
			pq.offer(team[1]);

			for (int i = 0; i < R; i++) {
				st = new StringTokenizer(br.readLine());
				int d, t, x;
				d = parseInt(st.nextToken());
				t = parseInt(st.nextToken());
				x = parseInt(st.nextToken());
				pq.peek().time += t - elapsed;
				//
				pq.remove(team[d]);
				team[d].point += x;
				pq.offer(team[d]);
				//
				if (pq.size() > 3) {
					List<Team> list = new ArrayList<>();
					for (int j = 0; j < 3; j++) {
						list.add(pq.poll());
					}
					pq.clear();
					pq.addAll(list);
				}
				//
				elapsed = t;
			}

			pq.peek().time += L - elapsed;

			//
			Team ans = team[1];

			for (int i = 1; i <= N; i++) {
				if (team[i].time > ans.time) ans = team[i];
			}

			System.out.println(ans.id);
		}
	}
}

class Team {

	int id, time = 0, point = 0;

	Team(int id) {
		this.id = id;
	}
}

Measured memory_bytes: 114000
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int t = scan.nextInt();
        int[] ar = new int[t];
        for (int i = 0; i < t; i++) {
            ar[i] = scan.nextInt();
        }

        Arrays.sort(ar);
        double result = ar[0];
        for (int i = 0; i < ar.length; i++) {
            result = (result+ar[i])/2;
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200;

char s[N];

typedef pair<int,int> P;
vector<P> v;

int main() {
    scanf("%s",s);
    ll k;
    cin>>k;
    int n=strlen(s);

    int b=0,e=0;
    while(b<n)
    {
        e=b;
        while(e<n&&s[b]==s[e])++e;
        v.push_back(P(b,e));
        b=e;
    }

    if(v.size()==1)
        cout<<n*k/2;
    else
    {
        if(s[0]==s[n-1])
        {
            ll tmp1=v[0].second-v[0].first;
            ll tmp2=v.back().second-v.back().first;
            ll tmp3=0;
            for(int i=1;i<v.size()-1;++i)
                tmp3+=(v[i].second-v[i].first)/2;
            tmp3*=k;
            cout<<tmp1/2+tmp2/2+tmp3+(tmp1+tmp2)/2*(k-1);
        }
        else
        {
            ll ans=0;
            for(P t:v)
                ans+=(t.second-t.first)/2;
            ans*=k;
            cout<<ans;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int x = N, y = N / 10, sum = 0;
  while (x > 0) {
    sum += x - y * 10;
    x /= 10;
    y /= 10;
  }
  if (N % sum == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
  

Measured memory_bytes: 256
n = gets.chomp.to_i
l = gets.chomp.split.map(&:to_i)

def eval(l, i, j, k)
  (l[i] + l[j] > l[k]) \
    and (l[j] + l[k] > l[i]) \
    and (l[k] + l[i] > l[j]) \
    and (l[i] != l[j] and l[j] != l[k] and l[k] != l[i])
end

cnt = 0
(0...n).each do |i|
  (i+1...n).each do |j|
    (j+1...n).each do |k|
      if eval(l, i, j, k)
        cnt += 1
      end
    end
  end
end

p cnt

Measured memory_bytes: 14300
import java.util.Scanner

fun main(args: Array<String>) {
  val cin = Scanner(System.`in`)
  val n = cin.nextInt() - 1

  var ct = Array<Int>(100010, {0})

  for (i in 0..n) {
    val a = cin.nextInt()
    ct[a]++
    ct[a + 1]++
    if (a != 0) {
      ct[a - 1]++
    }
  }

  var res = 0
  for (i in 0..100000) {
    res = Math.max(res, ct[i])
  }

  println(res)

  cin.close()
}

Measured memory_bytes: 52536
import java.util.*;

class Main {
    public static void main(String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] b = new int[n - 1];
        for (int i = 0; i < n - 1; i++) {
            b[i] = sc.nextInt();
        }
        sc.close();
        int a = b[0];
        for (int i = 0; i < n - 2; i++) {
            a += Math.min(b[i], b[i + 1]);
        }
        a += b[n - 2];
        System.out.println(a);
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define int long long 
int32_t main()
{
   int n,s=0; cin>>n;
   int arr[n],brr[n];
   for(int i=0;i<n;++i)
   cin>>arr[i];
   for(int i=0;i<n;++i)
   cin>>brr[i];
   for(int i=0;i<n;++i){
       if(arr[i]>brr[i])
       s+=arr[i]-brr[i];
   }
   cout<<s;
   return 0;
}


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

int main() {
    string a;
    getline(cin,a);
    char b = 'A' - 'a';
    for(int i = 0;i < a.size();i++){
        if(a[i] >= 'a' && a[i] <= 'z'){
            a[i] += b;
        }
        else if(a[i] >= 'A' && a[i] <= 'z'){
            a[i] -= b;
        }
        cout << a[i];
    }
    cout << endl;
}



Measured memory_bytes: 3172
N, A, B = map(int, input().split(' '))


def count_num_of_blue():
    global N, A, B

    total = 0
    division = int(N / (A+B))
    remainder = int(N % (A+B))
    if division > 0:
        total += A * division

    if remainder < A:
        total += remainder
    else:
        total += A

    print(total)


count_num_of_blue()


Measured memory_bytes: 3060
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long lint;

vector<vector<int>> adj;
vector<bool> mark, in_cycle;

vector<int> stack, cycle;
vector<bool> in_stack;

bool find_cycle(int v) {
  mark[v] = true;
  stack.push_back(v);
  in_stack[v] = true;
  for (int u : adj[v]) {
    if (in_stack[u]) {
      while (stack.back() != u) {
        cycle.push_back(stack.back());
        in_cycle[stack.back()] = true;
        stack.pop_back();
      }
      cycle.push_back(u);
      in_cycle[u] = true;
      stack.pop_back();
      reverse(cycle.begin(), cycle.end());
      return true;
    } else if (!mark[u] && find_cycle(u)) {
      return true;
    }
  }
  in_stack[v] = false;
  stack.pop_back();
  return false;
}

int get_gap(vector<int> &values) {
  sort(values.begin(), values.end());
  if (values.empty() || values[0] > 0)
    return 0;
  for (int i = 0; i + 1 < (int)values.size(); ++i)
    if (values[i] + 1 < values[i + 1])
      return values[i] + 1;
  return values.back() + 1;
}

vector<int> value;

int get_value(int v) {
  vector<int> adj_values;
  if (value[v] != -1)
    return value[v];
  for (int u : adj[v])
    adj_values.push_back(get_value(u));
  return get_gap(adj_values);
}

int main() {
  int n;
  scanf("%d", &n);
  adj.resize(n);
  for (int i = 0; i < n; ++i) {
    int p;
    scanf("%d", &p), --p;
    adj[p].push_back(i);
  }
  mark.resize(n, false);
  in_cycle.resize(n, false);
  in_stack.resize(n, false);
  for (int i = 0; i < n; ++i)
    if (!mark[i]) {
      if (find_cycle(i))
        break;
    }

  for (int i = 0; i < (int)cycle.size(); ++i) {
    int ci = cycle[i], cip1 = cycle[(i + 1) % cycle.size()];
    bool ok = false;
    for (int u : adj[ci])
      if (u == cip1) {
        ok = true;
        break;
      }
    assert(ok);
  }

  value.resize(n, -1);
  for (int v = 0; v < n; ++v)
    if (in_cycle[v])
      for (int u : adj[v])
        if (!in_cycle[u])
          value[u] = get_value(u);

  const int c0 = cycle[0];
  vector<int> c0values;
  for (int u : adj[c0])
    if (!in_cycle[u])
      c0values.push_back(value[u]);
  vector<int> cands;
  cands.push_back(get_gap(c0values));
  c0values.push_back(cands[0]);
  cands.push_back(get_gap(c0values));
  bool possible = false;
  for (int cand : cands) {
    value[c0] = cand;
    for (int i = (int)cycle.size() - 1; i > 0; --i) {
      int ci = cycle[i];
      value[ci] = -1;
      value[ci] = get_value(ci);
    }
    value[c0] = -1;
    if (get_value(c0) == cand) {
      possible = true;
      break;
    }
  }
  if (possible) printf("POSSIBLE\n");
  else printf("IMPOSSIBLE\n");
  return 0;
}


Measured memory_bytes: 22776
// AOJ 2224: Save your cats
// 2017.10.7 bal4u@uu

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

#define EPS 1e-7
#define MAX 10003

/* UNION-FIND library */
int p[MAX], rank[MAX];
void make_set(int x) { p[x] = x, rank[x] = 0; }
void link(int x, int y) {
	if (rank[x] > rank[y]) p[y] = x;
	else { p[x] = y; if (rank[x] == rank[y]) rank[y] = rank[y] + 1;	}
}
int find_set(int x) { if (x != p[x]) p[x] = find_set(p[x]);	return p[x]; }
void union_set(int x, int y) { link(find_set(x), find_set(y)); }

typedef struct { int a, b; double d; } T;
T tbl[50005];

int x[MAX], y[MAX];

int cmp(T *a, T *b)
{
	if (fabs(b->d - a->d) <= EPS) return 0;
	if (a->d <= b->d) return 1;
	return -1;
}

int main()
{
	int n, m, i, s, t;
	double ans, d, dx, dy;

    scanf("%d%d", &n, &m);
    for (i = 1; i <= n; i++) scanf("%d%d",x+i, y+i), make_set(i);
    for (ans = 0, i = 0; i < m; i++) {
        scanf("%d%d", &s, &t);
		dx = x[s] - x[t], dy = y[s] - y[t];
		d = sqrt(dx*dx + dy*dy);
        tbl[i].a = s, tbl[i].b = t, tbl[i].d = d;
        ans += d;
    }
    qsort(tbl, m, sizeof(T), cmp);

    for (i = 0; i < m; i++) {
        s = find_set(tbl[i].a), t = find_set(tbl[i].b);
        if (p[s] != p[t]) union_set(s, t), ans -= tbl[i].d;
    }
    printf("%lf\n", ans);
    return 0;
}

Measured memory_bytes: 2556
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int sum=0;
    for(int i=0; i<s.size(); i++)
    {
        sum=sum+s[i]-48;
    }
    if(sum%9==0)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3680
#include<iostream>
using namespace std;
int main(){
   int n,a[100001]={};
   int count=0;
   cin>>n;
   for(int i=0;i<n;i++)cin>>a[i];

   for(int i=0;i<n;i++)
    if(a[i]%2==0)
     for(int j=i+1;j<n;j++){
      if(a[j]%2==0){
        a[j]+=a[i];
        a[i]=0;
        break;
       }
      }
     else if(a[i]%2!=0){
       for(int j=i;j<n;j++)
        if(a[j+1]%2!=0){
          a[j+1]+=a[i];
          a[i]=0;
          break;
         }
       }
   for(int i=0;i<n;i++)if(a[i]!=0)count++;

   if(count==1)cout<<"YES"<<endl;
   else cout<<"NO"<<endl;
return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int a[3]; bool v=1;
int main()
{
    for(auto& b:a) cin>>b;
    sort(a,a+3);
    for(auto b:a) 
    {
        if(!v) cout<<" "; cout<<b; v=0;
    }
    //cout<<(is_sorted(&a[0],&a[3])? "Yes" :"No");
    cout<<'\n';
}
//dont copy my code
//you wont understand anyway


Measured memory_bytes: 3168
N = int(input())
MOD = 10**9+7
dp = [[0]*3 for _ in range(61)]
dp[60][0] = 1
for d in range(59,-1,-1):
    for s in range(3):
        for k in range(3):
            ns = min(2, 2*s + ((N>>d)&1) - k)
            if ns < 0: continue
            dp[d][ns] += dp[d+1][s]
            dp[d][ns] %= MOD
print(sum(dp[0]) % MOD)

Measured memory_bytes: 9140
#include <iostream>
#define N 100
#define INFINITY 2000000000
using namespace std;
void prim();
int M[N][N],d[N],p[N],u,n,mincost,i,j;
string color[N];
int main(){
  cin >> n;
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      cin >> M[i][j];
    }
  }
  prim();
  return 0;
}
void prim(){
  for(i=0;i<n;i++) color[i]="WHITE",d[i]=INFINITY;
  d[0]=0;
  p[0]=-1;
  while(1){
    mincost=INFINITY;
    for(i=0;i<n;i++){
      if(color[i]!="BLACK"&&d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
    if(mincost==INFINITY) break;
    color[u]="BLACK";
    for(i=0;i<n;i++){
      if(color[i]!="BLACK"&&M[u][i]!=-1){
	if(M[u][i]<d[i]){
	  d[i]=M[u][i];
	  p[i]=u;
	  color[i]="GLAY";
	}
      }
    }
  }
  int sum=0;
  for(i=0;i<n;i++) sum+=d[i];
  cout << sum << endl;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));

typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 9223372036854775806ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
//-0.4620981203755741
int main(){
    int n;
    std::cin >> n;
    VEC(double,a,n);
    sort(all(a),greater<double>());
    double ans=0;
    rep(i,n){
        a[i]*=pow(0.5,min(i+1,n-1));
        ans+=a[i];
    }
    std::cout << keta(10)<<ans << std::endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
ll mod=1000000007;

int main() {
  int n,m;cin>>n>>m;
  int lmax=1;
  int rmin=n;
  for(int i=0;i<m;++i){
    int l,r;cin>>l>>r;
    lmax= max(lmax,l);
    rmin= min(rmin,r);
  }
  cout << max(rmin-lmax+1, 0) << endl;
  return 0;
}


Measured memory_bytes: 256
use std::collections::HashMap;

fn main() {
    let (n, v) = input();
    println!("{}", solve(n, v));
}

fn input() -> (usize, Vec<String>) {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.pop();
    let n: usize = buf.parse().unwrap();
    let mut v: Vec<String> = Vec::new();
    for i in 0..n {
        let mut b = String::new();
        std::io::stdin().read_line(&mut b).unwrap();
        b.pop();
        v.push(b);
    }
    (n, v)
}

fn solve(n: usize, v: Vec<String>) -> usize {
    let mut set: HashMap<String, bool> = HashMap::new();
    for a in v.iter() {
        set.entry(a.to_string()).or_insert(true);
    }
    set.len()
}

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

ans=0
cont=True
while cont:
  for i in range(N):
    if A[i] % 2 == 0:
      A[i] //= 2
    else:
      cont=False
      break
  if cont==True:
    ans += 1
    
print(ans)


Measured memory_bytes: 2940
/*
     Author:Raghav Bansal
     IIIT Una
                  */
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define BOLT ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define X first
#define Y second
#define endl "\n"
using namespace std;
void solve() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (i % 3 != 0 and i % 5 != 0) {
			ans += i;
		}
	}
	cout << ans << endl;
}
int32_t main() {
	BOLT;
	int t;
	t = 1;
	while (t--)
	{
		solve();
	}
}

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

long long calc_dist(long long x, long long y);

int main(){
    int count = 0;
    long long N, D;
    long long X, Y;

    std::cin >> N >> D;

    for(int i = 0; i < N; i++){
        std::cin >> X >> Y;
        if(calc_dist(X,Y) <= D*D){
            count++;
        }
    }

    std::cout << count;
}

long long calc_dist(long long x, long long y){
    long long ans;
    ans = x*x + y*y;
    return ans; 
}


Measured memory_bytes: 3632
from collections import deque
import sys

N = int(input())

b = list(map(int,input().split()))

q = deque([])

q.append([b,[]])

dic = {}

while len(q) > 0:

    now = q.pop()

    nb = now[0]
    nc = now[1]

    for i in range(len(nb)):

        i = len(nb) - i - 1

        if (i+1) == nb[i]:

            nex = []
            nec = []
            for j in range(len(nb)):
                if j != i:
                    nex.append(nb[j])
            for j in range(len(nc)):
                nec.append(nc[j])
            
            nec.append(nb[i])
            

            s = " ".join(map(str,nex))
            if s in dic:
                continue
            dic[s] = 1

            if len(nex) == 0:
                nec.reverse()
                print (" ".join(map(str,nec)))
                sys.exit()

            q.append([nex,nec])
            break

print (-1)


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

int main() {
    int n;
    cin >> n;
    vector<int> students(n), ans(n);
    for (int i = 0; i < n; ++i) {
        cin >> students.at(i);
    }
    for (int j = 0; j < n; ++j) {
        ans.at(students.at(j) - 1) = j + 1;
    }
    for (int k : ans) {
        cout << k << " ";
    }
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <string>

const int K = 50;
const char BLACK = '#';
const char WHITE = '.';

int main() {
  int A, B;
  std::cin >> A >> B;

  std::vector<std::string> m;

  for (int i = 0; i < 2 * K; i++) {
    m.push_back(std::string(2 * K, i < K ? BLACK : WHITE));
  }

  for (int i = 0; i < A - 1; i++) {
    const int y = 2 * (i / (K / 2));
    const int x = 2 * (i % (K / 2));

    m[y][x] = WHITE;
  }

  for (int i = 0; i < B - 1; i++) {
    const int y = 2 * K - 1 - 2 * (i / (K / 2));
    const int x = 2 * (i % (K / 2));

    m[y][x] = BLACK;
  }

  std::cout << 2 * K << " " << 2 * K << std::endl;

  for (int y = 0; y < 2 * K; y++) {
    std::cout << m[y] << std::endl;
  }
}


Measured memory_bytes: 256
import heapq

N,M = map(int, input().split())
L = [-int(i) for i in input().split()]
heapq.heapify(L)



for i in range(M):
    h = -(-heapq.heappop(L) // 2)
 
    heapq.heappush(L,h)

print(-sum(L))

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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#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--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB emplace_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll p, q, r;
    cin >> p >> q >> r;
    ll tmp = max(p, max(q, r));
    cout << p + q + r - tmp;
    return 0;
}

Measured memory_bytes: 3580
N, K, C = [int(input_) for input_ in input().split(" ")]
    
tick_cross = input()
    
def find_earliest_work_days(K, C, tick_cross):
    """
    Find the list of the earliest day in all possible days for the n-th 
    work day.
    
    Parameters:
    K (int): The number of work days.
    C (int): Minimum interval between the previous work day and the 
             next work day.
    tick_cross (str): The character string of days he can go to work.
             
    Returns:
    List[int]: The list of the earliest day in all possible days for 
               the n-th work day.
    """
    
    N = len(tick_cross)
        
    day = 0
    earliest_work_days = []
    number_of_work_days = len(earliest_work_days)
    while (day < N) and (number_of_work_days < K):
        if tick_cross[day] == "o":
            earliest_work_days.append(day+1)
            number_of_work_days = len(earliest_work_days)
            day += C + 1
        else:
            day += 1
            
    return earliest_work_days
    
def find_latest_work_days(K, C, tick_cross): 
    """
    Find the list of the latest day in all possible days for the n-th 
    work day.
    
    Parameters
    K (int): The number of work days.
    C (int): Minimum interval between the previous work day and the 
             next work day.
    tick_cross (str): The character string of days he can go to work.
             
    Returns:
    List[int]: The list of the latest day in all possible days for 
               the n-th work day.
    """
    
    N = len(tick_cross)
        
    day = N - 1
    latest_work_days = []
    number_of_work_days = len(latest_work_days)
    while (day >= 0) and (number_of_work_days < K):
        if tick_cross[day] == "o":
            latest_work_days.append(day+1)
            number_of_work_days = len(latest_work_days)
            day -= (C + 1)
        else:
            day -= 1
            
    return sorted(latest_work_days)
                
earliest_work_days = find_earliest_work_days(K, C, tick_cross)
latest_work_days = find_latest_work_days(K, C, tick_cross)
for earliest, latest in zip(earliest_work_days, latest_work_days):
    if earliest == latest:
        print(earliest)

Measured memory_bytes: 20836
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a = sc.nextInt();
		String b = "Three";
		for(int i=0 ; i<a ; i++) {
			String c = sc.next();
			if(c.equals("Y")) {
				b = "Four";
			}
		}
		System.out.println(b);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;

int cnt[20];
int main(){
  for(int i=0;i<3;i++){
    int n;
    cin >> n;
    ++cnt[n];
  }
  bool res = cnt[5] == 2 && cnt[7] == 1;
  cout << (res ? "YES" : "NO") << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#define MOD 1000000007
using namespace std;
typedef long long ll;
int main()
{
    ll n;
    cin>>n;
    ll arr[100001],dp[100001]={0};
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        dp[arr[i]]++;
    }
    int flag=0,count=0;
    for(int i=0;i<n;i++)
    {
        if(dp[i]>2){
            flag=1;
            break;
        }
        else if(dp[i]==2)
        {
            count++;
        }
        //else if(dp[i]==1)
        //{
          //  flag=1;
            //break;
        //}
    }
    //cout<<count;
    int sar=0;
    if(n&1)
    {
        if(dp[0]!=1)
            sar=1;
    }

    if(sar||flag)
        cout<<"0"<<endl;
    else
    {
        ll ans=1;
        for(int i=0;i<count;i++)
        {
            ans=(ans%1000000007)*2;
        }
        cout<<ans%1000000007;
    }

    return 0;
}


Measured memory_bytes: 1792
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

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

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    input! {a:String,b:String}
    println!(
        "{}",
        if a == b.chars().rev().collect::<String>() {
            "YES"
        } else {
            "NO"
        }
    )
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s;
    cin>>s;
    int zero=0,one=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='0') zero++;
        else one++;
    }
    cout<<2*min(one,zero)<<endl;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; 
		//order_of_key (k) : Number of items strictly smaller than k .
		//find_by_order(k) : K-th element in a set (counting from zero) (returns an iterator)           


void inp_out()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
	#endif
}

int32_t main()
{
	fastIO
	inp_out();
	int n; 
	cin >> n; 
	vi a(n); 
	int total = 0; 
	for(int i = 0; i < n; ++ i)
	{
		cin >> a[i]; 
		total += a[i]; 
		total %= MOD; 
	}
	int ans = 0; 

	for(int i = 0; i < n; ++ i)
	{
		total -= a[i]; 
		total %= MOD; 
		total += MOD; 
		total %= MOD; 
		ans += (total * a[i]);
		ans %= MOD;  
	}

	cout << ans; 

	return 0;
}

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

typedef long long int lli;
lli mod=1000000007;

int main()
{
	lli n,m;
	cin>>n>>m;
	lli temp;
	set<lli> forbidden;
	for(lli i=0;i<m;i++)
	{
		cin>>temp;
		forbidden.insert(temp-1);

	}
	if(n==1)
	{
		cout<<1<<endl;
		return 0;
	}
	vector<lli> dp(n,0);
	if(forbidden.find(n-1)==forbidden.end())
	{
		dp[n-1]=1;
	}
	if(forbidden.find(n-2)==forbidden.end())
	{
		dp[n-2]=1;
	}
	for(lli i=n-3;i>=0;i--)
	{
		if(forbidden.find(i)==forbidden.end())
		{
			dp[i]=(dp[i+1]+dp[i+2])%mod;
		}

	}
	cout<<(dp[0]+dp[1])%mod<<endl;


	return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define ff first
#define ss second 
#define MP make _pair
#define PB push_back
#define ll long long
#define pri 1000000007
using namespace std;
void run(){
	ll n,k;
	cin>>n>>k;
	ll a[n+1];
	for(ll i=1;i<=n;i++){cin>>a[i];}
	ll dp[n+1][k+1];
	for(ll i=0;i<k+1;i++)for(ll j=0;j<=n;j++)dp[j][i]=0;
		for(ll i=0;i<k+1;i++)dp[0][i]=1;
	for(ll i=1;i<=n;i++){
	  ll sm=0;
		for(ll j=0;j<=k;j++)
	{
	    sm=(dp[i-1][j]-(j-a[i]-1>=0?dp[i-1][j-a[i]-1]:0)+pri+sm)%pri;
		dp[i][j]=(dp[i][j]+sm)%pri;
	}
	
	}
cout<<(dp[n][k]-(k-1>=0?dp[n][k-1]:0)+pri)%pri;
	
}
int main() {
	run();
	// your code goes here
	return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};




int main(){
    int N,D;cin >>N >> D;
    cout<<N/(2*D+1) + (N%(2*D+1) != 0 ? 1 : 0)<<endl;;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace abc161
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            var chars = s.ToCharArray();
            var ans = chars[2] == chars[3] && chars[4] == chars[5] ? "Yes" : "No";
            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int ans = 1, count = 0;
    for(int i = 1; i <= N; i++){
        int c = 0, t = i;
        while(t % 2 == 0){
            c++; t /= 2;
        }
        if(c > count){
            count = c; ans = i;
        }

    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int s[200000][2];

int main(void)
{
    int N, M, Q;
    int a, q;
    int b;
    int i, j;
    int next_b, before_b;
    
    
    scanf("%d%d%d", &N, &M, &Q);
    
    for (i = 0; i < N; i++){
        s[i][0] = 1;
        s[i][1] = -1;
    }
    
    b = 0;
    for (i = 0; i < M; i++){
        scanf("%d", &a);
        if (a % 2 == 0){
            for (j = 0; j < a; j++){
                b += s[b][0];
                b %= N;
            }
            next_b = (b + s[b][0]) % N;
            before_b = (b + s[b][1] + N) % N;
            
            s[before_b][0] += s[b][0];
            s[next_b][1] += s[b][1];

            s[b][0] = s[b][1] = 0;

            b = next_b;
        }
        else {
            for (j = 0; j < a; j++){
                b += s[b][1];
                b = (b + N) % N;
            }
            next_b = (b + s[b][0]) % N;
            before_b = (b + s[b][1] + N) % N;

            s[before_b][0] += s[b][0];
            s[next_b][1] += s[b][1];

            s[b][0] = s[b][1] = 0;

            b = next_b;
        }
        
//        printf("%d:", b);
//        for (j = 0; j < N; j++){
//            printf("(%d,%d)", s[j][0], s[j][1]);
//        }
//        printf("\n");
        
    }
    for (i = 0; i < Q; i++){
        scanf("%d", &q);
        printf("%d\n", (s[q][0] == 0 ? 0: 1));
    }
    return (0);
    
}
                    


Measured memory_bytes: 3284
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();


bool cmp(pair<int,int>p,pair<int,int>q) {
    // return p.first>q.first;//descending by first
    // return p.first<q.first;//ascending by first
    // return p.second>q.second;//descending by second
    return p.second<q.second;//ascending by second
}

// bool cmp(int p,int q) {
    // return p>q;//descending
    // return p<q;//ascending
// }


int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    lli n;
    int k;
    cin>>n>>k;
    lli count=0;
    while(n!=0) {
        ++count;
        n/=k;
    }
    cout<<count<<endl;
    // ()?cout<<"Yes"<<endl:cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define MP make_pair
#define int long long int
using namespace std;
typedef pair<int, int> PII;
const int INF = 3e18;

int n, d, x[200010], y[200010], b[200010];

PII sorted[200010];
int ans = 0;

struct segtree
{
  int tree[524288];
  int size;

  void reset(bool option = false)
  {
    size = 1;
    while(size < n){
      size <<= 1;
    }

    if(option){
      for(int i = 0; i < size * 2 - 1; i++){
	tree[i] = -INF;
      }
    }
  }

  void update(int where, int val)
  {
    int now = size - 1 + where;
    tree[now] = val;
    while(now > 0){
      now = (now - 1) / 2;
      tree[now] = max(tree[now * 2 + 1], tree[now * 2 + 2]);
    }
  }

  int top()
  {
    return tree[0];
  }
} xmin, xmax, ymin, ymax;

signed main(){
  scanf("%lld%lld", &n, &d);
  for(int i = 0; i < n; i++){
    scanf("%lld%lld%lld", &x[i], &y[i], &b[i]);
  }

  for(int i = 0; i < n; i++){
    sorted[i] = MP(b[i], i);
  }

  sort(sorted, sorted + n);

  xmin.reset(true), xmax.reset(), ymin.reset(true), ymax.reset();

  int start = 0, nowd = 0;
  for(int i = 0; i < n; i++){
    nowd = sorted[i].first;
    xmin.update(i, -x[sorted[i].second]);
    xmax.update(i, x[sorted[i].second]);
    ymin.update(i, -y[sorted[i].second]);
    ymax.update(i, y[sorted[i].second]);

    while(start < n){
      if(sorted[start].first < nowd - d){
	xmin.update(start, -INF);
	xmax.update(start, 0);
	ymin.update(start, -INF);
	ymax.update(start, 0);
	start++;
      }
      else{
	break;
      }
    }

    ans = max(ans, (xmax.top() + xmin.top()) * (ymax.top() + ymin.top()));
  }

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

Measured memory_bytes: 24940
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define ALL(x) begin(x), end(x)
using ll = long long;
using namespace std;

int main() {
    // input
    int n, m; cin >> n >> m;
    vector<ll> a(n);
    REP (i, n) {
        cin >> a[i];
    }
    vector<int> b(m);
    vector<ll> c(m);
    REP (j, m) {
        cin >> b[j] >> c[j];
    }

    // solve
    sort(ALL(a));
    vector<int> order(m);
    iota(ALL(order), 0);
    sort(ALL(order), [&](int i, int j) {
        return c[i] > c[j];  // reversed
    });
    int i = 0;
    for (int j : order) {
        REP (k, b[j]) {
            if (i < n and a[i] < c[j]) {
                a[i] = c[j];
                ++ i;
            } else {
                break;
            }
        }
    }

    // output
    cout << accumulate(ALL(a), 0ll) << endl;
    return 0;
}


Measured memory_bytes: 2560
n = int(input())
a = list(map(int,input().split()))
a = sorted(a,reverse=True)
ans = 0
b = a[0]
j = 0
for i in range(1,n):
    ans += b
    if i%2 == 1:
        j += 1
        b = a[j]
print(ans)

Measured memory_bytes: 31760
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <math.h>
using namespace std;

int main(int argc, char const *argv[]){
    int n,m;
    cin >> n >> m;

    long sum = 0;

    vector<int> a(n);

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

    if (a.size() == 1) {
        a[0] = a[0]/pow(2,m);
    }
    else {
        sort(a.begin(),a.end());

        for (int cnt = 0; cnt < m; cnt++)
        {
            int tar;
            tar = a.back();
            
            if (tar == 0) {
                break;
            }
            
            a.pop_back();
            int discount = tar/2.0;
            int head = -1;
            int tail = a.size();
            int mid;

            while(tail-head > 1) {
                mid = head + (tail-head)/2;

                if (a[mid] >= discount) tail = mid;
                else head = mid;
            }
            a.insert(a.begin()+tail,discount);            
        }
    }
    for (int i = 0; i < n; i++)
    {
        sum += a[i];
    }
    
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

vector<int> dijkstra(int i, int n, vector<vector<pair<int, int>>> graph) {
  vector<int> d(n, INF);
  d[i] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;
  q.push(make_pair(0, i));
  while (!q.empty()) {
    pair<int, int> p = q.top();
    q.pop();
    int v = p.second;
    if (d[v] < p.first) {
      continue;
    }
    for (auto x : graph[v]) {
      if (d[x.first] > d[v] + x.second) {
        d[x.first] = d[v] + x.second;
        q.push(pair<int, int>(d[x.first], x.first));
      }
    }
  }
  return d;
}

signed main() {
  int N; 
  cin >> N;

  vector<vector<pair<int, int>>> graph(N);
  REP(i, N-1){
    int u, v, d;
    cin >> u >> v >> d;
    u--; v--;
    graph[u].emplace_back(v, d);
    graph[v].emplace_back(u, d);
  }
  
  int Q, K;
  cin >> Q >> K;

  auto dist = dijkstra(K-1, N, graph);

  while(Q--){
    int x, y;
    cin >> x >> y;
    x--; y--;
    cout << dist[x]+dist[y] << "\n";
  }

  return 0;
}

Measured memory_bytes: 18160
from math import floor

N, M = map(int, input().split())
if N%2 == 1:
    for p1 in range(1, M+1):
        p2 = M*2+1-p1
        print(p1, p2)
else:
    for p1 in range(1, min(M,floor(N/4))+1):
        p2 = N-p1+1
        print(p1, p2)
    for p1 in range(p1+1, M+1):
        p2 = N-p1
        print(p1, p2)


Measured memory_bytes: 9272
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
  ll a,b;
  cin >> a >> b;
  ll x;
  cin >> x;
  ll d = b/x+1;
  ll f = (a-1)/x+1;
  if(a == 0)
    f = 0;
  
  //d -= a/x;
  cout << d-f << endl;
  return 0;
}


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

int main() {
    int n; cin >> n;
    vector<vector<int>> charn(n, vector<int>(26));
    for (int i=0; i<n; ++i) {
        string s; cin >> s;
        for (char j: s) {
            charn[i][j - 'a']++;;
        }
    }
    vector<int> ans(26);
    for (int i=0; i<26; ++i) {
        int minn = 100;
        for (int j=0; j<n; ++j) {
            minn = min(minn, charn[j][i]);
        }
        for (int j=0; j<minn; ++j) cout << (char)('a' + i);
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n, y;

    cin >> n >> y;
    for (int i = 0; i <= n; i++) {
        for ( int j = 0; j + i <= n; j++) {
            int k = n - i - j;

            if ( i * 10000 + j * 5000 + k * 1000 == y ) {
                printf("%d %d %d\n", i, j, k);
                return (0);
            }
        }
    }

    printf("-1 -1 -1\n");

    return 0;
}
// 自分でも驚くほど汚いコードを描いたと思う


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

int main() {
  int n;
  while (cin >> n, n) {
    auto v = vector<int>(n);
    for (int i = 0; i < n; ++i) cin >> v[i];
    sort(begin(v), end(v));
    int s = accumulate(begin(v) + 1, end(v) - 1, 0);
    cout << s / (n - 2) << endl;
  }
  return 0;
}



Measured memory_bytes: 3056