akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
"""
input:
5 6
0 1
1 0
1 2
2 4
4 3
3 2
4
0 1
0 3
2 3
3 4
 
output:
1
0
1
1
"""
 
import sys
from math import isinf
 
sys.setrecursionlimit(int(1e5))
 
 
def generate_adj_table(_v_info):
    for v_detail in _v_info:
        v_from, v_to = map(int, v_detail)
        init_adj_table[v_from].append(v_to)
    return init_adj_table
 
 
def Tarjan(current, low, dfn, scc_stack, in_scc_stack):
    global timer
    dfn[current] = low[current] = timer
    timer += 1
 
    scc_stack.append(current)
    in_scc_stack[current] = True
 
    current_scc_set = set()
    for adj in adj_table[current]:
        if isinf(dfn[adj]):
            Tarjan(adj, low, dfn, scc_stack, in_scc_stack)
            low[current] = min(low[current], low[adj])
 
        elif in_scc_stack[adj]:
            low[current] = min(low[current], dfn[adj])
 
    scc_candidate = -1
    if dfn[current] == low[current]:
        while scc_candidate != current:
            scc_candidate = scc_stack.pop()
            in_scc_stack[scc_candidate] = False
            current_scc_set.add(scc_candidate)
 
        init_scc_sets_list.append(current_scc_set)
 
    return None
 
 
def scc_cluster():
    dfn = [float('inf')] * vertices
    low = [float('inf')] * vertices
    scc_stack = list()
    in_scc_stack = [False] * vertices
 
    for v in range(vertices):
        if isinf(dfn[v]):
            Tarjan(v, low, dfn, scc_stack, in_scc_stack)
 
    return init_scc_sets_list
 
 
def solve(_scc_sets_list):
    for question in q_list:
        flag = False
        ele1, ele2 = map(int, question)
        for each in _scc_sets_list:
            if (ele1 in each) and (ele2 in each):
                flag = True
                break
        if flag:
            print('1')
        else:
            print('0')
 
    return None
 
 
if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:edges + 1])
    q_num = int(_input[edges + 1])
    q_list = map(lambda x: x.split(), _input[edges + 2:])
 
    init_adj_table = tuple([] for _ in range(vertices))
    adj_table = generate_adj_table(v_info)
 
    timer = 0
    init_scc_sets_list = []
    scc_sets_list = scc_cluster()
 
    solve(scc_sets_list)

Measured memory_bytes: 26548
import java.util.*;

public class Main {

    static int DAT_SIZE = (1<<24)-1;

    static long[] data = new long[DAT_SIZE];
    static long[] datb = new long[DAT_SIZE];

    static void add(int a, int b, long x, int k, int l, int r) {
        if (a<=l && r<=b) {
            data[k] += x;
        } else if (l<b && a<r) {
            datb[k] += (Math.min(b, r) - Math.max(a, l))*x;
            add(a, b, x, k*2+1, l, (l+r)/2);
            add(a, b, x, k*2+2, (l+r)/2, r);
        }
    }

