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

int N, M;
std::vector <int> edge[110000];
int s, t;
bool vis[110000];
std::vector <int> ex1, ex2;

void expand (int u, std::vector <int> &ex) {
	ex.push_back (u);
	for (int i : edge[u]) {
		if (vis[i] == false) {
			vis[i] = true;
			expand (i, ex);
			return;
		}
	}
	return;	
}

int main () {
	std::ios::sync_with_stdio (0);
	std::cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		int u, v;
		std::cin >> u >> v;
		edge[u].push_back (v);
		edge[v].push_back (u);
		s = u; t = v;
	}
	vis[s] = vis[t] = true;
	expand (s, ex1);
	expand (t, ex2);
	std::reverse (ex1.begin (), ex1.end ());
	std::cout << ex1.size () + ex2.size () << std::endl;
	for (int i : ex1) std::cout << i << " ";
	for (int i : ex2) std::cout << i << " ";	
}


Measured memory_bytes: 9592
#include<cstdio>
using namespace std;
int main()
{
	int k,a,b;
	scanf("%d",&k);
	scanf("%d%d",&a,&b);
	for(int i=a;i<=b;i++)
	{
		if(i%k==0)
		{
			printf("OK\n");
			return 0;
		}
	} 
	printf("NG\n");
	return 0;
} 


Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>

using namespace std;

typedef pair<long, tuple<long,long,long>> P;

int main() {
  long x,y,z,k;
  long a;
  vector<vector<long>> cake(3);

  cin >> x >> y >> z >> k;

  for (int i=0; i<x; i++) {
    cin >> a;
    cake[0].push_back(a);
  }
  sort(cake[0].rbegin(), cake[0].rend());

  for (int i=0; i<y; i++) {
    cin >> a;
    cake[1].push_back(a);
  }
  sort(cake[1].rbegin(), cake[1].rend());

  for (int i=0; i<y; i++) {
    cin >> a;
    cake[2].push_back(a);
  }
  sort(cake[2].rbegin(), cake[2].rend());

  priority_queue<P> ans;
  set<tuple<long,long,long>> used;
  used.insert(make_tuple(0,0,0));
  ans.push(P(cake[0][0] + cake[1][0] + cake[2][0], make_tuple(0,0,0)));

  for (int i=0; i<k; i++) {
    cout << ans.top().first << endl;;
    int xi,yi,zi;
    tie(xi,yi,zi) = ans.top().second;
    ans.pop();

    tuple<long, long, long> t;
    if (x-1 >= xi+1) {

      t = make_tuple(xi+1, yi, zi);
      auto it = used.find(t);
      if (it == used.end()) {
        used.insert(t);
        ans.push(P( cake[0][xi+1]+cake[1][yi]+cake[2][zi], t));
      }
    }

    if (y-1 >= yi+1) {
      t = make_tuple(xi, yi+1, zi);
      auto it = used.find(t);
      if (it == used.end()) {
        used.insert(t);
        ans.push(P( cake[0][xi]+cake[1][yi+1]+cake[2][zi], t));
      }
    }

    if (z-1 >= zi+1) {
      t = make_tuple(xi, yi, zi+1);
      auto it = used.find(t);
      if (it == used.end()) {
        used.insert(t);
        ans.push(P( cake[0][xi]+cake[1][yi]+cake[2][zi+1], t));
      }
    }
  }

}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <stdio.h>
#include <unistd.h>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#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
#define PI 3.14159265359

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int main() {
  int n;
  string s;
  cin >> n >> s;
  string origin = s;
  int kakko[2];
  kakko[0] = kakko[1] = 0;
  int left, right;
  left = right = 0;
  rep (i, s.size()) {
    if (s[i] == '(') {
      kakko[0]++;
    } else {
      if (kakko[0] > 0) kakko[0]--;
      else left++;
    }
  }
  right = kakko[0];
  rep (i, left) cout << '(';
  cout << s;
  rep (i, right) cout << ')';
  cout << endl;
  return 0;
}



Measured memory_bytes: 256
import kotlin.math.abs
import kotlin.math.floor
import kotlin.math.round
import kotlin.math.roundToInt

private class E {
    fun solve() {
        val n = nextInt()
        val k = nextInt()
        val a = Array(n) { nextInt() }

        var l = 1
        var r = a.max()!!
        while (r > l) {
            val m = (r + l) / 2
            var count = 0
            for (x in a) {
                if (x % m == 0) {
                    count += x / m - 1
                } else {
                    count += x / m
                }
            }
            if (count > k) {
                l = m + 1
            } else {
                r = m
            }
        }
        println(r)
    }

    var tokenBuffer = listOf<String>()
    var bufferPosition = 0

    private fun checkBuffer() {
        if (bufferPosition == tokenBuffer.size) {
            tokenBuffer = nextLine().split(" ")
            bufferPosition = 0
        }
    }

    fun nextLine() = readLine()!!
    fun nextInt(): Int {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toInt()
    }

    fun nextLong(): Long {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toLong()
    }

    fun nextDouble(): Double {
        checkBuffer()
        return tokenBuffer[bufferPosition++].toDouble()
    }

    fun nextToken(): String {
        checkBuffer()
        return tokenBuffer[bufferPosition++]
    }
}

