akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

#define rep(i,n)   for(int i=0;i<n;++i)
#define rep1(i,n)  for(int i=1;i<=n;++i)
#define INF        ( 1<<20 )

using namespace std;

int costs[101][101];

int main()
{
	int N,M,S,G1,G2;
	while(cin>>N>>M>>S>>G1>>G2,N|M|S|G1|G2)
	{
		rep1(i,N)rep1(j,N)costs[i][j] = INF;
		rep1(i,N)costs[i][i] = 0;

		int b1,b2,c;
		rep(i,M)
		{
			cin>>b1>>b2>>c;
			costs[b1][b2] = /*costs[b2][b1] = */c;
		}

		rep1(k,N)rep1(i,N)rep1(j,N)
		{
			costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j]);
		}

		int m = INF;
		rep1(i,N)
		{
			m = min(m, costs[S][i] + costs[i][G1] + costs[i][G2]);
		}
		cout << m << endl;
	}
	return 0;
}

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

using namespace std;

#define rep(i, x)   for (__typeof(x) i = 0; i < x; i++)
#define mp             make_pair
#define pb             push_back
#define fi             first
#define se             second
#define sz(x)          (int)((x).size())
#define all(x)         (x).begin(), (x).end()
#define sci(x)         int x;       scanf("%d", &x);
#define scii(x, y)     int x, y;    scanf("%d %d", &x, &y);
#define sciii(x, y, z) int x, y, z; scanf("%d %d %d", &x, &y, &z);
#define TC(x)          sci(x); while(x --)
#define eprintf(...)   fprintf(stderr, __VA_ARGS__)
#define debug(x)       { cerr << #x << " = " << x << endl; }
#define repi(i, x)  for (__typeof(x) i = x-1; i >= 0; i --)
#define fore(itr, x)   for (__typeof(x.begin()) itr = x.begin(); itr != x.end(); itr ++)
#define forei(itr, x)  for (__typeof(x.end()) itr = x.end() - 1; itr != x.begin() - 1; itr --)
typedef long long      ll;
typedef pair<int, int> ii;
typedef pair<ii, int>  iii;
typedef vector<int>    vi;
typedef vector<ii>     vii;
typedef vector<iii>    viii;
typedef vector<vector<int> > vvi;
const   int            infi = numeric_limits<int>::max();
const   double         eps = 0;
const   int            ms  = 0;

int main()
{
    ios::sync_with_stdio(false);//endl->"\n"
    cin.tie(0);

    int n, T;
    cin >> n >> T;
    vi c(n), t(n);
    rep(i, n) cin >> c[i] >> t[i];
    int mi = 1001;
    rep(i,n){
        if(t[i] <= T)mi = min(c[i], mi);
    }
    mi == 1001 ? cout << "TLE" << "\n" : cout << mi << "\n";
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int C[] = new int[N];
		int A[][] = new int[N][M];
		for(int i = 0 ; i < N ; ++i){
			C[i] = sc.nextInt();
			for(int j = 0 ; j < M ; ++j){
				A[i][j] = sc.nextInt();
			}			
		}
		int ret = Integer.MAX_VALUE;
		for(int p = 0 ; p < (1 << N) ; ++p){
			int skill[] = new int[M];
			int cost = 0;
			for(int i = 0 ; i < N ; ++i){
				if((p & (1 << i)) == 0){
					continue;
				}
				cost += C[i];
				for(int j = 0 ; j < M ; ++j){
					skill[j] += A[i][j];
				}
			}
			boolean f = true;
			for(int i = 0 ; i < M ; ++i){
				if(skill[i] < X){
					f = false;
				}
			}
			if(f){
				ret = Math.min(ret, cost);				
			}
		}
		if(ret == Integer.MAX_VALUE){
			System.out.println(-1);
		}else{
			System.out.println(ret);
		}
	}
}


Measured memory_bytes: 28472
#include <iostream>
#include <string>

int main(int argc, char const *argv[]) {
    std::string r;
    std::string g;
    std::string b;

    std::cin >> r>>g>>b;
    std::string s= g+b;
    int num=std::stoi(s);
    if (num%4==0) {
        std::cout << "YES" << '\n';
    }
    else{
        std::cout << "NO" << '\n';
    }


    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <limits>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	int n; cin >> n;
	vector<int> a(n);

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

	int ans = 0;
	for (int i = 0; i < n; i++) {
		int tmp=*max_element(a.begin(), a.begin()+i);

		if (a[i] >= tmp)ans++;
	}

	cout << ans << endl;
}

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

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int T, A;
    cin >> T >> A;
    vector<int> H(N);
    REP(i, 0, N) {
        cin >> H[i];
    }
    int minCost = 1 << 30;
    int index = -1;
    REP(i, 0, N) {
        if (abs(6 * H[i] - (T - A) * 1000) < minCost) {
            minCost = abs(6 * H[i] - (T - A) * 1000);
            index = i;
        }
    }
    cout << index + 1 << endl;
    return 0;
}


