akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	long long x, k, d;
	cin >> x >> k >> d;

	x = abs(x);

	long long ans = 0;
	if (x / d >= k) {
		ans = x - (d * k);
	}
	else {
		k -= x / d;
		x -= (x / d) * d;
		if (k % 2 == 0) {
			ans = x;
		}
		else {
			ans = x - d;
			ans = abs(ans);
		}
	}

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

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
using namespace std;

const long long int INF=999999999999999;

long long int N,L,T,X[100005],W[100005],touch=0,after[100005],output[100005],zero;

int main() {
	cout << fixed << setprecision(5);
	cin>>N>>L>>T;
	for(int i=0;i<N;i++)
	{
		cin>>X[i]>>W[i];
		after[i]=(X[i]-(2*W[i]-3)*T)%L;
		after[i]=(after[i]+L)%L;
	}
	zero=after[0];
	for(int i=1;i<N;i++)
	{
		if(W[0]==1)
		{
			if(W[i]==2&&X[i]-X[0]<2*T)
			{
				touch+=1+(2*T-(X[i]-X[0])-1)/(L);
			}
		}
		
		if(W[0]==2)
		{
			if(W[i]==1&&L+X[0]-X[i]<=2*T)
			{
				touch+=1+(2*T+(X[i]-X[0]-L))/(L);
			}
		}
	}
	touch%=N;
	//cout<<touch<<endl;
	if(W[0]==2)touch=(5*N-touch)%N;
	//cout<<touch<<endl;
	sort(after,after+N);
	for(int i=0;i<N;i++)
	{
		if(after[i]==zero)
		{
			for(int j=0;j<N;j++)
			{
				output[(touch+j)%N]=after[(i+j)%N];
			}
			break;
		}
		//cout<<aft
	}
	for(int i=0;i<N;i++)
	{
		cout<<output[i]<<endl;
	}
}


Measured memory_bytes: 4352
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using PP = std::pair<ll,P>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

const int MOD = 1e9+7;
const ll INF = 1e18;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

int main(){
	char c, prev = getchar();
	bool ok = false;
	while((c=getchar())!='\n'){
		if(prev=='A' and c=='C') ok = true;
		prev = c;
	}
	if(ok) puts("Yes");
	else puts("No");
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define COUT(x) cout<<x<<"\n"

const ll INF = 1e18;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v){ll a = v[0]; for (ll i = 1; i<SIZE(v); i++) {a = gcd(a, v[i]);} return a;}
ll LCM(VI v){ll a = v[0]; for (ll i = 1; i<SIZE(v); i++) {a = lcm(a, v[i]);} return a;}


