akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


int main() {
    string s, t;
    li a, b;
    cin >> s >> t;
    cin >> a >> b;
    string u;
    cin >> u;
    if (u == s) {
        a--;
    } else {
        b--;
    }
    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int a[10];
    int i;
    for(i=0;i<10;i++){
        cin>>a[i];
    }
    for(i=0;i<10;i++){
        for(int j=0;j<9;j++){
            if(a[j]<a[j+1]){
                int tmp;
                tmp=a[j];
                a[j]=a[j+1];
                a[j+1]=tmp;
            }
        }
    }
    for(i=0;i<3;i++){
        cout<<a[i]<<endl;
    }
    return 0;



}


Measured memory_bytes: 3080
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int a,b;
  int s = 0;
  while(cin>>a>>b,a+b) {
    int f = 0;
    if (s)
      cout << endl;
    else
      s++;
    for(int i=a;i<=b;i++) {
      if (i%4==0&&i%100!=0 || i%400==0) {
        cout << i << endl;
        f++;
      }
    }
    if (f==0) cout << "NA" << endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(){
    int n, m;
    cin >> n >> m;
    int l = 0;
    int r = 1e8;
    rep(i, m) {
        int tmp_l, tmp_r;
        cin >> tmp_l >> tmp_r;

        if ( l < tmp_l ) {
            l = tmp_l;
        }
        if ( tmp_r < r ) {
            r = tmp_r;
        }
    }
    if ( r < l ) {
        cout << 0 << endl;
    }
    else {
        cout << r - l + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from collections import deque


def read_input():
    n, q = map(int, input().split())
    
    # 辺を整理
    edges = {i: [] for i in range(n)}
    for _ in range(n - 1):
        a, b = map(int, input().split())
        edges[a - 1].append(b - 1)
        edges[b - 1].append(a - 1)
    # カウントを整理
    counter = {i: 0 for i in range(n)}
    for _ in range(q):
        p, x = map(int, input().split())
        counter[p - 1] += x
    
    return n, edges, counter


def submit():
    n, edges, counter = read_input()

    # 深さ優先探索で各頂点のカウントを調べる
    v_count = {i: -1 for i in range(n)}
    q = deque()
    q.append((0, 0))
    while len(q):
        v, p = q.pop()
        v_count[v] = p + counter[v]
        for e in edges[v]:
            if v_count[e] < 0:
                q.append((e, v_count[v]))

    res = []
    for i in range(n):       
        res.append(v_count[i])
    print(" ".join(map(str, res)))


submit()

Measured memory_bytes: 126040
#include<iostream>
#include<vector>
using namespace std;
int a[1000001];
int b[1000001];
int n,m;

int main(){
  a[1]=1;
  for(int i=2;i<=1000000;i++){
    if(i%2==0){
      a[i]=a[i/2];
    }else if(i%3==0){
      a[i]=a[i/3];
    }else if(i%5==0){
      a[i]=a[i/5];
    }
  }

  for(int i=1;i<=1000000;i++)b[i]=a[i]+b[i-1];
  
  while(1){
    cin>>n;
    if(n==0)break;
    cin>>m;
    cout<<b[m]-b[n-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 8972
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/
/*
int dfs(int foo, int timer)
{
    //foo is node number
    if (finds[foo].first != -1)
        return timer;
    finds[foo].first = ++timer;
    int result = timer;
    if (data[foo].size() != 0)
    {
        rep(i, data[foo].size())
        {
            result = dfs(data[foo][i], result);
        }
    }
    finds[foo].second = ++result;
    return result;
}
*/
int main(){
    int left=0, right,top ,bot=0,w,h,n;
    cin>>w>>h>>n;
    right=w;
    top=h;
    rep(i,n){
        int a,b,c;
        cin>>a>>b>>c;
        if(c==1){
            left=max(left,min(a,right));
        }else if(c==2){
            right= min(right,max(a,left));
        }else if(c==3){
            bot= max(bot,min(b,top));
        }else if(c==4){
            top=min(top,max(b,bot));
        }
        //cout<<left<<" "<<right<<" "<<top<<" "<<bot<<endl;
    }
    int ans= (right-left)*(top-bot);
    if(ans<0) cout<<0<<endl;
    else cout<<ans<<endl;
    return 0;
}


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

int h,w,oldcnt = 0;
char field[1000][1000],mon[2][2],joi[] = {'J','O','I'};

bool isMon(int x,int y){
  bool ret = true;
  if(x < 0 || x >= h - 1 || y < 0 || y >= w - 1) return false;
  for(int i = 0;i < 2;i++){
    for(int j = 0;j < 2;j++){
      if(field[x + i][y + j] != mon[i][j]) ret = false;
    }
  }
  return ret;
}

int main(){
  cin >> h >> w;
  getchar();
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      field[i][j] = getchar();
    }
    getchar();
  }
  for(int i = 0;i < 2;i++){
    for(int j = 0;j < 2;j++){
      mon[i][j] = getchar();
    }
    getchar();
  }
  for(int i = 0;i < h - 1;i++){
    for(int j = 0;j < w - 1;j++){
      if(isMon(i,j)) oldcnt++;
    }
  }
  int maxcnt = 0;
  for(int i = 0;i < h;i++){
    for(int j = 0;j < w;j++){
      for(int k = 0;k < 3;k++){
	if(field[i][j] == joi[k]) continue;
	int cnt = 0;
	char t = field[i][j];
	field[i][j] = joi[k];
        for(int k = -1;k < 1;k++){
	  for(int l = -1;l < 1;l++){
	    if(isMon(i + k,j + l)) cnt++;
	  }
	}
	maxcnt = max(maxcnt,cnt);
	field[i][j] = t;
      }
    }
  }
  cout << oldcnt + maxcnt << endl;
  return 0;
}

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

def get_syokin(a):
    if a == 3:
        return 100000
    elif a == 2:
        return 200000
    elif a == 1:
        return 300000
    return 0

def solve():
    X, Y = map(int, input().split())
    ans = 0

    ans += get_syokin(X)
    ans += get_syokin(Y)

    if X==1 and Y==1:
        ans += 400000

    print(ans)


if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
const int INF = 9999999;
const int max_e=15;
const int max_v=15;
int d[max_v][max_v];
int V,E;
int read()
{
    int n;
    scanf("%d",&n);
    if(n==0) return 0;
    V=0;
    for(int i=0;i<max_v;i++)
        for(int j=0;j<max_v;j++)
        {
            if(i==j) d[i][j]=0;
            else d[i][j]=INF;
        }
    while(n--)
    {
        int a,b,c;
        scanf("%d%d%d",&a,&b,&c);
        a+=1,b+=1;
        V=max(V,max(a,b));
        d[a-1][b-1]=d[b-1][a-1]=c;
    }
    return 1;

}
void floyd_warshall()
{
    for(int k=0;k<V;k++)
        for(int i=0;i<V;i++)
            for(int j=0;j<V;j++)
            {
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
}

int main()
{
    while(read())
    {
        floyd_warshall();
        int cnt=INF,id;
        for(int i=0;i<V;i++)
        {
            int sum=0;
            for(int j=0;j<V;j++)
            {
                sum+=d[i][j];
            }
            if(cnt>sum)
            {
                cnt=sum,id=i;
            }
        }
        printf("%d %d\n",id,cnt);
    }
    return 0;
}

Measured memory_bytes: 2692
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	num, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return num
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func solve(isUse []bool, n, m, x int, c []int, skill [][]int) int {
	if len(isUse) == n {
		score := make([]int, m)
		price := 0
		for i := 0; i < n; i++ {
			if isUse[i] {
				price += c[i]
				for j := 0; j < m; j++ {
					score[j] += skill[i][j]
				}
			}
		}
		for i := 0; i < m; i++ {
			if score[i] < x {
				return -1
			}
		}
		return price
	}

	isUse = append(isUse, true)
	temp1 := solve(isUse, n, m, x, c, skill)
	isUse[len(isUse)-1] = false
	temp2 := solve(isUse, n, m, x, c, skill)
	if temp1 == -1 && temp2 == -1 {
		return -1
	}
	if temp1 == -1 {
		return temp2
	}
	if temp2 == -1 {
		return temp1
	}
	if temp1 > temp2 {
		return temp2
	} else {
		return temp1
	}

}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	m := nextInt()
	x := nextInt()

	c := make([]int, n)
	skill := make([][]int, n)
	for i := 0; i < n; i++ {
		c[i] = nextInt()
		skill[i] = make([]int, m)
		for j := 0; j < m; j++ {
			skill[i][j] = nextInt()
		}
	}

	isUse := make([]bool, 0, n)

	ans := solve(isUse, n, m, x, c, skill)

	fmt.Println(ans)
}


Measured memory_bytes: 2164
import java.util.*;
import java.io.*;
public class Main {

	public static void main(String[] args) throws Exception{
		int num = 998244353;

		// TODO Auto-generated method stub
 		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
 		PrintWriter out = new PrintWriter(System.out);
//	 		String input1 = bf.readLine().trim();
//	 		String input2 = bf.readLine().trim();
	 		StringTokenizer st = new StringTokenizer(bf.readLine());
	 		int n = Integer.parseInt(st.nextToken());
	 		int m = Integer.parseInt(st.nextToken());
 		
 		out.println(100*Math.max(0, 10-n) + m);
 		out.println();
	 		
 		out.close();
 		
 		
 		
 	}
}
 	
 
//StringJoiner sj = new StringJoiner(" "); 
//sj.add(strings)
//sj.toString() gives string of those stuff w spaces or whatever that sequence is

 		
 		
 		
 		
	




Measured memory_bytes: 25456
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: u64 = sc.read();
    let m: usize = sc.read();
    let mut min: u64 = 1;
    let mut max: u64 = n;
    for _ in 0..m {
        min = cmp::max(min, sc.read());
        max = cmp::min(max, sc.read());
    }
    if min > max {
        println!("0");
    } else {
        println!("{}", max - min + 1);
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main(){
	char left,right;
	int array[3];
	array[0] = 1,array[1] = 0,array[2] = 0;

	while(scanf("%c,%c",&left,&right)!=EOF){
		if((left == 'A' && right == 'B') || (left == 'B'&&right == 'A')){
			swap(array[0],array[1]);
		}else if((left == 'A' && right == 'C') || (left == 'C' && right == 'A')){
			swap(array[0],array[2]);
		}else{
			swap(array[1],array[2]);
		}
	}

	for(int i=0;i<3;i++){
		if(array[i] == 1){
			switch(i){
			case 0:
				printf("A\n");
				break;
			case 1:
				printf("B\n");
				break;
			case 2:
				printf("C\n");
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2560
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int n , m , col[N] , cnt[2];
vi g[N];

int main(){
    scanf("%d%d",&n,&m);
    rep(i,0,m){
        int u,v;
        scanf("%d%d",&u,&v);
        --u;--v;
        g[u].pb(v);
        g[v].pb(u);
    }
    rep(i,0,n) col[i]=-1;
    vi q;q.pb(0);col[0]=0;
    bool oddcir = false;
    rep(i,0,sz(q)){
        int c=q[i];
        cnt[col[c]]++;
        for(auto t:g[c]) {
            if(col[t]==-1) col[t]=col[c]^1,q.pb(t);
            else if(col[c]==col[t]) {
                oddcir = true;
            }
        }
    }
    if(oddcir) cout << 1ll * n * (n - 1) / 2 - m << endl;
    else cout << 1ll * cnt[0] * cnt[1] - m << endl;
    return 0;
}


Measured memory_bytes: 6784
#include <string>
#include <iostream>

using namespace std;

int main (){
    
    string str;
    cin >> str;
    
    for (int i =0 ; i < str.size()-1; i ++) {
        if (str[i] == str[i+1]) {
            cout << i+1<< " " <<i+2<<endl;
            return 0;
        }
    }
    for (int i =0 ; i < str.size()-2; i ++) {
        if (str[i] == str[i+2]) {
            cout << i+1<< " " <<i+3<<endl;
            return 0;
        }
    }
    
    cout<<"-1 -1"<<endl;
    return 0;
}

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

using namespace std;

int main(void){
	while(1){
		int n, q;
		int date[100] = {};
		cin >> n >> q;
		if(n == 0 and q == 0){
			break;
		}

		for(int i = 0; i < n; i++){
			int num;
			cin >> num;
			for(int j = 0; j < num; j++){
				int d;
				cin >> d;
				date[d - 1] += 1;
			}
		}
		int min = q - 1;
		int decide = 0;
		for(int i = 0; i < 100; i++){
			if(date[i] > min){
				min = date[i];
				decide = i + 1;
			}
		}
		cout << decide << endl;
	}
	return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n, x, y; cin >> n >> x >> y;
  x--; y--;

  map<int, int> mp;
  for(int i=0;i<n;++i) {
    for(int j=i+1;j<n;++j) {
      if(i <= x && y <= j) {
        //cout << i << " " << j << " " << j-i-diff << endl;
        mp[(j-y) + 1 + (x - i)]++;
      } else if(i <= x && x <= j) {
        int d = min(j-i, (x-i) + 1 + (y-j));
        mp[d]++;
      } else if(i <= y && y <= j) {
        int d = min(j-i, (i-x) + 1 + (j-y));
        mp[d]++;
      } else if(x <= i && j <= y) {
        //cout << i << " " << j << " " << j-i << endl;
        int d = min(j-i, (y - j) + 1 + (i - x));
        mp[d]++;
      } else {
        mp[j-i]++;
      }
    }
  }

  for(int i=1;i<n;++i) {
    cout << mp[i] << endl;
  }

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;
int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int num[5];
    rep(i, 5) { cin >> num[i]; }
    int rest = 10, min = 0;
    for (int i = 0; i < 5; i++) {
        if (num[i] % 10 < rest && num[i] % 10 != 0) {
            rest = num[i] % 10;
            min = i;
        }
    }
    int ans = 0;
    rep(i, 5) {
        if (i == min) {
            ans += num[min];
        } else if (num[i] % 10 != 0) {
            ans += (num[i] / 10 + 1) * 10;
        } else {
            ans += num[i];
        }
    }
    cout << ans << endl;
    return 0;
}

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

int solve(){
  long long n, a, b;  cin >> n >> a >> b;
  long long remain = max(0ll, n - n/(a+b)*(a+b));
  long long ans = n/(a+b)*a +  (remain>=a ? a : remain);

  cout << ans << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  long int count=0;
  for(int i=1;i<=n;i++){
    if(i%3!=0&&i%5!=0){
      count+=i;
    }
  }
  cout<<count<<endl;

}

Measured memory_bytes: 3644
n=int(input())
x,y=zip(*sorted(sorted(map(int,input().split())) for _ in range(n)))
a=x[-1]
b=d=2*10**9
for i in range(n-1):
    a=max(a,y[i])
    b=min(b,y[i])
    d=min(d,a-min(b,x[i+1]))
print(min((x[-1]-x[0])*(max(y)-min(y)),(max(y)-x[0])*d))

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

int main() {
  int N, K;
  cin >> N >> K;
  
  int sum = 1;
  for (int i = 0; i < N; i++) {
    if ( (sum * 2) <= (sum + K) ) {
      sum *= 2;
    }
    else {
      sum += K;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e9
typedef long long ll;
typedef pair<ll,ll> P;
ll h,w;
ll cost[10][10];
ll dist[210][210];


void dijkstra(ll start){
    priority_queue<P,vector<P>,greater<P>>que;
    dist[start][start]=0;
    que.push(P(start,dist[start][start]));
    while(!que.empty()){
        P p=que.top();
        que.pop();
        ll now=p.first;
        ll d=p.second;
        for(ll i=0;i<10;i++){
            if(now==i)continue;
            if(dist[start][i]>d+cost[now][i]){
                dist[start][i]=d+cost[now][i];
                que.push(P(i,dist[start][i]));
            }
        }
    }
}

int main(void){
    ll a,ans=0;
    for(int i=0;i<210;i++){
        for(int j=0;j<210;j++){
            dist[i][j]=(ll)INF;
        }
    }
    cin>>h>>w;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin>>cost[i][j];
        }
    }
    for(int i=0;i<10;i++)dijkstra(i);
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>a;
            if(a==-1)continue;
            //cout<<dist[a][1]<<endl;
            ans+=dist[a][1];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
 int k,n;
  cin>>k>>n;
  int a[n];
  for(int i = 0; i<n;i++)
  {
   cin>>a[i]; 
  }
  int maxm = 0;
  for(int i = 1; i<n;i++)
  {
    maxm = max(maxm,abs(a[i]-a[i-1]));
  }
  maxm = max(maxm,abs(k-a[n-1]+a[0]));
             cout<<k-maxm<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
const int MOD = 1e9+7;
const int MOOD = 998244353;
typedef long long ll;
#define PI 3.14159265359
using namespace std;


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

	for (int i = 0; i < n-k; i++){
		if (a[i] < a[i+k]) cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	return 0;
}

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

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

    int n;
    long long w, w_arr[100], v_arr[100], dp[100001]; // (W+1)
    memset(dp, 0, sizeof(dp));
    cin >> n >> w;
    for (int i = 0; i < n; i++) {
        cin >> w_arr[i] >> v_arr[i];
    }
    for (int i = 0; i < n; i++) {
        for (long long j = w; j >= w_arr[i]; j--) {
            dp[j] = max(dp[j], v_arr[i] + dp[j-w_arr[i]]);
        }
    }
    cout << dp[w];

    return 0;
}

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

int main()
{
    int n,ans=0;

    cin>>n;

    int blocks[n];
    for(int i;i<n;i++)
    {
        cin>>blocks[i];
    }

    int target=1;

    for(int i=0;i<n;i++)
    {
        if(blocks[i]==target)
        {
            target++;
        }
        else
        {
            ans++;
        }
    }

    if(ans!=n) cout<<ans;
    else cout<<"-1";
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>

using namespace std;

int cost[6] = {100, 101, 102, 103, 104, 105};

int X;

int memo[100005];
bool isPossible(int remCost)
{
    if (remCost == 0) return true;
    if (remCost < 0) return false;
    if (memo[remCost] != -1) return memo[remCost] == 0 ? false : true;
    bool ans = false;
    for (int i = 0; i < 6; i++)
    {
        ans = ans || isPossible(remCost - cost[i]);
    }
    memo[remCost] = ans ? 1 : 0;
    return ans;
}

int main()
{
    scanf("%d", &X);
    memset(memo, -1, sizeof(memo));
    printf(isPossible(X) ? "1\n" : "0\n");
    return 0;
}


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

#define INF 10000000
#define MAX_V 1000

int V,E;
struct edge{int from,to,cost;};
vector<edge> edges;
int d[MAX_V];
int main(){
  int f,t,c;
  int s;
  scanf("%d %d %d",&V,&E,&s);
  for(int i=0;i<E;i++){
    scanf("%d %d %d",&f,&t,&c);
    edge es;
    es.from=f;es.to=t;es.cost=c;
    edges.push_back(es);
  }
  fill(d,d+V,INF);
  d[s]=0;
  for(int i=0;i<V;i++){
   
    for(int j=0;j<E;j++){
      edge e=edges[j];
      if(d[e.from]!=INF && d[e.to] > d[e.from]+e.cost){
	d[e.to]=d[e.from]+e.cost;
	if(i==V-1){
	  printf("NEGATIVE CYCLE\n");
	  return 0;
	}
      }
    }
  }
  for(int x=0;x<V;x++){
    if(d[x]!=INF) printf("%d\n",d[x]);
    else printf("INF\n");
  }
  return 0;
}

Measured memory_bytes: 2792
#include <iostream>
#include <string>
#include <stack>

using namespace std;

int main() {
  while (true) {
    string s;
    getline(cin, s);
    if (s == ".") { break; }

    bool is_valid = true;

    stack<char> st;

    for (int i = 0; i < s.length(); i++) {
      if (s[i] == '(') { st.push(s[i]); }
      if (s[i] == ')') {
        if ( st.empty() || st.top() != '(') {
          is_valid = false;
          break;
        }
        st.pop();
      }
      if (s[i] == '[') { st.push(s[i]); }
      if (s[i] == ']') {
        if (st.empty() || st.top() != '[') {
          is_valid = false;
          break;
        }
        st.pop();
      }
    }
    if (!st.empty()) { is_valid = false; }
    cout << ( is_valid ? "yes" : "no") << endl;
  }

  return 0;
}


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

using namespace std;

template <typename T> T gcd(T x, T y) {
  if (y == 0)
    return x;
  return gcd(y, x % y);
}

template <typename T> T lcm(T x, T y) {
  if (x == 0 || y == 0)
    return 0;
  return x / gcd(x, y) * y;
}

int main() {
  int N, A;
  cin >> N >> A;
  cout << N * N - A << endl;
}

Measured memory_bytes: 256
N = int(input())
h = list(map(int, input().split()))

a = [0]*N
answer = 0
while(True):
    area_flag = False
    area = 0
    comp_cnt = 0
    # print(a)
    for i in range(N):
        if a[i]>=h[i] and h[i]==0:
            comp_cnt+=1
            if area_flag:
                area += 1
            area_flag = False
            continue
        elif a[i]>=h[i]:
            comp_cnt+=1
            if area_flag:
                area += 1
            area_flag = False
            continue
        area_flag = True
        a[i]+= 1
    if area_flag and comp_cnt!=0:
        area += 1
    answer += area
    # print(area)
    if comp_cnt == N: 
        answer += min(h)
        break


print(answer)
        


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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string s; cin >> s;
    vi c(26); REP(i, (int)s.length()) c[s[i]-'a']++;
    REP(i, (int)c.size())
    {
        if(c[i] >= 2)
        {
            no;
            return 0;
        }
    }
    yes;
}

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

int main(void){
    int N,M,flag=0;
    cin >> N >> M;
    vector<int> digid(N,10);
    for(int i=0;i<M;i++){
        int s,c;
        cin >> s >>c;
        if(s==1&&c==0) {
            digid.at(0)=0;
            flag++;
            break;
        }
        if(digid.at(s-1)==10||digid.at(s-1)==c){
        digid.at(s-1)=c;
        }else{
            flag++;
            break;
        }
    }
    
    if(N==1&&(digid.at(0)==0||digid.at(0)==10)){
        cout << 0;
    }else if(flag){
        cout << -1;
    }else{
        if(digid.at(0)==10) cout << 1;
        else cout << digid.at(0);
        for(int i=1;i<N;i++){
            if(digid.at(i)==10) cout << 0;
            else cout << digid.at(i);
        }
    }
}

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

int main(void){
  char str[128];
  int state=0;
  
  cin >> str;
  for (char *p=str; *p; p++){
    if (state==0 && *p=='C') state++;
    else if (state==1 && *p=='F') state++;
  }
  cout << (state==2?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 384
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let m: usize = sc.cin();
    let mut g = vec![vec![]; n];
    for _ in 0..m {
        let a = sc.cin::<usize>() - 1;
        let b = sc.cin::<usize>() - 1;
        g[a].push(b);
        g[b].push(a);
    }
    let mut prev = vec![None; n];
    let mut stack = std::collections::VecDeque::new();
    stack.push_back(0);
    while let Some(u) = stack.pop_front() {
        for &v in g[u].iter() {
            if prev[v] == None {
                prev[v] = Some(u);
                stack.push_back(v);
            }
        }
    }
    put!("Yes");
    for &p in prev[1..].iter() {
        put!(p.unwrap() + 1);
    }
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 12632
n, c = gets.split.map(&:to_i)
data = n.times.map{ gets.split.map(&:to_i) }

#p data
data2 = []

# unify
data.group_by{|s,t,c|c}.each_value.map do |cc|
  cc.sort!
  o = []
  cc.each do |s,t,c|
    if o.last.nil? || o.last[1] != s
      o << [s, t, c]
    else
      o.last[1] = t
    end
  end

  data2.concat(o)
end

pa = Hash.new(0)
data2.each do |s,t,c|
  pa[s-0.5] += 1
  pa[t] -= 1
end

sum = 0
mx = 0
pa.sort.each do |t, d|
  #p [t, d]
  sum += d
  mx = [sum, mx].max
end

p mx


Measured memory_bytes: 37760
import java.util.Scanner;

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		String mot = "";
		String fro = "";
		String bac = ""; 
		String str;
		String shu = "";
		
		
		
		int count = 0;
		int i = 0;
		int h = 0;
		
		
		while(true){
			
			//System.out.println("word please");
			mot = as.next();
			//System.out.println(mot+"::");
			
			if(mot.equals("-")){
				
				break;
				
			}
			
			shu = mot;
			//System.out.println("number please");
			count = as.nextInt();
			
			for(i=0;i<count;i++){
				
				h = as.nextInt();
				
				fro = shu.substring(0,h);
				bac = shu.substring(h);
				shu = bac + fro;
				
			}
			
			str = shu;
			System.out.println(str);
			
		}

	}

}

Measured memory_bytes: 26388
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;


long long int N, M, K, H, W, L, R;

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

	vector<int>v(3);
	for (int i = 0; i < 3; i++) {
		cin >> v[i];
	}
	cin >> K;
	sort(v.begin(), v.end());
	v[2] <<= K;
	cout << v[0] + v[1] + v[2] << endl;
	return 0;
}


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

#define REP( i, n )     for( int (i) = 0; (i) < (n); (i)++ )
#define ALL( a )        (a).begin(), (a).end()

using namespace std;
using ll = long long;
using P = pair<int, int>;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

ll gcd( ll a, ll b ){
    if( b == 0 ) return a;
    else return gcd( b, a % b );
}

int main(){
    ll a, b, c, d; cin >> a >> b >> c >> d;
    ll t1 = b / c - ( a - 1 ) / c;
    ll t2 = b / d - ( a - 1 ) / d;
    ll cd = c * d / gcd( c, d );
    ll t3 = b / cd - ( a - 1 ) / cd;
    ll t = t1 + t2 - t3;

    cout << b - a - t + 1 << endl;
}

/*

*/

Measured memory_bytes: 384
def check(C, H, W, hp, wp):
    count = 0
    for hi in range(H):
        for wi in range(W):
            if (C[hi][wi] == '#') and (0 == (hp&(1<<hi))) and (0 == (wp&(1<<wi))):
                count += 1
    return count

def main():
    H, W, K = map(int, input().split())
    C = [list(input()) for _ in range(H)]
    ans = 0
    for hp in range(2**H):
        for wp in range(2**W):
            if check(C, H, W, hp, wp) == K:
                ans += 1
    print(ans)

main()


Measured memory_bytes: 68176
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> P;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
ll h[110];
ll dfs(ll l,ll r,ll hl,ll hr,ll nh){
    if(l==r)return 1;
    ll mi=inf,num=-1;
    ll ret=1;
    rep(i,l,r){
        if(mi>h[i]){
            mi=h[i];
            num=i;
        }
    }
    if(l>hl&&r<hr){
        (ret*=beki(2,mi-nh,mod))%=mod;
    }
    (ret*=dfs(l,num,hl,hr,mi))%=mod;
    (ret*=dfs(num+1,r,hl,hr,mi))%=mod;
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n;cin>>n;
    rep(i,1,n+1)cin>>h[i];
   // cout<<dfs(0,3,0,3,0)<<endl;
    h[0]=1;
    h[n+1]=1;
    ll dp[n+2];
    fill(dp,dp+n+1,0);
    dp[0]=1;
    rep(i,1,n+1){
        rep(j,i,n+1){
            (dp[j]+=dp[i-1]*dfs(i-1,j+2,i-1,j+2,1))%=mod;
        }
    }
    ll ans=dp[n]*2;
    cout<<ans%mod<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;

int main() {
  int x;
  cin >> x;
  cout << x * x * x << endl;
  return 0;
}



Measured memory_bytes: 3076
def main():

    N,M = map(int,input().split())
    A = [i for i in map(int,input().split())]
    A.sort()
    tmpC = 0
    targetList = []

    for i in range(M):

        element = list(map(int,input().split()))
        targetList.append(element)

    targetList.sort(key=lambda x:x[1],reverse=True)
    
    flag = False
    ans = 0
    for b,c in targetList:
        for j in range(b):
            if N > tmpC and A[tmpC] < c:
                ans += c
                tmpC +=1
            else:
                flag = True
                break
        if flag:
            break
    
    if tmpC < N:

        ans += sum(A[tmpC:])


    print(ans)






if __name__== "__main__":
    main() 


Measured memory_bytes: 32888
#include <iostream>

int main(){
    int n, ans = 1e9;
    std::cin >> n;
    for(int i = 0; i <= n; i++){
        int c = 0;
        int t = i;
        while (t) {
            c += t % 6;
            t /= 6;
        }
        t = n - i;
        while (t) {
            c += t % 9;
            t /= 9;
        }
        ans = std::min(ans, c);
    }
    std::cout << ans << std::endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=100010;
struct edge{ll v,from,w;}e[maxn*3];
ll n,first[maxn],deep[maxn],f[maxn][20],g[maxn][20],v[maxn],tot,lca,q;
void insert(ll u,ll v,ll w)
{tot++;e[tot].v=v;e[tot].w=w;e[tot].from=first[u];first[u]=tot;}
void dfs(ll x,ll fa)
{
    for(ll i=1;(1<<i)<=deep[x];i++)
    {
        f[x][i]=f[f[x][i-1]][i-1];
        g[x][i]=g[x][i-1]+g[f[x][i-1]][i-1];
    }
    for(ll i=first[x];i;i=e[i].from)if(e[i].v!=fa)
    {
        ll y=e[i].v;
        f[y][0]=x;
        deep[y]=deep[x]+1;
        g[y][0]=e[i].w;
        dfs(y,x);
    }
}
ll find(ll x,ll y)
{
    ll ans=0;
    if(deep[x]<deep[y])swap(x,y);
    ll d=deep[x]-deep[y]; 
    for(ll i=0;(1<<i)<=deep[x];i++)
        if((1<<i)&d){ans+=g[x][i];x=f[x][i];}
    if(x==y)return ans;
    for(ll i=20;i>=0;i--)
    if((1<<i)<=deep[x]&&f[x][i]!=f[y][i])
    {
        ans+=g[x][i]+g[y][i];
        x=f[x][i];y=f[y][i];
    }
    lca=f[x][0];
    return ans+g[x][0]+g[y][0];
}
int main()
{
    scanf("%lld",&n);
    for(ll i=1;i<n;i++)
    {
        ll u,v,w;
        scanf("%lld%lld%lld",&u,&v,&w);
        insert(u,v,w);
        insert(v,u,w);
    }
    dfs(1,-1);
    ll K;
    scanf("%lld%lld",&q,&K);
    for(ll i=1;i<=q;i++)
    {
        ll u,v;
        scanf("%lld%lld",&u,&v);
        printf("%lld\n",find(u,K)+find(K,v));
    }
    return 0;
}

Measured memory_bytes: 43008
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

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

    vector<long> s(n,0);
    s[0]=a[0];
    for(int i=1;i<n;i++){
        s[i]=s[i-1]+a[i];
    }

    long ans=0;

    sort(s.begin(),s.end());
    int x=0;
    while(x<n){
        int current=x;
        while(x<n&&s[current]==s[x]){
            x++;
        }
        long count=x-current;
        ans+=count*(count-1)/2;
        if(s[current]==0){
            ans+=count;
        }
    }

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



Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define print(a) cout<<a<<endl;
int aaa[200] = {}, bbb[200] = {}, counta=1,countb=1,xxx[1100000] = {}, yyy[1100000] = {};

int foo(int n, int x){
	int mi = 1000000;
	if(xxx[n]) return xxx[n]+x;
	if(x > 5) return mi;
	for(int i = counta-1; i >= 1; i--){
		if(aaa[i] < n){
			mi = min(foo(n-aaa[i],x+1), mi);
			if(mi - n == 1)break;
		}
	}
	
	xxx[n] = mi;
	return mi;
}
int boo(int n, int x){
	int mi = 1000000;
	if(yyy[n]) return yyy[n]+x;
	for(int i = countb-1; i >= 1; i--){
		if(bbb[i] < n){
			mi = min(boo(n-bbb[i],x+1), mi);
			if(mi - n == 1)break;
		}
	}
	yyy[n] = mi;
	return mi;
}

int main(){
	int i, n, abc;
	for(i = 1; abc <= 1000000; i++){
		abc = (i*(i+1)*(i+2))/6;
		xxx[abc] = 1;
		if(abc%2){
			yyy[abc] = 1;
			bbb[countb++] = abc;
		}
		aaa[counta++] = abc;
	}
	for(i = 1; i <= 1000000; i++){
		xxx[i] = foo(i, 0);
		yyy[i] = boo(i, 0);
	}
	while(1){
		cin>>n;
		if(n == 0) break;
		cout<<xxx[n]<<" "<<yyy[n]<<endl;
	}
	return 0;
}



Measured memory_bytes: 10900
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    int a,b,c,tmp;
    cin >> a >> b >> c;
    if(b < a){tmp = a; a = b; b = tmp;}
    if(a <= c && c <= b){cout << "Yes" << endl;}
    else{cout << "No" << endl;}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
   
   int a, b, c, k;
   cin >> a >> b >> c >> k;
   
   int cnt = 0;
   while(a >= b || b >= c){
       if(cnt >= k){
           cout << "No";
           return 0;
       }
       if(a >= b){
           b *= 2;
       }
       else if(b >= c){
           c *= 2;
       }
       cnt++;
   }
   
   cout << "Yes";
   
    return 0;
}


Measured memory_bytes: 3588
/*
 * ----------------------------------------------------------------------------
 *  (: Bismillahir Rahmanir Rahim :) 
 * File: /home/grimfirefly/Programming/Atcoder/Today/C_A_x_B_C.cpp
 * Project: /home/grimfirefly/Programming/Atcoder/Today
 * Created Date: Saturday, September 19th 2020, 6:08:22 pm
 * Author: Grim Firefly :)
 * Author Mail : GrimFirefly1@gmail.com
 * -----
 * Last Modified: Sat Sep 19 2020
 * Modified By: Grim Firefly :)
 * -----
 *   ________        .__           ___________.__                  _____ .__          
 *  /  _____/_______ |__|  _____   \_   _____/|__|_______   ____ _/ ____\|  |  ___.__.
 * /   \  ___\_  __ \|  | /     \   |    __)  |  |\_  __ \_/ __ \\   __\ |  | <   |  |
 * \    \_\  \|  | \/|  ||  Y Y  \  |     \   |  | |  | \/\  ___/ |  |   |  |__\___  |
 *  \______  /|__|   |__||__|_|  /  \___  /   |__| |__|    \___  >|__|   |____// ____|
 *         \/                  \/       \/                     \/              \/     
 * 
 *           |\_|\
 *           | a_a\
 *           | | "]
 *       ____| '-\___
 *      /.----.___.-'\
 *     //        _    \
 *    //   .-. (GF)  /|
 *   |'|  /\:  .--  / \
 *  // |-/  \_/____/\/~|
 * |/  \ |  []_|_|_] \ |
 * | \  | \ |___   _\ ]_}
 * | |  '-' /   '.'  |
 * | |     /    /|:  | 
 * | |     |   / |:  /\
 * | |     /  /  |  /  \
 * | |    |  /  /  |    \
 * \ |    |/\/  |/|/\    \
 *  \|\ |\|  |  | / /\/\__\
 *   \ \| | /   | |__
 *        / |   |____)
 *        |_/
 * ----------------------------------------------------------------------------
 */

//Code Start
#include <bits/stdc++.h>
using namespace std;

//constant
#define PI acos(-1.0)
#define SZ 10000
#define mod 1000000007
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double db;
typedef unsigned un;
typedef pair<int, int> pii;
typedef vector<int> vi;

//Debug Setting up
#define watch(x) cout << (#x) << "=" << x << endl
#define watch2(x, y) cout << (#x) << "=" << x << " & " << (#y) << "=" << y << endl;
#define watchara(wow)     \
    for (auto x : wow)    \
    {                     \
        cout << x << " "; \
    }                     \
    cout << "\n"

//defining fast_io
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

//defining something
#define F first
#define S second

//Main Function Start From Here
void solve()
{
    ll n;
    cin >> n;
    ll sum = 0;
    ll mid = (n - 1) / 2;
    for (int i = 1; i <= mid; i++)
        sum += (n - 1) / i;
    sum += (n - 1) - mid;
    cout << sum << endl;
}

int main()
{
    fast_io;

    solve();

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin>>N;
    int left=0;
    int right=N-1;
    cout << left<<endl;
    string l,r;
    cin>>l;
    if(l=="Vacant")return 0;
    cout << right<<endl;
    cin>>r;
    if(r=="Vacant")return 0;
    while(true){
        int mid=(left+right)/2;
        cout << mid << endl;
        string m;
        cin>>m;
        if(m=="Vacant")return 0;
        if((mid-left)%2==0&&m!=l){
            right=mid;
            r=m;
        }else if((mid-left)%2==1&&m==l){
            right=mid;
            r=m;
        }else{
            left=mid;
            l=m;
        }


    }

    



}


Measured memory_bytes: 848