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

using namespace std;

#define BUF_SIZE 22

struct Node{
	Node(){
		left_child = right_child = parent = 0;
		data = 0;
	}
	Node *left_child,*right_child,*parent;
	long long data;
};

class Tree{
public:
	Tree(){
		root = new Node();
		num_of_node = 0;
	}
	void insert(long long insert_data){
		if(num_of_node == 0){
			root->data = insert_data;
			num_of_node++;
		}else{
			Node* tmp = root;
			while(true){
				if(tmp->data < insert_data){
					if(tmp->right_child == 0){
						tmp->right_child = new Node();
						tmp->right_child->data = insert_data;
						tmp->right_child->parent = tmp;
						num_of_node++;
						break;
					}else{
						tmp = tmp->right_child;
					}
				}else{
					if(tmp->left_child == 0){
						tmp->left_child = new Node();
						tmp->left_child->data = insert_data;
						tmp->left_child->parent = tmp;
						num_of_node++;
						break;
					}else{
						tmp = tmp->left_child;
					}
				}
			}
		}
	}

	void print(){
		inORDER(root);
		printf("\n");
		preORDER(root);
		printf("\n");
	}

private:

	Node* root;
	int num_of_node;

private:
	void preORDER(Node* node){
		printf(" %lld",node->data);
		if(node->left_child != 0) preORDER(node->left_child);
		if(node->right_child != 0) preORDER(node->right_child);
	}

	void inORDER(Node* node){
		if(node->left_child != 0) inORDER(node->left_child);
		printf(" %lld",node->data);
		if(node->right_child != 0) inORDER(node->right_child);
	}
};


int main(){
	int m;
	long long insert_data;
	char buf[BUF_SIZE];
	Tree tree;

	scanf("%d",&m);
	getchar();

	for(int i = 0; i < m; i++){
		fgets(buf,BUF_SIZE,stdin);
		if(buf[0] == 'i'){
			insert_data = 0;
			for(int k = 0; buf[k] != '\0';k++){
				if(buf[k] >= '0' && buf[k] <= '9'){
					insert_data = 10*insert_data + (buf[k] - '0');
				}
			}
			tree.insert(insert_data);
		}else{
			tree.print();
		}
	}
}

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

using namespace std;

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define rep(i,a,b) for(auto i = (a); i != (b); ++i)
#define REP(i,n) rep(i,0,n)
#define all(v) (v).begin(), (v).end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int maxn = 1e5;
int N, C, s[maxn], t[maxn], c[maxn], used[maxn];

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

	cin >> N >> C;
	vi events;
	REP(i, N) {
		cin >> s[i] >> t[i] >> c[i];
		events.eb(i);
	}

	sort(all(events), [] (int a, int b) { return s[a] < s[b]; });

	int nret = 0;
	vii deadlines; // (time, idx)
	for (int cur : events) {
		size_t idx = 0;
		for (; idx < deadlines.size(); idx++) {
			// switch to cur's channel.
			if (deadlines[idx].x < s[cur]) break;
			// stay on the same channel
			if (deadlines[idx].x == s[cur] && deadlines[idx].y == c[cur]) break;
		}
		ii deadline(t[cur], c[cur]);
		if (idx == deadlines.size()) {
			deadlines.pb(deadline);
			nret = max(nret, (int) deadlines.size());
		} else {
			deadlines[idx] = deadline;
		}
	}
	cout << nret << endl;
	return 0;
}

Measured memory_bytes: 1912
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s.find("mw")!=string::npos||s.find("wm")!=string::npos||s.find("ee")!=string::npos)cout<<"Rabbit"<<endl;
  else cout<<"Cat"<<endl;
}

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

void print(int x[],int n){
    for(int i=0;i<n;i++){
        if(i>0)printf(" ");
        printf("%d",x[i]);
    }
    printf("\n");
}

void InsertionSort(int x[],int n){
	int t,j;
	for(int i=1;i<n;i++){
	    print(x,n);
		t = x[i];
		j = i-1;
		while( j>=0 && t<x[j]){
			x[j+1]=x[j];
			x[j]=t;
			j--;
		}
	}
	print(x,n);
}

int main() {
    int n;
	scanf("%d",&n);
	int lst[n];
	for(int i=0;i<n;i++){
	    cin >> lst[i];
	}
	InsertionSort(lst,n);
	return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5+2;
int N, h[MAXN], dp[MAXN];
int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);
	cin >> N;
	for(int i = 1;i<=N;i++) cin >> h[i];
	memset(dp, 0x3f, sizeof(dp));
	dp[1] = 0;
	for(int i = 1;i<=N;i++){
		if(i+1<=N)dp[i+1] = min(dp[i+1], dp[i]+abs(h[i]-h[i+1]));
		if(i+2<=N)dp[i+2] = min(dp[i+2], dp[i]+abs(h[i]-h[i+2]));
	}
	cout << dp[N] << '\n';
	return 0;
}

Measured memory_bytes: 1024
N = int(input())
S = [input() for i in range(N)]
d = {}
m = 0
for i in S:
    if i in d:
        d[i] += 1
        if d[i] > m:
            m = d[i]
    else:
        d[i] = 1
        
d = dict(sorted(d.items(), reverse=True))
a = {}
for i in d.keys():
    if m <= d[i]:
        a[i] = 0
a = sorted(a)
for i in a:
    print(i)

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

int main() {
  double pi = 3.141592653589793;
  double a, b, h, m;
  cin >> a >> b >> h >> m;
  double min = 60 * h + m;
  double d = 5.5 * min;
    double rad = d * (pi / 180);
  double x;
  x = a*a + b*b - 2*a*b*cos(rad);
  double ans = pow(x, 0.5);
  cout << fixed << setprecision(15);
  cout << ans << endl;
}

