akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

ll w,h,ans;
vector<vector<char>> t;
void dfs(ll x, ll y){
  if(value(x,y,w,h)){
    if( t[x][y] != '.' ) return ;
    ++ans;
    t[x][y] = '0';
    rep(i,4){
      dfs(x+dx[i],y+dy[i]);
    }
  }
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(cin >> w >> h && w && h){
    ll x,y;
    t = vector<vector<char>>(20,vector<char>(20,' '));
    ans = 0;
    rep(i,h){
      rep(j,w){
        cin >> t[j][i];
        if(t[j][i] == '@'){
          x = j;
          y = i;
        }
      }
    }
    t[x][y] = '.';
    dfs(x,y);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3136
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int a, b, c;
set<int> s;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> a >> b >> c;
    s.insert(a);
    s.insert(b);
    s.insert(c);
    if (SZ(s) == 2) cout << "Yes";
    else cout << "No";
    return 0;
}


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

string s;

void read() {
    int dummy;
    cin >> dummy >> s;
}


void work() {
    int cnt = 0;
    for (int i = 0; i + 2 < s.size(); ++i) {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C') {
            ++cnt;
        }
    }
    cout << cnt << endl;
}


int main() {
    read();
    work();
    return 0;
}


Measured memory_bytes: 256
def hyouji(moji,a,b):
    for j in range(a,b):
        print(moji[j],end="")
    print()

def gyakujun(moji,a,b):
    moji1=[moji[i] for i in range(a,b)]
    moji1.reverse()
    for i in range(a,b):
        moji[i]=moji1[i-a]
    return moji
    
def replace(moji,a,b,p):
    for i in range(a,b):
        moji[i]=p[i-a]
    return moji

nyuryoku=input()
moji=[]

for i in nyuryoku:
    moji.append(i)

kaisu=int(input())

for j in range(kaisu):
    command=list(map(str,input().split()))
    p=[]
    meirei=command[0]
    a=int(command[1])
    b=int(command[2])+1
    if len(command)==4:
        for i in command[3]:
            p.append(i)
    if meirei=="print":
        hyouji(moji,a,b)
    elif meirei=="reverse":
        gyakujun(moji,a,b)
    elif meirei=="replace":
        replace(moji,a,b,p)



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

using namespace std;

const int N = 2e5 + 5;

struct DSU {
    int par[N], sz[N];
    void init (int n) {
        iota(par + 1, par + n + 1, 1);
        fill(sz + 1, sz + n + 1, 1);
    }

    int Find (int x) {
        return par[x] == x ? x : par[x] = Find(par[x]);
    }

    bool same (int x, int y) {
        return Find(x) == Find(y);
    }

    void join (int x, int y) {
        x = Find(x); y = Find(y);
        if (x == y) return;

        if (sz[x] > sz[y]) sz[x] += sz[y], par[y] = x;
        else sz[y] += sz[x], par[x] = y;
    }
} dsu;

int n, q, t, u, v;

int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> q; dsu.init(n);
    for (int i = 1; i <= q; i++) {
        cin >> t >> u >> v; u++; v++;
        if (t == 0) dsu.join(u, v);
        else cout << (dsu.same(u, v) ? 1 : 0) << "\n";
    }
    return 0;
}


Measured memory_bytes: 5016
# i*j > (i-1)(j+1) から　i-j ができるだけ小さくなるようなi,jを選べば良い
# for i in range(1,n**0.5+1):　でn % i == 0 なら更新んすうr
n = int(input())
max_i = 0
for i in range(1,int(n**0.5)+1):
    if n % i == 0:
        max_i = i
    #print(max_i,i)
print(max_i+n//max_i-2)

Measured memory_bytes: 40172
#include <stdio.h>

int main(void) {
	int i,n;
	int brk=0,num=1;
	int a[200000];

	scanf("%d",&n);
	for(i=0; i<n; i++) {
		scanf("%d",&a[i]);
		if(a[i]==num) num++;
		else brk++;
	}
	if(num==1) printf("-1");
	else printf("%d",brk);
	return 0;
}


Measured memory_bytes: 896
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100000

int main(){

	int N,K;
	scanf("%d %d",&N,&K);

	int* table = new int[N];
	for(int i = 0; i < N; i++)scanf("%d",&table[i]);

	int* check = new int[NUM+1];
	for(int i = 1; i <= NUM; i++)check[i] = 0;

	int count = 0,left = 0,right = 0;
	int ans = BIG_NUM;

	while(true){

		while(right <= N-1){
			check[table[right]]++;
			if(table[right] <= K && check[table[right]] == 1){
				count++;
			}
			if(count == K)break;
			right++;
		}
		if(right == N)break;

		ans = min(ans,right-left+1);

		while(left <= right){
			left++;
			check[table[left-1]]--;
			if(table[left-1] <= K && check[table[left-1]] == 0){
				count--;
				break;
			}
			ans = min(ans,right-left+1);
		}
		right++;
	}

	if(ans == BIG_NUM){
		printf("0\n");
	}else{
		printf("%d\n",ans);
	}

	return 0;
}



Measured memory_bytes: 3996
N = int(input())
Hs = list(map(int, input().split()))

for i in reversed(range(N-1)):
    if Hs[i]-1 > Hs[i+1]:
        print('No')
        break
    elif Hs[i]-1 == Hs[i+1]:
        Hs[i] -= 1
    else:
        pass
else:
    print('Yes')


Measured memory_bytes: 14224
#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;
 
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair <long long,long long> ii;
typedef complex<long double> point;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector <ll> arr;
    for (int z=0;z<s.size();){
        ll c = 0;
        if (s[z] == 'L'){
            for (;z<s.size();z++){
                if (s[z] == 'L') c++;
                else break;
            }
            arr.push_back(c);
        }
        else if (s[z] == 'R'){
            for (;z<s.size();z++){
                if (s[z] == 'R') c++;
                else break;
            }
            arr.push_back(c);
        }
    }
    sort(arr.begin(),arr.end());
    ll ans = 0;
    for (int z=0;z<s.size();z++){
        if (s[z] == s[z+1])ans++;
    }
    cout  << min(ans+min(k,ll(arr.size()))*2,n-1) << endl;
}