Measured memory_bytes: 256
fn main() {
    let n = read::<usize>();
    if n % 2 == 0 {
        println!("{}", n / 2);
    } else {
        println!("{}", n / 2 + 1);
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().parse().ok().unwrap()
}

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

typedef long long ll;

int main() {
	
	int n,m;
	cin >> n >> m;
	int a = 0, w = 0;
	vector<pair<int,int>> cnt(n,pair<int,int>(make_pair(0,0)));
	for (int i=0; i<m; i++) {
		int p;
		string s;
		cin >> p >> s;
		--p;
		if (cnt[p].first != 1) {
			if (s == "AC") {
				cnt[p].first = 1;
			} else {
				cnt[p].second++;
			}
		}
	}
	for (auto& e:cnt) {
		if (e.first == 1) {
			a++;
			w += e.second;
		}
	}
	
	cout << a << ' ' << w;
	
	return 0;
}


Measured memory_bytes: 4056
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <climits>
using namespace std;

typedef long long ll;
/*
typedef struct Name   Name;
struct Name {
    int a[3];
};
*/
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) for (int i = 0; i < (a); i++)
int main()
{
    int a, b;
    cin >> a >> b;
    int c = b-2*a;
    if(c%2 == 0 && c >= 0 && a*2 >= c)
    {
        cout << "Yes" << "\n";
    }
    else
    {
        cout << "No" << "\n";
    }
    
}

Measured memory_bytes: 3596
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc=new Scanner(System.in);
    
    int n=sc.nextInt();
    double arr[]=new double[n];
   
    
    double av=0;
    for (int i=0;i<n;i++)
      arr[i]=sc.nextDouble();
    Arrays.sort(arr);
    for (int i=0;i<n-1;i++)
    {
      av=(arr[i]+arr[i+1])/(double)2;
      arr[i+1]=av;
    }
      System.out.println(av);
  }
}

Measured memory_bytes: 25172
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    REP(i, N) {
        cin >> A[i];
        B[i] = A[i];
    }
    sort(ALL(A), greater<int>());
    int tmp = A[0];
    int tmp2 = A[1];
    int cnt = 0;
    REP(i, N) {
        if (A[i] == tmp) {
            cnt++;
        }
    }
    REP(i, N) {
        if (B[i] == tmp) {
            if (cnt > 1) {
                cout << tmp << endl;
            } else {
                cout << tmp2 << endl;
            }
        } else {
            cout << tmp << endl;
        }
    }
    return 0;
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
            var count = s.Count(z => z == 'R');

            Console.WriteLine(count > N / 2 ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 11220
s = input()
YY = int(s[:2]) 
MM = int(s[2:])

if 0 < YY < 13 and 0 < MM < 13:
    print("AMBIGUOUS")
elif 0 < YY < 13:
    print("MMYY")
elif 0 < MM < 13:
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3060
cmin = lambda a,b : a if a<b else b
cmax = lambda a,b : a if a>b else b
iin = lambda : int(input())
lin = lambda : list(map(int,input().split()))
rin = lambda n : [int(input()) for _ in range(n)]

a,b = map(int,input().split())

at = []
for i in range(1,1500):
    if int(i*0.08)==a: at += [i]

bt = []
for i in range(1,1500):
    if int(i*0.1)==b: bt += [i]

ans = set(at) & set(bt)

print(min(ans) if ans else -1)

Measured memory_bytes: 3064
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

int main(){
  long long n,x;
  cin >> n >> x;
  long long a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  long long count = 0;
  long long temp;

  for(int i=0;i<n;i++){
    if(a[i] > x){
      count += a[i]-x;
      a[i] = x;
    }
  }
  for(int i=0;i<n-1;i++){
    temp = 0;
    if(a[i]+a[i+1] <= x) continue;
    temp = min(a[i]+a[i+1]-x,a[i+1]);
    a[i+1] -= temp;
    count += temp;
    if(a[i] > x){
      count += a[i]-x;
    }
  }
  cout << count << endl;


  return 0;
}


Measured memory_bytes: 1024
#include <limits.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <math.h>

#define P 1000000007

int comp(const void *a, const void *b){return *(int*)a-*(int*)b;}

int main(void){
	int n, i;
	int a[2][101];
	scanf("%d", &n);
	a[0][0]=a[1][0]=0;
	for(i=0; i<n; i++){
		int A;
		scanf("%d", &A);
		a[0][i+1]=a[0][i]+A;
	}
	for(i=0; i<n; i++){
		int A;
		scanf("%d", &A);
		a[1][i+1]=a[1][i]+A;
	}
	int max=0, now;
	for(i=1; i<=n; i++){
		now = a[0][i]+a[1][n]-a[1][i-1];
		if(now>max) max=now;
	}
	printf("%d\n", max);
}


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

ll dp[101][100001];

ll nps(ll* v_arr, ll *w_arr, ll w, ll n){
	if(w == 0 || n == 0) return 0;
	if(dp[n][w]) return dp[n][w]; 

	if(w - v_arr[n - 1] >= 0) return dp[n][w] = max(w_arr[n - 1] + nps(v_arr, w_arr, w - v_arr[n - 1], n - 1),
										 			nps(v_arr, w_arr, w, n - 1));
	else return dp[n][w] =  nps(v_arr, w_arr, w, n - 1);
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n , w;
	cin >> n >> w;
	memset(dp, 0, sizeof dp);
	ll v_arr[n], w_arr[n];
	for(int i = 0; i < n; i++){
		cin >> v_arr[i] >> w_arr[i];
	}
	cout << nps(v_arr, w_arr, w , n);
	
}


Measured memory_bytes: 82496
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,m,count=0;cin>>n>>m;
  vector<long long>v(n),vv(n);
  map<long long,long long>frq;
  for(long long i=0;i<n;i++)
  {cin>>v[i];
  }
  while(m--)
  {
  long long a,b;cin>>a>>b;
    a--,b--;
    vv[a]=max(vv[a],v[b]);
    vv[b]=max(vv[b],v[a]);
    frq[v[a]]++;frq[v[b]]++;
  }
  for(long long i=0;i<n;i++)
  {if(vv[i]==0)count++;
  else if(v[i]>vv[i])count++;
  }
  cout<<count;
}


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

