akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
const double PI = acos(-1.0);
const string ALP = "abcdefghijklmnopqrstuvwxyz";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
int main(){
  int x,y;
  int a[12] = {0,2,0,1,0,1,0,0,1,0,1,0};
  cin >> x >> y;
  cout << ((a[x-1]==a[y-1])?"Yes":"No") << endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
s=[list(map(int,input().split()))for i in range(n)]
s.insert(0,[0,0,0])
p=0
for i in range(n):
    c=s[i+1][0]-s[i][0]
    d=abs(s[i+1][1]-s[i][1])+abs(s[i+1][2]-s[i][2])
    if c<d or (c-d)%2==1:
        p=1
        break
print("No" if p==1 else "Yes")

Measured memory_bytes: 27300
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
	int n, k, c;
	string s;
	cin >> n >> k >> c;
	cin >> s;
	vector<int> v1, v2;
	int last = -0x3f3f3f3f;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'o' && i - last > c) {
			v1.push_back(i);
			last = i;
		}
	}
	if (v1.size() > k) {
		return 0;
	}
	last = 0x3f3f3f3f;
	for (int i = s.size() - 1; i >= 0; i--) {
		if (s[i] == 'o' && last - i > c) {
			v2.push_back(i);
			last = i;
		}
	}
	reverse(v2.begin(), v2.end());
	for (int i = 0; i < v1.size(); i++) {
		if (v1[i] == v2[i]) {
			cout << v1[i] + 1 << endl;
		}
	}
}


Measured memory_bytes: 5688
///////////////////////////////////////////// Template /////////////////////////////////////////////
#![allow(non_snake_case, unused)]
use std::collections::*;

//////////////////// missing functions in 1.15.1 ////////////////////
macro_rules! eprint {
	($($t:tt)*) => { {
		use ::std::io::Write;
		let _ = write!(::std::io::stderr(), $($t)*);
	} };
}
macro_rules! eprintln {
	($($t:tt)*) => { {
		use ::std::io::Write;
		let _ = writeln!(::std::io::stderr(), $($t)*);
	} };
}

//////////////////// useful functions ////////////////////
pub trait SetMin {
	fn setmin(&mut self, v: Self) -> bool;
}
impl<T> SetMin for T where T: PartialOrd {
	fn setmin(&mut self, v: T) -> bool {
		*self > v && { *self = v; true }
	}
}
pub trait SetMax {
	fn setmax(&mut self, v: Self) -> bool;
}
impl<T> SetMax for T where T: PartialOrd {
	fn setmax(&mut self, v: T) -> bool {
		*self < v && { *self = v; true }
	}
}

macro_rules! debug {
	($($v: expr),*) => {
		$(eprint!("{} = {:?} ", stringify!($v), $v);)*
		eprintln!("@ {}:{}", file!(), line!());
	}
}

macro_rules! mat {
	($($e:expr),*) => { Vec::from(vec![$($e),*]) };
	($($e:expr,)*) => { Vec::from(vec![$($e),*]) };
	($e:expr; $d:expr) => { Vec::from(vec![$e; $d]) };
	($e:expr; $d:expr $(; $ds:expr)+) => { Vec::from(vec![mat![$e $(; $ds)*]; $d]) };
}

pub fn readln() -> String {
	let mut line = String::new();
	::std::io::stdin().read_line(&mut line).unwrap_or_else(|e| panic!("{}", e));
	line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:ty),+) => {
		($(_read!($it; $t)),*)
	};
}

pub fn main() {
	let _ = ::std::thread::Builder::new().name("run".to_string()).stack_size(32 * 1024 * 1024).spawn(run).unwrap().join();
}
////////////////////////////////////////////////////////////////////////////////////////////////////

fn run() {
	let (a, b) = read!(i32, i32);
	debug!(a, b);
	if a + b == 15 {
		println!("+");
	} else if a * b == 15 {
		println!("*");
	} else {
		println!("x");
	}
}


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

using namespace std;

int x, n, cnt;

int main(){
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> x;
		if(x != i + 1) cnt++;
	}
	if(cnt >= 3){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}
}

Measured memory_bytes: 256
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val (x1, y1, x2, y2) = nextIntList()
    val p1 = V(x1, y1)
    val p2 = V(x2, y2)
    val v1 = p2 - p1
    val p3 = p2 + v1.rot90()
    val p4 = p3 - v1
    println("$p3 $p4")
}

data class V(val x: Double, val y: Double) {
    companion object {
        fun rad(A: Double, rad: Double) = V(A * Math.cos(rad), A * Math.sin(rad))
        fun deg(A: Double, deg: Double) = rad(A, d2r(deg))
        private fun d2r(d: Double) = d * Math.PI / 180
    }

