akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define reads(s) string s; cin >> s;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;}
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define setprec cout << fixed << showpoint << setprecision(20);
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 1e6 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	read(n);
	readarr(a, n);
	
	int f[N + 1] = {}, ans[N + 1] = {};
	FOR (i, 1, n) f[a[i]]++;
	
	FOR (i, 1, N)
	{
	    if (!f[i]) continue;
	    for (int j = 2*i; j <= N; j += i)
	        if (f[j]) ans[j] = 1;
	}
	
	int cnt = 0;
	FOR (i, 1, n)
	    if (!ans[a[i]] && f[a[i]] <= 1) cnt++;
	    
	print(cnt);
}



















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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




//source: https://atcoder.jp/contests/dp/tasks/dp_w
// W: Intervals




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



const ll inf = 2e18;

////////////////////////////////////////////////////////////////////////////////////
ll t[maxn*4], o[maxn*4];

void push(int v) {
    t[2*v]+=o[v];
    t[2*v+1]+=o[v];
    o[2*v]+=o[v];
    o[2*v+1]+=o[v];
    o[v]=0;
}

ll queryMin(int v, int tl, int tr, int l, int r) {
    if (l>tr||r<tl) return inf;
    if (l<=tl&&tr<=r) {
	return t[v];
    } else {
	push(v);
	int tm=(tl+tr)/2;
	return min(queryMin(2*v,tl,tm,l,r),queryMin(2*v+1,tm+1,tr,l,r));
    }
}

void rangeAdd(int v, int tl, int tr, int l, int r, ll dx) {
    if (l>r) return;
    if (l>tr||r<tl) return;
    if (l<=tl&&tr<=r) {
	t[v]+=dx;
	o[v]+=dx;
    } else {
	push(v);
	int tm=(tl+tr)/2;
	rangeAdd(2*v,tl,tm,l,r,dx);
	rangeAdd(2*v+1,tm+1,tr,l,r,dx);
	t[v]=min(t[2*v],t[2*v+1]);
    }
}


//0-indexed helpers
//upd(l,r,dx): add dx on range [l,r]
//qry(l,r): query for min on range [l,r]
//edit(i,val): edit index i to be val

void upd(int l, int r, ll dx) {
    if (l>r) return;
    rangeAdd(1,1,maxn,l+1,r+1,dx);
}

ll qry(int l, int r) {
    assert(l<=r);
    return queryMin(1,1,maxn,l+1,r+1);
}

void edit(int i, ll val) {
    upd(i,i,val-qry(i,i));
}
////////////////////////////////////////////////////////////////////////////////////



vector<pair<int,int>> intervals[maxn];


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

    int n, m; cin>>n>>m;
    ll tot=0;
    
    while (m--) {
	int l,r,a; cin>>l>>r>>a;
	tot += a;
	intervals[r].push_back({l,a});
    }


    //dp[i]: given we set ith index to 1, find min prefix representing not taking an interval.
    //as we scan past right border of intervals (that become deactivated), penalize dp values
    //that are before left border of recently deactivated interval.

    //dp[0]: we took none of the intervals
    
    upd(0,n+1,inf);
    edit(0,0);

    for (int i=1; i<=n+1; i++) {
	for (auto p: intervals[i-1]) {
	    upd(0,p.first-1,p.second);
	}
	ll dp = qry(0,i);
	edit(i,dp);
    }

    ll res = tot - qry(0,n+1);
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 51584
#include <stdio.h>

int main(void){
    
    int value[6]={1,5,10,50,100,500},i,sum=0,c;
    
    for (i=0; i<6; i++) {
        scanf("%d",&c);
        sum+=value[i]*c;
    }
    if (sum>=1000) {
        puts("1");
    }else
        puts("0");
    return 0;
}

Measured memory_bytes: 1016
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;
const string nyan("(=^・ω・^=)");

int N, C, A[400], B[400];
ll DP[401], s[401][401];

