akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
using namespace std;

struct Node{
	int key;
	Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z;
	
	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;
	
	while(x != NIL){
		y = x;
		if(z->key < x->key){
			x = x->left;
		} else {
			x = x->right;
		}
	}
	z->parent = y;
	if( y == NIL){
		root = z;
	} else {
		if(z->key < y->key){
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

bool find(int k, Node *u){
	if(u == NIL) return false;
	if(u->key == k) return true;
	return (u->key > k)?find(k,u->left):find(k,u->right);
}

Node * treeMinimum(Node *x){
	while(x->left != NIL) x = x->left;
	return x;
}

Node * _find(Node *u, int k){
	while(u != NIL && k != u->key){
		if(k < u->key) u = u ->left;
		else u = u->right;
	}
	return u;
}

Node * treeSuccessor(Node * x){
	if(x->right != NIL) return treeMinimum(x->right);
	Node  *y = x->parent;
	while(y != NIL && x == y->right){
		x = y;
		y = y->parent;
	}
	return y;
}
void treeDelete(Node *z){
	Node *y;
	Node *x;
	
	if(z->left == NIL  || z->right == NIL) y = z;
	else y = treeSuccessor(z);
	
	if(y->left != NIL){
		x = y->left;
	} else {
		x = y->right;
	}
	
	if(x != NIL){
		x->parent = y->parent;
	}
	
	if(y->parent == NIL){
		root = x;
	} else {
		if(y == y->parent->left){
			y->parent->left = x;
		} else {
			y->parent->right = x;
		}
	}
	
	if(y != z){
		z->key = y->key;
	}
	
	free(y);
}

void inorder(Node *u){
	if( u == NIL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preoder(Node *u){
	if( u == NIL) return;
	printf(" %d", u->key);
	preoder(u->left);
	preoder(u->right);
}

int main(){
	int n;
	string s;
	
	cin>>n;
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++){
		// scanf("%s", s);
		cin>>s;
		if(s == "print"){
			inorder(root);
			printf("\n");
			preoder(root);
			printf("\n");
		} else if(s == "insert"){
			int x;
			scanf("%d", &x);
			insert(x);
		} else if(s == "find"){
			int k;
			scanf("%d", &k);
			printf(("%s",find(k,root)?"yes":"no"));
			printf("\n");
		} else if(s == "delete"){
			int k;
			scanf("%d", &k);
			treeDelete(_find(root,k));
		}
	}
	
	return 0;
}


Measured memory_bytes: 22076
class Calc:
    def __init__(self, max_value, mod):
        """combination(max_value, all)"""
        fact = [-1] * (max_value + 1)
        fact[0] = 1
        fact[1] = 1
        for x in range(2, max_value + 1):
            fact[x] = x * fact[x - 1] % mod

        invs = [1] * (max_value + 1)
        invs[max_value] = pow(fact[max_value], mod - 2, mod)
        for x in range(max_value - 1, 0, -1):
            invs[x] = invs[x + 1] * (x + 1) % mod

        self.fact = fact
        self.invs = invs
        self.mod = mod

    def combination(self, n, r):
        if n - r < r:
            return self.combination(n, n - r)
        if r < 0:
            return 0
        if r == 0:
            return 1
        if r == 1:
            return n
        return self.fact[n] * self.invs[r] * self.invs[n - r] % self.mod

    def factorial(self, n):
        return self.fact[n]


def main():
    MOD = 10 ** 9 + 7

    N, K = map(int, input().split())
    K = min(K, N - 1)  # K=最大空室数->N部屋空室は不可能

    calc = Calc(max_value=N * 2, mod=MOD)

    ans = 0
    for v in range(K + 1):  # 空室数
        ans = (ans + (calc.combination(N, v) * calc.combination(v + (N - v) - 1, v)) % MOD) % MOD

    print(ans)


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector <int> p(a), q(b), r(c);
    for (int i = 0; i < a; i++) cin >> p[i];
    for (int i = 0; i < b; i++) cin >> q[i];
    for (int i = 0; i < c; i++) cin >> r[i];

    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());

    for (int i = 0; i < x; i++) r.push_back(p[i]);
    for (int i = 0; i < y; i++) r.push_back(q[i]);

    ll ans = 0;
    sort(r.rbegin(), r.rend());

    for (int i = 0; i < x+y; i++) ans += r[i];

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



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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	string s;
	cin >> s;
	int n=s.length();
	for(int i=0; i<n; i++){
		if(s[i]=='?'){
			s[i]='D';
		}
	}
	cout << s << endl;
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)
#define MAX 10000000
#define MOD 1000000007


 
//Answer
 
 
int main() {

long N,M,t;
typedef pair<long,long> P;
cin>>N>>M;
vector<P> ab(M);
vector<P> ba(M);
vector<long> X(N,1);
for(long i=0;i<M;i++){
cin>>ab.at(i).first;
cin>>ab.at(i).second;
if(ab.at(i).first>ab.at(i).second){
    t=ab.at(i).first;
    ab.at(i).first=ab.at(i).second;
    ab.at(i).second=t;
}
	ba.at(i).first=ab.at(i).second;
    ba.at(i).second=ab.at(i).first;
}
sort(ab.begin(),ab.end());
sort(ba.begin(),ba.end());
queue<long> que;
long count,max=0;
for(long i=0;i<N;i++){
count=0;
que.push(i+1);
while(que.size()){
    long q=que.front();
    que.pop();
// cout<<q<<endl;
    if(X.at(q-1)==1){
        count++;
        X.at(q-1)=0;
      P pp=make_pair(q,0);
       auto itr1=lower_bound(ab.begin(),ab.end(),pp);
       auto itr2=lower_bound(ba.begin(),ba.end(),pp);
      long it=distance(ab.begin(),itr1);
      long it2=distance(ba.begin(),itr2);
   //   cout<<distance(ab.begin(),itr1)<<endl;
      while(it<M&&(q==ab.at(it).first)){
         que.push(ab.at(it).second);
            it++;
       }
      while(it2<M&&(q==ba.at(it2).first)){
         que.push(ba.at(it2).second);
            it2++;
       }
      
    }
}
if(max<count){
    max=count;
}
}
cout<<max<<endl;

}



Measured memory_bytes: 12620
#include<iostream>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
	string str;
	int page;
	map<string,vector<int>> dict;

	while(cin >> str >> page){
		dict[str].push_back(page);
	}

	for(map<string,vector<int>>::iterator it = dict.begin(); it != dict.end(); it++){
		sort(it->second.begin(), it->second.end());

		cout << it->first << endl;

		for(int i = 0; i < (int)it->second.size(); i++){
			cout << it->second[i];
			cout << ((i < (int)it->second.size()-1)?' ':'\n');
		}
	}
}

Measured memory_bytes: 1240
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define SZ(x) ((ll)(x).size())
typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}