Measured memory_bytes: 1480
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
''' 
------------------------
author : iiou16
------------------------
'''

def main():
    N = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))

    count = 0
    nokori = 0

    for i in range(len(A)):
        mon = A[i]
        if nokori >= mon:
            count += mon
            mon = 0
        else:
            count += nokori
            mon -= nokori
        if i < N:
            if B[i] >= mon:
                count += mon
                nokori = B[i] - mon
            else:
                count += B[i]
                nokori = 0
    print(count)


if __name__ == '__main__':
    main()

Measured memory_bytes: 18624
#include <bits/stdc++.h>
#define mod 1000000007
#define MAXN 200000 + 5
#define ll long long
#define int long long
using namespace std;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(arr) arr.begin() , arr.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i , a , n) for(int i = a ; i < n ; i++)
#define s(arr) sort(all(arr))
#define r(arr) reverse(all(arr))
#define rs(arr) s(arr) ; r(arr)
#define con continue
#define endl "\n"
 
//debug
#define trace1(x)                cout<<#x<<": "<<x<<endl
#define trace2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl

int dp[10000 + 5];

signed main(){
    FAST;
    int h , n;
    cin >> h >> n;
    vector< pair < int , int > > arr(n);
    rep(i , 0 , n){
        cin >> arr[i].ff >> arr[i].ss;
    }

    dp[0] = 0;
    for (int i = 1 ; i <= h ; i++)
        dp[i] = LLONG_MAX;
    for (int i = 0 ; i < n ; i++){
        for (int j = 1 ; j <= arr[i].ff ; j++)
            dp[j] = min(dp[j] , arr[i].ss);
    }
    for (int i = 1 ; i <= h ; i++){
        for (int j = 0 ; j < n ; j++){
            dp[i] = min(dp[i] , dp[max(0ll , i - arr[j].ff)] + arr[j].ss);
        }
    }
    // rep(i , 1 , h + 1){
    //     cout << dp[i] << endl;
    // }
    cout << dp[h] << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    int a,b,c,i;
    while (cin>>a>>b){
        c=a+b;
        for(i=1; c>=10; i++){
            c/=10;
        }
        cout<<i<<endl;
    }
    return 0;
}


Measured memory_bytes: 2992
#include <iostream>
#include <string>
using namespace std;
int main()
{
    string s1, s2, temp;
    int i1, i2;
    cin >> s1 >> s2 >> i1 >> i2 >> temp;
    if (temp == s1)
    {
        cout << i1 - 1 << ' ' << i2 << endl;
    }else{
        cout << i1 << ' ' << i2 - 1 << endl;
    }
}

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

using namespace std;
typedef long long ll;

const int MAX_N = 1e5+10;

int main(int argc, char const *argv[])
{
	int N, abc[MAX_N][3]={0};
	ll dp[MAX_N][3] = {0};
	cin >> N;
	for (int i = 0; i < N; ++i) {
		scanf("%d %d %d", &abc[i+1][0], &abc[i+1][1], &abc[i+1][2]);
	}

	for (int i = 1; i <= N; ++i) {
		for (int p = 0; p < 3; ++p) {
			for (int q = 0; q < 3; ++q) {
				if (p==q) continue;
				dp[i][q] = max(dp[i][q], dp[i-1][p]+abc[i][q]);
			}
		}
	}

	cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;

	return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;

typedef pair <int,int> pii;
typedef vector <pii> vpii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef long long int lli;
typedef vector <lli> vlli;
typedef vector <vlli> vvlli;
typedef vector <string> vs;
typedef vector <bool> vb;

#define rep(i, n) for( i = 0; i < (n); ++i)
#define repA(i, a, n) for( i = a; i <= (n); ++i)
#define repD(i, a, n) for( i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sortr(x) sort(x.begin(),x.end(),greater <int> ())
#define mod 1000000007
#define ff first
#define ss second
#define fill(a,c)  memset(a, c, sizeof (a))
#define formap(i,v) for(auto &i: v)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl(v) cout<<#v<<" = \n"; { int c=0; formap(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it<<endl;} cerr<<endl
#define dbgstlp(v) cout<<#v<<" = \n"; { int c=0; formap(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it.first<<" , "<<it.second<<endl;} cerr<<endl
#define PI  3.14159265358979323846
#define pb push_back




int main() {
     cin.sync_with_stdio(0);cin.tie(0);
     cin.exceptions(cin.failbit);
    
    
    int i,j,n,ans,b;
    cin>>n;
    float f=1.08,k,p;
    k= (n*1.0)/1.08, p=((n+1)*1.0)/1.08;
    ans=ceil(k);b=floor(p);
    if (ans*1.08>=n+1)cout<<":(";
    else cout<<ans;
    
     
     
     
     
     
     
     
     
     
   
   
	return 0;
}


Measured memory_bytes: 3632
#include <stack>
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

#if __has_include("debugger.cpp")
  #include "debugger.cpp"
#else
void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) > 0) cout << " ";
  print(std::forward<Tail>(tail)...);
}
# endif

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

