akhauriyash/Code-Regression huggingface dataset:
X=int(input())
han=0
for a in range(1001):
    if a * 100 > X:
        break
    for b in range(1001-a):
        if a * 100 + b * 101 > X:
            break
        for c in range(1001-a-b):
            if a * 100 + b * 101 + c * 102 > X:
                break
            for d in range(1001-a-b-c):
                if a * 100 + b * 101 + c * 102 + 103 * d> X:
                    break
                for e in range(1001-a-b-c-d):
                    if a * 100 + b * 101 + c * 102 + 103 * d + 104 * e>X:
                       break
                    for f in range(1001-a-b-c-d-e):
                        if a * 100 + b * 101 + c * 102 + 103 * d + 104 * e + 105 * f>X:
                            break
                        if a*100+b*101+c*102+103*d+104*e+105*f==X:
                            print("1")
                            han=1
                            exit()

if han==0:
    print(0)

Measured memory_bytes: 73816
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

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


int N;
int I[256+1], R[256+1], O[256+1];
const int M = 256;

int main()
{
  while(1){
    cin >> N;
    if(N == 0) break;
    rep(i, N) cin >> I[i];
    double H = INF;
    int S = 0, A = 0, C = 0;
    rep(s, 15+1) rep(a, 15+1) rep(c, 15+1){
      memset(O, 0, sizeof(O));
      R[0] = s;
      for(int i=1;i<=N;i++) R[i] = (a*R[i-1] + c) % M;
      rep(i, N) O[(I[i]+R[i+1])%M]++;
      double h = 0;
      rep(i, 256){
	if(O[i] == 0) continue;
	h += -O[i] * log((double)O[i]/(double)N);
      }
      if(h + EPS < H){
	H = h;
	S = s;
	A = a;
	C = c;
      }
    }
    cout << S << " "<< A << " " << C << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
//#include<tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define lll bignum
#define ls(x) ( x << 1 )
#define rs(x) ( x << 1 | 1 )
//#define mid ( ( l + r ) >> 1 )
#define lowbit(x) ( x & -x )
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define re register
#define For(i, j, k) for(re int i = (j); i <= (k); ++i)
#define foR(i, j, k) for(re int i = (j); i >= (k); --i)
#define Cross(i, j, k) for(re int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 23;
const ll inf = 0x3f3f3f3f3f3f;

ll n, Ans = 0, V[N], C[N], f[N][N];

namespace IO {

	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; bool f = 0; char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = (x << 3) + (x << 1) + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write( ll x ) {
		if ( x < 0 ) putchar ('-'), x = -x;
		if ( x > 9 ) write ( x / 10 ); putchar ( x % 10 | 48 );
	}

	inline void wrn ( ll x ) { write (x); putchar (' '); }

	inline void wln ( ll x ) { write (x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn (x), wln (y); }

}

using namespace IO;

int main()
{
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	n = read(); 
	For ( i, 1, n ) V[i] = read();
	For ( i, 1, n ) C[i] = read();
	For ( i, 1, n ) if ( V[i] - C[i] > 0 ) Ans += V[i] - C[i];
	return wln (Ans), 0;
}

/*

*/



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

#define ll long long

int main() {
  ll n, a, b, cnt, num;
  cnt = LONG_LONG_MAX;
  cin >> n;
  for (a = 1; a <= sqrt(n); a++)
    if (n % a == 0) {
      b = n / a;
      if (a * b == n && cnt > (a + b - 2)) cnt = a + b - 2;
    }

  cout << cnt << endl;
}

Measured memory_bytes: 3664
/**
 *    author:  nasimnoob
**/

#include<bits/stdc++.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<math.h>
using namespace std;

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

typedef long long                       ll;
typedef unsigned long long              ull;
typedef long double                     ld;

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

#define      cube(x)                    (x*x*x)
#define      sqr(x)                     (x*x)
#define      PI                         acos(-1)

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

int main()
{
    //string ;
    int k,n,m,i,j,l=0,b;
    int a[1000]= {0};
    cin>>k>>m;
    while(m--)
    {
        cin>>n;
        for(i=1; i<=n; i++)
        {
            cin>>b;
            a[b]++;
        }
    }
    int count=0;
    for(i=1; i<=k; i++)
    {
        if(a[i]==0)
            count++;
    }
    cout<<count<<endl;
    return 0;
}




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

int BinarySearch(int S[],int n, int value){
    int left = 0, right = n, mid;
    while(left<right){
        mid = (left+right)/2;
        if(S[mid]==value) return 1;
        else{
            if(S[mid]>value) right = mid;
            else left = mid+1;
        }
    }
    return 0;
}

int main(){

//    for(int i=0;cin>>ch;++i){
//        printf("%c",ch);
//    }
//    while(cin>>ch)cout<<ch;
    int n,q;
    int S[100000+1];
    int sum = 0;
    int T;
    scanf("%d",&n);
    for(int i=0;i<n;++i) scanf("%d",&S[i]);
    scanf("%d",&q);
    for(int i=0;i<q;++i){
        scanf("%d",&T);
        sum += BinarySearch(S,n,T);
    }
    printf("%d\n",sum);
	return 0;
}



Measured memory_bytes: 3496
import sys
nodes = [0] * 100
for line in sys.stdin:
	frm, to = map(int, line.split())
	if frm == 0 and to == 0:
		if nodes[1] & 1 and nodes[2] & 1 and all(not(i & 1) for i in nodes[3:]):
			print "OK"
		else:
			print "NG"
		nodes = [0] * 100
	else:
		nodes[frm] += 1
		nodes[to] += 1

Measured memory_bytes: 4228
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void){
	int n;
	cin >> n;
	bool can = true;
	rep(i, 0, n) {
		int a;
		cin >> a;
		if (a % 2 == 0 ){
			if (a % 3 != 0 && a % 5 != 0) {
				can = false;
				break;
			}
		}
	}
	if (can)cout << "APPROVED"<< endl;
	else cout << "DENIED" << endl;
	return 0;
}


Measured memory_bytes: 256
// Problem: A - Frog 1
// Contest: AtCoder - Educational DP Contest
// URL: https://atcoder.jp/contests/dp/tasks/dp_a
// Parsed on: 2020-09-06 12:44:28
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include <algorithm>
#include <cmath>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

#define fastio  ios_base::sync_with_stdio(false); cin.tie(0);

using namespace std;

int main()
{
	int n;
	cin>>n;
	vector<int> dp(n), arr(n);
	for(auto&e: arr) cin >> e;
	dp[0] = 0;
	dp[1] = abs(arr[0] - arr[1]);
	for(int a=2;a<n;a++)
	{
		int ma = dp[a-2] + abs(arr[a-2] - arr[a]);
		int mb = dp[a-1] + abs(arr[a-1] - arr[a]);
		
		dp[a] = min(ma, mb);
	}
	
	cout << dp[n-1];
	return 0;
}


Measured memory_bytes: 3588
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

MOD=10**9+7
def exp(n,x)
  ans=1
  while x>0
      if (x&1).nonzero?
        ans*=n
        ans%=MOD
      end
      n*=n
      n%=MOD
      x/=2
  end 
  return ans
end

N,a,b=get_i
def cal(n,r)
    ans=1
    x=1
    1.upto(r) do|i|
      ans*=(n-i+1)
      x*=i
      ans%=MOD
      x%=MOD
    end
    return (ans*exp(x,MOD-2))%MOD
end

ans=exp(2,N)-1
#p ans
ans-=cal(N,a)
ans+=MOD if ans<0
ans-=cal(N,b)
ans+=MOD if ans<0
#p cal(N,a)
#p cal(N,b)
puts ans%MOD

Measured memory_bytes: 3964
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int s = sc.nextInt();
		
		int cnt = 0;
		for (int i = 0; i <= k; i++) {
			for (int j = 0; j <= k; j++) {
				int lastOne = s - i - j;
				if (lastOne >= 0 && lastOne <= k) {
					cnt++;
				}
			}
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007

int main () {
    ll  a, b, c ;
    cin >> a >> b >> c ; 
    ll d = c - a - b ;
    if(d > 0 && d * d > 4 * a * b){
        cout << "Yes" << endl ; 
    }
    else {
        cout << "No" << endl ; 
    }
}



Measured memory_bytes: 3580
#include<bits/stdc++.h>
#define up(j,k,i) for(ll i=j;i<k;i++)
#define down(j,k,i) for(ll i=j;i>k;i--)
#define M 1000000007
#define pp(n) printf("%lld\n",ll(n))
#define ps(n) printf("%lld ",ll(n))
#define pd(x,y) printf("%lld %lld\n",ll(x),ll(y))
#define is(n) scanf("%lld",&n)
#define inf LLONG_MAX
#define id(n,m) scanf("%lld%lld",&n,&m)
#define it(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define ss(s) scanf("%s",s)
#define cool 0
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pll pair<ll,ll> 
#define db cout<<"######\n"
#define null(a) memset(a,0,sizeof(a))
#define neg(a) memset(a,255,sizeof(a))
typedef long double ld;
typedef long long int ll;
using namespace std;
ll i,j,k,z,t,n,m,sum,ans,x,y,maxm=0,minm=inf; bool flag;
set<ll> lev[100005];
vector<ll> v[100005];
ll par[100005];
void dfs(ll x,ll level,ll parent)
{
	par[x]=parent;
	
	for(auto c:v[x])
	if(c!=parent)
	dfs(c,level+1,x);
	
	lev[level].insert(x);
}
int main()
{
	is(n);
	
	up(0,n-1,i)
	{
		id(x,y);
		v[x].pb(y);
		v[y].pb(x);
	}
	
	dfs(1,1,0);
	
	down(n,0,i)
	{
		for(auto c:lev[i])
		{
			x=par[c];
			
			auto it=lev[i-1].find(x);
			
			if(it==lev[i-1].end())
			{
				puts("First");
				return 0;
			}
			else
			lev[i-1].erase(it);
		}
	}
	
	puts("Second");
}


Measured memory_bytes: 16512
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>

using namespace std;
#define i64  long long

#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807

void solve(void)
{
 
  int N,M,L;
  cin>>N>>M>>L;

  vector<vector<i64> > mat1(N,vector<i64>(M,0));
  vector<vector<i64> > mat2(M,vector<i64>(L,0));

  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < M; j++)
    {
      cin>>mat1[i][j];
    }
  }

  for (int i = 0; i < M; i++)
  {
    for (int j = 0; j < L; j++)
    {
      cin>>mat2[i][j];
    }
    
  }
  
    vector<vector<i64> > mat3(N,vector<i64>(L,0));


    for (int row = 0; row < N; row++)
    {
      for (int col = 0; col < L; col++)
      {
        for (int i = 0; i < M; i++)
        {
          mat3[row][col] += mat1[row][i]*mat2[i][col];
        }
      }
    }

    for (int row = 0; row < N; row++)
    {
      for (int col = 0; col < L; col++)
      {
        cout<<mat3[row][col];
        if(col != L -1) cout<<" ";
      }
      cout<<endl;
    }
    
    

  return;
}

int main(int argc, const char *argv[])
{

  solve();

  return 0;
}



Measured memory_bytes: 3208
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String str = sc.next();
		String output = new String();
		for (int i = 0; i < str.length(); i++) {
			char c = calcChar(str.charAt(i), n);
			output = output + c;
		}
		System.out.println(output);
	}

	public static char calcChar(char ch, int n) {
		for (int i = 0; i < n; i++) {
			if (ch == 'Z') {
				ch = 'A';
			} else {
				ch++;
			}
		}
		return ch;
	}

}