    constructor(x: Int, y: Int) : this(x.toDouble(), y.toDouble())
    constructor(x: Long, y: Long) : this(x.toDouble(), y.toDouble())

    fun norm() = Math.sqrt(x * x + y * y)
    fun normalized() = V(x / norm(), y / norm())
    fun distanceTo(o: V) = Math.sqrt((x - o.x) * (x - o.x) + (y - o.y) * (y - o.y))

    fun rot90() = rot(90.0)
    fun rot180() = rot(180.0)
    fun rot270() = rot(270.0)
    fun rot(d: Double): V {
        val r = d2r(d)
        val xx = x * Math.cos(r) - y * Math.sin(r)
        val yy = x * Math.sin(r) + y * Math.cos(r)
        return V(xx, yy)
    }

    operator fun plus(o: V) = V(x + o.x, y + o.y)
    operator fun minus(o: V) = V(x - o.x, y - o.y)

    override fun toString(): String {
        return "${Math.round(x)} ${Math.round(y)}"
    }
}

Measured memory_bytes: 37688
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N, *A=map(int,read().split())

bound = [0]*(N+1)
bound[0] = 1
#Nが0のとき
if N == 0:
  if A[0] == 1:
    print(1)
  else:
    print(-1)
  sys.exit()
  
#Nが0以外のとき 
#上から
for i in range(1,N+1):
  bound[i] = (bound[i-1]-A[i-1]) *2
  if bound[i] < A[i]:
    print(-1)
    sys.exit()
    
#下からのと最小値を取る
cum_sum = 0 
for i in range(N,-1,-1):
  cum_sum += A[i]
  bound[i] = min(bound[i],cum_sum)
print(sum(bound))


Measured memory_bytes: 674396
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
#define vecmin(A) *min_element(A.begin(),A.end());
#define vecmax(A) *max_element(A.begin(),A.end());
typedef long long ll;

ll MOD = (ll)pow(10,9)+7;

ll spow(ll a,ll p){
  if(p == 0) return 1;
  if(p == 1) return a;
  return (a*spow(a,p-1))%MOD;
}

int main(){
  int n;
  cin >> n;
  map<int,int> mp;
  rep(i,n){
    int x;
    cin >> x;
    mp[x] ++;
  }
  if(n%2 == 0){
    for(auto p : mp){
      if(p.first%2 == 0){
        cout << 0 << endl;
        return 0;
      }
      if(p.second != 2){
        cout << 0 << endl;
        return 0;
      }//if_p.second
    }//for_p
    cout << spow(2,mp.size()) << endl;
    return 0;
  }//if_mp.size
  if(n%2 == 1){
    for(auto p : mp){
      if(p.first == 1){
        cout << 0 << endl;
        return 0;
      }
      if(p.first == 0){
        if(p.second != 1){
          cout << 0 << endl;
          return 0;
        }
      }
      if(p.first > 0){
        if(p.second != 2){
          cout << 0 << endl;
          return 0;
        }
      }
    }
    cout << spow(2,mp.size()-1) << endl;
    return 0;
  }//if_mp.size
}


Measured memory_bytes: 3328
const n_list = require('fs').readFileSync('/dev/stdin', 'utf8').split(' ').map(s => parseInt(s, 10));

var ans = false;

if (n_list[0] === n_list[1] && n_list[0] !== n_list[2] ||
  n_list[0] === n_list[2] && n_list[0] !== n_list[1] ||
  n_list[1] === n_list[2] && n_list[0] !== n_list[1]) {
	ans = true;
}

if (ans) {
	console.log('Yes');
} else {
	console.log('No');
}


Measured memory_bytes: 7372
#UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n,m = map(int,input().split())

uf = UnionFind(n+1)
for i in range(m):
    a,b = map(int,input().split())
    uf.union(a,b)
    
ans = 0
for i in range(1,n+1):
    ans = max(ans, uf.size(i))
print(ans)

Measured memory_bytes: 14736
#include <iostream>
#include <algorithm>
#include <math.h>
#include <cstdio>
using namespace std;

typedef long long ll;

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

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




