akhauriyash/Code-Regression huggingface dataset:
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#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 <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;

int H, W;
char board[310][310];

int solve(int w1, int w2) {
    vector< vector<int> > cost1(H+1, vector<int>(H+1));
    vector< vector<int> > cost2(H+1, vector<int>(H+1));

    // w1 のほうが w2 より i だけ高い場合
    // b[j+i][w1] と b[j][w2] とを比較
    for(int i=0; i<H; i++) {
        for(int j=0; j<H; j++) {
            cost1[i][j+1] += cost1[i][j];
            if(j+i < H) cost1[i][j+1] += (board[j+i][w1] == board[j][w2]);
        }
    }

    // w2 のほうが w1 より i だけ高い場合
    // b[j][w1] と b[j+i][w2] とを比較
    for(int i=0; i<H; i++) {
        for(int j=0; j<H; j++) {
            cost2[i][j+1] += cost2[i][j];
            if(j+i < H) cost2[i][j+1] += (board[j][w1] == board[j+i][w2]);
        }
    }

    vector< vector<int> > dp(H+1, vector<int>(H+1, INF));
    dp[H][H] = 0;
    for(int i=H; i>=0; i--) {
        for(int j=H; j>=0; j--) {
            int diff = abs(i - j);
            for(int k=0; k<2; k++) {
                int ni = i - (k == 0);
                int nj = j - (k == 1);
                if(ni < 0 or nj < 0) continue;
                if(i >= j) {
                    int c = cost1[diff][j];
                    chmin(dp[ni][nj], dp[i][j] + c);
                }
                if(i <= j) {
                    int c = cost2[diff][i];
                    chmin(dp[ni][nj], dp[i][j] + c);
                }
            }
        }
    }
    return dp[0][0];
}

