akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define LL long long

using namespace std;

int main(){
	int N, W;
	int A[105], B[105];
	LL dp[100005];
	
	scanf("%d%d",&N,&W);
	for (int i=0;i<N;i++) scanf("%d%d",A+i,B+i);
	
	for (int i=1;i<=N*1000;i++) dp[i]=-1;
	dp[0]=0;
	
	for (int i=0;i<N;i++){
		for (int j=N*1000;j>=B[i];j--){
			if (dp[j-B[i]]==-1) continue;
			if (dp[j-B[i]] + A[i] > W) continue;
			if (dp[j]==-1) dp[j] = dp[j-B[i]] + A[i];
			else dp[j] = min(dp[j],dp[j-B[i]] + A[i]); 
		}
	}
	
	for (int i=N*1000;i>=0;i--){
		if (dp[i]!=-1){
			printf("%d\n",i);
			break;
		}
	}
	
	return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}

const long long INF = 1LL << 60;

int N;
long long h[100010];

long long dp[100010];

int main()
{
    int N;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        cin >> h[i];
    }

    for (int i = 0; i < 100010; i++)
    {
        dp[i] = INF;
    }

    dp[0] = 0;

    for (int i = 1; i < N; i++)
    {
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1)
        {
            chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
        }
    }

    cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1792
import java.util.Scanner;
import java.io.PrintWriter;

class Main {
    static int countChangingToAnaglam(String s) {
        int left = 0;
        int right = s.length() - 1;
        char[] sChar = s.toCharArray();
        int count = 0;
        while (left < right) {
            if (sChar[left] != sChar[right]) count ++;
            left ++;
            right --;
        }
        return count;
    }


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        String s = sc.next();

        out.println(countChangingToAnaglam(s));
        out.flush();
    }
}


Measured memory_bytes: 23764
/* ex2_3
   kohei_suzuki */

#include <stdio.h>
int main(void){
    int N; //マス目
    int A; //白のマス数

    scanf("%d", &N);//入力受取
    scanf("%d", &A);//入力受取

    if(1<=N && N<=100 && 0<=A && A<=N*N){
        printf("%d", N*N-A);
    }
    return 0;
}

Measured memory_bytes: 128
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

long long gcd(long long a, long long b) {
	long long r = -1;
	if (a < b) {
		swap(a, b);
	}
	while (r != 0) {
		r = a % b;
		if (r == 0) {
			return b;
		}
		else {
			a = b;
			b = r;
		}
	}
}

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b) {
		cout << c << endl;
	}
	else if (b == c) {
		cout << a << endl;
	}
	else {
		cout << b << endl;
	}
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7