    static long sum(int a, int b, int k, int l, int r) {
        if (b<=l || r<=a) {
            return 0;
        } else if (a<=l && r<=b) {
            return data[k]*(r-l)+datb[k];
        } else {
            long res = (Math.min(b, r) - Math.max(a, l)) * data[k];
            res += sum(a, b, k*2+1, l, (l+r)/2);
            res += sum(a, b, k*2+2, (l+r)/2, r);
            return res;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int D = Integer.parseInt(sc.next());
        int A = Integer.parseInt(sc.next());
        Long[] X = new Long[N];
        ArrayList<long[]> list = new ArrayList<long[]>();
        for (int i=0;i<N;i++) {
            X[i] = Long.parseLong(sc.next());
            long H = Integer.parseInt(sc.next());
            long[] add = {X[i], (H+A-1)/A};
            list.add(add);
        }
        Collections.sort(list, (o1, o2)->Long.compare(o1[0], o2[0]));
        for (int i=0;i<N;i++) {
            add(i, i+1, list.get(i)[1], 0, 0, N);
        }
        Arrays.sort(X);
        int[] index = new int[N];
        long ans = 0;
        for (int i=0;i<N;i++) {
            index[i] = ~Arrays.binarySearch(X, X[i]+2*D+1, (o1, o2)->o1>=o2?1:-1);
            long cnt = sum(i, i+1, 0, 0, N);
            if (cnt<=0) continue;
            add(i, index[i], -cnt, 0, 0, N);
            ans += cnt;
        }
        // System.out.println(Arrays.toString(X));
        // System.out.println(Arrays.toString(index));
        System.out.println(ans);
    }
}

Measured memory_bytes: 364552
#include<stack>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#include<iostream>
#define INF 0x7fffffff//1<<31-1
#define IP 3.141592654
#define LINF 9223372036854775807//1<<63-1
#define rep(i,a,b) for(long long i=a;i<b;i++)
#define per(i,a,b) for(long long i=b-1;i>=a;i--)
using namespace std;
typedef long long LL;
const int maxn=2e5+10;
const int maxm=1e8+10;


int main()
{
    int a,b;scanf("%d%d",&a,&b);
    if(a>b)cout<<a-b<<endl;
    else cout<<"0"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void)
{
    int  a,b[2000],i,j,n=0,m,x,y,z=0;
    char c[10100],s[10100];

    scanf("%d",&a);
    scanf("%s",s);
    for (size_t i = 0; i < a; i++)
    {
     if(s[i]==s[a/2+i]) z++;
    }
    if(a%2==1) printf("No");
    else if(z==a/2) printf("Yes");
    else printf("No");
    printf("\n");
    return 0;
}

Measured memory_bytes: 128
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import heapq

n, m = map(int, readline().split())
a = list(map(lambda x: int(x)*(-1), readline().split()))
heapq.heapify(a)
for i in range(m):
    memo = heapq.heappop(a)
    heapq.heappush(a, (-memo // 2) * (-1))
print(-sum(a))


Measured memory_bytes: 12600
#include <stdio.h>
#define N 100

int M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u,int n){
    int v;
    color[u] = 1;
    d[u] = ++tt;
    for(v=0;v<n;v++){
        if(M[u][v] == 0) continue;
        if(color[v] == 0){
            dfs_visit(v,n);
        }
    }
    color[u] = 2;
    f[u] = ++tt;
}

void dfs(int n){
    int u;
    for(u=0;u<n;u++) color[u] = 0;
    tt = 0;
    for(u=0;u<n;u++) if(color[u] == 0) dfs_visit(u,n);
    for(u=0;u<n;u++) printf("%d %d %d\n",u+1,d[u],f[u]);
}

int main(void){
    int n,u,v,k,i,j;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            M[i][j] = 0;
        }
    }
    for(i=0;i<n;i++){
        scanf("%d %d",&u,&k);
        u--;
        for(j=0;j<k;j++){
            scanf("%d",&v);
            v--;
            M[u][v]=1;
        }
    }
    dfs(n);
    
    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
#define yn {puts("Yes");}else{puts("No");}

// long long version
const int MAX_N = 300005;
ll bit[MAX_N+1];
int nn = MAX_N; //　1-index

void adds(int a, ll w){
    for(int x = a; x <= nn; x += x & -x) bit[x] += w;
}
ll sums(int a){ // bit[1,a]の和を返す.
    ll ret = 0;
    for(int x = a; x > 0; x -= x & -x) ret += bit[x];  
    return ret;
}

int main() {
    ll n, d, a;
    cin >> n >> d >> a;

    vector<P> v;
    rep(i,n){
        int x, h;
        cin >> x >> h;
        v.push_back(P(x, h));
    }

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

    ll b[n];
    rep(i,n)b[i] = v[i].first;

    ll ans = 0;

    int i = 0;

    while(true){
        ll x = v[i].first;
        ll y = v[i].second;
        ll xd = x + d + d;
        int j = lower_bound(b, b+n, xd+1) - b;
        ll cnt = sums(i+1);
        if(cnt * a >= y){
            i++;
        }else{
            y -= cnt * a;
            ll z = (y - 1) / a + 1;
            ans += z;
            adds(i+1, z);
            adds(j+1, -z);
            i++;
        }
        if(i == n)break;
    }

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


Measured memory_bytes: 7148
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits>
#include <queue>
#include <utility>

using namespace std;

const int Inf = numeric_limits<int>::max();

bool outside(int i, int j, int H, int W){
    if (i < 0) return true;
    if (i >=H) return true;
    if (j < 0) return true;
    if (j >=W) return true;
    return false;
}

int main(int argc, char** argv){
    int H, W;
    cin >> H >> W;

    vector<vector<int>> v(H, vector<int>(W, Inf));
    queue<pair<int, int>> q;
    for (int i=0; i<H; i++){
        string s;
        cin >> s;
        for (int j=0; j<W; j++)
            if (s[j] == '#'){
                v[i][j] = 0;
                q.push(make_pair(i, j));
            }
    }

    while (!q.empty()){
        pair<int, int> p = q.front();
        q.pop();
        int i = p.first;
        int j = p.second;
        int k, l;
        for (int h=0; h<4; h++){
            switch (h){
                case 0:
                    k = i-1; l = j;
                    break;
                case 1:
                    k = i;   l = j-1;
                    break;
                case 2:
                    k = i;   l = j+1;
                    break;
                case 3:
                    k = i+1; l = j;
                    break;
            }
            if (outside(k, l, H, W)) continue;
            if (v[k][l] == Inf){
                v[k][l] = v[i][j] + 1;
                q.push(make_pair(k, l));
            }
        }
    }

    int ans = 0;
    for (int i=0; i<H; i++){
        for (int j=0; j<W; j++){
            ans = max(ans, v[i][j]);
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 12432
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

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

    Graph G(n);
    for(int i = 0;i < n; i++){
        int u, k;
        cin >> u >> k;
        for(int j = 0; j < k; j++){
            int v;
            cin >> v;
            G[u-1].push_back(v-1);
        }
    }

    vector<int> dist(n, -1);
    queue<int> que;

    dist[0] = 0;
    que.push(0);

    while(!que.empty()){
        int v = que.front();
        que.pop();

        for(int nv: G[v]){
            if(dist[nv] != -1) continue;

            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }

    for(int i = 0; i < n; i++) cout << i+1 << ' ' << dist[i] << endl;
}


Measured memory_bytes: 3160
package main

import (
    "fmt"
    "os"
    "bufio"
    "strings"
    "strconv"
    "math"
)

var sc = bufio.NewScanner(os.Stdin)

func StrStdin() (stringInput string){
  sc.Scan()
  OneLineString := sc.Text()
  stringInput = strings.TrimSpace(OneLineString)
  return 
}

func IntStdin() (int, error){
  stringInput := StrStdin()
  return strconv.Atoi(stringInput)
}

func SplitWithoutEmpty(stringTargeted string, delim string) (stringReturned []string) {
    stringSplited := strings.Split(stringTargeted, delim)

    for _, str := range stringSplited {
        if str != "" {
            stringReturned = append(stringReturned, str)
        }
    }

    return
}

func SplitStrStdin(delim string) (stringReturned []string) {
    stringInput := StrStdin()
  
    stringReturned = SplitWithoutEmpty(stringInput, delim)

    return
}

func SplitIntStdin(delim string) (intSlices []int, err error) {
    stringSplited := SplitStrStdin(delim)
	
    for i := range stringSplited {
        var iparam int
        iparam, err = strconv.Atoi(stringSplited[i])
        if err != nil {
            return
        }
        intSlices = append(intSlices, iparam)
    }
    return
}

func main(){
  first := SplitStrStdin(" ")
  
  result := ""
    for _, value := range first {
      result += value
    }
  
  a, error := strconv.Atoi(result)
  if error == nil{ 
    b := math.Sqrt(float64(a))
    
    if int(b)*int(b) == a {
      fmt.Println("Yes")
    }else{
      fmt.Println("No")
    }
  }
  
}


Measured memory_bytes: 640
n, m = map(int, input().split())

sc =[]
for j in range(m):
    s, c = map(int, input().split())
    s -= 1
    sc.append([s, c])


for i in range(10**n):
    i = str(i)
    if len(i) == n:
        judge = True
        for j in sc:
            if i[j[0]] != str(j[1]):
                judge = False
        if judge:
            print(i)
            exit()

print(-1)

Measured memory_bytes: 3064
import java.util.*;
import java.io.PrintWriter;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long x=sc.nextLong();
		long y=sc.nextLong();
		if(Math.abs(x-y)<=1){
			System.out.println("Brown");
		}else{
			System.out.println("Alice");
		}
	}
}


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

const ll INF = 1e12;

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

    ll h,n;
    cin >> h >> n;

    vector<vector<ll>> dp(1010,vector<ll>(10100,INF));
    vector<ll> w(n+1);
    vector<ll> v(n+1);

    for(int i = 1; i <= n; i++){
        cin >> v[i] >> w[i];
    }

    for(int i = 1; i <= n; i++){
        for(int j = 0; j <= h; j++){
            if(v[i] >= j) {
                dp[i][j] = min(w[i],dp[i-1][j]);
            } else {
                dp[i][j] = min(dp[i-1][j], dp[i][j - v[i]] + w[i]);
            }
        }
    }

    ll ans = INF;
    for(int i = 0; i <= n; i++){
        ans = min(ans, dp[i][h]);
    }
    cout << ans << endl;
}



Measured memory_bytes: 80128
dic=dict()
n=int(input())
for i in range(n):
    s=input()
    if s in dic:
        dic[s]+=1
    else:
        dic[s]=1
if "AC" in dic:
    print("AC x",dic["AC"])
else:
    print("AC x 0")
if "WA" in dic:
    print("WA x",dic["WA"])
else:
    print("WA x 0")
if "TLE" in dic:
    print("TLE x",dic["TLE"])
else:
    print("TLE x 0")
if "RE" in dic:
    print("RE x",dic["RE"])
else:
    print("RE x 0")
               


Measured memory_bytes: 69836
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> S(1<<N);
    map<int,int> m;
    for(int i=0;i<(1<<N);i++){
        cin >> S[i];
        m[S[i]]++;
    }
    sort(S.begin(),S.end(),greater<int>());

    auto decrement = [&](int value){
        m[value]--;
        if(m[value]==0) m.erase(value);
    };
    vector<int> exist;
    exist.push_back(S[0]);
    decrement(S[0]);
    for(int i=0;i<N;i++){
        sort(exist.begin(),exist.end(),greater<int>());
        vector<int> nexist = exist; 
        for(auto x:exist){
            map<int,int>::iterator it = m.lower_bound(x);
            if(it==m.begin()){
                cout << "No" << endl;
                return 0;
            }
            it--;
            nexist.push_back(it->first);
            decrement(it->first);
        }
        exist = nexist;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 15600
#include <bits/stdc++.h>
using namespace::std;
#define all(x) (x).begin(),(x).end()
#define int long long


signed main() { /*[J][O][L][S][K][E][Y]*/
        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int k, a, b; cin >> k >> a >> b;
        for (int i = 0; i <= b; i += k) {
                if (i >= a && i <= b) {
                        cout << "OK";
                        return 0;
                }
        }

        cout << "NG"
;        return 0;
}

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

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

ll kaizyou(ll N){
  ll num=1;
  for(ll i=1;i<=N;i++){
  num*=i;
  }
  return num;
}

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

 
int main(){
  int h,n;
  cin >> h >> n;
  vector<int>a(n);
  rep(i,n){
    cin >> a[i];
  }
  int num=0;
  rep(i,n){
    num+=a[i];
  }
  if(num>=h){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}
      
  
  
  

Measured memory_bytes: 640
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	final long MOD = (long) 1e9 + 7;

	void run() {
		Scanner sc = new Scanner(System.in);
		long K = sc.nextLong();
		int X = sc.nextInt();
		int Y = sc.nextInt();
		int signX = X == 0 ? 1 : X / Math.abs(X);
		int signY = Y == 0 ? 1 : Y / Math.abs(Y);
		X = Math.abs(X);
		Y = Math.abs(Y);
		if (K % 2 == 0 && (X + Y) % 2 == 1) {
			System.out.println(-1);
			return;
		}
		if (X + Y == K) {
			System.out.println(1);
			System.out.println(X * signX + " " + Y * signY);
			return;
		}
		boolean flip = X > Y;
		if (X > Y) {
			X ^= Y;
			Y ^= X;
			X ^= Y;
			signX ^= signY;
			signY ^= signX;
			signX ^= signY;
		}
		if (X < K && Y < K) {
			if ((X + Y) % 2 == 0) {
				long n = 2;
				go(X, Y, K, n, signX, signY, flip);
			} else {
				if (X + Y >= K) {
					long n = 3;
					go(X, Y, K, n, signX, signY, flip);
				} else {
					System.out.println(3);
					long[][] ans = new long[3][2];
					ans[0] = new long[] { X, K - X };
					ans[1] = new long[] { (K + X + Y) / 2, -(K - (K + X + Y) / 2) };
					ans[2] = new long[] { -ans[1][0], ans[1][1] };
					int curX = 0;
					int curY = 0;
					for (int i = 0; i < ans.length; ++i) {
						ans[i][0] *= signX;
						ans[i][1] *= signY;
						if (flip) {
							ans[i][0] ^= ans[i][1];
							ans[i][1] ^= ans[i][0];
							ans[i][0] ^= ans[i][1];
						}
						curX += ans[i][0];
						curY += ans[i][1];
						System.out.println(curX + " " + curY);
					}
				}
			}
			return;
		}
		long n = (X + Y + K - 1) / K;
		if (K % 2 == 1 && n % 2 != (X + Y) % 2) {
			++n;
		}
		go(X, Y, K, n, signX, signY, flip);
	}

	void go(long X, long Y, long K, long n, int signX, int signY, boolean flip) {
		System.out.println(n);
		long[][] ans = new long[(int) n][2];
		int p = 0;
		long delta = (n * K - X - Y) / 2;
		long cnt1 = X + delta;
		long cnt2 = Y;
		long cnt3 = delta;
		for (int i = 0; i < cnt1 / K; ++i) {
			ans[p++] = new long[] { K, 0 };
		}
		cnt1 %= K;
		if (cnt1 != 0) {
			ans[p++] = new long[] { cnt1, K - cnt1 };
			cnt2 -= K - cnt1;
			cnt1 = 0;
		}
		for (int i = 0; i < cnt2 / K; ++i) {
			ans[p++] = new long[] { 0, K };
		}
		cnt2 %= K;
		if (cnt2 > 0) {
			ans[p++] = new long[] { -(K - cnt2), cnt2 };
			cnt3 -= (K - cnt2);
			cnt2 = 0;
		}
		if (cnt3 % K != 0) {
			tr("err", cnt3, K);
			throw new AssertionError();
		}

		for (int i = 0; i < cnt3 / K; ++i) {
			ans[p++] = new long[] { K, 0 };
		}
		int curX = 0;
		int curY = 0;
		for (int i = 0; i < ans.length; ++i) {
			ans[i][0] *= signX;
			ans[i][1] *= signY;
			if (flip) {
				ans[i][0] ^= ans[i][1];
				ans[i][1] ^= ans[i][0];
				ans[i][0] ^= ans[i][1];
			}
			curX += ans[i][0];
			curY += ans[i][1];
			System.out.println(curX + " " + curY);
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}

Measured memory_bytes: 53444
K, X = map(int, input().split())
min_X = X - (K - 1)
max_X = X + (K - 1)
answer_list = [i for i in range(max(min_X, -1000000), min(max_X + 1, 1000001), 1)]
print(" ".join(map(str, answer_list)))

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

int Min(int a, int b) { if (a < b) { return a; }return b; }

typedef struct {
	int i;
	int num;
}set;

signed compair(const void *a, const void *b) {
	return ((set *)b)->num - ((set *)a)->num;
}

int main() {
	int i, N;
	int z = 100002;
	int ans = 0, tmpa, tmpb;
	scanf("%d", &N);
	int *V = (int *)malloc(sizeof(int)*N);
	set *A = (set *)malloc(sizeof(set)*z);
	set *B = (set *)malloc(sizeof(set)*z);
	for (i = 0; i < z; i++) {
		A[i].num = 0;
		B[i].num = 0;
		A[i].i = i;
		B[i].i = i;
	}
	for (int i = 0; i < N; i++) {
		scanf("%d", &V[i]);
		if (i % 2 == 0) {
			A[V[i]].num++;
		}
		else {
			B[V[i]].num++;
		}
	}
	qsort(A, z, sizeof(set), compair);
	qsort(B, z, sizeof(set), compair);
	if (A[0].i != B[0].i && A[1].num==0 && B[1].num == 0)
	{
		ans = 0;
	}
	else if (A[0].i != B[0].i)
	{
		ans = abs(N / 2 - A[0].num) + abs(N / 2 - B[0].num);
	}
	else if (A[0].i == B[0].i)
	{
		tmpa = abs(N / 2 - A[0].num) + abs(N / 2 - B[1].num);
		tmpb = abs(N / 2 - B[0].num) + abs(N / 2 - A[1].num);
		ans = Min(tmpa, tmpb);
	}

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

Measured memory_bytes: 2736
#include<bits/stdc++.h>
using namespace std;
//#include<ext/rope>
//using namespace __gnu_cxx
//#include<ext/pb_ds/priority_queue.hpp>
//using namespace __gnu_pbds;
#define lowbit(x) (x&-x)
#define pb push_back
#define empb emplace_back
#define all(x) (x).begin(),(x).end()
#define clr(a,b) memset(a,b,sizeof(a))
#define caze(T) for(cin>>T;T;T--)
#define inf (1<<29)
#define Endl ('\n')
#define fi first
#define se second
#define db double
#define ldb long double
#define ll long long
#define pii pair<int,int>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define ull unsigned long long
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
inline char nc() {
	#define SZ 1000000
	static char buf[SZ], *p1, *p2;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,SZ,stdin),p1==p2)?EOF:*p1++;
}
template<typename T>
inline int scan(T &x) {
	char c, sign=1; 
	while(!isdigit(c=nc())&&c!=EOF)if(c=='-')sign*=-1;
	if(c==EOF) return EOF;
	for(x = 0; isdigit(c); c = nc())
		x = (x<<1) + (x<<3) + (c&15);
	return x *= sign, 1;
}
template<typename T, typename...Args>
inline int scan(T &x, Args&...args) {
	return scan(x), scan(args...);
}
const int N=5050;
const int mod=1000000007;
int dp[N][N];
char s[N];
void upd(int &x,int y){x+=y;if(x>=mod)x-=mod;}
int main()
{
	int n,m;
	cin>>n>>s;
	m=strlen(s);
	dp[0][0]=1;
	for(int i=1;i<=n;++i)
	{
		upd(dp[i][0],dp[i-1][0]);
		for(int j=1;j<=i;++j)
		{
			upd(dp[i][j-1],dp[i-1][j]);
			upd(dp[i][j],dp[i-1][j-1]);
			upd(dp[i][j],dp[i-1][j-1]);
		}
	}
	const int iv=(mod+1)/2;
	int ans=dp[n][m];
	for(int i=0;i<m;++i)
		ans=1LL*ans*iv%mod;
	cout<<ans<<Endl;
}

Measured memory_bytes: 97280
#include<iostream>
using namespace std;
int main(){
    while(1){
	    int a,b;
    	char op;
        cin>>a>>op>>b;
        if(op=='?')break;
        if(op=='+'){
            cout<<a+b<<endl;
        }else if(op=='-'){
            cout<<a-b<<endl;
        }else if(op=='*'){
            cout<<a*b<<endl;
        }else if(op=='/'){
            cout<<a/b<<endl;
        }
        
    }
    return 0;
    
}


Measured memory_bytes: 3108
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        String[] number = line.split(" ");
        int x = Integer.parseInt(number[0]);
        int y = Integer.parseInt(number[1]);
        int[] groupB = new int[4];
        groupB[0] = 4;
        groupB[1] = 6;
        groupB[2] = 9;
        groupB[3] = 11;
        boolean yorn = false;
        boolean firstif = true;
        boolean firstelse = true;
        
        if((x == 2) || (y == 2)) {
            yorn = false;
        } else {
            for(int i = 0; i < 4; i++) {
                if((groupB[i] == x) && firstif) {
                    yorn = false;
                    for(int j = i + 1; j < 4; j++) {
                        if(groupB[j] == y) {
                            yorn = yorn || true;
                        } else {
                            yorn = yorn || false;
                        }
                    }
                    firstif = false;
                } else if(firstelse && firstif) {
                    yorn = true;
                    for(int j = i + 1; j < 4; j++) {
                        if(groupB[j] == y) {
                            yorn = yorn && false;
                            firstelse = false;
                        } else {
                            yorn = yorn && true;
                        }
                    }
                }
            }
        }
        if(yorn) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 21460
A,B,N=map(int,input().split())
if B!=1:
	p=(N+1)//B
	result=0
	if p!=0:
		for a in range(1,p+1):
			x=a*B-1
			s=(A*x)//B - A*(a-1)
			if result < s:
				result=s
	else:
		result=A*N//B -A*(N//B)
	print(result)
else:
	print(0)

Measured memory_bytes: 9204
package main

import "fmt"

func main() {

	var x, y int

	for  {
		fmt.Scan(&y,&x)
		if x==0 && y==0 {
			break
		}

		for row:=0; row<y; row++ {
			for col:=0; col<x; col++ {
				fmt.Print("#")
			}
			fmt.Print("\n")
		}
		fmt.Print("\n")
	}
}


Measured memory_bytes: 1128
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <string>
#include <sstream>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;
int n, k;
vector<int> a;
int main(int argc, char *argv[]) {
    cin >> n >> k;
    a.resize(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    // dp[i] == true if first player wins if there is no stones remaining to make next move
    vector<bool> dp(k + 1);
    for (int stones = 0; stones <= k; ++stones) {
        for (int x: a) {
            if (stones >= x && !dp[stones - x]) {
                dp[stones] = true;
            }
        }
    }
    cout << (dp[k] ? "First" : "Second") << endl;
    return 0;
}

Measured memory_bytes: 256
name1,a1,b1 = map(str,input().split())
name2,a2,b2 = map(str,input().split())
name3,a3,b3 = map(str,input().split())
name4,a4,b4 = map(str,input().split())
name5,a5,b5 = map(str,input().split())
name6,a6,b6 = map(str,input().split())
name7,a7,b7 = map(str,input().split())
name8,a8,b8 = map(str,input().split())
name9,a9,b9 = map(str,input().split())
print(name1,int(a1)+int(b1),int(a1)*200+int(b1)*300)
print(name2,int(a2)+int(b2),int(a2)*200+int(b2)*300)
print(name3,int(a3)+int(b3),int(a3)*200+int(b3)*300)
print(name4,int(a4)+int(b4),int(a4)*200+int(b4)*300)
print(name5,int(a5)+int(b5),int(a5)*200+int(b5)*300)
print(name6,int(a6)+int(b6),int(a6)*200+int(b6)*300)
print(name7,int(a7)+int(b7),int(a7)*200+int(b7)*300)
print(name8,int(a8)+int(b8),int(a8)*200+int(b8)*300)
print(name9,int(a9)+int(b9),int(a9)*200+int(b9)*300)


Measured memory_bytes: 5600
import java.util.*

fun <T> calcPermutationList(sortedList: Array<T>): List<List<T>> {
    val permutationList = mutableListOf<List<T>>()
    val queue = ArrayDeque<List<T>>().apply { addFirst(listOf()) }
    while (queue.isNotEmpty()) {
        val p = queue.removeFirst()

        if (p.size == sortedList.size) {
            permutationList += p
        } else {
            queue += sortedList.filterNot { p.contains(it) }.map { p + it }
        }
    }

    return permutationList
}

fun main(args: Array<String>) {
    val n = readInteger()
    val p = readIntegerList()
    val q = readIntegerList()

    calcPermutationList((1..n).toList().toTypedArray())
        .let { it.indexOf(p) - it.indexOf(q) }
        .let(Math::abs)
        .let(::println)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 54568
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
 
const ll mm = 1e9+7;
 
 
ll kai(ll a,ll b){
    ll ans =1;
    while(a>b){
        ans=(ans*a)%mm;
      
        a--;
    }
    return ans;
}
 
 
ll joyou(ll a,ll b){
    ll ans=1;
    while (b) {
        ans*=a;
        ans%=mm;
        b--;
    }
    return ans;
}
 
int main() {
    ll N;
    cin >> N;
    ll rid = (joyou(9, N)*2)%mm - joyou(8, N);
    if(rid<0)rid+=mm;
    ll ans = joyou(10, N)-rid;
    if(ans<0)ans+=mm;
    cout << ans%mm << endl;
    
    
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include<bitset>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); ++i)
#define loops(i,f,n) for(int i = (f); i < (n); ++i)
#define INF 9999999
#define lint long long int
#define in(a) cin>>a
#define out(a) cout<<a<<endl
int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> a(m), b(m), c(m);
	loop(i, m)
	{
		cin >> a[i] >> b[i] >> c[i];
		a[i]--; b[i]--;
	}
	vector<vector<int>> dist(n, vector<int>(n));
	loop(i, n)
	{
		loop(j, n)
		{
			dist[i][j] = INF;
		}
		dist[i][i] = 0;
	}
	loop(i, m)
	{
		dist[a[i]][b[i]] = dist[b[i]][a[i]] = min(dist[a[i]][b[i]], c[i]);
	}

	loop(i, n)//mid
	{
		loop(j, n)//start
		{
			loop(k, n)//goal
			{
				dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
			}
		}
	}
	int ans = 0;
	loop(i, m)
	{
		if (dist[a[i]][b[i]] < c[i])ans++;
	}

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

Measured memory_bytes: 256
use std::collections::BinaryHeap;
use std::cmp::Ordering;

#[derive(Debug, Default, PartialEq, PartialOrd)]
struct F(f64);
impl Eq for F {
}
impl Ord for F {
    fn cmp(&self, other: &Self) -> Ordering {
        self.partial_cmp(other).unwrap()
    }
}
#[allow(dead_code)]
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)*}
    };
}

#[allow(dead_code)]
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)*}
    };

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