int main() {
    cin >> H >> W;
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            cin >> board[i][j];
        }
    }

    ll ans = 0;
    for(int i=0; i+1<W; i++) {
        int res = solve(i, i+1);
        fprintf(stderr, "res = %d\n", res);
        ans += res;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1496
#include<stdio.h>
 int main(){
   int N,K;
   scanf("%d %d",&N,&K);
   if(N>=K){
     for(int a=0;a<N;a++){
       printf("%d",K);
     }}else{
       for(int b=0;b<K;b++){
       printf("%d",N);
       }
     }
     return 0;
   }

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
char s[N];
int dp[N][2][2];
int n;

int solve(int pos, int carry, int tight) {
  if (pos == n) return carry == 0;
  int& ret = dp[pos][carry][tight];
  if (ret >= 0) return ret;
  ret = 0;
  for (int x = 0; x < 2; ++x) {
    for (int y = 0; y < 2; ++y) {
      for (int nxt_carry = 0; nxt_carry < 2; ++nxt_carry) {
        int sum_val = x + y + nxt_carry;
        int xor_val = x ^ y;
        if (sum_val / 2 != carry) continue;
        sum_val %= 2;
        if (tight && sum_val > s[pos] - '0') continue;
        if (xor_val != sum_val) continue;
        int nxt_tight = tight && (sum_val == s[pos] - '0');
        ret += solve(pos + 1, nxt_carry, nxt_tight);
        ret %= MOD;
      }
    }
  }
  return ret;
}

int main() {
  scanf("%s", s);
  n = strlen(s);
  memset(dp, 255, sizeof(dp));
  int ret = solve(0, 0, 1);
  printf("%d\n", ret);
  return 0;
}


Measured memory_bytes: 12928
args = gets.split(" ").map(&:to_i)

input_a = args[0]
input_b = args[1]
input_K = args[2]

calc_divisor = lambda{|input| (1..input).select do |i|
                                 input.modulo(i) == 0
                              end}
if (input_a <= input_b)
  divisors_list = calc_divisor.call(input_a)
  res = divisors_list.select{|div| input_b.modulo(div) == 0}.sort.reverse
else
  divisors_list = calc_divisor.call(input_b)
  res = divisors_list.select{|div| input_a.modulo(div) == 0}.sort.reverse
end

puts res.at(input_K - 1)


Measured memory_bytes: 1788
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <bitset>
#include <iterator>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <random>
#include <numeric>
#include <set>
#include <cassert>
#include <cmath>
#include <cinttypes>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os; }
template<class T> istream& operator>>(istream& is, vector<T>& v) { for (auto i = begin(v); i != end(v); i++) is >> *i; return is; }
struct fast_io {
	fast_io& operator>> (int& target) { scanf("%" PRId32, &target);  return *this; }
	fast_io& operator>> (unsigned int& target) { scanf("%" PRIu32, &target);  return *this; }
	fast_io& operator>> (long long& target) { scanf("%" PRId64, &target);  return *this; }
	fast_io& operator>> (unsigned long long& target) { scanf("%" PRIu64, &target);  return *this; }
	template<typename T> fast_io& operator>> (vector<T>& target) { for (auto& value : target) { *this >> value; } return *this; }
	fast_io& operator<< (const int value) { printf("%" PRId32, value); return *this; }
	fast_io& operator<< (const unsigned int value) { printf("%" PRIu32, value); return *this; }
	fast_io& operator<< (const long long value) { printf("%" PRId64, value); return *this; }
	fast_io& operator<< (const unsigned long long value) { printf("%" PRIu64, value); return *this; }
	fast_io& operator<< (const string& value) { printf("%s", value.c_str()); return *this; }
	template<typename T> fast_io& operator<< (const vector<T>& target) { for (auto& value : target) { *this << value << " "; } return *this; }
}; fast_io fio;

template<class ForwardIt, class UnaryPredicate>
ForwardIt first_true(ForwardIt first, ForwardIt last, UnaryPredicate predicate) {
	ForwardIt it;
	typename std::iterator_traits<ForwardIt>::difference_type count, step; count = std::distance(first, last);
	while (count > 0) {
		it = first;	step = count / 2;
		std::advance(it, step);
		if (!predicate(*it)) { first = ++it; count -= step + 1; }
		else count = step;
	}
	return first;
}

#define MOD 1000000007
#define pii pair<int,int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define sort_all(x) sort(all(x))
#define make_unique(x) (x).erase(unique(all(x)), (x).end())



int main() {

#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	long long A, B, V, W, T;
	fio >> A >> V >> B >> W >> T;

	long long vdiff = abs(V - W);
	long long ddiff = abs(A - B);
	if (V > W && T * vdiff >= ddiff)
		fio << "YES";
	else
		fio << "NO";

	return 0;
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using vi = vector<int>;
using vvi = vector<vi>;

const int N = 8;

bool IN(int y, int x){
    return 0<=y && y<N && 0<=x && x<N;
}

void dfs(const vvi &f, int t){
    bool end = true;
    rep(i,N)rep(j,N)if(f[i][j]==-1){
        bool ok = false;
        vvi nf(f);
        nf[i][j] = t;
        for(int dy=-1; dy<=1; ++dy)for(int dx=-1; dx<=1; ++dx){
            if(dy==0 && dx==0) continue;

            int cy = i+dy, cx = j+dx;
            if(IN(cy,cx) && nf[cy][cx]==!t){
                while(IN(cy,cx) && nf[cy][cx]==!t){
                    cy += dy;
                    cx += dx;
                }

                if(IN(cy,cx) && nf[cy][cx]==t){
                    cy = i+dy;
                    cx = j+dx;
                    while(IN(cy,cx) && nf[cy][cx]==!t){
                        nf[cy][cx] = t;
                        cy += dy;
                        cx += dx;
                    }
                    ok = true;
                }
            }
        }
        if(ok){
            end = false;
            dfs(nf,!t);
        }
    }

    if(end){
        printf("---------------------\n");
        rep(i,N){
            rep(j,N){
                char c = f[i][j]+'0';
                if(f[i][j]==-1) c = '.';
                printf("%c", c);
            }
            printf("\n");
        }
    }
}

void test(){
    vvi s(N);
    rep(i,N) s[i] = vi(N,-1);
    s[3][3] = 0;
    s[3][4] = 1;
    s[4][4] = 0;

    dfs(s,1);
    dbg("END");
}

int f[N][N]={};
int dp[N][N][N][N];
int solve(int ly, int lx, int ry, int rx){
    if(dp[ly][lx][ry][rx]>=0) return dp[ly][lx][ry][rx];

    int a = 0;
    for(int i=ly; i<=ry; ++i)for(int j=lx; j<=rx; ++j) a += f[i][j];

    return dp[ly][lx][ry][rx] = a;
}

int main(){
    // test();

    rep(i,N)rep(j,N){
        if(i%2==0 && j%2==1) f[i][j] = 0;
        else f[i][j] = 1;
    }

    memset(dp, -1, sizeof(dp));
    int q;
    scanf(" %d", &q);
    while(q--){
        int a,b,c,d;
        scanf(" %d %d %d %d", &a, &b, &c, &d);
        printf("%d\n", solve(a-1, b-1, c-1, d-1));
    }
    return 0;
}



Measured memory_bytes: 3244
void main(){
	int[] fares;
	foreach(_;0..4){
		fares ~= inelm();
	}
	min( fares[0]+fares[2], fares[0]+fares[3],
			fares[1]+fares[2], fares[1]+fares[3])
		.writeln();
}
     
import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math, std.range;
const long mod = 10^^9+7;      
// 1要素のみの入力
T inelm(T= int)(){
	return to!(T)( readln().chomp() );
}
     
// 1行に同一型の複数入力
T[] inln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split())ln ~= elm.to!T();
	return ln;
}