def solve(n, k):
    if n % k == 0:
        return n // k
    diff = (n // k) + 1
    target = n - n % k
    if (n - target) % diff == 0:
        return solve(target, k)
    n -= -((-(n - target)) // diff) * diff
    return solve(n, k)


n = I()
ret = 0
for i in range(n):
    a, k = LI()
    ret ^= solve(a, k)

print("Takahashi" if ret else "Aoki")

Measured memory_bytes: 109864
#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define D                double
#define F                first
#define S                second
#define pb               push_back
#define pf               push_front
#define MP               make_pair
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define it(it,mp)        for(auto it=mp.begin() ; it!=mp.end() ; it++)
#define IOS              ios_base :: sync_with_stdio(false); cin.tie(NULL);
const int N = 1e5 + 5;
const int inf = 1e9 + 1;
const double eps = 1e-15;
const double EPS = 1e-9;
const double PI = acos(-1.0);
typedef long long int                   ll;
typedef pair<int,int>                   PII;
int minCoins(int coins[], int m, int V)
{

    int table[V+1];

    table[0] = 0;
    for (int i=1; i<=V; i++)
        table[i] = INT_MAX;


    for (int i=1; i<=V; i++)
    {
        for (int j=0; j<m; j++)
          if (coins[j] <= i)
          {
              int sub_res = table[i-coins[j]];
              if (sub_res != INT_MAX && sub_res + 1 < table[i])
                  table[i] = sub_res + 1;
          }
    }
    return table[V];
}
int coins[]= {59049 , 46656,7776,6561,1296,729,216,81,36,9,6,1} ;
int main()
{
    IOS
    // READ("test.txt");
    //WRITE("");


    int sz = sizeof(coins)/sizeof(int) ;
    int need ;
    cin >> need;
    cout<< minCoins(coins,sz,need)<<endl;
}



Measured memory_bytes: 640
<?php
list($n) = ints();
list($x) = strs();
$pcx = popcount($x);
$mod2[0][$pcx + 1] = 1 % ($pcx + 1);
if ($pcx > 1) $mod2[0][$pcx - 1] = 1;
for ($i = 1; $i < $n; ++$i) {
    $mod2[$i][$pcx + 1] = $mod2[$i - 1][$pcx + 1] * 2 % ($pcx + 1);
    if ($pcx > 1) $mod2[$i][$pcx - 1] = $mod2[$i - 1][$pcx - 1] * 2 % ($pcx - 1);
}
$xmodp = f($x, $pcx + 1);
$xmodm = $pcx > 1 ? f($x, $pcx - 1) : 0;
for ($i = 0; $i < $n; ++$i) {
    if ($x[$i] === '0') {
        $xt = ($xmodp + $mod2[$n - 1 - $i][$pcx + 1]) % ($pcx + 1);
    } else {
        if ($pcx <= 1) {
            $ans[] = 0;
            continue;
        }
        $xt = ($xmodm - $mod2[$n - 1 - $i][$pcx - 1] + ($pcx - 1)) % ($pcx - 1);
    }
    $ans[] = f2($xt) + 1;
}
echo implode(PHP_EOL, $ans);
function f($x, $pc)
{
    global $n, $mod2;
    if ($pc === 0) return 0;
    $mod = 0;
    for ($i = 0; $i < $n; ++$i)
        if ($x[$i] === '1') $mod = ($mod2[$n - 1 - $i][$pc] + $mod) % $pc;
    return $mod;
}
function f2($n)
{
    if ($n === 0) return 0;
    return 1 + f2($n % popcount(decbin($n)));
}
function popcount($x)
{
    $res = 0;
    for ($i = 0; $i < strlen($x); ++$i)
        if ($x[$i] === '1') ++$res;
    return $res;
}
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 106424
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>

#define repeat(i,n) for (long long i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i] << '\n'
#define debugArrayP(x,n) for(long long i = 0; (i) < (n); ++ (i)) cerr << #x << "[" << i << "]: " << x[i].first<< " " << x[i].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = INT_MAX;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int A,B;cin>>A>>B;
  vector<vll> d(A,vll(B));
  repeat(i,A){
    repeat(j,B){
      cin>>d[i][j];
    }
  }
  vector<vll> f(110,vll(110,0));
  repeat(a,101){
    repeat(b,101){
      repeat(x,A){
        repeat(y,B){
          f[a][b]=max(f[a][b],d[x][y]-a*(x+1)-b*(y+1));
        }
      }
    }
  }
  vector<vll> D(A,vll(B,INF));
  bool isok=true;
  repeat(x,A){
    repeat(y,B){
      repeat(a,101){
        repeat(b,101){
          D[x][y]=min(D[x][y],a*(x+1)+b*(y+1)+f[a][b]);
        }
      }
      isok &= D[x][y]==d[x][y];
    }
  }
  if(!isok){
    cout<<"Impossible"<<endl;
    return 0;
  }
  cout<<"Possible"<<endl;
  cout << 202 << " " << 200+101*101 << endl;
  repeat(i,100){
    cout << i+1 << " " << i+2 << " X" << endl;
  }
  repeat(i,100){
    cout << i+102 << " " << i+103 << " Y" << endl;
  }
  repeat(i,101){
    repeat(j,101){
      cout << i+1 << " " << 202-j << " "<< f[i][j] << endl;
    }
  }
  cout << "1 202" << endl;
  return 0;
}


Measured memory_bytes: 512
/*package whatever //do not write package name here */
import java.util.*;
import java.io.*;

class Main {
	public static void main (String[] args) {
// 		System.out.println("GfG!");
		Scanner input=new Scanner(System.in);
		String S=input.nextLine();
		if(S.equals("ABC"))
		    System.out.println("ARC");
		else
		    System.out.println("ABC");
		input.close();
		
	}
}

Measured memory_bytes: 35780
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
//#define int long long
#define endl '\n'
#define INF 1000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

int mp[67108864];

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

	string s;
	cin >> s;
	int n = s.size();
	int tmp = 0;
	vector<int> sum(n + 1);
	rep(i, n) {
		tmp ^= (1 << (s[i] - 'a'));
		sum[i + 1] = tmp;
	}
	vector<int> ans(n + 1, INF); ans[0] = 0;
	rep(i, n) {
		rep(j, 26) {
			if ((sum[i + 1] ^ (1 << j)) == 0 || mp[sum[i + 1] ^ (1 << j)] != 0) {
				chmin(ans[i + 1], mp[sum[i + 1] ^ (1 << j)] + 1);
			}
		}
		if (sum[i + 1] == 0 || mp[sum[i + 1]] != 0) chmin(ans[i + 1], mp[sum[i + 1]] + 1);
		if (sum[i + 1] != 0) {
			if (mp[sum[i + 1]]) chmin(mp[sum[i + 1]], ans[i + 1]);
			else mp[sum[i + 1]] = ans[i + 1];
		}
	}
	cout << ans[n] << endl;
}

Measured memory_bytes: 263956
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;

