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

   typedef long long ll;
   typedef pair<ll, ll> Pii;
   typedef vector<ll> Vi;
   typedef vector<Vi> VVi;

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define RSORT(x) sort((x).rbegin(), (x).rend()
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

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

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}
   ll pow(ll a, ll b, ll m){if (b == 0) return 1; else if (b % 2 == 0) return (pow(a * a, b / 2, m) % m); else return (pow(a * a, b / 2) * a) % m;}
   ll residue(ll a, ll m){return ((a % m) + m) % m;};

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

int main(){
  string S; cin >> S;
  REP(i, S.size()){
    cout << (10 - (S[i] - '0'));
  }
  cout << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

A.sort(reverse=True)

dic = {}
for i in range(N):
    if A[i] in dic:
        dic[A[i]] += 1
    else:
        dic[A[i]] = 1
 
res = 0
for i in range(N):
    if A[i] in dic:
        n = 0
        tmp = A[i]
        while True:
            if tmp == 0:
                break
            tmp //= 2
            n += 1

        if 2 ** n - A[i] in dic:
            if 2 ** n - A[i] == A[i] and dic[A[i]] < 2:
                pass
            else:
                res += 1
                dic[2 ** n - A[i]] -= 1
                if dic[2 ** n - A[i]] == 0:
                    dic.pop(2 ** n - A[i])

        dic[A[i]] -= 1
        if dic[A[i]] == 0:
            dic.pop(A[i])
        
print(res)
    

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

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var N = input[0];
            var K = input[1];
            var A = ReadArrayInt();
            var cnt = new int[N + 1];
            for (int i = 0; i < A.Length; i++) cnt[A[i]]++;
            cnt = cnt.OrderByDescending(i => i).ToArray();
            var ans = N;
            for (int i = 0; i < K; i++) ans -= cnt[i];

            Console.WriteLine(ans);
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 39492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;
#define INF 100000000

int h, w;
vector<vector<char>> s;

int		bfs(Pair start)
{
	vector<Vec> distance(h, Vec(w, INF));
	distance[start.first][start.second] = 0;
	int max_distance = 0;
	queue<Pair> q;
	q.push(start);
	while(!q.empty())
	{
		int fi , fj;
		fi = q.front().first;
		fj = q.front().second;
		q.pop();
		if (fi - 1 >= 0 && s[fi-1][fj] == '.' && distance[fi-1][fj] == INF)
		{
			distance[fi-1][fj] = distance[fi][fj] + 1;
			max_distance = distance[fi][fj] + 1;
			q.push(Pair(fi-1, fj));
		}
		if (fi + 1 < h && s[fi+1][fj] == '.' && distance[fi+1][fj] == INF)
		{
			distance[fi+1][fj] = distance[fi][fj] + 1;
			max_distance = distance[fi][fj] + 1;
			q.push(Pair(fi+1, fj));
		}
		if (fj - 1 >= 0 && s[fi][fj-1] == '.' && distance[fi][fj-1] == INF)
		{
			distance[fi][fj-1] = distance[fi][fj] + 1;
			max_distance = distance[fi][fj] + 1;
			q.push(Pair(fi, fj-1));
		}
		if (fj + 1 < w && s[fi][fj+1] == '.' && distance[fi][fj+1] == INF)
		{
			distance[fi][fj+1] = distance[fi][fj] + 1;
			max_distance = distance[fi][fj] + 1;
			q.push(Pair(fi, fj+1));
		}

	}
	return (max_distance);
}


int		main(void)
{
	cin >> h >> w;
	s = vector<vector<char>>(h, vector<char>(w));
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			cin >> s[i][j];
	int max = 0;
	for (int i = 0; i < h; i++)
	{
		for (int j = 0; j < w; j++)
		{
			if (s[i][j] == '.')
			{
				int tmp = bfs(Pair(i, j));
				if (tmp > max)
					max = tmp;
			}
		}
	}
	cout << max << endl;
}
	


Measured memory_bytes: 256
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int maxX = scanner.nextInt();
    int minY = scanner.nextInt();

    for (int i = 0; i < N; i++) {
      int x = scanner.nextInt();
      if (x > maxX) maxX = x;
    }
    for (int i = 0; i < M; i++) {
      int y = scanner.nextInt();
      if (y < minY) minY = y;
    }

    if (minY - maxX > 0) {
      System.out.println("No War");
    } else {
      System.out.println("War");
    }
  }
}


Measured memory_bytes: 22996
while line = gets
  n,r = line.split.map(&:to_i)
  deck=(0..n-1).to_a
  cs  = gets.split.map(&:to_i)
  cs.each do |c|
    a = deck[n/2..n-1]
    b = deck[0...n/2]
    deck =[]
    until a.empty? && b.empty?
      c.times do
        if tmp =a.shift
          deck.push(tmp)
        end
      end
      c.times do
        if tmp = b.shift
          deck.push(tmp)
        end
      end
    end
  end
  p deck[-1]
end

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