Measured memory_bytes: 2684
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

#define NIL -1
#define N 100005

//struct Node{
//	int val;
//	Node *p, *l, *r;
//};

struct Node {
	int p, l, r;
	Node():p(NIL), l(NIL), r(NIL){}
};

Node T[N];
int D[N], H[N];

void preo(int u){
	if (u == NIL) return;
	printf(" %d", u);
	preo(T[u].l);
	preo(T[u].r);
}

void ino(int u){
	if (u == NIL) return;
	ino(T[u].l);
	printf(" %d", u);
	ino(T[u].r);
}

void posto(int u){
	if (u == NIL) return;
	posto(T[u].l);
	posto(T[u].r);
	printf(" %d", u);
}

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

	for (int i = 0; i < n; ++i){
		int u, l, r; cin >> u >> l >> r;
		T[u].l = l;
		T[u].r = r;
		if (l != NIL) T[l].p = u;
		if (r != NIL) T[r].p = u;
	}

	int root;
	for (int i = 0; i < n; ++i) if (T[i].p == NIL) root = i;

	printf("Preorder\n");
	preo(root);
	printf("\n");
	printf("Inorder\n");
	ino(root);
	printf("\n");
	printf("Postorder\n");
	posto(root);
	printf("\n");

	return 0;
}
//Sample Output 1
//Preorder
//0 1 2 3 4 5 6 7 8
//Inorder
//2 1 3 0 6 5 7 4 8
//Postorder
//2 3 1 6 7 5 8 4 0

Measured memory_bytes: 4324
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    ll T = 1, A = 1;
    rep(i,n) {
        ll t,a;
        cin >> t >> a;
        ll num = (T+t-1)/t;
        if(num*a >= A) {
            T = num*t;
            A = num*a;
        } else {
            num = (A+a-1)/a;
            T = num*t;
            A = num*a;
        }
    }
    cout << T+A << endl;
}


Measured memory_bytes: 256
using System;
class AOJ
{
    public static void Main()
    {
        while (true)
        {
            string[] st = Console.ReadLine().Split(' ','\n');
            int a = int.Parse(st[0]);
            int b = int.Parse(st[1]);
            if (a == 0 && b == 0)
                break;
            for (int i = 0; i < a; i++)
            {
                for (int j = 0; j < b; j++)
                {
                    Console.Write("#");
                }
                Console.WriteLine();
            }
            Console.WriteLine();
       

        }
    }
}

Measured memory_bytes: 8792
n = gets.to_i
t, a = gets.split(" ").map(&:to_i)
hs = gets.split(" ").map(&:to_i)

array = []
hs.each_with_index do |h, i|
  average_temp = t - (h * 0.006)
#   p "#{i+1} #{average_temp} #{(a - average_temp).abs}"
  array << (a - average_temp).abs
end

puts array.index(array.min) + 1

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  int n, a, b;
  cin >> n >> a >> b;
  cout << (a * n < b ? a * n : b) << endl;
  return 0;
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

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 != v.size() ? " " : "");
  }
  return os;
}

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

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

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


Measured memory_bytes: 256
import sys
import math
# input処理を高速化する
input = sys.stdin.readline

A,B,C,D = map(int,input().split())

while True:
    C=C-B
    if C<=0:
        print('Yes')
        exit(0)
    A=A-D
    if A<=0:
        print('No')
        exit(0)

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n; cin >> n;
    string s;
    cin >> s;

    int ans = 1;
    FOR(i, 1, n)if (s[i - 1] != s[i])ans++;
    cout << ans << "\n";
}


Measured memory_bytes: 512
import java.util.*;
import java.math.*;
class Main
{
	public static void main(String args[])
	{
		Scanner scan = new Scanner(System.in);
		int n;
		n = scan.nextInt();
		long t;
		BigInteger lcm = BigInteger.ONE;
		for(int i = 0; i < n; ++i)
		{
			t = scan.nextLong();
			if(i == 0)
			{
				lcm = BigInteger.valueOf(t);
			}
			else
			{
				lcm = lcm.multiply(BigInteger.valueOf(t)).divide(lcm.gcd(BigInteger.valueOf(t)));
			}
		}
		System.out.println(lcm);
	}
}