int main(){
    int n,x;
    cin >> n >> x;
    vector<int> a(n);
    REP(i,n){
        cin >> a[i];
    }
    ll res = 0;
    int temp = max(a[0]-x,0);
    res += temp;
    a[0] -= temp;
    REP(i,n-1){
        int temp = max(a[i]+a[i+1]-x,0);
        res += temp;
        a[i+1] -= temp;
    }
    put(res);
    return 0;
}


Measured memory_bytes: 640
using System;
using System.Linq;

namespace ABC086_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var T = new int[N][];
            for (int i = 0; i < N; i++)
            {
                T[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            }

            var canGo = true;
            var x = 0;
            var y = 0;

            for (int i = 0; i < N; i++)
            {
                var nx = T[i][1];
                var ny = T[i][2];
                canGo = Math.Abs(nx - x) + Math.Abs(ny - y) <= T[i][0];
                if (!canGo) break;
                canGo = (Math.Abs(nx - x) + Math.Abs(ny - y)) % 2 == 0 && T[i][0] % 2 == 0
                    || (Math.Abs(nx - x) + Math.Abs(ny - y)) % 2 == 1 && T[i][0] % 2 == 1;
                if (!canGo) break;
            }

            Console.WriteLine(canGo ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 22460
#include <stdio.h>

int main(){
    int a,b,c,max;
    scanf("%d %d %d",&a,&b,&c);
    max=a;
    if(b>max){
        max=b;
    }

    if(c>max){
        max=c;
    }
    printf("%d",a+b+c-max);

    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<int> ds(N);
    for (int i = 0; i < N; ++i) cin >> ds[i];
    int sum = 0;
    for (int i = 0; i < N; ++i)
    {
        for (int j = i + 1; j < N; ++j)
        {
            sum += ds[i] * ds[j];
        }
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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() {
    int N;
    cin >> N;
    int H[N];
    rep(i,N) cin >> H[i];

    int ans = 0;
    int count = 0;
    rep(i,N-1) {
        if (H[i] >= H[i + 1]) {
            count++;
            ans = max(ans, count);
        } else {
            count = 0;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<stdio.h>
using namespace std;

int main(void){
    int n,k,count = 0;
    cin >> n >> k;
    int h[100000] = {0};
    for(int i = 0;i < 100000;i++){
        scanf("%d",&h[i]);
        if(h[i] >= k)count += 1;
    }
    printf("%d\n",count);
}

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

long long ans;
int a[200100], c[200100];

int main ()
{
	int n;
	cin >> n;
	for (int i=1;i<=n;i++)
	{
		cin >> a[i];
		c[a[i]]++;
	}
	
	for (int i=1;i<=n;i++) ans+=1ll*c[i]*(c[i]-1)/2;
	
	for (int i=1;i<=n;i++)
	{
		cout << ans-c[a[i]]+1 << endl;
	} 
	return 0;
}

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

struct process {
    char name[10];
    int time;
};


void out (struct process a, int t)
{
    for (int i = 0; i < strlen(a.name); i++)
        printf("%c", a.name[i]);
    printf(" %d\n", t);
}

void scheduling(struct process a[], int n, int qms)
{
    int head = 0; int tail = n-1;
    int t_sum = 0;
    while (head != tail ){
        if (a[head].time <= qms){
            t_sum += a[head].time;
            out(a[head], t_sum);
            if (head == n-1)
                head = 0;
            else
                head++;
            }
        else{
            a[head].time -= qms;
            t_sum += qms;
            struct process tmp = a[head];
            if (head == n-1)
                head = 0;
            else
                head++;
            if (tail == n-1)
                tail = 0;
            else
                tail++;
            a[tail] = tmp;
        }
    }
    out(a[head], t_sum + a[head].time);
}

int main()
{
    struct process a[100000];
    int i, n, qms;

    scanf("%d", &n);
    scanf("%d", &qms);

    for (i = 0; i < n; i++){
        scanf("%s", a[i].name);
        scanf("%d", &a[i].time);
    }
    scheduling(a, n, qms);
}


Measured memory_bytes: 3372
#include <cmath>
#include <iostream>
using namespace std;
 
double distance(double x[], double y[], int size, int p) {
  int i;
  double res = 0, t;
 
  if (p == -1) {
    for (i = 0; i < size; i++) {
      t = abs(x[i] - y[i]);
      if (t > res) {
        res = t;
      }
    }
 
    return res;
  }
 
  for (i = 0; i < size; i++) {
    res += pow(abs(x[i] - y[i]), p);
  }
 
  return pow(res, 1.0 / p);
}
 
int main() {
  double x[100], y[100];
  int n, i;
 
  cin >> n;
 
  for (i = 0; i < n; i++) {
    cin >> x[i];
  }
 
  for (i = 0; i < n; i++) {
    cin >> y[i];
  }
 
  cout << fixed << distance(x, y, n, 1) << endl;
  cout << fixed << distance(x, y, n, 2) << endl;
  cout << fixed << distance(x, y, n, 3) << endl;
  cout << fixed << distance(x, y, n, -1) << endl;
 
  return 0;
}

Measured memory_bytes: 1344
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
int main() {
	int N;
	cin >> N;
	string S = to_string(N);
	int sum = 0;
	for (int i = 0; i < S.size(); i++) sum += S[i] - '0';
	if (N%sum == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <stdio.h>

#define mmod 1000000007

// f[2*n]=3*f[n];
//f[2*n+1]=2*f[n]+f[n+1];


int main()
{
    char st[100010];
    scanf("%s",st);

    long long ans0=0,ans1=1;

    if (st[0]=='1'){
        ans0=1;ans1=3;
    }

    for (int i=1;st[i];i++)
    {
        if (st[i]=='0')
        {
            ans1=2*ans0%mmod + ans1%mmod;ans1%=mmod;
            ans0*=3;ans0%=mmod;
        }
        else
        {
            long long tmp=3*ans1%mmod;
            ans0 = 2*ans0%mmod+ans1%mmod;ans1=mmod;
            ans1 = tmp;
        }
    }
    printf("%lld\n",ans1);


}


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


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

int main() {
  ll n;
  cin >> n;
  ll ans;
  cin >> ans;
  for(int i=0;i<n-1;i++) {
    ll temp;
    cin >> temp;
    ans=max(ans,temp)/gcd(ans,temp)*min(ans,temp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <functional>
#include <array>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getrnd(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}

template <typename T1, typename T2> inline bool relax(T1& a, const T2& b) {
    return a > b ? a = b, true : false;
}

template <typename T1, typename T2> inline bool strain(T1& a, const T2& b) {
    return a < b ? a = b, true : false;
}

// :::::::::::::::::::::::::::::::

void solve() {
    int n;
    cin >> n;
    
    vector<pair<ll, ll>> p;
    for (int i = 0; i < n; ++i) {
        ll x, y;
        cin >> x >> y;
        
        p.emplace_back(x, y);
    }
    sort(p.begin(), p.end());
    
    
    ll mnd = 2e13, mns = 2e13, ans = 0;
    for (auto [x, y] : p) {
        strain(ans, max(x + y - mns, x - y - mnd));
        relax(mns, x + y);
        relax(mnd, x - y);
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));
    
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    
    return 0;
}


Measured memory_bytes: 7464
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int sum = 0;
        for(int i=0; i<k; i++) {
            sum+=a[i];
        }
        System.out.println(sum);
    }


}

Measured memory_bytes: 38748
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>

#define roop(i, n) for(int i=0;i<n;i++)
#define DIV 1000000007

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

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

ll combination(ll n, ll r) {
	if (n < 0 || r < 0 || r > n) return -1;

	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> num(r);
	vector<ll> den(r);

	for (ll i = 0; i < r; i++) {
		num[i] = n - r + i + 1;
		den[i] = i + 1;
	}

	for (ll p = 2; p <= r; p++) {
		ll pivot = den[p - 1];
		if (pivot > 1) {
			ll offset = (n - r) % p;
			for (ll k = p - 1; k < r; k += p) {
				num[k - offset] /= pivot;
				den[k] /= pivot;
			}
		}
	}
	ll result = 1;
	for (ll k = 0; k < r; k++) {
		if (num[k] > 1) result *= num[k];
	}
	return result;
}

vector<string> split(const string& src, const char* delim = ",") {
	vector<string> vec;
	string::size_type len = src.length();

	for (string::size_type i = 0, n; i < len; i = n + 1) {
		n = src.find_first_of(delim, i);
		if (n == string::npos) {
			n = len;
		}
		vec.push_back(src.substr(i, n - i));
	}

	return vec;
}

int main() {
	ll n, m;
	cin >> n >> m;
	if (m < n) {
		ll tmp = n;
		n = m;
		m = tmp;
	}
	if (n == 1) {
		if (m == 1) {
			cout << 1 << endl;
		} else {
			cout << m - 2 << endl;
		}
	} else {
		cout << (n - 2) * (m - 2) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

H,W = LI()
N = I()
a = LI()

c = [[0]*W for _ in range(H)]
now = 0
for i in range(H):
    if i%2 == 0:
        for j in range(W):
            c[i][j] = now + 1
            a[now] -= 1
            if a[now] == 0:
                now += 1
    else:
        for j in range(W)[::-1]:
            c[i][j] = now + 1
            a[now] -= 1
            if a[now] == 0:
                now += 1

for i in range(H):
    print(*c[i])

Measured memory_bytes: 42096
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv vector<int>
#define endl "\n"
#define test(i) cout<<i<<endl
#define tests(i) cout<<"i: "<<i<<endl;
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())
void file(){
    #ifdef LOCAL
    freopen("demo.in","r",stdin);
    freopen("demo.out","w",stdout);
    #endif
}
bool sortdes(const pair<int,int> &a, const pair<int,int> &b){return a.ss<b.ss;}
bool sortasc(const pair<int,int> &a, const pair<int,int> &b){return a.ss>b.ss;} 
int gcd(int x,int y){return __gcd(x,y);}
// lld fact(lld n);
// lld nCr(lld n,lld r){return fact(n) / (fact(r) * fact(n - r));}
// lld fact(lld n){ lld res = 1; for(lld i = 2; i <= n; i++){res = res * i;}return res;} 
// const int maxi = 1e6+10;
// vector<int> v[maxi];
// long long a[maxi];
// void dfs(int x,int y){
//     a[x]+=a[y];
//     for(int i:v[x]){
//         if(i!=y){
//             dfs(i,x);
//         }
//     }
// }

void test_case(){
    int n;
    cin>>n;
    if(n<=999){
        cout<<"ABC";
        return;
    }
    if(n>999 && n<=1998){
        cout<<"ABD";
        return;
    }
}

int main(){
    fastio;
    file();
    int T=1;
    // int T;
    // cin>>T;
    for(int nr=1;nr<=T;++nr) {
        // cout<<"Case #"<<nr<<": ";
		test_case();
    }
}

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

int main(){
    int H,A;
    cin >> H >> A;
    
    int ans = 0;
    rep(i,10001){
        if(H - i*A <= 0){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}


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

int main() {
    string S;
    cin >> S;
    int ans = 0, n = S.size();
    rep(i, n) {
        ans++;
        if (S[i] == S[i + 1]) {
            i += 2;
            if (i < n) ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
S = list(map(int, list(input())))
for pattern in range(1 << 3):
    this_sum = S[0]
    for i in [1, 2, 3]:
        if pattern & 1 << i-1:
            this_sum += S[i]
        else:
            this_sum -= S[i]
    if this_sum == 7:
        break
output = str(S[0]) + "".join(["-+"[bool(pattern & 1 << i-1)] + str(S[i]) for i in [1, 2, 3]]) + "=7"
print(output)

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

using namespace std;
using ll = long long;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    
    ll x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    
    ll c = min(x/d,k);
    
    x -= c * d;
    
    if ((k - c) & 1) 
      x -= d;
    
    cout << abs(x);
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
        int D = sc.nextInt();
        
        int train = Math.min(A,B);
        int bus = Math.min(C,D);
        
        System.out.println(train+bus);

    }
}

Measured memory_bytes: 21844
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (S == T && (T = (S = B) + fread(B, 1, 1 << 15, stdin), S == T) ? EOF : *S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char B[1 << 15], *S = B, *T = B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
#define maxn 110
int n;
char a[maxn], b[maxn];
int main()
{
//	setfile();
	scanf("%d", &n);
	scanf("%s%s", a + 1, b + 1);
	for (R int i = 1; i <= n; ++i)
	{
		R bool check = 1;
		for (R int j = i, k = 1; j <= n && check; ++j, ++k)
			if (a[j] != b[k]) check = 0;
		if (check) return !printf("%d\n", i + n - 1 );
	}
	printf("%d\n", n * 2 );
	return 0;
}


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

const double eps = 1e-9;

int main() {
  int n;
  double p,q,r,s;
  cin>>n;

  while(n--) {
    cin>>p>>q>>r>>s;
    double a = q/p,b = r/p,c = s/p;
    double d = a,e = b,alpha = 0.0;
    if(abs(c) > eps) {
      double low = -1000000000,hi = 1000000000;
      for(int i=0; i<200; ++i) {
    double mid = (low+hi)/2.0;
    if(mid*mid*mid+a*mid*mid+b*mid+c < 0) low = mid;
    else hi = mid;
      }
      alpha = low;
      d = a+alpha, e = -c/alpha;
    }

    double han = d*d - 4.0*e;
    double s1 = 0.0,s2 = 0.0;
    if(han > -eps) {
      if(han < 0.0) han = 0.0;
      s1 = 0.5*(-d + sqrt(han));
      s2 = 0.5*(-d - sqrt(han));
    }
    //cout<<alpha<<" "<<s1<<" "<<s2<<" "<<d<<" "<<e<<" "<<han<<endl;
    int ps = 0, ns = 0;
    if(alpha > eps) ps++;
    if(alpha < -eps) ns++;
    if(s1 > eps) ps++;
    if(s1 < -eps) ns++;
    if(s2 > eps) ps++;
    if(s2 < -eps) ns++;
    cout<<ps<<" "<<ns<<endl;
  }
}

Measured memory_bytes: 0
import sys

n = int(input())

number_list = list(map(int, input().split()))

ans = 'Yes'

if n == 1:
    ans = 'Yes'

else:
    for i in range(n-1):
        if number_list[-(i+2)] <= number_list[-(i+1)]:
            pass
        elif number_list[-(i+2)] - 1 <= number_list[-(i+1)]:
            number_list[-(i+2)] = number_list[-(i+2)] - 1
        else:
            ans = 'No'
            break
            
    

print(ans)


Measured memory_bytes: 14224
#include <stdio.h>
#include <string.h>

int main(void){
    char t[101],h[101];
    int i,n,ts=0,hs=0;

    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%s %s",&t,&h);
        if(strcmp(t,h)>0) ts+=3;
        else if(strcmp(t,h)==0){
            ts++; hs++;
        }
        else hs+=3;
        getchar();
    }

    printf("%d %d\n",ts,hs);

    return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
#define inf 1e9+5;
# define ll long long
using namespace std;
int main(){
   ll n;
   cin>>n;
   vector<ll>a(n),b(n),c(n);
   for(int i=0;i<n;i++)
   {
     cin>>a[i];
     cin>>b[i];
     cin>>c[i];

    }
    int dp[n][3];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            dp[i][j]=-inf;
        }
    }
 
     dp[0][0]=a[0];
     dp[0][1]=b[0];
     dp[0][2]=c[0];
    for(int i=1;i<n;i++)
     {
      dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
      dp[i][1]=b[i]+max(dp[i-1][2],dp[i-1][0]);
      dp[i][2]=c[i]+max(dp[i-1][1],dp[i-1][0]);
          



    }       
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<"\n";
    // for(int i=0;i<n;i++){
    //     for(int j=0;j<3;j++)
    //     cout<<dp[i][j]<<" ";
    //     cout<<"\n";
    // }

                                                                                 //dp[i][0]   for swimming
                                                                                 //dp[i][1]     for bug finding
                                                                                 //dp[i][2]      for hw;
            
      
   
   
   }

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

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

const ll INF = 10000000000000000;

int main() {
  int n; ll w;
  cin >> n >> w;
  vector<ll> weight(110,0);
  vector<ll> value(110,0);
  rep(i,0,n) cin >> weight[i] >> value[i];
  vector<vector<ll>> dp(110, vector<ll>(100100,INF));
  dp[0][0] = 0;
  rep(i,0,n) rep(sum_v,0,100101) {
    if (sum_v - value[i] >= 0) {
      chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);
    }
    chmin(dp[i+1][sum_v], dp[i][sum_v]);
  }
  ll ans;
  rep(sum_v,0,100100) {
    if (dp[n][sum_v] <= w) ans = sum_v;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 90344
import numpy as np
n,m,c=map(int,input().split())
b=np.array(list(map(int,input().split())))
ans=0
cnt=0
for i in range(0,n):
  a=np.array(list(map(int,input().split())))
  x=a*b
  
  for j in range(0,m):
    cnt+=x[j]
  cnt+=c  
  
  if cnt>0:
    ans+=1
    
  cnt=0  
    
print(ans)    
    
  
  




Measured memory_bytes: 12580
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;
typedef long long LL;
LL i,j,k,n,m;
LL mod=1000000007;
string s;

int main() {
  cin >> n >> k;
  map<int, int> mp;
  for (i=0;i<n;++i) {
    int t; cin >> t;
    if (mp.find(t) != mp.end()) {
      mp[t] +=1;
    } else {
      mp[t] =1;
    }
  }
  vector<pair<int, int>> v;
  for (auto const& ele: mp) {
    v.push_back(make_pair(ele.first,ele.second));
  }
  sort(v.begin(), v.end(), [](const pair<int, int>& a,const pair<int, int>& b){return a.second < b.second;});
  int cnt =0;
  if (v.size() > k){
  	for (j=0;j<v.size() - k; ++j) cnt += v[j].second;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 11768
#include<stdio.h>
int main()
{
     int A,B,x;

        scanf("%d %d",&A ,&B);
        {
            x = (A+B);
            if(x%2==0)
            {

                printf("%d\n",x/2);
            }
            else if(x%2!=0)
            {
                printf("%d\n",(x/2)+1);
            }
            }
        return 0;
    }


Measured memory_bytes: 128
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
	    FastScanner sc = new FastScanner(System.in);
	    PrintWriter pw = new PrintWriter(System.out);
		int n = sc.nextInt(), q = sc.nextInt(), c = 0;
		char[] s = sc.next().toCharArray();
		int[] count = new int[n];
		for (int i = 1; i < n; i++) {
			if (s[i-1] == 'A' && s[i] == 'C') {
				c++;
			}
			count[i] = c;
		}

		for (int i = 0; i < q; i++) {
			int start = sc.nextInt(), end = sc.nextInt();
			pw.println(count[end -1] - count[start -1]);
		}
		pw.close();
		sc.close();
	}
}

class FastScanner implements Closeable {
	private final InputStream in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	public FastScanner(InputStream in) {
		this.in = in;
	}
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}else{
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
	public String next() {
		if (!hasNext()) throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while(isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	public long nextLong() {
		if (!hasNext()) throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			}else if(b == -1 || !isPrintableChar(b)){
				return minus ? -n : n;
			}else{
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) nl;
	}
	public double nextDouble() { return Double.parseDouble(next());}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
	}
}


Measured memory_bytes: 31948
#include <iostream>
#include <cmath>
#include <vector>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long int ll;

int main(){
    /*input*/
    int n;  cin >> n;
    /*calculation*/
    int sqr = (int)sqrt(n);
    /*output*/
    cout << sqr*sqr << endl;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

N = INT()
lim = [INT() for _ in range(5)]

print(-(-N//min(lim))+4)

Measured memory_bytes: 5200
#include <stdio.h>

int main(void)
{
  int N,i;
  long int sum = 0;
    
  do{
    scanf("%d",&N);
  } while(N<1 || N>1000000);
  
  for(i=1;i<=N;i++){
    if(i % 3 != 0 && i % 5 != 0)
      sum += i;
  }
  printf("%ld\n",sum);
  
  return 0;
} 

Measured memory_bytes: 1688
#include <iostream>
#include <vector>

using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
typedef long long ll;

int main() {
    int N;
    cin >> N;
    int As[N],Bs[N],Cs[N-1];
    // input form
    REP(i,N) {
        cin >> As[i];
    }
    REP(i,N) {
        cin >> Bs[i];
    }
    REP(i,N-1) {
        cin >> Cs[i];
    }

    int beforeEatNum = -1;
    int manzokuSum = 0;
    REP(i,N) {
        if (beforeEatNum != -1) {
            int EatNum = As[i];
            // cout << "takahashi eat:"<< EatNum << endl;
            if (beforeEatNum+1 == EatNum) {
                // cout << "get bonus" << endl;
                manzokuSum += Cs[EatNum-2];
            }
        }
        manzokuSum += Bs[As[i]-1];
        // cout << "manzoku" << manzokuSum << endl;
        beforeEatNum = As[i];

    }

    cout << manzokuSum << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
a_list = input().split(" ")
A_list = list(map(int,a_list))
A_list.insert(0,0)

sum_len = 0
for i in range(N):
	sum_len += abs(A_list[i]-A_list[i+1])

sum_len += abs(A_list[N])

for j in range(1,N+1):
	if(j != N):
		length = sum_len - (abs(A_list[j-1]-A_list[j])+abs(A_list[j]-A_list[j+1]))
		length += abs(A_list[j-1]-A_list[j+1])
		print(length)
	elif(j == N):
		length = sum_len - abs(A_list[j-1]-A_list[j]) - abs(A_list[j])
		length += abs(A_list[j-1])
		print(length)

Measured memory_bytes: 15100
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 62
char Fix(int t)
{
	if (t < 10)
		return '0' + t;
	t -= 10;
	if (t < 26)
		return 'a' + t;
	t -= 26;
	return 'A' + t;
}
string s[N];
int sum = N, tim;
int Query(string s)
{
	if (s.length() > 128)
		return 0x3f3f3f3f;
	++tim;
	if (tim >= 850)
		while (1);
			cout << "?" << " " << s << endl;
	fflush(stdout);
	int ans = 0;
	cin >> ans;
	return ans;
}
int len = 0x3f3f3f3f, q[N];
string Merge(string a, string b)
{
	int i = 0, j = 0;
	int la = a.length(), lb = b.length();
	string ret = string();
	while (i < la && j < lb)
	{
		string qr = ret;
		qr += a[i];
		for (int k = j; k < lb; k++)
			qr += b[k];
		if (Query(qr) + qr.length() == len)
			ret += a[i++];
		else
			ret += b[j++];
	}
	while (i < la)
		ret += a[i++];
	while (j < lb)
		ret += b[j++];
	return ret;
}
int main()
{
	for (int i = 0; i < N; i++)
	{
		s[i] += Fix(i);
		q[i] = Query(s[i]) + 1;
		len = min(len, q[i]);
	}
	for (int i = 0; i < N; i++)
	{
		if (q[i] == len)
			while (Query(s[i] + Fix(i)) + s[i].length() + 1 == len)
				s[i] += Fix(i);
		else
			s[i] = string();
	}
	while (1)
	{
		for (int i = 0; i < N; i++)
			for (int j = i + 1; j < N; j++)
				if (s[i].length() > s[j].length())
					swap(s[i], s[j]);
		int t = 0;
		while (!s[t].length())t++;
		if (t + 1 == N)
			break;
		string now = Merge(s[t], s[t + 1]);
		s[t + 1] = now;
		s[t] = string();
	}
	cout << "! "<< s[N - 1] << endl;
	fflush(stdout);
}


Measured memory_bytes: 3776
N = int(input())
count = 0
flag = 0
for i in range(N):
  D_1, D_2 = map(int,input().split())
  if D_1 == D_2:
    count += 1
  else:
    count = 0
  if count == 3:
    flag = 1
    break
if flag:
  print('Yes')
else:
  print('No')

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

const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int dp[100010][3];

int main()
{
    int n;
    cin >> n;
    int a[n][3];
    for(int i = 0; i < n; i++) for(int j = 0; j < 3; j++) cin >> a[i][j];
    for(int i = 0; i <= n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(j == k) continue;
                dp[i+1][k] = max(dp[i+1][k],dp[i][j]+a[i][k]);
            }
        }
    }
    cout << *max_element(dp[n],dp[n]+3) << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ull;
typedef long long int ll;
typedef pair<ll, ll> P;

int main()
{
    int a;
    cin >> a;
    cout << a + a*a + a*a*a << endl;
    
}

Measured memory_bytes: 3588
/**
 *  Author : Coda
 *  Title : OSU!
 *  Date : 2019-08-20
 */
#include <bits/stdc++.h>
using namespace std ;

typedef long long ll ;
typedef unsigned long long ull ;
typedef double DB ;
const long long mod = 1e9+7 ;
const double pi = acos(-1) ;
#define PB push_back
#define MP make_pair
#define lb lower_bound
#define ub upper_bound
#define fs first
#define sd second
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define debug(x) cout << #x << " = " << x << endl
#define debug2(x,y) cout << #x << " = " << x << ' ' << #y << " = " << y << endl
#define debug3(x,y,z) cout << #x << " = " << x << ' ' << #y << " = " << y << ' ' << #z << " = " << z << endl
//#pragma comment(linker,"/STACK:10240000,10240000")
//#include <random>
//mt19937 rand_(time(0));
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll qpow(ll a,ll b,ll c){ll t=1;while(b){if(b&1)t=t*a%c;a=a*a%c;b>>=1;}return t;}
ll inv(ll x){return qpow(x,mod-2,mod);}
int test = 1 ;

const int maxn = 5 + 3e5 ;
const int maxm = 5 + 1e6 ;
// Write the variables here

int N,W ;
ll v[maxn],w[maxn] ;
ll dp[maxn] ;

//#define TEST
int main(){
#ifdef TEST
    freopen("in.txt","r",stdin) ;
#endif
    while(test--){
        // code begins
        scanf("%d%d",&N,&W) ;
        for(int i=1 ; i<=N ; i++){
            scanf("%lld%lld",&w[i],&v[i]) ;
        }
        ll ans = 0 ;
        for(int i=1 ; i<=N ; i++){
            for(int j=W ; j>=w[i] ; j--){
                dp[j] = max(dp[j],dp[j-w[i]]+v[i]) ;
                ans = max(ans,dp[j]) ;
            }
        }

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

    }
#ifdef TEST
    cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
#endif
    return 0 ;
}


Measured memory_bytes: 5120
#include <cmath>
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
char map[55][55];
int dist[55][55];
int dx[8] = { 1,-1,0,0,-1,-1,1,1 };
int dy[8] = { 0,0,1,-1 ,-1,1,-1,1};
int h, w;
int dfs(P p) {
	queue<P>que;
	que.push(p);
	int count = 0;
	
	int nowx = que.front().second;
	int nowy = que.front().first;
	
		for (int k = 0; k < 8; k++) {
			int nextx = nowx + dx[k];
			int nexty = nowy + dy[k];
			if (nextx >= 0 && nextx < w && nexty >= 0 && nexty < h && map[nexty][nextx] == '#' ) {
				count++;
			}
		}
	return count;
}

int main() {
	
	cin >> h >> w;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> map[i][j];
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			dist[i][j] = inf;
		}
	}
	

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (map[i][j] == '.') {
				dist[i][j] = dfs(make_pair(i, j));
			}
		}
	}

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (j % w == 0)cout << endl;
			if (dist[i][j] == inf) {
				cout << "#";
			}
			else {
				cout << dist[i][j];
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
/**************************************************
 * Atcoder problems
 * Contest No :087
 * Problem No :B
 * File Name  :program.cs
 * Create date:2020/06/07
 *
 * Copyright 2020 Shunichi Sato,All Rights Reserved.
**************************************************/
//memo terinal command
//compile:mcs program.cs
//excute :mono program.exe
using System;
class Program
{
    static void Main(string[] args)
    {
        int mountA = 500;
        int mountB = 100;
        int mountC = 50;
        // 個数の入力
        int a = int.Parse(Console.ReadLine());//500yen
        int b = int.Parse(Console.ReadLine());//100yen
        int c = int.Parse(Console.ReadLine());//50yen
        int x = int.Parse(Console.ReadLine());//total
        int output = 0;
        // 判定
        for (int A = 0; A <= a;A++)
        {
            for(int B = 0; B <= b; B++)
            {
                for (int C = 0; C <= c; C++)
                {
                    int total = mountA * A + mountB * B + mountC * C;
                    if (total == x)
                    {
                        output++;
                    }
                }
            }
        }
        //出力
        Console.WriteLine(output);
    }
}


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

int main() {
int a,b;
cin >> a >> b;
 int xxx=a*b;
 if(xxx%2==0){
   cout<<"Even"<<endl;
 }else{
   cout<<"Odd"<<endl;
 }
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, A, B, C, D;
string S;
int main(){


    cin >> N >> A >> B>> C >> D;
    A--; B--; C--; D--;
    cin >> S;
    
    bool sn_ok = true;
    bool fn_ok = true;
    for(int i = A; i < C; i++){
        if(S[i] == '#' && S[i+1] == '#'){
            sn_ok = false;
        }
    }
    for(int i = B; i < D; i++){
        if(S[i] == '#' && S[i+1] == '#'){
            fn_ok = false;
        }
    }

    string yes = "Yes";
    string no = "No";

    if(C < D){
        if(sn_ok && fn_ok){
            cout << yes << endl;
        }
        else{
            cout << no << endl;
        }
    }
    else{
        if(sn_ok && fn_ok){
            bool ok = false;
            // B + 1からはじめて、D+1までの
            for(int i = B - 1; i < D; i++){
                if((S[i] == '.' && S[i+1] == '.' && S[i+2] == '.')){
                    ok = true;
                }
            }
            if(ok){
                cout << yes << endl;
            }
            else{
                // cout << "ok"<<endl;
                cout << no  << endl;
            }
        }
        else{
            cout << no << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 640
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
AB = [lr() for _ in range(M)]
V = [x for x in range(N+1)]
total = N * (N-1) // 2

def find(A, x):
    parent = A[x]
    if parent == x: return x
    root = find(A, parent)
    A[x] = root
    return root

def union(A, x, y):
    root, second = find(A, x), find(A, y)
    if root > second:
        second, root = root, second
    A[second] = root

def merge(A, x, y):
    root_A = find(A, a); root_B = find(A, b)
    if root_A == root_B:
        return 0
    ret = group[root_A] * group[root_B]
    new_group = group[root_A] + group[root_B]
    group[root_A] = group[root_B] = new_group
    union(A, a, b)
    return ret

conv = 0
answer = []
group = [1] * (N+1)
for a, b in AB[::-1]:
    answer.append(total - conv)
    conv += merge(V, a, b)

for x in answer[::-1]:
    print(x)


Measured memory_bytes: 38108
s=list(input())
t=list(input())
m=len(t)
for i in range(len(s)-len(t)+1):
    ma=len(t)
    for j in range(len(t)):
        if s[i+j]==t[j]:
            ma-=1
    if ma <m:
        m=ma
print(m)

Measured memory_bytes: 9008
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
#define endl "\n"
#define vvi vector<vector<int> >
#define vvl vector<vector<long long> >
ll mod = 1e9 + 7;
//const double pi = acos(-1.0);
/*
ll kmp(string x)
{
    ll n= x.length();
    //cout<<x<<endl;
    vector<ll> lcp(x.length(), 0);
    for(ll i=1;i<n;i++)
    {
        ll j=lcp[i-1];
        while(j>0 && x[j]!=x[i])
            j=lcp[j-1];
        if(x[i]==x[j])
            j++;
        lcp[i]=j;
    }
    return lcp[n-1];
}

int N = 1000002;
int ar[100002];
void sieve()
{
    for(int i=1;i<=N;i++)
        ar[i] = 1;
    ar[0] = 0;
    for(int i=2;i*i<=N;i++)
    {
        if(ar[i] && i*i<=N)
        {
            for(int j = i*i; j<=N;j+=i)
                ar[j] = 0;
        }
    }
}

ll modex(ll a,ll b){
    if(b<=0){
        return 1;
    }
    if(b%2==0)
    {
        ll x = modex(a, b/2);
        return ((x*x)%mod);
    }
    else
        return ((a%mod * modex(a, b-1))%mod);
}

ll c[1010][1010];

ll combina(ll i, ll j){
        for (int i=0;i<=1005;i++)
        for (int j=0;j<=i;j++)
        {
            if (j==i||j==0)
                c[i][j]=1;
            else
            c[i][j]=c[i-1][j-1]+c[i-1][j];
            c[i][j]%=mod;
        }
        return c[i][j];
}
void find_fac(int x){
    vector<ll> di;
    for(ll i = 2; i*i <= x; i++)
    {
        if(x%i==0){
            di.push_back(i);
            while(x%i==0)
                x/=i;
        }
    }
    if(x > 1)
        di.push_back(x);
}
*/


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout.precision(12);
    string s, t;
    cin>>s>>t;
    int an = INT_MAX;
    for(int i=0;i<=s.length()-t.length();i++){
        int c = 0;
        //cout<<i<<" ";
        for(int j=0;j<t.length();j++){
            //cout<<j<<" ";
            if(s[i+j]==t[j])
                c++;
        }
        cout<<endl;
        an = min(an, (int)t.length()-c);
    }
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 3636
line = gets.split(' ').map(&:to_i)
 
n = line[0]
x = line[1]
y = line[2]
 
def min(x,y)
  if x < y then
    return x
  else
    return y
  end
end
  
def abs(x,y)
  if x < y then
    return y - x
  else
    return x - y
  end
end
  
dist_freq = []
for i in 1..n-1
  dist_freq[i] = 0
end
 
for i in 1..n
  for j in (i+1)..n
    dis1 = j - i
    dis2 = abs(x,i) + 1 + abs(y,j)
    dist_freq[min(dis1,dis2)] += 1
  end
end
 
for i in 1..n-1
  puts dist_freq[i]
end

Measured memory_bytes: 1788