akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	ll n;
	string m = "abcdefghijklmnopqrstuvwxyz";
	string ans = "";

	cin >> n;

	vector<ll> v[26];

	REP(i, 26) {
		REP(j, n) {
			v[i].push_back(0);
		}
	}

	REP(i, n) {
		string s;
		cin >> s;
		REP(j, s.size()) {
			v[s[j] - 'a'][i]++;
		}
	}

	REP(i, 26) {
		sort(v[i].begin(), v[i].end());
		REP(j, v[i][0]) {
			ans += m[i];
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define deb(x) cout<<#x<<" = "<<x<<"\n";
 
signed main()
{
	//freopen("input.txt", "r", stdin);
	
	int n, k; cin>>n>>k;
	priority_queue<int> q;
	
	for(int i=0; i<n; i++)
	{
		int x; cin>>x;
		q.push(x);
	}
	for(int i=0; i<k && !q.empty(); i++)
	{
		int t = q.top(); q.pop();
		t /= 2;
		if(t>0) q.push(t);
	}
	int ans = 0;
	while(!q.empty())
	{
		int t = q.top(); q.pop();
		ans += t;
	}
	cout<<ans<<"\n";
	
	
	
	
}

Measured memory_bytes: 1400
#include <stdio.h>

int main(void){
    int a,b,c,d = 0;
    int n,cnt = 0;
    
    while( scanf( "%d" , &n ) != EOF){
        cnt = 0;
        for( a = 0 ; a <= 9; a++ ){
            for( b = 0 ; b <= 9 ; b++ ){
                for( c = 0 ; c <= 9 ; c++ ){
                    for( d = 0 ; d <= 9 ; d++ ){
                        if( a + b + c + d == n ){
                            cnt++;
                        }
                    }
                }
            }
        }
        printf("%d\n", cnt );
    }
}



Measured memory_bytes: 2032
#include<iostream>
#include<string>
#include<algorithm>
#include<stack>
#include<vector>
#define rep(i, n) for(int i = 0; i < n; i++ )
using namespace std;

//  max(0, S-2K) <= X <= min(S, K);
//  Y + Z = S - X && 0 <= Y,Z <= K;
//  max( 0 , S-X-K ) <= Y <= min(S-X, K)
int K, S;

int combination(int lower, int upper) {
  int comb = 0;
  for ( int j = lower; j <= upper; j++ ) {
    int lower_temp, upper_temp;
    lower_temp = max(0, S-K-j);
    upper_temp = min(S-j, K);
    comb += (upper_temp - lower_temp) + 1;
  }
  return comb;
}

int main() {
  int lower, upper;
  cin >> K >> S;
  lower = max(0, S - 2*K);
  upper = min(S, K);
  cout << combination(lower, upper) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
const int mod = 1e9 + 7;
const int INF = 1e9;
using namespace std;
typedef long long ll;

int main()
{
    int n,m;
    cin >> n >> m;
    int  p[100000],y[100000];
    vector<int> yd[100001];
    for(int i = 0; i < m; i++){
        cin >> p[i] >> y[i];
        yd[p[i]].push_back(y[i]);
    }
    for(int i = 0; i < n; i++){
        sort(yd[i+1].begin(),yd[i+1].end());
    }
    for(int i = 0; i < m; i++){
        printf("%06d",p[i]);
        printf("%06d\n",lower_bound(yd[p[i]].begin(),yd[p[i]].end(),y[i]) - yd[p[i]].begin() + 1);
    }
}

Measured memory_bytes: 7808
#include <stdio.h>
#include <stdlib.h>
#include <string.h>


// 優先度付きキューの構造体
typedef struct queue_t{
	char c;
	int count;
	struct queue_t *left, *right;
} QUEUE_T;

QUEUE_T *PRIORITY_QUEUE[27];


// 小さい頂点を丁度いい所まで浮かび上がらせる
void Up_heap(int pos)
{
	int parent = pos / 2;
	QUEUE_T *x = PRIORITY_QUEUE[pos];

	while(parent >= 1){
		if(PRIORITY_QUEUE[parent]->count > x->count){
			PRIORITY_QUEUE[pos] = PRIORITY_QUEUE[parent];
			pos = parent;
			parent = pos / 2;
		}else
			break;
	}

	PRIORITY_QUEUE[pos] = x;
}


// 一番上(カウントが最小値)の頂点を取り出す、一番下のを一番上に持ってきてから、丁度いい所まで沈める
QUEUE_T *Down_heap(int count)
{
	QUEUE_T *x, *tmp;
	int pos = 1;
	int l = 2;

	x = PRIORITY_QUEUE[1];

	tmp = PRIORITY_QUEUE[1] = PRIORITY_QUEUE[count--];

	while(l <= count){
		if((l + 1) <= count && PRIORITY_QUEUE[l]->count > PRIORITY_QUEUE[l + 1]->count)
			l++;

		if(PRIORITY_QUEUE[l]->count < tmp->count){
			PRIORITY_QUEUE[pos] = PRIORITY_QUEUE[l];
			pos = l;
			l = pos * 2;
		}else
			break;
	}

	PRIORITY_QUEUE[pos] = tmp;

	return x;
}


// 文字に関する情報を頂点としてキューへ登録
void Add(int count, int num, int moji_count)
{
	QUEUE_T *p;

	if( (p = (QUEUE_T *)malloc(sizeof(QUEUE_T))) == NULL){
		printf("malloc error\n");
		exit(1);
	}

	p->c = 97 + num;
	p->count = moji_count;
	p->left = NULL;
	p->right = NULL;

	PRIORITY_QUEUE[count] = p;

	Up_heap(count);
}


// 統合した頂点をキューへ登録、丁度いいところまで浮かび上がらせる
void Add2(QUEUE_T *x, int count)
{
	PRIORITY_QUEUE[count] = x;
	Up_heap(count);
}


// ２つの頂点を統合した頂点を作成
QUEUE_T *Make_huffmann_tree(QUEUE_T *left, QUEUE_T *right)
{
	QUEUE_T *p;

	if( (p = (QUEUE_T *)malloc(sizeof(QUEUE_T))) == NULL){
		printf("malloc error\n");
		exit(1);
	}

	p->c = 'X';
	p->count = left->count + right->count;
	p->left = left;
	p->right = right;

	return p;
}


int SUM = 0;
char CODE[256] = "";

// ハフマンツリーを実際にたどって、ビット列を割り当てる
void Tree_walk(QUEUE_T *x, int depth)
{
	char moji[256];

	if(x->left != NULL){
		strcat(CODE, "0");
		Tree_walk(x->left, depth + 1);
		CODE[strlen(CODE) - 1] = '\0';
	}

	if(x->right != NULL){
		strcat(CODE, "1");
		Tree_walk(x->right, depth + 1);
		CODE[strlen(CODE) - 1] = '\0';
	}

	if(x->left == NULL & x->right == NULL){
		// 文字と割り当てられたビット列の表示
//		printf("ans = %c:%s\n", x->c, CODE);
		SUM += strlen(CODE) * x->count;
	}
}


int main()
{
	QUEUE_T *x, *y, *z;
	char in_str[1000005];
	int moji_count[26];
	int len;
	int count, count2;
	int i, j, k;

	scanf("%s", in_str);

	len = strlen(in_str);

	for(i = 0; i < 26; i++)
		moji_count[i] = 0;

	// 出現文字のカウント
	for(i = 0; i < len; i++)
		moji_count[in_str[i] - 97]++;

	// ヒープ木の作成
	count = 1;
	for(i = 0; i < 26; i++){
		if(moji_count[i] != 0){
//			printf("%c:%d\n", 97 + i, moji_count[i]);
			Add(count++, i, moji_count[i]);
		}
	}

	// ハフマン木の作成
	count--;
	while(count != 1){
		x = Down_heap(count--);
		y = Down_heap(count--);
		z = Make_huffmann_tree(x, y);
		Add2(z, ++count);
	}

	// ハフマツリーをたどってビット列を割り当てる
	Tree_walk(PRIORITY_QUEUE[1], 0);

	// 答え
	if(SUM)
		printf("%d\n", SUM);
	else
		printf("%d\n", PRIORITY_QUEUE[1]->count);

	return 0;
}


Measured memory_bytes: 2112
s = gets.chomp

if s.chars.all? {|c| c == s[0] }
  puts 0
  exit
end

array = []
('a'..'z').to_a.each do |target|
  dupped = s.dup
  1.upto(s.length) do |i|
    0.upto(s.length - i - 1) do |j|
      next if dupped[j] == target
      if dupped[j + 1] == target
        dupped[j] = dupped[j + 1]
      end
    end

    dupped = dupped[0..-2]

    # p dupped

    if dupped.chars.all? {|c| c == target }
      array << i
      break
    end
  end
end

p array.min


Measured memory_bytes: 1916
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <queue>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int a[128], b[128], r[128];
    fill(a, a+128, 0);
    fill(b, b+128, 0);
    fill(r, r+128, 0);
    string sa, sb;
    cin >> sa >> sb;
    reverse(sa.begin(), sa.end());
    reverse(sb.begin(), sb.end());
    for (unsigned int j = 0; j < min(128, int(sa.length())); j++)
      a[j] = sa[j] - '0';
    for (unsigned int j = 0; j < min(128, int(sb.length())); j++)
      b[j] = sb[j] - '0';
    for (int j = 0; j <= 80; j++) {
      r[j] += a[j] + b[j];
      r[j+1] += r[j] / 10;
      r[j] %= 10;
    }
    if (r[80])
      cout << "overflow" << endl;
    else {
      int k = 79;
      for (; k >= 1 && !r[k]; k--);
      for (int j = k; j >= 0; j--)
        cout << r[j];
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int number = sc.nextInt();
    int[] cards = new int[number];
    for (int i = 0; i < number; i++) {
      cards[i] = sc.nextInt();
    }
    Arrays.sort(cards);
    int Alice = 0;
    int Bob = 0;
    if (number % 2 == 0) {
      for (int j = 0; j < number; j++) {
        if (j % 2 == 1) {
          Alice += cards[j];
        } else {
          Bob += cards[j];
        }
      }
    } else {
      for  (int j = 0; j < number; j++) {
        if (j % 2 == 0) {
          Alice += cards[j];
        } else {
          Bob += cards[j];
        }
      } 
    }
    System.out.println(Alice - Bob);
  }
}

Measured memory_bytes: 23892
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * author @sahil
 */
 public class Main {
    final static int M=100000+5;
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String s[]=br.readLine().split(" ");
        int a[]=new int[M];
        for(int i=0;i<n;++i){
            int x=Integer.parseInt(s[i]);
            if(x>0){
                a[x]++;
                a[x-1]++;
                a[x+1]++;
            }
            if(x==0){
                a[0]++;
                a[1]++;
            }
        }
        int max=-1;
        if(n==1) System.out.println("1");
        else{
            for(int i=0;i<M;++i){
                if(a[i]>0 && a[i]>max)
                    max=a[i];
            }
            System.out.println(max);
        }


    }
}


Measured memory_bytes: 37852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];
    vector<vector<int>> 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 nx : g[i])
        {
            if(h[nx] >= h[i]) flag = false;
        }
        if(flag) ans++;
    }
    cout << ans << endl;
}



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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<long long> vl;
typedef pair<long long, long long> pl;
typedef vector<vector<long long>> matrix;

