akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;
 
struct P {
    bool operator<(const P &p) const {
        return l < p.l;
    }
    int l, r;
};
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    int n;
    cin >> n;
 
    vector<P> p(n);
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        r++;
 
        p[i] = { l, r };
    }
    sort(p.begin(), p.end());
 
    if (n == 2) {
        int s = 0;
        for (int i = 0; i < n; i++) {
            int w = p[i].r - p[i].l;
            s += w;
        }
        cout << s << endl;
        exit(0);
    }
 
    int il = n - 1, l_max = p[il].l;
    int ir = -1, r_min = 1 << 30;
    for (int i = 0; i < n; i++) {
        if (p[i].r < r_min) {
            r_min = p[i].r;
            ir = i;
        }
    }
 
    int w_max = 0;
    for (int i = 0; i < n; i++) {
        if (i == il || i == ir) continue;
        int w = p[i].r - p[i].l;
        if (w > w_max) {
            w_max = w;
        }
    }
 
    int s0;
    {
        int w = max(p[ir].r - p[il].l, 0);
        s0 = w + w_max;//同じグループにした場合のスコア
    }
 
    if (il == ir) {
        cout << s0 << endl;
        exit(0);
    }
 
    int s1 = 0, r = p[il].r;
    for (int i = n - 1; i > 0; i--) {//il側に属するのが[i,n-1]とする
        r = min(r, p[i].r);
        int s = max(p[ir].r - p[i - 1].l, 0) + max(r - p[il].l, 0);
        s1 = max(s1, s);
    }
 
    cout << max(s0, s1) << endl;
 
    //左右に分けてしまいたくなる 片方を1問だけにするのも有効そう 同じ区間を2回に分けて使うこともある
    //バラバラだったら、一番長い1個を使うことになる
    //Lが最大のやつは、他のどれと組んでもLが悪化しない つまりそれを含むほうの左端はその最大のL
    //あくまでもそいつから見ればだが自分以上のRと組んでも悪化しない 引き受けることができる
    //3個以上残っててLが最大のとRが最小のやつが同じだったら除ける 何を加えても悪化しないので全部引き受ける
    //その2つ、同じグループだと最小の区間が出来上がる 何を加えても悪化しないので一番長い1個をもう片方にする N=2ならばらすだけ
    //違うグループとするとこれはO(N)でわかるんじゃ？ Rが最小のやつはLしか悪化しないから、全部取るところから始めて
    //そもそも片方を0問にするメリットはない
 
    return 0;
}

Measured memory_bytes: 1024
import math
import fractions
MOD=1000000007
n=int(input())
a=list(map(int,input().split()))
x=1
ans=0
for i in a:
  x=x*i//fractions.gcd(x,i)
for i in a:
  ans=ans+x//i
print(ans%MOD,'\n')

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

int main(){

  int N,K;
  cin >> N >> K;
  
  int ans = 1;
  
  for(int i = 0; i < N; ++i){
  
    if(2*ans < ans+K){
    
      ans *= 2;
    
    }else{
    
      ans += K;
    
    }
  
  }
  
  cout << ans << endl;
  
  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
// typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

// llong POW(llong a, llong b){
//   if(b == 0) return 1;
//   else{
//     if(b%2 == 0) return POW(a * a % MOD, b / 2) % MOD;
//     else return a * POW(a * a % MOD, b / 2) % MOD;
//   }
// }

int main(){
  int N, K;
  cin >> N >> K;
  if(N%K==0) cout << 0 << endl;
  else cout << 1 << endl;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author lstd
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>

using namespace std;

#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define RE(i, n) FOR(i,1,n)
#define REP(i,n) FOR(i, 0, (int)(n)-1)
#define fst first
#define snd second

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

string to_string(string s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string) s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}



void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

int XMOV[4] = {0, 0, 1, -1};
int YMOV[4] = {1, -1, 0, 0};

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

using namespace std;

class DFaceProducesUnhappiness {
public:
	void solve(std::istream& in, std::ostream& out) {
		int n, k;
		string s;
		in >> n >> k >> s;

		int numberOfHappyPeople = 0;
		for (int i = 1; i < n; i++){
			if(s[i] == s[i-1])
				numberOfHappyPeople++;
		}
		out << min(n-1, 2*k + numberOfHappyPeople);

	}
};

int main() {
	DFaceProducesUnhappiness solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    cin >> N;
    int in;
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> in;
        sum += (in - 1);
    }

    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 888
#include <stdio.h>  
#include <string.h>
#define M 500000
#define NIL -1

typedef struct node_tbl
{
	int key,p,l,r;
} node;

node T[M+1];
int root=NIL;
int size=0;

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

	T[z].key=k;
	T[z].l=NIL;
	T[z].r=NIL;

	while (x!=NIL)
	{
		y=x;
		if (T[z].key<T[x].key) x=T[x].l;
		else                   x=T[x].r;
	}

	T[z].p=y;
	if (y==NIL) root=z;
	else{
		if (T[z].key<T[y].key)
			T[y].l=z;
		else
			T[y].r=z;
	}
}