Measured memory_bytes: 148024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const int N = (1 << 18) + 3;
const int M = 100100;
const int L = 19;
const int B = 9;
int ans[M];
int a[N][2];
int dp[L][M];
int n, q;
vector<pii> Q[N];

void dfs(int v, int h) {
	if (v > n) return;
	if (h < B) {
		for (int x = 0; x < M; x++) {
			dp[h + 1][x] = dp[h][x];
		}
		for (int x = 0; x < M - a[v][1]; x++)
			dp[h + 1][x + a[v][1]] = max(dp[h + 1][x + a[v][1]], dp[h][x] + a[v][0]);
	}
	h++;
	if (!Q[v].empty()) {
		//eprintf("v = %d\n", v);
		vector<pii> b;
		int u = v;
		int ch = h;
		while(ch > B) {
			b.push_back(mp(a[u][0], a[u][1]));
			u /= 2;
			ch--;
		}
		/*
		for (pii t : b)
			eprintf("(%d %d) ", t.first, t.second);
		eprintf("\n");
		*/
		int m = (int)b.size();
		vector<pii> c(1 << m);
		c[0] = mp(0, 0);
		for (int mask = 1; mask < (1 << m); mask++) {
			int k = 0;
			while(((mask >> k) & 1) == 0) k++;
			c[mask].first = c[mask ^ (1 << k)].first + b[k].first;
			c[mask].second = c[mask ^ (1 << k)].second + b[k].second;
		}
		/*
		for (pii t : c)
			eprintf("(%d %d) ", t.first, t.second);
		eprintf("\n");
		*/
		for (pii t : Q[v]) {
			int id = t.second;
			for (int mask = 0; mask < (1 << m); mask++) {
				int x = t.first - c[mask].second;
				if (x < 0) continue;
				ans[id] = max(ans[id], dp[ch][x] + c[mask].first);
			}
		}
	}
	dfs(2 * v, h);
	dfs(2 * v + 1, h);
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d%d", &a[i][0], &a[i][1]);
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		int v, x;
		scanf("%d%d", &v, &x);
		Q[v].push_back(mp(x, i));
	}
	dfs(1, 0);
	for (int i = 0; i < q; i++)
		printf("%d\n", ans[i]);

	return 0;
}