#define F 						first
#define S 						second
#define PB 						push_back
#define MP 						make_pair
#define all(c) 					c.begin(), c.end()
#define f(i,a,b) 				for(ll i=a; i<b; i++)
#define rep(i,n) 				f(i,0,n)
#define tr(c,i) 				for(typeof(c).begin() i = c.begin(); i != c.end(); i++)
#define present(c,x) 			(c.find(x) != c.end())	//for set and map
#define cpresent(c,x) 			(find(all(c),x) != c.end())	//for vectors
#define w(t)					ll t; cin>>t; while(t--)
#define epsilon 				1e-9
#define MOD						(ll)1e9

void doublade() {
	ios::sync_with_stdio(false); cin.tie(0); cout.precision(10);
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
}

int main() {
	doublade();
	// w(t) {
		ll n, d;
		cin >> n >> d;
		ll cnt=0;
		rep(i, n) {
			ll x, y;
			cin >> x >> y;
			ll dis = x*x + y*y;
			// cout<<dis<<"\n";
			if(dis<=d*d) cnt++;
		}
		cout<<cnt<<"\n";
	// }
	return 0;
}

Measured memory_bytes: 3648
#bit全探索
n,m,x=map(int,input().split())
a=[]
for i in range(n):
    ai=list(map(int,input().split()))
    a.append(ai)

