akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#pragma warning (disable:4996)
//FILE *in = fopen("input.txt", "r"), *out = fopen("output.txt", "w");
FILE *in = stdin, *out = stdout;
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
#define INF 1e9
#define NM 305
#define MOD 1000000007
#define FOR(i,n,m) for (int i=(n);i<=(m);i++)
#define si(n) fscanf(in,"%d",&n)
#define sd(n) fscanf(in,"%lld",&n)
typedef long long int ll;

int n, K;
int dy[NM][NM][NM];
int Q[NM][3];
vector<pair<int,int> > a[NM];
void input(){
	si(n), si(K);
	FOR(i, 1, K){
		FOR(j, 0, 2) si(Q[i][j]);
		a[Q[i][1]].push_back({ Q[i][0], Q[i][2] });
	}
}
bool isValid(int i, int r, int g, int b){
	for (auto &p : a[i]){
		int s = p.first, t = p.second;
		if (s <= r) t--;
		if (s <= g) t--;
		if (s <= b) t--;
		if (t != 0) return false;
	}
	return true;
}
void pro(){
	dy[0][0][0] = 1;
	FOR(r, 0, n){
		FOR(g, 0, n){
			FOR(b, 0, n){
				int i = max(r, max(g, b));
				if (!isValid(i, r, g, b)){
					dy[r][g][b] = 0;
					continue;
				}
				if (i == n) continue;
				dy[i + 1][g][b] += dy[r][g][b]; dy[i + 1][g][b] %= MOD;
				dy[r][i + 1][b] += dy[r][g][b]; dy[r][i + 1][b] %= MOD;
				dy[r][g][i + 1] += dy[r][g][b]; dy[r][g][i + 1] %= MOD;
			}
		}
	}
	int ans = 0;
	FOR(i, 0, n - 1) FOR(j, 0, n - 1){
		ans += dy[n][i][j]; ans %= MOD;
		ans += dy[i][n][j]; ans %= MOD;
		ans += dy[i][j][n]; ans %= MOD;
	}
	fprintf(out, "%d", ans);
}
int main(){
	input();
	pro();
	return 0;
}

Measured memory_bytes: 110848
import java.util.Scanner;
class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		Main app = new Main();
		while(scan.hasNext()){
			String cipher = scan.nextLine();
			System.out.println(app.decipher(cipher));
		}
	}
	
	public String decipher(String cipher){
		String str = "";
		for(int i=0;i<cipher.length();i++){
			char ch = cipher.charAt(i);
			if('C'<ch && ch<='Z'){
				str = str + (char)(ch-3);
			}else if('A'<=ch && ch<='C'){
				str = str + (char)(ch+23);
			}else{
				str += ch;
			}
		}
		
		return str;
	}
}

