akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>

template<typename T>
class BinTree;

template<typename T>
class Node {
    T value;
    Node<T> *parent, *left, *right;
    Node (T _value) : value(_value) {
        parent = nullptr;
        left = nullptr;
        right = nullptr;
    }
    Node (){
        parent = nullptr;
        left = nullptr;
        right = nullptr;
    }
    friend BinTree<T>;
    public:
    void inorder(std::vector<T> &ret) {
        if(left) left->inorder(ret);
        ret.push_back(value);
        if(right) right->inorder(ret);
    }
    void preorder(std::vector<T> &ret) {
        ret.push_back(value);
        if(left) left->preorder(ret);
        if(right) right->preorder(ret);
    }
    void postorder(std::vector<T> &ret) {
        if(left) left->postorder(ret);
        if(right) right->postorder(ret);
        ret.push_back(value);
    }
};

template<typename T> 
class BinTree{
    Node<T> *root;
    size_t size;
    void insert_main(Node<T> *z) {
        Node<T> *y = nullptr, *x = root;
        while(x) {
            // std::cout << x << '\n';
            y = x;
            if(z->value < x->value) {
                x = x->left;
            }
            else {
                x = x->right;
            }
        }
        z->parent = y;
        if(y == nullptr) {
            root = z;
        }
        else if(z->value < y->value) {
            y->left = z;
        }
        else {
            y->right = z;
        }
    }
    bool find_main(T x) {
        Node<T> *y = root;
        while(y) {
            if(y->value == x) {
                return true;
            }
            if(x < y->value) {
                y = y->left;
            }
            else {
                y = y->right;
            }
        }
        return false;
    }
    public:
    BinTree() {
        root = nullptr;
        size = 0;
    }
    bool empty() {return size == 0;}
    void insert(T x) {
        Node<T> *z = new Node<T>(x);
        insert_main(z);
    }
    bool find(T x) {return find_main(x);}
    void preorder(std::vector<T> &ret) {root->preorder(ret);}
    void inorder(std::vector<T> &ret) {root->inorder(ret);}
    void postorder(std::vector<T> &ret) {root->postorder(ret);}
};

template<typename T>
void vdeb(std::vector<T> &da) {
    size_t size = da.size();
    for(int i = 0; i < size; ++i) {
        std::cout << ' ' <<  da[i];
    }
    std::cout << '\n';
}

int main() {
    int n; std::cin >> n;
    BinTree<int> bt;
    for(int i = 0; i < n; ++i) {
        std::string s;
        std::cin >> s;
        if(s == "insert") {
            int x; std::cin >> x;
            bt.insert(x);
        }
        else if(s == "find") {
            int x; std::cin >> x;
            std::printf(bt.find(x)?"yes\n":"no\n");
        }
        else if(s == "print") {
            std::vector<int> pre(0), mid(0);
            bt.preorder(pre);
            bt.inorder(mid);
            vdeb(mid);
            vdeb(pre);
        }
    }
}