int main() {
  string input(s);
  stack<char> p;
  REP(i, s.size()) {
    if (s[i] == 'T' && !p.empty() && p.top() == 'S') {
      p.pop();
    } else {
      p.push(s[i]);
    }
  }

  print(p.size());
}


Measured memory_bytes: 3720
n = int(raw_input())
minv = int(raw_input())
maxv = -1*10**9
  
for j in range(n-1):
  nums = int(raw_input())  
  diff = nums - minv
  if maxv < diff:
    maxv = diff
  if nums < minv:
    minv = nums
  
print maxv

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

int C;
void BubbleSort(int A[],int N){
    bool flag = true;
    
    while(flag){
        flag = false;
        
        for(int j = N-1; j>=1; j--){
            if(A[j]<A[j-1]){
                swap(A[j],A[j-1]);
                C++;
                flag = true;
            }
        }
    }
}

int main(){
    int N;
    cin>>N;
    
    int A[100];
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    C = 0;
    
    BubbleSort(A,N);
    
    for(int i=0; i<N; i++){
        cout<<A[i];
        if(i<N-1)
            cout<<" ";
        else
            cout<<endl;
    }
    cout<<C<<endl;
    
    return 0;
}

Measured memory_bytes: 1160
import math
a,b,h,m = map(int, input().split())
ls = 30*h+m*0.5
ss = 6*m
angle = abs(ls-ss) if abs(ls-ss)<180 else 360-abs(ls-ss)
length = (a**2 + b**2 - 2*a*b*math.cos(math.radians(angle)))**0.5
print(length)

Measured memory_bytes: 9416
#include <bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define YesNo(b) b?cout << "Yes" << endl: cout << "No" << endl
#define YESNO(b) b?cout << "YES" << endl: cout << "NO" << endl
#define All(x) (x).begin(),(x).end()
#define VectorSumTotal(a) accumulate(a.begin(), a.end(), 0LL)
#define VectorStringTotal(a) accumulate(a.begin(), a.end(), string())
#define VectorSumMin(a) *std::min_element(a.begin(), a.end())
#define VectorSumMax(a) *std::max_element(a.begin(), a.end())
#define SortAscending(a) sort(a.begin(), a.end())
#define SortDescending(a) sort(a.begin(), a.end(), greater<>())

vector<string> VectorInput(long long int a) {
    vector<string> returnVector;
    string temp;
    for (int i = 0; i < a; ++i) {
        cin >> temp;
        returnVector.push_back(temp);
    }
    return returnVector;
}