#define INF (10000000)

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

    vector<int> L;

    for(int i=0; i<N; ++i) {
        int temp;
        cin >> temp;
        if(i!=0) temp+=L[i-1];
        L.push_back(temp);
    }

    pair<int,int> dp[N][N];

    for(int i=1; i<N; ++i) { // initialize ... divide into 2 parts / i...last index
        int mx=INF, mn=-1, gap=INF;
        for(int j=0; j<N-1; ++j) {
            int temp=abs(L[i]-2*L[j]); // when cut after index-j
            if(gap>temp) { // compare gap
                mx=max(L[i]-L[j],L[j]); //update
                mn=min(L[i]-L[j],L[j]);
                gap=temp;
            }
        }
        dp[1][i].first=mx;
        dp[1][i].second=mn;
    }

    for(int i=2; i<N; ++i) { // i... number of divides
        for(int j=1; j<N; ++j) { // j... last index
            int mx=INF, mn=-1, gap=INF;
            for(int k=1; j-k>=i-1; ++k) { // k...add new section to i-1 divides
                int temp=abs(L[j]-L[j-k]);
                if(max(dp[i-1][j-k].first,temp)-min(dp[i-1][j-k].second,temp)<gap) {
                    mx=max(dp[i-1][j-k].first,temp);
                    mn=min(dp[i-1][j-k].second,temp);
                    gap=mx-mn;
                }
            }
            dp[i][j].first=mx;
            dp[i][j].second=mn;
        }
    }

    int ans=10000000;

    for(int i=1; i<N; ++i) {
        ans=min(ans,dp[i][N-1].first-dp[i][N-1].second);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;
  string s,t;cin >> s >> t;
  for(int i=0;i<n*2;i++){
    if(i%2==0){
      cout << s[i/2];
    }
    else{
      cout << t[i/2];
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for(int i=0;i<(int)(n);++i)
#define FOR(i, b, n)  for(int i=b;i<(n);++i)
#define ALL(c) (c).begin(),(c).end()
#define SS size()
#define PB push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

template<typename T, typename U> static void AMIN(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void AMAX(T &x, U y) { if (x < y) x = y; }

template <typename T> void print(T& w) {
    for(auto e : w) cout << e << ", ";
    cout << endl;
}


int main() {
	ios::sync_with_stdio(0);
	vi bb; int amax = 0; 
	int n, h; 
	cin >> n >> h; 
	REP(i,n) {
		int a, b; cin >> a >> b; 
		bb.PB(b); 
		AMAX(amax, a); 
	}
	sort(ALL(bb));
	reverse(ALL(bb));
	int res = 0; 
	for(int b : bb) {
		if (b<amax || h<=0) break; 
		++res; 
		h -= b;
	}
	if (h>0) res += (h + amax - 1) / amax; 
	cout << res << endl;
}


Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <algorithm>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
using namespace std;

const int MOD=1e9+7;
const int N=1e5+7;

int w[105];
int v[105];
int sol[105][N];


int32_t main()
{
	IOS;
	int n,W;
	cin>>n>>W;
	for (int i = 1; i <= n ; ++i)
	{
		cin>>w[i]>>v[i];
	}
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= W; ++j)
		{
			if (w[i] <= j)
			{
				sol[i][j] = max(v[i] + sol[i-1][j-w[i]] , sol[i-1][j]);
			}
			else
				sol[i][j] = sol[i-1][j];
		}
	}
	cout << sol[n][W];
	return 0;
}



Measured memory_bytes: 79360
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int n; cin >> n;
  int ans = 0;
  vector<int> num;
  for (int i = 0; i < n; i++) {
    int x; cin >> x;
    num.push_back(x);
    if (i < 2) continue;

    if (num[i - 2] <= num[i - 1] && num[i - 1] < num[i]) ans++;
    else if (num[i - 2] > num[i - 1] && num[i - 1] >= num[i]) ans++;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const int MAX = 100100;

int main() {
    int n;
    cin >> n;
    vector<int> dp(MAX, INF);
    while (n--) {
        int e; cin >> e;
        *lower_bound(dp.begin(), dp.end(), e) = e;
    }
    cout << lower_bound(dp.begin(), dp.end(), INF) - dp.begin() << endl;
    return 0;
}


Measured memory_bytes: 3112
/*
    PROG: milk2
	LANG: C++14
	ID: ashikuj1
*/

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

#define mod (ll) (1e9)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define pb push_back
#define make_pair mp
#define pi acos(-1)
#define N (int)3e5


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

struct node
{
    int a;
    int b;
};


int ceil(int a,int b)
{
    if(a%b)
        return a/b+1;
    else
        return a/b;
}

bool cmp1(pair<int,int>a,pair<int,int>b)
{
    if(a.first<b.first)
        return true;
    return false;
}

bool cmp(pair<int,int>a,pair<int,int>b)
{
    if(a.second<b.second)
        return true;
    return false;
}

void bin(unsigned n)
{
    if (n > 1)
        bin(n>>1);

    printf("%d", n & 1);
}
#define pri printf("! %d %d %d %d %d %d\n",a,b,c,d,e,f)



int main()
{
//#ifndef ONLINE_JUDGE
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
//#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;
    string s="";
    for(int i=1;i<=n;i++)
    {
        s+=to_string(i);
    }
//    cout<<s<<endl;
    string a,b;
    for(int i=0;i<n;i++)
    {
        char ch;
        cin>>ch;
        a+=ch;
    }
    for(int i=0;i<n;i++)
    {
        char ch;
        cin>>ch;
        b+=ch;
    }
//    cout<<a<<" "<<b<<endl;

    int x,y;
    int count=0;
    do{
        count++;
        if(s==a)
            x=count;
        if(s==b)
            y=count;
    }while(next_permutation(s.begin(),s.end()));
    cout<<abs(x-y)<<endl;
    return 0;
}


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int maxn = 200010;

vi g[2][maxn];
int dep[maxn], par[maxn]; //sugim

void dfs(int v, int p, int d) { //on sugim
	dep[v] = d;
	par[v] = p;
	for (int to : g[1][v]) if (to != p) {
		dfs(to, v, d + 1);
	}
}

bool far(int a, int b) { //on sugim, 3
	if (dep[a] > dep[b]) swap(a, b);
	if (a == b || par[b] == a || par[a] == par[b] || (par[b] != -1 && par[par[b]] == a)) {
		return false;
	} else {
		return true;
	}
}

const int INF = 1e8;

int DFS(int v, int p, int d) { //on sigma
	int res = (dep[v] - d) * 2;
	for (int to : g[0][v]) if (to != p) {
		if (dep[to] > d+1) {
			res = max(res, DFS(to, v, d + 1) + 2);
		}
		if (far(v, to)) {
			res = max(res, INF);
		}
	}
	return res;
}

int main() {
	int N, X, Y;
	cin >> N >> X >> Y; --X; --Y;

	rep(t, 2) {
		rep(i, N-1) {
			int a, b;
			cin >> a >> b;
			--a; --b;
			g[t][a].pb(b); g[t][b].pb(a);
		}
	}

	dfs(Y, -1, 0);
	int ans = DFS(X, -1, 0);
	if (ans >= INF) ans = -1;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 33536
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

const int L=16;

string toS(int x,int k){
    string ret="";
    rep(_,k){
        ret.push_back('0'+x%2);x>>=1;
    }
    return ret;
}

bool prefsame(string &a,string &b){
    size_t n=min(a.size(),b.size());
    for(size_t i=0;i<n;i++)if(a[i]!=b[i])return false;
    return true;
}

string diff(string &a,string &b){
    size_t m=min(a.size(),b.size());
    string ret="";
    if(a.size()>b.size())   for(size_t i=m;i<a.size();i++)ret.push_back(a[i]);
    else                    for(size_t i=m;i<b.size();i++)ret.push_back(b[i]);
    return ret;
}

signed main(){
    int n;cin>>n;
    vector<string> s(n);
    cin>>s;

    // make dic
    vector<string> p;
    map<string,int> id;
    p.push_back("");
    id[""]=0;
    int sz=1;
    for(int i=1;i<=L;i++){
        for(int bit=0;bit<(1<<i);bit++){
            auto t=toS(bit,i);
            id[t]=sz++;
            p.push_back(t);
        }
    }

    // solve
    int dp[sz][2];
    rep(i,sz)rep(j,2)dp[i][j]=INF;
    using T=tuple<int,int,int>;
    priority_queue<T,vector<T>,greater<T>>que;
    rep(i,n){
        dp[id[s[i]]][0]=(int)s[i].size();
        que.push(make_tuple((int)s[i].size(),0,id[s[i]]));
    }

    while(!que.empty()){
        auto t=que.top();que.pop();
        int now=get<2>(t),y=get<1>(t);
        rep(i,n)if(prefsame(p[now],s[i])){
            auto tos=diff(p[now],s[i]);
            int to=id[tos];
            if(to!=0){
                if(chmin(dp[to][1],dp[now][y]+(int)s[i].size()))que.push(make_tuple(dp[to][1],1,to));
            }else{
                chmin(dp[to][y],dp[now][y]+(int)s[i].size());
            }
        }
    }    


    if(dp[0][1]<INF)cout<<dp[0][1]/2<<endl;
    else cout<<0<<endl;
    return 0;
}



Measured memory_bytes: 21468
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0;i < (int)n;i++)
#define repb(i, n) for(int i = (int)n;i >= 0;i--)
#define reps(i, m, n) for(int i = (int)m;i < (int)n;i++)
#define repsb(i, m, n) for(int i = (int)m;i >= (int)n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define INF 999999999999999999
using namespace std;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using namespace std;
int main(int argc, char const *argv[]) {
    int n,q,temp,cnt=0;
    cin>>n;
    vector<int> s(n);
    rep(i,n)  cin>>s[i];
    cin>>q;
    rep(i,q){
      int l=0;
      int r=n;
      int mid;
      cin>>temp;
      while (l<r) {
        mid=(l+r)/2;
        if(s[mid]==temp){
          cnt++;
          break;
        }
        else if(temp<s[mid])  r=mid;
        else   l=mid+1;
      }
    }
    cout<<cnt<<endl;
    return 0;
}



Measured memory_bytes: 3148
#include <atcoder/math.hpp>
#include <iostream>
#include <set>

#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n)                       _range(i, 0, n)
#define _range(i, a, b)                  for (int i = int(a); i < int(b); ++i)
#define rep(...)                         _overload(__VA_ARGS__, _range, _rep, )(__VA_ARGS__)

#define _rrep(i, n)      _rrange(i, n, 0)
#define _rrange(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)
#define rrep(...)        _overload(__VA_ARGS__, _rrange, _rrep, )(__VA_ARGS__)

using ll = long long;
using namespace std;
using namespace atcoder;

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

    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }

    vector<ll> factors;
    ll cur = 2 * n;

    for (ll i = 2; i * i <= cur; ++i) {
        if (cur % i) continue;
        ll val = 1LL;
        while (cur % i == 0) {
            val *= i;
            cur /= i;
        }
        factors.push_back(val);
    }

    if (cur != 1) { factors.push_back(cur); }


    const int k = factors.size();

    ll ans = 1LL << 60;

    rep(mask, 1 << k) {
        ll x = 1LL, y = 1LL;
        rep(i, k) {
            if (mask >> i & 1) {
                x *= factors[i];
            } else {
                y *= factors[i];
            }
        }

        if (y == 1) { continue; }

        const vector<ll> r = {0, y - 1};
        const vector<ll> m = {x, y};

        const ll a = crt(r, m).first;
        ans        = min(ans, a);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3196
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var str = Console.ReadLine();

            var cnt = 0;
            for (var i = 0; i < n - 2; i++)
            {
                if (str[i] == 'A' && str[i + 1] == 'B' && str[i + 2] == 'C')
                {
                    cnt++;
                    i += 2;
                }
            }

            Console.WriteLine(cnt);
        }
    }
}