Measured memory_bytes: 26304
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    static final FS sc = new FS();  // 封装输入类
    static final PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {
        int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt();
        int k = sc.nextInt();
        if (solve(a, b, c, k)) {
            pw.println("Yes");
        } else {
            pw.println("No");
        }
        pw.flush();
    }

    static boolean solve(int a, int b, int c, int k) {
        while (a >= b) {
            b *= 2;
            k--;
            if (k < 0) {
                return false;
            }
        }
        while (b >= c) {
            c *= 2;
            k--;
            if (k < 0) {
                return false;
            }
        }
        return true;
    }

    static class FS {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");
        String next() {
            while(!st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch(Exception ignored) {}
            }
            return st.nextToken();
        }
        int[] nextArray(int n) {
            int[] a = new int[n];
            for(int i = 0;i < n;i++) {
                a[i] = nextInt();
            }
            return a;
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 32888
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	var pre int = -999
	for i := 0; i < n; i++ {
		if pre <= a[i]-1 {
			pre = a[i] - 1
		} else if pre <= a[i] {
			pre = a[i]
		} else {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 5504
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define Inf 1000000000
#define nmax_def 110000
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;

int main() {
	int N;
	cin >> N;
	vector<double> x(N);
	vector<double> y(N);
	rep(i, N) {
		cin >> x[i] >> y[i];
	}
	double ans = 10000.0;

	double X = 0.0;
	double Y = 0.0;
	vector<pair<double, int>> dstlist(N);
	rep(i, N) {
		dstlist[i].first = (x[i] - X) * (x[i] - X) + (y[i] - Y) * (y[i] - Y);
		dstlist[i].second = i;
	}
	double cent_ratio = 1.0;
	double cent_ratio_dist = 0.9999;
	rep(n, 2000000) {
		sort(dstlist.begin(), dstlist.end(), greater<pair<double, int>>());
		X = X * (1.0 - cent_ratio) + x[dstlist[0].second] * cent_ratio;
		Y = Y * (1.0 - cent_ratio) + y[dstlist[0].second] * cent_ratio;
		rep(i, N) {
			dstlist[i].first = (x[i] - X) * (x[i] - X) + (y[i] - Y) * (y[i] - Y);
			dstlist[i].second = i;
		}
		cent_ratio *= cent_ratio_dist;
	}
	double anstmp = 0.0;
	rep(n, N) {
		double dist_tmp = sqrt((x[n] - X) * (x[n] - X) + (y[n] - Y) * (y[n] - Y));
		anstmp = max(anstmp, dist_tmp);
	}
	ans = min(ans, anstmp);
	printf("%.12f\n", ans);
	return 0;
}

Measured memory_bytes: 384
while True:
    (m, f, r) = [int(i) for i in input().split()]
    if m == f == r == -1:
        break
 
    s = m + f
 
    if m == -1 or f == -1 or s < 30:
        print('F')
    elif s < 50 and r < 50:
        print('D')
    elif s < 65:
        print('C')
    elif s < 80:
        print('B')
    else:
        print('A')

Measured memory_bytes: 6720
#include<iostream>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue> 
#include<stack>
#include<vector>
#include<map>
#include<set>

#define ll long long
#define pb push_back
#define ff first
#define ss second

using namespace std;

struct cmpr{
    bool operator()(pair<string,pair<int,int> > a,pair<string,pair<int,int> > b) const{
        if(a.ff == b.ff){
            return a.ss.ff>b.ss.ff;
        }
        else{
            return a.ff<b.ff;
        }
    }
};

int main(){
   int n;
   cin>>n;
   vector<pair<string,pair<int,int> > > r;
   int p;
   string s;
   int i=1;
   while(n--){
       cin>>s>>p;
       r.pb({s,{p,i}});
       i++;
   }
   sort(r.begin(),r.end(),cmpr());
    for(int i=0;i<r.size();i++){
        cout<<r[i].ss.ss<<endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
const int N=2e5+5;
using namespace std; 
char s[N];
int main(){
	int n,num=0,ans=0;scanf("%d%s",&n,s);
	for(int i=0;s[i];i++)num+=(s[i]=='W');
	for(int i=n-1;~i;i--){
		if(!num)break;
		ans+=(s[i]=='R'),num--;
	}
	printf("%d",ans);
	return 0;
}

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

using namespace std;
typedef long long ll;


int main(){
    ll n, z, w;
    cin >> n >> z >> w;
    vector<ll> card(n);
    for(int i = 0; i < n; ++i){
        cin >> card.at(i);
    }
    ll ans = abs(card.at(n - 1) - w);
    if(n > 1){
        ans = max(ans, abs(card.at(n - 1) - card.at(n - 2)));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner cin = new Scanner(System.in);

		String[] work = cin.nextLine().split(" ");
		int a = Integer.parseInt(work[0]);
		int b = Integer.parseInt(work[1]);
		int c = Integer.parseInt(work[2]);

		int min = getMin(a + b, a + c, b + c);

		System.out.println(min);

		cin.close();
	}

	private static int getMin(int a, int b, int c) {
		int min = a;
		if (min > b) {
			min = b;
		}
		if (min > c) {
			min = c;
		}

		return min;
	}
}

Measured memory_bytes: 21844
#include<iostream>

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	char s[5];
	cin>>s;
	
	sort(s,s+4);
	
	if(s[0]==s[1] && s[2]==s[3] && s[1]!=s[2])
		cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		int gcd = 1, n;
		scan.close();
		
		if ( x == y) {
			gcd = x;
		} else {
			if (x > y) {
				n = x % y;
				gcd = Gcd(y,n);
			}else {
				n = y % x;
				gcd = Gcd(x,n);
			}
		}
		
		System.out.println(gcd);
		
	}
	
	public static int Gcd(int a, int b) {
		int gcd = 1;
		int n;
		
		n = Math.min(a, b);
		
		for (int i = n; i >= 1; i--) {
			if (a % i == 0 && b % i == 0) {
				gcd = i;
				break;
			}
			
		}
		
		return gcd;
	}
}



Measured memory_bytes: 26408
#include <random>
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld eps = 1e-12;
constexpr int inf = numeric_limits<int>::max() / 2;
constexpr ll mod = 1e9 + 7;
mt19937_64 rnd{random_device()()};

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

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

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  const int K_MAX = 100;
  for (int i = 0; i < min(K_MAX, k); i++) {
    auto tmp = a;
    for (int j = 0; j < n; j++) a[j] = 0;
    for (int j = 0; j < n; j++) {
      int l = max(j - tmp[j], 0);
      int r = min(n - 1, j + tmp[j]);
      a[l]++;
      if (r + 1 < n) a[r+1]--;
    }
    for (int j = 1; j < n; j++) a[j] += a[j - 1];
  }
  printv(a);
}


Measured memory_bytes: 4980
# AGC033A - Darker and Darker
def bfs() -> None:
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    cur, q = 0, []
    for x, b in enumerate(B):
        for y, i in enumerate(b):
            if i != cur:
                continue
            for dx, dy in dxy:
                nx, ny = x + dx, y + dy
                if 0 <= nx < H and 0 <= ny < W and B[nx][ny] == -1:
                    B[nx][ny] = cur + 1
                    q.append((nx, ny))
    while q:
        cur += 1
        next_q = []
        for x, y in q:
            for dx, dy in dxy:
                nx, ny = x + dx, y + dy
                if 0 <= nx < H and 0 <= ny < W and B[nx][ny] == -1:
                    B[nx][ny] = cur + 1
                    next_q.append((nx, ny))
        q = next_q
    return cur


def main():
    global H, W, B
    H, W, *A = open(0).read().split()
    H, W = int(H), int(W)
    B = [[0 if i == "#" else -1 for i in a] for a in A]
    dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]
    ans = bfs()
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 103244
#include <cstdio>
using namespace std;

struct pre{ int v, w; };

int max(int a, int b){
	return (a > b)? a : b;
}

int main(){
	const int MAX_N = 1000, MAX_W = 1000;
	int N, W;
	pre dat[MAX_N];
	int dp[MAX_N][MAX_W + 1];
	int p;
	
	for(int n = 1;; n++){
		scanf("%d", &W);
		if(W == 0) break;
		scanf("%d", &N);
		for(int i = 0; i < N; i++) scanf("%d,%d", &dat[i].v, &dat[i].w);
		
		for(int i = 0; i < MAX_N; i++){
			for(int j = 0; j < MAX_W; j++){
				dp[i][j] = 0;
			}
		}
		
		for(int i = dat[0].w; i <= W; i++) dp[0][i] = dat[0].v;
		for(int i = 1; i < N; i++){
			for(int j = 0; j <= W; j++){
				dp[i][j] = max((dat[i].w <= j)? dp[i - 1][j - dat[i].w] + dat[i].v : 0, dp[i - 1][j]);
			}
		}
		
		for(int i = 0; i <= W; i++){
			if(dp[N - 1][i] == dp[N - 1][W]){
				printf("Case %d:\n%d\n%d\n", n, dp[N - 1][W], i);
				break;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 4948
#include <iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stdio.h>
#include<string>

using namespace std;

int main() {
	int a,b;
	cin >> a>>b;

	string s;
	int c = 0;
	for (int i = a; i <= b; ++i) {
		s = to_string(i);
		
		if (s[0] == s[4] && s[1] == s[3])c++;	
	}

cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
class RootedTree:
    class Node:
        def __init__(self):
            self.parent = -1
            self.depth = 0
            self.children = []
            
            
    def __init__(self, n):
        self.nodes_num = n
        self.nodes = [None] * n
        for i in range(self.nodes_num):
            node = self.Node()
            self.nodes[i] = node


    def load(self, node_info):
        for _node_info in node_info:
            node_num = _node_info[0]
            if len(_node_info) > 2:
                self.nodes[node_num].children = _node_info[2:]
            else:
                self.nodes[node_num].children = []
            for child in self.nodes[node_num].children:
                self.nodes[child].parent = node_num


    def _calc_depth(self, p):
        if self.nodes[p].parent == -1:
            return 0
        return 1 + self._calc_depth(self.nodes[p].parent) 

    
    def calc_depth(self):
        for i in range(self.nodes_num):
            self.nodes[i].depth = self._calc_depth(i)

    
    def print_nodes(self):
        for i in range(self.nodes_num):
            if self.nodes[i].parent == -1:
                type = 'root'
            elif len(self.nodes[i].children) == 0:
                type = 'leaf'
            else:
                type = 'internal node'
            print('node {0}: parent = {1}, depth = {2}, {3}, {4}'.format(i, self.nodes[i].parent, self.nodes[i].depth, type, self.nodes[i].children))



if __name__ == '__main__':
    n = int(input())
    rt = RootedTree(n)
    node_info = []
    for _ in range(n):
        node_info.append(list(map(int, input().rstrip().split())))
    rt.load(node_info)
    rt.calc_depth()
    rt.print_nodes()


Measured memory_bytes: 50288
import java.util.*;
class OK{
	private int c;
	private int h;
	public OK(int c,int h){
		this.c = c;
		this.h = h;
	}
	public int getC(){
		return c;
	}
	public int getH(){
		return h;
	}
}
class OOK implements Comparator<OK> {
    public int compare(OK h1, OK h2) {
        if(h1.getH() < h2.getH()) {
            return -1;
        } else if(h1.getH() > h2.getH()) {
            return 1;
        } else {
            return 0;
        }
    }
}
class Main{
	public static void main(String[] args){  
        Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		List<OK> job = new ArrayList<>();
		int max = 0;
		int sum = 0;
		int a; int b;
		for(int x = 0; x < n; x++){
			a = sc.nextInt();
			b = sc.nextInt();
			job.add(new OK(a,b));
			if(max < b){
				max = b;
			}
			sum = sum + a;
		}
		Collections.sort(job,new OOK());
		boolean judge = true;
		int ai = 0;
		int bi;
		for(OK m : job){
			ai = ai + m.getC();
			bi = m.getH();
			if(ai > bi){
				judge = false;
			}
		}
		if(sum <= max && judge == true){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
    }
}





Measured memory_bytes: 102004
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=2e5+10;
typedef long long ll;
int a[maxn];
int main(){
	int n,cnt=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(i%2==1&&a[i]%2==1){
			cnt++;
		}
	}
	cout<<cnt;
} 

Measured memory_bytes: 3584
#include<iostream>
using namespace std;
int main()
{
int h,w;
while(1)
{
cin>>h>>w;
if(h==0&&w==0)break;
for(int i=0;i<h;i++)
{
for(int j=0;j<w;j++)
{
if((i+j)%2==0)cout<<"#";
else cout<<".";
}
cout<<endl;
}
cout<<endl;
}
return 0;
}

Measured memory_bytes: 3052
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&e);
	if(a<40)	a=40;
	if(b<40)	b=40;
	if(c<40)	c=40;
	if(d<40)	d=40;
	if(e<40)	e=40;
	printf("%d\n",(a+b+c+d+e)/5);
	return 0;
}



Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;i++)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;i++)
#define per(i,a,b) for(int i=(b),i##_st=(a);i>=i##_st;i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define dbg(x) cerr<<#x" = "<<x<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define Es(x,i) for(Edge *i=G[x];i;i=i->nxt)
typedef long long ll;
typedef pair<int,int> pii;
const int inf=~0u>>1,MOD=1e9+7;
inline int rd() {
    int x,c,f=1;while(!isdigit(c=getchar()))f=c!='-';x=c-'0';
    while(isdigit(c=getchar()))x=x*10+c-'0';return f?x:-x;
}
const int N=5e5+5;
int a[N],p[N],q[N];
int n,D;
int main(){
	n=rd(),D=rd();
	rep(i,1,n)a[i]=rd();
	p[0]=D;rep(i,1,n)p[i]=min(p[i-1],abs(p[i-1]-a[i]));
	q[n+1]=1;per(i,1,n)q[i]=2*q[i+1]<=a[i]?q[i+1]:q[i+1]+a[i];
	int Q=rd();
	while(Q--){
		int x=rd();
		puts(p[x-1]>=q[x+1]?"YES":"NO"); 
	}
}

Measured memory_bytes: 7808
import java.util.Scanner;

public class Main {

    Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        String str = scanner.next();
        int len = str.length();
        System.out.println(String.valueOf(str.charAt(0)) + (len - 2) + String.valueOf(str.charAt(len - 1)));
    }
}


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

int main() {
	int N, L, COUNT = 0;
	cin >> N >> L;
	if (L <= 0 && N + L - 1 >= 0) {
		for (int i = L; i < L + N; i++) COUNT += i;
	}
	else if (L >= 0) {
		for (int i = L + 1; i < L + N; i++) COUNT += i;
	}
	else {
		for (int i = L; i < L + N - 1; i++) COUNT += i;
	}
	cout << COUNT << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector> //可変長配列
#include <queue> //キュー
#include <unordered_map> //ハッシュ連想配列
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#define ll long long int
#define INFTY (1<<21)

using namespace std;

int main(void){
    cin.sync_with_stdio(false);
    string a,b; cin>>a>>b;
    double res = sqrt(stoi(a+b));
    cout<<(modf(res, &res)==0?"Yes":"No")<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  int a,b; cin>>a>>b;
  if((a+b)%2==0)
  cout<<(a+b)/2<<endl;
  else
  cout<<(a+b)/2+1<<endl;


  return 0;
}


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;
#define NIL NULL

Node root;

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

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

Node treeSearch(Node u, int k)
{
  Node x;
  if( u == NIL || k == x->key )
    {
      return u;
    }
  if( k < x->key )
    {
      return treeSearch(x->left,k);
    }
  else return treeSearch(x->right,k);
  
}

Node treeSuccessor(Node x)
{
  Node y;
  if( x->right != NIL )
    {
      return treeMinimum(x->right);
    }

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

  return y;
}

void treeDelete(Node z)
{
  Node y; // node to be deleted
  Node x; // child of y

  if( z->left == NIL || z->right == NIL ) y = z;
  else y = treeSuccessor(z);
    
  if( y->left != NIL ) x = y->left;
  else x = y->right;
    
  if( x != NIL ) x->parent = y->parent;

  if( y->parent == NIL ) root = x;
  else if( y == y->parent->left ) y->parent->left = x;
  else y->parent->right = x;

  if( y != z ) z->key = y->key;
 
}

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

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL )
    {
      y = x;
      if( z->key < x->key )
	{
	  x = x->left;
	}
      else
	{
	  x = x->right;
	}
    }
      z->parent = y;

      if( y == NIL ) root = z;
      else if( z->key < y->key ) y->left = z;
      else y->right = z;
}

void inorder(Node u)
{ 
  if( u == NIL ) return;

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

  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}


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



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

using namespace std;

int main(){
	int X, Y;
	cin >> X >> Y;

	if (Y - 2 * X < 0) {
		cout << "No" << endl;
		return 0;
	}

	if (4 * X - Y < 0) {
		cout << "No" << endl;
		return 0;
	}

	if (Y % 2 == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	else {
		cout << "No" << endl;
		return 0;
	}
}

Measured memory_bytes: 3632
import java.util.*;

public class Main
{
	static void addEdge(ArrayList<ArrayList<Integer>> adj,int u,int v)
	{
		adj.get(u).add(v);
	}
	
	static int dfs(ArrayList<ArrayList<Integer>> adj,int x,boolean visited[],int dp[])
	{
		visited[x]=true;
		dp[x]=0;
		for(int i=0;i<adj.get(x).size();i++)
		{
			if(!visited[adj.get(x).get(i)])
			{
				dp[adj.get(x).get(i)]=dfs(adj,adj.get(x).get(i),visited,dp);
			}
			if(dp[x]<dp[adj.get(x).get(i)]+1)
				dp[x]=dp[adj.get(x).get(i)]+1;
		}
		return dp[x];
	}
	
	public static void main(String[] args)
	{
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int m=in.nextInt();
		ArrayList<ArrayList<Integer>> adj=new ArrayList<ArrayList<Integer>>();
		for(int i=0;i<=n;i++)
			adj.add(new ArrayList<Integer>());
		for(int i=0;i<m;i++)
			addEdge(adj,in.nextInt(),in.nextInt());
		boolean visited[]=new boolean[n+1];
		int dp[]=new int[n+1];
		Arrays.fill(visited, false);
		int ans=0;
		for(int i=1;i<=n;i++)
		{
			if(!visited[i])
				dp[i]=dfs(adj,i,visited,dp);
			if(ans<dp[i])
				ans=dp[i];
		}
		System.out.println(ans);
	}
}


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

int main(void){
    long int table[200001]={0}, i, n, a[200001], ans=0;

    scanf("%ld",&n);
    for(i=1;i<=n;i++){
        scanf("%ld",&a[i]);
        table[a[i]]++;
    }

    for(i=1;i<=n;i++){
        if(table[i] != 0){
            ans += table[i]*(table[i]-1)/2;
        }
    }

    for(i=1;i<=n;i++){

        if(table[a[i]]==1){
            printf("%ld\n",ans);
        }else{
            printf("%ld\n",ans-(table[a[i]]-1));
        }
    }

    return 0;
}

Measured memory_bytes: 5792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,y,z,k,s;
	cin>>k>>s;
	int ans=0;
	for(x=0;x<=k;x++)
	{
		for(y=0;y<=k;y++)
		{
			z=s-x-y;
			if(z>=0&&z<=k)
			{
				ans++;
			}
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long int
 
#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.size()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>());
#define VSORT(v) sort(v.begin(),v.end());
#define VGSORT(v) sort(v.begin(),v.end(),greater<int>());
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cout << fixed << setprecision(0);
////////////////////////////////////////////	
	int n,k;
	cin >> n >> k;
	cout << k*pow(k-1,n-1) << endl;
//////////////////////////////////////////////
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

long long nCr(long long n, long long r){
  long long ans = 1;
  for (int i = 1; i <= r; i++){
    ans = ans * (n + 1 - i)/ i; 
  }
  return ans;
}

int main(){
  int N, A, B; cin >> N >> A >> B;

  vector <long long> V(N);
  for (int i = 0; i < N; i++) cin >> V[i];
  
  sort(V.begin(), V.end(), greater<long long>());

  long double sum = 0;
  for (int i = 0; i < A; i++){
    sum += V[i];
  }
  long double ans = sum / A;
  
  int check = A - 1;
  for (int i = A; i < B; i++){
    sum += V[i];
    if (sum / (i + 1) > ans){
      ans = sum / (i + 1);
      check = i;
    }
  }

  int cnt = 1;
  for (int i = check - 1; i >= 0; i--){
    if (V[i] == V[check]){
      cnt++;
    }else{
      break;
    }
  }
  int kable = 0;
  for (int i = check + 1; i < N; i++){
    if(V[i] == V[check]){
      kable++;
    }else{
      break;
    }
  }
  
  cout << setprecision(16) << ans << endl;
  if (V[0] == V[check]){
    long long anscnt = 0;
    for (int i = A; i <= B; i++){
      anscnt += nCr(cnt + kable, i);
    }
    cout << anscnt << endl;
  }else{
    cout << nCr(cnt + kable, cnt) << endl;
  }

  return 0;
}


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

#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int n; cin >> n;
  int m = 3000000;
  vector<int> w(n, 0);
  vector<int> e(n, 0);
  string s; cin >> s;

  for (int i = 1; i < n; i++) {
    if (s[i - 1] == 'W')
      w[i] = 1 + w[i - 1];
    else
      w[i] = w[i - 1];
  }
  for (int i = n - 2; i >= 0; i--) {
    if (s[i + 1] == 'E')
      e[i] = 1 + e[i + 1];
    else
      e[i] = e[i + 1];
  }
  int min = e[0] + w[0];
  for (int i = 1; i < n; i++) {
    if (min > e[i] + w[i]) min = e[i] + w[i];
  }
  cout << min << endl;
}



Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
int a[3];
int main(){
	cin>>a[0];
	cin>>a[1];
	cin>>a[2];
	sort(a,a+3);
	int ans=0;
	for(int i=1;i<3;i++){
		ans+=a[i]-a[i-1];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES


int func(int b[], int n)
{
	int s = 0;
	for(int i=0;i<n-1;i++)
	{
		s = s+abs(b[i]-b[i+1]);
	}
	return s;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
///    freopen("input.txt","r",stdin);
///    freopen("output.txt","w",stdout);
	int n,m;
	cin>>n>>m;
	int y[m],p[m];
	vector< pair<int, int > > v;
	for(int i=0;i<m;i++)
	{
		 cin>>p[i]>>y[i];
		 v.push_back(make_pair(p[i],y[i]));
	}
	sort(v.begin(),v.end());
	map< pair<int , int > , string > mm;
	bool pre_changed = false;
	int pre = -1;
	string second_part;
	for(int i=0;i<m;i++)
	{	
		if( v[i].first != pre)
		{
			pre_changed = true;
			pre = v[i].first;
			second_part = "000000";
		}
		else
		{
			pre_changed = false;
		}
		second_part = to_string(stoi(second_part) + stoi("000001"));
		while(second_part.size()<6)
		{
			second_part = '0'+second_part;
		}
		string first_part = to_string(v[i].first);
		while(first_part.size()<6)
		{
			first_part = '0'+first_part;
		}
		mm[make_pair(v[i].first, v[i].second)] = first_part + second_part;
	}
	for(int i=0;i<m;i++)
	{
		cout<<mm[make_pair(p[i],y[i])]<<endl;
	}
	return 0;
}

Measured memory_bytes: 14068
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<int> v;
  for(int i = 0; i < 3; i++){
    int a;
    scanf("%d", &a);
    v.push_back(a);
  }
  sort(v.begin(), v.end());
  printf("%s\n", (v[0] + v[1] == v[2]) ? "Yes" : "No");
  return 0;
}


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

using namespace std;

int main()
{
	int n, k;
	cin >> n >> k;
	
	vector<int> v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}

	long long t = 0;
	double max = 0.0;

	for (int i = 0; i < k; i++) {
		t += v[i];
	}
	max = ((t - k) / 2.0) + k;
	double tmp;
	for (int i = 1; i <= n - k; i++) {
		t -= v[i - 1];
		t += v[k + i - 1];
		tmp = ((t - k) / 2.0) + k;
		if (max < tmp) {
			max = tmp;
		}
	}
	printf("%.7f\n", max);

	return 0;
}

Measured memory_bytes: 1024
using System;
public class Hello{
    public static void Main(){
        // Your code here!
        string line=Console.ReadLine();
        int count=0;
    
        for(int i=0;i<line.Length;i++) {
		    if(line[i]=='1') {
                count++;
            } 
        }
        
        Console.WriteLine(count);
    }
}


Measured memory_bytes: 11092
a,b,c,d=input().split()
a=int(a)
b=int(b)
c=int(c)
d=int(d)
e=0
while e==0:
  c=c-b
  if c<=0:
    print("Yes")
    break
  a=a-d
  if a<=0:
    print("No")
    break

Measured memory_bytes: 9148
/*********************"ANJAN AGARWALA"************************
***************************@anjn98****************************/

//#define opti
#ifdef opti
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
ll power(ll x,ll y,ll p){ll r=1; x=x%p; while(y){ if(y&1) r= r*x%p; y=y>>1; x=x*x%p; } return r; }
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define IO 				ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(v) 			v.begin(),v.end()
#define PR(a) 			cout<<"("<<a<<")";
#define ED 				cout<<'\n';
#define endl 			'\n'
#define loop(j,a,n) 	for(int j=a;j<=n;j++)
#define loop1(j,a,n) 	for(int j=a;j>=n;j--)
#define fr1(j,n) 		for(int j=0;j<n;j++)
#define fr(n) 			for(int i=0;i<n;i++)
#define trav(x,s)       for(auto x:s)
#define PB 				push_back
#define MP 				make_pair
#define pii 			pair<int,int>
#define pll 			pair<long long int,long long int>
#define F 				first
#define S 				second 
#define binf 			2000000000000000001
#define mod 			1000000007

const int  M=1,N=1e5+9;
ll dp[N],a[N];

int32_t main()
{	
	IO
    int n;cin>>n;
    fr(n)cin>>a[i+2];

    loop(i,3,n+1)
    {
        if(i==3)dp[i]=abs(a[i]-a[i-1])+dp[i-1];
        else dp[i]=min((abs(a[i]-a[i-1])+dp[i-1]),(abs(a[i]-a[i-2])+dp[i-2]));
        
    }
    cout<<dp[n+1]<<endl;


}

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

int main() {
	string S;
	getline(cin, S);
	if (S[2] == S[3] && S[4] == S[5]) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

int main(){

	double R_0,W_0,C,R,start_rate;

	while(true){
		scanf("%lf %lf %lf %lf",&R_0,&W_0,&C,&R);
		if(R_0 == 0 && W_0 == 0 && C == 0 && R == 0)break;

		start_rate = R_0/W_0;

		if(fabs(C-start_rate) < 0.00000001 || start_rate > C){
			printf("0\n");
			continue;
		}

		for(double X = 1; ;X += 1.0){
			if((R_0+X*R)/W_0 >= C){
				printf("%.0lf\n",X);
				break;
			}
		}
	}

    return 0;
}

Measured memory_bytes: 2744
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();

        if(A>=2*B){
            System.out.println(A - 2*B);
        }
        else if(A<2*B){
            System.out.println(0);
        }
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,i,j,tot=0;
  cin>>n;
  for (i = 1; i <= n; ++i)
  {
        for(j=i;j<=n;j+=i)
        {
            tot+=j;
        }
  }
  cout<<tot;
  return 0;
}


Measured memory_bytes: 3644
n = int(input())
A = [[0 for i in range(n)] for j in range(n)]

for i in range(n):
    u, k, *v = list(map(int, input().split()))
    for j in v:
        A[int(u)-1][int(j)-1] = 1
        # A[int(j)-1][int(u)-1] = 1

# for row in A:
#     msg = ' '.join(map(str, row))
#     # print(msg)

d = [-1] * n
f = [-1] * n

t = 0

# recursive


def dfs(u):
    global t
    # print('visit:', str(u), str(t))
    t += 1
    d[u] = t
    for i in range(len(A[u])):
        if A[u][i] == 1 and d[i] == -1:
            dfs(i)
    t += 1
    f[u] = t
            


for i in range(n):
    if d[i] == -1:
        # print('start from:', str(i))
        dfs(i)


for i in range(n):
    print(str(i+1), str(d[i]), str(f[i]))


Measured memory_bytes: 5804
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iterator>
#include <fstream>
#include <cstddef>
#include <cstring>

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define PB push_back
#define rep(i, a) for(int i = 0; i < a; i++)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second
#define mp make_pair
#define INT int_64
const ll INF = (1<<30);
const ll NEGA=-INF*10000; 


ll ans = 0;
int n,m;
int cnt=0;

int p[2000000];
int main() 
{
  int n;
  cin>>n;
  ans=0;
  rep(i,n) {
    cin>>p[i];
  }
  
  int f=0;
  rep(i,n){
    if(i){
      if(p[i]==p[i-1]+1) ans++;
      else if(p[i]<=p[i-1])ans+=p[i];
      else{
          f=1;
          break;
      }
    }else{
        if(p[i]){
            f=1;
            break;
        }
    }
  }
if(f) cout<<-1<<endl;
else cout<<ans<<endl;  
}



Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int p = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'p'){
            p++;
        }
    }
    cout << s.size() / 2 - p << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define PI 3.14159265358979
#define EPS 1e-8
#define mod 1000000007
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define endl "\n"
	 
const ll INF=(ll)2e18;
		
		
const int N=2e5+5;
	
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}	

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s1,s2;
	cin>>s1>>s2;
	ll t;
	cin>>t;
	
	ll ca[100050]={0};
	ll cb[100050]={0};
	
	ll Ca[100050]={0};
	ll Cb[100050]={0};
	
	ll n=max(s1.length(),s2.length());
	
	ll i;
	for(i=0;i<s1.length();i++)
	{
		ca[i+1]=ca[i];
		cb[i+1]=cb[i];
		
		if(s1[i]=='A')
			ca[i+1]++;
		else
			cb[i+1]++;
	}
	for(;i<n;i++)
	{
		ca[i+1]=ca[i];
		cb[i+1]=cb[i];
	}
	for(ll i=0;i<s2.length();i++)
	{
		Ca[i+1]=Ca[i];
		Cb[i+1]=Cb[i];
		
		if(s2[i]=='A')
			Ca[i+1]++;
		else
			Cb[i+1]++;
	}
	for(;i<n;i++)
	{
		Ca[i+1]=Ca[i];
		Cb[i+1]=Cb[i];
	}
	
	for(ll i=0;i<t;i++)
	{
		ll a,b,c,d;
		cin>>a>>b>>c>>d;
		
		ll cnta= ca[b]-ca[a-1];
		ll cntb= cb[b]-cb[a-1];
		
		ll c1=cnta + 2*cntb;
		
		ll Cnta= Ca[d]-Ca[c-1];
		ll Cntb= Cb[d]-Cb[c-1];
		ll c2=Cnta + 2*Cntb;
		//cout<<cnta<<" "<<cntb<<" "<<Cnta<<" "<<Cntb<<endl;
		
		while(c1<c2)
		{
			c1*=4;
		}
		if((c1-c2)%3==0)
			cout<<"YES\n";
		else
			cout<<"NO\n";
		
		
	}
}

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