#[allow(dead_code)]
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")
    };
}

fn main() {
    input!{
        n: usize,
        m: usize,
        aa: [f64; n]
    }

    let mut bh = BinaryHeap::with_capacity(n);
    for a in aa.into_iter() {
        bh.push(F(a));
    }

    // TODO logic
    for _k in 0..m {
        // insertion sort
        let F(a) = bh.pop().unwrap();
        let a = a / 2f64;

        bh.push(F(a));
    }

    // TODO to integer
    let sum = bh.iter().fold(0, |sum, &F(a)| sum + (a as usize));

    println!("{}", sum);
}


Measured memory_bytes: 6396
#include <iostream>
#include <numeric>

using namespace std;

int main() {
    int a[8];
    for (int i=0; i<8; ++i) cin >> a[i];
    cout << max(accumulate(a, a+4, 0), accumulate(a+4, a+8, 0)) << endl;
    return 0;
}

Measured memory_bytes: 1160
def is_inside(l: int, c: int, r: int) -> bool:
    return (0 <= c - r) & (c + r <= l)


if __name__ == "__main__":
    w, h, a, b, r = map(lambda x: int(x), input().split())
    if (is_inside(w, a, r) & is_inside(h, b, r)):
        print("Yes")
    else:
        print("No")



Measured memory_bytes: 5600
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
def f(v,i,ans):
    if i == 0:return
    if str(v)[-1] != "0":
        x = int(str(v)+str(int(str(v)[-1])-1))
        ans.add(x)
        f(x,i-1,ans)
    y = int(str(v)+str(v)[-1])
    ans.add(y)
    f(y,i-1,ans)
    if str(v)[-1] != "9":
        z = int(str(v)+str(int(str(v)[-1])+1))
        ans.add(z)
        f(z,i-1,ans)
