akhauriyash/Code-Regression huggingface dataset:
/**
 *    author:  FromDihPout
 *    created: 2020-07-29
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    vector<int> range = {3200, 2800, 2400, 2000, 1600, 1200, 800, 400, 1};
    const int COLS = range.size();
    
    int n;
    cin >> n;
    vector<int> cnt(COLS);
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        for (int j = 0; j < COLS; j++) {
            if (x >= range[j]) {
                cnt[j]++;
                break;
            }
        }
    }
    
    int unique = 0;
    for (int i = 1; i < COLS; i++) {
        unique += cnt[i] > 0;
    }
    
    cout << max(unique, 1) << ' ' << unique + cnt[0] << '\n';
    return 0;
}

Measured memory_bytes: 3580
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int d = scan.nextInt();
//		int[][] xy = new int[n][2];
		int count = 0;
		for(int i = 0; i < n; i++) {
			if(cal(scan.nextLong(), scan.nextLong()) <= d) {
				count++;
			}
		}
		System.out.println(count);
	}
	
	private static double cal(long x, long y) {
		return Math.sqrt(x*x + y*y);
	}

}

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

int main(void){
    int m, f, r;

while(1){
    cin >> m >> f >> r;
    if(m == -1 && f == -1 && r == -1) break;

    if(m == -1 || f == -1){
        cout << 'F';
    }else if(m+f >= 80){
       cout << 'A';
    }else if (m+f >= 65){
       cout << 'B';
    }else if (m+f >= 50){
       cout << 'C';
    }else if (m+f >= 30){
       if(r >= 50) 
       cout << 'C';
       else cout << 'D';
    }else {
       cout << 'F';
    }
    cout << endl;
}
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


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

Measured memory_bytes: 256
def divisor(a):
    ret = []
    for i in range(1, int(a ** 0.5) + 1):
        if not a % i:
            ret.append(i)
            ret.append(a // i)
    
    return ret

def make_lists():
    ret = [[] for i in range(20000)]

    for i in range(0, int(20000 ** 0.5) + 1):
        for j in range(0, int(20000 ** 0.5) + 1):
            if i ** 2 + j ** 2 < 20000:
                ret[i ** 2 + j ** 2].append([i, j])
    
    return ret

lists = make_lists()
ans = []

for loop in range(int(input())):
    m, n = map(int, input().split())
    C = []

    for div in divisor(m ** 2 + n ** 2):
        for l in lists[div]:
            for tmp in [-1, 1]:
                for tmp2 in [-1, 1]:
                    x, y = l[0] * tmp, l[1] * tmp2
                    if not (m * x + n * y) % (x ** 2 + y ** 2) and not (n * x - m * y) % (x ** 2 + y ** 2):
                        if [x, y] not in C:
                            C.append([x, y])

    ans.append('P' if len(C) == 8 else 'C')

[print(i) for i in ans]


Measured memory_bytes: 8312
#include <stdio.h>
const int maxn=1e5+5;
int a[maxn];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	int x=1,ans=0;
	for(int i=0;i<=n;i++)
	{
		x=a[x];
		ans++;
		if(x==2)break;
	}
	if(x==2)printf("%d",ans);
	else printf("-1");
	return 0;
}

Measured memory_bytes: 512
#![allow(dead_code)]

fn main() {
    let mut num:String = read();
    
    num = num.replace("?", "D");
    println!("{}", num);

}


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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}


fn read_n<T: std::str::FromStr>(n: u32) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

Measured memory_bytes: 2368
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;


int main(void){
  int n,d,i,x,h;
  ll a;
  P m[200005];
  
  cin >> n >> d >> a;
  for (i=1;i<=n;i++){
    cin >> x >> h;
    m[i]=P(x,h);
  }
  
  sort(m+1,m+n+1);
  
  int l,r,ko[200005]={};
  ll ru[200005];
  r=2;
  ru[0]=0;
  for (l=1;l<=n;l++){
    if (ko[l]==0) ko[l]=l;
    while (r<=n && m[r].first-m[l].first <= d*2){
      ko[r]=l;
      r++;
    }
    
    m[l].second-=a*(ru[l-1]-ru[ko[l]-1]);
    
    if (m[l].second<=0) ru[l]=0;
    else ru[l]=(m[l].second+a-1)/a;
    
    ru[l]+=ru[l-1];
  }
  
  cout << ru[n] << endl;
  
  return 0;
}

Measured memory_bytes: 4096
import heapq

n, m = map(int, input().split())
a = list(map(lambda x: int(x)*(-1), input().split()))
heapq.heapify(a)

for _ in range(m):
    tmp_min = heapq.heappop(a)
    heapq.heappush(a, (-1)*(-tmp_min//2))
print(-sum(a))

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;

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

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back
#define mp make_pair

int main()
{
    ll N, M, X;
    cin >> N >> M >> X;
    vec C(N);
    mat A(N, vec(M));
    REP(i,0,N) {
        cin >> C[i];
        REP(j,0,M) cin >> A[i][j];
    }

    vec S(M, 0);
    vec_b F(N, false);
    bool f = true;
    ll m = INF, sum = 0;
    REP(i,0,1<<N) {
        REP(j,0,N) {
            F[j] = ((i >> j) & 1 == 1);
        }
        REP(j,0,M) S[j] = 0;
        f = true;
        REP(j,0,N) {
            if(F[j]) {
                REP(k,0,M) S[k] += A[j][k];
            }
        }
        REP(j,0,M) {
            if(S[j] < X) {
                f = false;
                break;
            }
        }
        if(f) {
            sum = 0;
            REP(j,0,N) {
                if(F[j]) sum += C[j];
            }
            m = MIN(m,sum);
        }
    }
    if(m != INF) _PR(m);
    else _PR(-1);

    return 0;
}

/*



*/