Measured memory_bytes: 27524
N, M = map(int, input().split())

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

# NG = 0, OK = 1
count_list = [1] * N
for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    if H[A] >= H[B]:
        count_list[B] = 0
    if H[A] <= H[B]:
        count_list[A] = 0
print(sum(count_list))

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

constexpr int64_t MOD= 1'000'000'007;
constexpr bool is_FACTORIAL_STORED= false; // 階乗を配列に格納をする前処理をする/しない
constexpr int Nfac= is_FACTORIAL_STORED ? 500'007
                                        : 0;
/* 剰余環 Z/nZ */
struct mint{ // Z/nZ に関する演算(n:素数の場合は除算も)をサポートする構造体
  int64_t rep; // 出力すべき代表元 rep \in {0,1,..,MOD- 1}
  mint(int64_t x=0): rep(((x%MOD)+ MOD)% MOD){}
  mint operator-() const { return mint(-rep);}
  mint& operator+=(const mint& x){
    rep+= x.rep; 
    if(rep>= MOD) rep-= MOD;
    return *this;
  }
  mint& operator-=(const mint& x){
    rep-= x.rep;
    if(rep< 0) rep+= MOD;
    return *this;
  }
  mint& operator*=(const mint& x){
    rep*= x.rep; rep%= MOD;
    return *this;
  }
  mint operator+(const mint x) const {
    mint ans(*this);
    ans+= x;
    return ans;
  }
  mint operator-(const mint x) const {
    mint ans(*this);
    ans-= x;
    return ans;
  }
  mint operator*(const mint x) const {
    mint ans(*this);
    ans*= x;
    return ans;
  }
  bool operator==(const mint x) const {
    return rep==x.rep;
  }
  bool operator!=(const mint x) const {
    return rep!=x.rep;
  }