int main () {
  int n;
  cin >> n;
  for (int i = 1; i <= 50000; i++) {
    int o = (int) i * 1.08;
    if (o == n) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int n,q,k;
vector<pair<int,ll>> v[100010];
ll dis[100010];

void dfs(int now){
  //cout<<now<<" "<<dis[now]<<endl;
  for(int i=0;i<v[now].size();i++){
    if(dis[v[now][i].first]==-1){
      dis[v[now][i].first]=dis[now]+v[now][i].second;
      dfs(v[now][i].first);
    }
  }
}

int main(){
  cin>>n;
  for(int i=1;i<n;i++){
    int a,b;
    ll c;
    cin>>a>>b>>c;
    v[a].push_back(make_pair(b,c));
    v[b].push_back(make_pair(a,c));
  }

  for(int i=0;i<=n;i++) dis[i]=-1;

  cin>>q>>k;
  dis[k]=0;
  dfs(k);

  for(int i=0;i<q;i++){
    int x,y;
    cin>>x>>y;
    cout<<dis[x]+dis[y]<<endl;
  }

  return 0;
}


Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int a[maxn];
set<int>s;
set<int>::iterator it;
int main()
{
  for(int i=0;i<3;i++)
    cin>>a[i];
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
  {
       if(i!=j)
       s.insert(a[i]+a[j]);
  }
  cout<<*(s.begin())<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int n;
	cin>>n;
	int s[2*n],ans=0;
	for(int i=0;i<2*n;i++)
	cin>>s[i];
	sort(s,s+2*n);
	for(int i=0;i<2*n;i=i+2)
	ans+=s[i];
	cout<<ans;
return 0;	
}

Measured memory_bytes: 256
macro_rules! get_one {
    ($t:ty) => {{
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse::<$t>().unwrap()
    }};

    ($t:ty; $n:expr) => {
        (0..$n).map(|_| get_one!($t)).collect::<Vec<_>>()
    };
}

macro_rules! get_vec {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::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_vec!($t)).collect::<Vec<_>>()
    };
}

fn main() {
    let n = get_one!(usize);
    let ps = get_vec!(usize);


    let mut ps_idx: Vec<_> = ps.into_iter().enumerate().collect();
    ps_idx.sort_by_key(|x| x.1);

    let mut count = 0;
    let mut max_idx = n;
    for &(idx, _) in ps_idx.iter() {
        if max_idx > idx {
            count += 1;
            max_idx = idx;
        }
    }

    println!("{}", count)

    // for i in ps_idx.iter() {
    //     match ps.iter().position(|&x| x == i) {
    //         Some(pos) => {
    //             count += 1;
    //             ps = ps.into_iter().take(pos).collect();
    //         },
    //         None => continue ,
    //     }
    // }
    //
    // println!("{}", count)

}


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

using namespace std;

typedef long long ll;

const int MX = 100005;

template <typename T> void read(T &x)
{
	x = 0; char c = getchar(); bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

struct NODE
{
	int a, b, c;
};

int X, Y, Z;
NODE seq[MX];

void input()
{
	read(X), read(Y), read(Z);
	for(int i=1; i<=X+Y+Z; i++) read(seq[i].a), read(seq[i].b), read(seq[i].c);
}

bool cmpb_a(NODE x, NODE y)
{
	return x.b-x.a < y.b-y.a;
}

multiset<int> st;
ll fl[MX], fr[MX];

void work()
{
	ll sum = 0, ans = 0;
	sort(seq+1, seq+X+Y+Z+1, cmpb_a);
	for(int i=1; i<=X+Y+Z; i++) sum += seq[i].c;
	for(int i=1; i<=X; i++) fl[i] = fl[i-1]+seq[i].a-seq[i].c, st.insert(seq[i].a-seq[i].c);
	for(int i=X+1; i<=X+Z; i++)
	{
		fl[i] = fl[i-1] + seq[i].a - seq[i].c;
		st.insert(seq[i].a-seq[i].c);
		fl[i] -= *st.begin();
		st.erase(st.begin());
	}
	st.clear();
	for(int i=X+Y+Z-1; i>=X+Z; i--) fr[i] = fr[i+1]+seq[i+1].b-seq[i+1].c, st.insert(seq[i+1].b-seq[i+1].c);
	for(int i=X+Z-1; i>=X; i--)
	{
		fr[i] = fr[i+1] + seq[i+1].b - seq[i+1].c;
		st.insert(seq[i+1].b-seq[i+1].c);
		fr[i] -= *st.begin();
		st.erase(st.begin());
	}
	for(int i=X; i<=X+Z; i++) ans = max(ans, sum+fl[i]+fr[i]);
	printf("%lld\n", ans);
}

int main()
{
	input();
	work();
	return 0;
}

Measured memory_bytes: 6656
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
#include <queue>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a;
    cin >> a;
    cout << 48 - a;
}

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

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int ans=0;
    if(a==b) ans++;
    if(b==c) ans++;
    if(c==a) ans++;
    if(ans == 1) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
l = []
for i in range(n):
 l.append(int(input()))
l.sort()
a = sum(l)
for i in range(n):
 if a%10 == 0:
  if l[i]%10 != 0:
   a -= l[i]
 else:
  break
a = a if a%10 != 0 else 0
print(a)

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

int N;
string S;
long long m, c, t;

void add(int i) {
    if (S[i] == 'M') ++m;
    else if (S[i] == 'C') ++c, t += m;
}

void erase(int i) {
    if (S[i] == 'M') --m, t -= c;
    else if (S[i] == 'C') --c;
}

long long solve(int K) {
    long long res = 0;
    m = 0; t = 0;
    int r = 0;
    for (int l = 0; l < N;) {
        while (r < N && r - l < K) add(r++);
        if (S[l] == 'D') res += t;
        erase(l++);
    }
    return res;
}

int main() {
    while (cin >> N >> S) {
        int Q; cin >> Q;
        for (int i = 0; i < Q; ++i) {
            int k; cin >> k;
            cout << solve(k) << endl;
        }
    }
}


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

// THINK: INT vs LONG LONG?

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

	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (a[i] != a[j]) {
				for (int k = j + 1; k < n; ++k) {
					if (a[k] != a[j] && a[k] != a[i]) {
						ans += ((long long) a[i] + a[j] + a[k] > (long long) 2 * max(a[i], max(a[j], a[k])));
					}
				}
			}
		}
	}
	cout << ans << '\n';
	
	return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<string.h>