Measured memory_bytes: 4360
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int A[3];
  cin >> A[0] >> A[1] >> A[2];
  sort(A,A+3);
  cout << (A[0] * A[1]) / 2 << endl;
  return 0;
}

Measured memory_bytes: 3636
#define _GLIBCXX_DEBUG
#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>;

void solve()
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> a(m);
    rep(i, m) cin >> a[i];
    int right = 0, left = 0;
    rep(i, m)
    {
        if (a[i] > x)
            right++;
        else
            left++;
    }
    int ans = min(right, left);
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
    while(true){
    int n;
    cin >> n;
    if(n==0) break;
    vector<int> scores(n);
    for(int i=0; i<scores.size(); i++){
        cin >> scores[i];
    }
    double avg=0, var=0;
    for(int i=0; i<scores.size(); i++){
        avg += scores[i];
    }
    avg/=scores.size();
    for(int i=0; i<scores.size(); i++){
        var += (avg - scores[i])*(avg - scores[i]);
    }
    var /= scores.size();
    cout << fixed << setprecision(10);
    cout << sqrt(var) << endl;
    }
    return 0;
}



Measured memory_bytes: 3300
""" AtCoder """

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

l = []

ans = []

if B - A < K:
    for i in range(A, B + 1):
        ans.append(i)
else:
    for i in range(A, A + K + 1):
        l.append(i)
    for i in range(B - K, B + 1):
        l.append(i)
    for i in range(K):
        ans.append(l[i])
        ans.append(l[-i-1])

ans = set(ans)

ans = sorted(ans)

for i in range(len(ans)):
    print(ans[i])