int main(){
	
	int a,b,c;
	while(cin>>a>>b>>c,(a+b+c)){
		int n;
		cin>>n;
		vector<int>A;
		vector<int>B;
		vector<int>C;
		vector<int>S;
		
		int d[301];
		for(int i=0;i<=300;i++){
			d[i]=2;
		}
		
		int t1,t2,t3,t4;
		for(int i=0;i<n;i++){
			cin>>t1>>t2>>t3>>t4;
			
			A.push_back(t1);
			B.push_back(t2);
			C.push_back(t3);
			S.push_back(t4);
			
		}
		
		int flag=1;
		
		while(flag==1){
			flag=0;
			for(int i=0;i<n;i++){
				if(S[i]==1){
					if(d[A[i]]==2){
						flag=1;
						d[A[i]]=1;
					}
					if(d[B[i]]==2){
						flag=1;
						d[B[i]]=1;
					}
					if(d[C[i]]==2){
						flag=1;
						d[C[i]]=1;
					}
				}
				else{
					if(d[A[i]]==1 && d[B[i]]==1 && d[C[i]]==2){
						flag=1;
						d[C[i]]=0;
					}
					if(d[A[i]]==1 && d[B[i]]==2 && d[C[i]]==1){
						flag=1;
						d[B[i]]=0;
					}
					if(d[A[i]]==2 && d[B[i]]==1 && d[C[i]]==1){
						flag=1;
						d[A[i]]=0;
					}
					
				}
			}
			
			
		}
		
		for(int i=1;i<=a+b+c;i++){
			cout<<d[i]<<endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 1240
#include <stdio.h>          // printf(), scanf()
#define MAX_N 10000

int
main(int argc, char** argv)
{
	int s[MAX_N + 1];
	int n = 0;
	int q = 0;
	int t = 0;
	int i, j;

	scanf("%d", &n);
	for (i = 0; i < n; ++i)
		scanf("%d", &s[i]);

	scanf("%d", &q);
	int count = 0;
	for (i = 0; i < q; ++i)
	{
		scanf("%d", &t);
		s[n] = t;
		for (j = 0; s[j] != t; ++j)
			;

		if (j < n)
			count++;
	}

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

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;
const long long int MOD=1e9+7;
const double PI = 3.1415926535;

int main(){
  double a, b, x;
  cin >> a >> b >> x;
  double h = b-x/(a*a);
  double t;
  if(h<=b/2){
    t = atan(h/(a/2.0));
  }
  else{
    t = atan(b/(2.0*x/(a*b)));
  }
  printf("%.8lf\n",180.0*t/PI);
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  
#define pb push_back
#define mp make_pair
#define in insert
#define f first
#define s second
#define ll long long
#define ld long double
  
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
const int inf = 2e9;
const ll INF = 1e18;

ll w[N], v[N], dp[N], p[N];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("*.in", "r", stdin);freopen("*.out", "w", stdout);
	int n, W;
	cin >> n >> W;
	for(int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}
	dp[0] = 1;
	for(int i = 1; i <= n; i++) {
		for(int j = 1e5; j >= 0; j--) {
			if(dp[j] == 1) {
				dp[j + v[i]] = 1;
				if(p[j + v[i]])
					p[j + v[i]] = min(p[j + v[i]], p[j] + w[i]);
				else 
					p[j + v[i]] = p[j] + w[i];
			}
		}
	}
	for(int i = 1e5; i >= 0; i--) {
		if(dp[i] && p[i] <= W) {
			cout << i;
			break;
		}
	}
}

Measured memory_bytes: 5632
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int l = scan.nextInt();
        int min = Math.abs(l);
        int sub = l;
        for(int i = 2; i <= n; i++){
            if(Math.abs(l + i - 1) < min){
                min = Math.abs(l + i - 1);
                sub = l + i - 1;
            }
        }
        int sum = 0;
        for(int i = 1; i <= n; i++){
            sum += l + i - 1;
        }
        System.out.println(sum - sub);
    }
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    double theta = 6.0 * m - (30 * h + 0.5 * m);
    theta = theta * M_PI / 180.0;

    cout << fixed << setprecision(15);
    cout << sqrt(a * a + b * b - 2.0 * a * b * cos(theta)) << endl;
    return 0;
}


Measured memory_bytes: 4156
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n;
  ans = 1;
  rep(i, n) {
    cin >> a[i];
    if (a[i] == 0) {
      Cout(0);
      return 0;
    }
  }
  rep(i, n) {
    ld k1, k2;
    k1 = (ld)ans;
    k2 = (ld)LINF / (ld)a[i];
    if (k1 > k2) {
      Cout(-1);
      return 0;
    }
    ans *= a[i];
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 4432
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define rep(i,n) for(int i=0;i<n;i++)
int n,a[200];
int ans=0,maxi;
map<int,int>col;
signed main(){
    cin>>n;
    rep(i,n){
        cin>>a[i];
        int c=a[i]/400;
        if(a[i]>3199)c=8;
        col[c]++;
    }
    rep(i,8){
        if(col[i]>0)ans++;
    }
    maxi=ans+col[8];
    if(ans==0)ans++;
    cout<<ans<<" "<<maxi<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from io import StringIO
import unittest

def resolve():
    n,k=list(map(int,input().split()))
    p = list(map(int,input().split()))

    loop=n-k+1

    ms=0
    bef=0
    for i in range(loop):
        tmp=0
        if i ==0:
            for j in range(k):
                tmp+=p[i+j]/2+1/2
            if tmp > ms:
                ms = tmp
        else:
            tmp=bef
            tmp-=(p[i-1]/2+1/2)
            tmp+=(p[i+k-1]/2+1/2)
            if tmp > ms:
                ms = tmp
        bef=tmp

    print(ms)

    return

resolve()


Measured memory_bytes: 84588
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int idx;
string s;
vector<int> v[128];

vector<int> op(char ch,vector<int> a,vector<int> b=vector<int>()){
	vector<int> res(502);
	vector<int>::iterator it;

	if(ch == 'u') it = set_union(a.begin(),a.end(),b.begin(),b.end(),res.begin());
	if(ch == 'i') it = set_intersection(a.begin(),a.end(),b.begin(),b.end(),res.begin());
	if(ch == 'd') it = set_difference(a.begin(),a.end(),b.begin(),b.end(),res.begin());
	if(ch == 's') it = set_symmetric_difference(a.begin(),a.end(),b.begin(),b.end(),res.begin());
	if(ch == 'c') it = set_difference(v['U'].begin(),v['U'].end(),a.begin(),a.end(),res.begin());

	res.resize(it-res.begin());
	return res;
}

vector<int> solve(void){
	if(s[idx] == ')'){
		idx++;
		return vector<int>();
	}

	bool flg = false;
	if(s[idx] == 'c'){
		flg = true;
		idx++;
	}

	vector<int> res;
	if(s[idx] == '('){
		idx++;
		res = solve();
	}
	else{
		res = v[s[idx++]];
	}

	if(flg) res = op('c',res);

	while(idx < s.length() && s[idx] != ')'){
		char ch = s[idx++];

		flg = false;
		if(s[idx] == 'c'){
			flg = true;
			idx++;
		}

		vector<int> tmp;
		if(s[idx] == '('){
			idx++;
			tmp = solve();
		}
		else{
			tmp = v[s[idx++]];
		}

		if(flg) tmp = op('c',tmp);
		res = op(ch,res,tmp);
	}
	idx++;
	return res;
}

int main(void){
	while(1){
		v['U'].clear();
		for(int i=0;i<5;i++) v['A'+i].clear();

		while(1){
			char name;
			int n;
			if(!(cin>>name>>n)) return 0;
			if(name == 'R') break;

			v[name] = vector<int>(n);
			for(int i=0;i<n;i++){
				cin>>v[name][i];
			}
			sort(v[name].begin(),v[name].end());
			v['U'] = op('u',v[name],v['U']);
		}

		cin>>s;
		idx = 0;

		vector<int> ans = solve();
		if(ans.empty()){
			cout<<"NULL\n";
			continue;
		}

		for(int i=0;i<ans.size()-1;i++){
			cout<<ans[i]<<" ";
		}
		cout<<ans[ans.size()-1]<<endl;
	}
}

Measured memory_bytes: 0
package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
	wtr = bufio.NewWriter(os.Stdout)
)

func scanInt() int {
	sc.Scan()
	a,_ := strconv.Atoi(sc.Text())
	return a
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ { res[i] = scanInt() }
	return res
}

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

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

	n, k := scanInt(), scanInt()
	h := scanInts(n)

	ans := 0

	for _, e := range h {
		if e >= k {
			ans++
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
	double n,t,a,h;
	int i;
	double X,min;
	int S;
	cin>>n>>t>>a;
	min=100000;
	for(i=0;i<n;i++){
		cin>>h;
		X=a-(t-h*0.006);
		if(X<0) X*=-1; 
//		cout<<X<<endl;
		if(min>X){
			min=X;
			S=i+1;
		}
	}
	cout<<S<<endl;
	return 0;
}

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


int main() {
string T;
cin >> T;
rep(i,T.size()) {
    if (T.at(i) == '?') T.at(i) = 'D';
}
cout << T << endl;

return 0;
}

Measured memory_bytes: 3756
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define isNum(a) (a>='0'&&a<='9')
#define SP putchar(' ')
#define EL putchar('\n')
#define inf 2147483647
#define N 10
#define File(a) freopen(a".in", "r", stdin), freopen(a".out", "w", stdout)
template<class T>inline void read(T&);
template<class T>inline void write(const T&);
int cnt[N];
int main () {
    for (int i=1; i<=3; ++i) {
        int u, v;
        read(u), read(v);
        ++cnt[u], ++cnt[v];
    }
    int ans=0;
    for (int i=1; i<=4; ++i) {
        ans+=cnt[i]&1;
    }
    puts(ans==0||ans==2?"YES":"NO");
    return 0;
}
template<class T>void read(T &Re) {
    T k=0;
    char ch=getchar();
    int flag=1;
    while (!isNum(ch)) {
        if (ch=='-') {
            flag=-1;
        }
        ch=getchar();
    }
    while (isNum(ch)) {
        k=(k<<1)+(k<<3)+ch-'0';
        ch=getchar();
    }
    Re=flag*k;
}
template<class T>void write(const T& Wr) {
    if (Wr<0) {
        putchar('-');
        write(-Wr);
    }else {
        if (Wr<10) {
            putchar(Wr+'0');
        }else {
            write(Wr/10);
            putchar((Wr%10)+'0');
        }
    }
}


Measured memory_bytes: 256
# n=int(input())
# a,b=map(int, input().split())
# c=list(map(int, input().split()))
# s=[list(map(int,list(input()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき

# a=100
# b=0.987654321
# print('{0:06d}-{1:6f}'.format(a,b))  # 0埋めのときの出力
# 000100-0.987654

import numpy as np
import math
import copy

x, a=map(int, input().split())

if x < a:
    print(0)
else:
    print(10)

Measured memory_bytes: 21780
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = Integer.parseInt(sc.next());
    int K = Integer.parseInt(sc.next());

    for (int i = 0; i < N; i++) {
      Integer.parseInt(sc.next());
    }

    int ans = (N - 1) / (K - 1);
    if ((N - 1) % (K - 1) != 0) {
      ans++;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 44844
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 998244353;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n, x;
	cin >> n >> x;
	int mn = inf;
	for (int i = 0; i < n; ++i) {
		int t;
		cin >> t;
		x -= t;
		mn = min(mn, t);
	}
	cout << n + x / mn << '\n';
 	return 0;
}


Measured memory_bytes: 256
A,B = map(int, raw_input().split())
G = [['#']*100 for _ in range(50)] + [['.']*100 for _ in range(50)]
A -= 1
B -= 1
for y in range(0,50,2):
  for x in range(0,100,2):
    if A>0:
      G[y][x] = '.'
      A -= 1
    if B>0:
      G[99-y][x] = '#'
      B -= 1
print 100,100
for g in G:
  print "".join(g)


Measured memory_bytes: 2692
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>

#define cauto const auto&
#define ALL(v) begin(v),end(v)
#else
#define ALL(v) (v).begin(),(v).end()
#endif

using namespace std;


namespace{
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T> inline T &chmin(T &x, const T &y){ return x = min(x, y); }
template <class T> inline T &chmax(T &x, const T &y){ return x = max(x, y); }
template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8

struct union_find{
	typedef unsigned size_type;
	vector<int> par;
	size_type grs;
	explicit union_find(size_type n = 0){ init(n); }
	void init(size_type n){
		par.assign(n, -1);
		grs = n;
	}
	size_type find(size_type x){
		if(par[x] < 0){ return x; }
		return par[x] = find(par[x]);
	}
	size_type size(size_type x){
		return -par[find(x)];
	}
	size_type groups(){
		return grs;
	}
	bool unite(size_type x, size_type y){
		x = find(x);
		y = find(y);
		if(x == y){ return false; }
		if(par[x] < par[y]){ swap(x, y); }
		par[y] += par[x];
		par[x] = y;
		--grs;
		return true;
	}
	bool same(size_type x, size_type y){
		return find(x) == find(y);
	}
	bool is_root(size_type x){
		return find(x) == x;
	}
};

void mainmain(){
	const int LIM = 100010;
	union_find uf(2 * LIM);
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; ++i){
		int x, y;
		scanf("%d%d", &x, &y);
		uf.unite(x, y + LIM);
	}

	VV(LL) cnts;
	initvv(cnts, 2, 2 * LIM);
	for(int i = 0; i < 2 * LIM; ++i){
		++cnts[i >= LIM][uf.find(i)];
	}
	LL ans = -n;
	for(int i = 0; i < 2 * LIM; ++i){
		ans += cnts[0][i] * cnts[1][i];
	}
	printf("%lld\n", ans);
}



}
int main() try{
//	ios::sync_with_stdio(false); cin.tie(0);
	cout << fixed << setprecision(10);
	cerr << fixed << setprecision(4);
	mainmain();
}
catch(...){
	throw;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main(void){//main関数
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if(s[0]==s[1] && s[1]==s[2]){
    //正直面倒だった
    cout << "No" << endl;
    return 0;
  }
  cout << ((s[0]==s[1] && s[2]==s[3]) || (s[0]==s[3] && s[1]==s[2])?"Yes":"No") << endl;
  return 0;
  //今日のノルマ達成！
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
//#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<double,double> P;
const ll INF = 4*1e18;
const int MOD = 1000000007;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

string a, b,c;
bool ab[10000],cb[10000],ac[10000];

signed main(){
  cin>>a>>b>>c;
  rep(i,8001)ab[i] = cb[i] = ac[i] = true;
  rep(i,8001){
    if(i+b.length() <= 4000 || 4000+a.length() <= i)continue;
    repd(j,max(i,4000LL),min(4000LL+a.length(), i+b.length())){
      if(a[j-4000LL] != b[j-i] && a[j-4000LL] != '?' && b[j-i] != '?'){
        ab[i] = false;break;
      }
    }
  }
  rep(i,8001){
    if(i+b.length() <= 4000 || 4000+c.length() <= i)continue;
    repd(j,max(i,4000LL),min(4000LL+c.length(), i+b.length())){
      if(c[j-4000LL] != b[j-i] && c[j-4000LL] != '?' && b[j-i] != '?'){
        cb[i] = false;break;
      }
    }
  }
  rep(i,8001){
    if(i+c.length() <= 4000 || 4000+a.length() <= i)continue;
    repd(j,max(i,4000LL),min(4000LL+a.length(), i+c.length())){
      if(a[j-4000LL] != c[j-i] && a[j-4000LL] != '?' && c[j-i] != '?'){
        ac[i] = false;break;
      }
    }
  }
  int ans = INF;
  rep(i,8001){
    rep(j,8001){
      if(ab[i] && ac[j] && cb[4000+i-j]){
        int mx = max(4000LL+a.length(), max(i+b.length(),j+c.length())),
            mm = min(4000LL,min(i,j));
        if(ans > mx-mm){
          ans = mx-mm;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
// Contest: AtCoder Beginner Contest 178 (https://atcoder.jp/contests/abc178)
// Problem: E: Dist Max (https://atcoder.jp/contests/abc178/tasks/abc178_e)


// region boilerplate
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <chrono>
#include <cstdint>
#include <deque>
#include <exception>
#include <forward_list>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#if __cplusplus >= 201703L
#   include <optional>
#   include <string_view>
#   include <variant>
#endif

using namespace std;

#if __cplusplus >= 201703L
#   define all(a)      begin(a),end(a)
#   define sz(x)       ((int)size(x))
#else
#   define all(a)      (a).begin(),(a).end()
#   define sz(x)       ((int)(x).size())
#endif

#define rep(a, b)      for(int a = 0; a < (b); ++a)
#define reps(a, b, c)  for(int a = (b); a < (c); ++a)
#define trav(a, b)     for(auto& a : b)

using ll = long long;
using ld = long double;
using u64 = uint64_t;
using u32 = uint32_t;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vpi = vector<pi>;

#if __cplusplus >= 201703L
#   define MAYBE_UNUSED [[maybe_unused]]
#else
#   define MAYBE_UNUSED
#endif

MAYBE_UNUSED static constexpr int INF = (int)1e9 + 5;
MAYBE_UNUSED static constexpr ll INFL = (ll)1e18 + 5;
MAYBE_UNUSED static mt19937 rng((u32)chrono::duration_cast<chrono::nanoseconds>(chrono::high_resolution_clock::now().time_since_epoch()).count());
//endregion

ll solve(vpi& p, int l, int r) {
    if (r - l < 2)
        return 0;

    int m = (r + l) / 2;
    ll mx = max(solve(p, l, m), solve(p, m, r));

    int j = m;
    ll down = -INFL;
    reps(i, l, m) {
        auto [x, y] = p[i];
        while (j < r && p[j].second <= y)
            down = max(down, (ll)p[j].first - p[j].second), ++j;
        mx = max(mx, down - x + y);
    }

    j = r - 1;
    ll up = -INFL;
    for (int i = m - 1; i >= l; --i) {
        auto [x, y] = p[i];
        while (j >= m && p[j].second >= y)
            up = max(up, (ll)p[j].first + p[j].second), --j;
        mx = max(mx, up - x - y);
    }

    inplace_merge(begin(p) + l, begin(p) + m, begin(p) + r,
                  [&](auto& p1, auto& p2) { return p1.second < p2.second; });
    return mx;
}

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

    int n; cin >> n;
    vpi p(n);
    for (auto& [x, y] : p) cin >> x >> y;
    sort(all(p));

    cout << solve(p, 0, n) << '\n';

    return 0;
}


Measured memory_bytes: 7212
n,m=map(int,input().split())
M=[0]*m
for nn in range(n):
  s=input().split()
  for i in range(int(s[0])):
    M[int(s[i+1])-1]+=1
a=0
for mm in range(m):
  if M[mm]==n:
    a+=1
print(a)

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#define int long long
using namespace std;
int val[100001];
int wt[100001];


int knapsck(int n, int w){
    int dp[n+1][w+1];
    memset(dp[0], 0ll, sizeof(dp[0]));

    for (int i=0; i<=n; i++){
        for (int j = 0; j <= w; j++){
            // Base Case ...
            if(i==0 || j == 0){
                dp[i][j] = 0ll; 
                continue;
            }
            if(wt[i-1]>j)
                dp[i][j] = dp[i-1][j];
            else{
                dp[i][j] = max( 
                                dp[ i-1 ][j] , 
                                val[i-1] + dp[ i-1 ][ j - wt[i-1] ] );
            }
        }
    }
    return dp[n][w]; 
}

signed main() {
    int n, w;

    cin >> n >> w;
    for (int i=0;i<n; i++)
        cin >> wt[i] >> val[i];
    cout<<knapsck(n, w);
     
    return 0;
}

Measured memory_bytes: 82416
import sys
from bisect import bisect_left

input = sys.stdin.readline


def main():
    N = int(input())
    L = list(map(int, input().split()))

    L.sort()
    ans = 0
    for i in range(N - 1):
        a = L[i]
        for j in range(i + 1, N):
            k = bisect_left(L, a + L[j], lo=j)
            ans += (k - 1 - j)

    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
  long long x; cin >> x;
  long long ans = x/11;
  if (x % 11 == 0) ans = 2*ans;
  else if (x%11 <= 6 ) ans = 2*ans + 1;
  else ans = 2*ans + 2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    X = input()
    
    def popcount(x):
        '''xの立っているビット数をカウントする関数
        (xは64bit整数)'''

        # 2bitごとの組に分け、立っているビット数を2bitで表現する
        x = x - ((x >> 1) & 0x5555555555555555)

        # 4bit整数に 上位2bit + 下位2bit を計算した値を入れる
        x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)

        x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f # 8bitごと
        x = x + (x >> 8) # 16bitごと
        x = x + (x >> 16) # 32bitごと
        x = x + (x >> 32) # 64bitごと = 全部の合計
        return x & 0x0000007f

    ans = []
   
    f = [0] * N
    # preprocess 1
    for i in range(1, N):
        pc = popcount(i)
        j =  i % pc
        f[i] = f[j] + 1
    
    # preprocess 2
    X_COUNT = X.count("1")
    X = tuple(map(int, tuple(X)))
    rem_plus = [0] * N
    rem_minus = [0] * N
    two_factor = 1
    for i in range(N):
        rem_plus[i] = two_factor
        two_factor *= 2
        two_factor %= (X_COUNT+1)

    if X_COUNT > 1:
        two_factor = 1
        for i in range(N):
            rem_minus[i] = two_factor
            two_factor *= 2
            two_factor %= (X_COUNT-1)


    X_rem_plus = 0
    X_rem_minus = 0
    two_factor = 1
    for c in X[::-1]:
        X_rem_plus += two_factor*c
        X_rem_plus %= (X_COUNT+1)
        two_factor *= 2
        two_factor %= (X_COUNT+1)
    
    if X_COUNT > 1:
        two_factor = 1
        for c in X[::-1]:
            X_rem_minus += two_factor*c
            X_rem_minus %= (X_COUNT-1)
            two_factor *= 2
            two_factor %= (X_COUNT-1)
    
    for i, c in enumerate(X):
        if c:
            if X_COUNT > 1:
                rem = X_rem_minus - rem_minus[N-1-i]
                rem %= (X_COUNT-1)
                ans.append(f[rem]+1)
            elif X_COUNT == 1:
                ans.append(0)
            else:
                ans.append(0)
        else:
            rem = X_rem_plus + rem_plus[N-1-i]
            rem %= (X_COUNT+1)
            ans.append(f[rem]+1)
   
    print(*ans, sep="\n")

if __name__ == "__main__":
    main()

Measured memory_bytes: 32692
from collections import deque
import sys
def main():
  a,b=map(int,sys.stdin.readline().split())
  e=[[]for i in range(a)]

  for i in range(a-1):
    c1,c2=map(int,sys.stdin.readline().split())
    e[c1-1].append(c2-1)
    e[c2-1].append(c1-1)

  g=[[]for i in range(a)]
  f=deque()
  f.append((0,-1))
  ans=[0 for _ in range(a)]
  for i in range(b):
    ten,p=map(int,input().split())
    ans[ten-1]+=p
  i=0
  while len(f)!=0:
    i,fr=f.popleft()
    for j in e[i]:
      if j==fr:
        continue
      else:
        ans[j]+=ans[i]
        f.append((j,i)) 
  print(*ans)
if __name__ == '__main__':  
  main()
    
  

  
  


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++){
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>

int A[1000000], n;

int binarySearch(int key) {
  int left = 0;
  int right = n;
  int mid;
  while(left < right) {
    mid = (left + right) / 2;
    if(key == A[mid]) return 1; 
    if(key > A[mid]) left = mid + 1;
    else if(key < A[mid]) right = mid; 
  }
  return 0;
}

int main(void) {
  int i, q, k, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) {
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++) {
    scanf("%d",&k);
    if(binarySearch(k))
      sum++;
  }
  printf("%d\n",sum);
  return 0;
}


Measured memory_bytes: 2120
# 各桁の数値の総和を計算する.
def calc_digit_sum(num):
    sums = 0
    while num > 0:
        sums += num % 10
        num //= 10
    return sums


n = int(input())
for idx1 in range(1, 10):
    for idx2 in range(1, 10):
        if idx1 * idx2 == n:
            print("Yes")
            exit()

print("No")

Measured memory_bytes: 61880
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}

struct edge{
  int to; ll cost;
};

int N;
vector<edge> G[100100];
int Q, K;

ll d[100100];

void dfs(int i, ll co) {
  d[i] = co;
  for(int j = 0; j < G[i].size(); j++) {
    if(d[G[i][j].to] == INF) dfs(G[i][j].to , co + G[i][j].cost);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N;
  rep(i, N - 1) {
    int a, b; cin >> a >> b; a --; b --;
    ll c; cin >> c;
    edge es; es.to = b; es.cost = c;
    G[a].push_back(es);
    es.to = a;
    G[b].push_back(es);
  }
  rep(i, N) d[i] = INF;
  cin >> Q >> K; K --;
  dfs(K, 0);
  rep(i, Q) {
    int x, y; cin >> x >> y; x --; y --;
    cout << d[x] + d[y] << "\n";
  }
  return 0;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

int32_t main(){
	int n,k;
	cin>>n>>k;
	cout<<min(n%k,k-n%k);
}


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

lint dp[21234];

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

int main() {
    lint h, n;
    cin >> h >> n;

    vector<lint> a(n), b(n);
    for(lint i=0; i<n; i++)  cin >> a[i] >> b[i];

    fill(begin(dp), end(dp), 1e18);
    dp[0] = 0;

    for(lint i=0; i<n; i++) {
        for(lint d=0; d<21234; d++) {
            if(d + a[i] > 21234)  continue;
            chmin(dp[d + a[i]], dp[d] + b[i]);
        }
    }

    lint ans = 1e18;
    for(lint d=h; d<21234; d++) {
        chmin(ans, dp[d]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
string a[200020];
int main(void)
{
    int n,mx=0;
    map<string,int>mp;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
        mx=max(mx,mp[a[i]]);
    }
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        if(mp[a[i]]==mx)
        {
            cout<<a[i]<<endl;
            mp[a[i]]=0;
        }
    }
    return 0;
}


Measured memory_bytes: 26752
#include<iostream>
using namespace std;
int main() {
	int a,b,c; cin >> a;
	b = a / 100;
	c = a % 100;
	if (0 < b && b < 13 && c>12)cout << "MMYY";
	else if (0 < c && c < 13 && b>12)cout << "YYMM";
	else if (0 < b && b < 13 && 0 < c && c < 13)cout << "AMBIGUOUS";
	else if (0 < b && b < 13 && c == 0)cout << "MMYY";
	else if (0 < c && c < 13 && b == 0)cout << "YYMM";
	else cout << "NA";
}


Measured memory_bytes: 256
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    int ans;
    if(b + c >= a){
        ans = c - (a - b);
    }
    else {
        ans = 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
    int a;
    cin >> a;
    cout << (a % 2 == 0 ? a : a * 2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
int main(){
    int v[5]={},w[5]={0,1,1,2,2};
    for(int i=0;i<6;i++){
        int x;
        scanf("%d",&x);
        v[x]++;
    }
    std::sort(v,v+5);
    for(int i=0;i<5;i++){
        if(v[i]!=w[i]){
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}

Measured memory_bytes: 128
package main

import (
  "fmt"
)
var N, M int

var adj[51][]int
var indegree [51]int

func check(from, to int) bool{
  visited := make([]bool, N+1)

  cnt := 0
  for i := 1; i <= N; i++ {
    if visited[i] {
      continue
    }
    cnt += 1
    dfs(i, visited, from, to)
  }
  if cnt > 1 {
    return true
  } else {
    return false
  }
}

func dfs(cur int, visited []bool, from, to int) {
  visited[cur] = true
  for i := 0; i < len(adj[cur]); i++ {
    if cur == from && adj[cur][i] == to {
      continue
    }
    next := adj[cur][i]
    if visited[next] {
      continue
    }
    dfs(next, visited, from, to)
  }
}

func main() {
  fmt.Scanf("%d %d", &N, &M)

  for i := 0; i < M; i++ {
    var a, b int
    fmt.Scanf("%d %d", &a, &b)
    adj[a] = append(adj[a], b)
    adj[b] = append(adj[b], a)
    indegree[a] += 1
    indegree[b] += 1
  }
  ret := 0

  for i := 1; i <= N; i++ {
    for j := 0; j < len(adj[i]); j++ {
      if(check(i, adj[i][j])) {
        ret += 1
//        fmt.Printf("fronm %d to %d\n", i, adj[i][j])
      }
    }
  }
  fmt.Println(ret)
}


Measured memory_bytes: 512