void Main()
{
	ll N;
	ll res=0;
	string sres;
	cin>>N;
	ll val=100.0;
	while (val<N){
		val+=val*0.01;
		res++;
	}

	cout << res << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 3652
n, x, d = map(int, input().split())
mp ={}
#初項はマイナスの可能性あり
if d == 0:
    if x == 0:
        print(1)
    else:
        print(n+1)
    exit()

for i in range(n+1):
    a = i*x
    L = (i*(i-1)//2)
    #min = a + L*d
    #max = a + R*d
    R = (i*(2*n-i-1)//2)
    C = a//d
#    if L > R:
#        L, R = R, L
    #ディクショナリは定義されていない状態でappendできない
    if mp.get(a%d):
        mp[a%d].append([C+L, C+R])
    else:
        mp[a%d] = [[C+L, C+R]]

inf = float('inf')
ans = 0
for j in mp:
    now = mp[j]
    now.sort()
    pl = -inf
    for l, r in now:
#        print('time:', j, 'l:', l, 'r:',r)
        if r <= pl:
            continue
        if l > pl:
            ans += r-l+1
        else:
            ans += r-pl
        pl = r
print(ans)

Measured memory_bytes: 92376
N = int(input())
ABC = [list(map(int, input().split())) for _ in range(N - 1)]
Q, K = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(Q)]

graph = [[] for _ in range(N + 1)]
for A, B, C in ABC:
  graph[A].append((B, C))
  graph[B].append((A, C))
#print("graph:", graph)

INF = 10 ** 15
stack = [K]
depth = [INF] * (N + 1)
depth[K] = 0

while stack:
  a = stack.pop()
  for b, d in graph[a]:
    if depth[b] > depth[a] + d:
      depth[b] = depth[a] + d
      stack.append(b)
#print(depth[1:])

for X, Y in XY:
  print(depth[X] + depth[Y])

Measured memory_bytes: 109016
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define PI (acos(-1))
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/


class UnionFind {
public:
	vector<ll> v;
	UnionFind(size_t size) : v(size, -1) {}

	ll root(ll x) {
		return (v[x] < 0 ? x : v[x] = root(v[x]));
	}

	bool is_root(ll x) {
		return x == root(x);
	}

	bool is_same(ll x, ll y) {
		return root(x) == root(y);
	}

	bool unite(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (v[x] > v[y]) swap(x, y);
		v[x] += v[y];
		v[y] = x;
		return true;
	}

	ll size(ll x) {
		return -v[root(x)];
	}
};


constexpr ll N_MAX = 2;
constexpr ll L_MAX = 100000;

ll N, K, L;

ll p[L_MAX];
ll q[L_MAX];
ll r[L_MAX];
ll s[L_MAX];

void input() {
	scanf("%lld%lld%lld", &N, &K, &L);
	UnionFind a(N),b(N);
	rep(i, K) {
		scanf("%lld%lld", p + i, q + i);
		p[i]--;q[i]--;
		a.unite(p[i],q[i]);
	}
	rep(i, L) {
		scanf("%lld%lld", r + i, s + i);
		r[i]--;s[i]--;
		b.unite(r[i],s[i]);
	}

	map<pair<ll,ll>,ll> m;
	rep(i,N){
		auto t=make_pair(a.root(i),b.root(i));
		m[t]++;
	}
	rep(i,N){
		auto t=make_pair(a.root(i),b.root(i));
		cout<<m[t];
		if(i==N)cout<<endl;
		else cout<<' ';
	}
}

signed main() {
	input();

	return 0;
}


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

#define ALL(a) (a).begin(), (a).end()
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define rep(i, n) FOR(i, 0, n)
#define repi(i, n) FOR(i, 1, n + 1)
#define pp(v) cerr << #v "=" << (v) << endl;
#define ppa(v) cerr << "- " << #v << endl; rep(i,v.size()) cerr << #v << "[" << i << "] = " << v[i] << endl;
#define div_ceil(a,b) ((a) + ((b) - 1)) / (b)
#define UNIQUE(v) v.erase( unique(ALL(v)), v.end() );
#define INF 0x3f3f3f3f
#define LLINF 1000111000111000111LL
#define MOD 1000000007
#define TIME system("date +%M:%S.%N")
using Graph = vector<vector<int>>;
using ll = long long;
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

#define mp make_pair


int main() {
  ll a,b,k;cin>>a>>b>>k;
  ll c = a - k;
  ll d = a + b - k;
  if (c<0) c=0;
  if (d<0) d=0;
  if (d>b) d = b;
  cout << c << " " << d << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
using namespace std;
typedef long long ll;
typedef vector<int>VI;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define reprev(i, n) for (int i = (int)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define fi first
#define se second
#define MAX 100100//5
#define MAX_N 200100
#define MAX_B 1001001//6
#define MAX_S 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1 << 29
#define INFTY 1000000000000000000LL
#define MAX_INT INT_MAX
#define MAX_LL LLONG_MAX
int factorial(int n){
    if(n==0)return 1;
    return n*factorial(n-1);
}
int main(){
    int n;cin>>n;
    int x[10],y[10];
    rep(i,n)cin>>x[i]>>y[i];
    //最大で8!の全探索(40000ぐらい)
    double sum=0;
    int f=factorial(n-1)*2;
    rep(i,n)for(int j=i+1;j<n;j++){
        double d=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
        sum+=d*(double)f;
    }
    double ans=sum/(double)factorial(n);
    printf("%.10lf\n",ans);
}

Measured memory_bytes: 256
import sys
from collections import deque
H,W=map(int,input().split())
A=[[c for c in l.strip()] for l in sys.stdin]
maze=[[3000]*W for i in range(H)]
q=deque([])
start=[]
dy=[1,0,-1,0]
dx=[0,1,0,-1]
for i in range(H):
  for j in range(W):
    if(A[i][j]=="#"):
      q.append((i,j))
#print(start)
x=0
y=maze[:]

for i in q:
  maze[i[0]][i[1]]=0
while(q):
  c=q.popleft()
  for j in range(4):
    if(c[0]+dy[j]>=0 and c[0]+dy[j]<H and c[1]+dx[j]>=0 and c[1]+dx[j]<W):
      if(maze[c[0]+dy[j]][c[1]+dx[j]]==3000 and A[c[0]+dy[j]][c[1]+dx[j]]=="."):
        q.append((c[0]+dy[j],c[1]+dx[j]))
        maze[c[0]+dy[j]][c[1]+dx[j]]=maze[c[0]][c[1]]+1
        
        x=max(x,maze[c[0]+dy[j]][c[1]+dx[j]])
print(x)


Measured memory_bytes: 123612
import scala.collection.mutable

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N = sc.nextInt()
  val hashMap = mutable.Map[Int, Int]()
  for (_ <- 1 to N) {
    val i = Integer.numberOfTrailingZeros(sc.nextInt()).min(2)
    hashMap.update(i, hashMap.getOrElse(i, 0) + 1)
  }
  val isSortable =
    hashMap.getOrElse(0, 0) + (if (hashMap.contains(1)) 1 else 0) <= hashMap.getOrElse(2, 0) + 1
  println(if (isSortable) "Yes" else "No")
}


Measured memory_bytes: 58216
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int H, W;
	cin >> H >> W;
	
	vector<string> maps;
	REP(i, H) {
		string s;
		cin >> s;
		maps.push_back(s);
	}
	
	vector<vector<int>> done(H, vector<int>(W, 0));
	int dx[]{1, 0}, dy[]{0, 1};
	
	bool ans = true;
	int cy = 0, cx = 0;
	while (true) {
		done[cy][cx] = true;
		if (cy == H - 1 && cx == W - 1) break;
		auto isinmap = [&](int y, int x) { return 0 <= y && y < H && 0 <= x && x < W; };
		bool update = false;
		REP(i, 2) {
			int ny = cy + dy[i], nx = cx + dx[i];
			if (isinmap(ny, nx) && maps[ny][nx] == '#') {
				cy = ny;
				cx = nx;
				update = true;
				break;
			}
		}
		if (!update) break;
	}
	
	ans &= cy == H - 1 && cx == W - 1;
	REP(i, H) REP(j, W) if (!done[i][j] && maps[i][j] == '#') ans = false;
	puts([&] {
		return ans;
	}() ? "Possible": "Impossible");
	
	return 0;
}


Measured memory_bytes: 256
#import copy

n=int(input())
A=input().split()
C=A[:] #参照渡しのため

def bubble_sort(n,A):
  flag=True
  i=0
  while flag:
    flag=False
    for j in reversed(range(i+1,n)):
      if int(A[j][1])<int(A[j-1][1]):
        tmp=A[j]
        A[j]=A[j-1]
        A[j-1]=tmp
        flag=True
    i+=1
  return A

def selection_sort(n,A):
  for i in range(n):
    minj=i
    for j in range(i+1,n):
      #print(A[minj],A[j])
      if int(A[j][1])<int(A[minj][1]):
        minj=j
    tmp=A[i]
    A[i]=A[minj]
    A[minj]=tmp
    # 途中で入れ替わるからnot stable
    #print("---")
  return A

x=bubble_sort(n,A)
y=selection_sort(n,C)
print(*x) # stable
print('Stable')
print(*y) # not stable
print('Stable' if x==y else 'Not stable')



Measured memory_bytes: 5612
import java.util.*;

public class Main{
	public static void main(String[] args){  
  		Scanner sc = new Scanner(System.in);
      	String S = sc.next();
      
      	for(char i='a'; i<='z'; i++){
         	if(S.indexOf(i) >= 0){
            	continue;  
            } else {
            	System.out.println(i);
              	return;
            }
        }
  		System.out.println("None");
    }
}

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

def prime_fact(x):
    fact=[]
    for i in range(2, int(x**(0.5))+1):
        while x%i==0:
            fact.append(i)
            x//=i
    if x!=1:
        fact.append(x)
    if not fact:
        fact=[x]
    return fact

def eratosthenes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]
p=eratosthenes(100)
d={}
for p_i in p:
    d[p_i]=0
for i in range(2,n+1):
    pf=prime_fact(i)
    for pf_i in pf:
        d[pf_i]+=1

cnt74=0
cnt24=0
cnt14=0
cnt4=0
cnt2=0

for key in d:
    if d[key]>=74:
        cnt74+=1
    if d[key]>=24:
        cnt24+=1
    if d[key]>=14:
        cnt14+=1
    if d[key]>=4:
        cnt4+=1
    if d[key]>=2:
        cnt2+=1

print(int(cnt74+(cnt2-1)*cnt24+(cnt4-1)*cnt14+(cnt2-2)*cnt4*(cnt4-1)/2))


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(){

	int n, a, b, ap = 0, bp = 0;

	cin >> n;

	while (n != 0){

		for (int i = 0; i < n; i++){
			cin >> a >> b;

			//?????°?????´??°
			if (a > b)
				ap += a + b;
			else if (a < b)
				bp += a + b;
			else{
				ap += a;
				bp += b;
			}
		}

		cout << ap << " " << bp << endl;

		ap = 0;
		bp = 0;

		cin >> n;

	}
}

Measured memory_bytes: 1160
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<cstdio>
#include<algorithm>
#define LL long long
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int>pii;
int n,n2;
char s[6010];
int pos[6010];
int a[3010],b[3010];
string dp[6010],ans;
int main(){
	cin>>n;
	n2=2*n;
	scanf("%s",s+1);
	for(int i=1;i<=n2;i++)
		if(s[i]=='a')a[++a[0]]=i,pos[i]=a[0];
		else b[++b[0]]=i,pos[i]=b[0];
	for(int i=n;i>=1;i--){
		if(a[i]<b[i]){
			int k=i;
			for(int j=a[i]+1;j<b[i];j++)k=max(k,pos[j]);
			dp[i]="ab"+dp[k+1];
		}else{
			int k=i;
			while(k<n&&b[k+1]<a[k])k++;
			for(int j=b[i];j<=n2;j++)if(i<=pos[j]&&pos[j]<=k)dp[i]+=s[j];
			dp[i]+=dp[k+1];
		}
		dp[i]=max(dp[i],dp[i+1]);
		ans=max(ans,dp[i]);
	}
	cout<<ans<<endl;
	return 0;
}


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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();

		int ssa = Math.min(a, k);
		int ssc = Math.max(0, Math.min(k-a-b, c));

		System.out.println(ssa-ssc);
	}
}