def main():
    K = int(input())
    ans = set()
    for i in range(1,10):
        ans.add(i)
        f(i,10,ans)
    ans = list(ans)
    ans.sort()
    print(ans[K-1])
if __name__ == "__main__":
    main()

Measured memory_bytes: 90968
#include <cassert>
#include "limits.h"
#include <limits>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<long long,long long>;



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

  ll n,m;
  std::cin>>n>>m;

  std::vector<std::vector<ll>> graph(n);

  rep(i,0,m){
    ll a,b;
    std::cin>>a>>b;
    a--;b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  std::vector<std::vector<ll>> color(n,std::vector<ll>(11,MOD));

  struct Query{
    ll v,d,col;
    Query(ll a,ll b,ll c):v(a),d(b),col(c){}
  };

  std::vector<Query> query;

  ll q;
  std::cin>>q;

  rep(i,0,q){
    ll v,d,c;
    std::cin>>v>>d>>c;
    v--;
    query.emplace_back(Query(v,d,c));
  }

  std::reverse(all(query));

  rep(i,0,q){
    chmin(color[query[i].v][query[i].d],i);
  }

  for(ll i=10;i>0;i--){
    rep(j,0,n){
      for(ll e:graph[j]){
        chmin(color[e][i-1],color[j][i]);
      }
      chmin(color[j][i-1],color[j][i]);
    }
  }

  rep(i,0,n){
    if(color[i][0]!=MOD)std::cout<<query[color[i][0]].col<<"\n";
    else std::cout<<0<<"\n";
  }

  return 0;
}