int main() {

	int n, m; cin >> n >> m;
	vector<int> x(m);
	for (int i = 0; i < m; i++) {
		cin >> x[i];
	}
	sort(x.begin(), x.end());

	vector<int> dist(m - 1);
	for (int i = 0; i < m - 1; i++) {
		dist[i] = x[i + 1] - x[i];
	}
	sort(dist.begin(), dist.end());

	int sum = 0;
	for (int i = 0; i < max(0, m - n); i++) {
		sum += dist[i];
	}
	
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INL inline
#define REG register
#define DB double
#define LDB long double
#define ULL unsigned long long
#define LL long long

#define RPT(i,x,y) for (REG int i=(x);i<(y);i++)
#define DRPT(i,x,y) for (REG int i=(x);i>(y);i--)
#define MST(a,b) memset((a),(b),sizeof(a))
#define MRK() cout<<"Mark"<<endl;
#define WRT(x) cout<<#x<<" = "<<(x)<<endl;

#define MAXN 110000
#define MAXM 10000
#define MOD 998244353
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-5

#define _ 0
using namespace std;

int pa[MAXN],dis[MAXN];

int getpa(int x)
{
	if (pa[x]==x)
		return x;
	int f=pa[x];
	pa[x]=getpa(pa[x]);
	dis[x]+=dis[f];
	return pa[x];
}

bool merge(int x,int y,int d)
{
	int px=getpa(x),py=getpa(y);
	if (px==py && d!=dis[x]-dis[y])
		return false;
	pa[px]=py;
	dis[px]=d+dis[y]-dis[x];
	return true;
}

int n,m;

int main()
{
	int x,y,z;
	cin>>n>>m;
	RPT(i,1,n+1)
		pa[i]=i;
	RPT(i,0,m)
	{
		scanf("%d%d%d",&x,&y,&z);
		if (!merge(y,x,z))
		{
			cout<<"No";
			return 0;
		}
		/*
		cout<<endl<<"--------------\n\n";
		RPT(i,1,n+1)
		{
			cout<<pa[i]<<' '<<dis[i]<<endl;
		}
		*/
	}
	cout<<"Yes";
	return ~~(0^_^0);
}



Measured memory_bytes: 1024
// ?´??????°????§£

#include <iostream>
#include <cmath>
using namespace std;

bool isPrime(int x) {
  if(x == 2) return true;

  if(x < 2 || x % 2 == 0) return false;

  int i = 3;
  while(i <= sqrt(x)) {
	if(x % i == 0) return false;
	i += 2;
  }
  return true;
}

int main() {
  int n;
  cin >> n;
  cout << n << ":";

  while(n > 1) {
    for(int i = 2; i <= 50847534; ++i) {
      if(isPrime(n)) {
        cout << " " << n;
        n /= n;
        break;
      }
      if(isPrime(i) && n % i == 0) {
        n /= i;
        cout << " " << i;
        break;
      }
    }
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

const int INF = 1000000000;

class RangeAddMinSegmentTree {
public:
	vector<pair<int, int>> dat;
	vector<int> lazy;
	int size_ = 1;

	void init(int sz) {
		while (size_ <= sz) size_ *= 2;
		dat.resize(size_ * 2, make_pair(0, INF));
		lazy.resize(size_ * 2, 0);

		for (int i = 0; i < size_; i++) {
			int pos = i + size_;
			dat[pos].second = i;
			while (pos >= 2) {
				pos >>= 1;
				dat[pos].second = min(dat[pos].second, i);
			}
		}
	}
	void refresh(int u) {
		lazy[u * 2 + 0] += lazy[u];
		lazy[u * 2 + 1] += lazy[u];
		pair<int, int> V1 = make_pair(dat[u * 2 + 0].first + lazy[u * 2 + 0], dat[u * 2 + 0].second);
		pair<int, int> V2 = make_pair(dat[u * 2 + 1].first + lazy[u * 2 + 1], dat[u * 2 + 1].second);
		dat[u] = min(V1, V2);
		lazy[u] = 0;
	}
	void add_(int l, int r, int x, int a, int b, int u) {
		if (l <= a && b <= r) { lazy[u] += x; return; }
		if (r <= a || b <= l) return;
		refresh(u);
		add_(l, r, x, a, (a + b) >> 1, u * 2);
		add_(l, r, x, (a + b) >> 1, b, u * 2 + 1);
		refresh(u);
	}
	void add(int l, int r, int x) {
		l = max(l, 0);
		add_(l, r, x, 0, size_, 1);
	}
	pair<int, int> query_(int l, int r, int a, int b, int u) {
		if (l <= a && b <= r) return make_pair(dat[u].first + lazy[u], dat[u].second);
		if (r <= a || b <= l) return make_pair(INF, -1);

		refresh(u);
		pair<int, int> V1 = query_(l, r, a, (a + b) >> 1, u * 2);
		pair<int, int> V2 = query_(l, r, (a + b) >> 1, b, u * 2 + 1);
		refresh(u);
		return min(V1, V2);
	}
	pair<int, int> query(int l, int r) {
		return query_(l, r, 0, size_, 1);
	}
	void delete_zero(int l, int r) {
		int cx = l;
		while (cx < r) {
			pair<int, int> F = query(cx, r);
			if (F.first != 0) return;
			add(F.second, F.second + 1, INF);
			cx = F.second + 1;
		}
	}
};

int num[1 << 19];

bool solve(vector<int> Z) {
	for (int i = 0; i < Z.size(); i++) { num[Z[i]] = i; }

	RangeAddMinSegmentTree X;
	X.init(Z.size() + 2);
	X.add(0, Z.size(), 1000000000);

	for (int i = Z.size() - 1; i >= 0; i--) {
		pair<int, int> V = X.query(0, num[i]);
		if (V.first < i) return false;
		X.add(num[i], num[i] + 1, i - 1000000000);
		X.add(num[i], Z.size(), -1);
	}
	return true;
}

int N, A[1 << 19];
int D[1 << 19];

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++) {
		scanf("%d", &A[i]);
		D[i] = max(D[i - 1], A[i]);
	}
	vector<int> R; R.push_back(0);
	for (int i = 1; i <= N; i++) {
		if (D[i] == i) R.push_back(i);
	}
	for (int i = 0; i < R.size() - 1; i++) {
		vector<int> E;
		for (int j = R[i] + 1; j <= R[i + 1]; j++) E.push_back(A[j]);

		bool flag = false;
		for (int j = 1; j < E.size(); j += 2) {
			if (E[j] != R[i] + j + 1) flag = true;
		}
		if (flag == true) {
			cout << "No" << endl;
			return 0;
		}

		vector<int> F;
		for (int j = 0; j < E.size(); j += 2) F.push_back((E[j] - R[i]) / 2);

		bool ret = solve(F);
		if (ret == false) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 14448
#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;
	vector<int> a, b(n);

	REP(i, n) cin >> b[i];
	reverse(b.begin(), b.begin() + n);
	REP(i, n){
		REP(j, b.size()){
			if(b[j] == b.size() - j){
				a.pb(b[j]);
				b.erase(b.begin() + j);
				break;
			}
		}
	}
	reverse(a.begin(), a.begin()+n);
	if(b.empty()) REP(i, n)  cout << a[i] << endl;
	else cout << -1 << endl;
    return 0;
}

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

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;


void main() {
    int N;
    scan(N);
    auto d = readln.split.to!(int[]);

    auto cnt = new int[](13);
    foreach (di ; d) {
        cnt[di]++;
    }

    if (cnt[0] > 0) {
        writeln(0);
        return;
    }
    if (cnt.any!"a > 2") {
        writeln(0);
        return;
    }

    int ans;

    int f(int[] s) {
        auto ss = s.dup.sort();
        int res = inf;
        foreach (i ; 0 .. ss.length.to!int - 1) {
            chmin(res, ss[i + 1] - ss[i]);
        }
        return res;
    }

    void dfs(int i, int[] s) {
        if (i == 13) {
            debug {
                writeln(s);
            }
            chmax(ans, f(s));
            return;
        }
        auto ss = s.dup;
        if (cnt[i] > 1) {
            ss ~= [i, 24 - i];
            dfs(i + 1, ss);
        }
        else if (cnt[i] == 1) {
            auto ssa = ss.dup ~ [i];
            dfs(i + 1, ssa);
            auto ssb = ss.dup ~ [24 - i];
            dfs(i + 1, ssb);
        }
        else {
            dfs(i + 1, ss);
        }
    }

    dfs(1, [0, 24]);

    writeln(ans);
}



void scan(T...)(ref T args) {
    auto line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront;
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x > arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;
    foreach (arg; args) if (x < arg) {
        x = arg;
        isChanged = true;
    }
    return isChanged;
}

void yes(bool ok, string y = "Yes", string n = "No") {
    return writeln(ok ? y : n);
}


Measured memory_bytes: 508
from sys import stdin
rs = lambda : stdin.readline().strip()
ri = lambda : int(rs())
ril = lambda : list(map(int, rs().split()))

def main():
    N = int(input())
    A, B = ril()
    P = ril()
    a, b, c = 0, 0, 0
    for p in P:
        if p <= A:
            a += 1
        elif p <= B:
            b += 1
        else:
            c += 1
    print(min(a, b, c))

if __name__ == '__main__':
    main()


Measured memory_bytes: 9160
#include <stdio.h>

int main(){
  int N;
  int p;
  int cnt = 0;
  
  scanf("%d",&N);

  for(int i=1;i<=N;i++){
    scanf("%d" ,&p);
    if( p != i )
      cnt++;
  }

  if( cnt == 0 || cnt == 2)
    printf("YES\n");
  else
    printf("NO\n");
  
  return 0;
}


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

using ll = long long; 
const int INF = 1e9+7;

int main() {
    int N;
  	scanf("%d", &N);
  	int min = INF;
  	int ans = 0;
  	for (int i = 0; i < N; i++) {
    	int n;
      	scanf("%d", &n);
      	if (n <= min) {
          	ans += 1;
          	min = n;
        }
    }
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
v = list(sorted(map(int, input().split())))
v.append(2000)
total = n*(n-1)*(n-2) / 6



def bs(left, s):
    right = n+1
    while left < right-1:
        m = (right+left)//2

        if v[m]>=s:
            right = m
        else:
            left = m
    return right


for i, x in enumerate(v[:-2]):
    for j, y in enumerate(v[i+1:-1]):
        k = bs(j, y+x)
        total -= (n-k)

print(int(total))

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

using namespace std;

int main(){
    string s; cin >> s;
    vector<bool> alpha(26, false);
    for(int i = 0; i < s.size(); i++){
        alpha[(int)(s[i] - 'a')] = true;
    }
    if(s.size() < 26){
        cout << s;
        for(int i = 0; i < 26; i++){
            if(!alpha[i]){
                cout << (char)(i + 'a') << endl;
                break;
            }
        }
    }
    else{
        int i = 25;
        vector<char> temp;
        for(; i > 0; i--){
            temp.push_back(s[i]);
            if(s[i] > s[i-1])break;
        }
        if(i == 0){
            cout << -1 << endl;
            return 0;
        }
        char key = s[i-1];
        sort(temp.begin(), temp.end());
        vector<char>::iterator top = upper_bound(temp.begin(), temp.end(), key);
        for(int j = 0; j < i-1; j++){
            cout << s[j];
        }
        cout << *top << endl;
    }
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using lint = long long int;
using ulint = unsigned long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  string t = "yuiophjklnm";
  while (true) {
    string s; cin >> s;
    if (s == "#") break;
    int n = s.size();
    int res = 0;
    for (int i = 0; i < n - 1; ++i) {
      bool b0 = find(begin(t), end(t), s[i]) != end(t);
      bool b1 = find(begin(t), end(t), s[i + 1]) != end(t);
      res += b0 ^ b1;
    }
    cout << res << '\n';
  }
}


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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli data[10]={0};

	REP(i,0,4){
		lli a;
		cin>>a;
		data[a]++;
	}
	if(data[1]==1 && data[9]==1&&data[7]==1&&data[4]==1){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		string[] ST = GetStrings(2);
		char[] tmp = new char[2 * N];
		for(int i = 0; i < N; i++)
		{
			tmp[2 * i] = ST[0][i];
			tmp[2 * i + 1] = ST[1][i];
		}
		WriteLine(new String(tmp));
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

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

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

class UnionFind{
public:
  vi Parent;
  UnionFind(int n){
    Parent = vi(n,-1);
  }

  int root(int a){
    if(Parent[a] < 0) return a;
    else return Parent[a] = root(Parent[a]);
  }

  int size(int a){
    return -Parent[root(a)];
  }

  bool merge(int a, int b){
    a = root(a);
    b = root(b);
    if(a == b) return false;

    if(size(a) < size(b)) swap(a,b);
    Parent[a] += Parent[b];
    Parent[b] = a;

    return true;
  }
};

class Factrial{
public:
  vl Fac;
  Factrial(int MAX){
    Fac = vl(MAX+1);
    rep(i,MAX) {
      if(i == 0) Fac[i+1] = 1;
      else Fac[i+1] = ((i+1)*Fac[i])%MOD;
    }
  }
};

const int MAX = 1000;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int power(int k){
  int tmp = 1;
  rep(i,k) tmp *= 9;
  return tmp;
}

int dfs(string s, int k){
  int n = sz(s);
  if(k == 0){
    return 1;
  }
  if(n == 0){
    return 0;
  }
  int top = s[0]-'0';
  int ret = 0;
  //printf("n:%d k:%d com:%d pow:%d\n", n, k, COM(n-1,k), power(k));
  if(top != 0){
    ret += COM(n-1,k)*power(k) + max(top-1,0) * COM(n-1,k-1) * power(k-1);
    s.erase(s.begin());
    ret += dfs(s, k-1);
    return ret;
  }
  else{
    s.erase(s.begin());
    return dfs(s, k);
  }

}

int main(){
  string N; int k;
  cin >> N >> k;
  int n = N.size();

  COMinit();

  vi a(n+1),b(n+1);

  //cout << n*(n-1)*(n-2)/6*9*9*9 << endl;
  cout << dfs(N,k) << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define int long long
#define FILE_IO freopen("input.txt","r",stdin)/#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for (auto &it : t) cout << it << " ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 

void solve(){
   set<char> c;
   string s;
   cin >> s;
   for (auto it : s) c.insert(it);
   bool ok =  (int)c.size() == (int)s.length();
   if (ok) cout << "yes" << endl;
   else cout << "no" << endl;	
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>

using namespace std;

//#include "triangle_point.h"
//#include "linear_search.h"
//#include "binary_search.h"
//#include "algo_lowerbound.h"
//#include "point_radian.h"


int main(){
    int W, H, N;
    int x, y, a, sum;
    cin >> W >> H >> N;
    vector<vector<int>> v;
    v = vector<vector<int>>(H, vector<int>(W, 1));

    
    while(cin >> x >> y >> a){
        if (a == 1){
            for(int i = 0; i < H; ++i){
                for (int j = 0; j < x; ++j){
                    v[i][j] = 0;
                }
            }
        }else if (a== 2){
            for(int i = 0; i < H; ++i){
                for (int j = x; j < W; ++j){
                    v[i][j] = 0;
                }
            }
            
        }else if (a == 3){
            for(int i = 0; i < y; ++i){
                for(int j = 0; j < W; ++j){
                    v[i][j] = 0;
                }
            }
            
        }else{
            for(int i = y; i < H; ++i){
                for(int j = 0; j < W; ++j){
                    v[i][j] = 0;
                }
            }
            
        }
    }
    
    sum = 0;
    for (auto y:v){
        for(auto x:y){
            sum += x;
        }
    }
    cout << sum << "\n";
}



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

S = list(input())
lis = []
for s in S:
    if s=='0':
        lis.append(str(0))
    if s=='1':
        lis.append(str(1))
    if s=='B':
        if len(lis):
            lis.pop()

print(''.join(lis))

Measured memory_bytes: 61948
fn main() {
    let scan = std::io::stdin();
    let mut line = String::new();
    let _ = scan.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();
    let mut n: i32 = vec[0].parse().unwrap();
    let mut ans = n;

    let scan = std::io::stdin();
    let mut line = String::new();
    let _ = scan.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();
    n = vec[0].parse().unwrap();

    if n < ans{
        ans = n;
    }

    let scan = std::io::stdin();
    let mut line = String::new();
    let _ = scan.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();
    n = vec[0].parse().unwrap();
    let mut tmp = n;

    let scan = std::io::stdin();
    let mut line = String::new();
    let _ = scan.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();
    n = vec[0].parse().unwrap();

    if n < tmp{
        tmp = n;
    }

    ans = ans + tmp;

    println!("{}",ans);

}


Measured memory_bytes: 4352
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得 multisetもある
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair
#include <cmath>

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)

template <class InputIterator, class T>
bool contains_itr(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class T>
bool contains_set(set<T> st, const T &value)
{
    if (st.find(value) == st.end())
    {
        return false;
    }
    else
    {
        return true;
    }
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// endは排他的(exclusive)なので注意
vector<ll> range(ll begin, ll end)
{
    vector<ll> result;
    for (ll i = begin; i < end; ++i)
    {
        result.push_back(i);
    }
    return result;
}

// =========ここまでテンプレ============

int main()
{
    ll n, k;
    cin >> n >> k;
    multiset<ll> p;
    rep(i, n)
    {
        ll tempP;
        cin >> tempP;
        p.insert(tempP);
    }
    ll result = 0;
    ll i = 0;
    for (auto itr = p.begin(); i < k; ++itr)
    {
        ++i;
        result += *itr;
    }
    cout << result << endl;
}

Measured memory_bytes: 3200
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T, class S> std::ostream& operator << (std::ostream& os, std::pair<T, S> p)
{
  return os << p.first << " " << p.second;
}

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N;
  std::cin >> N;

  std::vector< ll > va(N, 0LL);
  std::vector< ll > vb(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
  }
  for (ll i = 0; i < N; i++) {
    std::cin >> vb[i];
  }

  ll acnt = 0LL;
  ll bcnt = 0LL;
  for (ll i = 0; i < N; i++) {
    if (va[i] < vb[i]) {
      ll cnt = (vb[i] - va[i] + 1) / 2;
      va[i] += 2LL * cnt;
      acnt += cnt;
    }
  }

  for (ll i = 0; i < N; i++) {
    if (va[i] > vb[i]) {
      ll cnt = va[i] - vb[i];
      vb[i] += cnt;
      bcnt += cnt;
    }
  }

  if (acnt >= bcnt) print("Yes");
  else print("No");
  return 0;
}


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


using namespace std;

char s[200002];
int n, nxt[200002][26], dp[200002];
string ans;

int main()
{
  cin >> (s + 1);
  n = strlen(s + 1);
  dp[n + 1] = 1;
  for (int i = 0; i < 26; i++)
    nxt[n + 1][i] = n + 1;
  for (int i = n; i >= 1; i--) {
    for (int j = 0; j < 26; j++)
      nxt[i][j] = nxt[i + 1][j];
    nxt[i][s[i] - 'a'] = i;
  }
  for (int i = n; i >= 1; i--) {
    bool ok = 0;
    dp[i] = n + 2;
    for (int j = 0; j < 26; j++) {
      if (nxt[i][j] != n + 1)
        dp[i] = min(dp[i], dp[nxt[i][j] + 1] + 1);
      else
        ok = 1;
    }
    if (ok)
      dp[i] = 1;
  }
  int i = 1;
  while (i <= n) {
    bool ok = 0;
    int l = -1, poz;
    for (int j = 0; j < 26; j++) {
      if (nxt[i][j] != n + 1) {
        if (l == -1 && dp[i] == dp[nxt[i][j] + 1] + 1) {
          l = j;
          poz = nxt[i][j] + 1;
        }
      }
      else {
        ok = 1;
        l = j;
        break;
      }
    }
    cout << (char)(l + 'a');
    if (ok)
      break;
    i = poz;
  }
  return 0;
}


Measured memory_bytes: 21504
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    
    long long A, B, K;

    cin >> A >> B >> K;
    if (A > K) {
        printf("%lld %lld\n", A - K, B);
    } else {
        printf("%lld %lld\n", (long long)0, max(B - K + A, (long long)0));
    }
    return 0;
}

Measured memory_bytes: 256
import math

N,A,B=map(int,input().split())

v=list(map(int,input().split()))
v.sort(reverse=True)
print(sum(v[0:A])/A)

cnt=v.count(v[0])
cnt2=v.count(v[A-1])
V=v[0:A]
cnt3=V.count(v[A-1])

def combinations_count(n, r):
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
        
if cnt<A:
    print(combinations_count(cnt2, cnt3))
elif cnt==A:
    print(1)
elif cnt>A:
    ans=0
    for i in range(A,min(cnt+1,B+1)):
        ans+=combinations_count(cnt,i)
    print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <unordered_map>

using namespace std;

typedef long long LL;

const int MAXN = 100002;

int nx, ny, m;
int x[MAXN], y[MAXN];
int min_pair_y[MAXN];

int main() {
    cin >> nx >> ny >> m;
    int min_y = MAXN;
    for (int i = 0;i < nx;i ++) cin >> x[i];
    for (int i = 0;i < ny;i ++) {
        cin >> y[i];
        min_y = y[i] < min_y ? y[i] : min_y;
    }
    for (int i = 0;i < nx;i ++) min_pair_y[i] = min_y;
    for (int i = 0;i < m;i ++) {
        int xx, yy, dd;
        cin >> xx >> yy >> dd;
        xx --;
        yy --;
        if (y[yy] - dd < min_pair_y[xx]) min_pair_y[xx] = y[yy] - dd;
    }
    int res = MAXN * 2;
    for (int i = 0;i < nx;i ++) {
        if (x[i] + min_pair_y[i] < res) {
            res = x[i] + min_pair_y[i];
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1408
//
// Created by RAJ SHAH on 18-08-2020.
//

#include <bits/stdc++.h>
using namespace std;

long long solve(long long x, long long k, long long d) {
    x = abs(x);
    if (k == 0) {
        return x;
    }
    if (k % 2 == 1) {
        return min(solve(x - d, k - 1, d), solve(x + d, k - 1, d));
    }
    d *= 2;
    k /= 2;
    if (x / k >= d) {
        return x - d * k;
    }
    x %= d;
    return min(x, d - x);
}

int main()
{
    long long x, k, d;
    cin >> x >> k >> d;
    cout<<solve(x,k,d)<<endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int min(ll a,ll b){
  if(a<b)
  return a;
  return b;
}
int main(){
  ll n;
  cin>>n;
  vector<ll>v(n,0);
  int dp[100001];
  for(int i=0;i<100001;i++){
    dp[i]=INT_MAX;
  }
  dp[0]=0;
  for(int i=0;i<n;i++){
    cin>>v[i];
  }
  for(int i=0;i<n;i++){
    for(int j=i+1;j<=i+2;j++){
      if(j<n){
        dp[j]=min(dp[j],dp[i]+abs(v[i]-v[j]));
      }
    }
  }
  cout<<dp[n-1]<<endl;
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
//#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define MOD 998244353
#define SIZE 400005


ll POW[SIZE];
ll fact[SIZE],inv_fact[SIZE];

ll extgcd(ll a,ll b,ll &x,ll &y){
	ll d = a;
	if(b != 0){
		d = extgcd(b,a%b,y,x);
		y -= (a/b)*x;
	}else{
		x = 1;
		y = 0;
	}
	return d;
}

ll mod_inverse(ll a,ll m){
    ll x,y;
    extgcd(a,m,x,y);
    return (m+x%m)%m;
}

ll nCk(ll n,ll k){

	ll ret = fact[n]*inv_fact[k];
	ret %= MOD;
	ret *= inv_fact[n-k];

	return ret%MOD;
}



int main(){

	fact[0] = 1;
	for(ll i = 1; i < SIZE; i++){
		fact[i] = i*fact[i-1];
		fact[i] %= MOD;
	}
	inv_fact[SIZE-1] = mod_inverse(fact[SIZE-1],MOD);
	for(ll i = SIZE-1; i >= 1; i--){

		inv_fact[i-1] = inv_fact[i]*i;
		inv_fact[i-1] %= MOD;
	}

	ll N,M,K;

	scanf("%lld %lld %lld",&N,&M,&K);

	POW[0] = 1;
	for(int i = 1; i < SIZE; i++){

		POW[i] = POW[i-1]*(M-1);
		POW[i] %= MOD;
	}

	ll ans = 0;

	for(ll i = 0; i <= K; i++){

		ll tmp = POW[N-i-1];
		tmp *= M;
		tmp %= MOD;
		tmp *= nCk(N-1,i);
		tmp %= MOD;

		ans += tmp;
		ans %= MOD;
	}

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

	return 0;
}


Measured memory_bytes: 13208
#include <iostream>
#include <string.h>
#include <queue>
struct node {
    int x , y , s ;
};

using namespace std;
int ma[1005][1005] ;
int main()
{
    queue<node> q ;
    int a , b ;
    cin >> a >> b ;
    int sum = a*b ;
    char ch ;
    node temp ;
    memset(ma,0,sizeof(ma)) ;
    for (int i = 0 ; i < a ; i++) {
        for (int j = 0 ; j < b ; j++) {
            cin >> ch ;
            if (ch=='#') {
                temp.x = i ;
                temp.y = j ;
                temp.s = 0 ;
                q.push(temp) ;
                sum-- ;
                ma[i][j] = 1 ;
            }
        }
    }
    if (sum==0) {
        cout << 0 << endl ;
        return 0 ;
    }
    node temp1 ;
    while(!q.empty()) {
        temp = q.front() ;
        q.pop() ;
        if (temp.x>0){
            if (!ma[temp.x-1][temp.y]) {
                ma[temp.x-1][temp.y] = 1 ;
                sum-- ;
                temp1.x = temp.x - 1;
                temp1.y = temp.y ;
                temp1.s = temp.s + 1 ;
                q.push(temp1) ;
            }
        }
        if (temp.x<a-1){
            if (!ma[temp.x+1][temp.y]) {
                ma[temp.x+1][temp.y] = 1 ;
                sum-- ;
                temp1.x = temp.x + 1;
                temp1.y = temp.y ;
                temp1.s = temp.s + 1 ;
                q.push(temp1) ;
            }
        }
        if (temp.y>0){
            if (!ma[temp.x][temp.y-1]) {
                ma[temp.x][temp.y-1] = 1 ;
                sum-- ;
                temp1.x = temp.x ;
                temp1.y = temp.y -1 ;
                temp1.s = temp.s + 1 ;
                q.push(temp1) ;
            }
        }
        if (temp.y<b-1){
            if (!ma[temp.x][temp.y+1]) {
                ma[temp.x][temp.y+1] = 1 ;
                sum-- ;
                temp1.x = temp.x ;
                temp1.y = temp.y + 1 ;
                temp1.s = temp.s + 1 ;
                q.push(temp1) ;
            }
        }
        if (sum==0) {
            cout << temp.s+1 << endl ;
            break ;
        }
    }
    return 0;
}


Measured memory_bytes: 16272
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#include<bits/stdc++.h>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
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 long long LLINF=1LL<<60;
//set<int>::iterator it;



int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	
	int a,b,ans1=0,ans2=0;
	string s;
	cin>>s;
	a=(s[0]-'0')*10+(s[1]-'0');
	b=(s[2]-'0')*10+(s[3]-'0');
	if(a>0&&b>0&&a<=12&&b<=12)cout<<"AMBIGUOUS"<<endl;
	else if(a>0&&a<=12)fin("MMYY");
	else if(b>0&&b<=12)fin("YYMM");
	else fin("NA");
	
	
	
	
	
	
	
	
	
	
	
	
	
//////////////////////////////////////////////////////
return 0;}











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

struct Edge {
	int to;
	int num;
};

vector<vector<Edge>> g(100005);
vector<int> ans(100005, -1);
int mx_col = 1;

int N;
int a[100005], b[100005];

bool visited[100005];
void bfs() {
	queue<pair<int, int>> Q;
	Q.emplace(0, -1);
	while (!Q.empty()) {
		auto [v, p_col] = Q.front();
		Q.pop();
		visited[v] = true;
		int col = 1;
		for (auto e: g[v]) {
			if (visited[e.to]) continue;
			if (col == p_col) col++;
			ans[e.num] = col;
			col++;
			Q.emplace(e.to, ans[e.num]);
		}
	}
}

int main() {
	cin >> N;
	for (int i = 0; i < N - 1; ++i) cin >> a[i] >> b[i];

	for (int i = 0; i < N - 1; ++i) {
		g[a[i] - 1].push_back({b[i] - 1, i});
		g[b[i] - 1].push_back({a[i] - 1, i});
	}

	bfs();

	cout << *max_element(ans.begin(), ans.end()) << endl;
	for (int i = 0; i < N - 1; i++) cout << ans[i] << endl;

	return 0;
}

Measured memory_bytes: 10776