Measured memory_bytes: 35692
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N, M, C;
	cin >> N >> M >> C;
	int B[25] = {}; 
	for(int i = 0; i < M; i++){
		cin >> B[i]; 
	}
	int ans = 0; 
	for(int q = 0; q < N; q++){
		int tmp = C; 
		for(int j = 0; j < M; j++){
			int a; cin >> a; 
			tmp += B[j] * a; 
		}
		if(tmp > 0) ans ++; 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] n = new int[5];
		for(int i=0;i<5;i++){
			n[i] = sc.nextInt();
		}
		Arrays.sort(n);
		for(int i=0;i<5;i++){
			if(i!=0)System.out.print(" ");
			System.out.print(n[4-i]);
		}
		System.out.println();
	}
}

Measured memory_bytes: 17232
N = int(input())
ans = [0 for _ in range(N)]
for z in range(1, 101):
  for y in range(1, 101):
    for x in range(1, 101):
      i = x**2 + y**2 + z**2 + x*y + y*z + z*x
      if i <= N:
        ans[i-1] += 1
        
for j in ans:
  print(j)

Measured memory_bytes: 69548
#include "bits/stdc++.h"
//#include <iostream>//POJ
//#include <vector>
//#include <string>
//#include <iomanip>
//#include <math.h>
using namespace std;
#define setc cin.tie(0);ios::sync_with_stdio(0)
#define repi(i,a,b) for(int i=(a), i##_len=(b); i<i##_len; ++i)
#define rep(i,n) repi(i,0,n)
#define repi_(i,a,b) for(int i=(a), i##_len=(b); i<=i##_len; ++i)
#define rep_(i,n) repi_(i,0,n)
#define all(x) (x).begin(),(x).end()
#define vsort(v) sort((v).begin(), (v).end())
#define gsort(v) tsort(v); reverse((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())
template<typename T> T vpop(vector<T> *v) {
	T res = v->back();
	v->pop_back();
	return res;
}
char vpop(string *v) {
	char res = v->back();
	v->pop_back();
	return res;
}
#define siz(v) ((int)(v).size())
#define ers(v, n) (v).erase((v).begin() + n)
#define cnt(v, n) count(all(v), n)
#define vmin(v) *min_element(v.begin(), v.end())
#define vmax(v) *max_element(v.begin(), v.end())
#define contain(q) !q.empty()
#define cont(q) !q.empty()
//#define qpop(q, a, b) a=q.back().first;b=q.back().second;q.pop()
//#define pqpop(p, a, b) a=q.top().first;b=q.top().second;q.pop()
#define el "\n"
#define sp " "
#define co(x) cout<<(x)<<el
#define coc(c, a, b) if(c)co((a));else co((b))
#define cosp(x) cout<<(x)<<' '
#define YES(c) coc(c,"YES", "NO")
#define Yes(c) coc(c,"Yes", "No")
#define yes(c) coc(c,"yes", "no")
#define POSSIBLE(c) coc(c, "POSSIBLE", "IMPOSSIBLE")
#define Possible(c) coc(c, "Possible", "Impossible")
#define possible(c) coc(c, "possible", "impossible")
#define inf INT_MAX
#define wildcard(T) numeric_limits<T>::min()