int main() {
    int N, L;
    cin >> N >> L;
    auto words = VectorInput(N);
    SortAscending(words);
    cout << VectorStringTotal(words) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sz(v) ((int)(v).size())
using namespace std;
using lint = long long;
using pi = pair<int, int>;
const int MAXN = 200005;
const int MAXT = 530000;

struct disj{
	int pa[MAXN];
	void init(int n){
		iota(pa, pa + n + 1, 0);
	}
	int find(int x){
		return pa[x] = (pa[x] == x ? x : find(pa[x]));
	}
	bool uni(int p, int q){
		p = find(p);
		q = find(q);
		if(p == q) return 0;
		pa[q] = p; return 1;
	}
}disj;

struct seg{
	int tree[MAXT], lim;
	void init(int n, int *a){
		memset(tree, 0x3f, sizeof(tree));
		for(lim = 1; lim <= n; lim <<= 1);
		for(int i=1; i<=n; i++){
			tree[i + lim] = a[i];
		}
		for(int i=lim; i; i--){
			tree[i] = min(tree[2*i], tree[2*i+1]);
		}
	}
	int query(int s, int e){
		s += lim;
		e += lim;
		int ret = 1e9;
		while(s < e){
			if(s%2 == 1) ret = min(ret, tree[s++]);
			if(e%2 == 0) ret = min(ret, tree[e--]);
			s >>= 1;
			e >>= 1;
		}
		if(s == e) ret = min(ret, tree[s]);
		return ret;
	}
}seg, ges;

int a[MAXN], b[MAXN];
int sor[MAXN];
int n, k;

int main(){
	cin >> n >> k;
	if(k == 1){
		cout << 1 << endl;
		return 0;
	}
	disj.init(n);
	for(int i=1; i<=n; i++){
		scanf("%d",&a[i]);
		b[i] = -a[i];
	}
	seg.init(n, a);
	ges.init(n, b);
	for(int i=2; i<=n; i++){
		sor[i] = sor[i-1];
		if(a[i-1] < a[i]) sor[i]++;
	}
	vector<int> already_sorted;
	for(int i=k; i<=n; i++){
		int sum = sor[i] - sor[i-k+1];
		if(sum == k - 1){
			already_sorted.push_back(i);
		}
	}
	for(int i=k+1; i<=n; i++){
		int minv = seg.query(i - k + 1, i - 1);
		int maxv = -ges.query(i - k + 1, i - 1);
		if(a[i-k] < minv && maxv < a[i]){
			disj.uni(i-1, i);
		}
	}
	int ret = 0;
	for(int i=1; i<sz(already_sorted); i++){
		disj.uni(already_sorted[0], already_sorted[i]);
	}
	for(int i=k; i<=n; i++){
		if(disj.find(i) == i) ret++;
	}
	cout << ret << endl;
}


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

int main() {
    string s;
    cin>>s;
    rep(i,3)if(s[i]=='7'){
        cout << "Yes" <<endl;
        return 0;
    }
    cout << "No" <<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int main(){
    int n;
    cin >> n;
    vector<pair<pair<int,int>,int> > p;
    n--;
    int t = 1;
    int c = 0;
    for(int i=0;i<100;i++){
        if((1<<i)-1>n){
            c = i-1;
            break;
        }
    }
    for(int i=1;i<=c;i++){
        p.PB(MP(MP(i,i+1),1<<(i-1)));
        p.PB(MP(MP(i,i+1),0));

    }
    t = (1<<(c))-1;
    // cout << c << endl;
    // cout << t << " T" << endl;
    for(int i=c;i>=1;i--){
        if(t+(1<<(i-1))<=n){
            p.PB(MP(MP(i,c+1),t+1));
            // cout << i << endl;
            //cout << t <<" T" << endl;
            t += (1<<(i-1));
        }
    }
    //cout << t << endl;
    cout << c+1 << " " << p.size() << endl;
    for(auto x:p){
        cout << x.first.first << " "<< x.first.second << " " << x.second << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18

priority_queue<llint,vector<llint>,greater<llint>> que;
priority_queue<llint> q;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int n;
string s;

void solve(){
	cin >> n;
	if(n==25)cout << "Christmas";
	if(n==24)cout << "Christmas Eve";
	if(n==23)cout << "Christmas Eve Eve";
	if(n==22)cout << "Christmas Eve Eve Eve";
	cout << endl;
}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#define INF 999999
using namespace std;
int main(){
    int ends=0;
    int A,B;
    while(cin>>A>>B,A){
        if(ends==1)puts("");
        ends=1;
        int FLG=0;
        for(int i=A;i<=B;i++){
            int FLGS=0;
            if(i%4==0)FLGS=1;
            if(i%100==0)FLGS=0;
            if(i%400==0)FLGS=1;
            if(FLGS==1){cout<<i<<endl;FLG=1;}
        }
        if(FLG==0)cout<<"NA"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1164
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

#define int long long

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

int g[101][101];
bool used[101][101];
int es[101][101];
signed main() {
	int N, M; cin >> N >> M;
	rep(i, N) rep(j, N) g[i][j] = 1 << 29;
	rep(i, M) {
		int a, b, c; cin >> a >> b >> c;
		a--; b--;
		es[a][b] = es[b][a] = g[a][b] = g[b][a] = c;
	}
	rep(k, N) rep(i, N) rep(j, N) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
	rep(i, N) rep(j, N) {
		if (es[i][j] == g[i][j]) used[i][j] = true;
	}
	rep(i, N) rep(j, i + 1, N) if (es[i][j]) M -= used[i][j];
	cout << M << endl;
	system("pause");
}

Measured memory_bytes: 1012
#include<stdio.h>
int main(){
    
    int N[100],n;
    int i,j,m;
    int k;
    
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&N[i]);
    }

    for(i=1;i<n;i++){
        
        for(j=0;j<n;j++){
            if(j!=0){
                printf(" ");
            }
            printf("%d",N[j]);
        }
        printf("\n");
        
        m=i;
        
        for(j=i-1;j>=0;j--){
            if(N[j]<N[m]){
                break;
            }
            else{
                k=N[j];
                N[j]=N[m];
                N[m]=k;
                m--;
            }
        }
        
    }
    
    for(j=0;j<n;j++){
            if(j!=0){
                printf(" ");
            }
            printf("%d",N[j]);
        }
        printf("\n");
    
    return 0;
}


Measured memory_bytes: 2048
//#pragma comment (linker,"/STACK:256000000")
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define next(a) ( ((a)+1)%SIZE )
#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )
#define INF 1000000000
#define SIZE 100000

#define INF 1000000000
#define LLINF 10000000000000000

typedef long long ll;

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

int cnt = 0;


void insertion_sort(int *a, int n,int g)
{
	int i, j;
	int k;

	for (i = g; i < n; i++)
	{
		k = i;

		while (a[k] < a[k - g] && k>=g)
		{
			swap(&a[k], &a[k - g]);
			k-=g;
			cnt++;
		}
	}
}

/*
void insertion_sort(int *A, int n, int g) {
	int i, j, v;
	for (i = g; i < n; i++) {
		v = A[i];
		j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j + g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j + g] = v;
	}
}*/


void shell_sort(int *a, int n)
{
	long long int h=1;
	int m = 1;
	int G[100];
	int i, j;

	while ((h*3+1) < n)
	{
		h = h * 3 + 1;
		m++;
	}

	for (i = 0; i < m; i++)
	{
		G[i] = h;
		h /= 3;
	}

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

	for (i = 0; i < m; i++)
	{
		if (i == m - 1)
			printf("%d\n", G[i]);
		else
			printf("%d ", G[i]);
	}

	for (i = 0; i < m; i++)
		insertion_sort(a, n, G[i]);

	printf("%d\n", cnt);
}
/*

int GCD(int x, int y)
{
	if (x < y)
		swap(&x, &y);

	int z;

	while (y > 0)
	{
		z = x;
		x = y;
		y = z % y;
	}
	return x;
}

int prime(int x)
{
	int i, j;

	for (i = 2; i <= sqrt(x); i++)
	{
		if (x % i == 0)
			return -1;
	}

	return 1;
}

void bubble_sort(int* p, int n)
{
	int i, j;

	for (i = 0; i < n; i++)
	{
		for (j=n-1; j > i ; j--)
		{
			if (p[j] < p[j - 1])
			{
				swap(&p[j], &p[j - 1]);
				cnt++;
			}
		}
	}
}
*/

/*
void selection_sort(int* p, int n)
{
	int i, j, min;

	for (i = 0; i < n; i++)
	{
		min = i;
		for (j = i+1; j < n; j++)
		{
			if (p[j] < p[min])
				min = j;
		}
		if (min != i)
		{
			swap(&p[min], &p[i]);
			cnt++;
		}
	}
}*/


int binary_search(int* a, int n,int key)
{
	int low, middle, high;

	low = 0, high = n - 1;

	while (low <= high)
	{
		middle = (low + high) / 2;

		if (key < a[middle])
			high = middle - 1;
		else if (key > a[middle])
			low = middle + 1;
		else
			return 1;
	}
	return 0;
}

void reverse(int a[], int b, int e)
{
	int i;

	for (i = 0; i <= (e-b-1) / 2; i++)
	{
		swap(&a[b+i], &a[e - 1 - i]);
	}
}

int main()
{
	int n;
	int a[1000];
	int q;
	int b, e;

	scanf("%d", &n);

	int i, j;

	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);

	scanf("%d", &q);

	for (i = 0; i < q; i++)
	{
		scanf("%d%d", &b, &e);
		reverse(a, b, e);
	}

	for (i = 0; i < n; i++)
	{
		if (i == n - 1)
			printf("%d\n", a[i]);
		else
			printf("%d ", a[i]);
	}

}


Measured memory_bytes: 2096
from scipy.sparse import coo_matrix
from scipy.sparse.csgraph import bellman_ford, NegativeCycleError
import sys
input = sys.stdin.readline


def main():
    n, m, p = map(int, input().split())

    edges = []
    routes = [[] for _ in range(n)]
    rev_routes = [[] for _ in range(n)]

    def get_reachable_nodes(start, routes):
        seen = {start}
        todo = []
        for to in routes[start]:
            todo.append(to)
            seen.add(to)

        while todo:
            node = todo.pop()
            for to in routes[node]:
                if to in seen:
                    continue
                todo.append(to)
                seen.add(to)
        return seen

    for _ in range(m):
        node1, node2, value = map(int, input().split())
        node1, node2, value = node1 - 1, node2 - 1, value - p
        edges.append([node1, node2, value])
        routes[node1].append(node2)
        rev_routes[node2].append(node1)

    from_start = get_reachable_nodes(0, routes)
    if n-1 not in from_start:
        print(-1)
        return

    to_goal = get_reachable_nodes(n-1, rev_routes)

    from_start_to_goal = from_start & to_goal

    temp_dict = dict()

    for row, col, value in edges:
        if {row, col} <= from_start_to_goal:
            if not (row, col) in temp_dict:
                temp_dict[(row, col)] = -value
            else:
                temp_dict[(row, col)] = min(-value, temp_dict[(row, col)])

    values = []
    rows = []
    cols = []

    for (row, col), minus_value in temp_dict.items():
        values.append(minus_value)
        rows.append(row)
        cols.append(col)

    graph = coo_matrix((values, (rows, cols)), shape=(n, n))
    try:
        bf = bellman_ford(graph, indices=[0])
        print(max(0, -int(bf[0][n - 1])))
    except NegativeCycleError:
        print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 16496
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
 
vector<string> hako;
void saiki(string cs,int i){
  if(i>=(int)cs.length()){
    hako.push_back(cs);
  }
  else {
    saiki(cs,i+1);
    saiki(cs.insert(i,"+"),i+2);
  }
}
 
int main(void){
  int i,j;
  string s;
  long long int res,tmp,t;
 
  cin>>s;
  saiki(s,1);
  res=0;
  for(i=0;i<(int)hako.size();i++){
    tmp=t=0;
    for(j=0;j<(int)hako[i].length();j++){
      if(hako[i][j]=='+') {tmp+=t; t=0;}
      else t=t*10+(long long int)(hako[i][j]-'0');
    }
    tmp+=t;
    res+=tmp;
  }
  cout<<res<<endl;
 
  return 0;
}

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

int main()
{
	int n, k;
	cin >> n >> k;
	vector<long long> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n - k; i++){
		if(a[i] < a[i + k]) cout << "Yes\n";
		else cout<< "No\n";
	}
	return 0;
}

Measured memory_bytes: 4840
use std::io;
use std::cmp::min;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let a = v[0];
	let b = v[1];
	let c = v[2];
	println!("{}", min(min(a+b, a+c), b+c));
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll Nmax=1e9;
const ll INF=1e9;

int main(){
  double w,h,x,y;
  cin>>w>>h>>x>>y;

  int num=0;
  if(w==2*x && h==2*y){
    num=1;
  }

  printf("%.10lf %d\n", (w*h)/2,num);


}


Measured memory_bytes: 3772
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
  int N, A[100], ans;
  ans=0;
  cin >> N;
  for(int i=0;i<N-1;i++)cin>>A[i];
  ans += A[0];
  for(int i=0;i<N-2;i++){
      ans += min(A[i], A[i+1]);
  }
  ans += A[N-2];
  cout << ans << "\n";

  return 0;
}
    
  

Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1e+9 + 7;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> mp;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        ++mp[a[i]];
    }
    ll sum = 0;
    for(auto it : mp)   sum += (ll)it.second * (it.second - 1) / 2;
    for(int i = 0; i < n; ++i){
        int cnt = mp[a[i]];
        ll dif = cnt - 1;
        cout << sum - dif << "\n";
    }
}