Measured memory_bytes: 21588
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in), 1);
		for(String line=br.readLine(); line!=null; line=br.readLine()) {
			if(line.length()==0)
				break;
			double[][] coefficient=new double[2][3];
			for(int i=0; i<coefficient.length; i++)
				coefficient[i]=new double[3];
			String[] array=line.split(" ");
			for(int i=0; i<6; i++) {
				coefficient[i/3][i%3]=Double.parseDouble(array[i]);
			}
			// sweep
			for(int i=0; i<2; i++) {
				for(int j=3-1; j>=i; j--) {
					coefficient[i][j]/=coefficient[i][i];
				}
				for(int j=0; j<2; j++) {
					if(i==j) continue;
					for(int k=3-1; k>=i; k--) {
						coefficient[j][k]-=coefficient[i][k]*coefficient[j][i];
					}
				}
			}
			BigDecimal[] ansBG=new BigDecimal[2];
			double[] ans=new double[2];
			for(int i=0; i<2; i++) {
				ansBG[i]=new BigDecimal(String.valueOf(coefficient[i][2]));
				ans[i]=ansBG[i].setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
			}
			String str=String.format("%.3f %.3f", ans[0], ans[1]);
			System.out.println(str);
		}
	}

}

Measured memory_bytes: 17236
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
const double eps = 1e-6;

/////////////////////////////////////////////

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

////////////////////////////////

#define int long long

const int N = 1e5 + 10;
int par[N];
int size[N];
int dost[N];
int dushman[N];
int candidate[N];
int getPar(int x){

	while(x!=par[x]){
		x = par[par[x]];
	}
	return x;
}

void unite(int x , int y){

	x = getPar(x);
	y = getPar(y);
	if(x==y)
		return ;
	if(size[x] < size[y]){

		par[x] = y;
		size[y] += size[x];
	}
	else {

		par[y] = x;
		size[x] += size[y];
	}
}

void solve(){

	int n , m , k;
	cin>>n>>m>>k;

	for(int i = 1 ; i <= n ; ++i)
		par[i] = i , size[i] = 1;

	for(int i = 1 ; i <= m ; ++i){

		int x , y;

		cin>>x>>y;
		dost[x]++ , dost[y]++;
		unite(x , y);
	}

	for(int i = 1 ; i <= n ; ++i){

		int p = getPar(i);

		int val = size[p];

		int should = val - 1;
		candidate[i] += should - dost[i];
	}

	for(int i = 1 ; i <= k ; ++i){

		int x, y;
		cin>>x>>y;

		if(getPar(x)==getPar(y))
			--candidate[x] , --candidate[y];
	}

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

signed main(){

    fast;
    int t = 1;
    //cin>>t;
    for(int i = 1 ; i <= t; ++i){

    	solve();
    }
}


Measured memory_bytes: 3968
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

vector<pair<pair<int,int>,int> > way[SIZE];
bool flag[SIZE];

int n,m;

int calc(int s, int g){
  int cost[SIZE] = {};
  bool visited[SIZE] = {};
  priority_queue<pair<int,int> > pq;

  pq.push({0,s});

  for(int i=0;i<n;i++){
    visited[i] = false;
  }
  
  while(pq.size()){
    pair<int,int> p = pq.top();
    pq.pop();

    int now = p.second;
    int now_cost = p.first;

    if(visited[now]) continue;
    visited[now] = true;
    cost[now] = -now_cost;
    
    for(int i=0;i<way[now].size();i++){
      pq.push({now_cost-way[now][i].first.second, way[now][i].first.first});
    }
  }

  pq.push({cost[g],g});

  for(int i=0;i<n;i++){
    visited[i] = false;
  }
  
  while(pq.size()){
    pair<int,int> p = pq.top();
    pq.pop();

    int now = p.second;
    int now_cost = p.first;    
    
    if(visited[now]) continue;
    visited[now] = true;
    
    for(int i=0;i<way[now].size();i++){
      int next = way[now][i].first.first;
      int id = way[now][i].second;
      if(now_cost-way[now][i].first.second == cost[next]){
        flag[id] = true;
        pq.push({now_cost-way[now][i].first.second, next});
      }
    }
  }

  return 0;
}

int main(){
  int a,b,c;
  
  scanf("%d%d",&n,&m);

  for(int i=0;i<m;i++){
    scanf("%d%d%d",&a,&b,&c);
    a--; b--;
    way[a].push_back({{b,c},i});
    way[b].push_back({{a,c},i});
  }

  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      calc(i,j);
    }
  }
  
  int ans = 0;

  for(int i=0;i<m;i++){
    if(flag[i] == false) ans++;
  }
    
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

template<class T>
struct SegmentTree {
private:
    int n;
    vector<T> node;
    T def;
    function<T(T,T)> out;
    
public:
    SegmentTree() {}
    SegmentTree(const vector<T> &v, T _def, function<T(T,T)> _out) {
        int vl = (int)v.size();
        n = 1;
        while(n < vl) n *= 2;
        def = _def; out = _out;
        node = vector<T>(2 * n - 1, def);
        for(int i = 0; i < vl; i++) node[i + n - 1] = v[i];
        for(int i = n - 2; i >= 0; i--) node[i] = out(node[i * 2 + 1], node[i * 2 + 2]);
    }
    