void find(int u){
    int id,x=0;
    scanf("%d",&id);
    while(1){
        if(T[x].key==0){
            printf("no\n");
            break;
        }
        else if(T[x].key==id){
            printf("yes\n");
            break;
        }
        else if(id<T[x].key) x=T[x].l;
        else if(id>T[x].key) x=T[x].r;   
    }
}


void inorder(int u){
	if (u==NIL) return;
	inorder(T[u].l);
	printf(" %d", T[u].key);
	inorder(T[u].r);
}

void preorder(int u){
	if (u==NIL) return;
	printf(" %d", T[u].key);
	preorder(T[u].l);
	preorder(T[u].r);
}

int main(){
	char o[8];
	int n,x,i;
	scanf("%d", &n);
	
	for (i=0;i<n;i++){
		scanf("%s",o);
		if(!strcmp("insert",o)){
			scanf("%d",&x);
			insert(x);
        }
        else if(!strcmp("find",o)) find(root);
		else if(!strcmp("print",o)){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;
}




Measured memory_bytes: 7984
A = int(input())
B = int(input())
C = int(input())
X = int(input())
 
counter = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if(500*a + 100*b + 50*c == X):
                counter += 1
print(counter)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n;
    cin, n;
    if (n % 2 == 1) {
        cout << 0 << endl;
    } else {
        n /= 2;
        auto func = [](ll k, int base) {
            ll ans = 0;
            while (k) {
                ans += k / base;
                k /= base;
            }
            return ans;
        };
        cout << min(func(n, 2) + 2 * n, func(n, 5)) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        int ans = 0;

        if (n < 105) ans = 0;
        else if (n < 135) ans = 1;
        else if (n < 165) ans = 2;
        else if (n < 189) ans = 3;
        else if (n < 195) ans = 4;
        else ans = 5;

        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
const int maxx=1e9+7;
int main()
{
    long long int sum=1;
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++)
    {
        sum = sum*i;
        sum=sum%maxx;
    }

    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define all(x) x.begin(),x.end()
#define ld long double
#define fast  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
signed main(){
    fast;
    int N;
    cin>>N;
    for(int w = 1;w<=3500;w++){
        for(int h = 1;h<=3500;h++){
            int num = N*w*h;
            int den = (int)4*w*h - N*(w+h);
            if(den>0){
                if(num%den == 0 && (num/den)<=3500){
                    cout<<h<<" "<<num/den<<" "<<w;
                    return 0;
                }
            }
        }
    }
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
a = list(map(int, input().split()))

# セグメント木を使うといいらしい

def update_max(k,x):
    k += num_max-1
    seg_max[k] = x
    while k:
        k = (k-1)//2
        seg_max[k] = max(seg_max[k*2+1],seg_max[k*2+2])

def query_max(p,q):
    if q<=p:
        return ide_ele_max
    p += num_max-1
    q += num_max-2
    res=ide_ele_max
    while q-p>1:
        if p&1 == 0:
            res = max(res,seg_max[p])
        if q&1 == 1:
            res = max(res,seg_max[q])
            q -= 1
        p = p//2
        q = (q-1)//2
    if p == q:
        res = max(res,seg_max[p])
    else:
        res = max(max(res,seg_max[p]),seg_max[q])
    return res

#####単位元######
ide_ele_max = 0

#num_max:n以上の最小の2のべき乗
# num_max =2**(n-1).bit_length()
num_max = 2**(len(str(bin(n-1))) -2)
seg_max=[ide_ele_max]*2*num_max

for i in range(n):
    h_i = h[i]
    update_max( h_i-1, query_max(0,h_i) + a[i] )

print(query_max(0,n))

Measured memory_bytes: 123856
def makelist(n, m):
    return [[0 for _ in range(m)] for _ in range(n)]
# 


s = input()
key = "keyence"
ind = 0

if s[:7] == key or s[7:] == key:
    print("YES")
else:
    ind = 0
    while ind < 7:
        if s[ind] == key[ind]:
            ind += 1
        else:
            break

    flag = True
    for i in range(7 - ind):
        if s[-i-1] != key[-i-1]:
            flag = False
            break
    if flag:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 38384
import heapq
n, m = map(int, input().split())
al = list(map(lambda x: (-1) * int(x), input().split()))
heapq.heapify(al)

for _ in range(m):
    al_min = heapq.heappop(al)
    heapq.heappush(al, (-1) * (-al_min // 2))

print(-sum(al))

Measured memory_bytes: 14180
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main() {
 ll n;
  string s;
  cin>>n>>s;
  bool all=true;
  rep(i,0,n){
   if(s[i]!=s[0])all=false;
  }
  if(all){
   cout<<0<<endl;
    return 0;
  }
  //////////////////
  int rcnt=0;//rの数
  rep(i,0,n){
    if(s[i]=='R')
  rcnt++;
  }
  ///////
  int ans=0;
  rep(i,rcnt,n){
    if(s[i]=='R')
    ans++;
  }
  
  
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3724
import sys
input = sys.stdin.readline

class Node:
    def __init__(self):
        self.is_root = True
        self.parent = None
        self.child_num = 0
    
    def root_node(self):
        node = self
        while not node.is_root:
            node = node.parent
        return node

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

    nodes = [Node() for i in range(N)]

    ab = [list(map(int, input().split())) for i in range(M)]
    
    inc = (N * (N-1)) // 2
    ans = [inc]
    for i in range(M-1, -1, -1):
        a, b = ab[i]
        a -= 1
        b -= 1
        root_a = nodes[a].root_node()
        if root_a != nodes[a]:
            nodes[a].parent = root_a
        root_b = nodes[b].root_node()
        if root_b != nodes[b]:
            nodes[b].parent = root_b
        if root_a == root_b:# もともと連結成分だった場合
            ans.append(inc)
        else:# 新たに連結成分になった場合
            if root_b.child_num > root_a.child_num:
                tmp = root_a
                root_a = root_b
                root_b = tmp
            inc -= (root_a.child_num + 1) * (root_b.child_num + 1)
            ans.append(inc)
            root_b.is_root = False
            root_b.parent = root_a
            root_a.child_num += root_b.child_num + 1

    for i in range(M-1, -1, -1):
        print(ans[i])

if __name__ == "__main__":
    main()



Measured memory_bytes: 49944
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
#define Lens 10005

using namespace std;
int a[Lens];
int prime(int i)
{
	if (i == 2 || i == 3)
		return 1;
	if (!(i % 6 == 1 || i % 6 == 5))
		return 0;
	int m = sqrt(i);
	for (int s = 5; s <= m; s+=6)
	{
		if (i%s == 0 || i % (s + 2) == 0)
		{
			return 0;
		}
	}
	return 1;
}

int main()
{
	int N;
	int sum = 0;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
		if (prime(a[i]))
			sum++;
	}
	cout << sum << endl;
	return 0;
}


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

typedef struct node{
  long key;
  struct node *left;
  struct node *right;
  struct node *p;
}Node;

void print_tree(Node *x,int order) {
  if (order == 0) {
    printf(" %ld", x->key);    
  }
  if(x->left != NULL) print_tree(x->left,order);
  if (order == 1) {
    printf(" %ld", x->key);    
  }
  if(x->right != NULL) print_tree(x->right,order);
  if (order == 2) {
    printf(" %ld", x->key);    
  }
}

Node *insert(Node *root, long key) {
  Node *z = (Node*)malloc(sizeof(Node));
  z->key = key;
  z->p = NULL;
  z->left = NULL;
  z->right = NULL;
  Node *x,*y;
  y = NULL;
  x = root;
  while(x != NULL) {
    y = x;
    if(z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->p = y;
  if(y  == NULL) return z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
  return root;
}

int search_tree(Node *root, long key) {
  Node *x = root;
  while(x != NULL) {
    if(x->key == key) return 1;
    else if(x->key > key) x = x->left;
    else if(x->key < key) x = x->right;
  }
  return 0;
}

Node *delete_node(Node *root, long key) {
  Node *x = root,*y = NULL;
  while(x != NULL) {
    if(x->key == key) break;
    y = x;
    if(x->key > key) x = x->left;
    else x = x->right;
  }
  if(x->left == NULL && x->right == NULL) {
    if(y == NULL) {
      free(x);
      return NULL;
    }
    if(y->key > key) y->left = NULL;
    else y->right = NULL;
    free(x);
    return root;
  }
  else if(x->left == NULL || x->right == NULL) {
    Node *z;
    if(x->left == NULL) z = x->right;
    if(x->right == NULL) z = x->left;
    if(y == NULL) {
      free(x);
      z->p = NULL;
      return z;
    }
    z->p = y;
    if(y->key > key) y->left = z;
    else x->p->right = z;
    free(x);
    return root; 
  }
  else{
    Node *z = x->right;
    while(z->left != NULL) z = z->left;
    long tmp = z->key;
    root = delete_node(root,tmp);
    x->key = tmp;
    return root;
  }
}

int main()
{
  long i,N,key;
  char command[7];
  Node *root = NULL;
  scanf("%ld",&N);
  for (i = 0; i < N; i++) {
    scanf("%s",command);
    if(strcmp(command,"insert") == 0) {
      scanf("%ld",&key);
      root = insert(root,key);
    }
    if(strcmp(command,"print") == 0) {
      print_tree(root,1);
      printf("\n");
      print_tree(root,0);
      printf("\n");
    }
    if(strcmp(command,"find") == 0) {
      scanf("%ld",&key);
      (search_tree(root,key) == 1) ? printf("yes\n") : printf("no\n");
    }
    if(strcmp(command,"delete") == 0) {
      scanf("%ld",&key);
      root = delete_node(root,key);
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  int N, M; cin >> N >> M;
  vector<int> H(N); rep(i, N) cin >> H.at(i);
  vector<int> A(M);
  vector<int> B(M);
  rep(i, M) cin >> A.at(i) >> B.at(i);
  int ans = 0;
  vector<int> good(N, 1);
  rep(i, M) {
    if(H.at(A.at(i)-1)>H.at(B.at(i)-1)){
      good.at(B.at(i)-1) = 0;
    } else if (H.at(A.at(i)-1)<H.at(B.at(i)-1)) {
      good.at(A.at(i)-1) = 0;
    } else {
      good.at(A.at(i)-1) = 0;
      good.at(B.at(i)-1) = 0;
    }
  }
  rep(i, N) ans += good.at(i);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4844
#include <iostream>
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long int ulli;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
/* TUMSE NAA HO PAAYEGA HAR DO DIN MAI LAGEGA
   LEKIN RUKNE KA NAHI :P */

int main() {
	// your code goes here
	FASTIO
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	ll ans=a*c;
	ans=max(ans,a*d);
	ans=max(ans,b*c);
	ans=max(ans,b*d);
	cout << ans;
	return 0;
}


Measured memory_bytes: 3636
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int a, b, q;
    cin >> a >> b >> q;

    vector<ll> s(a);
    vector<ll> t(b);
    for(int i = 0; i < a; i++) cin >> s[i];
    for(int i = 0; i < b; i++) cin >> t[i];
    vector<ll> qu(q);
    for(int i = 0; i < q; i++) cin >> qu[i];
    for(int i = 0; i < q; i++){
        ll x = qu[i];

        ll nearsb = lower_bound(all(s), x) - s.begin() - 1;
        ll nearsf = nearsb + 1;

        ll neartb = lower_bound(all(t), x) - t.begin() - 1;
        ll neartf = neartb + 1;

        ll ans = INF;

        if(nearsb >= 0 && neartb >= 0){
            ans = min(ans, max(abs(x - s[nearsb]), abs(x - t[neartb])));
        }

        if(nearsf < a && neartf < b){
            ans = min(ans, max(abs(x - s[nearsf]), abs(x - t[neartf])));
        }

        if(nearsb >= 0 && neartf < b){
            ans = min(ans, abs(x - s[nearsb]) * 2 + abs(x - t[neartf]));
            ans = min(ans, abs(x - s[nearsb]) + abs(x - t[neartf]) * 2);
        }
 
        if(nearsf < a && neartb >= 0){
            ans = min(ans, abs(x - s[nearsf]) * 2 + abs(x - t[neartb]));
            ans = min(ans, abs(x - s[nearsf]) + abs(x - t[neartb]) * 2);
        }

        cout << ans << endl;
    }
}   

Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <stack>
using namespace std;

int main(){
  int n,k;string s;cin>>n>>s>>k;
  char tar=s[k-1];
  for(int i=0;i<n;++i)
	if(s[i]!=tar)s[i]='*';
  cout<<s<<endl;
  return 0;
}


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

#define int long long

bool check(int x, int y) {
    while(x % y == 0) x /= y;
    return x % y == 1;
}

signed main() {
    int n;
    cin >> n;
    int ans = 1;
    for (int i =2 ; i <= sqrt(n); ++i) {
        if (n % i == 0) {
            if (check(n, i)) ++ans;
            if (i * i != n && check(n, n / i)) ++ans;
        }
    }
    if (n > 2) {
        ++ans;
        for (int i = 2; i <= sqrt(n - 1); ++i) {
            if ((n - 1) % i == 0) {
                ++ans;
                int z = (n - 1) / i;
                if (z != i) ++ans;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		char[] s = sc.next().toCharArray();
		int N = s.length;
		
		int ans = N;
		for(int i=1; i<N; i++) {
			if(s[i]!=s[i-1]) {
				ans = Math.min(ans, Math.max(i, N-i));
			}
		}
		
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 28500
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

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

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

struct Edge {
	ll to, cost, rev;
	int done; // 1:?????? 2:??????
	Edge() {}
	Edge(ll to, ll cost, ll rev) : to(to), cost(cost), rev(rev) { done = 0; }
};

vector<Edge> g[100000];
ll d[100000];
ll N, M, C, D;
bool used[100000];

int main() {
	cin >> N >> M >> C;
	
	REP(i, M) {
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		a--; b--;
		g[a].push_back(Edge(b, c, g[b].size()));
		g[b].push_back(Edge(a, c, g[a].size() - 1));
		D += c;
	}
	
	fill(d, d + N, -1);
	priority_queue<pll, vector<pll>, greater<pll> > pq; // d, pos
	
	pq.push(pll(0, 0));
	d[0] = 0;
	while (!pq.empty()) {
		pll now = pq.top(); pq.pop();
		
		ll cost = now.first;
		ll pos = now.second;
		
		if (d[pos] != -1 && d[pos] < cost) continue;
		
		REP(i, g[pos].size()) {
			Edge e = g[pos][i];
			if (d[e.to] == -1 || d[e.to] > cost + e.cost) {
				d[e.to] = cost + e.cost;
				pq.push(pll(d[e.to], e.to));
			}
		}
	}
	
	ll ans = D;
	REP(i, N) pq.push(pll(d[i], i));
	while (!pq.empty()) {
		pll now = pq.top(); pq.pop();
		
		ll cost = now.first;
		ll pos = now.second;
		
		REP(i, g[pos].size()) {
			Edge &e = g[pos][i];
			if (e.done == 2) continue;
			e.done++;
			g[e.to][e.rev].done++;
			if (e.done == 2) D -= e.cost;
		}
		
		ans = min(ans, cost * C + D);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 26768
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk

using namespace std;

inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }

const int N = 1000003;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = 1000003;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 26;

ll bin_pow(ll a, ll p) {
    ll res = 1;
    while (p) {
        if (p & 1) {
            res = res * a % MOD;
        }
        a = a * a % MOD;
        p >>= 1;
    }
    return res;
}

ll rev(ll x) {
    return bin_pow(x, MOD - 2);
}

ll fact[N], rfact[N];

void init() {
    fact[0] = 1;
    rep(i, 1, N) {
        fact[i] = fact[i - 1] * i % MOD;
    }
    rfact[N - 1] = rev(fact[N - 1]);
    repb(i, N - 2, -1) {
        rfact[i] = rfact[i + 1] * (i + 1) % MOD;
    }
}

ll C(int n, int k) {
    if (k < 0 || k > n) {
        return 0;
    }
    return fact[n] * rfact[k] % MOD * rfact[n - k] % MOD;
}

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    init();
    int q;
    cin >> q;
    while (q--) {
        ll x, d, n;
        cin >> x >> d >> n;
        if (d == 0) {
            cout << bin_pow(x, n) << "\n";
            continue;
        }
        ll ans = bin_pow(d, n);
        x = x * rev(d) % MOD;
        if (x == 0 || x + (n - 1) >= MOD) {
            cout << 0 << "\n";
            continue;
        }
        cout << ans * fact[x + (n - 1)] % MOD * rfact[x - 1] % MOD << "\n";
    }
    return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sz(a) signed(a.size())
using namespace std;

void solve(){
	ll n;
	cin >> n;
	ll op=0;
	for(ll i=2;i*i<=n;i++){
		ll f = 0;
		while(n%i == 0){
			n/=i;
			f++;
		}
		ll cnt = 0,itr=0;
		while(cnt<=f){
			++itr;
			cnt += itr;
		}
		op += max(0ll,(itr-1));
	}
	op += n>1;
	cout << op;
}

int main() {
    FAST;
    ll t=1;
    //cin>>t;
    while(t--) solve();	
    return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int MOD = 1000000007;

int main()
{
	int n = 0;
	cin >> n;
	double sum = 0;
	double a = 0;
	string b = "";
	for (int i = 0; i < n; i++)
	{
		cin >> a >> b;
		if (b == "JPY")
		{
			sum += a;
		}
		else
		{
			sum += a * 380000;
		}
	}
	cout << sum << "\n";
	return 0;
}

Measured memory_bytes: 256
import itertools
import numpy as np
N, M, X = map(int, input().split())
book = [list(map(int, input().split())) for _ in range(N)]
ans = float('inf')
for i in range(1, 13):
    for v in itertools.combinations(book, i):
        l = np.array([0]*(M+1))
        flag = True
        for ele in v:
            l += np.array(ele)
        l = list(l)
        for j in range(1, len(l)):
            if l[j] < X:
                flag = False
        if flag:
            ans = min(ans, l[0])
if ans == float('inf'):
  print(-1)
else:
  print(ans)

Measured memory_bytes: 27220
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int n,m,cnt=0,aa[220000],cntl=0;
pair<int,int> p[220000];
string s,ss[110000];
char c;
queue<int> que;
signed main(){
    cin>>n;
    rep(i,9){
        que.push(i+1);
    }
    while(1){
        cnt++;
        if(cnt==n){
            cout<<que.front();
            return 0;
        }
        if(que.front()%10!=0){
            que.push(que.front()*10+que.front()%10-1);
        }
        que.push(que.front()*10+que.front()%10);
        if(que.front()%10!=9){
            que.push(que.front()*10+que.front()%10+1);
        }
        que.pop();
    }
}

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

using namespace std;

int main(void){
	int a, b, c, d;
	scanf("%d\n%d\n%d\n%d", &a, &b, &c, &d);
	printf("%d\n", min(a, b) + min(c, d));
	return 0;
}

Measured memory_bytes: 764
using System;
using System.Linq;
using System.Collections.Generic;

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

            var sol = new Solve(N, array);
            sol.Dfs(0, 0, 0);
            Console.WriteLine(sol.Max);

        }
    }

    public class Solve
    {
        public int N { get; set; }
        public int[][] Array { get; set; }
        public int Max { get; set; } = 0;

        public Solve(int n, int[][] array)
        {
            N = n;
            Array = array;
        }

        public void Dfs(int x, int y, int total)
        {
            if (y == 1 && x == N)
                Max = Math.Max(total, Max);

            if (y < 1 && x < N)
                Dfs(x, y + 1, total + Array[y][x]);
            if (x < N)
                Dfs(x + 1, y, total + Array[y][x]);
        }
    }
}


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

int main(){
	int n;cin>>n;
	vector<int> dp(3);
	for(int i = 0; i < n; i++){
		vector<int> newdp(3);
		int a,b,c;
		cin>>a>>b>>c;
		newdp[0] = max(dp[1] + a, dp[2] + a);
		newdp[1] = max(dp[0] + b, dp[2] + b);
		newdp[2] = max(dp[0] + c, dp[1] + c);
		dp = newdp;
	}
	cout<<max({dp[0],dp[1],dp[2]});
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
	int i,min,max,a[10000],n;
	long sum;
	
	cin >> n;

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

	min=a[0];
	max=a[0];
	sum=a[0];

	for(i=1 ; i<n ; i++){
		if(a[i]<min) min=a[i];
	}
	for(i=1 ; i<n ; i++){
		if(a[i]>max) max=a[i];
	}
	for(i=1 ; i<n ; i++){
		sum=sum+a[i];
	}
	cout << min << " " << max << " " << sum << endl;

	return 0;
}

Measured memory_bytes: 1200
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
       	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int count = 0;
      	String s = br.readLine();
     	String t = br.readLine();
      	for(int i=0; i<3; i++) {
          	if(s.charAt(i) == t.charAt(i)) {
              	count++;
			}
		}
		System.out.println(count);
        
	}
}


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

#define  pf                  printf
#define  sc                  scanf
#define  PI                  2*acos(0.0)
#define  fast                ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define  mem(a,b)            memset(a, b, sizeof(a) )
#define  gcd(a,b)            __gcd(a,b)
#define  lcm(a,b)            (a*(b/gcd(a,b)))
#define  MAX                 1234567899
#define  mod                 1000000007
#define  all(v)              (v).begin(),(v).end()
#define  vSort(v)            sort(all(v))
#define  maxSort(v)          sort(all(v),greater<int>())
#define  Unique(v)           v.erase(unique(all(v)),v.end())
#define  sqr(x)              ((x)*(x))
#define  qube(x)             ((x)*(x)*(x))
#define  deci(n)             cout<<fixed<<setprecision(n)
#define  sci(n)              sc("%d",&(n))
#define  scii(x,y)           sc("%d %d",&(x),&(y))
#define  scl(x)              sc("%lld",&(x))
#define  scll(x,y)           sc("%lld %lld",&(x),&(y))
#define  vi                  vector<int>
#define  hi                  pf(" HI \n")
#define  pp                  pair<int,int>
#define  pb(x)               push_back(x)
#define  mp(x,y)             make_pair(x,y)
#define  F                   first
#define  S                   second
#define  check(n,pos)        (n & (1<<(pos)))
#define  biton(n,pos)        (n  (1<<(pos)))
#define  bitoff(n,pos)       (n & ~(1<<(pos)))
typedef  long long int       lli;
typedef  unsigned long long int ulli;
int dx4[] = { 0 , 0 , -1 , 1 } ;
int dy4[] = { -1 , 1 , 0 , 0 } ;
bool valid( int r , int c , int x , int y ){
    if( x >= 1 && x <= r && y >= 1 && y <= c ) return 1 ; return 0 ;}

using namespace std;

int main ()
{
    float a,b,ans;
    cin >> a>> b;
    ans= a/b;
    deci(10);
    cout << ans <<endl;

    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define inf (1<<26)

int ret , n;
vector<int> table;
void dfs(int sum , int pos , int depth , int c){
	if(sum > n)return;
	
	if(depth == c-1){
		if(binary_search(table.begin()+pos,table.end(),n-sum))ret++;
		return;
	}
	for(int i = pos ; i < table.size(); i++){
		dfs(sum+table[i],i,depth+1,c);
	}
}
int main(){
	
	for(int i = 1 ; i*i <= (1<<15) ; i++){
		table.push_back(i*i);
	}
	while(cin >> n , n){
		ret = 0;
		for(int i = 1 ; i < 5 ; i++){
			dfs(0,0,0,i);
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 908
using System;
class Program
{
    private bool check(int[] s, int k)
    {
        return (s[k] != s[k + 1]) ? true : false;
    }
    public static void Main()
    {
        Program prog = new Program();
        string str = Console.ReadLine();
        int[] s = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
            s[i] = (int)Char.GetNumericValue(str[i]);
        int t = str.Length;
        if (str.Length > 1)
        {
            for (int j = 0; j < str.Length - 1; j++)
            {
                if (prog.check(s, j))
                    if (Math.Max(j + 1, str.Length - j - 1) < t)
                        t = Math.Max(j + 1, str.Length - j - 1);
            }
        }
        else
            t = 1;
        Console.WriteLine(t);
    }
}

Measured memory_bytes: 13792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define FOR(i,a,n) for(i=a;i<n;i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
char str[100001];
int main(void)
{
	int i,len;
	scanf("%s",str);
	len=strlen(str);
	FOR(i,0,len-1){
		if(str[i]==str[i+1]){
			printf("%d %d\n",i+1,i+2);
			return 0;
		}
		else if(i+2<len&&str[i]==str[i+2]){
			printf("%d %d\n",i+1,i+3);
			return 0;
		}
	}
	puts("-1 -1");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //AtCoder
#include <iostream> //Codeforces
#include <vector> //Codeforces

#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Vc vector<char>
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl

using namespace std;
/****************************** START ******************************/

signed main(){
  int N;
  cin >> N;
  int cnt = 0;
  repeq(i,1,1000){
    repeq(j,i,1000000){
      if (i * j < N){
        if (i == j){
          cnt++;
        } else {
          cnt += 2;
        }
      }
    }
  }
  cout << cnt;
}


Measured memory_bytes: 3612
A, B, H, M = map(int, input().split())

import math

# print(H)
# print(360*(H%12)/12)
# print(360*(M%60)/60)

H = H + M/60
# print(H)
# exit()

tH = math.radians(360*(H%12)/12)
tM = math.radians(360*(M%60)/60)
# print(math.sin(tH))
# print(math.cos(tH))
# exit()
# print(math.sin(tM))
# print(math.cos(tM))


# pH = (A*math.cos(tH), A*math.sin(tH))
# pM = (B*math.cos(tM), B*math.sin(tM))

pH = (A*math.sin(tH), A*math.cos(tH))
pM = (B*math.sin(tM), B*math.cos(tM))

D = (pH[0] - pM[0])**2 + (pH[1] - pM[1])**2


print(D**0.5)


# posH = A * (H%12*360)


Measured memory_bytes: 9576
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
/**************************************************************************/
signed main() 
{
    fast;
    int l,r;
    cin>>l>>r;
    if(r-l+1>=2019)
        cout<<0;
    else
    {
        int ans = 1e18;
        for(int i=l;i<r;i++)
        {
            for(int j=i+1;j<=r;j++)
            {
                int p = i*j;
                ans = min(ans,p%2019);
            }
        }
        cout<<ans;
    }
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{

    char a[100000], b[100000];
    int i, t = 0, j = 0;

    scanf("%s", a);

    while(a[t])
        t++;

    for(i = 0; i < t; i += 2) {
        b[j] = a[i];
        j++;
    }
    b[j + 1] = '\0';
    printf("%s\n", b);

    return 0;
}

Measured memory_bytes: 384
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define lint long long

using namespace std;

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

  if(n>=10){
    cout << r << endl;
  }else{
    cout << r+100*(10-n) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){if(a%b==0)return b;return gcd(b,a%b);}
int lcm(int a,int b){int c=gcd(a,b);return ((a/c)*(b/c)*c);}
int main(){
	int a,b;
	while(scanf("%d %d",&a,&b)!=EOF){
		cout << gcd(a,b) << " " << lcm(a,b) << endl;
	}
}


Measured memory_bytes: 3244
#pragma warning(disable:4996)

#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <complex>
#include <iterator>
#include <random>
#include <time.h>
#include <tuple>
#include <functional>
#include <list>
#include <limits.h>
#define mp make_pair
#define ni(x) scanf("%d", &(x))
#define nii(x,y) scanf("%d%d",&(x),&(y))
#define mul(x,y) ((ll)(x)*(y)%mod)
#define mtp make_tuple
#define F(i,n) for(int i = 0; i < (n); i++)
#define FF(i,n) for(int i = 1; i <= (n); i++)
#define FE(i,n) for(int i = 0; i <= (n); i++)

#ifndef __GNUG__
int __builtin_popcount(int n) {
	int x = 0;
	while (n)n -= n&(-n), x++;
	return x;
}
#endif

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
const int mod = 1000000007;
const int inf = 2012345678;
const ll infl = 9012345678901234567;
const double pi = 3.1415926535897932384626433832795;
//----------------------------------------------------------------------------//

const int N = 100000;
vector<int> adj[N];

int dfs(int u, int p = -1) {
	int ret = 0;
	for (auto &x : adj[u]) {
		if (x == p)continue;
		int g = dfs(x, u);
		ret ^= g + 1;
	}
	return ret;
}

int main() {
#ifndef __GNUG__
	freopen("input.txt", "r", stdin);
#endif
	int n; ni(n);
	F(i, n - 1) {
		int u, v; nii(u, v);
		u--; v--;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	int x = dfs(0);
	if (x)puts("Alice");
	else puts("Bob");
	return 0;
}


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

int main()
{
  int n;
  int* p;

  cin >> n;

  p = new int[n];

  for(int i=0; i<n; i++)
    p[i]=0;

  for(int i=0; i<n-1; i++){
    int data;
    cin >> data;
    p[data-1]++;
  }

  for(int i=0; i<n; i++)
    cout << p[i] <<endl;
  
  delete[] p;
  
  return 0;
}

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

int main() {
  int N, D;
  cin >> N >> D;
  
  long long X_i, Y_i;
  
  int count = 0;
  double distance;
  for (int i = 0; i < N; i++){
    cin >> X_i >> Y_i;
  
	distance = sqrt(X_i * X_i + Y_i * Y_i);    
    if (distance <= D)
      count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define ll long long
#define V vector<long long>
#define VV vector<vector<long long>>
#define VVV vector<vector<vector<long long>>>
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0;(i)<(n);++(i))
using namespace std;

bool kai(string s,ll st,ll en){
    while(st<en){
        if(s[st]!=s[en]){
            return false;
        }
        st++;
        en--;
    }
    return true;
}

int main() {
    string s;
    cin>>s;
    if(!kai(s,0,s.size()-1)){
        cout<<"No"<<endl;
        return 0;
    }
    if(!kai(s,0,(s.size()-1)/2-1)){
        cout<<"No"<<endl;
        return 0;
    }
    if(!kai(s,(s.size()+3)/2-1,s.size()-1)){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  Name:- OMHARI 
  Institution:- UNIVERSIT OF CALCUTTA(INFORMATION TECHNOLOGY)
  Email:- omharicu@gmail.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include<bits/stdc++.h>
using namespace std; 

#define F               first
#define S               second
#define ull             unsigned long long
#define ll              long long
#define ul              unsigned long
#define db              double
#define ST              string
#define pb              push_back
#define mp              make_pair
#define el              "\n"
#define vll             vector <ll>
#define vl              vector <long int>
#define vi              vector <int>
#define all(v)          (v.begin(), v.end()) 
#define rall(v)         (v.rbegin(), v.rend()) 
#define is_sort(v)      is_sorted all(v)
#define max_of(v)       *max_element all(v)
#define min_of(v)       *min_element all(v)
#define itos(s)         to_string(s)
#define cntone(x)       __builtin_popcountll(x)
#define cntzro(x)       __builtin_clz(x)
#define For(i, a, b)    for(int i=a; i<b; i++)
#define Forr(i, a, b)    for(int i=a; i>=b; i--)
const ll mod = 1e9+7;

vi arr[2*100005];
int vis[2*100005];
int cnt=0;

void dfs(int node)
{
    cnt++;
    vis[node]=1;

    for(int child : arr[node])
    if(!vis[child])
    dfs(child);
}

void solve()
{
    int n,m;
    cin>>n>>m;
    while(m--)
    {
        int x,y;
        cin>>x>>y;
        arr[x].pb(y);
        arr[y].pb(x);
    }
    int ans=0;
    For(i, 1, n+1)
    {
        cnt=0;
        if(!vis[i])
        {
            dfs(i);
            ans=max(ans, cnt);
        }
    }

    cout<<ans;
}

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

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    /***************-Code starts from here-***************/
    // int t;
    // cin>>t;
    // while(t--)
    solve();
    return 0; 
} 

Measured memory_bytes: 21600
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
V<ll> g[100005];
ll cnt[100005];
ll solve(int cur){
    V<ll> tmp;
    for(int v:g[cur]){
        tmp.push_back(solve(v));
    }
    if(tmp.size()==0)return 0ll;
    ll res=0;
    sort(all(tmp),greater<ll>());
    for(int i=0;i<tmp.size();i++){
        chmax(res,tmp[i]+i+1);
    }
    return res;
}
int main(){
  ll n;
  cin>>n;
  V<ll> a(n);
  for(int i=0;i<n-1;i++){
      cin>>a[i];
      g[a[i]-1].push_back(i+1);
  }
  cout<<solve(0)<<"\n";
}


Measured memory_bytes: 20252
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
	
ll dp[100010][3];
int main(){
	ll n;
	ll a[100010],b[100010],c[100010];
	cin>>n;
	rep(i,0,n)cin>>a[i]>>b[i]>>c[i];
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	rep(i,0,n){
		rep(j,0,3){
			if(j==0){
				dp[i+1][1]=max(dp[i+1][1],dp[i][0]+b[i+1]);
				dp[i+1][2]=max(dp[i+1][2],dp[i][0]+c[i+1]);
			}
			if(j==1){
				dp[i+1][0]=max(dp[i+1][0],dp[i][1]+a[i+1]);
				dp[i+1][2]=max(dp[i+1][2],dp[i][1]+c[i+1]);
			}
			if(j==2){
				dp[i+1][1]=max(dp[i+1][1],dp[i][2]+b[i+1]);
				dp[i+1][0]=max(dp[i+1][0],dp[i][2]+a[i+1]);
			}
		}
	}
	ll ans=0;
	rep(i,0,3)ans=max(ans,dp[n-1][i]);
	cout<<ans<<endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    string S; cin >> S;
    if (S == "Sunny") cout << "Cloudy" << endl;
    if (S == "Cloudy") cout << "Rainy" << endl;
    if (S == "Rainy") cout << "Sunny" << endl;
}

Measured memory_bytes: 256