int main(){
    int r,c,n;
    cin>>r>>c>>n;
    map<int,int> vec;

    auto id=[&](int x,int y){
        if(x==0) return y+1;
        if(y==c) return c+2+x;
        if(x==r) return c+2+r+1+c-y;
        if(y==0) return c+2+r+1+c+1+r-x;
        return 0;
    };
    for(int i=0;i<n;i++){
        int x0,y0;
        cin>>x0>>y0;
        int x1,y1;
        cin>>x1>>y1;
        if(id(x0,y0) && id(x1,y1)){
            vec[id(x0,y0)]=i;
            vec[id(x1,y1)]=i;
        }
    }

    stack<int> st;
    for(auto &e:vec){
        int i=e.second;
        if(i!=-1){
            if(!st.empty() && st.top()==i) st.pop();
            else st.push(i);
        }
    }
    cout<<(st.empty() ? "YES" : "NO")<<endl;
    return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll a, b;
    int k;
    cin >> a >> b >> k;
    rep (i, k) {
        if (i % 2) {
            if (b % 2) b--;
            a += b / 2;
            b /= 2;
        } else {
            if (a % 2) a--;
            b += a / 2;
            a /= 2;
        }
        
    }
    cout << a << " " << b << endl;
    
    return 0;
}



Measured memory_bytes: 384
//In The Name Of GOD
 