  mint pow(int64_t d) const{
    assert(d >= 0); // ここで引っかかったら this.pow(d)= 0 or this.pow(-d).inv() のどちらかを選べ
    assert(!(*this==0 && d==0)); //   this.pow(d)= 0 or 1           　     のどちらかを選べ
    mint ans= 1;
    mint x= *this;
    while(d > 0){
      if(d&1){ ans*= x; }
      d >>= 1;
      x*= x;
    }

    return ans;
  }

  friend istream& operator >> (istream &is, mint& x) noexcept{
    int64_t a;
    is >> a;
    x= a;
    return is;
  }
  friend ostream& operator << (ostream &os, const mint& x) noexcept{
      return os << x.rep;
  }
  // MOD が素数(<=> Z/nZ が体)のとき
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint& x){
    *this *= x.inv();
    return *this;
  }
  mint operator/(const mint x) const {
    mint ans(*this);
    ans/= x;
    return ans;
  }
};
// ^^^ テンプレここまで ^^^

//  [x^S] prod_i sum_{j=0}^{Ai} x^j
// =[x^S] prod_i (sum_{j=0}^{Ai} x^j) (1-x) (sum_{j=0}^{S} x^j)
// =[x^S] prod_i (1-x^{Ai+1}) (sum_{j=0}^{S} x^j)
int main(){
  int N,S;
  cin >> N >> S;

  vector<int> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }

  vector<mint> dp(S+1);
  dp.at(0)= 1;
  for(auto a:data){
    for(int i= S; i>= a+1; i--){
      dp.at(i)-= dp.at(i-(a+1));
    }
    for(int i= 1; i<= S; i++){
      dp.at(i)+= dp.at(i-1);
    }
  }

  cout << dp.at(S) << endl;
}