fun main() {
    val reader = E().solve()

}


Measured memory_bytes: 66592
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

const int maxn = 1e5 + 100;
int a[maxn], b[maxn], c[maxn];
int cnt1[maxn],cnt2[maxn];
int main() {
	int n;
	cin >> n;
	int ans = 1;
	for (int i = 1; i <= n; i++) {
		if (i*i <= n) ans = i;
		else break;
	}
	cout << ans*ans << endl;
	//system("pause");

}

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

int main(void){
  int n , k;
  scanf("%d %d",&n ,&k);
  
  long long ans , count = 0 , count2 = 0;
  
  if(k%2 == 1){
    for(int i = 1;i <= n;i ++){
      if(i%k == 0){
        count ++;
      }
    }
    ans = pow(count,3);
  }

  else{
    for(int i = 1;i <= n;i ++){
      if(i%k == k/2){
        count ++;
      }
      else if(i%k == 0){
        count2 ++;
      }
    }
    ans = pow(count,3) + pow(count2,3);
  }

  printf("%lld\n",ans);

  return 0;
}

Measured memory_bytes: 2492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using piii = pair<pair<int, int>, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int N, K;
    cin >> N >> K;
    vector<bool> isok(N);
    for (int i = 0; i < K; ++i) {
        int d;
        cin >> d;
        for (int i = 0; i < d; ++i) {
            int A;
            cin >> A;
            A--;
            isok[A] = true;
        }
    }

    int cnt = 0;
    for (int i = 0; i < N; ++i)
        if (!isok[i])
            cnt++;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int input;
      cin >> input;
      
      int count=0;
      if(input%10==1) count++;
      if((input/10)%10==1) count++;
      if(input/100==1) count++;
      
      cout << count;
    }

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

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:i64,
        m:i64,
    }
    let (n,m) = (max(n,m),min(n,m));
    let ans = if n == 1 && m == 1 {
        1
    }  else if m == 1 {
        n - 2
    } else {
        (n-2)*(m-2)
    };
    println!("{}",ans);
}

Measured memory_bytes: 4352
using System;
using System.Linq;
class Program
{
    static void Main()
    {
        string[] s;
        s = Console.ReadLine().Split(' ');
        int n, w;
        n = int.Parse(s[0]);
        w = int.Parse(s[1]);
        int[][] vw = new int[n][];
        for (int i = 0; i < n; i++)
            vw[i] = Console.ReadLine().Split(' ').Select(p => int.Parse(p)).ToArray();
        int[,] dp = new int[n, w + 1];
        for (int j = 0; j <= w; j++)
            dp[0, j] = (vw[0][1] <= j) ? vw[0][0] : 0;
        for (int j = 1; j <= w; j++)
        {
            for (int i = 1; i < n; i++)
            {
                try
                {

                    dp[i, j] = Math.Max(dp[i - 1, j], dp[i - 1, j - vw[i][1]] + vw[i][0]);
                }
                catch
                {
                    dp[i, j] = dp[i - 1, j];
                }
            }
        }
        Console.WriteLine(dp[n - 1, w]);
    }
}


Measured memory_bytes: 13564
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const double EPS = 1e-7;
const long long mod = 1000000007 ;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define X real()
#define Y imag()
#define cross(a,b) (conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define dist(a,b) ( pow(a.X - b.X, 2) + pow( a.Y - b.Y, 2 ) )
typedef tuple <int, int, int> line;
typedef complex <double> point;
typedef vector <point> polygon;
ll nn, ww, w[1000000], v[1000000];
ll dp[100][100005];
ll solve(int idx, int weight)
{
    if( weight > ww )
        return -1e18;
    if( idx == nn )
        return 0;
    if( dp[idx][weight] != -1 )
        return dp[idx][weight];
    dp[idx][weight] = max( dp[idx][weight], v[idx] + solve( idx + 1, weight + w[idx] ) );
    dp[idx][weight] = max( dp[idx][weight], solve( idx + 1, weight ) );
    ///dp[idx][weight] = max( dp[idx][weight], w[idx] + solve( idx + 1, weight ) );
    return dp[idx][weight];
}
int main()
{
    Hello
    memset(dp, -1, sizeof dp);
    cin >> nn >> ww;
    for(int i = 0; i < nn; i++)
        cin >> w[i] >> v[i];
    cout << solve(0, 0);
    return 0;
}


Measured memory_bytes: 82176
import Data.Char
import Data.List
import qualified Data.ByteString.Char8 as B

main=B.interact$B.pack.show.f.unfoldr(B.readInt.B.dropWhile isSpace)
f (n:k:xs)
    | null mxs = pxs !! (k-1)
    | otherwise = a
    where
        (mxs,pxs) = span (<0) xs
        lm = length mxs
        ps = drop (max 0 (k-lm)) (0:take k pxs)
        as = zip ps $ drop (max 0 (lm-k)) $ map (0-) mxs
        a = minimum $ concatMap (\(a,b)->[a*2+b,a+b*2]) as


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

mod = 10**9 + 7

dp = [[0] * (4**3) for _ in range(n+1)]