Measured memory_bytes: 18480
#include<iostream>
int main(){
int a,b,c,d,p;
int x=0;
int y=0;
std::cin>>a>>b>>c>>d>>p;
x+=a*p;
y+=b;
if(c<p)y+=(p-c)*d;
if(x>y)
std::cout<<y<<std::endl;
else std::cout<<x<<std::endl;
}

Measured memory_bytes: 1164
#include<iostream>
#include<cmath>
#include<algorithm>
#include<climits>
using namespace std;

int target;
static const int amount[3] = {200, 300, 500};
static const int value[3] = {380, 550, 850};
static const int per[3] = {5, 4, 3};
static const double ratio[3] = {0.8, 0.85, 0.88};

int minv;

int getValue( int store, int n ){
    int discount = per[store] * (n/per[store]);
    int nondisc = n%per[store];
    return ((int)ceil(value[store]*ratio[store]*discount) + value[store]*nondisc);
}

int compute(){
    minv = INT_MAX;
    
    int sa, sb, sc;
    for ( int a = 0; a <= target/amount[0]; a++ ){
	for ( int b = 0; b <= target/amount[1]; b++ ){
	    for ( int c = 0; c <= target/amount[2]; c++ ){

		int total = a*amount[0] + b*amount[1] + c*amount[2];
		int value = getValue(0, a) + getValue(1, b) + getValue(2, c);

		if ( total == target ){
		    if ( minv > value ){
			minv = value;
			sa = a;
			sb = b;
			sc = c;
		    }
		}
	    }
	}
    }

    return minv;
}