Measured memory_bytes: 8320
from collections import deque
n, q = list(map(int, input().split()))

que = deque([])
for _ in range(n):
    que.append((int(x) if x.isdigit() else x for x in input().split()))
    
lap = 0

while que:
    name, lefttime = que.popleft()
    if lefttime <= q:
        lap += lefttime
        print(name, lap)
    else:
        lefttime -= q
        lap += q
        que.append((name, lefttime))


Measured memory_bytes: 46660
from sys import stdin

def main():

    input = stdin.readline

    X,Y = map(int,input().split())

    max_ashi = X * 4
    min_ashi = X * 2

    if (Y <= max_ashi) & (min_ashi <= Y) & (Y % 2 == 0):
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()

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

int ooo(int n,int p[50])
{
	int ans = 0;
	int pi;
	for (size_t i = 0; i < n; i++)
	{
		pi = p[i];
		if (!(pi==(i+1)))
		{
			if (p[pi] = (i + 1))
			{
				ans++;
			}
		}
	}
	return ans;
}
int main()
{
	int n;
	cin >> n;
	int p[50];
	for (size_t i = 0; i < n; i++)
	{
		cin >> p[i];
	}
	if (ooo(n, p) < 4)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
    return 0;
}



Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::*;

use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed reading char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed parsing")
}

