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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }

void solve() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  ll sum = 0;
  for (int i = 0; i < N; i++) {
    if (A[i] == 0) {
      ans += sum / 2;
      sum = 0;
    } else {
      sum += A[i];
    }
  }
  cout << ans + sum / 2 << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}

Measured memory_bytes: 1024
package main

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

func main() {
	list1 := getStdinIntArr64()
	N := list1[0]
	A := getStdinIntArr64()
	list2 := getStdinIntArr64()
	Q := list2[0]

	AMap := make(map[int64]int64, N+Q)
	var ASum int64 = 0
	for _, val := range A {
		AMap[val]++
		ASum += val
	}

	var i int64 = 0
	sumlist := make([]int64, 0)
	for ; i < Q; i++ {
		list3 := getStdinIntArr64()
		B := list3[0]
		C := list3[1]

		sum := ASum
		num := AMap[B]
		sum -= num * B
		sum += num * C
		ASum = sum
		AMap[B] = 0
		AMap[C] += num

		sumlist = append(sumlist, sum)
	}

	for i = 0; i < Q; i++ {
		fmt.Printf("%d\n", sumlist[i])
	}
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 21444
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll H,W,ans=0;
  cin>>H>>W;
  char S[H][W];
  REP(i,H){
    REP(j,W){
      cin>>S[i][j];
    }
  }
  
  REP(i,H){
    REP(j,W){
      if(S[i][j]=='#') continue;
      ll DIS[H][W];
      bool CAN[H][W];
      REP(k,H){
        REP(l,W){
          DIS[k][l]=MAX;
          CAN[k][l]=false;
        }
      }
      DIS[i][j]=0;
      
      queue<pair<ll,ll>> Q;
      Q.push(MP(i,j));
      while(!Q.empty()){
        auto it=Q.front();
        Q.pop();
        ll vx=it.first,vy=it.second;
        CAN[vx][vy]=true;
        REP(k,4){
          ll nx=vx+dx[k],ny=vy+dy[k];
          if(nx<0 || H<=nx || ny<0 || W<=ny) continue;
          if(S[nx][ny]=='#' || CAN[nx][ny]) continue;
          chmin(DIS[nx][ny],DIS[vx][vy]+1);
          Q.push(MP(nx,ny));
          CAN[nx][ny]=true;
        }
      }
      
      REP(k,H){
        REP(l,W){
          if(DIS[k][l]!=MAX) chmax(ans,DIS[k][l]);
        }
      }
    }
  }
  
  co(ans);
  return 0;
}

Measured memory_bytes: 3616
# -*- coding: utf-8 -*-
import sys
from heapq import heappop,heappush
from collections import deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N,C = map(int,readline().split())
data = [[] for _ in range(C+1)]
for i in range(N):
    s,t,c = map(int,readline().split())
    data[c].append((s,t))

TV = []
for d in data:
    N = len(d)
    if N == 0:
        continue
    d = sorted(d)
    g = d[0][1]
    cnt = 0
    for i in range(N-1):
        if g == d[i+1][0]:
            cnt += 1
        else:
            TV.append((d[i-cnt][0],d[i][1]))
            cnt = 0
        g = d[i+1][1]
    TV.append((d[-(1+cnt)][0],d[-1][1]))

TV = sorted(TV)
len_TV = len(TV)
q = [TV[0][1]]

for i in range(1,len_TV):
    s = TV[i][0]
    g = TV[i][1]
    m = heappop(q)
    if m >= s:
        heappush(q,m)
    heappush(q,g)

print(len(q))

Measured memory_bytes: 84040
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES	// M_PI=3.1415...
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 20桁出力 cout << setprecision(20) << double;
#include <queue>
#include <bitset>	// bitset<8> bs1(131uL); // 10000011 bs1[0]は1 01stringからビット集合生成可
#include <numeric>
#include <random>
#include <climits>  // A/Bを計算するときA==LLONG_MIN && B==-1のみ(1ull<<63)で代用
using namespace std;

typedef long long LL;
typedef pair<LL, LL> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;				// VVL v(100,VL(100,0));
typedef vector<pair<LL, LL> > VP;
typedef vector<string> VS;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef multimap<int, string, greater<int> > MuMIS;
typedef pair<LL, pair<P, P> > PP;

#define INF 999999999999999997		// 少し加算したらオーバーフローする
#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(LL i=(a);i<(b);i++)
#define FOR_REV(i,a,b) for(int i=(a);i>=(b);i--)
#define FOR_ITR(d) for(auto itr=d.begin(),d_end=d.end();itr!=d_end;++itr)	// C++11
#define O(s) cout<<s<<endl;
#define SORTVL(v) sort(v.begin(), v.end());
#define SORTVL_GR(v) sort(v.begin(), v.end(), greater<LL>());

#define DUMP_VVI(b) if(dbgF){FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}

template<class T>T IN() { T d; cin >> d; return d; }

LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a % b) : a; } // 最大公約数（Greatest Common Divisor）
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; } // 最小公倍数（Least Common Multiple）
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false); } // うるう年判定
string Replace(string S, string from, string to) { auto p = S.find(from); while (p != string::npos) { S.replace(p, from.size(), to); p = S.find(from, p + to.size()); }return S; }
// 桁和
LL Ketawa_s(string s) { LL a = 0; FOR(i, 0, s.length())a += s[i] - '0'; return a; }
// 末尾数字で切り上げ
LL CeilLastNumber(LL n) { return ((n + (10 - 1)) / 10) * 10; }
//二項係数 nCk mod pを求める
const LL MAX = 510000, p = 998244353; LL fac[MAX], finv[MAX], inv[MAX];
/* 前処理 */void COM_init() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; FOR(i, 2, MAX) { fac[i] = fac[i - 1] * i % p; inv[i] = p - inv[p % i] * (p / i) % p; finv[i] = finv[i - 1] * inv[i] % p; } }
/* 主処理 */LL COM(int n, int k) { if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % p) % p; }

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int dxx[8] = { 0,1,1,1,0,-1,-1,-1 };
int dyy[8] = { 1,1,0,-1,-1,-1,0,1 };

// -------------------------------------------------------------------------------

int main() {
	FAST_IO;
	bool dbgF = true; // for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;

	string S;
	cin >> S;
	FOR(i, 0, S.length()) {
		cout << "x";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    if(a+b<10){
      System.out.println(a+b);
    }else{
      System.out.println("error");
    }
  
  }
}

Measured memory_bytes: 21716
N = [int(_) for _ in input().split()]

def solve(N):
    N[0], N[1] = N[1], N[0]
    N[0], N[2] = N[2], N[0]
    
    return str(N[0]) + " " + str(N[1]) + " " + str(N[2])

print(solve(N))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

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

    ll n;
    cin>>n;
    vector<ll> ar(n),br(n);
    for(ll i=0;i<n;++i){cin>>ar[i];}
    for(ll i=0;i<n;++i){cin>>br[i];}

    ll power[30];
    power[0]=1;
    for(ll i=1;i<30;++i){power[i]=2*power[i-1];}

    ll ans=0;
    for(ll i=0;i<29;++i)
    {
        ll t=power[i];
        vector<ll> ch(n);
        for(ll j=0;j<n;++j){
            ch[j]=br[j]%(2*t);
        }
        sort(ch.begin(),ch.end());
        ll count=0;
        for(ll j=0;j<n;++j){
            ll x=ar[j]%(2*t);
            count+=lower_bound(ch.begin(),ch.end(),2*t-x)-lower_bound(ch.begin(),ch.end(),t-x);
            count+=lower_bound(ch.begin(),ch.end(),4*t-x)-lower_bound(ch.begin(),ch.end(),3*t-x);
        }
        ans+=(count%2)*power[i];
    }
    cout<<ans;

    return (0);
}


Measured memory_bytes: 4992
#include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <algorithm>
#include <limits>
#include <map>

using namespace std;
typedef long long ll;
bool sol(vector<ll> v) {
    ll d = v[1] - v[0];
    for (int i = 0; i < v.size(); i++) {
        if (v[i] != v[0]+d*i) return false;
    }
    return true;
}
int main() {
    while(1) {
        int n;
        cin >> n;
        if (!n) break;
        ll d[200];
        vector<ll> vv;
        vector<ll> v[200];
        for (int i = 0; i <= n; i++) {
            cin >> d[i];
            vv.push_back(d[i]);
            for (int j = 0; j <= n; j++) {
                if (i == j) continue;
                v[j].push_back(d[i]);
            }
        }
        assert(!sol(vv));
        set<int> s;
        int u = 0;
        for (int i = 0; i <= n; i++) {
            if (sol(v[i])) {
                u++;
        //        cout << d[i] << endl;
                s.insert(d[i]);
                //break;
            }
        }
        assert(s.size() == 1);
        cout << *s.begin() << endl;
        //assert(u <= 1);
    }
    return 0;
}

Measured memory_bytes: 1336
H,W,N = map(int, input().split())
st = [int(i) for i in input().split()]
S = input()
T = input()


def simu(dim1):
    now = [st[0],st[1]]

    if dim1 == 'U':
        dim2,L,step,dim = 'D',H,1,0
    if dim1 == 'D':
        dim2,L,step,dim = 'U',H,-1,0
    if dim1 == 'L':
        dim2,L,step,dim = 'R',W,1,1
    if dim1 == 'R':
        dim2,L,step,dim = 'L',W,-1,1

    for i in range(N):
        if S[i] == dim1:
            now[dim] -= step
        if now[dim] < 1 or now[dim] >= L+1:
            return True
        if T[i] == dim2:
            if step == 1:
                if now[dim] < L:
                    now[dim] += step
            else:
                if now[dim] > 1:
                    now[dim] += step
    return False
        
Dim = ['U','R','D','L']
for d in Dim:
    if simu(d):
        print('NO')
        exit()
print('YES')


Measured memory_bytes: 42192
#include<cstdio>
#include<map>

using namespace std;