int main(){
    while( cin >> target && target ) cout << compute() << endl;
}

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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

using _loop_int = int;
#define REP(i,n) for(_loop_int i=0; i<(_loop_int)(n); i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a); i<(_loop_int)(b); i++)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1; i>=(_loop_int)(a); i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

int n;
char s[252521];

int main(){
    scanf("%d%s",&n,s);
    int cur = 0;
    int num = 0;
    ll ans = 1;
    REP(i,2*n){
        int x = s[i] == 'B' ? 1 : 0;
        x ^= cur;
        if(x){
            // left
            num++;
            cur ^= 1;
        }else{
            // right
            ans = ans * num % MOD;
            num--;
            cur ^= 1;
        }
    }
    if(num>0)ans=0;
    ll factn = 1;
    FOR(i,1,n+1)factn=factn*i%MOD;
    ans = ans*factn%MOD;
    printf("%lld\n",ans);
    return 0;
}


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

int main(){
    long long N,a,b,minB=1000000001,sum=0;
    bool same=true;
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> a >> b;
        sum+=a;
        if(a!=b)
        same=false;
        if(a>b && minB>b)
        minB=b;
    }
    if(same==true)
    cout << 0 << endl;
    else
    cout << sum-minB << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
A_even = [a for a in A if a%2 == 0]
flag = True
for a in A_even:
    if a%3 != 0 and a%5 != 0:
        flag = False
        break
if flag:
    print("APPROVED")
else:
    print("DENIED")


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

void solve(long long N){
    vector<ll> dp(N+1, 0);
    for(ll i=1; i<=N; i++){
        dp[i] = i;
        ll tmp;
        //* try 6^k
        tmp = 6;
        while (i >= tmp){
            dp[i] = min(dp[i], dp[i-tmp]+1);
            tmp *= 6;
        }
        //* try 9^k
        tmp = 9;
        while(i >= tmp){
            dp[i] = min(dp[i], dp[i-tmp]+1);
            tmp *= 9;
        }
        dp[i] = min(dp[i-1]+1, dp[i]);
    }
    cout << dp[N] << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

void fnInput(int& rnNum)
{
  cin >> rnNum;
}
  
int fnNextPrimeGet(int nNum)
{
  int nNextPrime = nNum;

  while (true)
  {
    int nLessSqrt = sqrt(nNextPrime);
    bool bPrime = true;

    for (int n = 2; n <= nLessSqrt; n++)
      if (nNextPrime % n == 0)
      {
        bPrime = false;
        break;
      }
      
    if (bPrime) return nNextPrime;
    nNextPrime++;
  }
}
  
int main()
{
  int nNum;

  fnInput(nNum);
  cout << fnNextPrimeGet(nNum) << endl;

  return 0;
}

Measured memory_bytes: 256
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
S=[input().split() for l in range(M)]

List = []
for i in range(M):
    x = a[int(S[i][0])-1]+b[int(S[i][1])-1]-int(S[i][2])
    List.append(x)
    
Min = List[0]
for i in range(1,M):
    if Min > List[i]:
        Min = List[i]
        
mina = a[0]
for i in range(A):
    if mina > a[i]:
        mina = a[i]
        
minb = b[0]
for i in range(B):
    if minb > b[i]:
        minb = b[i]
        
if Min >= mina+minb:
    print(mina+minb)
else:
    print(Min)

Measured memory_bytes: 50220
#define f(I)(p[I]+h[I]*(h[I]-2*h[i]))
long C,h[2<<17],p[2<<17],X,a;
P[2<<17];
s,t,x,y;
main(i){
	for(scanf("%*d%ld%d",&C,h);~scanf("%ld",&a);P[++t]=i-1){
		for(h[i]=a;X=f(P[s]),s<t&&X>=f(P[s+1]);s++);
		for(p[i++]=X+=a*a+C;s<t&&(h[y=P[t]]-h[x=P[t-1]])*(f(y)-f(i-1))>(a-h[y])*(f(x)-f(y));t--);
	}
	printf("%ld",X);
}

Measured memory_bytes: 4608
#include <stdio.h>
#define N 2000001

int A[N], B[N], C[N];
int n;

void countingsort(int *, int *, int);

main() {
  int i, k = 0;

  scanf("%d", &n);

  for(i = 1; i < n + 1; i++) {
    scanf("%d", &A[i]);
  }
  for(i = 1; i < n + 1; i++) {
    if(A[i] > k) {
      k = A[i];
    }
  }
  k = k + 1;

  countingsort(A, B, k);

  for(i = 1; i < n + 1; i++) {
    if(i == n) {
      printf("%d\n", B[i]);
    }
    else {
      printf("%d ", B[i]);
    }
  }
  return 0;
}

void countingsort(int *A, int *B, int k) {
  int i, j;

  for(i = 0; i < k; i++) {
    C[i] = 0;
  }

  for(j = 1; j < n + 1; j++) {
    C[A[j]]++;
  }

  for(i = 1; i < k; i++) {
    C[i] = C[i] + C[i - 1];
  }

  for(j = n; j >= 1; j--) {
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
}

Measured memory_bytes: 17892
import java.util.ArrayDeque;
import java.util.Deque;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] hwn = br.readLine().split(" ");
        int h = Integer.parseInt(hwn[0]);
        int w = Integer.parseInt(hwn[1]);
        int n = Integer.parseInt(hwn[2]);
        char[][] grid = new char[h][w];
        int sx=-1, sy=-1;
        
        for (int i = 0; i < h; i++) {
            String raw = br.readLine();
            for (int j = 0; j < w; j++) {
                grid[i][j] = raw.charAt(j);
                if (grid[i][j] == 'S') {
                    sy = i;
                    sx = j;
                }
            }
        }
        
        int next = 1;
        int[][] dfyxs = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
        boolean[][] visited = new boolean[h][w];
        visited[sy][sx] = true;
        int[][] distance = new int[h][w];
        distance[sy][sx] = 0;
        Deque<Integer> xq = new ArrayDeque<Integer>();
        Deque<Integer> yq = new ArrayDeque<Integer>();
        int d = 0;
        int ans = 0;
        outer: while (true) {
            inner: for (int[] dfyx: dfyxs) {
                if (sy-dfyx[0] < 0 || sx-dfyx[1] < 0 || sy-dfyx[0] >= h || sx-dfyx[1] >= w) continue;
                if (visited[sy-dfyx[0]][sx-dfyx[1]] == true) continue;
                if (grid[sy-dfyx[0]][sx-dfyx[1]] == 'X') {
                    continue;
                }
                distance[sy-dfyx[0]][sx-dfyx[1]] = distance[sy][sx] + 1;
                //System.out.println((sy-dfyx[0]) + " " + (sx-dfyx[1]));
                if ((int)grid[sy-dfyx[0]][sx-dfyx[1]]-48 == next) {
                    //System.out.println("aaa");
                    //System.out.println(distance[sy-dfyx[0]][sx-dfyx[1]]);
                    yq.clear();
                    xq.clear();
                    ans += distance[sy-dfyx[0]][sx-dfyx[1]];
                    if (next == n) break outer;
                    next++;
                    distance = new int[h][w];
                    distance[sy-dfyx[0]][sx-dfyx[1]] = 0;
                    visited = new boolean[h][w];
                    sy = sy-dfyx[0];
                    sx = sx-dfyx[1];
                    continue outer;
                }
                visited[sy-dfyx[0]][sx-dfyx[1]] = true;
                xq.addLast(sx-dfyx[1]);
                yq.addLast(sy-dfyx[0]);
            }
            sy = yq.removeFirst();
            sx = xq.removeFirst();
        }
        //System.out.println(distance[3][1]);
        System.out.println(ans);
    }
}



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