Measured memory_bytes: 23408
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define RA(x) begin(x), end(x)
#define FE(i, x) for (auto i = begin(x); i != end(x); ++i)
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef vector<ll> VI;
typedef pair<ll,ll> PII;

void initialize(int* id,int MAX){
    for(int i = 0;i < MAX;++i)
        id[i] = i;
}

int root(int x,int* id){
    while(id[x] != x){
        id[x] = id[id[x]];
        x = id[x];
    }
    return x;
}

void union1(int x, int y,int* id){
    int p = root(x,id);
    int q = root(y,id);
    id[p] = id[q];
}

int main(){
    ios_base::sync_with_stdio(0);
    int n;
    cin>>n;
    pair<int,int> x[n],y[n];
    rep(i,0,n){
        cin>>x[i].F>>y[i].F;
        x[i].S=y[i].S=i;
    }
    sort(x,x+n);
    sort(y,y+n);
    pair<int,pair<int,int> > edges[2*n-2];
    rep(i,0,n-1){
        edges[i] = mp(x[i+1].F-x[i].F,mp(x[i].S,x[i+1].S));
        edges[n-1+i] = mp(y[i+1].F-y[i].F,mp(y[i].S,y[i+1].S));
    }
    sort(edges,edges+(2*n-2));
    ll ans=0;
    int *id;
    id = new int[n];
    initialize(id,n);
    rep(i,0,2*n-2){
        if(root(edges[i].S.F,id)!=root(edges[i].S.S,id)){
            ans+=edges[i].F;
            union1(edges[i].S.F,edges[i].S.S,id);
        }
    }
    cout<<ans<<endl;
}

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