#include <bits/stdc++.h>

using namespace std;

typedef long long ll ;

const int mod = 1000000007;
const int inf = 2000000000;
const int maxn = 500*1000+500*1000+15;
const int MLOG = 18;

#define pb push_back
#define pp pop_back
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);
#define sz(a) (int)(a.size())

int main(){
	int n;
	cin >> n;
	const int m = n;
	int al[m];
	for(int i = 0; i < n; i++){
		cin >> al[i];
	}
	sort(al, al + m);
	if(n%2){
		for(int i = 0; i < n; i++){
			if( ((i + 1) / 2) * 2 != al[i] ){
				cout << 0;
				return 0;
			}
		}
	}else{
		for(int i = 0; i < n; i++){
			if( (i / 2) * 2 + 1 != al[i] ){
				cout << 0;
				return 0;
			}
		}
	}
	int a=1;
	for(int i = 0; i < n/2; i++){
		a = ((ll)a * 2) % mod;
	}
	cout << a;
}


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

int main()
{
  int n,k;
  
  cin >> n >> k;
  
  int a[n];
  
  rep(i,0,n)cin>>a[i];
  
  sort(a,a+n);
  
  int ans=0;
  
  rep(i,0,k)ans+=a[i];
  
  cout << ans <<endl;
  }