    void update(int idx, T val) {
        idx += (n - 1);
        node[idx] = val;
        while(idx > 0) {
            idx = (idx - 1) / 2;
            node[idx] = out(node[idx * 2 + 1], node[idx * 2 + 2]);
        }
    }
    
    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if (r < 0) r = n;
        if ((r <= a) || (b <= l)) return def;
        if ((a <= l) && (r <= b)) return node[k];
        return out(query(a, b, 2 * k + 1, l, (l + r) / 2), query(a, b, 2 * k + 2, (l + r) / 2, r));
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    const ll chars = 'z' - 'a' + 1;
    ll n, q;
    string s;
    cin >> n >> s >> q;
    vector<SegmentTree<ll>> st(chars, SegmentTree<ll>(vector<ll>(n, 0), 0, [](ll a, ll b){ return a + b; }));
    rep(i, n) st[s[i] - 'a'].update(i, 1);
    rep(i, q) {
        ll t;
        cin >> t;
        if (t == 1) {
            ll a;
            char b;
            cin >> a >> b;
            a--;
            st[s[a] - 'a'].update(a, 0);
            st[b - 'a'].update(a, 1);
            s[a] = b;
        }
        else {
            ll a, b;
            cin >> a >> b;
            a--;
            ll ans = 0;
            rep(j, chars) {
                ll tmp = st[j].query(a, b);
                if (tmp > 0) ans++;
            }
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 226076
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Main {
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

	public static void main(String[] args) throws Exception {
		int sn = Integer.parseInt(br.readLine());
		List<Integer> slist = Arrays.stream(br.readLine().split(" "))
				.map(Integer::parseInt)
				.collect(Collectors.toList());
		int qn = Integer.parseInt(br.readLine());
		List<Integer> qlist = Arrays.stream(br.readLine().split(" "))
				.map(Integer::parseInt)
				.collect(Collectors.toList());
		
		int count = 0;
		for(int q: qlist){
			int left = 0;
			int right = slist.size();
			while(left < right){
				int mid = (left + right) / 2;
				if(q == slist.get(mid)){
					count++;
					break;
				}else if(slist.get(mid) < q){
					left = mid + 1;
				}else{
					right = mid;
				}
			}
		}
		
		System.out.println(count);
	}
}


Measured memory_bytes: 60644
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")
    };
}

fn main() {
    input! {
        n: usize,
        s: chars
    }

    let mut ec = 0;
    for i in 0..n {
        if s[i] == 'E' {
            ec = ec + 1;
        }
    }
    let mut tc = ec;
    let mut min = n;
    for i in 0..n {
        if s[i] == 'E' {
            min = std::cmp::min(tc- 1, min);
            tc = tc - 1;
        }else{
            min = std::cmp::min(tc , min);
            tc = tc + 1;
        }
    }
    println!("{}", min)
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
int H;
int A[114514];
int B[114514];
int C[114514];
int D[114514];
int ind[500];
int outd[500];
bool used[500];
vector<int> es[500];

int MakeVertex(int a, int c, bool rev=false) {
  if (c == 0) return a+rev*(H+1);
  return c+(H+1)*!rev;
}

pii GetIO(int v, pii &cnt) {
  if (es[v].empty()) {
    return pii(0, 0);
  }

  used[v] = true;
  pii ret(0, 0);
  for (int u : es[v]) {
    if (used[u]) continue;
    auto res = GetIO(u, cnt);
    ret.X += res.X;
    ret.Y += res.Y;
  }

  if (v >= H+1) {
    assert(ind[v] - outd[v] >= 0);
    cnt.X += 1;
    ret.X += ind[v] - outd[v];
  } else {
    assert(outd[v] - ind[v] >= 0);
    cnt.Y += 1;
    ret.Y += outd[v] - ind[v];
  }

  return ret;
}

signed main(){
  cin >> N >> H;

  rep(i, N) {
    cin >> A[i] >> B[i] >> C[i] >> D[i];
    
    int u = MakeVertex(A[i], C[i], true);
    int v = MakeVertex(B[i], D[i], false);

    ind[u]++;
    outd[v]++;

    es[u].eb(v);
    es[v].eb(u);
  }

  rep(v, H+1) {
    if (ind[v] > outd[v]) {
      cout << "NO" << endl;
      return 0;
    }
  }

  reps(v, H+1, 2*(H+1)) {
    if (ind[v] < outd[v]) {
      cout << "NO" << endl;
      return 0;
    }
  }

  rep(v, 2*(H+1)) {
    if (es[v].empty()) continue;
    if (used[v]) continue;

    pii cnt(0, 0);
    auto res = GetIO(v, cnt);
    //cout << res.X << ", " << res.Y << endl;
    //cout << cnt.X << ", " << cnt.Y << endl;
    bool fail = false;
    fail |= res.X != res.Y;
    fail |= cnt.X > 0 && cnt.Y == 0;
    fail |= cnt.X == 0 && cnt.Y > 0;
    fail |= res.X == 0; 
    if (fail) {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
}


Measured memory_bytes: 3328
import math
# b=input()
# c=[]
# for i in range(b):
#     c.append(a[i])
a = list(map(int,input().split()))
#b = list(map(int,input().split()))
s=int(input())

for i in range(s):
	a[a.index(max(a))]=	a[a.index(max(a))]*2
	
print(sum(a))

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

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

typedef long long int ll;

const ll INF=(ll)1e19;
//const int INF=(1<<30);


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

  int ans = (1<<10);
  REP(i,N){
    int a;
    cin >> a;
    int cnt = 0;
    while(a%2==0){
      a/=2;
      cnt++;
    }
    ans=min(ans,cnt);
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.*;
import java.math.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        int[] numlist = new int[30];
        int maxnum = 0;

        int index = 0;
        while(sc.hasNext()){  
            numlist[index] = sc.nextInt();
            if(maxnum < numlist[index]){
                maxnum = numlist[index];
            }
            index++;
        }

        int[] series = new int[maxnum+1];
        boolean[] checklist = new boolean[maxnum+1];
        series[0] = 0;
        series[1] = 1;
        checklist[0] = false;
        checklist[1] = false;
        for(int i = 2; i < maxnum+1; i++){
            series[i] = i;
            checklist[i] = true;
        }

        for(int i = 2; i < maxnum+1; i++){
            if(!checklist[i]){continue;}
            for(int j = 2; i*j < maxnum+1; j++){
                checklist[i*j] = false;
            }
        }

        int count;
        for(int i = 0; i < index; i++){
            count = 0;
            for(int j = 2; j < numlist[i] + 1; j++){
                if(checklist[j]){count++;}
            }
            System.out.println(count);
        }
 
    }
}

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

    // 入力
    int n;
    cin >> n;
    vi  a(n);
    int sum = 0;
    rep(i, n) { cin >> a[i]; }

    // 処理
    sort(all(a), greater<int>());
    // rep(i, n) { cout << a[i] << " "; }

    rep(i, n) {
        if (i % 2 == 0) {
            sum += a[i];
        } else {
            sum -= a[i];
        }
    }
    // 出力
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

    vector<int> A(3);
    cin >> A[0] >> A[1] >> A[2];
    swap(A[0], A[1]);
    swap(A[0], A[2]);
    cout << A[0] << " " << A[1] << " " << A[2] << "\n";

    return 0;
}


Measured memory_bytes: 256
h, n = map(int, input().split())
ab = []
for i in range(n):
    ab.append(list(map(int, input().split())))
num = [float("inf")] * (h + 1)
num[0] = 0
for i in range(h):
    mp = []
    for j in range(n):
        if (i + 1) - ab[j][0] < 0:
            mp.append(ab[j][1])
        else:
            mp.append(num[i + 1 - ab[j][0]] + ab[j][1])
    num[i + 1] = min(mp)
print(num[h])

Measured memory_bytes: 44528
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <cmath>
#include <iomanip>

using namespace std;


pair<double, double> ans(0,0);
vector<double> x;
vector<double> y;

void dfs(double length, vector<bool> visited, int cur, int visited_num){
    if(visited_num==visited.size()){
        ans.first += length;
        ans.second++;
        return;
    }

    for(int i=0; i<visited.size(); i++){
        if(visited[i])
            continue;
        visited[i]=true;
        double tmp = sqrt( pow(x[cur]-x[i],2) + pow(y[cur]-y[i],2));
        dfs(length+tmp, visited, i, visited_num+1);
        visited[i]=false;
    }
}


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

    x.resize(N);
    y.resize(N);

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

    vector<bool> visited(N, false);

    for(int i=0; i<N; i++) {
        visited[i] = true;
        dfs(0, visited, i, 1);
        visited[i] = false;
    }
    cout <<std::setprecision(7)<< ans.first/ans.second<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;

const vector<int> ComputeOns(const int N, const int value)
{
    vector<int> ons;
    int digit = value;
    for (int i = 0; i < N; ++i)
    {
        ons.push_back(digit % 2);
        digit /= 2;
    }
    return ons;
}

const bool LightOn(const int N, const vector<int> &switches, const vector<int> &ons, const int p)
{
    int sum = 0;
    for (const int s : switches)
    {
        sum += ons[s - 1];
    }
    return sum % 2 == p;
}

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> switches;
    for (int i = 0; i < M; ++i)
    {
        int ki;
        std::vector<int> swithces_i;
        cin >> ki;
        for (int j = 0; j < ki; ++j)
        {
            int sij;
            cin >> sij;
            swithces_i.push_back(sij);
        }
        switches.push_back(swithces_i);
    }
    vector<int> ps;
    for (int i = 0; i < M; ++i)
    {
        int pi;
        cin >> pi;
        ps.push_back(pi);
    }
    int caseNum = 0;
    for (int i = 0; i < pow(2, N); ++i)
    {
        const auto ons = ComputeOns(N, i);
        bool allLightsOn = true;
        for (int j = 0; j < M; ++j)
        {
            if (LightOn(N, switches[j], ons, ps[j]) == false)
            {
                allLightsOn = false;
                break;
            }
        }
        if (allLightsOn)
        {
            ++caseNum;
        }
    }
    cout << caseNum;

    return 0;
}

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

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

