akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>

// BEGIN CUT HERE
#ifdef _MSC_VER
#include <agents.h>
#endif
// END CUT HERE 

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define MP make_pair
#define MT make_tuple
#define X first
#define Y second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const int N = 2e4 + 10;
int a[N];
int main(){
	int n, m;
	while (cin >> n >> m, n){
		MEMSET(a, 0);
		a[1] = 1;
		vector<tuple<int, int, int>> v;
		rep(i, m){
			int t, x, y;
			cin >> t >> x >> y;
			v.emplace_back(t, x, y);
		}
		sort(ALL(v));
		for (auto t : v){
			int _, x, y;
			tie(_, x, y) = t;
			if (a[x]) a[y] = 1;
		}
		cout << count(a, a + N, 1) << endl;
	}

	return 0;
}

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

public class Main {
    int n, k;
    long[] xs, ys;
    long[] sxs, sys;
    public static void main(String[] args) {
        Main m = new Main();
        m.read();
        m.solve();
    }

    private void read() {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        k = sc.nextInt();
        xs = new long[n];
        ys = new long[n];
        sxs = new long[n];
        sys = new long[n];
        for (int i = 0; i < n; i++){
            xs[i] = sc.nextLong();
            ys[i] = sc.nextLong();
            sxs[i] = xs[i];
            sys[i] = ys[i];
        }
    }

    private void solve() {
        Arrays.sort(sxs);
        Arrays.sort(sys);
        int[][] cnts = new int[n+1][n+1];
        for (int i = 0; i < n; i++) {
            long x = xs[i];
            long y = ys[i];
            int ix = bs(sxs, x) + 1;
            int iy = bs(sys, y) + 1;
            cnts[iy][ix] = 1;
        }
        for (int i = 0; i < cnts.length; i++) {
            for (int j = 1; j < cnts.length; j++) {
                cnts[i][j] += cnts[i][j-1];
            }
        }
        for (int i = 1; i < cnts.length; i++) {
            for (int j = 0; j < cnts.length; j++) {
                cnts[i][j] += cnts[i-1][j];
            }
        }
        long ans = (sxs[n-1] - sxs[0]) * (sys[n-1] - sys[0]);
        for (int lx = 0; lx < n; lx++) {
            for (int ux = lx + 1; ux < n; ux++) {
                for (int ly = 0; ly < n; ly++) {
                    for (int uy = ly + 1; uy < n; uy++) {
                        int num = cnts[uy+1][ux+1] + cnts[ly][lx] - cnts[uy+1][lx] - cnts[ly][ux+1];
                        if (num >= k) {
                            long tmp = (sxs[ux] - sxs[lx]) * (sys[uy] - sys[ly]);
                            ans = Math.min(ans, tmp);
                        }
                    }
                }
            }
        }
        System.out.println(ans);
    }

    private int bs(long[] src, long trg) {
        int l = 0;
        int r = src.length;
        while (r > l) {
            int mid = (l + r) / 2;
            if (src[mid] >= trg) {
                r = mid;
            }
            else
                l = mid + 1;
        }
        return l;
    }

}


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

#define int long long

double dp[3003][3003] ;
int vis[3003][3003] ;
double p[3003] ;
int n ;
double solve(int i , int j ){
	if(i == n){
		if(j) return 0;
		return 1 ;
	}
	if(vis[i][j]) return dp[i][j] ;
	vis[i][j] = 1 ;
	return dp[i][j] = solve(i + 1, j - 1)*p[i] + solve(i + 1 , j)*(1 - p[i]) ;
}

int32_t main(){
	cin >> n ;
	for(int i = 0 ; i < n ; i++) cin >> p[i] ;
	double ans = 0;
	for(int i = n / 2 + 1 ; i <= n ; i++){
		ans += solve(0 , i) ;
	}
	cout << fixed << setprecision(10) << ans ;
	return 0 ;
}



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

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"
#define watch3(x,y,z) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<" and "<<(#z)<<" is "<<(z)<<"\n"

#define ll long long
#define ff first
#define ss second
#define null NULL
#define all(c) (c).begin(),(c).end()
#define nl "\n"

#define ld long double
#define eb emplace_back
#define pb push_back
#define pf push_front
#define mod 1000000007

typedef vector<ll> vl;
typedef vector< vl > vvl;
typedef pair< ll, ll> pll;
typedef map< ll, ll> mll;

#define pie_value 3.14159265358979323846

int main() {

	// Use ctrl+shift+b ( second option )
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt" , "w" , stderr);
#endif

	ll n, d;
	cin >> n >> d;

	ll count = 0;
	for (ll i = 1; i <= n; i++) {
		ll a, b;
		cin >> a >> b;

		ll val = ceil(sqrt(a * a + b * b));

		if ((ll)val <= d)
			count++;
	}

	cout << count << nl;


	return 0;
}


Measured memory_bytes: 3728
import java.util.*;
import java.math.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(Math.abs(x-a) <= Math.abs(x-b)){
      System.out.println("A");
    }else{
      System.out.println("B");
    }
  }
}


Measured memory_bytes: 23764
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