fn main() {
  let (n, k): (usize, usize) = (read::<usize>(), read::<usize>());
  let (r, s, p): (usize, usize, usize) = (read::<usize>(), read::<usize>(), read::<usize>());
  let t: String = read::<String>();

  let mut flg = [""; 100000];

  let mut res = 0;

  let mut count = 0;

  for c in t.chars().as_str().chars() {
    let x = match c {
      'r' => p,
      's' => r,
      'p' => s,
       _  => 0
    };

    let index = count % k;
    count = count + 1;

    if c.to_string() != flg[index] {
      res = res + x;

      flg[index] =  match c {
        'r' => "r",
        's' => "s",
        'p' => "p",
        _  => ""
      };
    } else {
      flg[index] = "";
    }
  }

  println!("{}", res);
}


Measured memory_bytes: 5884
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type point struct {
	x, y int
}

type points []point

func (ps points) Len() int {
	return len(ps)
}
func (ps points) Less(i, j int) bool {
	if ps[i].x < ps[j].x {
		return true
	} else if ps[i].x == ps[j].x && ps[i].y < ps[j].y {
		return true
	}
	return false
}
func (ps points) Swap(i, j int) {
	ps[i], ps[j] = ps[j], ps[i]
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	ps := make([]point, n)
	for i := range ps {
		ps[i].x = nextInt(sc)
		ps[i].y = nextInt(sc)
	}
	sort.Sort(points(ps))
	// fmt.Println(ps)
	wtr := bufio.NewWriter(os.Stdout)
	for i := 0; i < len(ps); i++ {
		fmt.Fprintf(wtr, "%d %d\n", ps[i].x, ps[i].y)
	}
	wtr.Flush()
}