  int left = 0;
  int right = N;
  rep(i,M){
    int L,R;
    cin >> L >> R;
    left = max(left,L);
    right = min(right,R);
  }
  cout << max(right - left + 1,0) << endl;
}

Measured memory_bytes: 256
// ===================================
//   author: M_sea
//   website: http://m-sea-blog.com/
// ===================================
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define re register
#define mp make_pair
#define clear(x,y) memset(x,y,sizeof(x))
using namespace std;

inline int read() {
    int X=0,w=1; char c=getchar();
    while (c<'0'||c>'9') { if (c=='-') w=-1; c=getchar(); }
    while (c>='0'&&c<='9') X=X*10+c-'0',c=getchar();
    return X*w;
}

const int N=200000+10;

int n,x[2][N];
pair<int,int> a[N];

struct edge { int v,nxt; } e[N*10];
int head[N],ecnt=0;
inline void addEdge(int u,int v) {
    e[++ecnt]=(edge){v,head[u]},head[u]=ecnt;
}

#define ls (o<<1)
#define rs (o<<1|1)
int ncnt,id[N];
inline void build(int o,int l,int r) {
    if (l==r) { id[o]=a[l].second; return; }
    id[o]=++ncnt; int mid=(l+r)>>1;
    build(ls,l,mid),build(rs,mid+1,r);
    addEdge(id[o],id[ls]),addEdge(id[o],id[rs]);
}
inline void link(int o,int l,int r,int ql,int qr,int u) {
    if (ql>qr) return;
    if (ql<=l&&r<=qr) { addEdge(u,id[o]); return; }
    int mid=(l+r)>>1;
    if (ql<=mid) link(ls,l,mid,ql,qr,u);
    if (qr>mid) link(rs,mid+1,r,ql,qr,u);
}
#undef ls
#undef rs