Measured memory_bytes: 3996
#include <bits/stdc++.h>
#define db(x) cout<<x<<" "
#define db1(x) cout<<x<<'\n'
#define db2(x,y) cout<<x<<" "<<y<<'\n'
#define db3(x,y,z) cout<<x<<" "<<y<<" "<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pair(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define ff first
#define ss second
using namespace std;
using ll = long long int;
ll ans = INT_MAX;

ll recur(vector<pair<ll,ll>>&v,int i,ll h,ll move,vector<vector<ll>> &dp){

	if(h<=0){
		return 0;
	}

	if(i==v.size())
	{
		return INT_MAX;
	}

	if(dp[i][h]!=-1)
		return dp[i][h];

	ll op1 = recur(v,i,h-v[i].first,move+1,dp);
	if(op1!=INT_MAX)
		op1+=v[i].second;
	ll op2 = recur(v,i+1,h,move,dp);

	return dp[i][h]= min(op1,op2);

}

void solve(){

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

	vector<pair<ll,ll>>v;

	vector<vector<ll>> dp(n+1,vector<ll>(h+1,-1));

	int i=0;

	rep(i,n){
		ll a,b;
		cin>>a>>b;
		v.pb(make_pair(a,b));
	}

	ll ans = recur(v,0,h,0,dp);

	db1(ans);

}



int main(){

  
 int t=1;
 //cin>>t;


while(t--){
  solve();
  }
      
  



	return 0;
}


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

int main(){
	int h,w,W,H;
    cin>>H>>W;
	cin>>h>>w;
	cout<<(H-h)*(W-w)<<endl;
	return 0;
	}


Measured memory_bytes: 256
import Control.Monad

main :: IO ()
main = do
  [n, a, b] <- map read . words <$> getLine
  s <- getLine
  forM_ (solve (a, b) s) $ \i -> putStrLn $ if i then "Yes" else "No"

solve :: (Int, Int) -> String -> [Bool]
solve _ [] = []
solve (a, b) (s:ss) = case s of
  'a' -> if a+b /= 0 then True : solve (a-1, b) ss else False : solve (a, b) ss
  'b' -> if a+b /= 0 && b /= 0 then True : solve (a, b-1) ss else False : solve (a, b) ss
  otherwise -> False : solve (a, b) ss


Measured memory_bytes: 5372
# https://beta.atcoder.jp/contests/abc054/tasks/abc054_b


def solve():
    n, m = map(int, input().split())
    img = [input() for _ in range(n)]
    tmp = [input() for _ in range(m)]

    for loop in range(n-m+1):
        for row in range(n-m+1):
            match = True
            for col in range(m):
                if img[col+loop][row:row+m] != tmp[col]:
                    match = False
            if match:
                print('Yes')
                return
    print('No')


if __name__ == '__main__':
    solve()

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

#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define pll         pair<long,long>
#define vi          vector<int>
#define vll         vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define mod        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rem(i,a,b)  for(int i=a;i>b;i--)
#define mp(a,b)     make_pair(a,b)
#define vvi(a,b,name)    vector<vector<int>> name(a,vector<int>(b,-1))


void solve(){
    string s1,s2,s3;cin>>s1>>s2>>s3;
    if(s1[s1.length()-1]==s2[0] && s2[s2.length()-1]==s3[0])cout<<"YES";
    else cout<<"NO";

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


Measured memory_bytes: 256
#include <iostream> 
#include <algorithm>
#include <cmath>
#include <vector>  
#define ll long long
 
ll mod = 1000000007;
 
int MAX = 1000000;
 
ll facs[1000000];
ll inv_fac_mod[1000000];  
 
using namespace std;
 
ll true_mod(ll x){
    return (x + mod) % mod;
}
 
int ipow(int base, int exp)
{
    if (exp == 1) return base;
    if (exp % 2 == 1) {
        ll result = ipow(base, exp / 2);
        result *= true_mod(result * base);
        result = true_mod(result);
        return result;
    } else {
        ll result = ipow(base, exp / 2);
        result *= true_mod(result);
        result = true_mod(result);
        return result;
    }
}
 
int main () {
    ll prod = 1;
    for(int i = 0; i < MAX; i++) {
        if(i == 0) facs[0] = 1;
        else {
            prod *= i;
            prod = (prod + mod) % mod;
            facs[i] = prod;
        }
    }
 
    for (int i = 0; i < MAX; i++) {
        inv_fac_mod[i] = ipow(facs[i], mod - 2);
    }
 
    ll x,y;
    cin >> x >> y;
 
    ll tx = 2 * x - y;
    ll ty = -x + 2 * y;
    if ((tx % 3 != 0) || (ty % 3 != 0)) {
        cout << 0 << endl;
        return 0;
    }

    if ((tx < 0) || (ty < 0)) {
        cout << 0 << endl;
        return 0;
    }
 
    tx /= 3; ty /= 3;
 
    cout << true_mod(true_mod(facs[tx+ty] * inv_fac_mod[tx]) * inv_fac_mod[ty]) << endl;
 
    return 0;
}

Measured memory_bytes: 15872
import java.util.*

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").mapIndexed{ index, value -> 
        Pair(index, value.toInt())
    }.toMutableList().apply {
        sortBy {it.second}
        forEach { print("${it.first + 1} ") }
    }
}