#define pb push_back
#define pq priority_queue
#define np next_permutation

#ifdef tqktmp_2
#define gc() getchar(); getchar()
#else
#define gc() 1
#endif
const unsigned int bf0 = (1 << 0);
const unsigned int bf1 = (1 << 1);
const unsigned int bf2 = (1 << 2);
const unsigned int bf3 = (1 << 3);
const unsigned int bf4 = (1 << 4);
const unsigned int bf5 = (1 << 5);
const unsigned int bf6 = (1 << 6);
const unsigned int bf7 = (1 << 7);

typedef long long lint;
typedef vector<int> ivec; typedef vector<string> svec;
typedef vector<vector<int>> ivvec;
typedef pair<int, int> P;

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

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

int main() {
	setc;

	lint k, n;
	cin >> n >> k;
	coc(n%k, "1", "0");

	gc();
}

Measured memory_bytes: 768
function prime(max){
   var arr=[];
   for(var i=0;i<=max;i++)arr[i]=i;
   arr[0]=false;
   arr[1]=false;
   var sqrt=Math.floor(Math.sqrt(max));
   for(var i=2;i<=sqrt;i++){
      if(arr[i]==false)continue;
         for(var j=i+i;j<=max;j+=i){
            arr[j]=false;
         }
   }
   var result=[];
   for(var i=0;i<=max;i++){
      if(arr[i]!==false)result.push(arr[i]);
   }
   return result;
}
var p=prime(30000);
var all=[];
for(var i=0;i<=90000;i++)all[i]=0;
for(var i=0;i<p.length;i++){
   var a=p[i];
   for(var j=i;j<p.length;j++){
      var b=p[j];
      for(var k=j;k<p.length;k++){
         var c=p[k];
         if(a+b<=c || b+c<=a || a+c<=b)break;
         all[a+b+c]++;
      }
   }
}
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n").map(Number);
arr.some(function(v){
   if(v==0)return true;
   console.log(all[v]);
});