Measured memory_bytes: 5416
#include<stdio.h>
#include<stdlib.h>
#define INF 100000000;
int heapExtractMax();
void maxHeapify(int);
void buildMaxHeap();
void heapIncreaseKey(int,int);
void maxHeapInsert(int);
int length=1;
int A[2000001];

int main(){
  char order[8];
  int data,i=1;
  while(order[0]!='e'||order[1]!='n'){
    scanf("%s",order);
    
    if(order[0]=='i'){
      
      scanf("%d",&data);
      maxHeapInsert(data);
      
      
    }
    else if(order[0]=='e'&&order[1]=='x')printf("%d\n",heapExtractMax());
    
  }



  return 0;
}

void maxHeapify(int i){
  int l,r,largest,a;
  l=i*2;
  r=i*2+1;

  if(l<=length && A[l]>A[i]) largest=l;
  else largest=i;

  if(r<=length && A[r]>A[largest]) largest=r;

  if(largest!=i){
    a=A[i];
    A[i]=A[largest];
    A[largest]=a;
    maxHeapify(largest);
  } 

}

int heapExtractMax(){
  int max;
  if(length<1){ return -INF;
      }
  max=A[1];
 
  A[1]=A[length];
  length--;
  maxHeapify(1);

  return max;
}
void maxHeapInsert(int key){

  length++;
  A[length]=-INF;
  heapIncreaseKey(length,key);

}

void heapIncreaseKey(int i,int key){
  int a;
  if(key<A[i]){
    return;
  }
  A[i]=key;
  while(i>1&&A[i/2]<A[i]){
    a=A[i];
    A[i]=A[i/2];
    A[i/2]=a;
    i=i/2;
  }
  
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e10;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)
typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;

ll ans = 0;

void rec(ll i, ll n, bool use3, bool use5, bool use7) {
    if (i > n) {
        return;
    }
    if (use3 && use5 && use7) {
        ans++;
    }
    rec(i * 10 + 3, n, true, use5, use7);
    rec(i * 10 + 5, n, use3, true, use7);
    rec(i * 10 + 7, n, use3, use5, true);
}


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

    rec(3, n, true, false, false);
    rec(5, n, false, true, false);
    rec(7, n, false, false, true);

    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  long long num, max, a, b, diff=1, curr=0, ender=0;
  cin >> num >> max;
  vector<long long> list, numlist;
  for (long long i=0; i<num; i++){
      cin >> a;
      list.push_back(a);}
  sort(list.begin(),list.end());
  a=list[0];
  for (long long i=1; i<num; i++){
      b=list[i];
      if (a!=b) {diff++;}
      a=b;}
  for (long long i=0; i<diff; i++){
      numlist.push_back(0);}
  a=list[0];
  for (long long i=0; i<num; i++){
      b=list[i];
      if (a==b) {numlist[curr]+=1;}
      else {curr++; numlist[curr]+=1;}
      a=b;}
  sort(numlist.begin(),numlist.end());
  reverse(numlist.begin(),numlist.end());
  for (long long i=max; i<diff; i++){
      ender+=numlist[i];}
  cout << ender;}