int main() {
	long long n, a, b;
	cin >> n >> a >> b;

	long long k = n / (a + b);
	long long ans = k * a;
	long long left = n - k * (a + b);

	if (left >= a) {
		ans += a;
	}
	else {
		ans += left;
	}

	cout << ans << endl;



	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return read.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtype!real;

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

void solve(){
	int n = rint;
	int m = rint;
	
	Node[] nodes;
	foreach(i; 0 .. n) nodes ~= new Node(i);
	
	const long infty = 10_000_999;
	
	foreach(x; nodes) foreach(y; nodes){
		if(x.id == y.id) x.costTo[y.id] = 0;
		else x.costTo[y.id] = infty;
	}
	
	
	Edge[] edges;
	foreach(j; 0 .. m){
		int a = rint - 1, b = rint - 1;
		long c = rlong;
		edges ~= new Edge(nodes[a], nodes[b], c);
	}
	edges.sort!"a.cost<b.cost"();
	
	foreach(ed; edges){
		ed.connect(nodes);
	}
	
	long ans;
	foreach(ed; edges) if(ed.isWorthless) ans += 1;
	
	ans.writeln;
	
}

class Node{
	int id;
	long[int] costTo;
	this(int id){
		this.id = id;
		this.costTo[this.id] = 0;
	}
}

class Edge{
	Node a, b;
	long cost;
	bool isWorthless;
	this(Node a, Node b, long c){
		this.a = a;
		this.b = b;
		this.cost = c;
	}
	void connect(Node[] nodes){
		if(a.costTo[b.id] > this.cost){
			foreach(x; nodes) foreach(y; nodes){
				if(x.costTo[y.id] > x.costTo[a.id] + this.cost + b.costTo[y.id]){
					x.costTo[y.id] = x.costTo[a.id] + this.cost + b.costTo[y.id];
					y.costTo[x.id] = x.costTo[a.id] + this.cost + b.costTo[y.id];
				}
				else if(x.costTo[y.id] > x.costTo[b.id] + this.cost + a.costTo[y.id]){
					x.costTo[y.id] = x.costTo[b.id] + this.cost + a.costTo[y.id];
					y.costTo[x.id] = x.costTo[b.id] + this.cost + a.costTo[y.id];
				}
			}
			a.costTo[b.id] = this.cost;
			b.costTo[a.id] = this.cost;
		}
		else if(a.costTo[b.id] < this.cost){
			this.isWorthless = 1;
		}
	}
}


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

using namespace std;
#define local
#ifdef local

template<class T>
void _E(T x) { cerr << x; }

void _E(double x) { cerr << fixed << setprecision(6) << x; }

void _E(string s) { cerr << "\"" << s << "\""; }

template<class A, class B>
void _E(pair<A, B> x) {
    cerr << '(';
    _E(x.first);
    cerr << ", ";
    _E(x.second);
    cerr << ")";
}

template<class T>
void _E(vector<T> x) {
    cerr << "[";
    for (auto it = x.begin(); it != x.end(); ++it) {
        if (it != x.begin()) cerr << ", ";
        _E(*it);
    }
    cerr << "]";
}

void ERR() {}

template<class A, class... B>
void ERR(A x, B... y) {
    _E(x);
    cerr << (sizeof...(y) ? ", " : " ");
    ERR(y...);
}

#define debug(x...) do { cerr << "{ "#x" } -> { "; ERR(x); cerr << "}" << endl; } while(false)
#else
#define debug(...) 114514.1919810
#endif
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f3f3f
#define ll long long
#define db long double
#define eps 1e-3
#define bin(x) cerr << bitset<10>(x) << endl
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
#define endl "\n"
const ll mod = 1e9 + 7;
const ll maxn = 2e4 + 10;
const db pi = acos(-1.0);
ll qpow(ll a, ll b) {
    ll ret = 1;
    for (; b; a = a * a % mod, b >>= 1) {
        if (b & 1) {
            ret = ret * a % mod;
        }
    }
    return ret;
}

vector<ll> f(maxn), invf(maxn);

ll inv(ll a) {
    return qpow(a, mod - 2);
}

void prework() {
    f[0] = 1;
    _rep(i, 1, maxn - 1) {
        f[i] = f[i - 1] * i % mod;
    }
    invf[maxn - 1] = qpow(f[maxn - 1], mod - 2);
    for (ll i = maxn - 2; i >= 0; i--) {
        invf[i] = invf[i + 1] * (i + 1) % mod;
    }
}

ll C(ll n, ll m) {
    if (n > m || m < 0)return 0;
    if (n == 0 || m == n) return 1;
    ll res = (f[m] * invf[m - n] % mod * invf[n]) % mod;
    return res;
}

string a[maxn];

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int d, t, s;
    cin >> d >> t >> s;
    cout << (t*s >= d ?  "Yes" : "No" ) << endl;
}