int main() {
	cin >> N >> C;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	for (int i = 0; i < N; ++i) {
		cin >> B[i];
	}
	for (int i = 0; i <= 400; ++i) {
		s[i][0] = 1;
	}
	for (int i = 0; i < 400; ++i) {
		for (int j = 0; j <= 400; ++j) {
			s[j][i + 1] = s[j][i] * j % mod;
		}
	}
	for (int i = 0; i < 400; ++i) {
		for (int j = 0; j <= 400; ++j) {
			s[i + 1][j] = (s[i][j] + s[i + 1][j]) % mod;
		}
	}
	for (int i = 0; i <= C; ++i) {
		DP[i] = s[B[0]][i] - s[A[0] - 1][i] + mod;
		DP[i] %= mod;
	}
	for (int i = 1; i < N; ++i) {
		for (int j = C; j >= 0; --j) {
			for (int k = C - j; k; --k) {
				DP[j + k] += DP[j] * ((s[B[i]][k] - s[A[i] - 1][k] + mod) % mod);
				DP[j + k] %= mod;
			}
			DP[j] *= B[i] - A[i] + 1;
			DP[j] %= mod;
		}
	}
	cout << DP[C] << endl;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  int s;
  cin >> s;
  int left = s / 100, right = s % 100;
  if (left <= 12 && right <= 12 && left != 0 && right != 0)
    cout << "AMBIGUOUS" << endl;
  else if (left <= 12 && left != 0)
    cout << "MMYY" << endl;
  else if (right <= 12 && right != 0)
    cout << "YYMM" << endl;
  else
    cout << "NA" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
ll mod=1e9+7;
#define PI acos(-1)
struct edge{int from, to;};

int main(){
    int n;
    cin>>n;
    map<string, int> mp;
    rep(i,n){
        string s;
        cin>>s;
        mp[s]++;
    }
    int MAX=0;

    for(auto i:mp){
        MAX=max(i.second, MAX);
    }

    for(auto it=mp.begin();it!=mp.end();it++){
        if(it->second == MAX){
            cout<<it->first<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 25216
def solve(n, k, h_list):
    h_list_s = list(sorted(h_list))
    if k >= n:
        return 0
    elif k > 0:
        return sum(h_list_s[:-k])
    else:
        return sum(h_list_s)


def main():
    n, k = map(int, input().split())
    h_list = list(map(int, input().split()))
    res = solve(n, k, h_list)
    print(res)


def test():
    assert solve(3, 1, [4, 1, 5]) == 5
    assert solve(8, 9, [7, 9, 3, 2, 8, 4, 6]) == 0
    assert solve(3, 0, [1000000000, 1000000000, 1000000000]) == 3000000000


if __name__ == "__main__":
    test()
    main()


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

int main() {
  string a,b,c; cin >>a >>b >>c;
  string s = "abc";
  s.at(0) = a.at(0)+('A'-'a');
  s.at(1) = b.at(0)+('A'-'a');
  s.at(2) = c.at(0)+('A'-'a');
  cout <<s <<endl;
}


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

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

char cookie[] = {'o', 'x'};
string field[8];

int turnNum(int x, int y, int d, int n, char c)
{
    if(x < 0 || y < 0 || x >= W || y >= H) return 0;
    
    if(field[y][x] == c) return n;
    if(field[y][x] == '.') return 0;

    int tx = x + dx[d];
    int ty = y + dy[d];
    
    return turnNum(tx, ty, d, n + 1, c);
}

bool turn(int x, int y, int d, char c)
{
    if(x < 0 || y < 0 || x >= W || y >= H) return false;
    if( field[y][x] == '.') return false;
    if( field[y][x] == c) return true;
    
    int tx = x + dx[d];
    int ty = y + dy[d];

    if(turn(tx,ty,d,c) == true) field[y][x] = c;
}

void solve()
{
    int t = 0;
    int pass = 0;
    
    while(1) {
	int mx = 0;
	int px = -1, py = -1;

	int start = (t%2==0 ? 0 : H-1);
	int end = (t%2==0 ? H : 0);
	for(int i=start; (t%2==0?i<end:i>=0); (t%2==0?i++:i--))
	    for(int j=start; (t%2==0?j<end:j>=0); (t%2==0?j++:j--)) {
		if(field[i][j] !='.') continue;
		
		int cnt = 0;
		for(int k=0; k<8; k++)
		    cnt += turnNum(j+dx[k], i+dy[k], k, 0, cookie[t%2]);

		if(cnt > mx) {
		    mx = cnt;
		    px = j;
		    py = i;
		}
	    }

	if(px == -1) {
	    pass++;

	    if( pass == 2) break;
	}
	else {
	    pass = 0;
	    
	    field[py][px] = cookie[t%2];
	    for(int i=0; i<8; i++)
		turn(px+dx[i], py+dy[i], i, cookie[t%2]);
	}

	t++;
    }
}

int main()
{
    for(int i=0; i<H; i++)
	cin >> field[i];

    solve();

    for(int i=0; i<H; i++)
	cout << field[i] << endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  int k, n;
  cin >> n >> k;

  vector<int> a(n), p(n);
  map<int,int> mp;
  rep(i, n) {
    cin >> a[i];
    mp[a[i]] += 1;
  }

  

  int diff = mp.size() - k;
  for (auto&& itr : mp) {
    // debug(itr.second);
    p[itr.second] += 1;
  }

  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (diff > 0) {
      for (int j = 0; j < p[i]; ++j) {
        diff -= 1;
        ans += i;
        if (diff <= 0) break;
      }
    } else {
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 11136
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>
 
#define INF 100000000
#define EPS 1e-9
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define MAX_N 50
#define MAX_Q 50
int N, Q;

vector<int> ans_list;
 
int main(){
  
  while(true){
    cin >> N >> Q;
    if(N == 0)
      break;

    P dp[1001];
    for(int i = 0; i <= 1000; i++){
      dp[i].first = 0;
      dp[i].second = i;
    }

    for(int i = 0; i < N; i++){
      int M;
      cin >> M;
      for(int num = 0; num < M; num++){
	int a;
	cin >> a;
	dp[a].first++;
      }
    }

    sort(dp, dp+1001);

    int ans = INF;
    int tmp = 0;

    for(int i = 1000; i >= 0; i--){
      if(dp[i].first >= Q){
	if(tmp < dp[i].first){
	  tmp = dp[i].first;
	  ans = dp[i].second;
	}
	else if(tmp == dp[i].first && ans > dp[i].second){
	  ans = dp[i].second;
	}
      }
      else
	break;
    }

    if(ans != INF)
      ans_list.push_back(ans);
    else
      ans_list.push_back(0);

  }
 
  for(int i = 0; i < ans_list.size(); i++){
    cout << ans_list[i] << endl;
  }
  
  return 0;
  
}

Measured memory_bytes: 1224
#include <stdio.h>

int main()
{
  int key,i,j,n,k;
  int A[100];

 scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }
  
  for(i=0;i<n;i++){
    key=A[i];
    j=i-1;
    while(j>=0 && A[j]>key)
      {
	A[j+1]=A[j];
	j--;
      }
    A[j+1]=key;
    
    for(k=0;k<n;k++){
      printf("%d",A[k]);
      if(k<n-1){
	printf(" ");
      }
	else if(k=n-1) break;
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
ll d[51][51];
int used[51] = {};
int i, j, k;
int main() {
	ll sum = 0;
	int n; int A, B; int a[50], b[50];
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> A; a[i] = A;
	}
	for (i = 0; i < n; i++) {
		cin >> B; b[i] = B;
	}
	for (i = 0; i <= 50; i++) {
		for (j = 0; j <= 50; j++) {
			d[i][j] = INF;
		}
	}
	while (true) {
		for (i = 0; i <= 50; i++) {
			for (j = 0; j <= i; j++) {
				if (i == j)d[i][j] = 0;
				else {
					ll mi = INF;
					for (k = j + 1; k <= 50; k++) {
						if (i%k == j) {
							d[i][j] = (ll)pow(2, k);
							if (used[k] == 1) {
								d[i][j] = 0;
							}
							mi = min(mi, d[i][j]);
						}
					}
					d[i][j] = mi;
				}
			}
		}
		for (k = 0; k <= 50; k++) {
			for (i = 0; i <= 50; i++) {
				for (j = 0; j <= i; j++) {
					if (i >= k && k >= j) {
						d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
					}
				}
			}
		}
		ll ma = 0; int check;
		for (i = 0; i < n; i++) {
			if (ma < d[a[i]][b[i]]) {
				ma = d[a[i]][b[i]];
				check = i;
			}
		}
		if (ma == INF) {
			cout << -1 << endl;
			return 0;
		}
		if (ma == 0)break;
		int check2 = 0;
		for (i = 0; i <= 50; i++) {
			ma /= 2;
			if (ma % 2 == 1) {
				check2 = i + 1;
			}
		}
		sum += (ll)pow(2, check2);
		used[check2] = 1;
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<string.h>
int main(void)
{
	int s,d,f,h,i,j;
	char a[5000];
	while(1){
		s=0;
		d=0;
		scanf("%s",a);
		h=strlen(a);
		if(a[0]=='0')	break;
		for(i=0;i<h;i++){
			d=a[i]-'0';
			//printf("%d\n",d);
			s+=d;
		}
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 2748
N = int(input())
t_old, x_old, y_old = 0, 0, 0

for i in range(N):
  t, x, y = map(int, input().split())
  dt = t - t_old
  dx = x - x_old
  dy = y - y_old
  t_old = t
  x_old = x
  y_old = y
  if abs(dx) + abs(dy) <= dt and (dt - (abs(dx) + abs(dy))) % 2 == 0:
    if i == N - 1:
      print('Yes')
    pass
  else:
    print('No')
    break
    


Measured memory_bytes: 3060
/*
    Author:DurJoy
*/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int Main = 2e5 + 10;
int  al[Main];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n , m;
    cin >> n >> m;
    int temp = 0;
    for(int i = 0; i < n; i++){
        cin >> al[i];
    }
    sort( al , al + n);
    for(int i = 0; i < n; i++){
        if(al[i] >= m){
            temp++;
        }
    }
    cout << temp << endl;
    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define REP(i, n) for(int i=0; i<n; i++)
#define RER(i, n) for(int i=n-1; i>=0; i--)
#define ALL(v) v.begin() v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int n;

signed main(){
	cin >> n;
	int a[3];
	REP(i, 3){
		if(n % 10 == 1) a[i] = 9;
		else if(n % 10 == 9) a[i] = 1;
		n /= 10;
	}
	RER(i, 3) cout << a[i];
	cout << endl;

    return 0;
}

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

int main(){
  int n, m;
  cin >> n;
  int b[n-1];
  
  rep(i,0,n-1) cin >> b[i];
  m=b[0]+b[n-2];
  rep(i,0,n-2){
    m+=min(b[i], b[i+1]);
  }
  cout << m << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int K = sc.nextInt();

        sc.close();

        //A<BとおいてAの数だけAとBの約数を求める

        ArrayList<Integer> factoringA = new ArrayList<>();
        ArrayList<Integer> factoringB = new ArrayList<>();

        if (A > B) {int temp = A; A=B; B = temp;}

        for(int n = 1; n < A+1 ; n++) {

            if(A % n == 0) {

                factoringA.add(n);
            }

            if(B % n == 0) {

                factoringB.add(n);
            }
        }

        //公約数のリスト
        List<Integer> commonDivisorList = new ArrayList<>();

        //Aの約数の数だけループさせる
        for (int a = 0; a < factoringA.size(); a++ ) {

            for (int b = 0; b < factoringB.size(); b++) {

                if (factoringA.get(a).equals(factoringB.get(b))) {

                    commonDivisorList.add(factoringA.get(a));
                }
            }
        }
        //commonDivisorListは昇順 => -(-commonDivisorList + K)番目が最大公約数からK番目に大きい数
        System.out.println(commonDivisorList.get(commonDivisorList.size() - K));

    }
}

Measured memory_bytes: 23764
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


using Graph = vector<vector<int>>;

void solve() {
    int N, M; cin >> N >> M;
    vector<int> H(N);
    for (int i = 0; i < N; i++) cin >> H[i];

    Graph G(N);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        bool flag = true;
        for (int j = 0; j < G[i].size(); j++) {
            if (H[i] <= H[G[i][j]]) {
                flag = false;
                break;
            }
        }
        if (flag) ans++;
    }

    cout << ans << endl;
}


int main() {
    solve();
    return 0;
}

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

const int INF=123456789;

typedef pair<int,int> P;

char g[1001][1001];
int H,W;

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

//sxsyからgxgyへの最短距離を求める
queue<P> que;

void bfs(){

  while(que.size()){
    P p=que.front();que.pop();

    if(p.second==12345){
      //cout<<"a"<<endl;
      ans++;
      if(que.size()==0) break;
      que.push(P(12345,12345));
    }

    for(int i=0;i<4;i++){
      int nx=p.second+dx[i], ny=p.first+dy[i];
      if(0<=nx&&nx<W&&0<=ny&&ny<H&&g[ny][nx]!='#'){
        //cout<<ny<<nx<<endl;
        que.push(P(ny,nx));
        g[ny][nx]='#';
      }
    }
  }

}

void solve(){

}

int main(){
  cin>>H>>W;
  for(int i=0;i<H;i++) for(int j=0;j<W;j++){
    cin>>g[i][j];
    if(g[i][j]=='#') que.push(P(i,j));
  }
  que.push(P(12345,12345));
 bfs();
  cout<<ans-1<<endl;
}


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

int main(){
  int X,N;
  cin >> X >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  vector<int> add(2*N);
  for(int i = 1; i < 2*N; i++) {
    add.at(i) = i;
    if(i%2==1){
      add.at(i) *= -1;
    }
  }
  int s = X;
  bool check;
  for(int i = 0; i < 2*N; i++) {    
    s += add.at(i);
    check = true;
    for(int j = 0;j<N; j++){
   	  if(s == vec.at(j)){
        check = false;
      }
    }
    if(check) {
      break;
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int main()
{
  int n, k;
  int a;
  int ans = 0;

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

  while((k - 1) * ans + 1 < n){
    ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    int N, M, ans, Mi;
    vector<string> s, t;
    ans = Mi = 0;
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        string si; cin >> si;
        s.push_back(si);
    }
    sort(s.begin(), s.end());
    cin >> M;
    for (int i = 0; i < M; i++)
    {
        string ti; cin >> ti;
        t.push_back(ti);
    }
    sort(t.begin(), t.end());
    for (int i = 0; i < N; i++)  
    {
        string now = s[i];
        int tmp = 1;
        while(true)
        {
            if (i + 1 == N)
            {
                break;
            }
            if (now == s[i + 1])
            {
              	i++;
                tmp++;
            }
            else
            {
                break;
            }
        }
        for (Mi = 0; Mi < M; Mi++)
        {
            if (now == t[Mi])
            {
                tmp--;
            }
        }
        if (ans < tmp) { ans = tmp; }
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
a, b, c, d = map(int, input().split())
if b < c or a > d:
    print('0')
elif a <= c and b >= d:
    print(d - c)
elif a >= c and b <= d:
    print(b - a)
elif b < d:
    print(b - c)
elif b > d:
    print(d - a)

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

o=N//2
e=N-o

import itertools
E=[]
O=[]
for i in range(N):
    if i%2==0:
        E.append(i)
    else:
        O.append(i)
ANS=10000

def mergecount(Z):
    cnt1 = 0
    z = len(Z)
    if z>1:
        A1 = Z[:z>>1]
        A2 = Z[z>>1:]
        cnt1 += mergecount(A1)
        cnt1 += mergecount(A2)
        i1=0
        i2=0
        for i in range(z):
            if i2 == len(A2):
                Z[i] = A1[i1]
                i1 += 1
            elif i1 == len(A1):
                Z[i] = A2[i2]
                i2 += 1
            elif A1[i1] <= A2[i2]:
                Z[i] = A1[i1]
                i1 += 1
            else:
                Z[i] = A2[i2]
                i2 += 1
                cnt1 += z//2 - i1
    return cnt1

for i in range(o+1):
    X=list(itertools.combinations(E,i))
    Y=list(itertools.combinations(O,i))
    for j in range(len(X)):
        for k in range(len(Y)):
            ev=[]
            od=[]
            for n in range(N):
                if n%2==0:
                    if n in X[j]:
                        od.append([B[n],n])
                    else:
                        ev.append([A[n],n])
                else:
                    if n in Y[k]:
                        ev.append([B[n],n])
                    else:
                        od.append([A[n],n])
            ev.sort()
            od.sort()
            #print(ev,od)
            Z=[]
            Num=0
            F=0
            for x in range(N):
                if x%2==0:
                    if Num>ev[x//2][0]:
                        F=1
                        break
                    else:
                        Num=ev[x//2][0]
                        Z.append(ev[x//2][1])
                else:
                    if Num>od[x//2][0]:
                        F=1
                        break
                    else:
                        Num=od[x//2][0]
                        Z.append(od[x//2][1])
            if F==0:
                #print(Z)
                tcnt=mergecount(Z)
            if F==0 and tcnt<ANS:
                ANS=tcnt
                
if ANS==10000:
    print(-1)
else:
    print(ANS)
    

Measured memory_bytes: 59480
void solve();

int main() {
	solve();
	return 0;
}

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> pii;

int N;
long long X;
vector<long long> A;
long long sum = 0;

void solve() {
	cin >> N;
	cin >> X;
	A.resize(N);
	for (int i = 0; i < N; i++)cin >> A[i];
	for (int n = 0; n < N; n++)sum += A[n];
	if (A[0] > X)A[0] = X;
	for (int n = 1; n < N; n++) {
		if (A[n - 1] + A[n] <= X)continue;
		A[n] = X - A[n - 1];
	}
	long long aftersum = 0;
	for (int n = 0; n < N; n++)aftersum += A[n];
	cout << sum - aftersum << endl;
	return;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int n;string s;cin>>n>>s;
  int ans=0;
  rep(i,1000){
    string t;
    int x=i;
    rep(j,3){
      t+=(char)(x%10+'0');
      x/=10;
    }
    int cnt=0;
    rep(j,n){
      if(t[cnt]==s[j])cnt++;
      if(cnt==3){
        ans++;
        break;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
const int N =  110;
inline int read()
{
  int p=0; int f=1; char ch=getchar();
  while(ch<'0' || ch>'9'){if(ch=='-') f=-1; ch=getchar();}
  while(ch>='0' && ch<='9'){p=p*10+ch-'0'; ch=getchar();}
  return p*f;
}
int a[N]; int n;
int main()
{
  n = read(); int k = read(); for(int i=1;i<=n;i++) a[i] = read();
  sort(a+1,a+n+1);
  int l = 1; while(l<=n && a[l]<=k){k-=a[l]; l++;}
  if(l==n+1)
  {
    if(k) l-=2;
    else l--;
  }
  else
  {
    l--;
  }
  printf("%d\n",l);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int mod = 1000000007;

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

    int x, y, z, k;
    cin >> x >> y >> z >> k;
    vector<int> a(x), b(y), c(z);
    rep(i, x) cin >> a[i];
    rep(i, y) cin >> b[i];
    rep(i, z) cin >> c[i];
    vector<int> v1;
    rep(i, x) rep(j, y) v1.push_back(a[i] + b[j]);
    sort(all(v1)), reverse(all(v1));
    int num = min(x * y, k);
    vector<int> v2(num);
    rep(i, num) v2[i] = v1[i];
    vector<int> ans;
    rep(i, num) rep(j, z) ans.push_back(v2[i] + c[j]);
    sort(all(ans)), reverse(all(ans));
    rep(i, k) cout << ans[i] << endl;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    priority_queue<int> p;

    int k;
    int n;
    Scd(n);
    Rep(i,n*2){
        Scd(k);
        p.push(k);
    }

    int ans = 0;
    Rep(i,n){
        p.pop();
        ans += p.top();
        p.pop();
    }

    printf ("%d\n", ans);

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  vector<int> t(n + 1, 0), v(n);
  FOR(i, 1, n + 1) cin >> t[i];
  rep(i, n) cin >> v[i];

  rep(i, n) t[i + 1] += t[i];
  vector<long double> velo(2 * t[n] + 1);
  for (long double i = 0; i <= t[n]; i += 0.5) velo[i * 2] = min(i, t[n] - i);

  rep(j, n) {
    for (long double i = 0; i <= t[n]; i += 0.5) {
      long double res = v[j];
      if (i < t[j]) res += t[j] - i;
      else if (i > t[j + 1]) res += i - t[j + 1];
      velo[i * 2] = min(velo[i * 2], res);
    }
  }

  long double ans = 0;
  rep(i, 2 * t[n]) ans += (velo[i] + velo[i + 1]) / 4;
  cout << setprecision(10) << ans << endl;


  
  return 0;
}

Measured memory_bytes: 896
#include<cstdio>
#include<algorithm>
using namespace std;
long long n,f[200000],mod=1000000007,a,b,s[200000];
int main()
{
	scanf("%lld%lld%lld",&n,&a,&b);
	for(int i=1;i<=n;i++)scanf("%lld",s+i);
	if(a>b)swap(a,b);
	for(int i=2;i<n;i++)
		if(s[i+1]-s[i-1]<a){puts("0");return 0;}
	f[0]=1;s[0]=-b;
	long long sum=0,r=0;
	for(int i=1;i<=n;i++)
	{
		for(;r<i&&s[i]-s[r]>=b;r++)sum=(sum+f[r])%mod;
		f[i]=sum;
		if(s[i]-s[i-1]<a)sum=0,r=i-1;
	}
	for(int i=r;i<=n;i++)sum=(sum+f[i])%mod;
	printf("%lld\n",sum);
	return 0;
}

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

A.sort()

m = A[0]
M = A[-1]
ans = list()
for a in A[1: -1]:
    if a < 0:
        ans.append((M, a))
        M = M - a
    else:
        ans.append((m, a))
        m = m - a
ans.append((M, m))
print(M - m)
for x, y in ans:
    print(x, y)

Measured memory_bytes: 62884
import itertools
N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))
PP = list(sorted(list(itertools.permutations(P))))
QQ = list(sorted(list(itertools.permutations(Q))))
a = 0
b = 0
for i in range(1, len(PP) + 1):
    if P == PP[i-1]:
        a = i
        break
for i in range(1, len(QQ) + 1):
    if Q == QQ[i-1]:
        b = i
        break
print(abs(a - b))

Measured memory_bytes: 13436
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

using namespace std;

int main()
{
    string S;
    string T;
    int A;
    int B;
    string U;

    cin >> S;
    cin >> T;
    cin >> A;
    cin >> B;
    cin >> U;

    if(U == S){
        cout << A - 1 << ' ' << B << endl;
    }

    if(U == T){
        cout << A << ' ' << B - 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
// Created by code_sm
//
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp> 
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> pseudo_set;
#define ll long long
#define vi vector<int>
#define si set<int> 
#define mii map<int,int>
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define extract_word(s)  stringstream str(s); while(str>>word)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define SET(s) cout<<fixed<<setprecision(s)
#define chotu 1000000007
#define set0(a) memset(a,0,sizeof(a))
#define endl "\n"
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define lower_string(s) transform(all(s),s.begin(),::tolower())
#define upper_string(s) transform(all(s),s.begin(),::toupper())
#define size(s) s.size()
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<typename T,typename U>
bool compare(T x,U y){return(abs(x-y)<=1e-9);}
int n,h[100001],ans=0,ini;
void solve()
{
fastio
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>h[i];
	int ini=0;
	int c=0;
for(int i=0;i<n;i++)
{
	if(ini>=h[i])
	{
		c++;
		ans=max(ans,c);
	}
	else
		c=0;
	ini=h[i];
}
cout<<ans;
}
int main()
{
//code
	
fastio	
int t;
t=1;
while(t--)
{
	solve();
	cout<<endl;
}
}


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

int main(){
    int n;
    cin >> n;
    ll ans,k,m,k2;
    ans=0;
    m=1001001001001;
    k2=0;
    rep(i,n){
        cin >> k;
        if(k<0){
            ++k2;
            m=min(m,k*(-1));
            ans+=k*(-1);
        }
        else{
            m=min(m,k);
            ans+=k;
        }
    }

    if(k2%2==0){
        cout << ans << endl;
    }
    else{
        cout << ans-2*m << endl;
    }
    

    return 0;
}

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

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define For(i, a) for (int i=0; i<(a); i++)
#define FORR(i,a,b) for (int i = (b)-1; i >= a; i--)
#define Forr(i,a) for (int i = (a)-1; i >= 0; i--)

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) 
void DBG() { cerr << "]\n";}
template<typename T, typename ...Args> void DBG(T first, Args... args){
cerr << first; if(sizeof...(args))cerr<<", "; DBG(args...); }

#define int ll
#define pb(x) push_back(x)
#define INF (int)1e17
#define PI 3.14159265358979323846
 
int del_x[4] = {-1, 1, 0, 0};
int del_y[4] = {0, 0, 1, -1};
int XX[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int YY[8] = {-1, 0, 1, 1, 1, 0, -1, -1};


void solve(){
	int n,x,k; cin >> n >> x >> k;
	cout << ((n+x-1)/x)*k <<"\n";
}

int32_t main(){ 
	#ifndef ONLINE_JUDGE
		clock_t tStart = clock();
		//freopen("in.txt", "r", stdin);
	#endif
	ios_base:: sync_with_stdio(false); 
	cin.tie(0); 
	int t=1;
	//cin >> t;
	for(int tt=1;tt<=t;tt++){
		//cout << "Case #"<<tt<<": ";
		solve();
	}
	#ifndef ONLINE_JUDGE
    cerr << "\nRun Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC <<" sec\n";
  #endif
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  string s[105];
  cin>>n;
  reps(i,n){
      cin>>s[i];
  }
  reps(i,n){
      for(int j=i+1;j<=n;j++){
	  if(s[i]==s[j]){
	      cout<<"No"<<'\n';
	      return 0;
	  }
      }
  }
  for(int i=2;i<=n;i++){
      int sum=s[i-1].size();
      if(s[i][0]!=s[i-1][sum-1]){
	  cout<<"No"<<'\n';
	  return 0;
      }
  }
  cout<<"Yes"<<'\n';
  return 0;
}


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

int main(){
  unsigned long long n;
  cin >> n;
  if ((n % 2 == 1)){
    cout << 0 << endl;
  }else{
    unsigned long long count = 0;
    for (unsigned long long i = 10; i <= n; i *= 5){
      count += (unsigned long long)(n/i);
    }    
    cout << count << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(a) (a).begin(),(a).end()
#define FOR(i,n) for(size_t i=0;i<(n);i++)
#define REP(n) FOR(i,n)
#define cinv(v,n) for(size_t i=0;i<(n);i++){cin>>(v)[i];}
#define nvec(type,v,n) vector<type> v(n);cinv(v,n)
#define npairs(type1,type2,v,n) vector<pair<type1,type2>> v(n);for(size_t i=0;i<(n);i++){cin>>v[i].first>>v[i].second;}

#define min_index(v) size_t(min_element(all(v))-(v).begin())
#define max_index(v) size_t(max_element(all(v))-(v).begin())
#define min_e(v) *min_element(all(v))
#define max_e(v) *max_element(all(v))

#define count_le(v,a) size_t(upper_bound(all(v),a)-(v).begin())
#define count_lt(v,a) size_t(lower_bound(all(v),a)-(v).begin())
#define count_ge(v,a) size_t((v).end()-lower_bound(all(v),a))
#define count_gt(v,a) size_t((v).end()-upper_bound(all(v),a))

#define order(neq_sl) [](const &auto s, const &auto l){return neq_sl;}
#define make_lr(v,type,l,r) vector<type> l(n+1),r(n+1);FOR(i,n){l[i+1]=l[i]+v[i];r[i+1]=r[i]+v[n-1-i];}

#define acm accumulate
#define SUM(v) accumulate(all(v),0l)

#define PI 3.1415926535897932

int main() {
  int a,b;
  cin>>a>>b;
  cout<<max(a-b*2,0);
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	double x[4], y[4];
	char dummy;
	
	while ( cin >> x[0] >> dummy >> y[0] >> dummy >> x[1] >> dummy >> y[1] >> dummy >> x[2] >> dummy >> y[2] >> dummy >> x[3] >> dummy >> y[3] ) {
		bool isClockwise;
		if ( x[0] != x[1] ) {
			isClockwise = ((y[2] - y[0]) * (x[1] - x[0]) < (y[1] - y[0]) * (x[2] - x[0]));
		}
		//else if ( x[0] > x[1] ) {
		//	isClockwise = ((y[2] - y[0]) * (x[1] - x[0]) > (y[1] - y[0]) * (x[2] - x[0]));
		//}
		else {
			isClockwise = ((x[2] > x[1]) == (y[1] > y[0]));
		}
		
		//cout << "isClockwise = " << isClockwise << endl;
		
		bool isConvex = true;
		for (int i=1; i<4; i++) {
			if ( x[i] != x[(i+1)%4] ) {
				if ( ((y[(i+2)%4] - y[i]) * (x[(i+1)%4] - x[i]) < (y[(i+1)%4] - y[i]) * (x[(i+2)%4] - x[i])) != isClockwise ) { isConvex = false; break; }
			}
			//else if ( x[i] > x[(i+1)%4] ) {
			//	if ( ((y[(i+2)%4] - y[i]) * (x[(i+1)%4] - x[i]) > (y[(i+1)%4] - y[i]) * (x[(i+2)%4] - x[i])) != isClockwise ) { isConvex = false; break; }
			//}
			else {
				if ( ( (x[(i+2)%4] > x[(i+1)%4]) == (y[(i+1)%4] > y[i]) ) != isClockwise ) { isConvex = false; break; }
			}
			//cout << i << endl;
		}
		if (isConvex) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3044
#include <algorithm>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P;
map<int, int> dp;
#define REP(i, n) for (int i = 0; i < n; i++)


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> d(N, 0);
  REP(i, N) cin >> d[i];
  int ans = 0;
  sort(d.begin(), d.end());
  int target = N/2;
  int pattern = d[target] - d[target-1];
  cout << pattern << endl;
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
class Atkin{
  public:
    int n, sqlim;
    vector<bool> prime;
    Atkin(int N):n(N+1){sqlim=(int)ceil(sqrt(n)); prime=vector<bool>(n,0); calc();}

    void calc(){
        int b;
        for (auto z:{1,5}) for (int y=z; y<=sqlim; y+=6) {
			for (int x=1; x<=sqlim && (b=4*x*x+y*y)<=n; ++x)prime[b].flip();
			for (int x=y+1; x<=sqlim && (b=3*x*x-y*y)<=n; x+=2)prime[b].flip();
		}
        for (auto z:{2,4}) for (int y=z; y<=sqlim; y+=6) {
			for (int x=1; x<=sqlim && (b=3*x*x+y*y)<=n; x+=2)prime[b].flip();
			for (int x=y+1; x<=sqlim && (b=3*x*x-y*y)<=n; x+=2)prime[b].flip();
		}
		for (int y=3; y<=sqlim; y+=6) for (auto z:{1,2}) 
			for (int x=z; x<=sqlim && (b=4*x*x+y*y)<=n; x+=3)prime[b].flip();
		prime[0]=0;
		for(int i=1;i<=sqlim;i++){
		    if(prime[i]==0)continue;
			int zz=i*i;
			for (int k=zz; k<=n; k+=zz)prime[k]=0;
		}
		prime[2]=prime[3]=1;
    }
};
int main(void){
    Atkin atkin(123456*2);
    int n;
    while(cin>>n,n){
        int ans=0;
        for(int i=n+1;i<=n*2;i++) ans+=atkin.prime[i];
        cout<<ans<<endl;
    }
}

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

int main(){
    int n;
    cin >> n;
    int p = n / 100;
    int q = p*100 + p*10 + p;
    if(q >= n){
        cout << q;
    } else {
        int r = p + 1;
        cout << r*100 + r*10 + r;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int
main(int argc, char *argv[])
{
    unsigned int NUM_CARS_MAX = 10;
    unsigned int id, stack[NUM_CARS_MAX], top;

    top = 0;
    while (1 == scanf("%u\n", &id)) {
        if (id) {
            stack[top++] = id;
            continue;
        }
        printf("%u\n", stack[--top]);
    }

    return 0;
}

Measured memory_bytes: 612
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      
      String s = sc.next();
      
      int n = 0;
      
      for(int i = 0; i <s.length(); i++){
        if(s.charAt(i) == '1'){
          n += 1;
        } else {
          n -= 1;
        }
      }
      
      System.out.println(s.length() - Math.abs(n));
          
      
    }
}

Measured memory_bytes: 26312
#include<bits/stdc++.h>
#define INF 2147483647
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol c=1,d=1,e=0,f=0,g=0,h=0;
  cin >>a;
  a+=1,a=a/2,a--;
  cout <<a<<'\n';
  return (0);
}


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

int main(){

    int N;
    cin >> N;

    int x[N],y[N],h[N];
    for(int i=0; i<N; i++){
        cin >> x[i] >> y[i] >> h[i];
    }

    for(int ix=0; ix<=100; ix++){
        for(int iy=0; iy<=100; iy++){

            int h_top = 0;

            for(int ih=0; ih<N; ih++){
                if(h[ih]>0){
                    int h_tmp = h[ih] + abs(ix-x[ih]) + abs(iy-y[ih]);
                    h_top = max(h_top,h_tmp);
                }
            }

            for(int ih=0; ih<N; ih++){
                int h_cur = h[ih] + abs(ix-x[ih]) + abs(iy-y[ih]);
                if (h[ih]>=0){
                    if (h_top > h_cur){break;}
                }
                
                if (ih == N-1){ cout << ix << " " << iy << " "<< h_top << endl;}
            }
        }
    }

    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll powmod(ll a, ll b) {
	a %= MOD;
	ll res = 1;
	while (b > 0) {
		if (b % 2 == 1)res = res * a % MOD;
		a = a * a % MOD;
		b /= 2;
	}
	return res;
}

ll n, k, s[2100], c[2100], as[2100];
int main() {
	cin >> n >> k;
	REP(i, n) cin >> s[i];
	ll ans = 0;
	REP(i, n) {
		FOR(j, i + 1, n) {
			if (s[i] > s[j]) {
				ans++;
				as[i]++;
			}
		}
	}
	REP(i, n) {
		c[s[i]]++;
	}
	REP(i, 2020) {
		c[i] *= k - 1;
	}
	REP(i, 2020) {
		c[i + 1] += c[i];
	}
	ll a2 = 0;
	REP(i, n) {
		ll sum = c[s[i] - 1], a = as[i];
		//cout << sum << " " << a << endl;
		ll now = sum % MOD * k % MOD;
		//cout << now << endl;
		now = now * powmod(2, MOD - 2) % MOD;
		a2 += now;
		a2 %= MOD;
	}
	cout << (ans * k % MOD + a2) % MOD  << endl;
}
	


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower


using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

bool is_prime(int n) {
    bool prime = true;
    for (int i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            prime = false;
            break;
        }
    }
    return prime;
}


int main() {
    int n;
    cin >> n;
    int ans = 0;
    rep(i, n) {
        int a;
        cin >> a;
        if (is_prime(a))ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,x;
	cin >> n;
	ll count = 1;
	for(int i = 0; i < n; i++) {
		cin >> x;
		if (x == count){
			count++;
		}
	}
	if (count != 1){
		cout << n - count + 1 << endl;
	}
	else{
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
template<class T> inline void read(T &x){
	x=0;register char c=getchar();register bool f=0;
	while(!isdigit(c))f^=c=='-',c=getchar();
	while(isdigit(c))x=x*10+c-'0',c=getchar();if(f)x=-x; 
}
const int N=1e6+10,mod=1e9+7;
int n,ans,f[N],g[N][3],fc[N],fi[N],vi[N];
inline int inc(int a,int b){return (a+=b)>=mod?a-mod:a;}
inline int binom(int n,int m){return (ll)fc[n]*fi[m]%mod*fi[n-m]%mod;}
inline int fpow(int a,int b){int s=1;for(;b;b>>=1,a=(ll)a*a%mod)if(b&1)s=(ll)s*a%mod;return s;}
int main(){
	std::cin>>n;
	g[1][0]=fi[0]=fi[1]=vi[0]=vi[1]=fc[0]=fc[1]=1;
	for(int i=2;i<=n;i++)fc[i]=(ll)fc[i-1]*i%mod;
	for(int i=2;i<=n;i++)vi[i]=(ll)(mod-mod/i)*vi[mod%i]%mod;
	for(int i=2;i<=n;i++)fi[i]=(ll)fi[i-1]*vi[i]%mod;
	for(int i=2;i<=n+1;i++){
		g[i][0]=inc(g[i-1][1],g[i-1][2]);
		g[i][1]=inc(g[i-1][0],g[i-1][2]);
		g[i][2]=inc(g[i-1][0],g[i-1][1]);
		// printf("> %d %d %d\n",g[i][0],g[i][1],g[i][2]);
	}
	for(int i=1;i<=n;i++)f[i]=(ll)g[i+1][1]*binom(n,i)%mod;
	for(int i=1;i<=n;i++)ans=(ans+(ll)f[i]*vi[i])%mod;
	// for(int i=1;i<=n;i++)std::cout<<f[i]<<" \n"[i==n];
	// std::cout<<ans<<std::endl;
	std::cout<<(ll)ans*fpow((ll)n*fpow(3,n)%mod,mod-2)%mod<<std::endl;
}

Measured memory_bytes: 27648
from collections import defaultdict
import bisect
n = int(input())
d = defaultdict(list)
for i,j in enumerate(input()):
  j = int(j)
  d[j].append(i)
c = 0
for i in range(10):
  for j in range(10):
    for k in range(10):
      if d[i] != [] and d[j] != [] and d[k] != []:
        b = bisect.bisect_right(d[j],d[i][0])
        if b != len(d[j]) and d[j][b] < d[k][-1]:
          c += 1
print(c)

Measured memory_bytes: 4704