Measured memory_bytes: 22172
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long a[510],b[510],n,k,s = 0,dp[510][510] = {};
bool ch(long long x){
	long long i,j;
	for(i=0;i<=n;i++){
		for(j=0;j<=n;j++){
			dp[i][j] = 1000000000;
		}
	}
	s = 0;
	for(i=0;i<n;i++){
		b[i] = a[i]%x;
		s += b[i];
	}
	dp[0][0] = 0;
	for(i=1;i<=n;i++){
		for(j=0;j<n;j++){
			dp[i][j] = min(dp[i][j],dp[i - 1][j]);
			dp[i][j + 1] = min(dp[i][j + 1],dp[i - 1][j] + b[i - 1]);
		}
	}
	for(i=0;i<=n;i++){
		if(max(dp[n][i],dp[n][i] + (n - i)*x - s)<=k){
			return true;
		}
	}
	return false;
}
vector<long long> v;
int main(){
	int i;
	cin >> n >> k;
	for(i=0;i<n;i++){
		cin >> a[i];
		s += a[i];
	}
	for(i=1;i*i<=s;i++){
		if(s%i==0){
			v.push_back(i);
			v.push_back(s/i);
		}
	}
	sort(v.begin(),v.end());
	for(i=(int)v.size() - 1;i>=0;i--){
		if(ch(v[i])){
			cout << v[i] << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

string f(const string& s, int k) {
    string t;
    rep (i, s.size()) {
        if (islower(s[i])) t += (char)((s[i]-'a'+k)%26+'a');
        else t += s[i];
    }
    return t;
}

bool ok(const string& t) {
    if (t.find("the") != string::npos) return true;
    if (t.find("this") != string::npos) return true;
    if (t.find("that") != string::npos) return true;
    return false;
}

int main() {
    string s;
    while (getline(cin, s)) {
        if (s.size() > 0 && s[s.size()-1] == '\r') s.resize(s.size()-1);
        rep (i, 26) {
            const string t = f(s, i);
            if (ok(t)) {
                cout << t << endl;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>

using namespace std;

#define MAX 100000
int n, k;
long long w[MAX];


int check(long long p)
{
	int i = 0;
	long long s = 0;


	for (int j = 0; j < k; j++) {

		s = 0;

		while (p >= w[i] + s) {
			s += w[i];

			i++;
			if (i == n) {
				return n;
			}
		}
	}

	return i;

}


//????????????????????§????????????????°?????????????
int  minKw()
{
	long long left = 0;
	long long right = 100000 * 10000;
	long long mid;
	int v;

	while ((right - left)>1) {
		mid = (left + right) / 2;
		v = check(mid);


		if (v >= n) {
			right = mid;
		}
		else {
			left = mid;
		}

	}

	return right;

}



int main(void)
{

	cin >> n >> k;
	//	insertionSortInput(w, n);

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

	cout << minKw() << endl;

	return 0;
}

Measured memory_bytes: 3872
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<climits>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

int main(){
    int N;
    cin>>N;
    int X[100];
    for(int i=0;i<N;i++){
        cin>>X[i];
    }

    int mn=INT_MAX;
    for(int i=-10;i<=110;i++){
        int p=i;
        int sum=0;
        for(int j=0;j<N;j++){
            sum+=(p-X[j])*(p-X[j]);
        }
        mn=min(sum,mn);
    }
    cout<<mn<<endl;

}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 1000000009
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

bool check(string a, string b, ll x){
  if(sz(a) < x){
    return true;
  }
  long long unsigned int sb = sz(b);
  rep(i, min(sz(a)-x, sb)){
    if(b.at(i) == '?' || a.at(x+i) == '?'){
      continue;
    }
    if(b.at(i) == a.at(x+i)){
      continue;
    }
    return false;
  }
  return true;
}

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  vector<bool> ab(4001, false);
  vector<bool> ac(4001, false);
  vector<bool> ba(4001, false);
  vector<bool> bc(4001, false);
  vector<bool> ca(4001, false);
  vector<bool> cb(4001, false);
  rep(i, 4001){
    if(check(a, b, i)){
      ab.at(i) = true;
    }
  }
  rep(i, 4001){
    if(check(a, c, i)){
      ac.at(i) = true;
    }
  }
  rep(i, 4001){
    if(check(b, a, i)){
      ba.at(i) = true;
    }
  }
  rep(i, 4001){
    if(check(b, c, i)){
      bc.at(i) = true;
    }
  }
  rep(i, 4001){
    if(check(c, a, i)){
      ca.at(i) = true;
    }
  }
  rep(i, 4001){
    if(check(c, b, i)){
      cb.at(i) = true;
    }
  }
  ll ans = 6000;
  ll sa = sz(a);
  ll sb = sz(b);
  ll sc = sz(c);
  //abc
  rep(i, 2001){
    rep(j, 2001){
      if(ab.at(i) && bc.at(j) && ac.at(i+j)){
        chmin(ans, max(sa, max(sb+i, sc+i+j)));
      }
    }
  }
  //acb
  rep(i, 2001){
    rep(j, 2001){
      if(ac.at(i) && cb.at(j) && ab.at(i+j)){
        chmin(ans, max(sa, max(sc+i, sb+i+j)));
      }
    }
  }
  //bac
  rep(i, 2001){
    rep(j, 2001){
      if(ba.at(i) && ac.at(j) && bc.at(i+j)){
        chmin(ans, max(sb, max(sa+i, sc+i+j)));
      }
    }
  }
  //bca
  rep(i, 2001){
    rep(j, 2001){
      if(bc.at(i) && ca.at(j) && ba.at(i+j)){
        chmin(ans, max(sb, max(sc+i, sa+i+j)));
      }
    }
  }
  //cab
  rep(i, 2001){
    rep(j, 2001){
      if(ca.at(i) && ab.at(j) && cb.at(i+j)){
        chmin(ans, max(sc, max(sa+i, sb+i+j)));
      }
    }
  }
  //cba
  rep(i, 2001){
    rep(j, 2001){
      if(cb.at(i) && ba.at(j) && ca.at(i+j)){
        chmin(ans, max(sc, max(sb+i, sa+i+j)));
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

min_diff = float('inf')
ans = -1

for i, h in enumerate(H):
    ave = T - h * 0.006
    if abs(ave - A) < abs(min_diff - A):
        min_diff = ave
        ans = i

print(ans + 1)


Measured memory_bytes: 3060
#include <stdio.h>
#define PI 3.14159265359
  
void kock(int n, double px1, double py1, double px2, double py2) {
      
    double sx,sy,tx, ty, ux, uy;
    if (n == 0) return;
      
    sx = (2*px1 + 1*px2)/3;
    sy = (2*py1 + 1*py2)/3;
    tx = (1*px1 + 2*px2)/3;
    ty = (1*py1 + 2*py2)/3;
    ux = (tx - sx) * cos(PI/3) - (ty - sy) * sin(PI/3) + sx;
    uy = (tx - sx) * sin(PI/3) + (ty - sy) * cos(PI/3) + sy;
  
      
    kock(n-1, px1, py1, sx, sy);
    printf("%f %f\n",sx, sy);
      
    kock(n-1, sx, sy, ux, uy);
    printf("%f %f\n", ux, uy);
      
    kock(n-1, ux, uy, tx, ty);
    printf("%f %f\n", tx, ty);
      
    kock(n-1, tx, ty, px2, py2);
      
}
  
int main() {
    int n;
    scanf("%d", &n);
      
    printf("0 0\n");
    kock(n, 0, 0, 100, 0);
    printf("100 0\n");
      
    return 0;
}

Measured memory_bytes: 1716
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;

int main(){
	int n, m;
	scanf("%d %d", &n, &m);
	std::vector<ll> a(m), b(m, 0);
	for(int i=0; i<m; i++){
		ll tmp;
		scanf("%ld %ld", &a[i], &tmp);
		for(int j=0; j<tmp; j++){
			ll c;
			scanf("%ld", &c);
			b[i] += (1<<(c-1));
		}
	}

	ll dp[m+1][1<<n];
	for(int i=0; i<=m; i++) for(int j=0; j<1<<n; j++) dp[i][j] = 1e11;
	dp[0][0] = 0;

	for(int i=0; i<m; i++){
		for(int j=0; j<(1<<n); j++){
			dp[i+1][j] = std::min(dp[i+1][j], dp[i][j]);
			dp[i+1][j|b[i]] = std::min(dp[i+1][j|b[i]], dp[i][j]+a[i]);
		}
	}

	if(dp[m][(1<<n)-1]>=1e11) puts("-1");
	else printf("%ld\n", dp[m][(1<<n)-1]);
	return 0;
}


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

int main()
{
  int N,X,count=0,inp;
  cin>>N>>X;
  int arr[N+1];
  memset(arr,0,sizeof(arr));
  for(int i=1;i<=N; i++)
  {
    cin>>inp;
    arr[i]=arr[i-1]+inp;
    if(arr[i]<=X)
    {
      count++;
    }    
  }
  cout<<(count+1);  
  return 0;
}


Measured memory_bytes: 256
open System
open System.Collections.Generic
open System.Linq
open System

// Following contents are my library. The Main processes are on the bottom of this code.

let puts = Console.WriteLine : 'a -> unit
let put = Console.Write : 'a -> unit
let read() = Console.ReadLine()
let reads () = Console.ReadLine().Split()
let read2 () = reads() |> (fun x -> x.[0], x.[1])
let read3 () = reads() |> (fun x -> x.[0], x.[1], x.[2])
let read4 () = reads() |> (fun x -> x.[0], x.[1], x.[2], x.[3])
let tmap2 f1 f2 (t1, t2) = (f1 t1, f2 t2)
let tmap3 f1 f2 f3 (t1, t2, t3) = (f1 t1, f2 t2, f3 t3)
let tmap4 f1 f2 f3 f4 (t1, t2, t3, t4) = (f1 t1, f2 t2, f3 t3, f4 t4)
let readAs f = read() |> f
let readAs2 f1 f2 = read2 () |> tmap2 f1 f2
let readAs3 f1 f2  f3 = read3 () |> tmap3 f1 f2 f3
let readAs4 f1 f2 f3 f4 = read4 () |> tmap4 f1 f2 f3 f4
let readInt () = readAs int
let readInt2 () = readAs2 int int
let readInt3 () = readAs3 int int int
let readInt4 () = readAs4 int int int int
let ensmallen l = l % 1000000007L
let manhattan x y = abs (fst x - fst y) + abs (snd x - snd y)
let sayYESNO b = if b then puts "YES" else puts "NO"


// The main contents of this submission are below this line.

let Lucas =
    Seq.unfold (fun (prevprev, prev) -> let current = prevprev + prev in Some (current, (prev, current))) (3L, -1L)

let n = readInt()
Seq.item n Lucas |> puts


Measured memory_bytes: 11348
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    ll section = n/(a+b);
    ll ans = section*a + min(n%(a+b),a);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    while(1){
        int n,m,i,j;
        cin>>n>>m;
        if(n==0) break;
        for(i=0;i<n;i++){
            for(j=0;j<m;j++) cout<<'#';
            cout<<'\n';
        }
        cout<<'\n';
    }
    return 0;
}


Measured memory_bytes: 3068
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

void fin(){
	freopen("test.txt", "r", stdin);
}

int main(){
//	fin();
	while(1){
		int t, p, r;
		cin >> t >> p >> r;
		if(!t) break;
		vector<pair<P, int> > v(t, MP(MP(0, 0), 0)); // ac, -time
		rep(i, t) v[i].second = -i;
		vector<vi> wa(t, vi(p, 0));
		while(r--){
			int tid, pid, time;
			string message;
			cin >> tid >> pid >> time >> message;
			tid--; pid--;
			if(message == "CORRECT"){
				v[tid].first.first++;
				v[tid].first.second -= time+1200*wa[tid][pid];
			}else{
				wa[tid][pid]++;
			}
		}
		sort(rev(v));
		rep(i, t){
			cout << -v[i].second+1 << ' ' << v[i].first.first << ' ' << -v[i].first.second << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1244
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int tmp = 0;
  	int ans = -1;
  	vector<string> s(201);
  	int n;
  	cin >> n;
  	REP(i, n) cin >> s[i];
  	vector<vector<int>> ls(n);
  	REP(i, n){
      	REP(j,n){
          	if(s[i][j] == '1'){
              	ls[i].push_back(j);
            }
        }
    }
	queue<pair<int, int>> q;
  	int now;
  	int ch[201];
 	bool crash;
	REP(x, n){
	    REP(y, 201) ch[y] = -1;
      	now = 1;
      	ch[x] = 1;
      	q.push(make_pair(x, now));
        crash = false;
      	//cout << x << " ";
	  	while(!q.empty()){
          	int here = q.front().first;
          	now = q.front().second;
          	//cout << here << " ";
          	q.pop();
           	if(crash){
              	now = -1;	
              	continue;
            }
    	  	REP(i, (int)ls[here].size()){
             	//cout << here << "->" << ls[here][i] << " " ;
              	if(ch[ls[here][i]] == -1){
                  	q.push(make_pair(ls[here][i], now +1));
                  	ch[ls[here][i]] = now + 1;
                }
              	else if(abs(ch[ls[here][i]] - now) != 1){
                  	crash = true;
                }
            }
        }
       	ans = max(ans, now);
      	//cout << endl;
    }
  	cout << ans << endl;
}


Measured memory_bytes: 3832
from collections import Counter
 
def main():
    n = int(input())
    A = [int(x) for x in input().split()]
    a_c = Counter(A)
    res = [int(v*(v-1)/2) for v in a_c.values()]
    cnt = sum(res)
    for a in A:
        ans = (cnt - (a_c[a]-1))
        print(ans)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 34116
#include "iostream"
#include "algorithm"
#include "cstring"
#include "cstdio"
#include "cmath"
#include "vector"
#include "map"
#include "set"
#include "queue"
using namespace std;
#define MAXN 200006
//#define int long long
#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define all(x) (x).begin() , (x).end()
#define mem( a ) memset( a , 0 , sizeof a )
#define P 1000000007
typedef long long ll;
int n , k , c;
char ch[MAXN];
int A[MAXN] , dp[MAXN] , pre[MAXN];
int que[MAXN] , head , tail;
vi ans;
void solve() {
    cin >> n >> k >> c;
    scanf("%s",ch + 1);
    for( int i = 1 ; i <= n ; ++ i ) A[i] = ( ch[i] == 'o' );
    head = 0 , tail = -1;
    que[++ tail] = 0;
    int re = 0;
    for( int i = 1 ; i <= n ; ++ i ) {
        if( i > c + 1 && A[i - c - 1] ) {
            while( tail >= head && dp[que[tail]] < dp[i - c - 1] ) -- tail;
            que[++ tail] = i - c - 1;
        }
        pre[i] = pre[i - 1];
        if( A[i] ) {
            dp[i] = dp[que[head]] + 1;
            pre[i] = i;
        }
        if( dp[i] == k ) ++ re;
    }
    if( dp[pre[n]] > k ){ return; }
    if( re == 1 ) ans.pb( pre[n] );
    int cur = pre[n] , now = k;
    while( dp[cur] != 1 ) {
        if (dp[pre[cur - c - 1]] == now - 1 && (dp[pre[pre[cur - c - 1] - 1]] != now - 1))
            ans.pb(pre[cur - c - 1]);
        cur = pre[cur - c - 1] , -- now;
    }
    sort( all( ans ) );
    for( int t : ans ) printf("%d\n",t);
}
signed main() {
//    freopen("2.in","r",stdin);
//    freopen("fuckout","w",stdout);
//    int T;cin >> T;while( T-- ) solve();
    solve();
}


Measured memory_bytes: 4980
#include <stdio.h>
#include <stdlib.h>


struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
  
};
typedef struct node * Node;
#define NIL NULL

Node root;

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

}

Node treeMaximum(Node x){
  while(x->right!=NIL)x=x->right;
  return x;


}

Node treeSearch(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){
  Node y;
  if(x->right!=NIL)return treeMinimum(x->right);

  y=x->parent;
  while(y!=NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}


void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  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;
  
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  
  z = malloc(sizeof(struct 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;
    
}



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


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


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20468
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <cmath>
#include <string>
#include <iomanip>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define inf 1013161010
#define ninf -1013161010
#define mod 1000000007
#define ll long long
#define lf long double
#define in(x) scanf("%d",&x);
#define sz(x) ((int)x.size())
#define lld l64d
#define rep(i,n) for(i=0;i<n;i++)
#define rrep(i,n) for(i=n-1;i>=0;i--)
#define rep1(i,a,b) for(i=a;i<=b;i++)
#define rrep1(i,a,b) for(i=a;i>=b;i--)
#define stlfor(i,t) for(auto i =t.begin();i!=t.end();i++)
#define fr freopen("x.txt","r",stdin)
#define frc freopen("y.txt","w",stdout)
#define all(x) x.begin(),x.end()
#define set0(x) memset(x,0,sizeof(x))
#define dbg cout<<"yo "<<endl;
#define pset(n) fixed<<showpoint<<setprecision(n)

#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pair<int,int> >
#define vpll vector<pair<ll,ll> >
#define si set<int>
#define mii map<int,int>
#define umii unordered_map<int,int>
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define mp make_pair

typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> OST;

ll toint(const string &s) { stringstream ss; ss << s; ll x; ss >> x; return x; }
string tostring ( ll number ){  stringstream ss; ss<< number; return ss.str();}

const lf pi = 2*acos(0);
const int nn = 2000006;

ll gcd(ll a,ll b){return (b==0)? a:gcd(b,a%b); }
void nope(int num = 0){ if(num==0) cout<<"NO"; else cout<<"-1"; exit(0); }

int a[100],k;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll i,j,n,tt;
    tt=1;
    //cin>>tt;
    while(tt--)
    {
        string s,t;
        cin>>s>>t;
        set<string>st;
        if(sz(t)>sz(s))
        {
            cout<<"UNRESTORABLE"<<endl;
            return 0;
        }
        for(i=0;i<=(sz(s)-sz(t));i++)
        {
            int f = 1;
            string a = s;
            for(j=0;j<sz(t);j++)
            {
                if(a[i+j]!='?' and a[i+j]!=t[j])
                {
                    f=0;
                }
                else if(a[i+j]=='?')
                    a[i+j]=t[j];
            }
            if(f==1)
            {
                for(j=0;j<sz(a);j++)
                    if(a[j]=='?')
                        a[j]='a';
                st.insert(a);
            }
        }
        if(sz(st)==0)
        {
            cout<<"UNRESTORABLE"<<endl;
        }
        else
        {
            cout<<*st.begin()<<endl;
        }

    }
    return 0;
}



Measured memory_bytes: 256
#!/usr/bin/perl
my ($n) = map { $_ - 0 } split(/\s+/,<STDIN>);
my @ab = ();
for(my $i=0;$i<$n;$i++){
  my @x = map { $_ - 0 } split(/\s+/,<STDIN>);
  push(@ab,\@x);
}
my @sab = sort { $a->[1] <=> $b->[1] } @ab;

my $res = 'Yes';
my $tot = 0;
for(my $i=0;$i<$n;$i++){
  $tot += $sab[$i]->[0];
  if( $tot > $sab[$i]->[1] ){
    $res = 'No';
    last;
  }
}
print "$res\n";
exit(0);




Measured memory_bytes: 46180
#include <stdio.h>
#include <cmath>
#include <algorithm>

using namespace std;

struct Team{
	char name[2];
	int win,lose;
};

int main(){

	int n,tmp;
	Team team[10];

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i = 0;i < n; i++){
			team[i].win = 0;
			team[i].lose = 0;
		}

		for(int i = 0; i < n; i++){
			scanf("%s",team[i].name);

			for(int k = 0; k < n-1; k++){
				scanf("%d",&tmp);
				if(tmp == 0)team[i].win++;
				else if(tmp == 1)team[i].lose++;
			}
		}

		for(int i=1; i <= n-1; i++){
			for(int k=n-1; k >= i; k--){
				if(team[k].win > team[k-1].win)swap(team[k],team[k-1]);
				else if(team[k].win == team[k-1].win && team[k].lose < team[k-1].lose)swap(team[k],team[k-1]);
			}
		}

		for(int i = 0; i < n; i++){
			printf("%s\n",team[i].name);
		}

	}

	return 0;
}

Measured memory_bytes: 2500
N = int(input())
D, X = map(int, input().split())

cnt = 0
for i in range(N):
    cnt_d = 0
    day = 1
    a = int(input())
    while day <= D:
        cnt_d += 1
        day = cnt_d * a + 1
    cnt += cnt_d
print(cnt + X)


Measured memory_bytes: 2940
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100009;

int a[55],n,k;
int chk(int i,int j)
{
    int lft=i-1;
    int rgt=n-j;
    if(lft+rgt>k)return -1;
    priority_queue<int>pq;
    int sum=0;
    for(int p=1;p<i;p++)pq.push(-a[p]),sum+=a[p];
    for(int p=j+1;p<=n;p++)pq.push(-a[p]),sum+=a[p];
    int baki=k-(lft+rgt);
   // cout<<sum<<" sum & baki "<<baki<<endl;
    while(baki>=1 && !pq.empty())
    {
         int x=-pq.top();
         pq.pop();
         //cout<<x<<" popping "<<endl;
         baki--;
         if(x<0)
         {
             sum-=x;
         }
         else
         {
             break;
         }
    }
    return sum;
}
int corner()
{
   if(k<n)return -1;
   int sum=0;
   f(i,1,n)
   {
       if(a[i]>0)sum+=a[i];
   }
   return sum;
}
 main()

{
    fast
    cin>>n>>k;
    int ses=0,tot=0;
    f(i,1,n)cin>>a[i];
    for(int i=1;i<=n;i++)
    {
        for(int j=i;j<=n;j++)
        {
            ses=max(ses,chk(i,j));
        }
    }
    //cout<<chk(3,5)<<"######"<<endl;
    ses=max(ses,corner());
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <deque>
#include <queue>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <set>
#include <stack>
#include <cstring>
#define INF 1e9
#define MOD 1e9+7
using namespace std;
using ll = long long;
int main() {
    ll n,k;
    cin >> n >> k;
    vector<ll> t(100010,0);
    vector<pair<ll,ll>> td(100010);
    priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;
    
    for(ll i=0;i<n;i++){
        ll x,y;
        cin >> x >> y;
        td[i] = make_pair(y,x);
    }
    sort(td.rbegin(),td.rend());
    ll ans = 0;
    ll tkazu = 0;
    for(ll i=0;i<k;i++){
        ans+=td[i].first;
        pq.emplace(td[i].first,td[i].second);
        if(t[td[i].second]==0){
            tkazu++;
        }
        t[td[i].second]++;
    }
    ll best = ans + tkazu*tkazu;
    for(ll i=k;i<n;i++){
        if(t[td[i].second]==0){
            ll x,y;
            ll cnt = 0;
            while(!pq.empty()){
            x = pq.top().first;
            y = pq.top().second;
            pq.pop();
                if(t[y]-1>0){
                    break;
                }
            }
            if(pq.empty()){
                break;
            }
            ans = ans + td[i].first - x;
            t[td[i].second]++;
            t[y]--;
            tkazu++;
            pq.emplace(td[i].first,td[i].second);
            best = max(best,ans+tkazu*tkazu);
        }
    }
    
    cout << best << endl;
}


Measured memory_bytes: 3704
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    vector<int> N(3, 0);
    cin >> N[0] >> N[1] >> N[2];

    sort(N.begin(), N.end());

    int max_val = N[2];
    int min_val = N[0];
    int mid_val = N[1];

    int count = max_val - mid_val;
    int diff = mid_val - min_val;
    count += (diff + 1) / 2;
    if(diff % 2 != 0) count += 1;

    cout << count << endl;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long k = sc.nextLong();

		long ans = 0;

		if (a > k) {
			ans = k;
			k = 0;
		} else {
			ans = a;
			k -= a;
		}

		if (k > 0) {
			if (b > k) {
				k = 0;
			} else {
				k -= b;
			}
		}

		if (k > 0){
			if (c > k) {
				ans -= k;
				k = 0;
			} else {
				ans -= c;
				k -= c;
			}
		}

		System.out.println(ans);
	}


}

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

int main(){
    int a,b,c,d,ans;
    cin >> a >> b >> c >> d;

    if(a <= c){
        if(b-c > 0){
            if(b < d)ans = b-c;
            else ans = d-c;
        }else ans = 0;
    }else{
        if(d-a > 0){
            if(d < b)ans = d-a;
            else ans = b-a;
        }else ans = 0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)

int main () {
  int a, b;
  cin >> a >> b;
  int x = a + b;
  cout << (x + 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
int n;
vector<ll> a(n);

bool ok(int x){
    ll sz = a[x];
    rep(i,n){
        if(i==x) continue;
        if(a[i] <= 2*sz) sz += a[i];
        else return false;
    }
    return true;
}

int main(){
    cin >> n;
    a.resize(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    int left = -1,right = n;
    while(right - left > 1){
        int mid = (left + right)/2;
        if(ok(mid)) right= mid;
        else left = mid;
    }
    cout << n-right << endl;
    return 0;
}

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

//Creating Node Structure
struct Node
{
    int data;
    Node *link;
};
//creating head pointer and equating to NULL
Node *head = NULL;

//Function to insert at the beginning of linked list
void insertBeg(int d)
{
    Node *ptr = new Node;
    ptr->data = d;
    ptr->link = head;
    head = ptr;
}
//Function to insert at the end of linked list
void insertEnd(int d)
{
    Node *ptr = new Node;
    ptr->data = d;
    ptr->link = NULL;

    //If list is empty
    if (head == NULL)
        head = ptr;
    //else list is not empty
    else
    {
        Node *temp = head;
        while (temp->link != NULL)
        {
            temp = temp->link;
        }
        temp->link = ptr;
    }
}
//Function to display linked list
void dispLink()
{
    Node *temp = head;
    while (temp != NULL)
    {
        cout << temp->data << " ";
        temp = temp->link;
    }
    cout << "\n";
}
//Main Function
int main()
{
    int x;
    cin >> x;
    cout << !x;
    return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)

int n;
int p[30];

int main(void){
	cin>>n;
	for (int i = 0; i < n; i++) cin>>p[i];

	int ans = 0;
	for (int i = 1; i + 1 < n; i++) {
		if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i + 1] < p[i] && p[i] < p[i - 1]))
			ans++;
	}

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

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

LL a[5000],cnt=0;
void  f(LL n)
{
    LL i;
    for(i=2; i<=n/i; i++)
        while(n%i==0)
        {
            n/=i;
            a[cnt++]=i;
        }
        if(n>1)
        a[cnt++]=n;
}
int main()
{
    LL n;
    int count=0;
    int ans=0;
    cin>>n;
    f(n);
    int be=0,ed;
    for(int i=1;i<=cnt;i++)
        if(a[i]!=a[i-1])
        {
            count=i-be;
            be=i;
            ans+=(sqrt(1+8*count)-1)/2;
        }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3688
import fractions
from functools import reduce
 
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N = int(input())
l = list(map(int, input().split(" ")))
 
p = lcm_list(l)
c = 0
for i in l:
  c += p // i
print(c % (10 ** 9 + 7))

Measured memory_bytes: 6112
#include <complex>
#include <iostream>

using xy_t = std::complex<double>;

// Calculate the signed area of a rectungle
double cross_product(xy_t a, xy_t b);
// is point p inside of abc
bool isInsideTriangle(xy_t a, xy_t b, xy_t c, xy_t p);

int main()
{
  double x[4], y[4]; // 4 points in plane
  while (true)
  {
    for (size_t i {}; i < 4; ++i)
      std::cin >> x[i] >> y[i];
    if (!std::cin)
      break;
    xy_t a {x[0], y[0]}, b {x[1], y[1]}, c {x[2], y[2]}, p {x[3], y[3]};
    std::cout << (isInsideTriangle(a, b, c, p) ? "YES" : "NO") << std::endl;
  }
}

double cross_product(xy_t a, xy_t b)
{
  return (std::conj(a) * b).imag();
}

bool isInsideTriangle(xy_t a, xy_t b, xy_t c, xy_t p)
{
  double area[3];
  area[0] = cross_product(a - p, b - p);
  area[1] = cross_product(b - p, c - p);
  area[2] = cross_product(c - p, a - p);
  if ((area[0] > 0 && area[1] > 0 && area[2] > 0)
      || (area[0] < 0 && area[1] < 0 && area[2] < 0))
    return true;
  else 
    return false;
}


Measured memory_bytes: 3040
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>

#define INF_LL 9000000000000000000
#define INF 2000000000

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

class SegTree{
	int n;
	vector<ll> seg;
public:
	SegTree(int n_){
		n = 1;
		while(n < n_) n *= 2;

		REP(i, n*2-1){
			seg.push_back(0);
		}
	}

	void add(int i, int x){
		i += n-1;
		seg[i] += x;
		while(i > 0){
			i = (i-1)/2;
			seg[i] = seg[i*2+1] + seg[i*2+2];
		}
	}

	int getSum(int s, int t){
		return getSum_solve(s, t, 0, 0, n);
	}
	
	int getSum_solve(int s, int t, int x, int l, int r){
		if(t <= l || r <= s) return 0;
		if(s <= l && r <= t) return seg[x];
		int res = 0;

		res += getSum_solve(s, t, x*2+1, l, (l+r)/2);
		res += getSum_solve(s, t, x*2+2, (l+r)/2, r);

		return res;
	}
};

int main(void){
	int n, q;
	cin >> n >> q;
	SegTree sg(n);
	REP(i, q){
		int com, x, y;
		cin >> com >> x >> y;
		if(com == 0){
			sg.add(x-1, y);
		}else{
			cout << sg.getSum(x-1, y) << endl;
		}
	}
}

Measured memory_bytes: 4936
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <functional>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<(x)<<endl
#define fi first
#define se second

#define INF 2147483600
#define EPS 1e-8

// ???????°???°???????????????
inline double add(double a, double b){
  if(abs(a+b) < EPS*(abs(a) + abs(b))) return 0;
  return a+b;
}

struct Point{
  double x,y;
  Point() {}
  Point(double nx, double ny) : x(nx), y(ny) {}
  Point operator + (const Point & p){ return Point(add(x, p.x), add(y, p.y)); }
  Point operator - (const Point & p){ return Point(add(x,-p.x), add(y,-p.y)); }
  Point operator * (double d){ return Point(x*d, y*d); }
  double dot(const Point & p){ return add(x * p.x, y*p.y); }  //??????
  double det(const Point & p){ return add(x * p.y, -y*p.x); } //??????
  double dist(const Point & p){ return sqrt((x-p.x)*(x-p.x) + (y-p.y)*(y-p.y)); }
  bool operator < (const Point & p) const {
    if(y != p.y) return y < p.y;
    else return x < p.x;
/*
    if(x != p.x) return x < p.x;
    else return y < p.y;
    */
  }
};

// Graham Scan
// ???????????????????¨?????????§return
// ???????????????????????????
vector<Point> convexHull(vector<Point> points){
  int n = points.size();
  sort(all(points));
  int k=0;
  vector<Point> qs(2*n);
  rep(i,n){
    while(k>1 && (qs[k-1] - qs[k-2]).det(points[i] - qs[k-1]) < 0) k--;
    qs[k++] = points[i];
  }
  for(int i=n-2,t=k; i>=0; i--){
    while(k>t && (qs[k-1] -qs[k-2]).det(points[i] - qs[k-1]) < 0) k--;
    qs[k++] = points[i];
  }
  qs.resize(k-1);
  return qs;
}

int main(){
  int n;
  cin>>n;
  vector<Point> vec(n);
  rep(i,n){
    double x, y;
    scanf("%lf %lf", &x, &y);
    vec[i] = Point(x,y);
  }
  vector<Point> conv = convexHull(vec);

  printf("%d\n", conv.size());
  rep(i,conv.size()){
    printf("%.0f %.0f\n", conv[i].x, conv[i].y);
  }

  return 0;
}

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

int main() {
  int n;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    m[tmp - 1]++;
    m[tmp]++;
    m[tmp + 1]++;
  }
  int mx = 0;
  for (auto k : m) {
    mx = max(mx, k.second);
  }
  cout << mx << endl;
}

Measured memory_bytes: 4736
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := map[int]int{}
	for i := 0; i < n; i++ {
		aa[getNextInt(scanner)] = 1
	}

	m := getNextInt(scanner)
	bb := make([]int, m)
	for i := 0; i < m; i++ {
		bb[i] = getNextInt(scanner)
	}
	for i := 0; i < m; i++ {
		if aa[bb[i]] == 0 {
			fmt.Fprintln(writer, 0)
			return
		}
	}
	fmt.Fprintln(writer, 1)
}



Measured memory_bytes: 15620
N=int(input())
R=[int(input()) for i in range(N)]
max_prifit=R[1]-R[0]
minR=R[0]
for i in range(1,N):
    max_prifit=max(max_prifit,R[i]-minR)
    minR=min(minR, R[i])

print(max_prifit)




Measured memory_bytes: 13596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000007
//0=48,A=65,a=97

int main() {
    int h,w,k;cin >> h >> w >> k;
    vector<vector<bool>> st(h, vector<bool>(w, false));
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            char x;cin >> x;
            if(x=='#') st[i][j]=true;
        }
    }

    vector<vector<int>> ans(h, vector<int>(w, 0));
    int n=0;
    vector<bool> low(h,false);


    for(int i = 0; i < h; i++) {
        bool sen=false;

        for(int j = 0; j < w; j++) {
            if(!sen && st[i][j]){
                sen=true;
                n++;
                low[i]=true;
                for(int l = 0; l <= j; l++) {
                    ans[i][l]=n;
                }
            }
            else if(sen && !st[i][j]){
                ans[i][j]=n;
            }
            else if(sen && st[i][j]){
                n++;
                ans[i][j]=n;
            }
        }
    }

    bool lsen=false;
    for(int i = 0; i < h; i++) {
        if(!lsen && low[i]){
            for(int j = 0; j <= i; j++) {
                ans[j]=ans[i];
            }
            lsen=true;
        }

        else if(lsen && i >= 1){
            if(!low[i]){
                ans[i]=ans[i-1];
            }
        }
    }


    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w-1; j++) {
            cout << ans[i][j] << ' ';
        }
        cout << ans[i][w-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 3988
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int a, b; cin >> a >> b;
    cout << a * b << endl;
    return 0;
}


Measured memory_bytes: 3624
import sys
N = int(input())
S = [int(input()) for _ in range(N)]

total = sum(S)
if total % 10 != 0:
  print(total)
  sys.exit(0)
else:
  S = sorted(S)
  for i in S:
    if i % 10 != 0:
      print(total-i)
      sys.exit(0)
  else:
    print('0')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
 
int main() {
  int N;
  ll K;
  cin >> N >> K;
  vector<ll> ap(N), food(N);
  for (int i=0; i < N; i++) {
    cin >> ap.at(i);
  }
  for (int i=0; i < N; i++) {
    cin >> food.at(i);
  }
  sort(ap.begin(),ap.end());
  sort(food.begin(),food.end());
  reverse(food.begin(),food.end());
  ll min = -1, mx = ap.at(N - 1) * food.at(0);
  while (abs(mx - min) > 1) {
    ll mid = min + (mx - min) / 2;
    ll count = 0;
    for (int i=0; i < N; i++) {
      count += max((ll)0, (ap.at(i) * food.at(i) - mid + food.at(i) - 1) / food.at(i));
    }
    if (count <= K)  mx = mid;
    else  min = mid;
    //検証用  cout << min << " " << mid << " " << mx << " " << j << " " << K << " " << score << endl;
  }
  cout << mx << endl;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[][] a = new long[n + 10][3];
        long[][] dp = new long[n + 10][3];

        for(int i = 0; i < n; i++)
            for(int j = 0; j < 3; j++) a[i][j] = Integer.parseInt(sc.next());

        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] = Math.max(dp[i + 1][k], dp[i][j] + a[i][k]);
                }
            }
        }
        long ans = 0;
        for(int i = 0; i < 3; i++) ans = Math.max(ans, dp[n][i]);
        System.out.println(ans);
    }
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int l = a + b;
  int r = c + d;

  if (l > r) cout << "Left" << endl;
  else if (l == r) cout << "Balanced" << endl;
  else cout << "Right" << endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    
    ans = 10 ** 5
    for i in range(10, 0, -1):
        a = 1000 * i
        if a < N:
            break
        ans = a - N
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 61756
#!python
# -*- coding: utf-8 -*-


C = {}


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

    C[1] = 1
    comb = 1
    for n in range(2, N):
        C[n] = comb
        comb += n

    ANS = 0
    x = 0
    s = 0
    length = 0
    R = 0

    for L in range(N):
        x ^= A[L]
        s += A[L]
        length += 1

        if x == s:
            ANS += length - 1

        else:
            while R <= L:
                R += 1
                x ^= A[R - 1]
                s -= A[R - 1]
                length -= 1

                if x == s:
                    ANS += length - 1
                    break
    ANS += N
    print(ANS)


if __name__ == '__main__':
    main()


Measured memory_bytes: 43132
h,w=map(lambda x: int(x), input().split())
s=[]
for i in range(h):
    s.append(input())

cnt=[[0 for i in range(w+2)] for j in range(h+2)]

for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            cnt[i][j]+=1
            cnt[i][j+1]+=1
            cnt[i][j+2]+=1
            cnt[i+1][j]+=1
            cnt[i+1][j+2]+=1
            cnt[i+2][j]+=1
            cnt[i+2][j+1]+=1
            cnt[i+2][j+2]+=1

ans=[['' for i in range(w)] for j in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            ans[i][j]='#'
        else:
            ans[i][j]=str(cnt[i+1][j+1])

for i in range(h):
    print(''.join(ans[i]))

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

int main(){
	int n,k;
	cin >> n >> k;
	vector<int> num(n+1, 0);
	int kind = 0;
	for(int i=0; i<n; i++){
		int x;
		cin >> x;
		if(num[x]==0) kind++;
		num[x]++;
	}
	sort(num.begin(), num.end());
	
	int ans=0;
	for(int i=n-kind-1; i<n; i++){
		if(kind <= k) break;
		if(num[i]==0) continue;
		ans += num[i];
		kind--;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define forin(in, n) for(int i=0; i<n; i++) cin>>in[i]
#define forout(out, n) for(int i=0; i<n; i++) cout<<out[i]<<endl

int main(){
    long double a, b; cin>>a>>b;
    ll ans=floor((a*(b*1000))/1000);
    cout<<ans<<endl;
}


Measured memory_bytes: 3684
#include<stdio.h>

int main(void){
	int h;
	int h1 = 0, h2 = 0, h3 = 0;
        for(int i = 0; i < 10 ; i++){
		scanf("%d", &h);
		if(h <= h3){
		}
		else if(h3 < h && h <= h2){
			h3 = h;
		}
		else if(h2 < h && h <= h1){
			h3 = h2;
			h2 = h;
		}
		else{
			h3 = h2;
			h2 = h1;
			h1 = h;
		}
        }
	printf("%d\n%d\n%d\n", h1, h2, h3);	
}

Measured memory_bytes: 1852
//https://atcoder.jp/contests/abc178/tasks/abc178_f
#include <bits/stdc++.h>

using namespace std;

const int MAXN=2e5+4;
long long a[MAXN];
long long b[MAXN];

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

    reverse(b, b+n);

    //寻找重合的区间
    int c=-1;
    int l=n;
    int r=-1;
#if 0
    for (int i=0; i<n; i++) {
        if (-1==c && a[i]==b[i]) {
            //第一次出现相等
            c=a[i];
            l=i;
        } else if (-1!=c && c!=a[i] && c!=b[i]) {
            //最后一次出现相等
            r=i-1;
        }
    }
#else
    for (int i=0; i<n; i++) {
        if (a[i]==b[i]) {
            c=a[i];
            break;
        }
    }
    for (int i=0; i<n; i++) {
        if (c==a[i] && c==b[i]) {
            l=min(l, i);
            r=max(r, i);
        }
    }
#endif

    //交换数据
    for (int i=0; i<n; i++) {
        if (c!=a[i] && c!=b[i] && l<=r) {
            swap(b[i], b[l]);
            l++;
        }
    }

    if (l<=r) {
        cout<<"No\n";
    } else {
        cout<<"Yes\n";
        for (int i=0; i<n; i++) {
            cout<<b[i]<<" ";
        }
    }

    return 0;
}

Measured memory_bytes: 6784
#include <stdio.h>
 
int main()
{
  int a[4];
  scanf("%d%d%d",&a[0],&a[1],&a[2]);
  a[1] *= 10;
  a[1] += a[2];
  if (a[1] % 4 == 0)
    printf("YES");
  else
    printf("NO");
}

Measured memory_bytes: 128