constexpr int mod = 1e9 + 7;

int main() {
    string k; cin >> k;
    int d; cin >> d;
    const int n = k.size();

    vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(d, vector<int>(2)));
    dp[0][0][0] = 1;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < d; ++j) {
            for(int lt = 0; lt < 2; ++lt) {
                for(int nxt = 0; nxt <= (lt == 0 ? (k[i] - '0') : 9); ++nxt) {
                    const int nlt = lt | (nxt < (k[i] - '0'));
                    (dp[i + 1][(j + nxt) % d][nlt] += dp[i][j][lt]) %= mod;
                }
            }
        }
    }

    int ans = (dp[n][0][0] + dp[n][0][1]) % mod;
    (ans += mod - 1) %= mod;
    cout << ans << endl;
}


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

int main(){
    int N, D;
    cin >> N >> D;
    vector<vector<int>> X(N, vector<int>(D));
    for (int i=0; i<N; i++) {
        for (int j=0; j<D; j++) {
            cin >> X.at(i).at(j);
        }
    }
    int count = 0;
    for (int i=0; i<N-1; i++) {
        for (int j=i+1; j<N; j++) {
            int dist = 0;
            for (int k=0; k<D; k++) {
                dist += (X.at(i).at(k) - X.at(j).at(k))*(X.at(i).at(k) - X.at(j).at(k));
            }
            for (int m=1; m<=dist; m++) {
                if (dist/m == m && dist%m == 0) count++;
            }
        }
    }
    cout << count << endl;
}

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