Measured memory_bytes: 84928
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define ull unsigned long long int
#define forn(i,n)for(ll i=0;i<(n);i++)
#define forn_rev(i,n)for(ll i=(n)-1;i>=0;i--)
#define for1n(i,n) for(ll i=1;i<=(n);i++)
#define ARRAY_SIZE(a) sizeof(a)/sizeof(*a)
#define MOD 1000000007
#define MAXN 1000005

using namespace std;


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    ll T=1;
    //cin>>T;
    while(T--)
    {


       ll N,K;
       cin>>N>>K;


       cout<<min(N%K,K-N%K);







    }



    return 0;
}

Measured memory_bytes: 3616
#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>

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

#define cauto const auto&
#else

#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 F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define double long double
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()


#define MOD 1000000007LL
#define EPS 1e-8
static const int INF=1<<24;

int check(double x1,double y1,double x2,double y2,double r2){
	double xy=(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1),r=r2*r2;
	if(r-xy<-EPS) return 1;
	else return -1;
}


void mainmain(){
	int n;
	while(cin>>n,n){
		vector<pair<pair<double,double>,double > >  a(n);
		rep(i,n){
			cin>>a[i].F.F>>a[i].F.S>>a[i].S;
		}
		int m;
		cin>>m;
		// vector<pair<double,double> > b(m);
		rep(l,m){
			double b[4];
			cin>>b[0]>>b[1]>>b[2]>>b[3];
			bool f=false;
			double x=b[0],y=b[1];
			double dx=(b[2]-b[0])/10000.0,dy=(b[3]-b[1])/10000.0;
			rep(i,n){
				int t=check(b[0],b[1],a[i].F.F,a[i].F.S,a[i].S);
				reep(j,1,10001){
					int t1=check(x+dx*j,y+dy*j,a[i].F.F,a[i].F.S,a[i].S);
						// cout<<x+dx*j<<" "<<y+dy*j<<" "<<a[i].F.F<<" "<<a[i].F.S<<" "<<a[i].S<<endl;
					if(t!=t1){
						f=true;
						break;
					}	
				}
				if(f) break;
			}
			if(f) cout<<"Safe\n";
			else cout<<"Danger\n";
		}
	}
	// cout<<check(0,3,3,3,3)<<endl;
	// cout<<check(-1,3,3,3,3)<<endl;
	// cout<<check(0.5,0,1,0,1)<<endl;
}



}
main() try{
    mainmain();
}
catch(...){
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T> ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m)
    os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int H,N;
  cin>>H>>N;
  LL sum=0;
  REP(i,0,N){
    LL a;
    cin>>a;
    sum+=a;
  }
  if(sum>=H){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }

  return 0;
}


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

// #include <bits/extc++.h>
// using namespace __gnu_pbds;

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

#define int long long
#define double long double
// template <typename T>
// using pbds_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using pii = pair<int, int>;
template<typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;
template<typename T>
using Prior = priority_queue<T>;

#define X first
#define Y second
#define ALL(x) (x).begin(), (x).end()
#define eb emplace_back
#define pb push_back

#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, 1); \
                 auto rnd = bind(__dis, __gen);

const int INF = 1E18;
const int mod = 1E9 + 7;

int32_t main() {
    fastIO();
    
    int a, b, ans = 0;
    cin >> a >> b;
    for (int i = a/100; i <= b/100; ++i) {
        int num = i * 100 + (i/10%10) * 10 + i/100;
        if (num >= a and num <= b) ++ans;
    }
    
    cout << ans << "\n";
    
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

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

    // start
    int n;
    cin >> n;
    cout << "ABC" << n << endl;
    // end

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long N = sc.nextLong();  //s型
		long M = sc.nextLong();  //c型
		
		if(N >= M / 2) {
			System.out.println(M / 2);
		} else {
			long count = N + (M - N * 2) / 4;
			System.out.println(count);
		}
	}
}


Measured memory_bytes: 35672
# coding: utf-8
import re
import bisect
from datetime import datetime as dt
import bisect
import math
from operator import itemgetter

def gcd(a, b):
    return math.gcd(a, b)

def lcm(a, b):
    return a * b / gcd(a, b)

class slist(list):
    def __init__(self, *args, **kw):
        list.__init__(self, *args, **kw)
        self.sort()

    def append(self, value):
        bisect.insort(self,value)

    def index_left(self, value):
        return bisect.bisect_left(self, value)