Measured memory_bytes: 4288
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=100005,md=1000000007;
int n,m,K,i,j,k,head[N],adj[N],nxt[N],ans,s[N],inv[N],jc[N],rjc[N],id[N],pre[N],col[N],cnt,len,tot,pw[N];
bool v[N],b[N];
int gcd(int a,int b)
{
	if(!b)
		return a;
	return gcd(b,a%b);
}
int C(int n,int m)
{
	return 1ll*jc[n]*rjc[m]%md*rjc[n-m]%md;
}
int work(int n)
{
	int rtn=0;
	for(int i=1;i<=n;++i)
		rtn=(rtn+pw[gcd(i,n)])%md;
	rtn=1ll*rtn*inv[n]%md;
	return rtn;
}
void dfs(int x,int dad)
{
	id[x]=pre[x]=++cnt;
	for(int y=head[x];y;y=nxt[y])
		if(!id[adj[y]])
		{
			s[++len]=(y+1)/2;
			dfs(adj[y],x);
			pre[x]=min(pre[x],pre[adj[y]]);
			if(pre[adj[y]]>=id[x])
			{
				int num1,num2,i;
				num1=num2=0;
				++tot;
				while(1)
				{
					if(col[adj[s[len]*2-1]]!=tot)
					{
						col[adj[s[len]*2-1]]=tot;
						++num1;
					}
					if(col[adj[s[len]*2]]!=tot)
					{
						col[adj[s[len]*2]]=tot;
						++num1;
					}
					--len;
					if(s[len+1]==(y+1)/2)
						break;
				}
				for(i=1;i<=m;++i)
					if(col[adj[i*2-1]]==tot&&col[adj[i*2]]==tot)
						++num2;
				//printf("%d %d %d\n",x,num1,num2);
				if(num2==1)
					ans=1ll*ans*K%md;
				else if(num1==num2)
					ans=1ll*ans*work(num1)%md;
				else
					ans=1ll*ans*C(num2+K-1,K-1)%md;
			}
		}
		else if(adj[y]!=dad)
			pre[x]=min(pre[x],id[adj[y]]);
}
int main()
{
	scanf("%d%d%d",&n,&m,&K);
	inv[1]=1;
	for(i=2;i<=n+m+K;++i)
		inv[i]=1ll*inv[md%i]*(md-md/i)%md;
	jc[0]=rjc[0]=pw[0]=1;
	for(i=1;i<=n+m+K;++i)
		jc[i]=1ll*jc[i-1]*i%md,rjc[i]=1ll*rjc[i-1]*inv[i]%md,pw[i]=1ll*pw[i-1]*K%md;
	for(i=1;i<=m;++i)
	{
		scanf("%d%d",&j,&k);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
	}
	ans=1;
	for(i=1;i<=n;++i)
		if(!id[i])
			dfs(i,-1);
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


int main() {

	while(1) {
		int n; cin >> n;
		if (n == 0) break;
		int min = 1000000001;
		/*
		for (int x = 0; x <= n; x++) {
			if (x > n) break;
			for (int y = 0; y <= n; y++) {
				if (x + y * y > n) break;
				for (int z = 0; z <= n; z++) {
					int energy = x + y * y + z * z * z;
					int m = x + y + z;
					if (energy > n) break;
					if (energy == n and min > m) {
						min = m;
					}
				}
			}
		}
		*/
		for (int z = 0; z <= n; z++) {
			if (z * z * z > n) break;
			for (int y = 0; y <= n; y++) {
				int x = n - (z * z * z + y * y);
				int m = x + y + z;
				if (x < 0) break;
				if (min > m) {
					min = m;
				}
			}
		}
		cout << min << endl;
	}
	return 0;
}



Measured memory_bytes: 3012
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
   ll n;cin>>n;
   map<ll,ll> mp;
   rep1(i,200)rep1(j,200)rep1(k,200){
       ll buf=i*i+j*j+k*k+i*j+j*k+k*i;
       mp[buf]++;
   }
   rep1(i,n)cout<<mp[i]<<endl;
}

Measured memory_bytes: 14012
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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;
vector<long long> a;

void solve() {
	map<long long, long long> ma;
	for (int i = 0; i < N; ++i) ma[a[i]]++;
	long long res = 0;
	for (auto it : ma) res += it.second * (it.second - 1) / 2;
	for (int i = 0; i < N; ++i) {
		long long val = ma[a[i]];
		long long before = val * (val - 1) / 2;
		long long after = (val - 1) * (val - 2) / 2;
		cout << res + after - before << endl;
	}
}

int main() {
	
	cin >> N;
	a.resize(N);
	for (int i = 0; i < N; ++i) cin >> a[i];
	solve();
	return 0;
}

Measured memory_bytes: 11008
n,h = map(int,input().split())
x = []
for i in range(n):
	x.append(list(map(int,input().split())))

t = 0
c = []#強い投げ刀たち
M = max(x[i][0] for i in range(n))

for i in range(n):
	if x[i][1]>M-1:
		c.append(x[i][1])
c.sort()
c.reverse()

if sum(c)>h-1:
	for i in range(len(c)):
		t += 1
		h -= c[i]
		if h<1:
			print(t)
			break
else:
	h -=sum(c)
	q = (h-1)//M+1
	print(q+len(c))