Measured memory_bytes: 3640
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
T=[]
#print(h)
for i in range(n):
    T.append(t-h[i]*0.006)
#print(T)
P=[]
for i in range(n):
    P.append(abs(T[i]-a))
#print(P)
print(P.index(min(P))+1)

Measured memory_bytes: 3060
#include <iostream>
static const int MOD = 1e9 + 7;
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  bool broken[n];

  for (int i = 0; i <= n; i++) {
    broken[i] = false;
  }

  int dp[n+2];
  int a;
  //欠けている段を入力
  for (int i = 0; i < m; i++) {
    cin >> a;
    broken[a] = true;
  }

  dp[n] = 1;
  dp[n+1] = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (broken[i]){
      dp[i] = 0;
      continue;
    }
    dp[i] = (dp[i+1] + dp[i+2]) % MOD;
  }

  cout << dp[0] << endl;
  return 0;
}

Measured memory_bytes: 768
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

ll N, K;
ll A[200010];
std::vector<ll> B;
std::map<ll, ll> last;
ll nxt[200010][50];

int main()
{
  std::cin >> N >> K;

  rep( i, N )
    std::cin >> A[i];

  for( ll i = 2*N-1; i >= 0; --i )
  {
    if( i < N )
      nxt[i][0] = last[A[i]]-i+1;

    last[A[i%N]] = i;
  }

  //std::cout << twoK << std::endl;

  rep( k, 40 )
  {
    rep( i, N )
    {
      //printf( "nxt[%d][%d] = %lld\n", i, k, nxt[i][k] );

      nxt[i][k+1] = nxt[i][k]+nxt[(i+nxt[i][k])%N][k];
    }
  }

  ll p = 0;

  for( ;; )
  {
    ll l = 40;

    while( l >= 0 && nxt[p%N][l]+p > N*K )
      --l;

    if( l == -1 )
      break;

    p += nxt[p%N][l];
  }

  if( p == N*K )
  {
    return 0;
  }

  //std::cout << p << std::endl;

  std::vector<ll> st;
  std::set<ll> in;

  repi( i, p%N, N )
  {
    if( in.count( A[i] ) )
    {
      do
      {
        in.erase( st.back() );
        st.pop_back();
      } while( in.count( A[i] ) );

      //std::cout << "false" << std::endl;
    }
    else
    {
      st.push_back( A[i] );
      in.insert( A[i] );

      //std::cout << "true" << std::endl;
    }
  }

  rep( i, st.size() )
    std::cout << st[i] << (i==st.size()-1?'\n':' ');

  return 0;
}