Measured memory_bytes: 19372
// 
// Least common ancestor by heavy-light decomposition
//
// Description:
//   For a rooted tree T, LCA(u,v) is a vertex u
//   that is the deepest node that is a common ancestor of u and v.
//
// Algorithm:
//   A heavy-light decomposition finds a partition of a tree into
//   a set of paths that is recursively defined as follows:
//   1) root is contained in a "heavy" path that spans root-to-child
//   2) other childs are linked by "light" edges and the subtrees are
//      recursively decomposed by the heavy-light decomposition.
//      Here, all subtrees have fewer nodes than the "heavy" path.
//
//   If two nodes u and v are located in the same heavy-path, LCA is
//   immediately obtained (shallower node is the LCA). Otherwise,
//   climbing light links until these are located in the same heavy-path.
//   By construction, only O(log n) light-link-climb is enough to reach
//   the root of the tree; thus it gives O(log n) algorithm.
//
// Complexity:
//   O(n) for preprocessing,
//   O(log n) for query
//
// Verified:
//   AOJ GRL_5C
//
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

#define fst first
#define snd second
#define all(c) ((c).begin()), ((c).end())
#define TEST(s) if (!(s)) { cout << __LINE__ << " " << #s << endl; exit(-1); }


struct tree {
  int n;
  vector<vector<int>> adj;
  tree(int n) : n(n), adj(n) { }
  void add_edge(int s, int t) {
    adj[s].push_back(t);
    adj[t].push_back(s);
  }
  vector<int> size, depth, head, parent;
  void rootify(int r) {
    size = depth = parent = head = vector<int>(n, -1);
    function<int (int,int)> dfs = [&](int u, int p) {
      parent[u] = p;
      depth[u] = depth[p]+1;
      for (int v: adj[u]) 
        if (v != p) size[u] += dfs(v, u);
      return ++size[u];
    }; dfs(r, r);
    function<void (int,int)> dec = [&](int u, int s) {
      head[u] = s;
      int z = -1;
      for (int v: adj[u]) 
        if (head[v] < 0 && (z < 0 || size[z] < size[v])) z = v;
      for (int v: adj[u]) 
        if (head[v] < 0) dec(v, v == z ? s : v);
    }; dec(r, r);
  }
  int lca(int u, int v) {
    while (head[u] != head[v]) 
      if (depth[head[u]] < depth[head[v]]) v = parent[head[v]];
      else                                 u = parent[head[u]];
    return depth[u] < depth[v] ? u : v;
  }
};