using namespace std;

int w,h,Col;
typedef pair<int,int> C;
typedef vector<vector<int> > P;
P V;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int res;

P temp;
int tres=0;


void calc(int y,int x){
	if(y<0 || x<0 || x>=w || y>=h) return;
	if(temp[y][x]==Col){tres++;temp[y][x]=0;
	for(int r=0;r<4;r++)
		calc(y+dy[r],x+dx[r]);
	}
}

void on(P N,int count,int c){

	if(count==5){temp=N;tres=0;calc(0,0);res=max(res,tres);return;}

	int nc=N[0][0];
	queue<C> Q;
	Q.push(make_pair(0,0));
	bool used[8][8];
	memset(used,false,sizeof(used));

	int tres=0;
	while(!Q.empty()){
		C now=Q.front();
		Q.pop();
		if(used[now.first][now.second]) continue;
		used[now.first][now.second]=true;
		N[now.first][now.second]=c;
		for(int r=0;r<4;r++){
			int ny=now.first+dy[r],nx=now.second+dx[r];
			if(ny<0 || nx<0 || ny>=h || nx>=w) continue;
			if(N[ny][nx]==nc)
				Q.push(make_pair(ny,nx));
		}
	}

	if(count!=4)
		for(int i=1;i<=6;i++)
				on(N,count+1,i);
	else on(N,count+1,Col);
}


void solve(){
	res=0;
	V.clear();
	V.resize(h);

	for(int y=0;y<h;y++)
		for(int x=0;x<w;x++){
			int t;
			cin>>t;
			V[y].push_back(t);
		}
	
	for(int i=1;i<=6;i++){
		if(V[0][0]!=i)
		 on(V,0,i);
	}

	cout<<res<<endl;

}



int main()
{
	while(cin>>h>>w>>Col){
		if(w==0) break;
		solve();
	}
	return 0;
}

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

map<pair<long long int,long long int>,long long int> dp;

const long long int mod = static_cast<long long int>(1e9) + 7;

long long int func(long long int s,long long int x){

    if(dp[make_pair(s,x)] != 0){
        return dp[make_pair(s,x)];
    }

    if(s==0){
        return dp[make_pair(s,x)] = 1;
    }
    //x=0 のときはsが奇数の時は条件を満たすa,bが見つからないので偶数の時にひとつだけ満たす。
    //例 s = 4 a=010 b=010
    //それに加えてs=0の時成立するので結果s/2 + 1 となる。
    if(x==0){
        return (dp[make_pair(s,x)] = s/2 + 1) % mod;
    }
    if(s == 1){
        return dp[make_pair(s,x)] = 2;
    }
    //x=1 になるとx=0の時に省かれたsが奇数の時の値がカウントできる。
    if(x == 1){
        return (dp[make_pair(s,x)] = func(s,0) + (s - 1) / 2) %= mod;
    }

    //s = a+bより s/2 = (a+b)/2  a xor b = x a,bが偶数
    //真ん中はaが奇数のときで、 a-1 + b  = s-1 となり a-1 xor b = x-1
    //右は両方が奇数の時で、a-1 + b-1 = s-2 a-1 xor b-1 = x
    return dp[make_pair(s,x)] = ( func(s/2,x/2) + func((s-1)/2,(x-1)/2) + func((s-2)/2,x/2) ) % mod;

}

int main() {

    long long int n;

    cin >> n;

    cout << func(n,n) << endl;

    return 0;
}

Measured memory_bytes: 384
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <random>
#include <cmath>
#include <chrono>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
using namespace std;
using LL = long long;
#define eps 1e-8
#define fi first
#define se second
#define eb emplace_back
#define close std::ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define FOR(i, x, y) for (LL i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (LL i = (x), _##i = (y); i > _##i; --i)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define CASET int ___T; cin>>___T; for(int __CS=1;__CS<=___T;__CS++)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
mt19937 dlsrand(random_device{}());
mt19937 mrand(std::chrono::system_clock::now().time_since_epoch().count()); 
int rnd(int x) { return mrand() % x;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
LL bin(LL x, LL n, LL MOD) {LL ret = MOD != 1;for (x %= MOD; n; n >>= 1, x = x * x % MOD)if (n & 1) ret = ret * x % MOD;return ret;}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }
const double PI = acos(-1.0);
constexpr int maxn = 1e6+10;
constexpr int mod = 1e9+7;
constexpr int INF = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3f;
constexpr ull base=2333, P_1=19260811, P_2=999998639;
void add(int &a,int b) {a+=b; if(a>=mod) a-=mod;}
void dec(int &a,int b) {a-=b; if(a<0) a+=mod;}
int main()
{
    int n , w , h;
    cin >> h >> w >> n;
    cout << min(ceil(n*1.0/h),ceil(n*1.0/w));
    
}

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

alias Tuple!(int, "r", int, "c", int, "d", int, "cost") Node;
int[] dr = [0, 0, -1, 1];
int[] dc = [-1, 1, 0, 0];