int n, a[200005];
map<int, int> m;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    ++m[a[i]];
  }
  long long res = 0;
  for (auto it = m.begin(); it != m.end(); ++it) {
    res += it->second * (it->second - 1ll) / 2;
  }
  for (int i = 0; i < n; i++) {
    printf("%lld\n", res - m[a[i]] * (m[a[i]] - 1ll) / 2 + (m[a[i]] - 2ll) * (m[a[i]] - 1ll) / 2);
  }
}


Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
using namespace std;
using ll = long long;
using vi = vector<int>;

int main() {
  int N;
  cin >> N;
  vi A(N);
  rep(i, N) cin >> A[i];
  ll ans = 0;
  int prev = A[0];
  rep(i, N - 1) {
    if (A[i + 1] < prev) {
      ans += prev - A[i + 1];
    } else {
      prev = A[i + 1];
    }
  }

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


Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

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

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    ll n,suma = 0,sumb = 0,b;
    cin >> n;
    vector<ll> a(n);
    rep0(i, n){
        cin >> a[i];
    }
    rep0(i, n){
        cin >> b;
        if (a[i] < b) {
            sumb += (b - a[i])/2;
        }else{
            suma += a[i] - b;
        }
    }
    
    if (suma <= sumb) {
        Yes;
    }else{
        No;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <array>
using namespace std;

int main()
{
	int n;
	while(cin >> n, n) {
		vector<string> v(n);
		for(int i = 0; i < n; ++i) {
			cin >> v[i];
			v[i].append(51 + n - v[i].size(), '#');
		}
		
		for(int i = 0; i < n; ++i) {
			for(int j = v[i].size() - 1; j >= 0; --j) {
				if(v[i][j] == '.') {
					v[i][j] = '+';
					break;
				}
			}
		}

		for(int i = 0; i <= 50 + n; ++i) {
			int prev = -1;
			for(int j = 0; j < n; ++j) {
				if(v[j][i] == '+') {
					if(prev == -1) {
						prev = j;
					} else {
						for(int k = prev + 1; k < j; ++k) {
							v[k][i] = '|';
						}
						prev = j;
					}
				} else if('a' <= v[j][i] && v[j][i] <= 'z') {
					prev = -1;
				}
			}
		}

		/*for(int i = 0; i < n; ++i) {
			cout << v[i] << endl;
		}*/
		
		for(int i = 0; i < n; ++i) {
			for(int j = 0; j <= 50 + n; ++j) {
				if(v[i][j] == '#') break;
				

				cout << (v[i][j] == '.' ? ' ' : v[i][j]);
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 4384
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

//long mod = 10^^9 + 7;
long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto N = RD;
	auto A = RDA;

	bool ok = A[0] == 0;
	auto m1 = new long[](N);
	auto m2 = new long[](N);
	{
		long cnt = 1;
		foreach (i; 1..N+1)
		{
			cnt *= 2;
			m1[i-1] = cnt;
			cnt -= A[i];
		}
	}
	{
		long cnt;
		foreach_reverse (i; 1..N+1)
		{
			cnt += A[i];
			m2[i-1] = cnt;
		}
	}
	debug writeln(m1);
	debug writeln(m2);

	debug writeln("ok:", ok);
	long last = 1;
	long ans = 1;
	foreach (i; 1..N+1)
	{
		auto num = min(m2[i-1], last*2);
		if (num < last || num <= 0)
		{
			debug writeln("i:", i);
			ok = false;
			break;
		}
		ans += num;
		last = num - A[i];
	}
	if (last != 0)
		ok = false;

	if (N == 0 && A[0] == 1)
		writeln(1);
	else if (!ok)
		writeln(-1);
	else
		writeln(ans);
	stdout.flush;
	debug readln;
}

Measured memory_bytes: 7740
# coding: utf-8
# Your code here!

N = int(input())
A = list(map(int, input().rstrip().split()))

A = sorted(A)

t = 1
inf = int(1e18)
f = False
for i in range(N):
    t *= A[i]
    if t > inf:
        f = True
        break
        
if f:
    print(-1)
else:
    print(t)

Measured memory_bytes: 84624
from bisect import bisect

n = int(input())
x = list(map(int, input().split()))
l = int(input())
q = int(input())

#r[i][j]: jから(2**i)日で行ける右端
r = [[i for i in range(n)] for _ in range(18)]
for j in range(n):
	r[0][j] = bisect(x, x[j]+l) - 1
for i in range(1, 18):
	for j in range(n):
		r[i][j] = r[i-1][r[i-1][j]]

def search(x, y):
	res = 0
	cur = x
	while True:
		for i in range(18):
			if r[i][cur] >= y:
				if i == 0:
					return res+1
				cur = r[i-1][cur]
				res += 1 << (i-1) 
				break

for _ in range(q):
	a, b = map(int, input().split())
	print(search(min(a, b)-1, max(a, b)-1))

Measured memory_bytes: 118680
#include <iostream>
#include <algorithm>
using namespace std;
long long N;
int main() {
	cin >> N;
	int ret = 0;
	for (int i = 0; i < 18; i++) {
		long long mul = 1;
		for (int j = 0; j < i; j++) mul *= 10;
		for (int j = 1; j <= 9; j++) {
			long long x = mul * (j + 1) - 1;
			if (x <= N) ret = max(ret, i * 9 + j);
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
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;}

#define INF 1120000000

vector<int> g[100005];
int col[100005];

bool dfs(int v, int c, int from=-1){
  col[v] = c;
  for(auto to : g[v]) if(to != from){
    if(col[to] == -1){
      if(!dfs(to, !c, v)) return false;
    } else {
      if(col[to] == col[v]) return false;
    }
  }
  return true;
}

int main(){
  int n,m;
  cin>>n>>m;
  rep(i,m){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  fill(col, col+n, -1);
  bool bl = dfs(0,1);

  if(bl){
    int x=0,y=0;
    rep(i,n){
      if(col[i]) x++;
      else y++;
    }
    cout << (long)x*y - m << endl;
  }
  else {
    cout <<(long)n*(n-1)/2 - m << endl;
  }

  return 0;
}


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

long long a, b;

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

int main()
{
    cin >> a >> b;
    cout << a * b / gcd(a, b);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

char *pronounce(int N);

void main()
{
    int N;

    scanf("%d", &N);
    printf("%s", pronounce(N));
}

char *pronounce(int N)
{
    if (N % 10 == 3)
        return "bon";
    if (N % 10 == 0)
        return "pon";
    if (N % 10 == 1)
        return "pon";
    if (N % 10 == 6)
        return "pon";
    if (N % 10 == 8)
        return "pon";
    else
        return "hon";
}


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

#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define phi 3.1415926535
 
using namespace std;
 
ll tc, cnt = 0, number, many, total = 0;
int rmove[4] = {0, 0, -1, 1};
int cmove[4] = {1, -1, 0, 0};



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // freopen("input.txt","r", stdin);
    // freopen("output.txt","w", stdout);
    // g++ -std=c++11 Default.cpp  -o test

    int many;
    cin >> many;

    int arr[many], sorted[many];
    for(int i = 0; i < many; i++)
    {
        cin >> arr[i];
        sorted[i] = arr[i];
    }

    sort(sorted, sorted + many);

    int answer = 0;
    for(int i = 0; i < many; i++)
    {
        if(sorted[i] != arr[i])
            answer++;
    }

    if(answer == 2 || answer == 0)
        cout << "YES";
    else
        cout << "NO";
    cout << endl;
    
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

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

ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}

int main(){
    ios::sync_with_stdio(false);
    deque<char> ans;
    string s; cin >> s;
    int q; cin >> q;
    for(char c:s) ans.push_back(c);
    bool flip=false;
    rep(i,q){
        int t;
        cin >> t;
        if(t==1){
            flip=!flip;
        } else{
            int f; char c;
            cin >> f >> c;
            if(!flip){
                if(f==1) ans.push_front(c);
                else ans.push_back(c);
            } else{
                if(f==1) ans.push_back(c);
                else ans.push_front(c);
            }
        }
    }
    if(flip) reverse(ans.begin(),ans.end());
    rep(i,ans.size()){
        cout << ans[i];
    }
    return 0;
}

Measured memory_bytes: 976
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(void){
  ll x,k,d;
  cin >> x >> k >> d;
  if (abs(x)/d > k) {
    cout << abs(x)-d*k << endl;
  }
  else{
    k-=abs(x)/d;
    x = abs(x)-d*(abs(x)/d);
    cout << abs(x-d*(k%2)) << endl;
  }
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

#define int long long

/*************** using variables ***************/
int n;
vector<LL> a, b;
vector<bool> close;
/**********************************************/

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n;
    a.resize(n);
    b.resize(n);
    close.resize(n);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];
    
    LL amari = 0;
    REP(i, n){
        if(a[i] < b[i]){
            amari += (b[i] - a[i]) / 2;
            close[i] = true;
        }
    }
    REP(i, n){
        if(close[i]) continue;
        
        if(a[i] <= b[i] + amari){
            amari -= a[i] - b[i];
            close[i] = true;
        }
    }
    REP(i, n){
        if(!close[i]){
            cout <<  "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

using namespace std;
using ll = long long;

using Field = vector<vector<int>>;
using Graph = vector<vector<int>>;
using VI = vector<int>;
using VC = vector<char>;
using PI = pair<int, int>;

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

const long long INF = 1LL<<60;
const int mod = 1000000007;

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

int N, M;
vector<int> A;

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

    cin >> N >> M;
    A.resize(M, 0);
    REP(i, M) cin >> A.at(i);

    ll sum = 0;
    ll ans = 0;

    for (auto x:A) sum += x;
    if (sum > N) ans = -1;
    else ans = N - sum;

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

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

mx = [-1]*n
mn = [float('inf')]*n
val = [0]*n
for i in range(n):
    v = int(input())
    mx[i] = mn[i] = v

for i in range(1,n):
    mx[n-i-1] = max(mx[n-i-1],mx[n-i])
    mn[i] = min(mn[i],mn[i-1])

ans = -float('inf')
for i in range(n-1):
    ans = max(ans,mx[i+1]-mn[i])

print(ans)



Measured memory_bytes: 16540
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<utility>
#include<queue>
#include<algorithm>
using namespace std;
char x,y;
int main(){
  cin>>x>>y;
  if(x>y)cout<<">"<<endl;
  else if(x==y)cout<<"="<<endl;
  else cout<<"<"<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys
input=sys.stdin.readline
n,q=map(int, input().split())
*c,=map(int, input().split())

qu=[list(map(int, input().split())) +[i] for i in range(q)]
qu.sort(key=lambda x:x[1])
bit=[0]*(n+1)

last=[-1]*(n+1)

def add(t,x):
    while t<=n:
        bit[t]+=x
        t += t&(-t)

def query(t):
    res=0
    while t:
        res+=bit[t]
        t-=t&(-t)
    return res

used=1
ans=[0]*q
for l,r,i in qu:
    while used<=r:
        add(used,1)
        if last[c[used-1]]>=0:
            add(last[c[used-1]],-1)
        last[c[used-1]]=used
        used+=1
    ansi=query(r)-query(l-1)
    ans[i]=ansi
for ansi in ans:
    print(ansi)


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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;


int main()
{
	ll n, m;
	cin >> n >> m;

	ll v[1010101];
	memset(v, 0, sizeof(v));

	for (int i = 0; i < m; i++) {
		ll a, b;
		cin >> a >> b;
		v[a-1]++;
		v[b-1]++;
	}
	for (int i = 0; i < n; i++) {
		if (v[i]%2!=0) {
			cout << "NO" << "\n";
			return 0;
		}
	}
	cout << "YES" << endl;
}


Measured memory_bytes: 8192
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>

using namespace std;

#define REP(i,n) for (int i=0;i<(n);++i)
#define REP2(i,n) for (int i=0;i<=(n);++i)
#define REP3(i,n) for (int i=1;i<=(n);++i)

static const int MAXN = 1001;
static const int MAXM = 1001;
static const int INF = 1e5;

int main() {

	int N;
	cin >> N;
	
	int a,sum;
	a = N;
	sum = 0;
	while (a > 0) {
		sum += a % 10;
		a /= 10;
		//cout << a  << " " << sum << endl;
	}

	//cout << sum;

	if (N%sum == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	

	//int end;
	//cin >> end;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

// template <class T> void vecout(T V) {
//     auto t = V.begin();
//     while(t != V.end()) {
//         cout << *t++;
//         if(t != V.end())
//             cout << " ";
//     }
//     cout << endl;
// };

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

    int A, B;
    cin >> A >> B;
    cout << max({A + B, A - B, A * B});
}

Measured memory_bytes: 256
from scipy.sparse import*
_,*s=open(0)
M=999
*g,=eval('[0]*M,'*M)
i=0
for t in s:
 i+=1;j=0
 for u in t:k=i*20+j;g[k][k+20]=u>'#'<(s+['#'*M])[i][j];j+=1;g[k][k+1]=u>'#'<t[j]
a=csgraph.johnson(csr_matrix(g),0)
print(int(max(a[a<M])))

Measured memory_bytes: 31908
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;
#define INF 100000000
typedef long long ll;

int n, m;

// UnionFind
#define MAXN 110
int par[MAXN], rank[MAXN];

void init(int n_) {
    for (int i = 0; i < n_; i++) {
        par[i] = i;
        rank[i] = 0;
    }
}

int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);
}

void unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) par[x] = y;
    else {
        par[y] = x;
        if (rank[x] == rank[y]) rank[x]++;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

// kruskal
#define MAXM 100010
struct edge {
    int from, to, cost;
};

bool comp(const edge &e1, const edge &e2) {
    return e1.cost < e2.cost;
}

edge es[MAXM];

int kruskal(void) {
    sort(es, es+m, comp);
    init(n);
    int ret = 0;
    for (int i = 0; i < m; i++) {
        edge e = es[i];
        if (!same(e.from, e.to)) {
            unite(e.from, e.to);
            ret += e.cost;
        }
    }
    return ret;
}
int main(void) {
    while (cin >> n >> m && n && m) {
        for (int i = 0; i < m; i++) {
            cin >> es[i].from >> es[i].to >> es[i].cost;
        }
        cout << kruskal() << endl;
    }
    return 0;
}

Measured memory_bytes: 1184
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#define MAXN 200001

int n, m, k, ans, a[MAXN], b[MAXN];
long long suma[MAXN], sumb[MAXN];

int max(int a, int b) { return a > b ? a : b; }

int main() {
	scanf("%d %d %d", &n, &m, &k);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		suma[i] = suma[i - 1] + a[i];
	}
	for (int i = 1; i <= m; ++i) {
		scanf("%d", &b[i]);
		sumb[i] = sumb[i - 1] + b[i];
	}
	for (int i = 0; i <= n; ++i) {
		int temp = k - suma[i];
		if (temp == 0) ans = max(ans, i);
		if(temp < 0) break;
		int pos = std::upper_bound(sumb + 1, sumb + m +1, temp) - sumb;
		ans = max(ans, i + pos - 1);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 8508
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#define M 1000000007
typedef unsigned long long int ll;
int main()
{
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll p,q,r,s;
    ll l=c/(__gcd(c,d));
    l*=d;
    p=(b/c)-((a-1)/c);
    q=(b/d)-((a-1)/d);
    r=(b/l)-((a-1)/l);
    s=p+q-r;
    cout<<b-a+1-s;


}


Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Test1 {

    


    class ClassMain {

        static bool[,] remainJ = new bool[21,21];
        static int robX = 10, robY = 10;

        public static void roboMv(string dir, int n) {
            char ch = dir[0];
            for (int i = 0; i < n; i++) {
                if (ch == 'N') { robY++; }
                else if (ch == 'E') { robX++; }
                else if (ch == 'S') { robY--; }
                else if (ch == 'W') { robX--; }
                if (remainJ[robY, robX]) { remainJ[robY, robX] = false; }
                //Console.WriteLine(robX + "x y" + robY);
            }
        }

        public static bool takeAllJ() {
            for (int i = 0; i <= 20; i++) {
                for (int j = 0; j <= 20; j++) {
                    if (remainJ[i, j]) { return false; }
                }
            }
            return true;
        }

        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line);
                if (n == 0) { break; }
                remainJ = new bool[21, 21];
                robX = 10; robY = 10;
                for (int i = 0; i < n; i++) {
                    int[] ints = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    remainJ[ints[1], ints[0]] = true;
                }
                int m = int.Parse(Console.ReadLine());
                for (int i = 0; i < m; i++) {
                    string[] strs = Console.ReadLine().Split(' ');
                    roboMv(strs[0], int.Parse(strs[1]));
                }
                if (takeAllJ()) {
                    Console.WriteLine("Yes");
                }
                else {
                    Console.WriteLine("No");
                }

            }
        }

        
    }



    
}

Measured memory_bytes: 5908
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll x,y,a,b,c;
 	cin>>x>>y>>a>>b>>c;
 	vector<ll> r(a),g(b),l(c);
 	for(ll i=0;i<a;i++)cin>>r[i];
 	for(ll i=0;i<b;i++)cin>>g[i];	
 	for(ll i=0;i<c;i++)cin>>l[i];
 	sort(r.rbegin(),r.rend());
 	sort(g.rbegin(),g.rend());
 	sort(l.rbegin(),l.rend()); 
 	ll ans=0;
 	multiset<ll>t;
 	for(ll i=0;i<x;i++)
 	{
 		ans+=r[i];
 		t.insert(r[i]);
 	}
 	for(ll i=0;i<y;i++)
 	{
 		ans+=g[i];
 		t.insert(g[i]);
 	}
 	for(ll i=c-1;i>=0;i--)
 	{
 		ll top = *t.begin();
 		if(top<l[i])
 		{
 			t.erase(t.begin());
 			ans-=top;
 			ans+=l[i];
 			t.insert(l[i]);
 		}
 	}
 	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11008
H, W, M = map(int,input().rstrip().split())
bomb = []
r = [0]*H
c = [0]*W
max_r = 0
max_c = 0
r_i = []
c_j = []
r_num = 0
c_num = 0
for i in range(M):
    h, w = map(int,input().rstrip().split())
    bomb.append([h-1,w-1])
    r[h-1] += 1
    if r[h-1]>max_r:
        max_r = r[h-1]
        r_i = [h-1]
        r_num = 1
    elif r[h-1]==max_r:
        r_i.append(h-1)
        r_num += 1
    c[w-1] += 1
    if c[w-1]>max_c:
        max_c = c[w-1]
        c_j = [w-1]
        c_num = 1
    elif c[w-1]==max_c:
        c_j.append(w-1)
        c_num += 1
r_set = set(r_i)
c_set = set(c_j)
num = 0
for i in range(M):
    if bomb[i][0] in r_set:
        if bomb[i][1] in c_set:
            num += 1
if num<r_num*c_num:
    ans = max_r+max_c
else:
    ans = max_r+max_c-1
print(ans)

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

using namespace std;

void print(vector <int> v) {
    for (int i=0; i<v.size(); i++) {
        cout << v[i] << " ";
    }
    cout << "\n";
}

int search(vector <int> v, int index) {
    if (index > 0 && index < v.size()) {
        return v[index];
    } else {
        return 0;
    }
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    
    int n;
    cin >> n;
    vector<int> r;
    vector<int> g;
    vector<int> b(n+1);
    for (int i=1; i<=n; i++) {
        char ch;
        cin >> ch;
        if (ch == 'R') {
            r.push_back(i);
        } else {
            if (ch == 'G') {
                g.push_back(i);
            } else {
                b[i] = 1;
            }
        }
    }
    long long total = 0;
    int c;
    int bs = n-r.size()-g.size();
    for (int i=0; i<r.size(); i++) {
        for (int j=0; j<g.size(); j++) {
            if (r[i] > g[j]) {
                int diff = r[i] - g[j];
                if (diff%2) {
                    c = search(b, r[i]+diff) + search(b, g[j]-diff);
                } else {
                    c = search(b, r[i]+diff) + search(b, g[j]-diff) + search(b, g[j]+diff/2);
                }
            } else {
                int diff = g[j] - r[i];
                if (diff%2) {
                    c = search(b, g[j]+diff) + search(b, r[i]-diff);
                } else {
                    c = search(b, g[j]+diff) + search(b, r[i]-diff) + search(b, r[i]+diff/2);
                }
            }
            total += bs - c;
        } 
    }
    cout << total << "\n";
}

Measured memory_bytes: 3676
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_DISABLE_PERFCRIT_LOCKS
#define POPCNTI(a) __builtin_popcount(a)
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <bits/stdc++.h>
 
using namespace std;
using namespace  __gnu_pbds;
 
// #ifndef _LOCAL_DEFINE
// inline int getchar_unlocked(){return _getchar_nolock();}
// inline void putchar_unlocked(char c) {_putchar_nolock(c);}
// #endif
 
typedef long long ll;  
typedef pair<int,int> pr; 
 
const ll MOD = 1e9 + 7,OOl=LLONG_MAX;
const int N = 1e6+1, M = 1e6+1, OO = INT_MAX,OOmem = 0x4f4f4f4f;
 
inline void WRITE_CHAR(char c)  {putchar_unlocked(c);}
 
template<typename T> 
inline bool READn (T &result) {
  int minus = 1;
  char ch;
  result=0;
  ch = (char) getchar_unlocked();
  if(ch!='-') while (!isdigit(ch) && ch!=EOF) ch= (char) getchar_unlocked(), minus = (ch == '-'? -1 : minus);
 
  if(ch==EOF) return false;
  while (isdigit(ch))  result = result*10 + (int) (ch - '0'),ch = (char) getchar_unlocked();
  
  result *= minus;
  return ch != '\n';
}
template<typename T>
inline void WRITEn(T x) {
  if (x < 0) {putchar_unlocked('-'); x = -x; }
  char writeBuffer[20], *writePtr = writeBuffer;
  do {
    *writePtr++ = (char)('0' + x % 10);
    x /= 10;
  }
  while (x);
  do  { putchar_unlocked(*--writePtr); }
  while (writePtr > writeBuffer);
}
inline bool Read_CHAR(char &c)
{
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  c = READ_CHARACTER;
  return true;
} 
inline bool READ_CHAR_ARRAY(char (&x)[N]) {
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  char *ptr = &x[0];
  while ((READ_CHARACTER != '\n' && READ_CHARACTER != '\t' && READ_CHARACTER != ' ' && READ_CHARACTER != EOF)) *ptr++ = READ_CHARACTER, READ_CHARACTER = (char)getchar_unlocked();
  *ptr = '\0';
  return true;
}
inline void WRITE_CHAR_ARRAY(const char *x) {
  while(*x != '\0')
    putchar_unlocked(*x++);
}
ll dp[2][N];
int w[101],cst[101];
int main()
{
  int n,W;
  READn(n),READn(W);
  for(int i=0;i<n;++i) READn(w[i]),READn(cst[i]);

  dp[0][0]=0;
  for(int i=1;i<=n;++i)
  {
    for(int sum = 1 ; sum<=W ; ++sum)
    {
      dp[i&1][sum] = dp[!(i&1)][sum];
      if(sum>=w[i-1]) dp[i&1][sum] = max(dp[i&1][sum],dp[!(i&1)][sum-w[i-1]]+cst[i-1]);
    }
  }
  WRITEn(dp[n&1][W]);
  return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define GET_ARRAY_SIZE(a)   (sizeof(a)/sizeof(a[0]))
#define LL long long
#define VI vector<int>
#define VL vector<LL>
#define VII vector< vector<int> >
#define VLL vector< vector<LL> >
#define VS vector<string>
#define PII pair<int,int>
#define PIS pair<int,string>
#define PSI pair<string,int>
#define PLL pair<ll,ll>
LL facctorialMethod(int k);
int main(){
    LL h,n,d,dsum;
    cin >> h >> n;
    VL a(n);
    dsum = 0;
    bool h_over = false;
    for(int i = 0; i < n; i++) {
        cin >> d;
        dsum += d;
        if(h <= dsum) {
            h_over = true;
            break;
        }
    }
    if(h_over) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

LL facctorialMethod(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i){
        sum *= i;
    }
    return sum;
}


Measured memory_bytes: 3952
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;

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

    int N, K ;
    cin >> N >> K;
    vector<int> a(N,0);
    REP(i,N){
        cin >> a[i];}
    sort(ALL(a));
    int ans = 0, lo = -1, hi = N;
    while(hi-lo>1){
        int mid = (hi+lo)/2;
        vector<vector<int>> dp(N+1,vector<int>(K+1, 0));
        dp[0][0] = 1;
        int f = 0;
        REP(i,N){
            if (i==mid) f = 1;
            else{
                REP(j,K+1){
                    if (j >= a[i]){
                        dp[i+1-f][j] = dp[i-f][j] || dp[i-f][j-a[i]];
                    }
                    else{
                        dp[i+1-f][j] = dp[i-f][j];
                    }
                }
            }
        }
        f = 1;
        for(int i = max(0,K-a[mid]); i < K; ++i){
            if (dp[N-1][i]== 1) f = 0;
        }
        if (f==0) hi = mid;
        else lo = mid;
    }
    cout << hi << endl;
    return 0;
}


Measured memory_bytes: 98232
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

int h,w;int dp[1100][1100];bool a[1100][1100];
signed main() {
  cin>>h>>w;
  rep(i,h){
    rep(j,w){
      char c;cin>>c;a[i+1][j+1] = (c == '.');
    }
  }
  rep(i,h)dp[i][0] = 0;rep(i,w)dp[0][i] = 0;
  dp[1][1] = 1;
  repd(i,1,h+1){
    repd(j,1,w+1){
      if(i == j && i == 1)continue;
      if(!a[i][j])dp[i][j] = 0;
      else dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MOD;
    }
  }

  cout << dp[h][w] << endl;
}

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

int to_int(string s){
	int p=0;
	int res=0;
	while(p<s.size()){
		int count=1;
		if(isdigit(s[p])){
			count=s[p]-'0';
			p++;
		}
		if(s[p]=='m') res+=count*1000;
		else if(s[p]=='c') res+=count*100;
		else if(s[p]=='x') res+=count*10;
		else if(s[p]=='i') res+=count;
		p++;
	}
	return res;
}

string to_string(int n){
	string res="";
	if(n/1000>0){
		if(n/1000>1) res+='0'+n/1000;
		res+='m';
		n%=1000;
	}
	if(n/100>0){
		if(n/100>1) res+='0'+n/100;
		res+='c';
		n%=100;
	}
	
	if(n/10>0){
		if(n/10>1) res+='0'+n/10;
		res+='x';
		n%=10;
	}
	if(n>0){
		if(n>1) res+='0'+n;
		res+='i';
	}
	return res;

}

int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		string s1,s2;
		cin>>s1>>s2;
		cout<<to_string(to_int(s1)+to_int(s2))<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (unsigned int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    int A,B,C,D;
    string S,T;
int main(){
    cin>>A>>B>>C>>D;

    if(abs(A-C)<=D||(abs(A-B)<=D&&abs(B-C)<=D))cout<<"Yes";
    else cout<<"No";
    return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>

using namespace std;
int n;
const int maxn = 1e7+5;//40M
const int S = 1e7+2;
int pri[maxn],cnt; bool mk[maxn];
int A[maxn];
void oula() {
	mk[1] = mk[0] = 1;
	for(int i=2;i<=S;i++) {
		if(!mk[i]) { pri[++cnt]=i; }
		for(int j=1;j<=cnt&&1ll*pri[j]*i<=S;j++) {
			int k = pri[j]*i;
			mk[k] = 1;
			if(i%pri[j]==0) break;
		}
	}
}
int la[405],en[405*405],owo,nt[405*405];
void adg(int x,int y) {
	en[++owo]=y; nt[owo]=la[x]; la[x]=owo;
}
int cc[2];
int yo[2][405];
int link[405],vis[405];
int hungary(int x) {
	for(int it=la[x];it;it=nt[it]) {
		int y = en[it];
		if(vis[y]) continue;
		vis[y] = 1;
		if((!link[y])||(hungary(link[y]))) {
			link[y] = x; return 1;
		}
	}
	return 0;
}
int main() {
	oula();
	scanf("%d",&n);
	for(int i=1;i<=n;i++) {
		int x; scanf("%d",&x); A[x] = 1;
	}
	for(int i=1;i<=S;i++) {
		int cf = A[i-1]^A[i];
		if(cf) {
			++cc[i&1];
			yo[i&1][ cc[i&1] ] = i;
		}
	}
	for(int i=1;i<=cc[0];i++) {
		for(int j=1;j<=cc[1];j++) {
			if(!mk[abs(yo[0][i]-yo[1][j])])
			adg(i,j);
		}
	}
	int ans = 0;
	for(int i=1;i<=cc[0];i++) {
		for(int j=1;j<=cc[1];j++) vis[j] = 0;
		ans += hungary(i);
	}
	cc[0]-=ans; cc[1]-=ans;
	ans += cc[0]/2*2 + cc[1]/2*2 + (cc[0]&1)*3;
	printf("%d",ans );
}

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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  for(int i=0; i<n; i++){
    cin >> d[i];
  }
  int count = 0;
  int temp = 1;
  for(int i=0; i<n; i++){
    if(d[i]==0)
      continue;
    
    count++;
    for(int j=i+1; j<n; j++){
      if(d[j]==d[i])
        d[j]=0;
    }
  }
  
  cout << count <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt(); //1が書かれたカードの枚数
		int B = sc.nextInt(); //0が書かれたカードの枚数
		int C = sc.nextInt(); //-1が書かれたカードの枚数
		int K = sc.nextInt(); //選ぶカードの枚数
		int sum = 0; //選んだカードの合計
		String flag = null;

		if(A >= K) { //選ぶカードは全部1
			flag = "A";
		}else if(A + B >= K) { //選ぶカードは1と0
			flag = "B";
		}else if (A + B + C >= K) { //選ぶカードは1と0と-1
			flag = "C";
		}else { //K = 0
			sum = 0;
		}

		switch(flag) {
		case "A":
			sum = K;
			break;
		case "B":
			sum = A;
			break;
		case "C":
			sum = A - (K - A - B);
		}

		System.out.print(sum);
	}

}


Measured memory_bytes: 35564