Measured memory_bytes: 28596
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=1e5+10;
    int N,M,K;
    vector<int>Friend[MAXN];
    set<int>Block[MAXN];
    int vis[MAXN];
    int fId[MAXN];
    int ans[MAXN];
    void fdfs(int r,int fid){
        vis[r]=true;
        fId[r]=fid;
        for(auto v:Friend[r]){
            if(vis[v])continue;
            fdfs(v,fid);
        }
    }

    void solve(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin>>N>>M>>K;
        for(int u=0;u<M;u++){
            int a,b;
            cin>>a>>b;
            Friend[a].push_back(b);
            Friend[b].push_back(a);
        }
        for(int u=0;u<K;u++){
            int a,b;
            cin>>a>>b;
            Block[a].insert(b);
            Block[b].insert(a);
        }
        int cl=1;
        for(int u=1;u<=N;u++){
            if(vis[u])continue;
            fdfs(u,cl++);
        }
        vector<int>cnt(cl+1,0);
        for(int u=1;u<=N;u++){
            cnt[fId[u]]++;
        }
        for(int u=1;u<=N;u++){
            ans[u]=cnt[fId[u]]-Friend[u].size();
            for(auto b:Block[u]){
                if(fId[b]==fId[u])ans[u]--;
            }
            cout<<ans[u]-1<<" ";
        }
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 22008
#include <bits/stdc++.h>
using namespace std;
int main(void){

    string a, b, c;
    cin >> a >> b >> c ;
    
    /*
    if(b - a == c - b){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    */
    
    //cout << a.at(0) - 'a' + 'A' << b.at(0) - 'a' + 'A' << c.at(0) - 'a' + 'A' << endl;
    printf("%c%c%c", a.at(0) - 'a' + 'A' , b.at(0) - 'a' + 'A' , c.at(0) - 'a' + 'A');

    return 0; 
}


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

int64_t count(int64_t n, int div)
{
  return n / div;
}

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

int main()
{
  int64_t a, b, ans1 = 0, ans2 = 0, tmp, c, d;
  cin >> a >> b >> c >> d;
  tmp = (c * d) / gcd(max(c, d), min(c, d));

  ans1 = b - (b / c + b / d - b / tmp);
  ans2 = a - 1 - ((a-1) / c + (a-1) / d - (a-1) / tmp);
  cout << ans1 - ans2 << endl;
}

Measured memory_bytes: 256
// AOJ 2641 Magic Bullet
// 2018.1.31 bal4u

#include <stdio.h>
#include <math.h>

#define EPS 1e-8

typedef struct { double x, y, z; } PP;				// Point
typedef struct { PP a, b; } LN;						// Line
typedef struct { PP p; int r; long long l; } SP;	// Sphere
SP ball[51];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	if (c == '-') {
		c = getchar_unlocked();
		do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
		while (c >= '0');
		return -n;
	}
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

long long inlong()
{
	long long n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

double dot(PP a, PP b)
{
	return a.x*b.x + a.y*b.y + a.z*b.z;
}

void project(PP *q, LN ln, PP p)
{
	double t;
	PP d, e;

	d.x = ln.a.x-ln.b.x, d.y = ln.a.y-ln.b.y, d.z = ln.a.z-ln.b.z;
	e.x = p.x-ln.a.x, e.y = p.y-ln.a.y, e.z = p.z-ln.a.z;
	t = dot(d, e) / dot(d, d);
	q->x = ln.a.x + d.x*t, q->y = ln.a.y + d.y*t, q->z = ln.a.z + d.z*t; 
}

double dist(PP a, PP b)
{
	double dx, dy, dz;
	dx = a.x-b.x, dy = a.y-b.y, dz = a.z-b.z;
	return sqrt(dx*dx + dy*dy + dz*dz);
}

int main()
{
	int n, q, i;
	long long ans;
	LN ln;
	PP p;

	n = in(), q = in();
	for (i = 0; i < n; i++) {
		ball[i].p.x = in(), ball[i].p.y = in(), ball[i].p.z = in();
		ball[i].r = in(), ball[i].l = inlong();
	}
	while (q--) {
		ln.a.x = in(), ln.a.y = in(), ln.a.z = in();
		ln.b.x = in(), ln.b.y = in(), ln.b.z = in();

		ans = 0;
		for (i = 0; i < n; i++) {
			project(&p, ln, ball[i].p);

			if (dist(ln.a, ln.b) >= dist(p, ln.a) &&
				dist(ln.a, ln.b) >= dist(p, ln.b) &&
				dist(p, ball[i].p) < ball[i].r + EPS) ans += ball[i].l;
		}
		printf("%lld\n", ans);
	}
	return 0;
}



Measured memory_bytes: 2080
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

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



int main() {
  int n, a, b;
  cin >> n >> a >> b;
  cout << min(n * a, b) << endl;
  return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
l=1
r=N
for m in range(M):
    L,R=map(int,input().split())
    if l<L:
        l=L
    if r>R:
        r=R

    if l>r:
        print(0)
        exit()
    
    #print("left:{}\tright:{}".format(l,r))

print(r-l+1)


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

bool isMale() {
    string result;
    cin >> result;
    if (result == "Vacant") {
        exit(0);
    }
    return result == "Male";
}

int main() {
    int N;
    cin >> N;
    int left = 0;
    int right = N - 1;
    cout << 0 << endl;
    bool leftMale = isMale();
    while (left < right) {
        int mid = (left + right + 1) / 2;
        cout << mid << endl;
        bool midMale = isMale();
        bool vacantLeft = false;
        if ((mid - left) % 2 == 0) {
            if (leftMale != midMale) {
                vacantLeft = true;
            }
        } else {
            if (leftMale == midMale) {
                vacantLeft = true;
            }
        }
        if (vacantLeft) {
            right = mid;
        } else {
            left = mid;
            leftMale = midMale;
        }
    }
}

Measured memory_bytes: 852
import java.math.BigInteger;
import java.util.*;
import java.io.*;

public class Main
{
	public static void main(String args[])
	{
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		while(n--!=0)
		{
			BigInteger a = in.nextBigInteger();
			BigInteger b = in.nextBigInteger();
			BigInteger ans = a.add(b);
			int counter=0;
			a=ans;
			while(a.compareTo(BigInteger.ZERO)!=0)
			{
				a=a.divide(new BigInteger("10"));
				counter++;
			}
			if(counter>80)System.out.println("overflow");
			else System.out.println(ans);  
		}
	}
}

Measured memory_bytes: 21800
import java.util.Scanner;

public class Main {
	public void main(Scanner sc) {
		long a = sc.nextLong();
		long b = new Long(sc.next().replace(".", ""));

		String ans = new Long(a * b).toString();

		if (ans.length() >= 3) {
			System.out.println(ans.substring(0, ans.length() - 2));
		} else {
			System.out.println(0);
		}
	}

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


Measured memory_bytes: 35880
#include<bits/stdc++.h>
using namespace std;
#define INF 1e9
typedef pair<int,int> pii;
struct edge{int cost,to;};
int N,K;
vector<int> vec[5010];
pii taxi[5010];
int D1[5010][5010];
int D2[5010];
vector<edge> vec2[5010];

int solve();
void dijkstra();

int main()
{
    scanf("%d%d",&N,&K);
    for(int i = 0; i < N; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        taxi[i + 1].first = a;
        taxi[i + 1].second = b;
    }
    for(int i = 0; i < K; i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        vec[a].push_back(b);
        vec[b].push_back(a);
    }
    printf("%d\n",solve());
    return 0;
}

void dijkstra()
{
    for(int i = 1; i <= N; i++)
    {
        D2[i] = INF;
    }
    D2[1] = 0;
    priority_queue<pii,vector<pii>,greater<pii> > que;
    que.push(pii(1,0));
    while(que.size())
    {
        pii test = que.top();que.pop();
        int now = test.first;
        if(D2[now] < test.second)continue;
        for(int i = 0; i < vec2[now].size(); i++)
        {
            edge e = vec2[now][i];
            if(D2[e.to] > D2[now] + e.cost)
            {
                D2[e.to] = D2[now] + e.cost;
                que.push(pii(e.to,D2[e.to]));
            }
        }
    }
    return;
}


int solve()
{
    for(int i = 1; i <= N; i++)
    {
        for(int j = 1; j <= N; j++)
        {
            D1[i][j] = INF;
        }
    }
    for(int i = 1; i <= N; i++)
    {
        queue <pii> que;
        que.push(pii(i,0));
        while(que.size())
        {
            pii test = que.front();que.pop();
            if(D1[i][test.first] != INF)continue;
            D1[i][test.first] = test.second;
            for(int j = 0; j < vec[test.first].size(); j++)
            {
                que.push(pii(vec[test.first][j],test.second + 1));
            }
        }
    }
    for(int i = 1; i <= N; i++)
    {
        for(int j = 1; j <= N; j++)
        {
            if(taxi[i].second >= D1[i][j])
            {
                edge e;
                e.to = j;e.cost = taxi[i].first;
                vec2[i].push_back(e);
            }
        }
    }
    dijkstra();
    return D2[N];
}

Measured memory_bytes: 225480
#include<stdio.h>
int main(){
  int n,t,x,y,s=0,i;
  scanf("%d%d%d",&n,&t,&y);
  for(i=1;i<n;i++){scanf("%d",&x);s+=x-y<t?x-y:t;y=x;}
  printf("%d",s+t);
}


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

bool dp[100001];// true, false がそれぞれ勝ち、負け

int main(){
  int N;
  int K;
  int a[100];
  std::cin>>N>>K;
  for(int i=0;i<N;++i){
    std::cin>>a[i];
  }
  dp[0]=false;
  for(int i=1;i<=K;++i){
    bool ok=false;
    for(int j=0;j<N;++j){
      if(i-a[j]<0)continue;
      ok|=!dp[i-a[j]];
    }
    dp[i]=ok;
  }
  if(dp[K])
    printf("First\n");
  else
    printf("Second\n");
  
  return 0;
}


Measured memory_bytes: 384
#include<stdio.h>

main(){
  int x,i,j,k;
  int a[3];

  scanf("%d",&i);
  for(;i>0;i--){

    for(j=0;j<3;j++){ 
      scanf("%d",&a[j]);
    }
    for(j=0;j<2;j++){
      for(k=j+1;k<3;k++){
	if(a[j]<a[k]){
	  x=a[j];
	  a[j]=a[k];
	  a[k]=x;
	}
      }
    }
 
    if(a[0]*a[0]==a[1]*a[1]+a[2]*a[2]){
      printf("YES\n");
    }
    else{ 
      printf("NO\n");
    }
  }
  
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  char b;
  cin >> b;
  if(b == 'A'){
    cout << 'T' << endl;
  }else if(b == 'T'){
    cout << 'A' << endl;
  }else if(b == 'C'){
    cout << 'G' << endl;
  }else{
    cout << 'C' << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdint>

int main()
{
	std::uint32_t n;
	for (std::cin >> n; n != 0; std::cin >> n) {
		typedef std::vector<std::int32_t> IntVec;
		IntVec a(n);
		for (std::size_t i = 0; i < n; ++i) {
			std::cin >> a[i];
		}
		for (std::size_t i = 1; i < n; ++i) {
			a[i] = std::max(a[i], a[i] + a[i - 1]);
		}
		std::cout << *std::max_element(a.begin(), a.end()) << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1204
package main

import (
	"fmt"
	"math"
)

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)
	height := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &height[i])
	}
	ans := minPossibleTotalCost2(n, k, height)
	fmt.Println(ans)
}

// https://atcoder.jp/contests/dp/tasks/dp_b
func minPossibleTotalCost2(n int, k int, height []int) int {
	dp := make([]int, n)
	dp[0] = 0
	for i := 1; i < n; i++ {
		dp[i] = 1 << 32
	}
	for i := 0; i < n; i++ {
		for j := i + 1; j <= k+i; j++ {
			if j < n {
				cost := int(math.Abs(float64(height[i] - height[j])))
				dp[j] = min(dp[j], dp[i]+cost)
			}
		}
	}
	return dp[n-1]
}

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 6320
using System;
using System.Collections.Generic;
using System.Linq;

public class MinMaxAndSum
{
    //????????°?????´??°???????°????????????§??????????¨????????±???????
    static void Main(string[] args)
    {
        /*---??£?¨???¨---*/
        int count;
        string[] strNum;
        /*---??£?¨???¨---*/

        /*?????????????????°??¨??´??°?????????*/
        count = int.Parse(Console.ReadLine());
        strNum = (Console.ReadLine().Split(' '));

        /*int?????????????§????????????????*/
        long[] intNum = strNum.Select(s => long.Parse(s)).ToArray();
        Array.Sort(intNum);

        /*????°????????????§??????????¨??????¨???*/
        Console.WriteLine("{0} {1} {2}", intNum[0], intNum[count - 1], intNum.Sum());
    }
}

Measured memory_bytes: 10796
#include <stdio.h>
#include <cstring>
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
int main() {
  char s[200001];
  scanf("%s",s);
  int l=strlen(s);
  int r[2019];
  int nr[2019];
  int rr=0;
  for(int i=0;i<2019;i++){
    r[i]=0;
  };
  for(int i=0;i<l;i++){
    for(int j=0;j<2019;j++){
      nr[j]=0;
    };
    for(int j=0;j<2019;j++){
      nr[(j*10+ctoi(s[i]))%2019]+=r[j];
    };
    nr[ctoi(s[i])]++;
    rr+=nr[0];
    for(int j=0;j<2019;j++){
      r[j]=nr[j];
    };
  };
  printf("%d",rr);
  return 0;
}

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

using namespace std;
const int N = 1e5+7;

int a[N];
int dp[N];

int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i];
	dp[2] = abs(a[2]-a[1]);
	for(int i=3;i<=n;i++){
		dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n]<<"\n";
	return 0;
}

Measured memory_bytes: 4396
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define OJ \
        freopen("input.txt","r",stdin); \
        freopen("output.txt","w",stdout);

int main()
{ 
   
//  OJ;
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
  char n;
  cin>>n;
  if(n-'A'<=26)
  {
      cout<<"A";
  }
  else{
      cout<<"a";
  }
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
using namespace std;

int n;
int t[100002];

int main() {

  while (cin >> n) {
    for (int i = 0; i < n; i++) {
      cin >> t[i];
    }

    // 2x
    int xMin = 0, xMax = 1000000001;
    
    while (true) {
      int x = (xMin + xMax) / 2;

      int status = 0;

      int preX = x;
      for (int i = 0; i < n; i++) {
        if (preX > t[i]) {
          if (i % 2 == 0) {
            status = 1;
            break;
          } else {
            status = -1;
            break;
          }
        }
        preX = t[i] - preX;
      }

      if (status == 0 && preX == x) {
        xMin = x;
        xMax = x + 1;
        break;
      }

      if (status == 1 || (status == 0 && preX < x)) {
        xMax = x;
      } else {
        xMin = x + 1;
      }
    }

    cout << xMin * 2;
    
    int preX = t[0] - xMin;

    for (int i = 0; i < n - 1; i++) {
      cout << " " << preX * 2;
      preX = t[i + 1] - preX;
    }
    cout << endl;
  }
}


Measured memory_bytes: 1664
N = int(input())
txys = [list(map(int, input().split())) for _ in range(N) ]
txys.insert(0, [0, 0, 0])

for i in range(N):
    t1, x1, y1 = txys[i]
    t2, x2, y2 = txys[i+1]
    dt = t2 - t1
    dist = abs(x1 - x2) + abs(y1 - y2)
    if dt % 2 != dist % 2 or dist > dt:
        print("No")
        exit()
print("Yes")



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

int mini(int t[]);

int main()
{
    int num[5], d[5], n;

    for(int i=0; i<5; i++){
        cin >> num[i];
    }

    /*for(int s=0; s<4; s++){
        for(int t=s+1; t<5; t++){
            if(num[t] > num[s]){
                int tmp = num[t];
                num[t] = num[s];
                num[s] = tmp;
            }
        }
    }*/

    for(int l=0; l<5; l++){
        if(num[l]%10 != 0)
            d[l] = num[l]%10;
        else
            d[l] = 10;    
    }

    n = mini(d);
    
    int min = num[0]+num[1]+num[2]+num[3]+num[4]-d[0]-d[1]-d[2]-d[3]-d[4]+d[n]+40;

    

    cout << min <<  endl;
    
    return 0;

}

int mini(int t[])
{
    int a =123;
    int c = 0;
    for(int b=0; b<5; b++)
        if(a > t[b]){
            a = t[b];
            c = b;
    }

    return c;
}



Measured memory_bytes: 256
#ifdef __cplusplus
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#else
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#endif

#define rep(i,n) for(int i = 0; i < (n); ++i)
 
#define BIG_PRIME 1000000007
#define BP_remainder(x) ((x) % BIG_PRIME)

#define INF (1 << 30)
#define INF_NEG (INF * -1)
#define INF_LONG (1LL << 62)
#define INF_LONG_NEG (INF_LONG * -1L)

typedef long long ll;
typedef char str255[256];
int StrLen(char *s) { for(int ptr = 0;; ++ptr) if(!s[ptr]) return ptr; } 
// char * の後ろから n 文字削除, 削除後の文字数を返す
int StrDel(char *s, int n) { int l = StrLen(s); s[l - n + 1] = '\0'; return l - n; }

int NumDigits(int i){ char s[20]; return sprintf(s, "%d", i); }
int NumDigitsLL(long long l){ char s[30]; sprintf(s, "%lld", l); return strlen(s); }

int is1stAns = 1;
#ifdef __cplusplus
template <class T> 
void print(T t) { if (is1stAns) cout << t, is1stAns = 0; else cout << " " << t; }
#else
void printI(int    i) { if (is1stAns) printf(  "%d", i), is1stAns = 0; else printf(  " %d", i); }
void printL(ll     l) { if (is1stAns) printf("%lld", l), is1stAns = 0; else printf(" %lld", l); }
void printD(double d) { if (is1stAns) printf("%.9f", d), is1stAns = 0; else printf(" %.9f", d); }
void printC(char   c) { if (is1stAns) printf(  "%c", c), is1stAns = 0; else printf(  " %c", c); }
void printS(char  *s) { if (is1stAns) printf(  "%s", s), is1stAns = 0; else printf(  " %s", s); }
#endif

ll min(ll a, ll b){ if (a < b) return a; else return b; }
ll max(ll a, ll b){ if (a > b) return a; else return b; }

signed main()
{
#ifdef __cplusplus
    cout << fixed << setprecision(9);
#endif

    ll N; scanf("%lld", &N);
    ll *A = (ll *)malloc(sizeof(ll) * N);
    rep(i, N) scanf("%lld", &A[i]);

    ll maxA = 0;
    ll nextMax = 0;

    rep(i, N){
        if (maxA < A[i]){
            nextMax = maxA;
            maxA = A[i];
        } else if (nextMax < A[i]){
            nextMax = A[i];
        }
    }

    rep(i, N){
        if (A[i] != maxA)
            printf("%lld\n", maxA);
        else
            printf("%lld\n", nextMax);
    }

    free(A);
    return 0;
}


Measured memory_bytes: 3072
from bisect import bisect_left
import sys
input = sys.stdin.readline
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    def same(self, x, y):
        return self.find(x) == self.find(y)
def main():
    N, Q = map(int, input().split())
    kouji = [list(map(int, input().split())) for _ in range(N)]
    D = [int(input()) for _ in range(Q)]
    ans = [-1]*Q
    nxt = [i+1 for i in range(Q)]
    uf = UnionFind(Q)
    kouji.sort(key=lambda x: x[2])
    for i in range(N):
        S, T, X = kouji[i]
        L = S-X
        R = T-X-1
        L_idx = bisect_left(D, L)
        R_idx = bisect_left(D, R+1)
        p = L_idx
        while p < R_idx:
            if ans[p] == -1:
                ans[p] = X
                uf.union(L_idx, p)
                nxt[p] = R_idx
                p += 1
            else:
                par = uf.find(p)
                p = nxt[par]
                uf.union(L_idx, par)
                par = uf.find(par)
                if nxt[par] < R_idx:
                    nxt[par] = R_idx
                if nxt[par] < p:
                    nxt[par] = p
    for i in range(Q):
        print(ans[i])

if __name__ == "__main__":
    main()


Measured memory_bytes: 80616
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {

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

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

		int[][] num = new int[n + 1][n + 1];
		for (int[] t : num) {
			Arrays.fill(t, -1);
		}
		for (int i = 0; i < m; i++) {
			StringTokenizer tokenizer = new StringTokenizer(scanner.next(), ",");
			int a = Integer.valueOf(tokenizer.nextToken());
			int b = Integer.valueOf(tokenizer.nextToken());
			int c = Integer.valueOf(tokenizer.nextToken());
			int d = Integer.valueOf(tokenizer.nextToken());
			num[a][b] = c;
			num[b][a] = d;

		}
		StringTokenizer tokenizer = new StringTokenizer(scanner.next(), ",");
		int q = Integer.parseInt(tokenizer.nextToken());
		int r = Integer.parseInt(tokenizer.nextToken());
		int ans = Integer.parseInt(tokenizer.nextToken())
				- Integer.parseInt(tokenizer.nextToken());
		int qs = getYen(q, r, num);
		int rs = getYen(r, q, num);
		ans = ans - qs - rs;
		System.out.println(ans);
	}

	public static int getYen(int q, int r, int[][] num) {
		int[] cost = new int[num.length];
		Arrays.fill(cost, Integer.MAX_VALUE);
		Deque<Integer> deque = new ArrayDeque<Integer>();
		cost[q] = 0;
		deque.push(q);
		while (!deque.isEmpty()) {
			for (int i = 0; i < deque.size(); i++) {
				int p = deque.pop();
				for (int j = 1; j < num.length; j++) {
					if (num[p][j] != -1 && num[p][j] + cost[p] < cost[j]) {
						deque.push(j);
						cost[j] = num[p][j] + cost[p];
					}
				}
			}
		}
		return cost[r];
	}
}

Measured memory_bytes: 17168
N=int(input())
xy=[list(map(int,input().split())) for _ in range(N)]
ans=0
for i in range(N):
    for j in range(i+1,N):
        d=((xy[i][0]-xy[j][0])**2+(xy[i][1]-xy[j][1])**2)**0.5
        ans+=2*d
print(ans/N)


Measured memory_bytes: 9324
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
	int n,d,x,y,no=0;
  	double di;
  	//vector< pair<int,int> > v;
  	cin>>n>>d;
  	for(int i=0;i<n;i++){
     	cin>>x>>y;
      	di=pow(pow(x,2)+pow(y,2),0.5);
      	if(di<=d)
          no++;
    }
  	cout<<no;
  	
}

Measured memory_bytes: 4244
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD (1'000'000'007)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

vector<vector<int>> graph;
vector<int> color;

// bool dfs(int c, int p){
//     color[p]=c;
//     for(int cc : graph[p]){
//         if(color[cc]==c) return false;
//         if(color[cc]==0) if(!dfs(-c, cc)) return false;
//     }    
//     return true;
// }

bool dfs(int v, int c) {
	color[v] = c;
	for (int i = 0; i < graph[v].size(); ++i) {
		if (color[graph[v][i]] == c)return false;//隣の色が同じなら失敗
		if (color[graph[v][i]] == -1) {//まだ塗られていないなら
			if (!dfs(graph[v][i], 1 - c))return false;//if文は()のなかが0のとき実行されない。つまり、これが実行されるのは!dfs=1つまりdfsがfalseを返したとき
		}
	}
	return true;
}

int main(void)
{
    ll n,m;
    cin >> n >> m;
    graph.resize(n, vector<int>());
	color.resize(n, -1);
    REP(i, m){
        int a,b;
        cin >> a >> b;
        a--;b--;
        graph[a].pb(b);
        graph[b].pb(a);
    }

    ll ans=0;
    if(dfs(0,0)){
    // if(dfs(1,0)){
        ll w=0;
        REP(i, n){
            if(color[i]==1) w++;
        }
        ans = w * (n-w) - m; 
    }else{
        ans = n*(n-1)/2 - m;
    }

    pr(ans);
}

Measured memory_bytes: 6528
import java.util.Scanner;
 
class Main {
  public static void main(String args[]) {
    Scanner scanner = new Scanner(System.in);

    while (true) {
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        if (x == 0 && y == 0){
           break; 
        }
        if (x < y){
            System.out.println(x + " " + y);
        } else {
            System.out.println(y + " " + x);
        }
    }
    
    
    scanner.close();
  }
}


Measured memory_bytes: 36248
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1'000'000'000ll + 7;
//const i64 smod = 998244353ll;
//const i64 inf = 1'000'000'000'000'000'000ll + 7;
//const i64 inf = 1'000'000'007;

const double inf = 1e9;

const long double eps = 1e-8;



int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed); cerr.precision(15); cerr.setf(ios::fixed);

    string s, t;
    cin >> s >> t;

    i64 R = t.size();
    for (i64 i = 0; i < s.size() - t.size() + 1; i++) {
        i64 r = 0;
        for (i64 j = 0; j < t.size(); j++) {
            //cerr << i + j << endl;
            if (s[i + j] != t[j]) {
                r += 1;
            }
        }
        R = min(R, r);
    }

    cout << R << endl;

    return 0;
}