int main() {
  int n;
  scanf("%d", &n);
  tree T(n);
  for (int u = 0; u < n ; ++u) {
    int k; 
    scanf("%d", &k);
    for (int j = 0; j < k; ++j) {
      int v;
      scanf("%d", &v);
      T.add_edge(u, v);
    }
  }
  T.rootify(0);
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    printf("%d\n", T.lca(u, v));
  }
}

Measured memory_bytes: 15796
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <complex>

using namespace std;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

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

    ll x, y;
    scanf("%lld %lld", &x, &y);
    int res = 1;
    while (2LL * x <= y) {
        ++res;
        x *= 2LL;
    }
    printf("%lld\n", res);
    
    return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    ii2(n, r); int ans;
    if(n >= 10) ans = r;
    else{
        ans = r + 100 * (10 - n);
    }
    out(ans);
}

Measured memory_bytes: 256
#include <map>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <sstream>
#include <vector>
#include <stack>
#include <utility>
#include <math.h>
using namespace std;

int main()
{
	int N, Y;
	cin >> N >> Y;
//	int tmp;
	int x, y, z;
	for (int i = 0; i <= N; i++)
	{
//		tmp = 0;

		//i枚の一万円札使うとする
		for (int j = 0; j <= N - i; j++)
		{
			//j枚の5000円札使うとする
			//残りN - i - j枚のお札があるので足す
			
			if (10000 * i + 5000 * j + 1000 * (N - i - j) == Y)
			{
				x = i, y = j, z = N - i - j;
				printf("%d %d %d\n", x, y, z);
				return 0;
			}
		}
	}

	printf("%d %d %d\n", -1, -1, -1);
	return 0;
}

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

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    char c;
    cin >> c;
    cout << char((int(c) - 'a' + 1) % 26 + 'a');
    
    return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<cassert>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const int inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;

signed main() {
	int x, y; cin >> x >> y;
	int cnt = 0;
	cnt += 100000 * max(0ll, 4 - x);
	cnt += 100000 * max(0ll, 4 - y);
	if (x == 1 && y == 1)cnt += 400000;
	cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	
	vector<int> b = a;
	sort(all(b));
	bool f = 0;
	if(a == b) f = 1;
	rep(i, n)REP(j, i+1, n){
		swap(a[i], a[j]);
		if(a == b) f = 1;
		swap(a[i], a[j]);
	}
	cout << (f ? "YES" : "NO") << endl;



}

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

int main() {
  int A, B, count = 0;
  cin >> A >> B;

  for (int i = A; i <= B; i++) {
    string org, inv;
    org = std::to_string(i);
    
    for (int j = (int)org.size(); j > 0; j--) {
      if ((int)inv.size() == 0 && org[j-1] == 0) {
        continue;
      }
      inv += org[j-1];
    }
    
    if (inv==org) {
      count += 1;
    }
  }
  cout << count;
}


Measured memory_bytes: 3580
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <string>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <functional>
#include <iterator>
#include <limits>
#include <numeric>
#include <utility>
#include <type_traits>
#include <cmath>
#include <cassert>
#include <cstdio>

using namespace std;
using namespace placeholders;

using LL = long long;
using ULL = unsigned long long;
using VI = vector< int >;
using VVI = vector< vector< int > >;
using VS = vector< string >;
using SS = stringstream;
using PII = pair< int, int >;
using VPII = vector< pair< int, int > >;
template < typename T = int > using VT = vector< T >;
template < typename T = int > using VVT = vector< vector< T > >;
template < typename T = int > using LIM = numeric_limits< T >;

template < typename T > inline istream& operator>>( istream &s, vector< T > &v ){ for ( T &t : v ) { s >> t; } return s; }
template < typename T > inline ostream& operator<<( ostream &s, const vector< T > &v ){ for ( int i = 0; i < int( v.size() ); ++i ){ s << ( " " + !i ) << v[i]; } return s; }
template < typename T > inline T fromString( const string &s ) { T res; istringstream iss( s ); iss >> res; return res; }
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