void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto K = s[2];
    auto B = H.iota.map!(_ => readln.chomp).array;
    int sr, sc;
    foreach (i; 0..H) foreach (j; 0..W) if (B[i][j] == 'S') sr = i, sc = j;

    bool is_goal(Node n) {
        return (n.r == 0 || n.r == H-1 || n.c == 0 || n.c == W-1);
    }

    auto used = new bool[][](H, W);
    DList!Node queue;
    queue.insertBack(Node(sr, sc, 0, 1));
    while (!queue.empty) {
        auto n = queue.front;
        queue.removeFront;
        auto r = n.r;
        auto c = n.c;
        auto d = n.d;
        auto cost = n.cost;

        if (is_goal(n)) {
            writeln(1);
            return;
        }

        if (used[r][c]) continue;
        used[r][c] = true;
        if (d == K) continue;

        foreach (i; 0..4) {
            int nr = r + dr[i];
            int nc = c + dc[i];
            if (nr < 0 || nr >= H || nc < 0 || nc >= W || B[nr][nc] == '#') continue;
            queue.insert(Node(nr, nc, d+1, cost));
        }
    }


    int ans = 1 << 29;
    foreach (i; 0..H) {
        foreach (j; 0..W) {
            if (!used[i][j]) continue;
            ans = min(ans, (i-1)/K + 2);
            ans = min(ans, (H-1-i-1)/K + 2);
            ans = min(ans, (j-1)/K + 2);
            ans = min(ans, (W-1-j-1)/K + 2);
        }
    }

    ans.writeln;
}


Measured memory_bytes: 8700
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001