#define rep(i,N) repf(i,0,N)
#define reps(i,N) repfs(i,0,N)
#define repf(i,a,b) for(int i=a;i<b;i++)
#define repfs(i,a,b) for(int i=a+1;i<=b;i++)
#define repr(i,N) for(int i=N-1;i>=0;i--)
#define reprs(i,N) for(int i=N;i>0;i--)

#define d(a) if(isDebugMode) cout<<#a<<"="<<a<<","
#define d2(a,b) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b
#define d3(a,b,c) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c
#define d4(a,b,c,d) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<","<<#d<<"="<<d
#define da(arr,N){if(isDebugMode){rep(i,N){if(arr[i]==INF)printf("INF ");else cout<<arr[i]<<" ";} cout<<endl;}}
#define da2(arr,N,M){if(isDebugMode)rep(i,N){rep(j,M){if(arr[i][j]==INF)printf(" INF");else printf(" %3d",arr[i][j]);}cout<<endl;}}
#define pb push_back
#define pob pop_back

auto chmax = [](int &a, int b) { a = max(a, b); };
auto chmin = [](int &a, int b) { a = min(a, b); };

typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;
const int MOD = 1000000007;
const int dx[4] = { 0, 1, 0,-1 };
const int dy[4] = { 1, 0,-1, 0 };

bool isDebugMode = 1;
//--------------------------------------//
ll n;
ll x;

void swap(ll &a, ll &b) {
	ll tmp = a;
	a = b;
	b = tmp;
}

ll f(ll a, ll b) {
	if (a == 0 || b == 0) return 0;
	if (a == b)
		return a;
	if (a > b)
		swap(a, b);
	if (b%a == 0)
		return (b / a * 2 - 1) * a;
	return 2 * a *(b / a) + f(b - a * (b / a), a);
}

void solve() {
	cout << n + f(n - x, x) << endl;
}

int main() {
	cin >> n >> x;
	solve();
	return 0;
}


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

typedef long long s64;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

template <class T>
inline void relax(T &a, const T &b)
{
	if (b > a)
		a = b;
}
template <class T>
inline void tense(T &a, const T &b)
{
	if (b < a)
		a = b;
}

const int MaxN = 100000;
const int INF = 1000000000;

int n;

struct edge
{
	int v, w;
	edge() {}
	edge(const int &_v, const int &_w)
		: v(_v), w(_w) {}
};
vector<edge> adj[MaxN + 1];

int size[MaxN + 1];

int nC = 0;
int vC[2];

int dfs1(int u, int fa)
{
	int vW = size[u] = 1;
	for (edge e : adj[u])
		if (e.v != fa)
		{
			int k = dfs1(e.v, u);
			size[u] += k;
			relax(vW, k);
		}
	relax(vW, n - size[u]);

	if (vW <= n / 2)
		vC[nC++] = u;

	return size[u];
}

s64 dep[MaxN + 1];

void dfs2(int u, int fa)
{
	for (edge e : adj[u])
		if (e.v != fa)
		{
			dep[e.v] = dep[u] + e.w;
			dfs2(e.v, u);
		}
}