#define NUMBERED( name, number ) NUMBERED2( name, number )
#define NUMBERED2( name, number ) name ## _ ## number
#define REP1( n ) REP2( NUMBERED( REP_COUNTER, __LINE__ ), n )
#define REP2( i, n ) REP3( i, 0, n )
#define REP3( i, m, n ) for ( int i = ( int )( m ); i < ( int )( n ); ++i )
#define GET_REP( a, b, c, F, ... ) F
#define REP( ... ) GET_REP( __VA_ARGS__, REP3, REP2, REP1 )( __VA_ARGS__ )
#define FOR( e, c ) for ( auto &&e : c )
#define ALL( c ) begin( c ), end( c )
#define AALL( a ) ( std::remove_all_extents< decltype( a ) >::type * )a, ( std::remove_all_extents< decltype( a ) >::type * )a + sizeof( a ) / sizeof( std::remove_all_extents< decltype( a ) >::type )
#define DRANGE( c, p ) ( c ).begin(), ( c ).begin() + ( p ), ( c ).end()

#define SZ( v ) ( (int)( v ).size() )
#define EXIST( c, e ) ( ( c ).find( e ) != ( c ).end() )

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

#define PB push_back
#define EM emplace
#define EB emplace_back
#define BI back_inserter

#define MP make_pair
#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

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

	int N;
	cin >> N;

	int k = 1;
	for ( ; k * ( k + 1 ) / 2 < N; ++k );

	for ( ; 0 < k; --k )
	{
		if ( k <= N )
		{
			cout << k << endl;
			N -= k;
		}
	}

	return 0;
}


Measured memory_bytes: 256
K, S = list(map(int, input().split()))
if S <= K:
	print(int((S + 2) * (S + 1) / 2))
elif S <= 2 * K:
	ans = (-3 * (K ** 2) + 3 * K + 6 * S * K - 2 * (S ** 2) + 2) // 2
	print(int(ans))
else:
	print(int((3 * K - S + 1) * (3 * K - S + 2) / 2))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,a,b) for(register int i=a;i<=b;++i)
#define rpd(i,a,b) for(register int i=a;i>=b;--i)
#define rep1(i,x) for(register int i=head[x];i;i=nxt[i])
typedef long long ll;
using namespace std;
inline int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,h,ans;
int main(){
    n=read();h=read();
    rep(i,1,n){int x=read();if(x>=h)ans++;}
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
	int A, B;
	cin >> A >> B;
	if (A / 10 == 0 && B / 10 == 0){
		cout << A * B << endl;
	}
	else{
		cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        for (int i = 0; i < n; ++i) {
            lis[i] = sc.nextInt();
        }
        int ans = 0;
        for (int i = 1; i < n - 1; ++i) {
            // System.out.println(String.format("%d -- %d %d %d", i, lis[i - 1], lis[i], lis[i + 1]));
            if ((lis[i - 1] < lis[i] && lis[i] < lis[i + 1]) ||
                (lis[i - 1] > lis[i] && lis[i] > lis[i + 1])) {
                ans += 1;
            }
        }

        System.out.println(ans);
    }
}



Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    int r = n % 1000;
    if (r == 0) cout << 0 << endl;
    else cout << 1000 - r << endl;
    return 0;
}

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


n,w = map(int,input().split())
WV = [list(map(int,input().split())) for i in range(n)]
dp = [[0 for i in range(w+1)] for j in range(n+1)]

for i in range(n):
    for j in range(w+1):
        if j >= WV[i][0]:
            dp[i+1][j] = max(dp[i][j],dp[i][j-WV[i][0]]+WV[i][1])
        else:
            dp[i + 1][j] = dp[i][j]
print(dp[n][w])