Measured memory_bytes: 7892
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	if a < b {
		for i := 0; i < b; i++ {
			fmt.Print(a)
		}
	} else {
		for i := 0; i < a; i++ {
			fmt.Print(b)
		}
	}
	fmt.Println()
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
const long double PI = (acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int ctoi(char c)
{
    switch (c)
    {
    case '0':
        return 0;
    case '1':
        return 1;
    case '2':
        return 2;
    case '3':
        return 3;
    case '4':
        return 4;
    case '5':
        return 5;
    case '6':
        return 6;
    case '7':
        return 7;
    case '8':
        return 8;
    case '9':
        return 9;
    default:
        return 0;
    }
}
int main()
{
    int X, Y;
    cin >> X >> Y;
    vector<string> board(50);
    rep(i, X)
    {
        cin >> board[i];
    }
    vector<int> dx = {1, 1, 0, -1, -1, -1, 0, 1};
    vector<int> dy = {0, -1, -1, -1, 0, 1, 1, 1};
    for (int i = 0; i < X; i++)
    {
        for (int j = 0; j < Y; j++)
        {
            if (board[i][j] == '.')
            {
                int cnt = 0;
                for (int k = 0; k < 8; k++)
                {
                    int x = i + dx[k];
                    int y = j + dy[k];
                    if (x >= 0 && x < X && y >= 0 && y < Y && board[x][y] == '#')
                    {
                        cnt++;
                    }
                }
                board[i][j] = cnt + '0';
            }
        }
    }
    rep(i, X)
    {
        cout << board[i] << endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Linq;
class p
{
  static void Main()
  {
    string[] input = Console.ReadLine().Split(' ');
    int H = int.Parse(input[0]);
    int W = int.Parse(input[1]);
    
    char[] header = Enumerable.Repeat('#', W + 2).ToArray();
    Console.WriteLine(header);
    for (int i = 0; i < H; i++) {
      Console.WriteLine("#" + Console.ReadLine() + "#");
    }
    Console.WriteLine(header);
  }
}

Measured memory_bytes: 13268
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
string po = "Possible";
string im = "Impossible";

int a, b, c;
int main() {
  cin >> a >> b;
  c = a + b;
  if (a % 3 == 0 || b % 3 == 0 || c % 3 == 0) cout << po << endl;
  else cout << im << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cctype>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << (char)toupper(s1[0]) << (char)toupper(s2[0]) << (char)toupper(s3[0]) << '\n';
    return 0;
}


Measured memory_bytes: 3608
import java.util.*;
import java.io.*;

public class Main {
    static long mod = 1_000_000_007L;
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out, false);
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        int sum = x + y;
        if (sum % 3 != 0 || sum/3 > x || sum/3 > y) {
            out.println(0);
        } else {
            int choose = x - sum/3;
            long[] fact = new long[sum + 1];
            fact[0] = fact[1] = 1;
            for(int i = 2; i <= sum; i++) {
                fact[i] = fact[i-1] * i;
                fact[i] %= mod;
            }
            int val = sum/3;
            long ans = (fact[val] * modInv(fact[val - choose])) % mod;
            ans = (ans* modInv(fact[choose])) % mod;
            out.println(ans);
        }
        out.flush();
    }
    static long modInv(long x) {
        return modPow(x, mod-2);
    }
    static long modPow(long x, long p) {
        if (p == 0) return 1;
        long t = modPow(x , p/2);
        t = (t * t) % mod;
        if (p % 2 == 0) return t;
        return (t * x) % mod;
    }
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 37972
using System;
using System.Linq;
class Program
 {
  static void Main(string[] args){
    var values =  Console.In.ReadToEnd().TrimEnd()
            .Split()
            .Select(n => int.Parse(n))
            .ToArray();
      int max = 0;
      int total = 0;
      for(int i = 0; i < values[0]; i++){
          int index = i+1;
          if(values[index] >= max){
              max = values[index];
              total++;
          }
      }
      Console.WriteLine(total);
  }
 }

Measured memory_bytes: 13268
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001



while True:
    N,X = map(int,input().split())
    if N == 0 and X == 0:
        break
    ans = 0
    for a in range(1,N+1):
        for b in range(1,N+1):
            if b <= a:
                continue
            c = X-(a+b)
            if c > b and c <= N:
                ans += 1
    print("%d"%(ans))



Measured memory_bytes: 5604
object Main {

  import java.util.Scanner

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val writer = new java.io.PrintWriter(System.out)
    writer.println(solve(sc))
    writer.flush()
  }

  def solve(sc: Scanner): String = {
    val (n, m) = (sc.nextInt(), sc.nextInt())
    val cards = Array.fill(n)(sc.nextLong()).sorted
    val operations = IndexedSeq.fill(m)((sc.nextInt(), sc.nextLong()))
    debug(n, m, cards.toSeq, operations)

    operations.sortBy(_._2).reverse.foldLeft(0) { case (acc, (b, c)) =>
      var i = acc
      while (i < b + acc && i < cards.length && cards(i) < c) {
        cards(i) = c
        i += 1
      }
      i
    }
    cards.sum.toString
  }

  private def debug(x: Any): Unit = {
    if (System.getenv("LOCAL_DEBUG") != null) println(x)
  }
}


Measured memory_bytes: 113424
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;

const int N = 2005;
const int inf = 1000000000;
struct edge {
    int to, nxt;
} tree[N << 1];
int n, head[N], l[N], r[N], sz[N], cnt = 0;
char str[N];
void addedge (int u, int v) {
    edge e = {v, head[u]};
    tree[head[u] = cnt++] = e;
}

void dfs (int u, int fa) {
    int l_mx = 0;
    sz[u] = (str[u - 1] == '1'), r[u] = 0;
    for (int i = head[u]; ~i; i = tree[i].nxt) {
        int v = tree[i].to;
        if (v != fa) {
            dfs(v, u);
            sz[u] += sz[v];
            l_mx = max(l_mx, l[v] + sz[v]), r[u] += r[v] + sz[v];
        }
    }
    l[u] = 0;
    for (int i = head[u]; ~i; i = tree[i].nxt) {
        int v = tree[i].to;
        if (v != fa) {
            if (r[v] + sz[v] <= l_mx) l[u] += r[v] + sz[v];
            else if (l_mx % 2 == (r[v] + sz[v]) % 2) l[u] += l_mx;
            else l[u] += l_mx - 1;
        }
    }
    l[u] = (l_mx << 1) - l[u];
    if (l[u] < 0) l[u] = r[u] & 1;
}
int main () {
    scanf("%d%s", &n, str);
    for (int i = 1; i <= n; i++) head[i] = -1;
    for (int i = 1; i < n; i++) {
        int u, v;
        scanf("%d%d", &u, &v);
        addedge(u, v), addedge(v, u);
    }

    int ans = inf;
    for (int i = 1; i <= n; i++) {
        dfs(i, 0);
        if (l[i] <= 0) ans = min(ans, r[i] >> 1);
    }
    if (ans >= inf) printf("-1\n");
    else printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 384