for w in range(4**3):
    if (w // 16) % 4 == 0 and (w // 4) % 4 == 2 and w % 4 == 3:
        continue
    if (w // 16) % 4 == 0 and (w // 4) % 4 == 3 and w % 4 == 2:
        continue
    if (w // 16) % 4 == 2 and (w // 4) % 4 == 0 and w % 4 == 3:
        continue
    dp[3][w] = 1

for i in range(3, n):
    for w in range(4**3):
        for nw in range(4):
            if (w // 4) % 4 == 0 and w % 4 == 2 and nw == 3:
                continue
            if (w // 4) % 4 == 0 and w % 4 == 3 and nw == 2:
                continue
            if (w // 4) % 4 == 2 and w % 4 == 0 and nw == 3:
                continue
            if (w // 16) % 4 == 0 and (w // 4) % 4 == 2 and nw == 3:
                continue
            if (w // 16) % 4 == 0 and w % 4 == 2 and nw % 4 == 3:
                continue
            dp[i+1][(((w // 4) % 4) * 16 + (w % 4) * 4) + nw] += dp[i][w]
            dp[i+1][(((w // 4) % 4) * 16 + (w % 4) * 4) + nw] %= mod

ans = 0
for w in range(4**3):
    ans += dp[n][w]
    ans %= mod

print(ans)

Measured memory_bytes: 3188
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

d,t,s=rm()
if t*s>=d:
    print('Yes')
else:
    print('No')


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

string S,T;
int main(){
	cin >> S;
	cin >> T;
	string U = S;
	S += U;
	bool judge = false;
	for(int i=0;i<S.size();i++){
		int j = 0,k = i;
		while(j<T.size() && k<S.size()+i){
			if(T[j] == S[k]){
				j++;
				k++;
			}else break;
			if(j == T.size()) judge = true;
		}
	}
	if(judge) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

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

typedef long long ll;
typedef long double ld;

using namespace std;

const int maxn = 100*1000+10;
int n, ans;
pair <int, int> a[maxn];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i].first;
        a[i].second = i;
    }
    sort (a, a + n);
    for (int i = 0; i < n; i += 2)
    {
        if (a[i].second & 1)
            ans++;
    }
    cout << ans;
	return 0;
}

Measured memory_bytes: 1024
def Crane_and_Turtle():
    X, Y = map(int, input().split())

    turu = 2
    kame = 4

    k_num = int(Y / kame)

    while True:
        t_num = X - k_num

        asi = kame * k_num + turu * t_num

        if t_num >= 0 and k_num >= 0:       
            if asi > Y:
                k_num -= 1
            elif asi == Y:
                return 'Yes'
            elif asi < Y:
                return 'No'
        else:
            return 'No'

print(Crane_and_Turtle())

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

const ll p = 998244353;
const int M = 3e5+5;

ll n, k, a, b;
ll fact[M], invfact[M];

ll exp(ll x, ll k) {
	if (k == 0)
		return 1;
	if (k%2 == 1)
		return x*exp(x, k-1)%p;
	ll y = exp(x, k/2);
	return y*y%p;
}

ll inv(ll x) { return exp(x, p-2); }

ll comb(ll x, ll y) {
	if (x < 0 || y < 0 || x < y)
		return 0;
	return fact[x]*invfact[y]%p*invfact[x-y]%p;
}

int main() {
	cin >> n >> a >> b >> k;
	fact[0] = invfact[0] = 1;
	for (int i = 1; i < M; ++i) {
		fact[i] = i*fact[i-1]%p;
		invfact[i] = inv(fact[i]);
	}

	ll ans = 0;

	for (int i = 0; i <= n; ++i) {
		//how many a's used?
		if (k-a*i < 0)
			continue;
		if ((k-a*i)%b != 0)
			continue;
		ll t = (k-a*i)/b;
		ans = (ans + comb(n, i)*comb(n, t))%p;
	}

	cout << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
	using namespace std;
	typedef long long ll;
	#define pii pair<int,int>
	#define pll pair<ll,ll>
	#define pdd pair<double,double>
	#define X first
	#define Y second
	#define REP(i,a) for(int i=0;i<a;++i)
	#define REPP(i,a,b) for(int i=a;i<b;++i)
	#define FILL(a,x) memset(a,x,sizeof(a))
	#define	foreach( gg,itit )	for( typeof(gg.begin()) itit=gg.begin();itit!=gg.end();itit++ )
	#define	mp make_pair
	#define	pb push_back
	#define all(s) s.begin(),s.end()
	#define present(c,x) ((c).find(x) != (c).end())
	const double EPS = 1e-8;
	const int mod = 1e9+7;
	const int N = 1e6+10;
	const ll INF = 1e16;

	//#define DEBUG
	ll power(ll x,ll y){
	  ll t=1;
	  while(y>0){
	    if(y%2) y-=1,t=t*x%mod;
	    else y/=2,x=x*x%mod;
	  }
	  return t;
	}
	#ifdef DEBUG
	#define dprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
	#else
	#define dprintf(fmt,...)
	#endif


	ll a[N][2];
	int main(){
		int n; scanf("%d",&n);

		REP(i,n){
			ll x; scanf("%lld",&x);
			if(i==0){
				if(x){
					a[0][1]=(x-1)/2;
				}else{
					a[0][1]=-INF;
				}
				a[0][0]=x/2;
			}else{
				a[i][0]=a[i][1]=-INF;
				REP(j,2) REP(k,2){
					if(x>=j+k){
						a[i][k]=max(j+(x-j-k)/2+a[i-1][j],a[i][k]);
					}
				}
			}
			//printf("%lld %lld\n",a[i][0],a[i][1]); 
		}
		printf("%lld\n",max((ll)0,max(a[n-1][0],a[n-1][0])));
		return 0;
	}


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

int main(){
    string S,T;
    string divide[4]={"dream","dreamer","erase","eraser"};
    cin>>S;
    reverse(S.begin(),S.end());
    for(int i=0;i<4;i++)reverse(divide[i].begin(),divide[i].end());

    bool can=true;
    for(int i=0;i<S.size();){
        bool can2=false;
        for(int j=0;j<4;j++){
            string d=divide[j];
            if(S.substr(i,d.size())==d){
                can2=true;
                i+=d.size();
            }
        }
        if(!can2){
            can=false;
            break;
        }
    }
    if (can) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;


    return 0;
}

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

#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long 
#define ffor(i,a,b) for(ll i=(a);i<(ll)(b);++i)
#define rep(i, n) ffor(i,0,n)
#define All(obj) (obj).begin(),(obj).end()
#define INF ((ll)1e9+7)
#define c(a) cout<<a<<"\n";
using namespace std;

int main() {
	speed;
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0;
	rep(i, n+1) {
		int c = 0;
		int t = i;
		rep(j, 5) {
			c += t % 10;
			t /= 10;
		}
		if (a <= c && c <= b)ans += i;
	}
	c(ans);
	ed;
	return 0; 
}



Measured memory_bytes: 256
/**
 *      ABC 65 B
 *      author  : kyomukyomupurin
 *      created : 2018-09-05 20:12:07
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    int a[N + 10];
    for (int i = 1; i <= N; ++i) {
        cin >> a[i];
    }
    int count = 1;
    int flag = 1;

    for (int i = 0; i < N; ++i) {
        if (a[flag] == 2){
            cout << count << endl; return 0;
        }
        else {
            flag = a[flag]; ++count;
        }
    }

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 640
import math  # noqa
import bisect  # noqa
import queue  # noqa


if __name__ == '__main__':
    N, K = map(int, input().split())

    MOD = 1_000_000_007
    ans = 0
    for k in range(K, N + 2):
        upper = ((N + N - k + 1) * k) // 2
        lower = ((k - 1) * k) // 2
        ans += upper - lower + 1
        ans %= MOD

    print(ans)


Measured memory_bytes: 85900
#include <stdio.h>

int main(void)
{
	int n, x, m;
	int sum, count, small;
	int i;

	scanf("%d %d", &n, &x);

	sum = 0;
	small = 1001;
	i = 0;
	while (i < n)
	{
		scanf("%d\n", &m);
		sum += m;
		if (m < small)
		{
			small = m;
		}
		i++;
	}

	count = n;
	if (small < (x - sum))
	{
		count += (x - sum) / small;
	}

	printf("%d", count);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>

using namespace std;

int main()
{
	int n,x;
	vector<int> len;

	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		len.push_back(x);
		cin>>x;
		len.push_back(x);
		cin>>x;
		len.push_back(x);

		sort(len.begin(),len.end());
		if(len[0]*len[0]+len[1]*len[1]==len[2]*len[2]) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;

		len.clear();
	}

}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MS2020B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] ABC = Console.ReadLine().Split(' ');
            int A = int.Parse(ABC[0]);
            int B = int.Parse(ABC[1]);
            int C = int.Parse(ABC[2]);
            int K = int.Parse(Console.ReadLine());
            int count = 0;
            while (A >= B)
            {
                B *= 2;
                count += 1;
            }
            while (B >= C)
            {
                C *= 2;
                count += 1;
            }
            if (count <= K)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


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

int main() {
    int n;
    cin >> n;
    vector<int> w(n);
    rep(i,n) cin >> w[i];
    int ans = accumulate(w.begin(), w.end(), 0);
    rep(i,n) {
        int s1 = 0, s2 = 0;
        rep(j,i) s1 += w[j];
        for (int j = i; j < n; j++) s2 += w[j];
        ans = min(ans,abs(s1-s2));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	boolean[] p = new boolean[50000];
	setp(p);
	while(kbd.hasNext()){
	    int n= kbd.nextInt();
	    if(n!=0) solve(p, n);
	}
    }

    static void solve(boolean[] p, int n){
	int ans=0, i, j;
	for(i=n-1; i>=2; i--){
	    if(p[i] && p[n-i]) {
		ans++;
		//System.out.println(i+" "+(n-i));
	    }
	}
	if(ans%2==1)
	    System.out.println(ans/2+1);
	else
	    System.out.println(ans/2);
    }

    static void setp(boolean[] p){
	Arrays.fill(p, true);
	int i, j;
	p[0] = false;
	p[1] = false;
	for(i=2; i<p.length; i++){
	    for(j=i+i; j<p.length; j+=i){
		if(p[i]) p[j] = false;
	    }
	}
    }
}

Measured memory_bytes: 33900
<?php
  
 fscanf(STDIN,"%d",$n);
$a = explode(" ",trim(fgets(STDIN)));


$hugou=1;
$diff=0;
rsort($a);



for($i=0;$i<$n;$i++){
  $diff += $a[$i]*$hugou;
  $hugou = $hugou*-1;
 }
   

echo $diff."\n";


 

Measured memory_bytes: 4728
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
  int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;

  int ans = 2e9;
  for (int k = 0; k <= max(x, y); k++) {
    int i = max(0, x - k);
    int j = max(0, y - k);
    ans = min(ans, i * a + j * b + k * c * 2);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAXN 200005

int main()
{
    long long i, N, K, cur, ans, a[MAXN];
    scanf("%lld%lld", &N, &K);
    for(i = 0; i < N; i++)
        scanf("%lld", a + i);
    for(i = 0; i < N; i++)
        a[i]++;
    for(ans = 0, i = 0; i < K; i++)
       ans += a[i];
    for(cur = ans, i = 0; (i + K) < N ; i++)
    {
      cur = cur + a[i + K] - a[i];
      ans = ans > cur ? ans : cur;
    }
    ans & 1 ? printf("%lld.500000000000\n", ans >> 1) : printf("%lld.000000000000\n", ans >> 1);
    return 0;
}

Measured memory_bytes: 1664
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    S = input().strip()

    D = {0: 1}
    ss = 0
    r = 1
    for s in S[::-1]:
        ss += int(s) * r
        ss %= 2019
        D[ss] = D.setdefault(ss, 0) + 1
        r *= 10
        r %= 2019

    print(sum(v * (v - 1) // 2 for v in D.values()))


if __name__ == "__main__":
    main()


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



int main(void){
    int n,x;
    cin >> n >> x;
    int l[n];
    int d=0;
    rep(i,n){
        int x;
        cin >> x;
        l[i] = x;
    }
    int ans=1;
    rep(i,n){
        d = d+l[i];
        if(d > x){
            break;
        }
      	ans++;
    }
    
    cout  << ans ;
    
    
    return 0;
}























Measured memory_bytes: 256
n = gets.to_i
array = gets.split.map(&:to_i).reverse

i = 0

(n-1).times {
    
    if array[i]>= array[i+1]
        
        
    elsif array[i] >= array[i+1]-1
        array[i+1]-=1
    
    else
        puts "No"
        exit
    end
    
    i+=1
}


puts "Yes"

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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cout << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;

LL a, b, x;

LL f(LL n)
{
	if(n < 0) return 0;
	return n / x + 1;
}

LL divisors()
{
	return f(b) - f(a - 1);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	//freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stderr);
#endif
	cin >> a >> b >> x;

	cout << divisors() << endl;

	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) = println(run {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val ab = (1..m).map { readLine()!!.split(" ").map { it.toInt() } }

    ab.flatten().groupBy { it }.mapValues { it.value.size }.let { counter ->
        (1..n).map { counter.getOrElse(it){0} }.joinToString("\n")
    }

})


Measured memory_bytes: 38040
#include<stdio.h>
#define MAX 100005
#define NIL -1

void print(int);
int rec(int,int);

struct Node{
  int p,l,r;
};


int n,B[MAX];
struct Node A[MAX];


int main(){
  int i,j,a,b,c,d,e;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    A[i].p = NIL;
    A[i].l = NIL;
    A[i].r = NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d %d",&b,&a);
    for(j=0;j<a;j++){
      scanf("%d",&c);
      if(j==0){
	A[b].l = c;
      }
      else A[d].r = c;
      d = c;
      A[c].p = b;
    }
  }
  for(i=0;i<n;i++){
    if(A[i].p == NIL){
      e = i;
    }
  }
  rec(e,0);
  for(i=0;i<n;i++){
    print(i);

  }
  return 0;
}

void print(int s){
  int i,c;
  printf("node %d: ",s);
  printf("parent = %d, ",A[s].p);
  printf("depth = %d, ",B[s]);
  if(A[s].p == NIL){
    printf("root, ");
  }
  else if(A[s].l == NIL){
    printf("leaf, ");
  }
  else printf("internal node, ");

  printf("[");

  for(i = 0,c = A[s].l;c != NIL;i++,c = A[c].r){
    if(i>0){
      printf(", ");
    }
    printf("%d",c);
  }
  printf("]\n");
}

int rec(int t,int q){
  B[t] = q;
  if(A[t].r != NIL)rec(A[t].r,q);
  if(A[t].l != NIL)rec(A[t].l,q+1);
}



Measured memory_bytes: 6468
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 10 ** 9 + 7
N = 2 * 10 ** 6 + 10 # N は必要分だけ用意する
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用
 
for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

k=int(input())
s=input()
lens=len(s)
mod=10**9+7
ans=0

now=1

for i in range(k+1):
    ans+=pow(25,i,mod)*pow(26,k-i,mod)*cmb(lens+i-1,lens-1,mod)
    ans=ans%mod

print(ans)

Measured memory_bytes: 186312
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin>>n;
    int room[4][3][10]={};
    int b,f,r,v;
    for(int i=1;i<=n;i++){
        cin>>b>>f>>r>>v;
        room[b-1][f-1][r-1]+=v;
    }
    for(int i=0;i<=3;i++){
        for(int j=0;j<=2;j++){
            for(int k=0;k<=9;k++){
                cout<<" "<<room[i][j][k];
            }
            cout<<endl;
        }
        if(i==3)break;
        for(int k=1;k<=20;k++){
            cout<<"#";
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    string s,t;
    cin>>s>>t;
    ll n=s.size(),m=t.size();

    vector<vector<int>> ccnt(26,vector<int>(n+1,0));
    for(int j=0; j<26; j++){
        for(int i=n-1; i>=0; i--){
            ccnt[j][i]=ccnt[j][i+1];
            if(s[i]==(char)(j+'a')) ccnt[j][i]--;
        }
    }

    map<char,int> cmap;
    for(int i=0; i<n; i++) cmap[s[i]]++;
    for(int i=0; i<m; i++){
        if(cmap[t[i]]==0){
            cout<<-1<<endl;
            return 0;
        }
    }

    ll itr=0;
    ll loop=0;
    for(int i=0; i<m; i++){
        if(ccnt[t[i]-'a'][itr]<0){
            auto jtr=lower_bound(ccnt[t[i]-'a'].begin()+itr,ccnt[t[i]-'a'].end(),ccnt[t[i]-'a'][itr]+1);
            itr=jtr-ccnt[t[i]-'a'].begin();
            
        }else{
            loop++;
            itr=0;
            auto jtr=lower_bound(ccnt[t[i]-'a'].begin()+itr,ccnt[t[i]-'a'].end(),ccnt[t[i]-'a'][itr]+1);
            itr=jtr-ccnt[t[i]-'a'].begin();
        }
    }
    ll ans=loop*n;
    ans+=itr;
    cout<<ans<<endl;
}

Measured memory_bytes: 11136
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	public static void main(String[] a){

		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

		String tmpString = null;

		try {
			if(null != (tmpString = bf.readLine())){
				String[] tmp = tmpString.split(" ");
				int count = tmp.length;
				int[] numbers = new int[count];
				for(int i = 0; i < count; i++){
					numbers[i] = Integer.parseInt(tmp[i]);
				}

				int[] ans = quickSort(numbers);
				for(int i = 0; i < count; i++){
					if(i != 0)System.out.print(" ");
					System.out.print(ans[i]);
				}
				System.out.println("");
			}
		} catch (IOException e) {
		}
	}

	private static int[] quickSort(int[] numbers){
		int count = numbers.length;
		for(int i = 0; i < count - 1; i++){
			for(int j = i + 1; j < count; j++){
				if(numbers[i] < numbers[j]){
					int tmp = numbers[i];
					numbers[i] = numbers[j];
					numbers[j] = tmp;
				}
			}

		}
		return numbers;
	}
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        string S, T; cin >> S >> T;
        vector<int> SS(S.size() + 1), TT(T.size() + 1);
        rep(i, S.size()) {
            SS[i + 1] = SS[i] + (S[i] == 'A' ? 1 : 2);
        }
        rep(i, T.size()) {
            TT[i + 1] = TT[i] + (T[i] == 'A' ? 1 : 2);
        }
        int Q; cin >> Q;
        rep(i, Q) {
            int a, b ,c , d; cin >> a >> b >> c >> d;
            cout << (((SS[b] - SS[a - 1]) % 3 == (TT[d] - TT[c - 1]) % 3) ? "YES" : "NO") << endl;
        }
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 1744
#include<iostream>

using namespace std;

int main(){
    
    int n, m, x, y;
    int max_x, min_y;

    cin >> n >> m >> x >> y;

    for(int i = 0; i < n; i++){
        int tmp;
        cin >> tmp;
        if(i == 0){
            max_x = tmp;
        }else{
            if(max_x < tmp){
                max_x = tmp;
            }
        }
    }

    for(int i = 0; i < m; i++){
        int tmp;
        cin >> tmp;
        if(i == 0){
            min_y = tmp;
        }else{
            if(min_y > tmp){
                min_y = tmp;
            }
        }
    }

    if(max_x < min_y && max_x < y && min_y > x){
        cout << "No War" << endl;
    }else{
        cout << "War" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
# aの最大公約数を求めればいい
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
# n個の数字の最大公約数
import functools
def gcdn(nums):
    return functools.reduce(gcd, nums)

print(gcdn(a))

Measured memory_bytes: 14224
#include <cstdio>

using namespace std;

int search(int S[], int key, int left, int right) {

  while ( left < right ) {
    int mid = (left + right) / 2;
    
    if ( S[mid] == key ) {
      return true;
    }
    else if ( S[mid] < key ) {
      left = mid + 1;
    }
    else if ( key < S[mid] ) {
      right = mid;
    }
  }
  return false;
}

int main() {
  int n, S[100000+5], q, key, left = 0, right, ans = 0;

  scanf("%d", &n);
  for (int i=0; i < n; i++) {
    scanf("%d", &S[i]);
  }
  right = n;
  
  scanf("%d", &q);
  for (int i=0; i < q; i++) {
    scanf("%d", &key);
    if ( search(S, key, left, right) ) {
      ans++;
    };
  }

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



Measured memory_bytes: 3088
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] array = new long[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextLong();
        }
        
        long now = array[0];
        long add = 0;
        for (int i = 1; i < n; i++) {
            if (array[i] < now) {
                add += now - array[i];
            } else {
                now = array[i];
            }
        }
        
        System.out.println(add);
    }
}


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

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

      for(int i = 1;i <= 9;i++){
            for(int j = 1; j <= 9;j++){
                  if(i*j == N){
                        cout << "Yes" << endl;
                        return 0;
                  }
            }
      }
      cout << "No" << endl;
}


Measured memory_bytes: 256
import itertools

def input_ints():
    return list(map(int, input().split()))

def output_list(v):
    print(' '.join(str(x) for x in v))

def main():
    n, l = input_ints()
    a = [x for x in range(l, l + n)]
    ans = sum(a)
    if a[-1] < 0:
        ans -= a[-1]
    if a[0] > 0:
        ans -= a[0]
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  string x,y;
  cin>>x>>y;
  int n = sz(x);
  vi c(26,-1);
  rep(i,n){
    if(c[x[i]-'a'] == -1 || c[x[i]-'a'] == (y[i]-'a')) c[x[i]-'a'] = y[i]-'a';
    else {
      cout<<"No"<<endl;
      return 0;
    }
  }
  swap(x,y);
  c = vi(26,-1);
  rep(i,n){
    if(c[x[i]-'a'] == -1 || c[x[i]-'a'] == (y[i]-'a')) c[x[i]-'a'] = y[i]-'a';
    else {
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



i64 a,b;
void solve(){
	cin >> a >> b;
	
	i64 cnt = 0;
	for(i64 i = a; i <= b; i*=2){
		cnt++;
	}
	cout << cnt << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 256
function Main(input){
	var xs = input.trim().split(' ').map(v=>parseInt(v,10));
	var result = xs.reduce(function (previous, current, index, xs) {
    return previous + current;
    });
    console.log(Math.ceil(result/xs.length)); 
}
Main(require('fs').readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 7372
using System;
class Program
{
    static void Main(string[] args)
    {
        string input = Console.ReadLine();
        // Nを数値化
        int N = int.Parse(input);
        int odd;
        if (N % 2 == 0)
        {
            odd = N / 2;
        }
        else
        {
            odd = (N / 2) + 1;
        }
        double ans = (double)odd / (double)N;
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
#pragma GCC target("avx2")
#pragma GCC optimize("O3", "unroll-loops")

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

#define int long long

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define RANDOM() random_device __rd; \
                 mt19937 __gen = mt19937(__rd()); \
                 uniform_int_distribution<int> __dis(0, MAXN); \
                 auto rnd = bind(__dis, __gen);

const int MAXN = 1E6;

int32_t main() {
    fastIO();
    
    int n, tmp;
    bool arr[3][3];
    map<int, int> tab;
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            arr[i][j] = 0;
            cin >> tmp;
            tab[tmp] = 3*i + j + 1;
        }
    }
    
    cin >> n;
    while (n--) {
        cin >> tmp;
        if (tab[tmp]) arr[(tab[tmp]-1) / 3][(tab[tmp]-1) % 3] = 1;
    }
    
    for (int i = 0; i < 3; ++i) {
        int cnt = 0;
        for (int j = 0; j < 3; ++j) cnt += arr[i][j] == 1;
        if (cnt == 3) return cout << "Yes", 0;
    }
    
    for (int i = 0; i < 3; ++i) {
        int cnt = 0;
        for (int j = 0; j < 3; ++j) cnt += arr[j][i] == 1;
        if (cnt == 3) return cout << "Yes", 0;
    }
    
    if (arr[0][0] and arr[1][1] and arr[2][2]) return cout << "Yes", 0;
    if (arr[0][2] and arr[1][1] and arr[2][0]) return cout << "Yes", 0;
    
    return cout << "No", 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N,M,L,S,T;
int D[300][300];
int J[16],E[16];
int dp[1<<16][16];
main()
{
	while(cin>>N>>M>>L>>S>>T,N)
	{
		S--;
		for(int i=0;i<N;i++)for(int j=0;j<N;j++)
		{
			D[i][j]=i==j?0:1e9;
		}
		for(int i=0;i<M;i++)
		{
			int a,b,c;cin>>a>>b>>c;a--,b--;
			D[a][b]=D[b][a]=c;
		}
		for(int i=0;i<L;i++)
		{
			cin>>J[i]>>E[i];
			J[i]--;
		}
		for(int k=0;k<N;k++)for(int i=0;i<N;i++)for(int j=0;j<N;j++)
		{
			D[i][j]=min(D[i][j],D[i][k]+D[k][j]);
		}
		for(int i=0;i<1<<L;i++)for(int j=0;j<L;j++)dp[i][j]=1e9;
		for(int i=0;i<L;i++)
		{
			dp[1<<i][i]=D[S][J[i]]+E[i];
		}
		int ans=0;
		for(int i=1;i<1<<L;i++)
		{
			for(int j=0;j<L;j++)
			{
				if(!(i>>j&1))continue;
				if(dp[i][j]+D[J[j]][S]<=T)ans=max(ans,__builtin_popcount(i));
				for(int k=0;k<L;k++)
				{
					if(i>>k&1)continue;
					dp[i|1<<k][k]=min(dp[i|1<<k][k],dp[i][j]+D[J[j]][J[k]]+E[k]);
				}
			}
		}
		cout<<ans<<endl;
	}
}



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

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n=nxtl(),k=nxtl();
    cout<<min({n,n%k,k-n%k})<<endl;
   
    
    return 0;   
}




 
 


Measured memory_bytes: 256
open Printf open Scanf
open Array

let count_substr s t =
  (Str.split (Str.regexp_string t) ("_" ^ s ^ "_")
  |> List.length) - 1

let () = scanf " %d" @@ fun n ->
  let arr = init n (fun _ -> scanf " %s" @@ fun s -> s)
  in
  let kba,kbx,kxa,kab = ref 0,ref 0,ref 0,ref 0 in
  iter (fun s ->
    let bx = s.[0] = 'B' in
    let xa = s.[String.length s-1] = 'A' in
    let ba = bx && xa in
    if ba then incr kba
    else if bx then incr kbx
    else if xa then incr kxa;
    kab := !kab + count_substr s "AB"
  ) arr;
  let kba,kbx,kxa,kab = !kba,!kbx,!kxa,!kab in
  print_int @@ kab +
    if kba >= 1 then (
      let pair_ba = kba - 1 in
      let add,kbx =
        if kbx > 0 then 1,kbx-1 else 0,kbx in
      let add,kxa =
        if kxa > 0 then add+1,kxa-1 else add,kxa in
      pair_ba + add + min kbx kxa
    ) else
      min kbx kxa





Measured memory_bytes: 4864
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

mod_list = []

a_mod = a % 10
if a_mod == 0:
    a_total = a
else:
    a_total = a + (10 - a_mod)
    mod_list.append(a_mod)

b_mod = b % 10
if b_mod == 0:
    b_total = b
else:
    b_total = b + (10 - b_mod)
    mod_list.append(b_mod)

c_mod = c % 10
if c_mod == 0:
    c_total = c
else:
    c_total = c + (10 - c_mod)
    mod_list.append(c_mod)

d_mod = d % 10
if d_mod == 0:
    d_total = d
else:
    d_total = d + (10 - d_mod)
    mod_list.append(d_mod)

e_mod = e % 10
if e_mod == 0:
    e_total = e
else:
    e_total = e + (10 - e_mod)
    mod_list.append(e_mod)

min_mod = 0
if len(mod_list) != 0:
    min_mod = min(mod_list)

if min_mod == 0:
    cut_time = 0
else:
    cut_time = 10 - min(mod_list)

print(a_total + b_total + c_total + d_total + e_total - cut_time)

Measured memory_bytes: 3064
#include <iostream>

int main (){
    int N;
    std::cin >> N;
    int ac =0,wa=0,tle=0,re=0;
    
    for (int i=0;i<N;i++){
        std::string s;
        std::cin >> s;
        if (s=="AC"){
            ac++;
        }
        else if (s=="WA"){
            wa++;
        }
        else if (s=="TLE"){
            tle++;
        }
        else{
            re++;
        }

    }

    std::cout << "AC x " << ac << std::endl;
    std::cout << "WA x " << wa << std::endl;
    std::cout << "TLE x " << tle << std::endl;
    std::cout << "RE x " << re << std::endl;

}


Measured memory_bytes: 3644
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String T = sc.next();
    int ans = 0;
    for (int i=0;i<3;i++){
      if (S.substring(i,i+1).equals(T.substring(i,i+1))){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
using namespace std;
int main()
{
    char s[5000];
    long long n,i,j,k,total=0,red[5000]={0},green[5000]={0},blue[5000]={0},r=0,g=0,b=0,x,y;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>s[i];
        if(s[i]=='R')
        {
            r++;
            red[i]=red[i-1]+1;
            blue[i]=blue[i-1];
            green[i]=green[i-1];
        }
        else if(s[i]=='G')
        {
            g++;
            green[i]=green[i-1]+1;
            red[i]=red[i-1];
            blue[i]=blue[i-1];
        }
        else if(s[i]=='B')
        {
            b++;
            blue[i]=blue[i-1]+1;
            red[i]=red[i-1];
            green[i]=green[i-1];
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {          
            if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R'))
            {
                x=b-blue[j];
                y=(j-i)+j;
                if(s[y]=='B'&&x>0&&y<=n)
                {
                    x--;
                }
                total+=x;
            }
            else if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R'))
            {
                x=g-green[j];
                y=(j-i)+j;
                if(s[y]=='G'&&x>0&&y<=n)
                {
                    x--;
                }
                total+=x;
            }
            else if((s[i]=='B'&&s[j]=='G')||(s[i]=='G'&&s[j]=='B'))
            {
                x=r-red[j];
                y=(j-i)+j;
                if(s[y]=='R'&&x>0&&y<=n)
                {
                    x--;
                }
                total+=x;
            }
        }
    }
    cout<<total<<endl;
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

int main() {
  int n;
  ll d;
  cin >> n >> d;
  int res = 0;
  repi(n) {
    ll x, y;
    cin >> x >> y;
    if (x * x + y * y <= d * d) res++;
  }
  cout << res << endl;
}


Measured memory_bytes: 3620