using namespace std;

const int MOD=1000000007;
int fact[10001];
int ifact[10001];

int powmod(int a, int b)
{
    int ret=1;
    for(; b>0; b/=2)
    {
        if(b&1)
            ret=1LL*ret*a%MOD;
        a=1LL*a*a%MOD;
    }
    return ret;
}

int C(int n, int k)
{
    return 1LL*fact[n]*ifact[k]%MOD*ifact[n-k]%MOD;
}

int solve(int a, int b, int c, int d, int f)
{
    if(c==0)
    {
        if(d==0)
            return 1LL*C(a+b+f, a+b)*C(a+b, a)%MOD;
        return 0;
    }
    int e=C(d+c-1, d);
    return 1LL*e*C(a+b+c+f, a+b+c)%MOD*C(a+b+c, a+b)%MOD*C(a+b, a)%MOD;
}

int main()
{
    fact[0]=1;
    ifact[0]=1;
    for(int i=1; i<=10000; i++)
    {
        fact[i]=1LL*fact[i-1]*i%MOD;
        ifact[i]=powmod(fact[i], MOD-2);
    }
    int N, A, B, C;
    scanf("%d%d%d%d", &N, &A, &B, &C);
    if(B%2==1)
        return printf("0\n"), 0;
    int ans=0;
    for(int c=0; c<=C; c+=3)
        for(int i=0; i<=min(A, C-c); i++)
            ans=(ans+solve(i, A-i, B/2, C-c-i, c/3))%MOD;
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

class D
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

		var d = Count(a, n);
		var M = d.Sum(c => (long)c * (c - 1) / 2);
		Console.WriteLine(string.Join("\n", a.Select(x => M - d[x] + 1)));
	}

	static int[] Count(int[] a, int max)
	{
		var r = new int[max + 1];
		foreach (var x in a) r[x]++;
		return r;
	}
}


Measured memory_bytes: 64040
import java.util.Scanner;

public class Main {

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

		int N = scanner.nextInt();

		int[] ai = new int[N];

		for(int i = 0;i<N;i++) {
			ai[i] = scanner.nextInt();
		}

		int cnt = 0;
		for (int i : ai) {
			while(i%2 != 1) {
				cnt ++;
				i = i/2;
			}
		}

		System.out.println(cnt);

	}

}