int dfn[N],low[N],tim=0,bl[N],scc=0,sta[N],in[N],top=0;
inline void tarjan(int u) {
    dfn[u]=low[u]=++tim,sta[++top]=u,in[u]=1;
    for (re int i=head[u];i;i=e[i].nxt) {
        int v=e[i].v;
        if (!dfn[v]) tarjan(v),low[u]=min(low[u],low[v]);
        else if (in[v]) low[u]=min(low[u],dfn[v]);
    }
    if (dfn[u]==low[u]) { ++scc;
        while (233) {
            int t=sta[top--]; bl[t]=scc,in[t]=0;
            if (t==u) break;
        }
    }
}

inline int check(int mid) {
    clear(head,0),ecnt=0;
    clear(dfn,0),clear(low,0),clear(bl,0),clear(in,0),tim=scc=top=0;
    ncnt=n<<1,build(1,1,n<<1);
    for (re int i=1;i<=n;++i)
        for (re int j=0;j<2;++j) {
            int l=lower_bound(a+1,a+n+n+1,mp(x[j][i]-mid+1,0))-a;
            int r=upper_bound(a+1,a+n+n+1,mp(x[j][i]+mid-1,n<<1|1))-a-1;
            int m=lower_bound(a+1,a+n+n+1,mp(x[j][i],i+(j^1)*n))-a;
            link(1,1,n<<1,l,m-1,i+j*n),link(1,1,n<<1,m+1,r,i+j*n);
        }
    for (re int i=1;i<=ncnt;++i) if (!dfn[i]) tarjan(i);
    for (re int i=1;i<=n;++i) if (bl[i]==bl[i+n]) return 0;
    return 1;
}

int main() {
    n=read();
    for (re int i=1;i<=n;++i) {
        x[0][i]=read(),x[1][i]=read();
        a[i]=mp(x[0][i],i+n),a[i+n]=mp(x[1][i],i);
    }
    sort(a+1,a+n+n+1);
    int L=0,R=1e9;
    while (L<R) {
        int mid=(L+R+1)>>1;
        if (check(mid)) L=mid;
        else R=mid-1;
    }
    printf("%d\n",L);
    return 0;
}
//qwq