if __name__ == '__main__':
    N = int(input())
    arr = [None] * N
    for i in range(N):
        arr[i] = list(map(int, input().split()))
    a = sorted(arr, key=lambda x: (x[1], x[0],))
    # print(a)
    sum = 0
    for b in a:
        sum += b[0]
        if sum > b[1]:
            print('No')
            exit()
    print('Yes')


Measured memory_bytes: 68372
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  map<string, int> mp;
  int n; cin >> n;
  for(int i = 0; i < n; i++) {
    string s; cin >> s;
    mp[s]++;
  }

  
  int num = 0;
  for(auto x : mp) {
    num = max(num, x.second);
  }
  for(auto x : mp) {
    if(x.second == num) cout << x.first << endl;
  }

  return 0;
}


Measured memory_bytes: 27136
import fileinput

iterator = fileinput.input()

a = int(iterator.next())
b = int(iterator.next())

def compute(a, b):
    if a == b:
        return 1

    # remove prefix
    n = (a ^ b).bit_length()
    high_order_bit = 1 << (n-1)
    ones_mask = (high_order_bit << 1) - 1
    a = a & ones_mask
    b = b & ones_mask

    # count possibilities
    # with first prefix 0
    prefix_0_count = high_order_bit - a
    # with first prefix 1
    b_max = (1 << (b ^ high_order_bit).bit_length()) - 1
    if a > b_max:
        prefix_1_count = b_max + 1 + prefix_0_count
    else:
        prefix_1_count = high_order_bit

    return prefix_0_count + prefix_1_count

print compute(a, b)


Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int k,x;
  	scanf("%d %d", &k, &x);
  	for(int i = x-k+1; i<x ;i++){
    	printf("%d ", i);
    }
  	for(int i = x; i<x+k ;i++){
    	printf("%d ", i);
    }
  	
	return 0;
}

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

bool isPrime(int X) {
    for (int i = 2; i <= int(sqrt(X)); i++) {
        if (X % i == 0) return false;
    }
    return true;
}

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

    int ans = 0;
    for (int i = 0; i < N; i++) {
        int X;
        cin >> X;
        if (isPrime(X)) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
#define REP(i,m,n) for(LL i=(m);i<(n);i++)

int main(){
  string n;
  cin >> n;
  
  if(n[0] == n[1] && n[1] == n[2]){
    cout << "Yes" << endl;
  }
  else if(n[2] == n[3] && n[1] == n[2]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define ff first
#define ss second
#define pi pair<ll,ll>
#define maxn 1000002
#define mod 1000000007

//vector<ll>adj[maxn];
//ll vis[maxn];
//ll cc[maxn];

//ll curr_cc;

ll arr[1000001];

int main(){
	
	
	for(int i=1;i<110;i++){
		for(int j=1;j<110;j++){
			for(int k=1;k<110;k++){
				ll res = i*i + j*j + k*k +i*j +j*k  +k*i;
				
				arr[res]++;
			}
		}
	}
	ll n;
	cin>>n;
	
	for(int i=1;i<=n;i++){
		cout<<arr[i]<<"\n";
	}
}
	
	
	
	



Measured memory_bytes: 4128
#include <stdio.h>

int main()
{
    int a, b;
    scanf("%i %i %i", &a, &b);
    if(a<b)
    {
        printf("a < b");
    }
    else if(a>b)
    {
        printf("a > b");
    }
    else if(a==b)
    {
        printf("a == b");
    }
    printf("\n");
    return 0;
}



Measured memory_bytes: 2120
#include <iostream>
#include <stdlib.h>
using namespace std;
int main(void){
    int a, b;
    cin >> a >> b;
    int ans = 0;
    string impossible;
    
    if (a % 2 == 0 && b % 2 != 0 ){
        impossible = "IMPOSSIBLE";
        cout << impossible << endl;
        return 0;
        
    }
    if (a % 2 != 0 && b % 2 == 0 ){
        impossible = "IMPOSSIBLE";
        cout << impossible << endl;
        return 0;
    }
    
    if(impossible != "IMPOSSIBLE"){
                while(true){
                    if(abs(a - ans) == abs(b - ans)){
                       break; 
                    }
                    ans++;
                }
                cout << ans << endl;
                return 0;
    }
    
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    string S;
    cin >> N >> M >> S;
    vector<int> ans;
    int pos = N;
    while (pos > 0) {
        int cnt = min(pos, M);
        if (S[pos - cnt] == '1') {
            bool is_ok = false;
            rep(i, pos - cnt, pos) {
                if (S[i] == '0') {
                    is_ok = true;
                    cnt = pos - i;
                    break;
                }
            }
            if (!is_ok) {
                cout << -1 << endl;
                return 0;
            }
        }
        ans.push_back(cnt);
        pos -= cnt;
    }
    rrep(i, ans.size(), 0) cout << ans[i] << " \n"[i == 0];
    return 0;
}

Measured memory_bytes: 1096