Measured memory_bytes: 3632
def main():
    H, W = list(map(int, input().split()))
    A = [[i for i in input()] for _ in range(H)]
    cur = []
    for h in range(H):
        for w in range(W):
            if A[h][w] == '#':
                cur.append((h, w))
    r = 0
    while cur:
        nxt = []
        for ch, cw in cur:
            for x, y in [(0, -1), (0, 1), (1, 0), (-1, 0)]:
                nh, nw = ch + x, cw + y
                if 0 <= nh < H and 0 <= nw < W and A[nh][nw] == '.':
                    A[nh][nw] = '#'
                    nxt.append((nh, nw))
        cur = nxt
        r += 1
    return r - 1

print(main())


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

int main(){
  string S;
  cin >> S;
  int count=0;
  for(int i=0;S[i]!='\0';i++){
    if(S[i]=='C'&&count == 0){
      count++;
    }
    if(S[i]=='F'&&count == 1){
      count++;
      break;
    }
  }
  if(count == 2){
    cout <<"Yes" << endl;
  }else{
    cout <<"No"<<endl;
  }
  return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

ll N, K;
vector<ll> a;
vector<ll> psum;
map<ll,ll> mp;

signed main() {
  cin >> N >> K;
  a.resize(N);
  psum.resize(N,0);
  rep(i,N) {
    cin >> a[i];
    (a[i]+=(K-1)) %= K;
    (psum[i] += a[i]) %= K;
    if (i>0) {
      (psum[i] += psum[i-1]) %= K;
    }
    if (i <= K-2) {
      mp[psum[i]]++;
    }
  }
  //rep(i,N) {
  //  cout << a[i] << " ";
  //}
  //cout << endl;
  //rep(i,N) {
  //  cout << psum[i] << " ";
  //}
  //cout << endl;

  ll ans = 0;
  ll t = 0;
  rep(i,N) {
    //printf("i=%d \n", i);
    //for (auto e: mp) {
    //  if (e.second > 0) {
    //    printf("mp[%d]=%d ", e.first, e.second);
    //  }
    //}
    //cout << endl;

    ans += mp[t];
    // printf("ans mp[%d]=%d\n", t, mp[t]);
    mp[psum[i]]--;
    if (i+K-1 < N) {
      mp[psum[i+K-1]]++;
    }
    (t = K + psum[i]) %= K;
  }
  cout << ans << endl;
}


Measured memory_bytes: 15872
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;

int n,w,inf=-1,wei[105],val[105],dp[10005];

int func(){
	for(int i=0;i<n;i++){
		for(int j=wei[i];j<=w;j++){
			dp[j]=max(dp[j],dp[j-wei[i]]+val[i]);
		}
	}
	return dp[w];
}

int main(){
	cin>>n>>w;
	for(int i=0;i<n;i++){
		cin>>val[i]>>wei[i];
	}
	cout<<func()<<endl;
}

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

using namespace std;

int n, k;

int h[100005];
int wynik[100005];

int main(void)
{
	
	cin >> n;
	
	for(int i=1;i<=n;i++)
	{
		
		cin >> h[i];
		
	}
	
	wynik[0]=1000000;
	wynik[1]=0;
	
	for(int i=2;i<=n;i++)
	{
		
		wynik[i]=min(wynik[i-2]+abs( h[i]-h[i-2] ), wynik[i-1]+abs( h[i]-h[i-1] ) );
		
	}
	
	cout << wynik[n];
	
	return(0);
	
}

Measured memory_bytes: 1024
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#include <random>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,n) for(int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for(int i=(a)-1;i>=b;--i)
#define range(i,a,b,c) for(int i=a;\
                    c>0?i<b:\
                    i>b;\
                    i+=c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define int long long
#ifdef _MSC_VER
const bool test = false;
#else 
const bool test = false;
#endif

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
const int INF = 1 << 28;
const ll INFL = (ll)1 << 58;
ll mod = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real& r) { return (r > eps) - (r < -eps); }
int sgn(const Real& a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep) {
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

template<class InputIterator>
int sum(InputIterator begin, InputIterator end) {
	return accumulate(begin, end, 0ll);
}

string reverse_str(string s) {
	reverse(all(s));
	return s;
}

struct Vertex {
	int id, weight, v, dist, flag;
	Vertex(int id, int weight, int v, int dist, int flag) : 
		id(id), weight(weight), v(v), dist(dist), flag(flag) {  }
	bool operator > (const Vertex& r) const { return dist > r.dist; }
};

using Graph = vector<vector<Vertex>>;

using Weight = int;

int n, m;
int v0;
int a, b, c;
vector<Vertex> g[MAX];
int d[505][55][2];

int dijkstra(int start) {
	rep(i, n) rep(j, c) rep(k, 2) {
		d[i][j][k] = INFL;
	}
	d[0][0][0] = 0;
	priority_queue<Vertex, vector<Vertex>, greater<Vertex>> q;
	for (q.push(Vertex(start, 0, v0, 0, false)); !q.empty(); ) {
		Vertex p = q.top(); q.pop();
		for (auto next_p : g[p.id]) {
			next_p.v = (a * p.v + b) % c;
			next_p.dist = p.dist + p.v * next_p.weight;
			next_p.flag = (p.flag || next_p.id == n - 1);
			if (d[next_p.id][next_p.v][next_p.flag] > next_p.dist) {
				d[next_p.id][next_p.v][next_p.flag] = next_p.dist;
				q.push(next_p);
			}
		}
	}
	int min_cost = INFL;
	rep(j, c) chmin(min_cost, d[0][j][1]);
	return min_cost;
}

void solve() {
	cin >> n >> m;
	rep(i, m) {
		int x, y, t;
		cin >> x >> y >> t;
		x--;
		y--;
		g[x].push_back(Vertex(y, t, 0, 0, false));
		g[y].push_back(Vertex(x, t, 0, 0, false));
	}
	cin >> v0;
	cin >> a >> b >> c;
	cout << dijkstra(0) << endl;
}

signed main() {
	srand(time(NULL));
	int T = (int)1e15;
	solve();
	cout << fixed << setprecision(15);
	rep(i, T) {
		char s[MAX];
		if (scanf("%s", s) == EOF) break;
		int n = strlen(s);
		for (int i = n - 1; i > -1; i--) {
			ungetc(s[i], stdin);
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 18632
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
    if (!y)
        return x;
    return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
    auto start = chrono::high_resolution_clock::now();
#endif
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;

    int v = n / 500;
    ll ans = 1LL*v * 1000;
    n -= v*500;

    v = n / 5;
    ans += v * 5;

    cout << ans;


#ifdef LOCAL
    auto end = chrono::high_resolution_clock::now();
    double time_taken =
        chrono::duration_cast<chrono::nanoseconds>(end - start).count();

    time_taken *= 1e-9;

    cerr << "\nTime taken by program is : " << fixed
         << time_taken << setprecision(9);
    cerr << " sec" << endl;
#endif
    return 0;
}


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

int main(){
	int n, r, maxv = -2000000000;

	cin>>n>>r;

	int minv = r;

	for(int j = 1; j < n; j++){
		cin>>r;
		maxv = max(maxv, r - minv);
		minv = min(minv, r);
	}

	cout<<maxv<<endl;

	return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>

int main()
{
	int a, b;
	scanf("%d",&a);
	scanf("%d",&b);
	
	if(a<b)
	{
		printf("a < b\n");
	}
	else if(a>b)
	{
		printf("a > b\n");
	}
	else
	{
		printf("a == b\n");
	}
}


Measured memory_bytes: 2056
#include <iostream>


#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <vector>
#include <list>
using namespace std;
#include <stdio.h>
#include <map> 
#include <algorithm>
#include <functional>
#include <algorithm>
#include <functional>
#include <array>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>




int main()
{
	std::vector<long int> a;
	long int A, B;
	std::string S;
	cin >> A >> B;

	int i = A - B * 2;

	i = std::max(0, i);


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

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;

inline int getint()
{
	static char c;
	while ((c = getchar()) < '0' || c > '9');

	int res = c - '0';
	while ((c = getchar()) >= '0' && c <= '9')
		res = res * 10 + c - '0';
	return res;
}

const int MaxN = 100000;
const int MaxM = 200;
const int MaxNV = MaxM * 2;

int n, m;
int in[MaxNV + 1], out[MaxNV + 1];

int ufs[MaxNV + 1];

int ufs_find(int v)
{
	return ufs[v] == v ? v : ufs[v] = ufs_find(ufs[v]);
}

int main()
{
	cin >> n >> m;

	for (int u = 1; u <= m + m; ++u)
		ufs[u] = u;

	for (int i = 0; i < n; ++i)
	{
		int a = getint(), b = getint();
		int c = getint(), d = getint();

		int u = c ? c + m : a;
		int v = d ? d : m + b;

		++out[u], ++in[v];

		ufs[ufs_find(v)] = ufs_find(u);
	}

	bool ok = true;

	for (int u = 1; u <= m; ++u)
		if (out[u] < in[u])
			ok = false;

	for (int v = 1; v <= m; ++v)
		if (out[v + m] > in[v + m])
			ok = false;

	for (int u = 1; u <= m + m; ++u)
		if (ufs[u] == u && (in[u] || out[u]))
		{
			bool all = true;
			for (int v = 1; v <= m + m; ++v)
				if (ufs_find(v) == u)
					all &= in[v] == out[v];

			if (all)
				ok = false;
		}

	puts(ok ? "YES" : "NO");

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int K = sc.nextInt();
        int[] b = new int[n];
        for (int i=0;i<n;i++) {
            b[i] = sc.nextInt();
        }
        long[] ruiseki = new long[n+1];
        for (int i=0;i<n;i++) {
            ruiseki[i+1] = ruiseki[i]+b[i];
        }

        int N = n*(n+1)/2;
        int[][] bit = new int[N][50];
        // int[] a = new int[N];
        // for (int i=0;i<N;i++) {
        //     a[i] = sc.nextInt();
        //     int aa = a[i];
        //     for (int j=0;j<50;j++) {
        //         bit[i][j] = (aa&1);
        //         aa=(aa>>1);
        //     }
        // }
        ArrayList<Long> a = new ArrayList<Long>();
        int index = 0;
        for (int i=0;i<n;i++) {
            for (int k=i+1;k<n+1;k++) {
                // a[i] = ruiseki[k+1]-ruiseki[i];
                long aa = ruiseki[k]-ruiseki[i];
                a.add(aa);
                for (int j=0;j<50;j++) {
                    bit[index][j] = (int)(aa&1);
                    aa=(aa>>1);
                }
                index++;
            }
        }
        // System.out.println(a);

        ArrayList<Integer> list = new ArrayList<Integer>();
        for (int i=0;i<N;i++) list.add(i);
        for (int j=49;j>=0;j--) {
            int cnt = 0;
            ArrayList<Integer> tmp = new ArrayList<Integer>();
            for (Integer i : list) {
                if (bit[i][j]==1) {
                    cnt++;
                    tmp.add(i);
                }
            }
            // System.out.println("j, tmp "+j+" "+tmp);
            if (cnt>=K) list=tmp;
        }
        // System.out.println(list);
        long ans = a.get(list.get(0));
        for (int i=1;i<list.size();i++) {
            ans = ans&a.get(list.get(i));
        }
        System.out.println(ans);
        // System.out.println(Arrays.deepToString(bit));
    }
}

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

bool p[1000009];
int a[1000009], n, mni, mxi, ul;

bool ps(int dl)
{
	int l = 0, r = 0;
	for (int i = 0; i <= n; i++) {
		int u = (ul - a[i]) / 2, d = (dl - a[i] + 1) / 2;
		if (p[i]) r++;
		l = max(l, d); r = min(r, u);
		if (l > r) return false;
	}
	return true;
}

int bs(int l, int r)
{
	int md = (l + r) / 2;
	if (r == l + 1 && md == l) md = r;
	if (l >= r) return md;
	if (ps(md)) return bs(md, r);
	else return bs(l, md - 1);
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s; cin >> s;
	n = s.length();
	for (int i = 0; i < n; i++) {
		if (s[i] == '?') {
			s[i] = '0';
			p[i + 1] = true;
		}
		if (s[i] == '0')
			a[i + 1] = a[i] - 1;
		else
			a[i + 1] = a[i] + 1;
	}
	mxi = 0, mni = 0;
	for (int i = 1; i <= n; i++) {
		if (a[mxi] <= a[i])
			mxi = i;
		if (a[mni] > a[i])
			mni = i;
	}
	int ans = a[mxi] - a[mni];
	if (mni <= mxi) {
		cout << ans << '\n';
		return 0;
	}
	ul = a[mxi];
	ans = min(ans, ul - bs(a[mni], a[mxi]));
	ul = a[mxi] + 1;
	ans = min(ans, ul - bs(a[mni], a[mxi]));
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 9300
/// Kazuki Hoshino


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
//#define endl '\n'
typedef tree<
int,
null_type,less<int>,
rb_tree_tag,tree_order_statistics_node_update>
ordered_set;

int n, pos[202020], m; // number of vertices
vector<vector<int>> adj; // adjacency list of graph
vector<bool> visited;
vector<int> ans;
vi p[202020];
int indeg[202020], outdeg[202020];

void dfs(int v) {
    visited[v] = true;
    for (int u : adj[v]) {
        if (!visited[u])
            dfs(u);
    }
    ans.push_back(v);
}

void topological_sort(int s) {
    visited.assign(n+100, false);
    ans.clear();
    dfs(s);
    for (int i = 1; i <= n; ++i) {
        if (!visited[i])
            dfs(i);
    }
    reverse(ans.begin(), ans.end());
}

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

#ifndef ONLINE_JUDGE
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
#endif

cin >> n >> m;
adj.resize(3*n);
for(int i=1;i<n+m;i++){
	int x,y;
	cin >> x >> y;
	indeg[y]++;
	outdeg[x]++;
	p[y].pb(x);
	adj[x].pb(y);
}
int root = 1;
for(int i=1;i<=n;i++){
	if(indeg[i]==0)root = i;
}
topological_sort(root);

for(int i=0;i<n;i++){
	pos[ans[i]]=i+1;
}

for(int i=1;i<=n;i++){
	int cur = 0;
	for(auto t:p[i]){
		if(pos[t]>pos[cur]){
			cur = t;
		}
	}
	cout << cur << endl;
}

return 0;}
///....


Measured memory_bytes: 27640
N=int(input())
p=list(map(int,input().split()))
A=p.copy()
A.sort()
if p==A:
  print("YES")
else:
  flag=0
  for i in range(N):
    for j in range(i):
      p[i],p[j]=p[j],p[i]
      if p==A:
        flag=1
        break
      else:
        p[i],p[j]=p[j],p[i]
    if flag==1:
      break
  if flag==0:
    print("NO")
  else:
    print("YES")

Measured memory_bytes: 3064
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(10)

using namespace std;

char s[500][500];
bool visit[500][500];
int num[500][500];

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

int bfs(int i, int j) {
    char c = s[i][j];
    if (c == '.') return 0;
    if (num[i][j] != -1) return num[i][j];

    CLR(visit, false);

    queue<pair<int, int>> q;
    REP(k, 4) {
        int nx = dx[k] + i;
        int ny = dy[k] + j;
        if (nx < 0 || nx >= H || ny < 0 || ny >= W) {
            continue;
        }
        if (s[nx][ny] == '#') continue;
        q.push({nx, ny});
    }


    vector<pair<int, int>> cand;
    int ans = 0;
    visit[i][j] = true;
    while (!q.empty()) {
        auto kv = q.front();
        q.pop();
        int kx = kv.first;
        int ky = kv.second;
        if (visit[kx][ky]) continue;
        visit[kx][ky] = true;

        if (s[kx][ky] == '.') {
            ans++;
            REP(k, 4) {
                int nx = dx[k] + kx;
                int ny = dy[k] + ky;
                if (nx < 0 || nx >= H || ny < 0 || ny >= W) {
                    continue;
                }
                if (s[nx][ny] == '.') continue;
                if (visit[nx][ny]) continue;
                q.push({nx, ny});
            }
        }
        else {
            cand.push_back({kx, ky});
            REP(k, 4) {
                int nx = dx[k] + kx;
                int ny = dy[k] + ky;
                if (nx < 0 || nx >= H || ny < 0 || ny >= W) {
                    continue;
                }
                if (s[nx][ny] == '#') continue;
                if (visit[nx][ny]) continue;
                q.push({nx, ny});
            }
        }
    }

    for (auto kv : cand) {
        num[kv.first][kv.second] = ans;
    }
    return num[i][j] = ans;
}

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

    cin >> H >> W;
    REP(i, H) {
        REP(j, W) {
            cin >> s[i][j];
            num[i][j] = -1;
        }
    }

    int ans = 0;
    REP(i, H) {
        REP(j, W) {
            ans += bfs(i, j);
        }
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

int main(){
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	while(b<=a){
		b*=2;k--;
	}
	while(c<=b){
		c*=2;k--;
	}
	if(k>=0)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main(){
    int p = 1000000007 ;
    int64_t n,k ;
    cin >> n >> k ;
    vector<int> a(n);
    for (size_t i = 0; i < n; i++)
    {
        cin >> a.at(i) ;
    }
    int64_t ans = 0 ;
    for (size_t i = 0; i < n-1; i++)
    {
        for (size_t j = i+1; j < n; j++)
        {
            if (a.at(i) < a.at(j))
            {
                
                ans += ((k*(k-1)) /2) % p ;
            }
            if (a.at(i) > a.at(j))
            {
                ans += ((k*(k+1)) /2) % p ;
            }
            if (ans >= p)
            {
                ans = ans % p ;
            }
            
            
        }
        
    }
    
    cout << ans << endl ;
}

Measured memory_bytes: 256
from collections import deque

def main():
    n,q = map(int,input().split())
    d = deque()
    for _ in range(n):
        p,t = input().split()
        d.append([p,int(t)])

    time = 0
    while len(d):
        p,t = d.popleft()
        if t<=q:
            time += t
            print (p,time)
        else:
            time+=q
            d.append([p,t-q])

if __name__ == '__main__':
    main()




Measured memory_bytes: 13300
#include<bits/stdc++.h>
using namespace std;
const int nax = 1e5*2;
using ll = long long;
ll max_self(ll &a, ll b){
    a = max(a,b);
    return a;
}
void flower(vector<int>&a, vector<int>&h){
  ll answere = 0;
  int n = h.size();
  ll dp[n+1];
  // making the segment tree and then storing the beauty value of each range within the non leaf node.
  int base = 1;
  while(base <= n){
      base *= 2;
  }// base is the value mutiple of 2 which is just greater than name
  // the size of the array should be equal to the 4*n;
  vector<ll>tree(2*base);
  memset(dp, -1, sizeof(dp));
  // max of dp[i] in range of [0, h[i]-1]
  for(int k=0; k<n; k++){
      
      
    int x = h[k] + base; // the way to go from down to upwards
    ll best = 0;
    while(x>1){
        if(x%2 == 1){
            max_self(best, tree[x-1]);
        }
        x /=2;
    }
    dp[h[k]] = best + a[k];
    for(int i=base+h[k]; i>= 1; i /=2){
        max_self(tree[i], dp[h[k]]);
    }
    
    //for(int i=0; i<k; i++){
    //  if(h[i] < h[k]){
	//dp[k] = max(dp[k], dp[i] + a[k]);
     // }
    }
    for(int i=0; i<=n; i++){
        answere = max_self(answere, dp[i]);
    }
  cout << answere << endl;
}

int main(){
  int n;
  cin >> n;
  vector<int>h(n);
  vector<int>a(n);
  for(int i=0; i<n; i++){
    cin >> h[i];
  }
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  flower(a, h);
  return 0;
}


Measured memory_bytes: 7424
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>
#define llint long long 
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

llint n;
llint a[55];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	llint ans = 0;
	while(1){
		llint mx = -1, mx_i;
		for(int i = 1; i <= n; i++){
			if(mx < a[i]){
				mx = a[i];
				mx_i = i;
			}
		}
		if(mx < n) break;
		
		llint q = a[mx_i] / n;
		a[mx_i] %= n;
		for(int i = 1; i <= n; i++){
			if(i == mx_i) continue;
			a[i] += q;
		}
		ans += q;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()
res = 0
for i in range(1,N+1):
    if len(str(i))%2: res += 1
print(res)


Measured memory_bytes: 3064
def bubblesort(c, n):
    for i in range(0, n):
        for j in range(n-1, i, -1):
            if int(c[j][1]) < int(c[j-1][1]):
                c[j], c[j-1] = c[j-1], c[j]

    return c


def selectionsort(c, n):
    for i in range(0, n):
        min_j = i
        for j in range(i, n):
            if int(c[j][1]) < int(c[min_j][1]):
                min_j = j

        c[i], c[min_j] = c[min_j], c[i]

    return c


n = int(input())
c_to_bubble = list(map(str, input().split()))
c_to_selection = c_to_bubble.copy()

bubblesorted = bubblesort(c_to_bubble, n)
selectionsorted = selectionsort(c_to_selection, n)

print(' '.join(bubblesorted))
print('Stable')
print(' '.join(selectionsorted))
if bubblesorted == selectionsorted:
    print('Stable')
else:
    print('Not stable')






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

int main(){
  string w;
  string t;
  cin >> w;
  
  for(int i = 0;i < w.size(); i++) {
    if('A' <= w[i] && w[i] <= 'Z') w[i] += 'a'-'A';
  }
  int count = 0;
  cin >> t;
  while(t != "END_OF_TEXT"){
    for(int i = 0;i < t.size(); i++) {
      if('A' <= t[i] && t[i] <= 'Z') t[i] += 'a'-'A';
    }
    if(w == t) count++;
    cin >> t;
  }
  cout << count << endl;
  return 0;
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  vector<int> p(n);
  int sum=0;
  rep(i,n){
    cin>>p[i];
    sum+=p[i];
  }

  int sa=9999999;
  int ans;
  for(int i=n-1;i>=0;i--){
    if(sa>=abs(n*p[i]-sum)) ans=i;
    chmin(sa,abs(n*p[i]-sum));
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(int i=0; i<n; i++)
#define loop(i, j, n) for(int i=j; i<n; i++)
using namespace std;
// }}} End Header

int main()
{
	double r;
	cin >> r;
	double PI=3.14159265358979323846;
	printf("%.20f", 2*r*PI);
	return 0;
}

Measured memory_bytes: 3784
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

int main(){
    int A,B;
    cin>>A>>B;
    if(A>12){
        cout<<B<<endl;
        return 0;
    }
    if(A<6){
        cout<<0<<endl;
        return 0;
    }
    else cout<<B/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

// auto mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
      if ((x += a.x) >= mod) x -= mod;
      return *this;
    }
    mint& operator-=(const mint a) {
      if ((x += mod-a.x) >= mod) x -= mod;
      return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
      if (!t) return 1;
      mint a = pow(t>>1);
      a *= a;
      if (t&1) a *= *this;
      return a;
    }

    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

string s;
mint dp[100100][2];

int main() {
    cin >> s;
    int slen = s.length();
    dp[0][0] = 1;
    for(int i = 0; i < slen; ++i) {
        if(s[i] == '0') {
            // a+bのi桁目を0にする
            dp[i+1][0] += dp[i][0];
            dp[i+1][1] += dp[i][1];

            // a+bのi桁目を1にする
            // 未満でi桁目が1
            dp[i+1][1] += (dp[i][1]*2);
        }else {
            dp[i+1][1] += (dp[i][0] + dp[i][1]);

            dp[i+1][0] += (dp[i][0]*2);
            dp[i+1][1] += (dp[i][1]*2);
        }
    }

    cout << dp[slen][0]+dp[slen][1] << endl;
}

Measured memory_bytes: 5312
package main

import (
	"fmt"
)
func div(n int) int {
	count := 0
	for x := 1; x <= n; x++ {
		if n % x == 0 {
			count = count + 1
		}
	}
	return count
}

func main(){
	var n int
	fmt.Scan(&n)
	ans := 0
	for i := 1; i <= n; i+=2 {
		if div(i) == 8 {
			ans = ans + 1
		}
	} 
	fmt.Println(ans)
}

Measured memory_bytes: 512
N, A, B, C = map(int,input().split())
ans = [[0, 0, 0, -30]]
for i in range(N):
    l = int(input())
    ans = [[p[j] + l * (i == j) for j in [0, 1, 2]] + [p[3] + (i < 3) * 10] for p in ans for i in range(4)]
print(min(abs(p[0] - A) + abs(p[1] - B) + abs(p[2] - C) + p[3] for p in ans if min(p[:3]) > 0))

Measured memory_bytes: 19556
a,b,k=map(int,input().split())
ans=[]
for i in range(a,min(a+k,b+1)):
    ans.append(i)
for j in range(b,max(b-k,a-1),-1):
    if j not in ans:
        ans.append(j)
ans.sort()
for k in range(len(ans)):
  print(ans[k])



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define prec fixed << setprecision(12)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define test int t; cin >> t; while(t--)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;

void solve() {
	int n;
	cin >> n;
	vi v(n), ans(n);
	rep(i, 0, n-1) cin >> v[i];
	rep(i, 0, n-1) ans[v[i]-1] = i+1;
	rep(i, 0, n-1) cout << ans[i] << " ";
}

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

	// test
	solve();

	return 0;
}

Measured memory_bytes: 4728
arc = []

def tool(N, K):
    if N == K:
        arc.append(0)
        return True

    elif N < K:
        if K-N in arc:
            return True
        else:
            arc.append(K-N)
            return tool(K-N, K)

    else:
        if N % K in arc:
            return True
        else:
            arc.append(N % K)
            return tool(N % K, K)


def main():
    n, k = map(int, raw_input().split())
    tool(n, k)

    print min(arc)


if __name__ == '__main__':
    main()

Measured memory_bytes: 2568
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
#define LL long long
#define inf 7999999996000000001LL
using namespace std;
const int maxn=55;
struct point
{
	int id;
	LL x,y;
	friend bool operator <(point a,point b)
	{
		return a.x<b.x;
	}
}bb[maxn],cc[maxn];
int sum[maxn][maxn],aa[maxn][maxn];
bool cmp(point a,point b)
{
	return a.y<b.y;
}
bool cmp2(point a,point b)
{
	return a.id<b.id;
}
int n,m;
void initial()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>cc[i].x>>cc[i].y;
		cc[i].id=i;
		bb[i]=cc[i];
	}
	sort(cc+1,cc+n+1);
	sort(bb+1,bb+n+1);
	cc[0].x=-inf,cc[0].y=-inf;
	int tot=0;
	for(int i=1;i<=n;i++)
	{
		if(cc[i].x>cc[i-1].x)tot++;
		bb[i].x=tot;
	}
	sort(cc+1,cc+n+1,cmp);
	sort(bb+1,bb+n+1,cmp);
	tot=0;
	memset(aa,0,sizeof(aa));
	for(int i=1;i<=n;i++)
	{
		if(cc[i].y>cc[i-1].y)tot++;
		bb[i].y=tot;
	}
	for(int i=1;i<=n;i++)
	aa[bb[i].x][bb[i].y]++;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	sum[i][j]=sum[i-1][j]+sum[i][j-1]+aa[i][j]-sum[i-1][j-1];	
}
LL MAX(LL a,LL b)
{
	return a>b?a:b;
}
LL MAX(LL a,LL b,LL c,LL d)
{
	return MAX(MAX(a,b),MAX(c,d));
}
LL MIN(LL a,LL b)
{
	return a<b?a:b;
}
LL MIN(LL a,LL b,LL c,LL d)
{
	return MIN(MIN(a,b),MIN(c,d));
}
void work()
{
	LL x1,y1,x2,y2,ans=inf;
	for(int a=1;a<=n;a++)
	for(int b=1;b<=n&&b!=a;b++)
	for(int c=1;c<=n;c++)
	for(int d=1;d<=n&&d!=c;d++)
	{
		x1=MIN(bb[a].x,bb[b].x);
		x2=MAX(bb[a].x,bb[b].x);
		y1=MIN(bb[c].y,bb[d].y);
		y2=MAX(bb[c].y,bb[d].y);
		int tot=sum[x2][y2]-sum[x1-1][y2]-sum[x2][y1-1]+sum[x1-1][y1-1];
		if(tot>=m)
		{
			x1=MIN(cc[a].x,cc[b].x);
		    x2=MAX(cc[a].x,cc[b].x);
		    y1=MIN(cc[c].y,cc[d].y);
		    y2=MAX(cc[c].y,cc[d].y);
			LL ans1=(x2-x1)*(y2-y1);
			ans=MIN(ans,ans1);
		}
	}
	cout<<ans;
}
int main()
{
	//freopen("1.txt","r",stdin);
	initial();
	work();
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long

const int N=1005;
const int MOD=1e9+7;
 
int n, m;
char a[N][N];
int cache[N][N];
 
int dp(int i, int j)
{
	if(i>n || j>m)
		return 0;
	if(a[i][j]=='#')
		return 0;
	if(i==n && j==m)
		return 1;
	int &ans=cache[i][j];
	if(ans!=-1)
		return ans;
	ans=dp(i+1, j) + dp(i, j+1);
	ans%=MOD;
	return ans;
}
 
int32_t main()
{
	
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
	memset(cache, -1, sizeof(cache));
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j];	
	int ans=dp(1, 1);
	cout<<ans;
	return 0;
}


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

typedef long long ll;

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

    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = (a < k ? a : k); k -= a;
    if(k > 0) k-= b;
    if(k > 0) ans -= (c < k ? c : k); 
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <queue>
#include <math.h>
#define ll long long
#define INF 100000000000
#define N 10000000
using namespace std;

int main(void){
    int x,n;
    cin>>x>>n;
    
    int data[n];
    for (int i=0; i<n; i++){
        cin>>data[i];
    }
    
    int p,q;
    p=x;
    q=x;
    
    while(true){
        bool a=true;
        for(int i=0; i<n; i++){
            if(data[i]==p) a=false;
        }
        
        if(a) break;
        
        p++;
    }
    
    while(true){
        bool a=true;
        for(int i=0; i<n; i++){
            if(data[i]==q) a=false;
        }
        
        if(a) break;
        
        q--;
    }
    
    if(x-q<=p-x) cout<<q<<endl;
    else cout<<p<<endl;
}

Measured memory_bytes: 3628
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

double acot(double x) {
	return PI / 2 - atan(x);
}



/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	ll a, b, c;
	ll k;
	scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
	printf("%lld\n", (k % 2 ? (a - b) * -1 : a - b));

	return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <string.h>
using namespace std;

struct Node {
    char name[10];
    int time;
    int nokori;
};

struct Node  S[100000];

int N, M, NOKORI;


int head = 0, tail = 0;

void push(struct Node node) {

    S[tail] = node;
    tail++;

    if (tail > N) {
        tail = 0;
    }
}

struct Node pop(){
    struct Node p;
    p = S[head];
    head++;

    if (head > N) {
        head = 0;
    }
    return p;
}

bool isEmpty(){
    if (head == tail) return true;
    return false;
}

int main() {

    struct Node p;
    //struct Node p2;
    //struct Node p3;
    //
    //strcpy(p1.name, "hoge1");
    //p1.time = 1;
    //strcpy(p2.name, "hoge2");
    //p2.time = 2;
    //strcpy(p3.name, "hoge3");
    //p3.time = 3;
    //push(p1);
    //push(p2);
    //push(p3);
    //
    //cout << pop().name << endl;
    //cout << pop().name << endl;
    //cout << pop().name << endl;
    //

    cin >> N;
    cin >> M;
    NOKORI = M;
    int shori;
    int _nokori;
    int _nokori2=0;
    int _nokori3=0;
    int _nokori4=0;
    int time = 0;

    for (int i = 0; i < N; i++) {
        cin >> S[i].name;
        cin >> S[i].time;
        S[i].nokori = S[i].time;
        tail++;
    }

    while (!isEmpty()) {

        p = pop();

        _nokori = p.nokori;
        _nokori2 = NOKORI;
        p.nokori = p.nokori - NOKORI;

        if (_nokori >= _nokori2) time = time + _nokori2;
        else time = time + _nokori;

        if (p.nokori-NOKORI <= 0) NOKORI = M;
        else NOKORI = _nokori2;
        //cout << NOKORI << endl;
        if(p.nokori <= 0) cout << p.name << " " <<  time << endl;
        else push(p);


    }





    return 0;
}

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

int main() {
  int N, a, b, c, d;
  cin >> N;
  
  d = N % 10;
  c = ((N - d) / 10) % 10;
  b = ((N - d - c*10) / 100) % 10;
  a = (N - d - c*10 - b*100) / 1000;
  
  if (a == b && b == c){
    cout << "Yes" << endl;
  }
  
  else if (b == c && c == d){
    cout << "Yes" << endl;
  }
       
  else{
    cout << "No" << endl;
  }
}


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

int main(){
int N;
cin>>N;
int a[N];
for(int c=0;c<N;c++ ){
   cin>>a[c];
}
int b[N+1];
b[0]=-1;
int s=1;
for(int i=0;i<N;i++){
    if(a[i]!=a[i+1]){
        b[s]=i;
        s++;
    }
}
b[s]=N-1;
int p=0;
for(int j=0;j<s;j++){
    p=p+floor((b[j+1]-b[j])/2);
}
cout<<p<<endl;
}
    


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N], dp[N];
int n;
int go(int x){
	if(x==n)return 0;
	if(x==n-1)return 1;
	int y = x;
	int l1 = 1, l2 = 1;
	while(y+1<n and a[y]<=a[y+1])y++,l1++;
	int &ans = dp[x];
	if(ans>0) return ans;
	int y1 = y; y = x;
	while(y+1<n and a[y]>=a[y+1])y++, l2++;
	if(l1>=l2) ans = 1+go(y1+1);
	else ans = 1+go(y+1);
	return ans;
	
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,k,j;
	cin >> n;
	fo(i, n) cin >> a[i], dp[i] = -1;
	cout << go(0) << endl;
	return 0;
} 

Measured memory_bytes: 8960
package main

import (
	f "fmt"
)

func main() {
	var n int
	f.Scan(&n)

	var diff int
	for i := 1; ; i++ {
		diff = 1000*i - n
		if diff > 0 && diff < 1000 {
			f.Println(diff)
			break
		} else if diff == 0 {
			f.Println(0)
			break
		}
	}
}


Measured memory_bytes: 1772
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
typedef long long ll;
int main() {
	int N, M;
	cin >> N >> M;
	dsu D(N);
	for (int i = 0; i < M; ++ i) {
		int u, v;
		cin >> u >> v;
		-- u; -- v;
		D.merge(u, v);
	}
	cout << D.groups().size() - 1 << endl;
}


Measured memory_bytes: 8860