int main(){
    vector<int> A(3);
    for(int&a:A)
        cin >> a;
    
    sort(A.begin(), A.end());
    
    int d1 = A[2]-A[1];
    int d2 = A[2]-A[0];
    
    if((d1%2 | d2%2)==0){
        cout << d1/2+d2/2 << endl;
        return 0;
    }
    
    if(d1%2 & d2%2){
        cout << (d1-1)/2 + (d2-1)/2 + 1 << endl;
        return 0;
    }
    
    if(d1%2){
        cout << d2/2 + (d1+1)/2 + 1 << endl;
        return 0;
    }
    cout << (d2+1)/2 + d1/2 + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include "bits/stdc++.h"
	
#define int long long
#define double long double 
#define PI 3.141592653589793
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
// Use for file I/O;
#define FIN string _fname = "paintbarn"; \
			string _is = _fname + ".in", _os = _fname + ".out"; \
			freopen(_is.c_str(), "r", stdin); \
			freopen(_os.c_str(), "w", stdout);

using namespace std;
	
int gcd(int a, int b) {
    while (b > 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}

const int INF = 4e18 + 10;
const int INF2 = 2e18 + 10;
const int INF3 = 2e10;
const int MAXN = 100000;
const int LOGN = 19;
const int MOD = 1e9 + 7;
const int EPS = 1e-9;
const int MULT = 2e5;
const int MCNST = MOD * MOD * 8;

int32_t main() {
	FAST;

	int n;
	cin >> n;
	if (n % 1000 == 0) cout << 0;
	else cout << 1000 - n % 1000;
}

Measured memory_bytes: 3620
//UG02-51-19-012
#include <stdio.h>



int main()
{
    int a, b, c;
    int r=0;
    scanf("%d%d%d",&a,&b,&c);
    r=a+b+c;

    if(r>=22)
        printf("bust");
    else
        printf("win");

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

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

  vector<int> P(M), Y(M);
  vector<vector<int>> a(N, vector<int>());
  for (int i = 0; i < M; ++i) {
    cin >> P[i] >> Y[i];
    a[P[i]-1].push_back(Y[i]);
  }

  for (int i = 0; i < N; ++i) {
    sort(ALL(a[i]));
  }

  for (int i = 0; i < M; ++i) {
    auto it = lower_bound(ALL(a[P[i]-1]), Y[i]);
    int rank = distance(a[P[i]-1].begin(), it)+1;

    cout << setfill('0') << right << setw(6) << P[i];
    cout << setfill('0') << right << setw(6) << rank;
    cout << endl;
  }

}

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

#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;

const int MAXN = 1e5 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOG = 18;
const double EPS = 1e-9;
const double PI = 3.1415926535;

int dist[MAXN];
bool visited[MAXN];
vector <int> G[MAXN];

void preprocess() {
    memset(visited, false, sizeof(visited));
    memset(dist, 0, sizeof(dist));
}

void dfs(int curr) {
    visited[curr] = true;
    for(auto v : G[curr]) {
        if(!visited[v])
            dfs(v);
        dist[curr] = max(dist[curr], dist[v] + 1);
    }
}

int main() {
    preprocess();
    int N, M, u, v, ans = 0;

    cin >> N >> M;
    for(int i = 0; i < M; i++) {
        cin >> u >> v;
        G[u].push_back(v);
    }

    for(int i = 1; i <= N; i++)
        if(!visited[i])
            dfs(i);

    for(int i = 1; i <= N; i++)
        ans = max(ans, dist[i]);
    cout << ans << endl;
    return 0;
}


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

int main(){
    int H, W;
    while(true){
        cin>>H>>W;
        if(H==0&&W==0){
            break;
        }
        else{
            rep(i, H){
                rep(j, W){
                    cout<<"#";
                }
                cout<<""<<endl;
            }
        }
        cout<<""<<endl;
    }
}


Measured memory_bytes: 3100
#include <iostream>
using namespace std;
#define REP(i,n) for (int i=0; i<(n); ++i)
int n,x,m;
int a[6];
int b[7];
int l[10],r[10],s[10];
int ans[6];
int ma;
void solve(int c) {
  if (c == n) {
    bool ok = 1;
    REP(i,m) {
      ok &= (b[r[i]]-b[l[i]-1] == s[i]);
    }
    if (ok) {
      if (ma < b[n]) {
        ma = b[n];
        REP(i,n) ans[i] = a[i];
      }
    }
    return;
  }
  REP(j,x+1) {
    a[c] = j;
    b[c+1] = b[c]+a[c];
    solve(c+1);
  }
}

int main() {
  while(cin>>n>>x>>m) {
    REP(i,m) cin >> l[i] >> r[i] >> s[i];
    ma = -1;
    solve(0);
    if (ma == -1) {
      cout << -1 << endl;
    } else {
      REP(i,n) {
        if (i) cout << " ";
        cout << ans[i];
      }
      cout << endl;
    }
  }
}

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

#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define forup(i,l,r) for (register int i = l ; i <= r ; i += lowbit(i))
#define fordown(i,id) for (register int i = id ; i ; i -= lowbit(i))
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define lowbit(x) ((x)&(-(x)))

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pr;

const ld inf = 2e18;
const int N = 3e6 + 10;
const int maxn = 100020;
const ll mod = 1e9 + 7;


struct node{
	int next,to,w;
}e[maxn * 2];
struct node2{
	int x,y,w;
	bool operator < (node2 a)const{
		return w < a.w;
	}
}dt[maxn],sub[maxn];
int head[maxn],cnt,fa[maxn],dth[maxn],faw[maxn];
int n,m,tot,delta[maxn],num;
ll X,totw,ans;
ll pow2[maxn];

inline void adde(int x,int y,int w){
	e[++cnt].to = y;
	e[cnt].next = head[x];
	e[cnt].w = w;
	head[x] = cnt;
}
void dfs(int x){
	fore(i,x){
		if ( e[i].to == fa[x] ) continue;
		dth[e[i].to] = dth[x] + 1, fa[e[i].to] = x , faw[e[i].to] = e[i].w;
		dfs(e[i].to);
	}
}
int getmx(int x,int y){
	int res = 0;
	while ( x != y ) {
		if ( dth[x] < dth[y] ) swap(x,y);
		res = max(res,faw[x]);
		x = fa[x];
	}
	return res;
}
int getfa(int x){ return x == fa[x] ? x : fa[x] = getfa(fa[x]); }
void kruskal(){
	rep(i,1,n) fa[i] = i;
	sort(dt + 1,dt + m + 1);
	rep(i,1,m){
		int x = dt[i].x , y = dt[i].y , w = dt[i].w;
		int p = getfa(x) , q = getfa(y);
		if ( p != q ){
			fa[p] = q;
			totw += w;
			adde(x,y,w) , adde(y,x,w);
			num++;
		}
		else sub[++tot] = dt[i];
	}
	if ( num < n - 1 ) return;
	rep(i,1,n) fa[i] = 0;
	dfs(1);
	rep(i,1,tot){
		int x = sub[i].x , y = sub[i].y , w = sub[i].w;
		int mxw = getmx(x,y);
		delta[i] = w - mxw;
	//	cout<<delta[i]<<endl;
	}
}	
void solve(){
	pow2[0] = 1;
	rep(i,1,m) pow2[i] = pow2[i - 1] * 2 % mod;
	if ( totw > X ) return;
	if ( totw == X ){
		int a = n - 1;
		rep(i,1,tot) if ( !delta[i] ) a++;
		ans = (pow2[a] - 2 + mod) % mod * pow2[m - a] % mod;
	}
	else{
		int a = n - 1,c = 0,b = 0;
		rep(i,1,tot){
		   	if ( delta[i] == X - totw ) c++;
			else if ( delta[i] < X - totw ) a++;
			else b++;
		}
		ans = (pow2[c] - 1) * 2 * pow2[b] % mod;
	}
}
int main(){
	scanf("%d %d %lld",&n,&m,&X);
	if ( n <= 2 ) return printf("0"),0;
	rep(i,1,m){
		int x,y,w;
		scanf("%d %d %d",&x,&y,&w);
		dt[i] = (node2){x,y,w};
	}
	kruskal();
	if ( num < n - 1 ) return printf("0"),0;
	solve();
	cout<<ans<<endl;
}


Measured memory_bytes: 4352
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
 
class Main {
 
    static ArrayDeque<String> queue = new ArrayDeque<String>();
 
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
        int n = Integer.parseInt(br.readLine());
        for (int i = 0; i < n; i++) {
            String order = br.readLine();
            if (order.contains("F")) {
                queue.poll();
            } else if (order.contains("L")) {
                queue.pollLast();
            } else if (order.contains("insert")) {
                queue.addFirst(order.replace("insert ", ""));
            } else {
                queue.removeFirstOccurrence(order.replace("delete ", ""));
            }
        }
 
        System.out.print(queue.poll());
        while (queue.isEmpty() != true) {
            System.out.print(" " + queue.poll());
        }
        if(queue.isEmpty()){
        	System.out.println();
        }
    }
}

Measured memory_bytes: 589080
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<vector>

using namespace std;

int main() {
	string s;
	long long n;
	cin >> s;
	n = s.length();
	long long count = 0;
	long long position = 1;
	for (long long i = 1; i < n;) {
		if (s[i] != s[i - 1]) {
			s.erase(s.begin() + i);
			s.erase(s.begin() + i - 1);
			++count;
			i = position;
			if (i < 1) i = 1;
			n -= 2;
			if (s.length() == 2) {
				if (s[0] == s[1])break;
			}
			else if (s.length() < 2)break;

			continue;
		}
		else {
			position = i - 1;
		}
		++i;
	}
	cout << count * 2 << endl;

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<bits/stdc++.h>
#define rep(i,n) for(i=0;i<n;i++)
#define pb push_back
#define lli long long int
#define all(v) (v.begin(),v.end())
#define fr first
#define sc second
#define mp make_pair
using namespace std;
int k=pow(10,9)+7;
int main()
{
    int n,m,i,j;
    cin>>n>>m;
    char a[n][m];
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++) cin>>a[i][j];
    }
    int dp[n][m];
    dp[0][0]=1;
    for(i=1;i<m;i++)
    {
        if(a[0][i]=='.') dp[0][i]=dp[0][i-1];
        else dp[0][i]=0;
    }
    for(i=1;i<n;i++)
    {
        if(a[i][0]=='.') dp[i][0]=dp[i-1][0];
        else dp[i][0]=0;
    }
    for(i=1;i<n;i++)
    {
        for(j=1;j<m;j++)
        {
            if(a[i][j]=='.') dp[i][j]=(dp[i-1][j]+dp[i][j-1])%k;
            else dp[i][j]=0;
        }
    }
    cout<<dp[n-1][m-1]%k;
}