Measured memory_bytes: 3656
import numpy as np

def transfer(state, x, y):
    state[x][0] -= 1
    state[y][0] += 1
    if state[x][0] == 0:
        if state[x][1] == 1:
            state[x][1] = 0
            state[y][1] = 1
    else:
        if state[x][1] == 1:
            state[y][1] = 1
            
n, m = map(int, input().split())

state = [[1, 0] for _ in range(n)]
state[0][1] = 1
for i in range(m):
    x, y = map(lambda x: int(x) - 1, input().split())
    transfer(state, x, y)

print(np.sum(state, axis=0)[1])

Measured memory_bytes: 23808
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;

#define Y first
#define X second

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int MAX = 1000;

int w, h;
vector<int> x1(MAX), y1(MAX), x2(MAX), y2(MAX), lis;
vector<vector<int> > board(MAX * 2 + 2, vector<int>(MAX * 2 + 2));

void compress(int& size, vector<int>& c1, vector<int>& c2) {
	lis.clear();
	lis.reserve(c1.size() * 2 + 2);

	lis.push_back(0);
	lis.push_back(size);

	for(int i = 0; i < c1.size(); ++i) {
		lis.push_back(c1[i]);
		lis.push_back(c2[i]);
	}

	sort(lis.begin(), lis.end());
	lis.erase(unique(lis.begin(), lis.end()), lis.end());

	for(int i = 0; i < c1.size(); ++i) {
		c1[i] = lower_bound(lis.begin(), lis.end(), c1[i]) - lis.begin();
		c2[i] = lower_bound(lis.begin(), lis.end(), c2[i]) - lis.begin();
	}

    size = lis.size();
}