Measured memory_bytes: 171656
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
mod util {
    use std::fmt::Debug;
    use std::io::{stdin, stdout, BufWriter, StdoutLock};
    use std::str::FromStr;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn chars() -> Vec<char> {
        line().chars().collect()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
    #[allow(dead_code)]
    pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
        let out = stdout();
        let writer = BufWriter::new(out.lock());
        f(writer)
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( [ $ t : ty ] ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; ( [ $ t : ty ] ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( [ $ t ] ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { eprintln ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }
const BIG_STACK_SIZE: bool = true;
#[allow(dead_code)]
fn main() {
    use std::thread;
    if BIG_STACK_SIZE {
        thread::Builder::new()
            .stack_size(32 * 1024 * 1024)
            .name("solve".into())
            .spawn(solve)
            .unwrap()
            .join()
            .unwrap();
    } else {
        solve();
    }
}
#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

fn solve() {
    let (n, m) = get!(u64, u64);
    println!("{}", min((2*n+m)/4, m/2));
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root, NIL;
int maxh;

Node treeSearch(Node u, int k){
  while( u != NIL && k != u->key ){
    if ( k < u->key ) u = u->left;
    else u = u->right;
  }
  return u;
}

void insert(int k){
  int H;
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL ){
    y = x;
    if ( z->key < x->key ){
      x = x->left;
    } else {
      x = x->right;
    }
  }

  z->parent = y;
  if ( y == NIL ){
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node u){
  if ( u == NIL ) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}
void preorder(Node u){
  if ( u == NIL ) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  maxh = 0;
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 20520
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H;
	string s;
	while(cin>>N>>M) {
		ll ans = (2<=N ? N*(N-1)/2 : 0)+(2<=M ? M*(M-1)/2 : 0);
		cout<<ans<<endl;
	}
	
	return 0;
}


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

bool check(vector<int> v,int x){
  v.erase(v.begin()+x);
  int a = v[1]-v[0];
  for(int i=2;i<v.size();i++)
    if(v[i]-v[i-1]!=a)return false;
  return true;
}

int main(){
  int n;
  while(cin >> n,n++){
    vector<int> h(n);
    for(int i=0;i<n;i++)cin >> h[i];
    for(int i=0;i<n;i++){
      if(check(h,i)){
	cout << h[i] << endl;
	break;
      }
    }
  }
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
using ld = long double;
const ul mod = 1000000007;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    bool same[n];
    bool result = false;

    rep(i, n) {
        ll d1, d2;
        cin >> d1 >> d2;
        same[i] = d1 == d2;
    }

    rep(i, n - 2) {
        if (same[i] && same[i + 1] && same[i + 2]) {
            result = true;
        }
    }

    cout << (result ? "Yes" : "No") << endl;
    return 0;
}



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

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define FILE "parade"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const ull ULLINF = numeric_limits<ull>::max();
const double PI = acos(-1.0);

int main()
{
//    freopen(FILE".in", "r", stdin);
//    freopen(FILE".out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int fv = 0, sv = 0;
    for(int i = 0; i < 3; i++)
    {
        int a;
        cin >> a;
        if(a == 5)
            fv++;
        if(a == 7)
            sv++;
    }
    cout << (fv == 2 && sv == 1 ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <cstdio>
#include <cmath>
#include <utility>
#include <bitset>
#include <complex>
#include <stack>
#include <tuple>
#include <math.h>
 
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll INF = 1e15;
const double eps=1e-8;
const ll MOD = (1e9)+7;
const ll MAX_N = 1 << 17;

int main(){
	ll N;
	cin >> N;
	ll c=0;
	for(int i=0;i<N;i++){
		ll x;
		cin >> x;
		if(x%2==1)
			c++;
	}
	if(c%2==0)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
const int INF = 1 << 27;
const ll LLINF = (ll)1 << 60;
const ll MOD = 1e9+7;

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

int N;
vector<vector<int>> multiply(vector<vector<int>>& a, vector<vector<int>>& b) {
  vector<vector<int>> ans(N, vector<int>(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      int x = 0;
      for (int k = 0; k < N; k++) {
        x = (x + (ll)a[i][k] * b[k][j]) % MOD;
      }
      ans[i][j] = x;
    }
  }
  return ans;
}

int main() {
  ll K;
  scanf("%d %lld\n", &N, &K);

  vector<vector<int>> a(N, vector<int>(N));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      scanf("%d", &a[i][j]);
    }
  }

  vector<vector<int>> ans(N, vector<int>(N, 0));
  for (int i = 0; i < N; i++) {
    ans[i][i] = 1;
  }

  while (K) {
    if (K & 1) {
      ans = multiply(ans, a);
    }
    a = multiply(a, a);
    K >>= 1;
  }

  int rlt = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      rlt = (rlt + ans[i][j]) % MOD;
    }
  }
  printf("%d\n", rlt);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mst(a, b) memset((a), (b), sizeof(a))
#define mp(a, b) make_pair(a, b)
#define pi acos(-1)
#define pii pair<int, int>
#define pb push_back
const int INF = 0x3f3f3f3f;
const double eps = 1e-10;
const int maxn = 3e3 + 7;
const int maxm = 5e5 + 10;
const int mod = 1e9 + 7;
ll dp[maxn][maxn];
ll s[maxn];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> s[i];
    for (int i = n; i > 0; --i)
    {
        for (int j = i; j <= n; ++j)
        {
            dp[i][j] = max(s[i] - dp[i + 1][j], s[j] - dp[i][j - 1]);
        }
    }
    cout << dp[1][n] << endl;
    return 0;
}

Measured memory_bytes: 70016