Measured memory_bytes: 104688
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

#define debug(x) cerr<<#x<<'='<<x<<'\n'
char s[233];
int main(void) {
	scanf("%s", s+1);
	int ans=0;
	for (int i=1; s[i]!='\0'; i++) {
		if (s[i]=='1') {
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define    bit(a)          __builtin_popcount(a)
#define    all(x)           x.begin(), x.end()
#define    minv(v)         *min_element(all(v))
#define    maxv(v)         *max_element(all(v))
#define    unq(v)           sort(all(v)),v.erase(unique(all(v)),v.end())
#define    w(x)             while(x--)
#define    rep(i,a,b)       for(i=a;i<=b;i++)
#define    ll               long long
#define    pb               push_back
#define    vii              vector<int>
#define    vll              vector<ll>
#define    vcc              vector<char>
#define    sii              set<int>
#define    sll              set<ll>
#define    scc              set<char>
#define    li               list<int>
#define    pii              pair<int,int>
#define    pll              pair<ll,ll>
#define    mii              map<int,int>
#define    mll              map<ll,ll>
#define    fill(arr,x)      memset(arr,x,sizeof(arr))
#define    gcd(a,b)         __gcd(a,b)
#define    lcm(a,b)        (a*(b/gcd(a,b)))
#define    srtc(a,b)        sort(a,a+b,greater<int>())
#define    pi               acos(-1.00)
#define _ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/*
//find the position of 0 or 1 in binary representation
int zero(int n)
{
    int i=1,pos=0;
    while(n)
    {
        if(n%2==0)pos=i;
        n/=2;
        i++;
    }
    return pos;
}
*/
int t;
string s;
int main()
{
    _ios;
    ll n,x,i;
    cin>>x>>n;
    ll arr[n+5];
    rep(i,1,n)cin>>arr[i];
    sort(arr+1,arr+n+1);
    arr[0]=arr[1]-2;
    arr[n+1]=arr[n]+2;
    ll temp,num,dif=INT_MAX;
    bool flag=false;
    rep(i,1,n+1)
    {
        if(arr[i]>x)flag=true;
        if(arr[i]-arr[i-1]>1)
        {
            if(!flag)temp=arr[i]-1;
            else temp=arr[i-1]+1;
            if(abs(x-temp)<dif)
            {
                dif=abs(x-temp);
                num=temp;
            }
        }
         //cout<<temp<<" ";
    }
    if(n)cout<<num<<endl;
    else cout<<x<<endl;
    return 0;
}





Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);i <= (e);(i)++)

#define int long long

i64 X;
int K;

vector<i64> r;

int Q;

vector<i64> t;
vector<i64> a;
using P = pair<i64,i64>;
vector<P> query;

signed main(){
  cin >> X >> K;
  r.resize(K);
  query.emplace_back(0,0);
  for(int i = 0;i < K;i++){
    cin >> r[i];
    query.emplace_back(r[i],-1);
  }
  cin >> Q;
  t.resize(Q);
  a.resize(Q);
  rep(i,0,Q - 1){
    cin >> t[i] >> a[i];
    query.push_back({t[i],i});
  }

  sort(begin(query),end(query));

  int XX = X;
  int ZZ = 0;
  int cou = 0;
  int before = 0;
  i64 x = X;
  i64 z = 0;
  int sum = 0;

  vector<i64> ans(Q);
  
  rep(i,0,query.size() - 1){
    P p = query[i];
    int index = p.second;
    int dif = p.first - before;
      if(cou % 2 == 0){
        x -= dif;
        z -= dif;
        sum -= dif;
        if(x < 0){
          x = 0;
        }
        if(z < 0){
          ZZ += -z;
          z = 0;
        }
      }
      else{
        x += dif;
        z += dif;
        sum += dif;
        z = min(X,z);
        if(x > X){
          XX -= x - X;
          x = X;
        }
      }
    if(p.second == -1) cou++;
    if(p.second > -1){
      if(a[index] >= XX){
        ans[index] = max(0LL,min(X,x));
      }
      else if(a[index] <= ZZ){
        ans[index] = max(0LL,min(X,z));
      }
      else{
        ans[index] = sum + a[index];
      }


    }

    before = p.first;
  } 

  for(i64 an : ans){
    cout << an << endl;
  }
}


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

n, m = map(int, input().split())
l = []
num = [0] * n
ans = [""] * m

for i in range(m):
    p, y = map(int, input().split())
    l.append(list([p, y, i]))

l.sort()


for p, y, i in l:
    num[p - 1] += 1
    ans[i] = str(p).zfill(6) + str(num[p - 1]).zfill(6)

for a in ans:
    print(a)


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.setf(ios::fixed);
    cout.precision(10);
    
    ll a, b, c;
    cin >> a >> b >> c;
    
    ll lhs = 4 * a * b;
    ll rhs = (c - a - b) * (c - a - b);
    if (c - a - b < 0) {
        cout << "No" << endl;
    }
    else 
        cout << (lhs < rhs ? "Yes" : "No") << endl;
}


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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i ,a, b) for (int i = a ; i <= b ; i++)
#define sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define cutiii(a,b,c) cout << a << " " << b << " " << c << endl;
#define vec(a) vector<int > a;

template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }

typedef long long LL;
typedef pair<int ,int > pii;
typedef pair<string ,int > psi;
typedef pair<string ,string > pss;
typedef pair<LL, LL> pLL;

const long long oo = 1e9 + 7;
const double PI = acos(-1.0);

double DEG_to_RAD(double d) { return d * PI / 180.0; }

string s;

int main(){
   // freopen("test.txt","r",stdin);
    cin >> s;
    s[3] = '8';
    cout << s << endl;
}


Measured memory_bytes: 256