Measured memory_bytes: 3064
def main():
    a = int(input())
    b = int(input())
    c = int(input())
    d = int(input())
    e = int(input())
    k = int(input())

    antennas = [a, b, c, d, e]
    max_val = max(antennas)
    min_val = min(antennas)

    if max_val - min_val > k:
        print(":(")
    else:
        print("Yay!")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def main():
    N, M, *A = map(int, read().split())
    B = A.copy()

    while not any(b % 2 for b in B):
        B = [b // 2 for b in B]

    if not all(b % 2 for b in B):
        print(0)
        return

    semi_lcm = 1
    for a in A:
        semi_lcm = lcm(semi_lcm, a // 2)

    print((M // semi_lcm + 1) // 2)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 15316
/*痛みを受け取れ，痛みを知れ*/
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1000007;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 6e5 + 5;

int main()
{
	//freopen("in.txt", "r", stdin);
	set<int> st;
	st.insert(1);
	st.insert(2);
	st.insert(3);
	int x;
	while (cin >> x)
	{
		st.erase(x);
	}
	cout << *st.begin() << endl;
	return 0;
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);

class UnionFind {
  public:
    std::vector<int> parent;

    UnionFind(int n);

    int root(int x);

    bool same(int x, int y);

    bool unite(int x, int y);
};

UnionFind::UnionFind(int n) {
  parent.resize(n, -1);
}

int UnionFind::root(int x) {
  if (parent[x] < 0)
    return x;
  else
    return parent[x] = root(parent[x]);
}

bool UnionFind::same(int a, int b) {
  return root(a) == root(b);
}

bool UnionFind::unite(int a, int b) {
  int x = root(a);
  int y = root(b);
  if (x == y) return false;

  if (parent[x] > parent[y]) {
    int tmp = parent[x];
    parent[x] = parent[y];
    parent[y] = tmp;
  }
  parent[x] += parent[y];
  parent[y] = x;
  return true;
}
int main(){
  int n, m;

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

  UnionFind u = UnionFind(n + 1);

  int p[n];
  REP (i, n) {
    scanf("%d", &p[i]);
  }

  REP (i, m) {
    int x, y;
    scanf("%d %d", &x, &y);
    u.unite(x, y);
  }

  int sum = 0;
  FOR (i, 1, n + 1) {
    if (u.same(p[i - 1], i)) sum++;
  }

  printf("%d\n", sum);
}


Measured memory_bytes: 1024
def pricing(A, B, C, tmp):
    A_price = tmp * A
    B_price = tmp * B
    AnB_price = A_price + B_price
    AB_price = tmp * 2 * C
    price = AnB_price if AnB_price < AB_price else AB_price
    return price


A, B, C, X, Y = map(int, input().split())
tmp = min(X, Y)
price = pricing(A, B, C, tmp)

tmp = max(X, Y) - tmp
if X > Y:
    price += pricing(A, 0, C, tmp)
else:
    price += pricing(0, B, C, tmp)

print(price)


Measured memory_bytes: 3064
#include<stdio.h>
int main(void)
{
	int N = 0, i = 0, j = 0, sum = 0;
	int a[55] = { 0 };
	scanf("%d", &N);
	for (i = 0; i < N; i++)
	scanf("%d", &a[i]);
	for (i = 0; i < N; i++)
	{		
		for (j = i + 1; j < N; j++)
		{
			sum += a[i] * a[j];
		}
	}
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <functional>
#include <map>
#include <set>
#include <cmath>
using namespace std;

#define INT_MAX 2147483647
#define ll long long 

// DP !!
int main() {
    int n, W;
    cin >> n >> W;

    vector<ll> w(n);
    vector<ll> v(n);

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

    vector<vector<ll>> dp(n + 1);

    for (int i = 0; i <= n; i++) {
        dp[i].resize(W + 1);
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= W; j++) {
            dp[i][j] = i > 0 ? dp[i - 1][j] : 0;
            if (j - w[i - 1] >= 0) {
                // j=3 w[i] = 3 i = 0
                dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i - 1]] + v[i - 1]);
            }
        }
    }

    cout << dp[n][W] << endl;

    return 0;
}

Measured memory_bytes: 79488
#include <cstdio>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
using namespace std;

typedef pair<int,int> pii;

void dec(map<int,int> &mp, int x){
	if(!--mp[x]){ mp.erase(x); }
}

int dif(map<int,int> &mp){
	map<int,int>::iterator it = mp.end();
	--it;
	return it->first - mp.begin()->first;
}

bool check(const vector<pii> &v, int y0, int th){
	int n = v.size();
	map<int,int> mpx, mpy;
	for(int i = 0; i < n; ++i){
		++mpx[v[i].first];
		++mpy[v[i].second];
	}
	if(dif(mpx) <= th && dif(mpy) <= th){ return true; }

	int lt = 0;
	for(int i = 0; i < n; ++i){
		while(v[lt].first < v[i].first - th){
			if(v[lt].second <= y0 + th){
				++mpx[v[lt].first];
				++mpy[v[lt].second];
			}
			++lt;
		}
		if(v[i].second <= y0 + th){
			dec(mpx, v[i].first);
			dec(mpy, v[i].second);
			if(dif(mpx) <= th && dif(mpy) <= th){ return true; }
		}
	}
	return false;
}

int main(){
	int n;
	scanf("%d", &n);
	vector<pii> v(n);
	int y0 = 1 << 30;
	for(int i = 0; i < n; ++i){
		int x, y;
		scanf("%d%d", &x, &y);
		v[i] = pii(x + y, x - y);
		y0 = min(y0, v[i].second);
	}
	sort(v.begin(), v.end());
	
	int left = 1, right = 300000;
	while(left < right){
		int mid = (left + right) >> 1;
		if(check(v, y0, mid)){
			right = mid;
		}
		else{
			left = mid + 1;
		}
	}
	printf("%d\n", left);
}

Measured memory_bytes: 9716
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {FIN
    
    int sm, i;
    string num;
    while (cin >> num, num != "0") {
        sm = 0;
        for (i = 0; i < num.size(); i++)
            sm += (num[i] - '0');
        cout << sm << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll>   vl;
#define f(i,n)  for(i=0;i<n;i++)
#define f1(i,n)  for(i=1;i<n;i++)
#define fr(i,n) for(i=n-1;i>=0;i--)
#define em emplace_back
#define mp make_pair
#define in insert
#define fi first
#define sc second
#define b begin
#define e end
#define er erase
#define l length
#define c clear
#define si size
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
const double pi=3.141592653;
const ll infi=1000000001;
const ll MOD=1000000007;
const ll mod=998244353;
const string no="NO\n",yes="YES\n";

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

// void dfs(vl v[],ll node,ll hai[]){
//     hai[node]=1;
//     for(auto i:v[node]){
//         if(hai[i]==0){
//             dfs(v,i,hai);
//         }
//     }
// }

// ll con(vl v[],ll hai[],ll sz){
//     ll count=0;
//     for(int i=1;i<sz;i++){
//         if(hai[i]==0){
//             count++;
//             dfs(v,i,hai);
//         }
//     }
    // return count;
// }

// void gcde(int a,int b,int *x,int *y){
//     if(a==0){
//         *x=0;
//         *y=1;
//         return;
//     }    
//     int x1,y1;
//     gcde(b%a,a,&x1,&y1);
    
//     *x=y1-(b/a)*x1;
//     *y=x1;
// }


// ll recur(vl v,ll in,ll m,ll n){
//     if(in==-1)  return 1000000000001;
//     ll d,e,c;
//     d=max(m/v[in],n*v[in]);
//     c=recur(v,in-1,m/v[in],n*v[in]);
//     e=recur(v,in-1,m,n);
//     return min(c,min(e,d));
// }

// ll bexpo(ll a,ll p){
//     ll x=1;
//     while(p){
//     if(p&1){
//         x=(x*a)%mod;
//     }
//     a=(a*a)%mod;
//     p>>=1;
//     }
//     return x;
// }
// int dx[8]{-1,0,0,1,-1,-1,1,1};
// int dy[8]{0,-1,1,0,-1,1,-1,1};


int main() {
    fastio
    int t=1;
    // cin>>t;
    ll n,m,i,l,d,bank,s,k,j,x,y,ans,q;

    while(t--){ans=0;
        cin>>n;
        
       n?cout<<0<<endl:cout<<1<<endl; 
       
    }
    
    
	return 0;
}

Measured memory_bytes: 3648
a, b, x = map(int, input().split())

import numpy as np
half = a * a * b / 2
if x > half:#すぐ零れる場合
    V = a * a * b
    S = (V - x) / a
    h = 2 * S / a
    rad = np.arctan(h / a)
    deg = rad * 180 / np.pi
    print(deg)
else:#なかなか零れない場合
    h = x * 2 / a / b
    rad = np.arctan(h / b)
    deg = rad * 180 / np.pi
    print(90 - deg)

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

int main() {
  string S;
  cin >> S;
  while(S.size()!=0){
    S.erase(S.size()-2,2);
    if(S.substr(0,S.size()/2)==S.substr(S.size()/2,S.size()/2)){
      cout << S.size() << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	private class DisjointSet {
		
		int[] p, rank;
		
		public DisjointSet(int size) {
			p = new int[size];
			rank = new int[size];
			for (int i = 0; i < size; i++) {
				makeSet(i);
			}
		}

		private void makeSet(int x) {
			p[x] = x;
			rank[x] = 0;
		}
		
		public boolean same(int x, int y) {
			return findSet(x) == findSet(y);
		}

		private int findSet(int x) {
			while (p[x] != x) {
				x = p[x];
			}
			return p[x];
		}
		
		public void unite(int x, int y) {
			link(findSet(x), findSet(y));
		}

		private void link(int x, int y) {
			if (rank[x] > rank[y]) {
				p[y] = x;
			} else {
				p[x] = y;
				if (rank[x] == rank[y]) {
					rank[y]++;
				}
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(reader.readLine());
		int n = Integer.parseInt(st.nextToken());
		DisjointSet ds = new DisjointSet(n);
		int q = Integer.parseInt(st.nextToken());
		for (int i = 0; i < q; i++) {
			st = new StringTokenizer(reader.readLine());
			int c = Integer.parseInt(st.nextToken());
			int x= Integer.parseInt(st.nextToken());
			int y = Integer.parseInt(st.nextToken());
			if (c == 0) {
				ds.unite(x, y);
			} else {
				System.out.println(ds.same(x, y)?"1":"0");
			}
		}
		reader.close();
	}
}


Measured memory_bytes: 60628
/* Tuan Kkura */
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define base 31
#define MOD 1e9+7
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define FORs(i, a, b) for(int i = a; i >= b; i--)
#define REP(i, a, b) for(int i = a; i < b; i++)
#define __FOR(i, a, b, k) for(int i = a; i <= b; i+= k)
#define __REP(i, a, b, k) for(int i = a; i < b; i+= k)
#define pb push_back
#define _io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

typedef pair <int, int> ii;
typedef vector <ii> vii;
#define fi first
#define se second
#define mp make_pair
#define PROB "text"
#define MAXN 200005

int main()
{
    _io
    string s, t;
    cin >> s >> t;
    int res = 0;
    REP(i, 0, 3)
        if(s[i] == t[i])    res++;
    cout << res;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{

    public static void main(String[] args)throws Exception{
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt(), t = sc.nextInt();
    	int[] tt = new int[n];
    	for(int i=0; i<n; i++)
    		tt[i] = sc.nextInt();
    	int res=0, tmp = tt[0];
    	for(int i=1; i<n; i++){
    		if(tmp+t>tt[i]){
    			res+=tt[i]-tmp;
    			tmp = tt[i];
    		}
    		else{
    			res+=t;	tmp = tt[i];
    		}
    	}
    	res+=t;
    	System.out.println(res);
    }
}

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

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  cout << (a.back() == b[0] && b.back() == c[0] ? "YES" : "NO") << endl;
}



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

int  main(){
  int n,s,sum=0,avg;
  vector<int>a;

  
  while(cin>>n,n){
    sum=0;
    avg=0;
    a.clear();
  for(int i=0;i<n;i++){
    cin>>s;
    a.push_back(s);
  }
 
  sort(a.begin(),a.end());
  
  for(int i=1;i<n-1;i++){
    sum=sum+a.at(i);
  }
    avg=sum/(n-2);
    
    cout<<avg<<endl;

  }



}

Measured memory_bytes: 1220
#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;

int main() {
    int N, K; cin >> N >> K;

    vector<int> gems;
    for (int i = 0; i < N; ++i) {
        int g; cin >> g;
        gems.push_back(g);
    }

    int max_score = 0;

    vector<int> vs(N);
    for (int A = 0; A <= K && A <= N; ++A) {
        for (int B = 0; A + B <= K && A + B <= N; ++B) {
            int rest = std::max(0, K - A - B);

            int pos = 0;
            for (int a = 0; a < A; ++a) {
                vs[pos++] = gems[a];
            }
            for (int b = 0; b < B; ++b) {
                vs[pos++] = gems[N - b - 1];
            }

            sort(&vs[0], &vs[pos], std::greater<int>());
            while (rest > 0 && pos > 0) {
                if (vs[pos - 1] < 0) {
                    --pos;
                    --rest;
                } else {
                    break;
                }
            }

            int score = accumulate(&vs[0], &vs[pos], 0);
            if (score > max_score) {
                max_score = score;
            }
        }
    }

    cout << max_score << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#define alphaNum 26

using namespace std;

int main(){
    string s;
    int count[alphaNum] = {0};
    while (getline(cin, s)) {
      for(int i = 0; i < s.length(); i++){
        if('A' <= s[i] && s[i] <= 'Z'){
          count[s[i] - 'A']++;
        }
        else if('a' <= s[i] && s[i] <= 'z'){
          count[s[i] - 'a']++;
        }
      }
    }
    for(int i = 0; i < alphaNum; i++){
      cout << (char)('a'+i) << " : " << count[i] << endl;
    }
    return 0;
}

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

int main() {
	string s;
	cin >> s;

	if (s.length() < 4) {
		cout << "No" << endl;
	}
	else if (!s.substr(0,4).compare("YAKI")) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import sys
n=int(input())
s=int(input())
if n==s:
  print(n+1)
  sys.exit()
if n<s:
  print(-1)
  sys.exit()
for i in range(2,int(n**0.5)+1):
  ct=0;x=n;b=i
  while x>=b:
    ct+=x%b
    x=x//b
  ct+=x
  if ct==s:
    print(b)
    sys.exit()
for i in range(int(n**0.5),0,-1):
  if (n-s)%i==0:
    ct=0;x=n;b=(n-s)//i+1
    while x>=b:
      ct+=x%b
      x=x//b
    ct+=x
    if ct==s:
      print(b)
      sys.exit()
print(-1)

Measured memory_bytes: 3064
H, W, M = map(int, input().split())
bombs = []
rows = [[]for _ in range(H)]
cols = [[]for _ in range(W)]
for _ in range(M):
    h, w = map(lambda x: int(x)-1, input().split())
    bombs.append((h, w))
    rows[h].append(w)
    cols[w].append(h)

max_row = 0
row_idx = set()
for i, row in enumerate(rows):
    if max_row < len(row):
        max_row = len(row)
        row_idx = {i}
        continue
    elif max_row == len(row):
        row_idx.add(i)

max_col = 0
col_idx = set()
for i, col in enumerate(cols):
    if max_col < len(col):
        max_col = len(col)
        col_idx = {i}
        continue
    elif max_col == len(col):
        col_idx.add(i)

ans = max_row+max_col
points = len(row_idx)*len(col_idx)
if M < points:
    print(ans)
else:
    for i, j in bombs:
        if i in row_idx and j in col_idx:
            points -= 1
    if points == 0:
        print(ans-1)
    else:
        print(ans)


Measured memory_bytes: 153396
/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
    //static long memo[][];
    //static int w[];
    //static int v[];
    //static int n;
   public static void main(String args[])
   {
       Scanner sc=new Scanner(System.in);
       int n=sc.nextInt();
       int W=sc.nextInt();
       int w[]=new int[n];
       int v[]=new int[n];
       long dp[]=new long[100000+1];
       for(int i=0;i<n;i++)
       {
           w[i]=sc.nextInt();
           v[i]=sc.nextInt();
       }
       Arrays.fill(dp,(long)1e9+2);
       dp[0]=0;
       for(int i=0;i<n;i++)
              {
       for(int j=100000;j>=0;j--)
           {
               if((j-v[i])>=0)dp[j]=Math.min(dp[j],dp[j-v[i]]+w[i]);
           }
       }
       for(int i=100000;i>=0;i--)
       {
           if(dp[i]<=W)
           {
               System.out.println(i);
               break;
           }
       }
       
   }
}

Measured memory_bytes: 22996
n, m = map(int, input().split())
h = list(map(int, input().split()))

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

for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append(b)
    edges[b].append(a)

ans = 0

for own in range(n):
    is_good = True
    for pair in edges[own]:
        if h[own] <= h[pair]:
            is_good= False
    if is_good:
        ans += 1

print(ans)

Measured memory_bytes: 29508
N = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            divisors.append(n//i)
    return divisors
    
divisors = make_divisors(N)

x_ax = divisors[-2] - 1
y_ax = divisors[-1] - 1

print(x_ax + y_ax)

Measured memory_bytes: 38640
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Graph vector<vector<int>>;
#define iterG(next_v, G, v) for(auto next_v : G[v]
int main(){
    int n, x;
    int tmpn, tmpx;
    int ans = 0;
    cin >> n >> x;
    //vector<pair<int, int> > s;
    while(n != 0 || x != 0){
        //pair<int, int> p = make_pair(n, x);
        //s.push_back(p);
        //cin >> n >> x;
    //}
    //rep(i, s.size()){
        //tmpn = s[i].first;
        //tmpx = s[i].second;
        ans = 0;
        for(int j =1;j<=n;j++){
            for(int k=j+1;k<=n;k++){
                for(int l=k+1;l<=n;l++){
                    if(j+k+l == x){
                        ans++;
                    }
                }
            }
        }
        cout << ans << endl;
        cin >> n >> x;


    }
    
    return 0;
}



Measured memory_bytes: 3120
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#define pb push_back
typedef long long ll;
using namespace std;

const int maxn = 1e6+5;
char s[maxn];
char c[maxn];
int main()
{
    scanf("%s",c);
    int len = strlen(c);
    for(int i = 200001; i <= 200001+len-1; i++) {
        s[i] = c[i-200001];
    }
    int q; cin >> q;
    int t, f;
    char c1;
    int a = 0;
    int len1 = 200000, len2 = 200001+len;
    while(q--) {
        cin >> t;
        if(t == 1) a^=1;
        else {
            cin >> f >> c1;
            if(f == 1) {
                if(a == 0) {
                    s[len1--] = c1;
                }
                else {
                    s[len2++] = c1;
                }
            }
            else {
                if(a == 0) {
                    s[len2++] = c1;
                }
                else s[len1--] = c1;
            }
        }
    }
    if(!a) {
        for(int i = len1+1; i < len2; i++) {
            cout << s[i];
        }
    }
    else{
        for(int i = len2-1; i > len1; i--) {
            cout << s[i];
        }
    }
    cout << endl;
}


Measured memory_bytes: 896
n = gets.to_i
a = gets.split(" ").map(&:to_i)

ret = {}
b = []
a.each do |i|
	if ret[i].nil?
		ret[i] = 1
	elsif ret[i] == 1 || ret[i] == 3
		b << i
		ret[i] += 1
	else
		ret[i] += 1
	end
end

if b.size <= 1
	puts 0
else
	b.sort!
	puts b[-2] * b[-1]
end


Measured memory_bytes: 14980
#include <bits/stdc++.h>
#ifdef DBP
#define deb(...) fprintf(stderr,__VA_ARGS__)
#else
#define deb(...) 0
#endif
#define fst first
#define snd second
#define fore(x,a,b) for(int x=(a), qwerty=(b); x<qwerty; x++)
#define pb push_back
#define mset(a,v) memset((a),(v),sizeof(a))
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

const int N=16;
ll score[1<<N], dp[1<<N], g[N][N];
int n;

int main(){FIN;
	cin >> n;
	fore(x,0,n)fore(y,0,n)cin>>g[x][y];
	fore(x,0,1<<n){
		fore(a,0,n)if(x&(1<<a)){
			fore(b,a+1,n)if(x&(1<<b)){
				score[x]+=g[a][b];
			}
		}
	}
	
	fore(m,1,1<<n){
		for(int s=m;s;s=(s-1)&m){
			dp[m]=max(dp[m],score[s]+dp[s^m]);
		}
	}
	
	cout << dp[(1<<n)-1] << "\n";
}

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

int main()
{
	int H, W;
	string w[100];
	int Ans[100][100];
	cin >> H >> W;
	for (int i = 0; i < H; i++)
	{
		cin >> w[i];
		bool c = false;
		int coun;
		for (int u = 0; u < W; u++)
		{
			if (c == false)
			{
				if (w[i][u] == '.')
				{
					Ans[i][u] = -1;
				}
				else
				{
					coun = 0;
					Ans[i][u] = coun;
					c = true;
				}
			}
			else
			{
				if (w[i][u] == '.')
				{
					coun++;
					Ans[i][u] = coun;
				}
				else
				{
					coun = 0;
					Ans[i][u] = coun;
				}
			}
		}
	}

	for (int i = 0; i < H; i++)
	{
		for (int u = 0; u < (W-1); u++)
		{
			cout <<Ans[i][u]<<" ";
		}
		cout << Ans[i][W - 1] << endl;
	}

	cin >> H;
}

Measured memory_bytes: 3176
#include <cstdio>
#include <iostream>
#include <string>
#include <queue>
using namespace std;

struct Node {
    int depth;
    Node* child[2];
    Node() {
        child[0] = child[1] = nullptr;
    }
};

int main() {
    long long int N, L; scanf("%lld%lld", &N, &L);

    Node* root = new Node;
    root -> depth = 0;
    for(int i=0; i<N; i++) {
        string s; cin >> s;
        Node* cur = root;

        for(size_t k=0; k<s.length(); k++) {
            int c = s[k] - '0', d = cur -> depth;
            if(cur -> child[c] == nullptr) {
                cur -> child[c] = new Node;
                cur -> child[c] -> depth = d + 1;
            }
            cur = cur -> child[c];
        }
    }

    queue<Node*> que;
    que.push(root);
    long long int ans = 0;
    while(que.size()) {
        Node* cur = que.front(); que.pop();
        if((cur -> child[0] == nullptr) && (cur -> child[1] == nullptr)) continue;
        if((cur -> child[0] == nullptr) || (cur -> child[1] == nullptr)) {
            int d = cur -> depth;
            ans ^= (L - d) & (d - L);
        }

        for(int k=0; k<2; k++) {
            if(cur -> child[k] != nullptr) {
                que.push(cur -> child[k]);
            }
        }
    }
    printf("%s\n", ans ? "Alice" : "Bob");
    return 0;
}

Measured memory_bytes: 3456
S = input().rstrip()

ans = 0
cnt0 = 0
cnt1 = 0
for s in S:
    if s == '0':
        if cnt1 > 0:
            ans += 2
            cnt1 -= 1
        else:
            cnt0 += 1
    else:
        if cnt0 > 0:
            ans += 2
            cnt0 -= 1
        else:
            cnt1 += 1
print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>

using namespace std;
using ull = unsigned long long;

int main() {
	ull A, B, K;
	cin >> A >> B >> K;

	for (size_t i = 0; i < K; i++) {
		const ull beforeA = A;
		const ull beforeB = B;
		if (i % 2 == 0) {
			if (A % 2 == 1) {
				A--;
			}
			const ull div = A / 2;
			A -= div;
			B += div;

		} else {
			if (B % 2 == 1) {
				B--;
			}
			const ull div = B / 2;
			B -= div;
			A += div;
		}
		if (beforeA == B && beforeB == A) {
			if (((K - 1) - i) % 2 == 1) {
				swap(A,B);
			}
			break;
		}
	}


	cout << A <<  " " << B << endl;

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N, Q; 
int par[200010]; 
int depth[200010]; 
int siz[200010];  
void init(){
	for(int i = 0; i < N; i++){
		par[i] = i; depth[i] = 0; siz[i] = 1; 
	}
}
int find(int x){
	if(par[x] == x) return x;
	else return par[x] = find(par[x]); 
}
void unite(int x, int y){
	x = find(x); 
	y = find(y); 
	if(x == y) return;
	else if(depth[x] < depth[y]){
		par[x] = y; 
		siz[y] += siz[x]; 
	}else{
		par[y] = x; 
		siz[x] += siz[y];  
		if(depth[x] == depth[y]) depth[x] ++; 
	}
}
bool same(int x, int y){
	return find(x) == find(y); 
}
int sz(int x){
	return siz[find(x)]; 
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> N >> Q; 
	init(); 
	while(Q--){
		int t, u, v; cin >> t >> u >> v; 
		if(t == 0) unite(u, v); 
		else cout << (same(u, v) ? 1 : 0) << "\n";  
	}
}

Measured memory_bytes: 5832
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	n *= 3;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	sort(rall(a));
	ll ans = 0;
	for (int i = 1; i < n / 3 * 2; i += 2) {
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;cin >> s;
	int n=s.size();
	int l=0,r=s.size()-1,ans=0;
	while(l<r){
		if(s.at(l)==s.at(r)){
			l++;
			r--;
		}
		else{
			if(s.at(l)=='x'){
				ans++;
				l++;
			}
			else if(s.at(r)=='x'){
				ans++;
				r--;
			}
			else{
				cout << -1 << endl;
				return 0;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <vector>
#include<functional>  
#define ll long long
#define out(a) printf("%d",a)
using namespace std;
int n;
int ans,sum;
int t;
int a[100050];
int mx;
int read()
{
	int s=0,t=1; char ch;
	while (ch<'0'||ch>'9') {if (ch=='-') t=-1;ch=getchar();}
	while (ch>='0'&&ch<='9') {s=s*10+ch-'0';ch=getchar();}
	return s*t;
}
int main()
{
	n=read(); mx=-233333; ans=-233333;
	for (int i=1;i<=n;i++) {
	  t=read(); a[t]++; mx=max(t,mx);
	}
	for (int i=0;i<=mx;i++)
	  if (a[i]>0) {
	  	sum+=a[i]; sum+=a[i-1]; sum+=a[i+1];
	  	ans=max(sum,ans); sum=0;
	  }
	  out(ans);
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
string s;
int main()
{

    //freopen("input.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin>>s;
    int t=s.size()-1;
    while(1)
    {
        if(t<=0)
            break;
        if(s.substr(t-4,5)=="dream")
            t-=5;
        else if(s.substr(t-4,5)=="erase")
            t-=5;
        else if(s.substr(t-5,6)=="eraser")
            t-=6;
        else if(s.substr(t-6,7)=="dreamer")
            t-=7;
        else
            break;
    }
    if(t==-1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }

#define P 1000000007

int k[200000];
int rk[200000];

int getk(int a, int x){
	if(x==1) return a;
	int b = getk(a, x/2);
	b = ((long)b)*b%P;
	if((x&1)==0){
		return b;
	}else{
		return ((long)b)*a%P;
	}
}

int perm(int a, int b){
	if(a<b) return 0;
	return ((long)k[a])*rk[a-b]%P;
}

void comb_init(int n){
	k[0]=1;
	for(int i=1; i<=n; i++){
		k[i]=k[i-1]*((long)i)%P;
	}	
	rk[n]=getk(k[n], P-2);
	for(int i=n-1; i>=0; i--){
		rk[i]=((long)rk[i+1])*(i+1)%P;
	}
}

int edge[99999][2];

int qmem[199998];

int *e[100000];
int el[100000];

int m;

int f(int from, int fromfrom){
	long ans = perm(m-2, el[from]-1);
	for(int i=0; i<el[from]; i++){
		int to = e[from][i];
		if(to != fromfrom)
			ans = ans * f(to, from) % P;
	}
	return ans;
}

int main(void){
	int n=nextint();
	m=nextint();
	for(int i=0; i<n-1; i++){
		int A=nextint()-1;
		int B=nextint()-1;
		edge[i][0]=A;
		edge[i][1]=B;
		el[A]++;
		el[B]++;
	}
	int ne=0;
	for(int i=0; i<n; i++){
		e[i]=&qmem[ne];
		ne+=el[i];
		el[i]=0;
	}
	for(int i=0; i<n-1; i++){
		int A=edge[i][0];
		int B=edge[i][1];
		e[A][el[A]++]=B;
		e[B][el[B]++]=A;
	}
	comb_init(m);
	long ans = (long) m * perm(m-1, el[0]) % P;
	for(int i=0; i<el[0]; i++){
		int to = e[0][i];
		ans = ans * f(to, 0) % P;
	}
	printf("%ld\n", ans);
}


Measured memory_bytes: 8192
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <math.h>
#include <iomanip>
#include <queue>
#include <map>
#include <list>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX 50
#define LARGENUM 1000000007
#define INF 9223372036854775807
#define ull unsigned long long 
typedef pair <int, int> P;

int main(){
    int H, W, D, a, Q, L, R;
    cin >> H >> W >> D;
    P p[H * W + 1];
    int Distance[H * W + 1];
    for (int i = 1; i <= H; i++){
        for (int j = 1; j <= W; j++){
            cin >> a;
            p[a] = P(i, j);
        }
    }
    for (int k = 1; k <= D; k++){
        Distance[k] = 0;
        int I = k;
        while(I + D <= H * W){
            Distance[I + D] = Distance[I] + abs(p[I].first - p[I + D].first) + abs(p[I].second - p[I + D].second);
            I += D;
        }
    }
    cin >> Q;
    rep(i, Q){
        cin >> L >> R;
        cout << Distance[R] - Distance[L] << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    string str; cin >> str;
    int n = str.length();

    long long ans = 0;
    for (int bit = 0; bit < (1 << (n - 1)); bit++) {
        string exp = {str[0]};
        long long sum = 0;
        rep(i, n - 1) {
            if (bit & (1 << i)) {
                exp += str[i + 1];
            } else {
                sum += stoi(exp);
                exp = str[i + 1];
            }
        }
        if (exp != "") {
            sum += stoll(exp);
        }
        ans += sum;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
use std::io::*;
use std::cmp::*;

fn main() {
    let mut input = String::new();
    stdin().read_line(&mut input);

    let vec = input.split_whitespace()
        .map(|x| x.parse::<i32>().expect("parse error"))
        .collect::<Vec<i32>>();

    println!("{}", max(vec[2] - vec[0] + vec[1], 0));
}


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

using namespace std;

namespace {
    const size_t not_found = 1000000;

    size_t search(vector<int>& vec, size_t start, size_t end, int key) {
        if (start == end) {
            if (vec[start] == key) {
                return start;
            } else {
                return not_found;
            }
        } else {
            size_t mid_idx = (end - start) / 2 + start;
            int mid = vec[mid_idx];
            if (mid == key) {
                return mid_idx;
            } else if (mid < key) {
                return search(vec, mid_idx+1, end, key);
            } else {
                if (mid_idx == start ) {
                    return not_found;
                } else {
                    return search(vec, start, mid_idx-1, key);
                }

            }
        }
    }
}

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

    vector<int> t;
    t.reserve(100000);
    int count = 0;

    int in;

    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> in;
        t.push_back(in);
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> in;
        if (search(t,0,t.size()-1,in) != not_found)
            count += 1;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 1520
#include <string.h>
#include <stdio.h>
int main(void){
    int i, len;
    char str[102];
    
    scanf("%s", &str);
    len = strlen(str);
    
    printf("%c", str[0]);
    printf("%d", len-2);
    printf("%c", str[len-1]);
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 128
a,b,c,x=int(input()),int(input()),int(input()),int(input())
def c500(n):
  global a
  if n%500==0 and n<=500*a:return 1
  return 0
def c100(n):
  global b;ans=0
  for i in range(min(n//100,b)+1):ans+=c500(n-100*i)
  return ans
def c50(n):
  global c;ans=0
  for i in range(min(n//50,c)+1):ans+=c100(n-50*i)
  return ans
print(c50(x))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PLL;

LL k,x,y,arr[100009];

PLL doit(LL x,LL y,LL mod)
{
    LL z=(x-1)/mod;
    z=(z+1)*mod;
    if(z>y)
    {
        cout<<-1<<endl;
        exit(0);
    }
    x=z;
    z=y/mod;
    z=(z+1)*mod-1;
    y=z;
    return make_pair(x,y);
}

int main()
{
    scanf("%lld",&k);
    for(int i=1;i<=k;i++)scanf("%lld",&arr[i]);
    PLL p;
    x=y=2;
    for(int i=k;i>=1;i--)
    {
        p=doit(x,y,arr[i]);
        x=p.first;
        y=p.second;
    }
    cout<<x<<" "<<y<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
const ll maxn = 200000 + 10;

ll R, C, n, stk[maxn << 1], top = 0;
struct data{
  ll l, r;
  data() {}
  data(ll _l, ll _r):l(_l), r(_r) { if(l > r) swap(l,r); }
  
  friend bool operator < (data a, data b) {
    return a.l < b.l;
	}
}a[maxn], b[maxn << 1];

int main() {
  scanf("%d%d%d", &R, &C, &n);
  R ++; C ++; ll tot = 0;
  for(ll i = 1;i <= n;i ++) {
    ll x1, y1, x2, y2;
    scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
    x1 ++; x2 ++; y1 ++; y2 ++;
    if(x1 > x2) swap(x1,x2), swap(y1,y2);
    if(x1 == 1 && x2 == R) {
      a[++ tot] = data(R + C + C - y2 + 1,y1);
      continue;
		}
		if(y1 > y2) swap(x1,x2), swap(y1,y2);
		if(y1 == 1 && y2 == C) {
		  a[++ tot] = data(R + 2 * C + R - x1 + 1,C + x2); 
		  continue;
		}
		if(y2 == 1 && x1 == 1) swap(x1,x2), swap(y1,y2);
		if(y1 == 1 && x2 == 1) {
			a[++ tot] = data(R + 2 * C + R - x1 + 1,y2);
			continue;
		}
		if(y2 == 1 && x1 == R) swap(x1,x2), swap(y1,y2);
		if(y1 == 1 && x2 == R) {
		  a[++ tot] = data(R + 2 * C + R - x1 + 1,R + C + C - y2 + 1);
		  continue;
		}
		if(x2 == R && y1 == C) swap(x1,x2), swap(y1,y2);
		if(x1 == R && y2 == C) {
			a[++ tot] = data(R + C + C - y1 + 1,C + x2);
			continue;
		}
		if(x2 == 1 && y1 == C) swap(x1,x2), swap(y1,y2);
		if(x1 == 1 && y2 == C) {
			a[++ tot] = data(C + x2,y1);
			continue;
		}
		if(x1 == 1 && x2 == 1) {
		  a[++ tot] = data(y2,y1);
		  continue;
		}
		if(y1 == C && y2 == C) {
		  a[++ tot] = data(C + x2,C + x1);
		  continue;
		}
		if(x1 == R && x2 == R) {
		  a[++ tot] = data(R + C + C - y1 + 1,R + C + C - y2 + 1);
		  continue;
		}
		if(y1 == 1 && y2 == 1) {
		  a[++ tot] = data(R + 2 * C + R - x1 + 1,R + 2 * C + R - x2 + 1);
		  continue;
		}
	}
	ll cnt = 0;
	for(ll i = 1;i <= tot;i ++) {
	  b[++ cnt].l = a[i].l, b[cnt].r = i;
	  b[++ cnt].l = a[i].r, b[cnt].r = - i;
	}
	sort(b + 1,b + cnt + 1);
	top = 0;
	for(ll i = 1;i <= cnt;i ++) {
		if(b[i].r > 0) stk[++ top] = b[i].r;
		else {
		  if(stk[top] != - b[i].r) {
		    puts("NO");
		    return 0;
			}
			top --;
		}
	}
	if(top) puts("NO");
	else puts("YES");
  return 0;
}

Measured memory_bytes: 8448
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		char[] arr = sc.next().toCharArray();
		int left = Math.min(a, b) - 1;
		int right = Math.max(c, d) - 1;
		for (int i = left + 1; i < right - 1; i++) {
			if (arr[i] == '#' && arr[i + 1] == '#') {
				System.out.println("No");
				return;
			}
		}
		if (c > d) {
			boolean flag = false;
			for (int i = b - 2; i <= d - 2 && i < n - 2; i++) {
				if (arr[i] == '.' && arr[i + 1] == '.' && arr[i + 2] == '.') {
					flag = true;
					break;
				}
			}
			if (!flag) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 26412
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        vector<pair<int, int> > doll(n);
        for(int i=0; i<n; ++i)
            cin >> doll[i].first >> doll[i].second;

        int m;
        cin >> m;
        doll.resize(n+m);
        for(int i=0; i<m; ++i)
            cin >> doll[n+i].first >> doll[n+i].second;

        sort(doll.begin(), doll.end());
        vector<int> num(n+m, 1);
        for(int i=0; i<n+m; ++i){
            for(int j=0; j<i; ++j){
                if(doll[j].first < doll[i].first && doll[j].second < doll[i].second)
                    num[i] = max(num[i], num[j] + 1);
            }
        }
        cout << *max_element(num.begin(), num.end()) << endl;
    }
}

Measured memory_bytes: 0
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        if (x == 7 || x == 5 || x == 3)
            System.out.println("YES");
        else
            System.out.println("NO");
    }
}

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

#define int long long
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 a[100010] = {};
signed main(){
	int n;
	cin >> n;
	int ans = 0;
	for(int i = 0;i < n;i++){
		int at;
		cin >> at;
		a[at]++;
		ans += at;
	}

	int q;
	cin >> q;
	for(int i = 0;i < q;i++){
		int b, c;
		cin >> b >> c;
		ans -= b*a[b];
		ans += c*a[b];
		a[c] += a[b];
		a[b] = 0;
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 4344
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        d: i64,
        p: [(i64, i64); n],
    }

    let mut count = 0i64;
    for (xi, yi) in p {
        if xi * xi + yi * yi <= d * d {
            count += 1;
        }
    }

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


Measured memory_bytes: 7832