Measured memory_bytes: 33920
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<set>
#define IOS ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
typedef pair<string,int> PII;
typedef long long ll;
int main(){
	IOS;
	string a;
	cin>>a;
	int ans=0;
	for(int i=0;i<a.size()/2;i++){
		if(a[i]!=a[a.size()-i-1]) ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int N=2e5+100;
int main()
{
    FASTINOUT;
    string s;
    cin>>s;
    for (int i=0;i<s.length();i++)
        s[i]='x';
    cout<<s<<endl;
    return 0;
}


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

typedef long long int ll;

set<pair<ll, ll>> point;

vector<pair<ll, ll>> row(300000), col(300000);

bool compare(pair<ll, ll> first, pair<ll, ll> second)
{
    return first.first > second.first;
}

int main(void)
{
    ll H, W, M;
    cin >> H >> W >> M;
    ll maxNum = 0;

    for (ll i = 0; i < M; i++)
    {
        ll a, b;
        cin >> a >> b;
        row[a - 1].first++;
        row[a - 1].second = a;
        col[b - 1].first++;
        col[b - 1].second = b;

        point.insert(make_pair(a, b));
    }

    sort(row.begin(), row.end(), compare);
    sort(col.begin(), col.end(), compare);

    ll tmpR = 0, tmpC = 0;
    for (ll i = 0; i < M; i++)
    {
        if (tmpR > row[i].first)
            break;

        tmpR = row[i].first;

        for (ll j = 0; j < M; j++)
        {
            if (tmpC > col[j].first)
                break;

            tmpC = col[j].first;

            ll total = tmpR + tmpC;
            if (point.find(make_pair(row[i].second, col[j].second)) != point.end())
            {
                total--;
                maxNum = max(maxNum, total);
            }
            else
            {
                cout << total;
                return 0;
            }
        }
    }

    cout << maxNum;
    return 0;
}


Measured memory_bytes: 31460
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7

ans = 0

for aa in a:
  ans += aa
  ans %= mod
ans *= ans
ans %= mod
for aa in a:
  ans -= aa*aa
  ans %= mod


if ans%2 == 1:
  print((ans+mod)//2)
else:
  ans //= 2
  print(ans)	

Measured memory_bytes: 31400
///*
/// https://atcoder.jp/contests/tokiomarine2020/tasks/tokiomarine2020_a
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
const int N =2e6+6;
const int mod = 1e9+7;
void solve(){
    string s;
    cin>>s;
    cout<<s[0]<<s[1]<<s[2]<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t = 1;
    while(t--)solve();
    return 0;
}
//*/
/*
/// https://atcoder.jp/contests/tokiomarine2020/tasks/tokiomarine2020_b
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
const int N =2e6+6;
const int mod = 1e9+7;
void solve(){
    ll a,v;
    ll b,w;
    ll T;
    cin>>a>>v>>b>>w>>T;
    ll d1 = v*T;
    ll d2 = w*T;
    d2+= abs(b-a);
//    cout<<d1<<" "<<d2<<endl;
    if(d2>d1)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t = 1;
    while(t--)solve();
    return 0;
}

*/
/*
/// https://atcoder.jp/contests/tokiomarine2020/tasks/tokiomarine2020_c
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
typedef long long ll;
const int N =2e6+6;
const int mod = 1e9+7;
int a[N];
int b[N];
void solve(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)a[i] = 0;
    for(int it = 1;it<=min(k,50);it++){
        for(int i=1;i<=n;i++){
            int x = max(1,i-a[i]);
            int y = min(n+1,i+a[i]+1);
            b[x] ++;
            b[y]--;
        }
        for(int i=1;i<=n;i++){
            b[i]+=b[i-1];
            a[i] = b[i];
        }
        for(int i=0;i<=n+1;i++)b[i] = 0;
    }
    for(int i=1;i<=n;i++)cout<<a[i]<<" ";
    cout<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int t = 1;
    while(t--)solve();
    return 0;
}
*/


Measured memory_bytes: 3652
#include <cmath>
#include <iostream>
#include <algorithm>
using namespace std;
int D, E;
int main() {
	while (cin >> D >> E, D) {
		double ret = 1e10;
		for (int i = 0; i <= D; i++) {
			ret = min(ret, abs(hypot(i, D - i) - E));
		}
		printf("%.9f\n", ret);
	}
}

Measured memory_bytes: 3244
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().solve();

	}

	private long getValue(int currentI, int currentWeight) {
		if (arrayMemo[currentI][currentWeight] != Integer.MIN_VALUE) {
			return arrayMemo[currentI][currentWeight];
		}
		long res = 0;
		if (currentI >= itemNum) {
			res = 0;
		} else if (currentWeight < arrayItem[currentI][0]) {
			res = getValue(currentI + 1, currentWeight);
		} else {
			res = Math.max(
					getValue(currentI + 1, currentWeight - (int) arrayItem[currentI][0]) + arrayItem[currentI][1],
					getValue(currentI + 1, currentWeight));
		}
		arrayMemo[currentI][currentWeight] = res;
		return res;
	}

	private long[][] arrayItem;
	private long[][] arrayMemo;
	private int itemNum = 0;
	private int weightTotalNum = 0;

	private void solve() {
		Scanner scanner = null;

		try {
			scanner = new Scanner(System.in);
			itemNum = scanner.nextInt();
			weightTotalNum = scanner.nextInt();

			arrayItem = new long[itemNum][2];
			arrayMemo = new long[itemNum + 1][weightTotalNum + 1];
			for (int i = 0; i < arrayItem.length; i++) {
				arrayItem[i][0] = scanner.nextInt();
				arrayItem[i][1] = scanner.nextInt();
			}

			for (int i = 0; i < arrayMemo.length; i++) {
				Arrays.fill(arrayMemo[i], Integer.MIN_VALUE);
			}

			System.out.println(getValue(0, weightTotalNum));
		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 127060
#include<stdio.h>
  
int main(void){
   int a,b,c,d;
   scanf("%d%d%d",&a,&b,&c);
     if(a>b){
       d=a; a=b; b=d;
     }
     if(b>c){
       d=b; b=c; c=d;
     }
     if(a>b){
       d=a; a=b; b=d;
     }
  printf("%d %d %d\n",a,b,c);
  return 0;
}


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

long long n, x, m;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> x >> m;
	map<long long, long long> pre;
	vector<long long> arr = {0, x};
	x = (x * x) % m;
	while(pre.find(x) == pre.end()){
		pre[x] = (int)arr.size();
		arr.push_back(x);
		x = (x * x) % m;
	}
	int cyc = pre[x], len = (int)arr.size();
	for(int i = 1; i < len; i++)
		arr[i] += arr[i - 1];
	if(n < cyc - 1) cout << arr[n] << '\n';
	else{
		long long ans = arr[cyc - 1];
		n -= cyc - 1;
		ans += (arr[len - 1] - arr[cyc - 1]) * (n / (len - cyc));
		n %= len - cyc;
		ans += arr[cyc + n - 1] - arr[cyc - 1];
		cout << ans << '\n';
	}
	return 0;
}

Measured memory_bytes: 6692
/*
これを入れて実行
g++ code.cpp
./a.out
 */

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

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

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}

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

//-----------------------ここから-----------


int main(void){
	int n, y;
	cin >> n >> y;

	for(int i = 0; i <= y / 10000; i++){
		for(int j = 0; j <= y / 5000; j++){
			if(n - i - j < 0)continue;
			if(y == 10000 * i + 5000 * j + 1000 * (n - i - j)){
				cout << i << " " << j << " " << n - i - j << endl;
				return 0;
			}
		}
	}

	cout << -1 << " " << -1 << " " << -1 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define bit_exist(x, n) ((x >> n) & 1)
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;}
#define pb push_back
#define f first
#define s second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod



signed main(){

    int N, D; cin >> N >> D;
    int d = 2 * D + 1;
    int ans = (N - 1) / d + 1;
    Out(ans);

    return 0;
}


Measured memory_bytes: 256
n=int(input())
ac=0
tle=0
wa=0
re=0
for i in range(n):
  s=input()
  if s=='AC':
    ac+=1
  elif s=='TLE':
    tle+=1
  elif s=='WA':
    wa+=1
  elif s=='RE':
    re+=1
print('AC x '+str(ac))
print('WA x '+str(wa))
print('TLE x '+str(tle))
print('RE x '+str(re))

Measured memory_bytes: 9208
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>


struct Point {
	int x, y;
};
class UnionFind {
	std::vector<int> parent;
public:
	UnionFind(int size) :parent(size, -1) {};
	int find(int a) {
		if (parent[a] < 0) return a;
		else return parent[a] = find(parent[a]);
	}
	bool is_same(int a, int b) { return find(a) == find(b); }
	void merge(int a, int b) {
		a = find(a);
		b = find(b);
		if (a != b) {
			if (parent[a] < parent[b]) {
				parent[a] += parent[b];
				parent[b] = a;
			}
			else {
				parent[b] += parent[a];
				parent[a] = b;
			}
		}
	}
};
enum class Axis {
	X, Y
};
int main() {
	int n; std::cin >> n;
	std::vector<Point> points(n); for (auto& p : points) std::cin >> p.x >> p.y;
	std::vector<int> sort_by_x(n), sort_by_y(n);
	for (auto i = 0; i < n; ++i) {
		sort_by_x[i] = i;
		sort_by_y[i] = i;
	}
	std::sort(sort_by_x.begin(), sort_by_x.end(), [&points](const int a, const int b) {return points[a].x < points[b].x; });
	std::sort(sort_by_y.begin(), sort_by_y.end(), [&points](const int a, const int b) {return points[a].y < points[b].y; });
	auto comparator = [&points, &sort_by_x, &sort_by_y](const std::pair<Axis, int>& a, const std::pair<Axis, int>& b) {
		int diff_a{ 0 };
		switch (a.first) {
		case Axis::X: diff_a = points[sort_by_x[a.second]].x - points[sort_by_x[a.second - 1]].x; break;
		case Axis::Y: diff_a = points[sort_by_y[a.second]].y - points[sort_by_y[a.second - 1]].y; break;
		default: break;
		}
		int diff_b{ 0 };
		switch (b.first) {
		case Axis::X: diff_b = points[sort_by_x[b.second]].x - points[sort_by_x[b.second - 1]].x; break;
		case Axis::Y: diff_b = points[sort_by_y[b.second]].y - points[sort_by_y[b.second - 1]].y; break;
		default: break;
		}
		return diff_a > diff_b;
	};
	std::priority_queue<std::pair<Axis, int>, std::vector<std::pair<Axis, int>>, decltype(comparator)> queue(comparator);
	for (auto i = 1; i < n; ++i) {
		queue.emplace(Axis::X, i);
		queue.emplace(Axis::Y, i);
	}
	UnionFind uft(n);
	long long int result = 0;
	while (!queue.empty()) {
		auto top = queue.top(); queue.pop();
		switch (top.first) {
		case Axis::X: 
			if (!uft.is_same(sort_by_x[top.second], sort_by_x[top.second - 1])) {
				result += points[sort_by_x[top.second]].x - points[sort_by_x[top.second - 1]].x;
				uft.merge(sort_by_x[top.second], sort_by_x[top.second - 1]);
			}
			break;
		case Axis::Y:
			if (!uft.is_same(sort_by_y[top.second], sort_by_y[top.second - 1])) {
				result += points[sort_by_y[top.second]].y - points[sort_by_y[top.second - 1]].y;
				uft.merge(sort_by_y[top.second], sort_by_y[top.second - 1]);
			}
			break;
		default: break;
		}
	}
	std::cout << result << std::endl;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

ll calc(ll n, vector<pair<ll, ll> > pp) {
	if (SZ(pp) == 0) {
		return n;
	} else if (SZ(pp) == 1) {
		int i = n / pp[0]._1;
		return n + i * (pp[0]._2 - pp[0]._1);
	} else if (SZ(pp) == 2) {
		ll ans = n;
		REPN(i, 0, n / pp[0]._1) {
			int j = (n - i * pp[0]._1) / pp[1]._1;
			ans = max(ans, n + i * (pp[0]._2 - pp[0]._1) + j * (pp[1]._2 - pp[1]._1));
		}
		return ans;
	} else {	// SZ(pp) == 3
		ll ans = n;
		REPN(i, 0, n / pp[0]._1) {
			REPN(j, 0, (n - i * pp[0]._1) / pp[1]._1) {
				int k = (n - i * pp[0]._1 - j * pp[1]._1) / pp[2]._1;
				ans = max(ans, n + i * (pp[0]._2 - pp[0]._1) + j * (pp[1]._2 - pp[1]._1) + k * (pp[2]._2 - pp[2]._1));
			}
		}
		return ans;
	}
}

void solve(){
	ll n, u[3], v[3];
	scanf("%lld", &n);
	REP(i, 0, 3) {
		scanf("%lld", &u[i]);
	}
	REP(i, 0, 3) {
		scanf("%lld", &v[i]);
	}
	vector<pair<ll, ll> > v1, v2;
	REP(i, 0, 3) {
		if (u[i] < v[i]) {
			v1.pb(mp(u[i], v[i]));
		} else if (u[i] > v[i]) {
			v2.pb(mp(v[i], u[i]));
		}
	}
	ll n1 = calc(n, v1);
	ll n2 = calc(n1, v2);
	printf("%lld\n", n2);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


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

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            var n = cin.ReadInt;
            var m = cin.ReadIntArray(n + 1);
            var y = cin.ReadIntArray(n);
            long sum = 0;
            var nextDamage = 0;
            for (var i = 0; i <= n; i++)
            {
                var currentDamage = i == n ? 0 : y[i];
                var currentLife = m[i];
                if (currentLife >= nextDamage)
                {
                    currentLife -= nextDamage;
                    sum += nextDamage;
                    if (currentLife >= currentDamage)
                    {
                        sum += currentDamage;
                        nextDamage = 0;
                    }
                    else
                    {
                        sum += currentLife;
                        nextDamage = currentDamage - currentLife;
                    }
                }
                else
                {
                    sum += currentLife;
                    nextDamage = currentDamage;
                }
            }
            WriteLine(sum);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 30940
fun main() {
    val N = readLine()!!.toInt()
    val As = readLine()!!.split(" ").map { it.toLong() }.toMutableList()
    var total = 0L
    for (ix in 1..As.size-1) {
        val stand = if (As[ix-1] > As[ix]) {
            As[ix-1] - As[ix]
        } else {
            0L
        }
        As[ix] += stand
        total += stand
    }
    println(total)
}

Measured memory_bytes: 70648
import java.io.*;

 public class Main{
	 public static void main(String args[]) throws IOException{
		 BufferedReader bf = new BufferedReader(
				 new InputStreamReader(System.in));
		String str = bf.readLine();
		String[] word = str.split(" ", 0);
		//char[]???????????????
		for(int i = 0; i < word.length; i++){
			char[] c = word[i].toCharArray();
			for(int j = 0; j < word[i].length(); j++){
				if(c[j] != '.'){
					c[j] -= 32;
				}
			}
			word[i] = new String(c);
		}
		//???????????????
		String answer = word[0]+" ";
		for(int i = 1; i < word.length-1; i++){
			answer += word[i]+" ";
		}
		answer += word[word.length-1];
		System.out.println(answer);
	}
}

Measured memory_bytes: 24204