int main()
{
	cin >> n;
	for (int i = 1; i < n; ++i)
	{
		int u = getint(), v = getint(), w = getint();
		adj[u].emplace_back(v, w);
		adj[v].emplace_back(u, w);
	}

	dfs1(1, 0);
	dfs2(vC[0], 0);

	s64 res = 0;
	for (int u = 1; u <= n; ++u)
		res += dep[u] << 1;

	int w1 = -1, w2 = INF;
	for (edge e : adj[vC[0]])
	{
		tense(w2, e.w);
		if (e.v == vC[1])
			w1 = e.w;
	}

	res -= ~w1 ? w1 : w2;

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 12288
#include "bits/stdc++.h"
using namespace std;
int dp[3001][3001];
int main()
{
	string s, t, ans = "\n";
	cin >> s >> t;	
	int m = s.length(), n = t.length();
	for(int i = 1; i <= m; ++i)
	{
		for(int j = 1; j <= n; ++j)
		{
			if(s[i - 1] == t[j - 1])
			{
				dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
			}
			dp[i][j] = max(dp[i][j], max(dp[i - 1][j], dp[i][j - 1]));
		}
	}
	for(int x = m, y = n; x && y; )
	{
		if(dp[x][y] == dp[x - 1][y])
		{
			--x;
		}
		else if(dp[x][y] == dp[x][y - 1])
		{
			--y;
		}
		else
		{
			ans = s[x - 1] + ans;
			--x;
			--y;
		}
	}
	cout << ans;
}


Measured memory_bytes: 35456
#!/usr/bin/python3

from fractions import Fraction
import heapq
import math
import sys


DEBUG = False


def inp():
    return sys.stdin.readline().rstrip()


def dprint(*value, sep=' ', end='\n'):
    if DEBUG:
        print(*value, sep=sep, end=end)


def solve(N, M, A):
    hq = [-a for a in A]
    heapq.heapify(hq)
    for _ in range(M):
        v = -hq[0]
        if v < 1:
            break
        v = Fraction(v, 2)
        heapq.heapreplace(hq, -v)

    return sum([math.floor(-v) for v in hq])


def main():
    N, M = [int(e) for e in input().split()]
    A = [int(e) for e in input().split()]
    print(solve(N, M, A))


if __name__ == '__main__':
    main()


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

#define ms(s, n) memset(s, n, sizeof(s))
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORd(i, a, b) for (int i = (a) ; i >= (b); i--)
#define FORall(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define sz(a) int((a).size())
#define present(t, x) (t.find(x) != t.end())
#define all(a) (a).begin(), (a).end()
#define uni(a) (a).erase(unique(all(a)), (a).end())
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define sp system("pause")
#define prec(n) fixed<<setprecision(n)
#define bit(n, i) (((n) >> (i)) & 1)
#define bitcount(n) __builtin_popcountll(n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;
const int MOD = (int) 1e9 + 7;
const int INF = (int) 1e9;
const ll LINF = (ll) 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-9;
const int N = (int) 1e5 + 10;
void TimeExecution() {
    cout << "\n\n===>> Time Execution: " << clock() / (double)1000 << " sec(s).";
}
int t;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    /*
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    */
    ll x;
    cin >> x;
    cout << 1000 * (x / 500) + 5 * ((x % 500) / 5);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

void look_for(int,int,int,int);

char map[20][20];
int cnt;

int main(){
  int i,j,w,h;
  while(1){
    cnt=0;
    scanf("%d %d",&w,&h);
    if(w==0 && h==0)break;
    for(i=0;i<h;i++){
      scanf("%s",map[i]);
    }
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(map[i][j]=='@')
	  look_for(i,j,h,w);
      }
    }
    printf("%d\n",cnt);
  }
  return 0;
}

void look_for(int h,int w,int height,int width){
  int i,j;
    cnt++;
    map[h][w]='N';
  for(i=-1;i<=1;i++){
    for(j=-1;j<=1;j++){
      if(i==j || i==-j || i+h<0 || j+w<0 ||i+h>=height || j+w>=width || (i==0 && j==0))continue;
      if(map[i+h][w+j]=='.')look_for(i+h,j+w,height,width);
    }
  }
}

Measured memory_bytes: 1720
#include <bits/stdc++.h>
#define ALL(A) (A).begin(), (A).end()
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };  // i<4:4way i<8:8way
int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

const ll mod = 1e9 + 7;
const ll INF = -1 * ((1LL << 63) + 1);
const int inf = -1 * ((1 << 31) + 1);

int d[200005];

ll modpow(ll a, ll n, ll mod) {
    if (mod <= 0) return 0;
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int solve(int n) {
    if (n == 0) return 0;
    return solve(n % __builtin_popcount(n)) + 1;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int p = 0;
    rep(i,n)if(s[i]=='1')p++;

    int a1 = 0; 
    int a2 = 0;

    for(int i=0;i<n;i++){
        if(s[i] == '1'){
            if(p==1){
                a1 = 0;
            }else{
                a1 = (a1 + modpow(2,n-1-i,p-1)) % (p-1);
            }
            a2 = (a2 + modpow(2,n-1-i,p+1)) % (p+1);
        }
    }

    for(int i=0;i<n;i++){
        ll now;
        if(s[i] == '1'){
            if(p==1){
                cout << 0 << endl;
                continue;
            }
            now = a1 - modpow(2,n-1-i,p-1) + (p-1)*1e5;
            now %= p-1;
            cout << 1 + solve(now) << endl;
        }else{
            now = a2;
            now += modpow(2,n-1-i,p+1);
            now %= p+1;
            cout << 1 + solve(now) << endl;
        }
    }
}

Measured memory_bytes: 3752
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s;
   cin >> s;
   int len=s.size();
   int ans=999;
   for(int i=0;i<=len-3;i++){
     int num=(s[i]-'0')*100+(s[i+1]-'0')*10+(s[i+2]-'0');
     ans=min(ans,abs(753-num));
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    d,x=map(int,input().split())
    A=[int(input()) for _ in range(n)]
    ans=x
    for a in A:
        ans+=(d-1)//a+1
    print(ans)
resolve()

Measured memory_bytes: 38256