Measured memory_bytes: 8456
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
long long int sum[111111];
int main(void)
{
  while(1){
    int n,k;
    cin >> n >> k;
    if(!n && !k) break;
    for(int i = 1; i <= n; i++){
      int a;
      cin >> a;
      sum[i] = sum[i-1] + a;
    }
    long long int best = -11111111111;
    for(int i = 0; i + k <= n; i++){
      best = max(best,sum[i+k] - sum[i]);
    }
    cout << best << endl;;
  }
}

Measured memory_bytes: 1936
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N; cin >> N;
    vector<int> D(N);
    for (int i = 0; i < N; i++) cin >> D[i];
    sort(D.begin(), D.end());
    cout << D[N/2] - D[N/2-1] << endl;
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    string S;
    cin >> S;

    ll N = S.size();

    ll ans = 0;
    ll count = 0;

    for (ll i = N-1; i >= 0; --i) {
        if (S[i] == 'B') {
            ans += N-1 - i - count;
            ++count;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 832
#include<bits/stdc++.h>
using namespace std;
long long int dp[3000][3000];
int main(){
    long long int n,x;
    cin >> n >> x;
    long long int time[n+10];
    for(long long int i = 1; i <= n; i++)
        cin >> time[i];

    for(long long int j = 1; j <= n; j++){
        dp[j][0] = time[j];
    }

    for(long long int i = 1; i < n; i++ ){
        for(long long int j = 1; j <=n; j++){
            dp[j][i] = min(dp[j][i-1],time[(((j-i) + n-1)%n)+1]);
        }
    }
    long long int ans = 10000000000000000;
    for(long long int i = 0; i < n; i++){
        long long int temp = i * x;
        for(long long int j = 1; j <= n; j++){
            temp += dp[j][i];
        }
        if(temp < ans)
            ans = temp;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 39552
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def adj(n): return [[] for _ in range(n)]

n = iinput()
a = iarr()
amax = max(a)

# ふるって生き残ったやつがTrue
dp = [1 for i in range(amax+1)]
for num in a:
    for i in range(2, amax//num + 1):
        tmp = num * i
        if dp[tmp]: dp[tmp] = 0

# カウンター
cnt = col.Counter(a)

# 生き残っていて、かつ、１回だけ登場するやつ
ans = 0
for key,val in cnt.items():
    if dp[key] and val==1: ans += 1

print(ans)



Measured memory_bytes: 72956
import java.util.*;

 
class Main {
 
    private static Scanner sc = new Scanner(System.in);
 
    public static void main(String[] args) {
        String s = sc.next();
        String s2 = sc.next();
        int n =Integer.parseInt(s);
        int k =Integer.parseInt(s2);
        int ans = 0;
        if(k == 1){
            ans = 0;
        }else{
            ans = n-k;
        }
        //String s = String.valueOf(i);
        //int i = Integer.parseInt(s);
        //System.out.println((s + s).contains(s2) ? "Yes" : "No");
        System.out.println(ans);
        /*
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            while ((line = br.readLine()) != null) {
                String[] tokens = line.split(" ");
                int h = Integer.parseInt(tokens[0]);
                int w = Integer.parseInt(tokens[1]);
                
                }
            }
        }
        */
    }
}

Measured memory_bytes: 21460
k=0
while 1:
    a,b=map(int,raw_input().split())
    if a==0:
        break
    if k:
        print
    f=0
    k=1
    for i in range(a,b+1):
        if i%400==0 or (i%4==0 and i%100!=0):
            f=1
            print i
    if f==0:
        print "NA"

Measured memory_bytes: 6328
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iostream>

using namespace std;
 
int main() {
int A[3]={0}, B[3]={0}, C[3]={0};
cin >> A[0] >> A[1] >> A[2];
cin >> B[0] >> B[1] >> B[2];
cin >> C[0] >> C[1] >> C[2];
if(A[0]-B[0]==A[1]-B[1] && A[2]-B[2]==A[1]-B[1] 
&& A[0]-C[0]==A[1]-C[1] && A[2]-C[2]==A[1]-C[1]){
  cout << "Yes" << endl;
}
else cout << "No" << endl; 
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int H,W,a,b;
	while(1){
		scanf("%d %d",&W,&H);
		if(H==0 && W==0)
		break;
	for(a=1; a<=W; a++){
		for(b=1; b<=H; b++){
		printf("#");
		}
		printf("\n");
	}
	printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
N,M = map(int,input().split())
a = [1]+[0]*(N-1)
b = [1]*N

for i in range(M):
  x,y = map(int,input().split())
  if a[x-1]==1 and b[x-1]==1:
    a[x-1]=0
    a[y-1]=1
  elif a[x-1]==1:
    a[y-1]=1
  b[x-1]-=1
  b[y-1]+=1
    
print(sum(a))

Measured memory_bytes: 4596
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    vector<int> p(n);
    rep(i, n) cin >> p[i];
    int res = 0;
    for(int i = 0; i < n - 2; i++) {
        if(p[i + 1] >= p[i] && p[i + 2] >= p[i + 1])
            res++;
        else if(p[i + 1] <= p[i] && p[i + 2] <= p[i + 1])
            res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int a,b,h,m;
#define P acos(-1)
int main() {
  ios::sync_with_stdio(false);
  cin>>a>>b>>h>>m;
  double x=1.0*m/60*(2*P);
 	double y=1.0*(h+1.0*m/60)/12*(2*P);
 	// cout<<x<<' '<<y<<endl;
 	double z=fabs(x-y);
 	// cout<<z<<endl;
 	if(z>P)z=2*P-z;
 	cout<<fixed<<setprecision(13);
 	cout<<sqrt(a*a+b*b-2*a*b*cos(z))<<'\n';
 	return 0;
}

Measured memory_bytes: 4172
#include <iostream>
#include <algorithm>

int w,h,n;

int X[100],Y[100],A[100];

bool board[100][100];

int main() {
	std::cin>>w>>h>>n;
	for(int i=0;i<n;++i)
		std::cin>>X[i]>>Y[i]>>A[i];
	for(int i=0;i<n;++i){
		switch(A[i]){
			case 1:
				for(int j=0;j<h;++j){
					for(int k=0;k<X[i];++k)
						board[j][k]=true;
				}
				break;
			case 2:
				for(int j=0;j<h;++j){
					for(int k=w-1;k>=X[i];--k)
						board[j][k]=true;
				}
				break;
			case 3:
				for(int j=0;j<Y[i];++j){
					for(int k=0;k<w;++k)
						board[j][k]=true;
				}
				break;
			case 4:
				for(int j=h-1;j>=Y[i];--j){
					for(int k=0;k<w;++k)
						board[j][k]=true;
				}
		}
	}
	int ans=0;
	for(int i=0;i<h;++i){
		for(int j=0;j<w;++j){
			if(!board[i][j])
				++ans;
		}
	}
	std::cout<<ans<<std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    rep(i, n)cin >> x[i] >> y[i] >> h[i];
    int idx;
    rep(i, n){
        if(h[i] > 0){
            idx = i;
            break;
        }
    }

    rep(cx, 101)rep(cy, 101){
        int H = h[idx] + abs(cx - x[idx]) + abs(cy - y[idx]);
        bool valid = true;
        rep(i, n){
            if(h[i] != max(0, H - abs(x[i] - cx) - abs(y[i] - cy))){
                valid = false;
                break;
            }
        }
        if(valid){
            cout << cx << ' ' << cy << ' ' << H << endl;
            return 0;
        }
    }
    
}

Measured memory_bytes: 256
h,w,k = map(int,input().split())
S = []
for i in range(h):
    S.append(list(input()))
cnt = 0
flag = False
for i in range(h):
    for j in range(w):
        if flag:
            if S[i][j] == "#":
                cnt += 1
            S[i][j] = str(cnt)
        else:
            if S[i][j] == "#":
                cnt += 1
                flag = True
                S[i][j] = str(cnt)
                if j != 0:
                    for k in range(j):
                        S[i][k] = str(cnt)
    flag = False
for i in range(h):
    k = i
    for j in range(w):
        if S[i][j] == ".":
            while S[k][j] == ".":
                k += 1
                if k > h-1:
                    break
            if k <= h-1:
                S[i] = S[k]
            else:
                l = i
                while S[l][j] == ".":
                    l -= 1
                S[i] = S[l]
for i in range(h):
    print(" ".join(S[i]))            

Measured memory_bytes: 9332
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(),b = sc.nextInt(),c = sc.nextInt(),d = 0;
        for(int i = a;i <= b;i++){
            if(c % i == 0) ++d;
        }
        System.out.println(d);
    }

}

Measured memory_bytes: 26160
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

constexpr double EPS = 1e-9;

struct point {
	double x, y;
	point(double x_ = 0.0, double y_ = 0.0):x(x_), y(y_) {}
	point(const point &p):x(p.x), y(p.y) {}

	point operator+(const point &p) const {
		return point(x + p.x, y + p.y);
	}

	point operator-(const point &p) const {
		return point(x - p.x, y - p.y);
	}

	point operator*(double s) const {
		return point(x * s, y * s);
	}

	point operator/(double s) const {
		return point(x / s, y / s);
	}

	bool operator<(const point &p) const {
		return x + EPS < p.x || (abs(x - p.x) < EPS && y + EPS < p.y);
	}
};

double norm(const point &p) {
	return p.x * p.x + p.y * p.y;
}

double dot(const point &a, const point &b) {
	return a.x * b.x + a.y * b.y;
}

double cross(const point &a, const point &b) {
	return a.x * b.y - a.y * b.x;
}

struct segment {
	point a, b;
	segment(const point &a_, const point &b_):a(a_), b(b_){}
};

struct line {
	point a, b;
	line(const point &a_, const point &b_):a(a_), b(b_){}
};

typedef vector<point> polygon;

int ccw(const point &a, point b, point c) {
	b = b - a;
	c = c - a;
	const double tmp = cross(b, c);
	if(tmp > EPS) return 1; // ccw
	if(tmp < -EPS) return -1; // cw
	if(dot(b, c) < 0) return 2; // c, a, b 順に一直線上
	if(norm(b) < norm(c)) return -2; // a, b, c 順に一直線上
	return 0; //a, c, b 順で一直線上
}

bool intersect(const line &l, const segment &s) {
	return cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - l.a) < EPS;
}

bool intersect(const polygon &P, const line &l) {
	point prev = P.back();
	for(const auto &curr : P) {
		if(intersect(l, segment(prev, curr))) return true;
		prev = curr;
	}
	return false;
}

point crosspoint(const line &l, const line &m) {
	const double tmp = cross(l.b - l.a, m.b - m.a);
	if(abs(tmp) < EPS) return l.a; // 平行
	return m.a + (m.b - m.a) * (cross(l.b - l.a, l.a - m.a) / tmp);
}

// L.aからL.bを向いた時の左側を残して切断する．
polygon convex_cut(const polygon &P, const line &l) {
	polygon res;

	point prev = P.back();
	int pc = ccw(l.a, l.b, prev);

	for(const auto &curr : P) {
		const int cc = ccw(l.a, l.b, curr);

		if(pc != -1) {
			res.emplace_back(prev);
		}
		if(pc * cc < 0) {
			res.emplace_back(crosspoint(l, line(prev, curr)));
		}

		prev = curr;
		pc = cc;
	}

	return res;
}

bool ok(const polygon &P) {
	constexpr int MIN = 0;
	constexpr int MAX = 10000;
	polygon rest{point(MIN, MIN), point(MIN, MAX), point(MAX, MAX), point(MAX, MIN)};

	point prev = P.back();
	for(const auto &curr : P) {
		rest = convex_cut(rest, line(prev, curr));
		if(rest.empty()) return false;
		prev = curr;
	}

	return true;
}

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

	for(int n; cin >> n && n;) {
		polygon P(n);
		for(auto &e : P) cin >> e.x >> e.y;
		cout << ok(P) << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

using namespace std;

int main(){
  
    vector<int> a(3);
    cin >> a[0] >> a[1] >> a[2];

    sort(ALL(a));

    cout << a[2] - a[0] << endl;



    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int cards[128][14]={{0}};
    int i,N;
    
    scanf("%d",&N);
    
    for(i=0;i<N;i++){
        char c;
        int cn;
        scanf("%c",&c);
        scanf("%c %d",&c,&cn);
        cards[c][cn]=1;
    }
    for(i=1;i<=13;i++){
        if(cards['S'][i]==0){
            printf("S %d\n",i);
        }
    }
    for(i=1;i<=13;i++){
        if(cards['H'][i]==0){
            printf("H %d\n",i);
        }
    }
    for(i=1;i<=13;i++){
        if(cards['C'][i]==0){
            printf("C %d\n",i);
        }
    }
    for(i=1;i<=13;i++){
        if(cards['D'][i]==0){
            printf("D %d\n",i);
        }
    }
    return(0);
}


Measured memory_bytes: 2036
N=int(input())
p=list(map(int,input().split()))
count=0
t=set()
for i in range(N):
  if p[i]==i+1:
    t.add(i)
ans=0
id=0
while(id<N):
  if id in t:
    if id+1 in t:
      id+=1
    ans+=1
  id+=1
  
  
print(ans)


Measured memory_bytes: 16960
def dot(a,b):
    return a.real*b.real+a.imag*b.imag

def cross(a,b):
    return a.real*b.imag-a.imag*b.real

x0,y0,x1,y1=map(int,input().split())
q=int(input())
p0=x0+y0*1j
p1=x1+y1*1j
a=p1-p0

for x2, y2 in (map(int, input().split()) for _ in [0]*q):
    p2=x2+y2*1j
    b=p2-p0
    S=cross(a,b)
    if S>0: #符号付面積が正だったら
        print("COUNTER_CLOCKWISE")
    elif S<0: #符号付面積が負だったら
        print("CLOCKWISE")
    else:               #符号付面積が0だったら(一直線上に存在する)
        if dot(a,b)>=0:
            if dot(a,a)<dot(b,b):
                print("ONLINE_FRONT") 
            else:
                print("ON_SEGMENT") 
        else:
            print("ONLINE_BACK")


Measured memory_bytes: 5648
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <set>
#include <string>
#include <vector>

#define endl '\n'

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) {
        int x, y;
        cin >> x >> y;
        if (y & 1 || 2 * x > y || y > 4 * x)
            cout << "No";
        else
            cout << "Yes";
    }
}

Measured memory_bytes: 3648
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<sstream>
#include<string>
#include<time.h>
#include<utility>
#include<vector>

using namespace std;

int n;
int A[200005],B[200005];

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",A+i);
		B[i]=A[i];
	}
	sort(A,A+n);
	int md1=A[n/2-1];
	int md2=A[n/2];
	for(int i=0;i<n;i++){
		if(B[i]>md1) printf("%d\n",md1);
		else printf("%d\n",md2);
	}
	return 0;
}


Measured memory_bytes: 3712
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author parsa bahrami
 */

#pragma GCC optimize("O2")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sz(x)                       (ll) x.size()
#define jjoin(x)                    for (auto i : x) cout << i << endl;
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define sep                         ' '
#define error(x)                    cerr << #x << " = " << x << endl
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define kill(x)                     return cout << x << endl , 0;
#define Hkill(x)                    cout << x << endl; exit(0);
#define endl                        '\n'

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 5e3 + 10;
const ll MAXA = 101;
const ll INF = 8e18;
const ll MOD = 998244353; //1e9 + 7
const ld PI = 4 * atan((ld) 1);
ll dp[MAXN][MAXN];
vector<ll> pos[30];

int main() {
    fast_io;
    set_random;
    ll n;
    cin >> n;
    string s;
    cin >> s;
    s = '#' + s;
    for (ll i = 1; i <= n; i++) {
        pos[s[i] - 'a'].push_back(i);
    }
    ll ans = -1;
    for (ll i = n; i; i--) {
        for (ll j = n; j; j--) {
            dp[i][j] = (s[i] == s[j] ? dp[i + 1][j + 1] + 1 : 0);
            if (i < j) {
                dp[i][j] = min(dp[i][j], j - i);
                ans = max(ans , dp[i][j]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 196096