void bfs(int y, int x) {
	queue<pair<int, int> > que;
	que.push(make_pair(y, x));
	board[y][x] = 1;

	while(!que.empty()) {
		pair<int, int> p = que.front();
		que.pop();

		for(int i = 0; i < 4; ++i) {
			int nx = p.X + dx[i];
			int ny = p.Y + dy[i];

			if(nx < 0 || nx >= w - 1 || ny < 0 || ny >= h - 1 || board[ny][nx])
				continue;

			board[ny][nx] = 1;
   			que.push(make_pair(ny, nx));
		}
	}
}

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

	while(cin >> w >> h, w | h) {
		int n;
		cin >> n;

		for(int i = 0; i < n; ++i)
			cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];

		compress(w, x1, x2);
		compress(h, y1, y2);

		for(int i = 0; i < h; ++i)
			fill(board[i].begin(), board[i].end(), 0);

		for(int i = 0; i < n; ++i) {
			board[y1[i]][x1[i]] += 1;
   			board[y1[i]][x2[i]] -= 1;
   			board[y2[i]][x1[i]] -= 1;
   			board[y2[i]][x2[i]] += 1;
		}

		for(int i = 0; i < h; ++i)
			for(int j = 0; j < w - 1; ++j)
				board[i][j + 1] += board[i][j];

		for(int j = 0; j < w; ++j)
			for(int i = 0; i < h - 1; ++i)
				board[i + 1][j] += board[i][j];

		for(int i = 0; i < h; ++i)
			board[i][w - 1] = 1;

		for(int i = 0; i < w; ++i)
			board[h - 1][i] = 1;

		int ans = 0;
		for(int i = 0; i < h; ++i) {
			for(int j = 0; j < w; ++j) {
				if(!board[i][j]) {
					++ans;
					bfs(i, j);
				}
			}
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 16980
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
#ifdef DEBUG
#define display(x) cerr << #x << " = " << x << endl;
#define displaya(a, st, n)\
	{cerr << #a << " = {";\
	for(int qwq = (st); qwq <= (n); ++qwq) {\
		if(qwq == (st)) cerr << a[qwq];\
		else cerr << ", " << a[qwq];\
	} cerr << "}" << endl;}
#define displayv(v) displaya(v, 0, (int)(v).size() - 1)
#endif
template<typename T> bool chmin(T &a, const T &b) { return a > b ? a = b, true : false; }
template<typename T> bool chmax(T &a, const T &b) { return a < b ? a = b, true : false; }

int n;
vector<int> p;

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	long long cnt = 0;
	int xa = 0, bx = 0;
	bool only = 0;
	for(int i = 0; i < n; ++i) {
		string s; cin >> s;
		char last = 0;
		for(char c : s) {
			if(c == 'A') last = c;
			else if(c == 'B') {
				cnt += (last == 'A');
				last = c;
			} else {
				last = c;
			}
		}
		if(s[0] == 'B') ++bx;
		if(s.back() == 'A') ++xa;
		only |= ((s[0] == 'B') != (s.back() == 'A'));
	}
	LL extra = max(0, min(bx, xa) - !only);
	cout << (cnt + extra) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int f(int &id,string s,string t){
	if(isalpha(s[id])) return t[s[id++]-'a']-'0';
	id++;
	char c=s[id];
//	cout<<c<<' '<<id<<endl;
	id++;
	int x=f(id,s,t),y=f(id,s,t);
	id++;
	if(c=='+') return x|y;
	if(c=='*') return x&y;
	if(c=='^') return x^y;
	assert(0);
}

int main(){
	while(1){
		string s,t;
		cin>>s;
		if(s==".") break;
		cin>>t;
		int id=0,x=f(id,s,t),res=0;
		for(int i=0;i<10000;i++){
			t=to_string(i);
			while(t.size()<4) t='0'+t;
			id=0;
			if(x==f(id,s,t)) res++;
		}
		cout<<x<<' '<<res<<endl;
	}
}


Measured memory_bytes: 3252