Measured memory_bytes: 14720
def getlist():
	return list(map(int, input().split()))

N = int(input())
A = getlist()
B = getlist()
C = getlist()
ans = 0

for i in range(N):
	ans += B[A[i] - 1]

for i in range(N - 1):
	if A[i + 1] - A[i] == 1:
		ans += C[A[i] - 1]

print(ans)

Measured memory_bytes: 38384
N = int(input())
a = list(map(int,input().split()))
if len(set(a)) == 1 and a[0] == 0:
    print("Yes")
    exit()
if N%3 != 0:
    print("No")
    exit()

import collections
sa = list(set(a))
sa.sort()
B = collections.Counter(a)

if len(sa) == 2 and 0 in sa:
    if B[0] == N//3 and B[sa[1]] == N*2//3:
        print("Yes")
    else: print("No")
    exit()
if len(sa) != 3:
    print("No")
    exit()

if B[sa[0]] == B[sa[1]] == B[sa[2]]:
    print("Yes" if sa[0] ^ sa[1] == sa[2] else "No")
else:
    print("No")

Measured memory_bytes: 20660
#include<iostream>
#include<algorithm>
#include<string.h>
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int maxn=2e5+5;
ll lcm(ll a,ll b)
{
	return a/__gcd(a,b)*b;
}
int main()
{
	ll n,m,ans=1;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		ll x;
		cin>>x;
		ans=lcm(ans,x);
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric> // accumulate(v.begin(), v.end(), 0)

using namespace std;
#define ll long long

int main(){
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> A(M);
  vector<int> B(M);
  for(int i=0; i<M; i++)
    cin >> B[i];
  int ans = 0;
  for(int i=0; i<N; i++) {
    int tmp = C;
    for(int i=0; i<M; i++) {
      cin >> A[i];
      tmp += A[i] * B[i];
    }
    if(tmp > 0) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

#include <boost/rational.hpp>
*/
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
using ll = long long;
using ld = long double;
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define rep3(i, n) for (ll i = 1; i < (ll)(n+1); i++)
#define rep4(i, s, n) for (ll i = (s); i < (ll)(n+1); i++)
#define repr(i,n) for (ll i = (n-1); i>=0;i--)
#define repr3(i,n) for(ll i = (n);i>0;i--)
#define stlen(s) ll s.size()-1
#define all(v) v.begin(), v.end()
#define cout(n) cout<<std::fixed<<std::setprecision(n)
using Graph = vector<vector<int>>;
#define INF1  INT_MAX;
#define INF2  LLONG_MAX;
#define PI  3.14159265358979323846;
#define MOD 1000000007;
/*
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部長が32の浮動小数点数型
using Real32 = mp::number<mp::cpp_dec_float<32>>;
// 仮数部長が1024の浮動小数点数型
using Real1024 = mp::number<mp::cpp_dec_float<1024>>;
// 有理数型
using Rat = boost::rational<Bint>;
*/


int main() {
int MAX = 101010;
    vector<int> is_prime(MAX, 1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < MAX; ++i) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < MAX; j += i) is_prime[j] = 0;
    }
int count[100001];
count[0]=0;
rep3(i,100000){
 if((i%2==1)&&(is_prime[i])&&(is_prime[(i+1)/2])){
   count[i]=count[i-1]+1;
 }
 else{
   count[i]=count[i-1];
 } 

}

int Q;
cin>>Q;
ll ans[Q];
rep(i,Q){
  int l,r;
  cin>>l>>r;
  ans[i]=count[r]-count[l-1];
}
rep(i,Q){
  cout<<ans[i]<<endl;
}


return 0;
}


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

ll gcd(ll a, ll b)
{
    if (a < b) {
        a ^= b;
        b ^= a;
        a ^= b;
    }

    return b ? gcd(b, a % b) : a;
}

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

int main(){
  ll a,b;
  cin >> a >> b;
  cout << lcm(a,b) << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Demand implements Comparable {
    int from;
    int to;

    public int compareTo(Object other) {
        Demand otherDemand = (Demand) other;
        return to - otherDemand.to;
    }
}

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

        int n = sc.nextInt();
        int m = sc.nextInt();

        Demand[] demands = new Demand[m];

        for (int i = 0; i < m; i++) {
            Demand demand = new Demand();
            demand.from = sc.nextInt();
            demand.to = sc.nextInt();
            demands[i] = demand;
        }

        Arrays.sort(demands);

        int ans = 0;
        int lastBridge = -1;

        for (int i = 0; i < m; i++) {
            if (demands[i].from > lastBridge) {
                lastBridge = demands[i].to - 1;
                ans++;
            }
        }

        System.out.println(ans);
    }

}


Measured memory_bytes: 90328