#可能判定
maxi=[0 for i in range(m)]
for i in range(n):
    for j in range(m):
        maxi[j]+=a[i][j+1]
for i in range(m):
    if maxi[i]<x:
        print(-1)
        exit()

mini=100000000
#全探索
for i in range(2**n):
    d=[]
    for j in range(n):
        if((i>>j)& 1):
            d.append(j)
    b=[0 for j in range(m)]
    #得た能力
    c=0
    #お金
    for j in d:
        c+=a[j][0]
        for k in range(m):
            b[k]+=a[j][k+1]
    l=0
    for j in b:
        if j<x:
            l=1
    if l==0:
        mini=min(mini,c)

print(mini)


Measured memory_bytes: 9160
#include<cstdio>
int A[20 + 5], B[20 + 5], C[20 + 5];
int main() {
	int N; scanf("%d", &N);
	for(int i=1;i<=N;i++)
		scanf("%d", &A[i]);
	int ans = 0;
	for(int i=1;i<=N;i++)
		scanf("%d", &B[i]), ans += B[i];
	for(int i=1;i<N;i++)
		scanf("%d", &C[i]);
	for(int i=1;i<N;i++)
		if( A[i] + 1 == A[i + 1] )
			ans += C[A[i]];
	printf("%d\n", ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define reg(i,a,b) for(int i=a;i<=b;i++)
#define reh(i,a,b) for(int i=a;i>b;i--)
#define in(x) scanf("%d",&x)
#define fro freopen("D:\\testdata.in", "r", stdin)
#define il inline
#define lson(q) q<<1
#define rson(q) q<<1|1
using namespace std;
typedef long long ll;
const int mx=1e5+10;
int t;
double a[mx];
int b[mx];
int n,m;

int main() {
	int n,lcm;
	scanf("%d",&n);
	 reg(i,1,n){
	 	scanf("%lf",&a[i]);
	 	
	 }
	 sort(a+1,a+1+n);
	 reg(i,2,n){
	 	a[i]=(a[i]+a[i-1])/2;
	 }
	 printf("%lf\n",a[n]);
	return 0;
}




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

int main(){
  int w;
  int ans;

  while(1){
    cin >> w;
    if(w<0)break;
    
    if(w<=10)ans = 1150;
    else if(w<=20)ans = 1150 + 125*(w-10);
    else if(w<=30)ans = 2400 + 140*(w-20);
    else ans = 3800 + 160*(w-30);

    cout << 4280 - ans << endl;
  }
}

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

using ll = long long;

ll digit_dp(ll n) {
	string S;
	while (n) S.push_back('0' + n % 10), n /= 10;
	reverse(S.begin(), S.end());
	n = S.size();
	vector<vector<vector<ll>>> dp(n + 1, vector<vector<ll>>(2, vector<ll>(145)));
	dp[0][0][0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 2; j++) {
			int lim = j ? 9 : S[i] - '0';
			for (int d = 0; d <= lim; d++) {
				for (int k = 0; k < 145; k++) {
					if (dp[i][j][k]) {
						dp[i + 1][j || d < lim][k + d] = 1;
					}
				}
			}
		}
	}
	ll res = 0;
	for (int j = 0; j < 145; j++) {
		for (int i = 0; i < 2; i++) {
			if (dp[n][i][j]) {
				res = j;
			}
		}
	}
	return res;
}

int main()
{
	ll N;
	cin >> N;
	cout << digit_dp(N) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
   int a,b,c;
   cin>>a>>b>>c;
   if(a==b && a==5 && c==7){ cout<<"YES"<<"\n";
   }
   else if(a==c && a==5 && b==7){cout<<"YES"<<"\n";}
   else if(b==c && b==5 && a==7){cout<<"YES"<<"\n";}
   else cout<<"NO"<<"\n";
}


Measured memory_bytes: 3560
#include<iostream>
using namespace std;
int main(){
  int n,i,sum = 0,p,ans = 0;cin >> n;
  int h[n];
  for(i=0;i<n;i++){
    cin >> h[i];sum += h[i];
  }
  while(sum != 0){
    p = 0;
    while(h[p] == 0) p++;
    while(p != n && h[p] != 0){
      h[p]--;sum--;p++;
    }
    ans++;
  }
  cout << ans << endl;
}

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


template<class T>
struct min_cost_flow {
	using value_type = T;
	using P = pair<value_type, int>;
private : 
	const value_type INF = numeric_limits<value_type>::max();
	struct edge {
	public : 
		int to, rev;
		value_type cap;
		value_type cost;
		edge (int to, value_type cap, value_type cost, int rev) : 
			to(to), cap(cap), cost(cost), rev(rev) { }
	};
	int n;
	vector<vector<edge>> g;
	vector<value_type> potential;
	vector<value_type> dist;
	vector<int> prev_vertex;
	vector<int> prev_edge;

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

public : 
	min_cost_flow (int n) :
		n(n), g(n), potential(n), dist(n), prev_vertex(n), prev_edge(n) { }

	void add_edge (int from, int to, value_type cap, value_type cost) {
		g[from].emplace_back(to, cap, cost, g[to].size());
		g[to].emplace_back(from, 0, -cost, g[from].size() - 1);
	}

	value_type solve (int s, int t, value_type f) {
		value_type ret = 0;
		fill(potential.begin(), potential.end(), 0);
		while (f > 0) {
			priority_queue<P, vector<P>, greater<P>> que;
			fill(dist.begin(), dist.end(), INF);
			dist[s] = 0;
			que.emplace(dist[s], s);
			while (not que.empty()) {
				value_type d; int v;
				tie(d, v) = que.top(); que.pop();
				if (dist[v] < d) continue;
				for (int i = 0; i < g[v].size(); i++) {
					const edge &e = g[v][i];
					if (e.cap > 0 and chmin(dist[e.to], dist[v] + e.cost + potential[v] - potential[e.to])) {
						prev_vertex[e.to] = v;
						prev_edge[e.to] = i;
						que.emplace(dist[e.to], e.to);
					}
				}
			}
			if (dist[t] == INF) return -1;
			for (int v = 0; v < n; v++) potential[v] += dist[v];
			value_type val = f;
			for (int v = t; v != s; v = prev_vertex[v]) {
				chmin(val, g[prev_vertex[v]][prev_edge[v]].cap);
			}
			f -= val;
			ret += (val * potential[t]);
			for (int v = t; v != s; v = prev_vertex[v]) {
				edge &e = g[prev_vertex[v]][prev_edge[v]];
				e.cap -= val;
				g[v][e.rev].cap += val;
			}
		}
		return ret;
	}

};

int main() {
	int n, m, f;
	cin >> n >> m >> f;
	min_cost_flow<int> mcf(n);
	for (int i = 0; i < m; i++) {
		int u, v, c, d;
		cin >> u >> v >> c >> d;
		mcf.add_edge(u, v, c, d);
	}
	
	cout << mcf.solve(0, n - 1, f) << '\n';
	
	return 0;
}



Measured memory_bytes: 3152
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  ll X,K,D; cin>>X>>K>>D;
  ll s0;
  if(X>0) s0=X/D; 
  else s0=X/(-D); 
  
  //cout<<s0<<endl;
  
  if(K<=s0) {cout<<min(abs(X+D*K),abs(X-D*K))<<endl; return 0;}
  
  K-=s0;
  //cout<<K<<endl;
  if(K%2==0) cout<<min(abs(X+D*s0),abs(X-D*s0))<<endl;
  else cout<<abs(D-min(abs(X+D*s0),abs(X-D*s0)))<<endl;
  
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
long long n, k[100005], mon[100005], ans;
bool pre(int a, int b) {
    if(k[a]<k[b]){return true;}
    else{return false;}
}

int main() {
	cin>>n;
	for (int i = 0; i < n; ++i) {
		cin>>k[i];
        mon[i+1] = i+1;
	}
    sort(mon,mon+n,pre);
	for (int i = 0; i < n; i += 2){
		if (mon[i+1] % 2 == 0){++ans;}
    }
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
def inpl():
    return list(map(int, input().split()))


N, X, Y = inpl()
X -= 1
Y -= 1
ans = {i: 0 for i in range(N)}
for i in range(N):
    for j in range(i + 1, N):
        c = min(j - i, abs(i - X) + 1 + abs(j - Y), abs(i - Y) + 1 + abs(j - X))
        ans[c] += 1

for i in range(1, N):
    print(ans[i])


Measured memory_bytes: 3572
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   string ans = "No";
   int n;
   cin >> n;
   FOR(i,1,10)
   {
      if(n%i == 0 && n/i <10)
      {
         ans = "Yes";
         break;
      }
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
arr=list(map(int,input().split()))
l=[-1]*(n+1)
tmp=[]
pos=1
cnt=0
while 1:
  if l[pos]!=-1:
    t=cnt-l[pos]
    if k<cnt:
      print(tmp[k])
    else:
      print(tmp[l[pos]+(k-cnt)%t])
    break
  l[pos]=cnt
  cnt+=1
  tmp.append(pos)
  pos=arr[pos-1]

Measured memory_bytes: 32380
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define in(x) cin>>x
#define ina(x, n) rep(x_i,n) cin>>x[x_i]
#define outa(x, n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int n; in(n);
  vll ans;
  rep(i,n) {
    int a; in(a);
    ans.pb(mp(a,i+1));
  }
  sort(all(ans));
  rep(i,n) cout<<ans[i].ss<<" \n"[i==n-1];
  return 0;
}


Measured memory_bytes: 2544
#include <bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     long long n;
     cin>>n;
    vector<long long > v(n);
    for(int i=0;i<n;i++)
    {
        cin>> v[i];
    }

    vector<long long > dp(n);
    if(n<1)
    {
        cout<<0;
        return 0;
    }

    dp[1]=abs(v[1]-v[0]);

    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
    }

    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define rrep(i,n) for (int i = (n - 1);i >= 0;i--)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    bool isGood = true;
    rep(i,3){
        if(s[i]==s[i+1]) isGood = false;
    }
    if(isGood) cout << "Good" << endl;
    else cout << "Bad" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vi vector<int>
using namespace std;
constexpr int MOD=1e9+7;
constexpr int mod=998244353;

bool prime(int n){
    for(int i = 2 ; i <= sqrt(n) ; ++i){
        if(n % i == 0) {
            return 0 ; 
        }
    }

    return 1 ; 
}

int main() {
    char c ; 
    cin >> c;  
    if(c >= 'a' && c  <= 'z')
        cout << 'a' ; 
    else
        cout << 'A' ; 
    

    return 0 ; 
}

Measured memory_bytes: 3648
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <bits/stdc++.h>
#include <string>
using namespace std;

int main(){
    long X;
    cin>>X;
    for(int t=1;;t++){
        int sum_t = t*(t+1)/2;
        if(sum_t>=X){
            cout<<t<<endl;
            return 0;
        }
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  string S;
  IN(S);

  bool flag = true;

  REP(i,S.size()){
    char ch = S[i];
    if(i%2==1){
      if(ch == 'R') flag=false;
    }else{
      if(ch == 'L') flag=false;
    }
  }

  if(flag){
    OUT("Yes");
  }else{
    OUT("No");
  }

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
void tos(int a[]){
    int t=a[0];
    a[0]=a[4];
    a[4]=a[5];
    a[5]=a[1];
    a[1]=t;
}
void ton(int a[]){
    int t=a[0];
    a[0]=a[1];
    a[1]=a[5];
    a[5]=a[4];
    a[4]=t;
}
void toe(int a[]){
    int t=a[0];
    a[0]=a[3];
    a[3]=a[5];
    a[5]=a[2];
    a[2]=t;
}
void tow(int a[]){
    int t=a[0];
    a[0]=a[2];
    a[2]=a[5];
    a[5]=a[3];
    a[3]=t;
}
void tor(int a[]){
    int t=a[1];
    a[1]=a[2];
    a[2]=a[4];
    a[4]=a[3];
    a[3]=t;
}
void tol(int a[]){
  int t=a[1];
  a[1]=a[3];
  a[3]=a[4];
  a[4]=a[2];
  a[2]=t;
}
int main(void){
  int a[6],s,i,n;
  char o[10];
  while(scanf("%d",&n),n){
    for(i=0;i<6;i++)
      a[i]=i+1;
    s=1;
    while(n--){
      scanf("%s",o);
      if(strcmp(o,"North")==0){
	ton(a);
	s+=a[0];
      }
      if(strcmp(o,"East")==0){
	toe(a);
	s+=a[0];
      }
      if(strcmp(o,"South")==0){
	tos(a);
	s+=a[0];
      }
      if(strcmp(o,"West")==0){
	tow(a);
	s+=a[0];
      }
      if(strcmp(o,"Right")==0){
	tor(a);
	s+=a[0];
      }
      if(strcmp(o,"Left")==0){
	tol(a);
	s+=a[0];
      }
    }
    printf("%d\n",s);
  }
  return 0;
}

Measured memory_bytes: 604
#include<algorithm>
#include<cmath>
#include<cctype>
#include<iomanip>
#include<iostream>
#include<map>
#include <queue>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define out(x) cout << x << endl;
#define each(e, v) for (auto&& e : v)
#define clamp(v,lo,hi) min(max(v,lo),hi)
#define debug(i) cout<<"point :"<< i << endl;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define all(a) a.begin(),a.end()
typedef long long LL;
typedef vector<int> vint;
typedef vector<long> vl;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef map<string, int> mapstri;
typedef map<int, int> mapii;
typedef std::pair<int, int> pairii;

int main () {
    string s;
    cin >> s;
    if (s[0] == '7' || s[1] == '7' || s[2] == '7') {
        out("Yes")
    } else {
        out("No")
    }
    return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;

const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int a[102345];
pair<bool,bool> f[102345];

int main(){
	int n;
	
	cin >> n;
	
	bool flag = 0;
	
	REP(i,n){
		cin >> a[i];
		
		if (f[a[i]].first == 0) f[a[i]].first = 1;
		else if (f[a[i]].second == 0) f[a[i]].second = 1;
		else flag = 1;
	}
	
	if (n%2 == 0){
		for (int i = 1; i < n; i+=2){
			if (f[i].first == 0 || f[i].second == 0) flag = 1;
		}
	}
	else {
		if (f[0].first == 0 || f[0].second == 1) flag = 1;
		
		for (int i = 2; i < n; i+=2){
			if (f[i].first == 0 || f[i].second == 0) flag = 1;
		}
	}
	
	if (flag) cout << 0 << endl;
	else {
		ll ans = 1;
		
		REP(i,n/2){
			ans *= 2;
			ans %= MOD;
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

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


Measured memory_bytes: 1024
import math
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# import re
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk

# slist = "abcdefghijklmnopqrstuvwxyz"
MOD = 10**9 + 7
A,B,H,M = map(int,input().split())

kakuH = 30 * H + 0.5 * M
kakuM = 6 * M

naiKaku = abs(kakuH-kakuM)

ans = A**2 + B**2 - 2*A*B*math.cos(math.radians(naiKaku))
ans = math.sqrt(ans)
print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 9500
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

const ll MOD = 998244353;

signed main(){
    int n,s; cin >> n >> s;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    ll dp[n+1][s+1];
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;
    rep(i,n){
        rep(j,s+1){
            if(j-a[i]>=0) dp[i+1][j]+=dp[i][j-a[i]];
            dp[i+1][j]+=2*dp[i][j];
            dp[i+1][j]%=MOD;
        }
    }
    cout << dp[n][s] << endl;
}


Measured memory_bytes: 73868
n=int(input())
r={"AC":0,"WA":0,"TLE":0,"RE":0}
for i in range(n):
  r[input()]+=1
print("AC x %d" % r["AC"])
print("WA x %d" % r["WA"])
print("TLE x %d" % r["TLE"])
print("RE x %d" % r["RE"])

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

for i in range(N):
  for j in range(i,N):
    A[i],A[j]= A[j],A[i]
    for k in range(N):
      if A[k]!= B[k]:
        break
    else:
      print('YES')
      exit()
    A[i],A[j]= A[j],A[i]
        
print('NO')

Measured memory_bytes: 3064
#include<stdio.h>
#include<ctype.h>
main(){
  int a=0;
  int b=0;
  int c=0;
  int d=0;
  int e=0;
  char A[1001]={0};
  while(1){
    scanf("%s",&A);
    if(A[0]=='0')break;
    int e=strlen(A);
    for(a=0;a<e;a++){
      if(A[a]!=0){
      int c=A[a]-'0';
      b=b+c;
      c=0;
      }
    }
    printf("%d\n",b);
    b=0;
    c=0;
  }
  return 0;
}

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

using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    vector <int> s(m), c(m), a(n + 1);
    for (int i = 0; i < m; i++)
    {
        cin >> s[i] >> c[i];
        a[s[i]] = c[i];
    }
    for (int i = 0; i < m; i++)
    {
        if (a[s[i]] != c[i] || (n > 1 && s[i] == 1 && c[i] == 0))
        {
            cout << -1;
            return 0;
        }
    }
    if (a[1] == 0 && n > 1) a[1] = 1;
    for (int i = 1; i <= n; i++)
        cout << a[i];
}

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

int main(){
    int x;
    cin >> x;
    int ans=1;
    if (x >= 4) {
        for (int i=2; i<floor(sqrt(x))+1; i++){
            int j=2;
            while (pow(i, j) <= x) {
                ans = fmax(ans, pow(i, j));
                j += 1;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4008
#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>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());
    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    int n=s.length();
    stack <char> st;
    for(int i=0;i<n;i++)
    {
        if(s[i]!='B')
            st.push(s[i]);
        else{
            if(st.size())
            st.pop();
        }
    }
    vector <char> fin;
    while(st.size())
    {
        fin.push_back(st.top());
        st.pop();
    }
    reverse(all(fin));
    for(auto i:fin)
        cout<<i;
    cout<<endl;

    
    return 0;   
}


 
 


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main() {
    int N, M; cin >> N >> M;
    vector<bool> ac(N,false);
    vector<int> cnt(N,0);
    int ansac=0,answa=0;
    REP(i,M) {
        int p; string s;
        cin >> p >> s; p--;
        if(ac[p]==false)cnt[p]++;
        if(s=="AC") ac[p] = true; 
    }
    REP(i,N) {
        if(ac[i]) {
            ansac++;
            answa += cnt[i] - 1;
        } 
    }
    cout << ansac << " " << answa << endl;
}

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

int n, x, y, num, ymx, ymn, xmx, xmn;
int main()
{
	int i;
//	freopen ("input.txt", "r", stdin);
	cin >> xmx >> ymx >> n;
	for (i = 0; i < n; i++) {
		scanf ("%d %d %d", &x, &y, &num);
		if (num == 1) xmn = max(xmn, x);
		else if (num == 2) xmx = min(xmx, x);
		else if (num == 3) ymn = max(ymn, y);
		else ymx = min(ymx, y);
	}
    cout << max(ymx - ymn, 0) * max(xmx - xmn, 0) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  static String s;

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

    s = sc.next();

    int n = s.length();
    int[] counts = new int[26];
    for(int i = 0; i < n; i++){
      ++counts[s.charAt(i) - 'A'];
    }

    boolean ok = true;
    if(counts['N' - 'A'] >= 1 && counts['S'- 'A'] < 1){
      ok = false;
    }
    if(counts['S'- 'A'] >= 1 && counts['N'- 'A'] < 1){
      ok = false;
    }
    if(counts['W'- 'A'] >= 1 && counts['E'- 'A'] < 1){
      ok = false;
    }
    if(counts['E'- 'A'] >= 1 && counts['W'- 'A'] < 1){
      ok = false;
    }

    if(ok){
      System.out.println("Yes");
    }
    else{
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 9940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    int K, S; cin >> K >> S;
    ll ans = 0;
    for (int i = 0; i <= K; i++) {
        for (int j = 0; j <= K; j++) {
            if (S - i - j >= 0 && S - i - j <= K) ans++;
        }
    }

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

Measured memory_bytes: 3632
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():


    H, W = map(int, input().split())
    maze = [input() for _ in range(H)]
    temp = [[0] * W for _ in range(H)]



    for h in range(H):
        for w in range(W):
            if maze[h][w] == ".":
                cnt=0
                for k, l in ([1, 0], [-1, 0], [0, 1], [0, -1],[1,1],[-1,1],[-1,-1],[1,-1]):

                    nh, nw = h + k, w + l
                    if nh < 0 or nh >= H or \
                            nw < 0 or nw >= W:
                        continue

                    elif maze[nh][nw] == "#":
                        cnt+=1

                temp[h][w]=cnt
            else:
                temp[h][w]='#'


    for i in temp:
        print(*i,sep='')

resolve()

Measured memory_bytes: 43632
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M = mapint()
if N>M:
  N = M
Xs = list(mapint())
Xs.sort()
dist = []
for i in range(1, M):
    dist.append(Xs[i]-Xs[i-1])
dist.sort()

print(sum(dist[:M-N]))

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

using namespace std;

#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int main()
{
    FAST();
    int n;
    cin >> n;
    if(n > 29)cout << "Yes";
    else cout << "No";
    return 0;
}


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

int main(){
  int n;
  int k;
  cin >> n >>k;
 string s;
 cin>>s;
if(s.substr(k-1,1)=="A"){
s.replace(k-1,1,"a");
}else if(s.substr(k-1,1)=="B"){
s.replace(k-1,1,"b");
}else if(s.substr(k-1,1)=="C"){
s.replace(k-1,1,"c");
}
cout << s<<endl;
 
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

int main()
{
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int x3,y3,x4,y4;
    int deltaY = y2 - y1;
    int deltaX = x2 - x1;

    x3 = x2 - deltaY;
    y3 = y2 + deltaX;

    x4 = x1 - deltaY;
    y4 = y1 + deltaX;

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;

    return 0;
}

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

int main(){
    int n;
    while(cin>>n){
        int a[2000];
        for (int i = 0; i < n;i++){
            cin >> a[i];
        }
        int q;
        cin >> q;
        int m[200];
        for (int i = 0; i < q;i++){
            cin >> m[i];
        }

        bool ans[100000] = {false};
            for (int bit = 0; bit < (1 << n);bit++){
                int num = 0;
                for (int i = 0; i < n;i++){
                    if(bit & (1<<i)){
                        num += a[i];
                    }
                }
                ans[num] = true;
            }

            for (int i = 0; i < q;i++){
                if(ans[m[i]] == true){
                    cout << "yes" << endl;
                }
                else{
                    cout << "no" << endl;
                }
            }
    }
}


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

ll s[333333], t[333333];

int main() {
   int n;
   cin >> n;
   vec<ll> a(3*n);
   rep (i, 3*n) {
      cin >> a[i];
   }

   pq<ll, vec<ll>, greater<ll>> Q;
   ll sum = 0;
   for (int i = 0; i < 3*n; i++) {
      Q.push(a[i]);
      sum += a[i];
      if (Q.size() > n) {
         sum -= Q.top();
         Q.pop();
      }
      s[i] = sum;
   }

   pq<ll> P;
   sum = 0;
   for (int i = 3*n-1; i >= 0; i--) {
      P.push(a[i]);
      sum += a[i];
      if (P.size() > n) {
         sum -= P.top();
         P.pop();
      }
      t[i] = sum;
   }  

   ll ans = -1e18;
   for (int i = n-1; i < 2*n; i++) {
      ans = max(ans, s[i] - t[i+1]);
   }
   cout << ans << endl;

   return 0;
}

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

// #define DEBUG 1

#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define iter2(c) for(auto it2=c.begin(); it2!=c.end(); it2++)
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define pmod(x,m) (((x)%(m)+m)%m)
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define priter(v) iter(v) {pr(*it)} nl
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define priter(v)
#define debug
#endif
#define MAXN 100000

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

bool graph[2][105][105];

void increment_graph(int i) 
{
    for (int u=1; u<=100; u++) {
        for (int v=1; v<=100; v++) {
            graph[i][u][v] = graph[1-i][u-1][v-1];
        }
    }
}

void add_node(int i, int u, int low, int high)
{
    for (int v=low; v<=high; v++)
        graph[i][u][v] = graph[i][v][u] = 1; 
}

int32_t main()
{
    #ifdef DEBUG
    //freopen("B.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    int N; 
    cin >> N; 
    if (N == 3) {
        cout<<2<<endl;
        cout<<"1 3"<<endl;
        cout<<"2 3"<<endl;
        return 0;
    }
    
    int n = 4; 
    int i = (n>>1)&1; 
    ms(graph,0);
    graph[i][1][2] = graph[i][2][1] = 1; 
    graph[i][1][3] = graph[i][3][1] = 1; 
    graph[i][4][3] = graph[i][3][4] = 1; 
    graph[i][4][2] = graph[i][2][4] = 1; 
    
    for (n=6; n<=N; n+=2) {
        i = (n>>1)&1; 
        increment_graph(i); 
        add_node(i, 1, 2, n-1);
        add_node(i, n, 2, n-1);
        // prl(n) 
        // print2D(graph[i], n+1, n+1);
    }
    
    if (N%2 == 1)
        add_node(i, N, 1, N-1); 
    
    vector<pair<int,int>> edges;
    for (int u=1; u<=N; u++) {
        for (int v=u+1; v<=N; v++) {
            if (graph[i][u][v])
                edges.push_back({u,v}); 
        }
    }
    cout<<sz(edges)<<endl;
    for (pair<int,int> p : edges) 
        cout<<p.first<<" "<<p.second<<endl; 
    return 0;
}


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


int main() {
	//code
	int x,n;
	cin>>x>>n;
	int a[n];
	map<int,int>m;
	for(int i=0;i<n;i++){
        cin>>a[i];
        m[a[i]]=1;}
        int ans=x;
        int mini=INT_MAX;
     for(int i=x-n;i<x+n;i++){
        if(!m.count(i)){
            if(mini>abs(x-i)){
                mini=abs(x-i);
                ans=i;}}
     }
      cout<<ans;
	return 0;
}


Measured memory_bytes: 3632
import math

N = int(input())

A = [0] * 5

human_in_city = [0]*6
human_in_city[0] = N
moving_human = [0]*5

for i in range(5):
    A[i] = int(input())

# count = 0
# while human_in_city[-1] != N:
#     count += 1
#     for i in range(5):
#         if human_in_city[i] >= A[i]:
#             moving_human[i] = A[i]
#         else:
#             moving_human[i] = human_in_city[i]
#     for i in range(5):
#         human_in_city[i+1] += moving_human[i]
#         human_in_city[i] -= moving_human[i]

min_A = min(A)

count = 5 + math.ceil(N / min_A) -1

print(count)

Measured memory_bytes: 38384
<?php
    $S = str_split(trim(fgets(STDIN)));
    
    $array = ["A","C","G","T"];
    
    // var_dump($array);
    $count=0;
    $max=0;
    for($i=0;$i<count($S);$i++){
        if(in_array($S[$i],$array,true)){
            $count++;
        }else{
            if($max<$count){
                $max = $count;
                $count=0;
            }
        }
    }
    if($max<$count){
        $max = $count;
        $count=0;
    }
    echo $max;
?>

Measured memory_bytes: 16208
#include <iostream>
using namespace std;
int main(){
  long long  n, k;
  cin >> n >> k;
  if(n%k==0){
    cout << 0 << endl;
    return 0;
  }
  long long x = n%k;
  if(x*2<k) cout << x << endl;
  else cout << k-x << endl; 
}

Measured memory_bytes: 256