akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(){
    int h, n;
    cin >> h >> n;
    int a[n], sum;
    sum = 0;
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }
    if(sum >= h) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, double> pid;
typedef pair<double, int> pdi;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	string S;
	cin >> S;
	S[3] = '8';
	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll h,w;
cin>>h>>w;
ll ans=0;
if(h==1){
cout << 1 << endl;}
else if(w==1){
cout << 1 << endl;}
else
if(h%2==0){
ans=(h/2)*w;
cout << ans << endl;}
else if(w%2==0){
ans = (w/2)*h;
cout << ans << endl;}
else{
ans = (w*h+1)/2;
cout<< ans <<endl;}}


Measured memory_bytes: 3620
// https://atcoder.jp/contests/hitachi2020/tasks/hitachi2020_c
// 日立製作所 社会システム事業部 プログラミングコンテスト2020
// C - ThREE

/*
Problem.
1からNまでの番号がついているN頂点の木について、
以下の条件を満たす順列Pを生成せよ。
- 全ての頂点(i,j)について、その距離が3であるならば、
P[i]とP[j]の和または積が３の倍数である。

Point.
順列内の数の種類は3で割った余りによって3種類rem0, rem1, rem2に分けられる。
また、仮定としてrem1,rem2の数に指定がなければ、生成される木は層ごとに交互に色が違う
ミルフィーユ状の木になる。
本問ではrem0 = N/3, rem1 = N/3 (+1), rem2 = N/3 (+1)と指定されていることになる。
偶数番目の層のノード数をC1, 奇数番目の層のノード数をC2とした時、
構築時の場合分けとして、
(i) C1 < rem1
- (注)C1 < rem1ということは、rem1でC1を埋めるとrem1の余りがC2に入ってしまい構築に失敗する。
題意より、C1 < rem1であるなら、C1 <= rem0である。
そのため、C1をrem0の数で埋め,C2を残りで埋めることで、全ての組が条件を満たすよう構築可能である。
(ii) C2 < rem2
- (注)(i)と同
C2をrem0の数で埋める。
(iii) C1 >= rem1 && C2 >= rem2
C1をrem1の数で、C2をrem2の数で埋め、残りをC0で埋めることで構築できる。
*/

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>

using namespace std;
using ll = long long;

void dfs(vector<vector<int>>&t, vector<int>&depth, int k, int dp, pair<int, int>&p){
  depth[k] = dp;
  if(dp%2) p.second++;
  else p.first++;
  for(auto i : t[k]){
    if(depth[i] != -1) continue;
    dfs(t, depth, i, dp+1, p);
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n; cin >> n;
  vector<vector<int>> t(n);
  int rem0 = n/3, rem1 = n/3 + (n%3 != 0), rem2 = n/3 + (n%3 == 2);
  for(int i = 0; i < n-1; i++){
    int a, b; cin >> a >> b;
    a--; b--;
    t[a].push_back(b);
    t[b].push_back(a);
  }
  vector<int> depth(n, -1);
  pair<int, int> p = {0, 0};
  dfs(t, depth, 0, 0, p);
  vector<int> ans(n);
  if(p.first < rem1){
    for(int i = 0; i < n; i++){
      if(depth[i]%2 == 0) ans[i] = (--rem0)*3 + 3;
      else{
        if(rem1) ans[i] = (--rem1)*3 + 1;
        else if(rem2) ans[i] = (--rem2)*3 + 2;
        else ans[i] = (--rem0)*3 + 3;
      }
    }
  }
  else if(p.second < rem2){
    for(int i = 0; i < n; i++){
      if(depth[i]%2 == 1) ans[i] = (--rem0)*3 + 3;
      else{
        if(rem1) ans[i] = (--rem1)*3 + 1;
        else if(rem2) ans[i] = (--rem2)*3 + 2;
        else ans[i] = (--rem0)*3 + 3;
      }
    }
  }
  else{
    for(int i = 0; i < n; i++){
      if(depth[i]%2 == 0){
        if(rem1) ans[i] = (--rem1)*3 + 1;
        else ans[i] = (--rem0)*3 + 3;
      }
      else{
        if(rem2) ans[i] = (--rem2)*3 + 2;
        else ans[i] = (--rem0)*3 + 3;
      }
    }
  }
  for(int i = 0; i < n; i++){
    cout << ans[i] << ' ';
  }
  cout << endl;
  // end-----------------------------------------------
  cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 20352
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

int main() {
  int N, M, Q;
  cin >> N >> M >> Q;

  vector<int> a(Q), b(Q), c(Q), d(Q);
  for (int i = 0; i < Q; i++) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  int ans = 0;
  queue<vector<int>> que;
  que.push(vector<int>(1, 1));

  while (true) {
    vector<int> A = que.front();
    que.pop();

    int score = 0;
    if ((int)A.size() == N + 1) {
      for (int i = 0; i < Q; i++) {
        if (A[b[i]] - A[a[i]] == c[i]) {
          score += d[i];
        }
      }
      ans = max(ans, score);
      if (A[1] == M) {
        break;
      }
      continue;
    }

    int tail = A.back();
    for (int add_elem = tail; add_elem <= M; add_elem++) {
      A.push_back(add_elem);
      que.push(A);
      A.pop_back();
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 11420
//解説ガン見 後でもう一回解きます
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=0;i<=(int)n;i++)
ll dp[105][4][2];
int main(void){
    string n;
    int k;
    cin>>n>>k;
    ll sz=n.size();
    dp[0][0][0]=1;
    
    rep(i,sz){
        rep(j,4){
            rep(l,2){
                int now=n[i]-'0';
                rep(d,10){
                    int ni=i+1,nj=j,nl=l;
                    if(d!=0) nj++;
                    if(nj>k) continue;
                    if(l==0){
                        if(d>now) continue;
                        else if(d<now) nl=1;
                        else nl=0;
                    }
                    dp[ni][nj][nl] += dp[i][j][l];
                }
            }
        }
    }
    
    ll res=dp[sz][k][1]+dp[sz][k][0];
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define N 500000 
struct node{
  struct node *r;
  struct node *l;
  struct node *p;
  int key;
};
typedef struct node * Node ;
Node root;

Node treemin(Node x){
  while(x->l != NULL){
    x=x->l;
  }
  return x;
}
Node treesrh(Node u,int k){
  if(u == NULL || k == u->key)return u;
  if(k < u->key)return treesrh(u->l,k);
  else return treesrh(u->r,k);
}
Node treesuc(Node x){
  Node y;
  if(x->r != NULL)return treemin(x->r);
  y=x->p;
  while(y != NULL && x==y->r){
    x=y;
    y=y->p;
  }
  return y;
}
void treedel(Node z){
  Node y;
  Node x;
}


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

  z = malloc(sizeof(struct node));
  z->key = k;
  z->l = NULL;
  z->r = NULL;

  while(x != NULL){
    y = x;
    if((z->key) < (x->key)) x = x->l;
    else x = x->r;
  } 
  z->p = y;

  if(y == NULL){
    root = z;
  }
  else if((z->key) < (y->key)){
    y->l = z;
  }
  else y->r = z;

  return;
}
void inorder(Node u){
  if(u->l != NULL){
    inorder(u->l);
  }
  printf(" %d",u->key);
  if(u->r !=NULL ){
    inorder(u->r);
  }
}

void preorder(Node u){
  printf(" %d",u->key);
  if(u->l != NULL){
    preorder(u->l);
  }
  if(u->r != NULL){
    preorder(u->r);
  }
}
int main(){
  int n,i,x;
  char c[10];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",c);

    if(c[0] == 'f'){
      scanf("%d",&x);
      Node a = treesrh(root,x);
      if(a != NULL)printf("yes\n");
      else printf("no\n");
    } else if(c[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    } else if(c[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}

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

const int N = 110;

int n;
int g[N][N], match[N];
bool vis[N];

bool dfs(int u) {
    for (int v = 0; v < n; ++v) if (g[u][v] && !vis[v]) {
        vis[v] = 1;
        if (match[v] == -1 || dfs(match[v])) {
            match[v] = u;
            return 1;
        }
    }
    return 0;
}
int maxMatch() {
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        match[i] = -1;
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            vis[j] = false;
        }
        ans += dfs(i);
    }
    return ans;
}

int main() {
    cin >> n;
    vector<int> a(n), b(n), c(n), d(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> c[i] >> d[i];
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0.; j < n; ++j) {
            if (a[i] < c[j] && b[i] < d[j]) {
                g[i][j] = 1;
            }
        }
    }
    cout << maxMatch() << '\n';
    return 0;
}

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


int main() {
  vector<int> vec(3);
  cin >> vec[0] >> vec[1] >> vec[2];
  sort(vec.begin(), vec.end());
  cout << vec[0] + vec[1] + (vec[2]*10) << endl;
  return 0;
  
}

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

int main(){
    int a, b, c, d;
    scanf("%d %d %d %d", &a, &b, &c, &d);

    int taka;
    if (c % b == 0) taka = c / b;
    else taka = c / b + 1;

    int aok;
    if (a % d == 0) aok = a / d;
    else aok = a/d + 1;

    if (taka <= aok) printf("Yes\n");
    else printf("No\n");

    return 0;
}

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


int main(){
	string A,B,C;
	cin >> A >> B >> C;
	if(A[A.size()-1]==B[0]&&B[B.size()-1]==C[0]){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 3005, mod = 998244353;
int dp[maxn][maxn];
int solve(int x2,int y2,int x1,int y1){
	if( x2 < x1 || y2 < y1 )return 0;
	if( x1 == x2 && y1 == y2 )return 1;
	int &ans = dp[x2][y2];
	if( ans !=-1 )return ans;
	ans = 0;
	ans = y2 * solve(x2-1,y2,x1,y1) % mod + x2 * solve(x2,y2-1,x1,y1) % mod - (x2-1) * (y2-1) % mod * solve(x2-1,y2-1,x1,y1) % mod;
	ans %= mod;
	ans += mod;
	ans %= mod;
	return ans;
}
int32_t main(){
	IOS
	memset(dp,-1,sizeof(dp));
	int x1,y1,x2,y2;cin>>x1>>y1>>x2>>y2;
	cout<<solve(x2,y2,x1,y1);
 }
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 74644
S = input()

o_count = 0
x_count = 0
k = len(S)
amari = 15-k

for i in range(len(S)):
    if S[i] == 'o':
        o_count += 1
    if S[i] == 'x':
        x_count += 1

if o_count + amari >= 8:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 38256
def maxHeapify(A,i):
    left,right=2*i,2*i+1
    if left<n and A[left]>A[i]:largest=left
    else:largest=i
    if right<n and A[right]>A[largest]:largest=right

    if largest!=i:
        A[i],A[largest]=A[largest],A[i]
        maxHeapify(A,largest)


def buildMaxHeap(A):
    for i in reversed(range(1,n//2+1)):
        maxHeapify(A,i)


n=int(input())+1
A=[0]+list(map(int,input().split()))
buildMaxHeap(A)
print(" ",end="")
print(*A[1:])


Measured memory_bytes: 63700
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;


void calc() {

	Int N; std::cin >> N;
	std::vector<Int> sum(N); //A + B
	Int ans = 0;
	rep(i, N) {
		Int A, B; std::cin >> A >> B;
		sum[i] = A + B;
		ans -= B;
	}
	std::sort(sum.rbegin(), sum.rend());
	rep(i, N) {
		if (i % 2 == 0)ans += sum[i];
	}

	std::cout << ans;

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>
#include<queue>
#include<cmath>

using namespace std;

typedef long long int64;

int main(void){
     int64 a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
    return 0;
}

Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			if (n % 1111 == 0) {
				System.out.println("NA");
				continue;
			}

			int count = 0;
			while (true) {
				if (n == 6174) {
					break;
				}
				n = slove(n);
				count++;
			}
			System.out.println(count);
		}

	}

	private int slove(int n) {
		char[] c = new char[4];
		for(int i = 0;i<4;i++)
			c[i] = '0';
		char[] ch = String.valueOf(n).toCharArray();
		for (int i = 0; i < ch.length; i++) {
			c[i] = ch[i];
		}
		Arrays.sort(c);
		StringBuilder builder = new StringBuilder(String.valueOf(c));
		int min = Integer.valueOf(builder.toString());
		int max = Integer.valueOf(builder.reverse().toString());
		return max - min;
	}
}

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

using namespace std;
typedef long long ll;

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

  ll h[100000];
  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
  }

  bool good[100000];
  for (int i = 1; i <= n; ++i) {
    good[i] = true;
  }

  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (h[a] < h[b]) {
      good[a] = false;
    } else if (h[a] > h[b]) {
      good[b] = false;
    } else {
      good[a] = false;
      good[b] = false;
    }
  }

  int result = 0;

  for (int i = 1; i <= n; ++i) {
    if (good[i]) {
      ++result;
    }
  }

  cout << result;

  return 0;
}


Measured memory_bytes: 4516
S = str(input())

#10**nのmod計算
A = []
p =1
for i in range(len(S)):
  A.append(p)
  p = p*10%2019

#左からi文字以降の数字列のmod計算
X = []
a = 0
for i in range(len(S)):
  a = (a + int(S[len(S)-i-1])*A[i]) %2019
  X.append(a)
X.sort()
flag =1
n = 0

#modが同じになる組み合わせ、またはもともとmodが0になる数字列の個数の総和計算
for i in range(len(X)-1):
  if X[i]==0:
    n +=1
  if X[i]==X[i+1]:
    flag += 1
  else:
    n += int(flag*(flag-1)/2)
    flag = 1
n += int(flag*(flag-1)/2)
if X[len(X)-1]==0:
  n +=1
print(n)


Measured memory_bytes: 24284
#include <iostream>
#include <fstream>
#include <sstream>
#include <cmath>
#include <math.h>
#include <cstring>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <iomanip>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <cstdlib>
#include <cstdio>
#include <functional>
#include <memory.h>
#include <cassert>
#include <complex>
#include <ctime>
#include <limits>

using namespace std;

using ll = long long;
using ld = long double;
using db = double;
using str = string;

using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>; 

using vi = vector<int>;
using vl = vector<long long>;
using vd = vector<double>;
using vs = vector<string>;
using vld = vector<long double>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<long long, long long>>;
using vpd = vector<pair<double, double>>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend() 
#define rs resize
#define ins insert 
#define ft front() 
#define bk back()
#define pf push_front 
#define pb push_back
#define eb emplace_back 
#define lb lower_bound 
#define ub upper_bound
#define nl "\n"
#define trav(i, x) for (auto& i: x)

const int MOD = 998244353;
const int MX = 5005;
const ll INF = 1e18; 
const ld PI = acos((ld)-1);
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); 

ll lcm(ll a, ll b) { return (a / (__gcd(a, b)) * b); }
ll gcd(ll a,ll b) { return b ? gcd(b, a % b) : a; }
ll pow(ll a, ll b) { ll res = 1; while (b > 0) { if (b & 1) res = res * a; a = a * a; b >>= 1; } return res; }

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

	int x, y;
	cin >> x >> y;
	for(int i = 0; i <= x; i++) {
		for(int j = 0; j <= x; j++) {
			if(i * 2 + j * 4 == y && (i + j) == x) {
				cout << "Yes" << nl;
				return 0;
			}
		}
	}
	cout << "No" << nl;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long X, long long N, std::vector<long long> p){
    int minDiff = INT_MAX, answer = INT_MAX;
    rrep(i,-1,102) {
        if (find(all(p), i) != p.end()) continue;
        if (abs(X - i) <= minDiff) {
            minDiff = abs(X-i);
            answer = min<int>(answer, i);
        }
    }
    cout << answer << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long X;
    scanf("%lld",&X);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(X, N, std::move(p));
    return 0;
}


Measured memory_bytes: 3696
/*
看到这个数据范围 n <= 21，就感觉是状压 dp
怎么设计状态呢
因为答案与顺序无关，所以 f[i] 为前 i 个男生匹配完了的方案数。
好像没法记录女生选的情况，所以在加一维 f[i][mask] 为前 i 个男生匹配完，女生状态为 mask 的方案数
第 i 个男生可以枚举一个女生转移
好像 i 这一维不需要啊
好像枚举 i 这一步也不需要啊
mask 中 1 的个数是 i 啦
n <= 21，如果枚举 i 这一维的话，大概是 2^21 * 21 * 21  = 924844032 TLE
如果不枚举 i 的话 2^n * n AC 啦 
要用到什么呢？
判断某一位是不是 1：用 & 
去掉某一位的 1：用 ^ 
求有多少个 1：这一步可以用一个函数啊，开头是双下划线，好像 noip 不让用：__builtin_popcount
额这个函数怎么记住？划分一下是：built in pop count 好记多了呀 
哦，初始状态 f[0] = 0;  答案是 f[(1 << n) - 1] 
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 21 + 5;
int n, a[N][N], f[1 << N], p = 1e9 + 7; 
int main() {
	int n; scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			scanf("%d", &a[i][j]);
	f[0] = 1;
	for (int mask = 0; mask < (1 << n); mask++) {
		int i = __builtin_popcount(mask);
		for (int j = 1; j <= n; j++) {
			if (mask & (1 << (j - 1)) && a[i][j])
				f[mask] = (f[mask] + f[mask ^ (1 << (j - 1))]) % p;
		}
	}
	printf("%d\n", f[(1 << n) - 1]);
	return 0;
} 

Measured memory_bytes: 10496
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using vi = vector<int>;
using vl = vector<i64>;
using vd = vector<double>;
using pi = pair<int, int>;
using pl = pair<i64, i64>;
using pd = pair<double, double>;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

template <typename T>
class Vec2 {
 public:
  Vec2(){};
  Vec2(T x, T y) : x(x), y(y){};
  Vec2<T> operator+(Vec2<T> p);
  Vec2<T> operator-(Vec2<T> p);
  T dot(Vec2<T> p);
  bool is_paralell(Vec2<T> p);
  bool is_vertical(Vec2<T> p);
  T x, y;
};

template <typename T>
Vec2<T> Vec2<T>::operator+(Vec2<T> p) {
  return Vec2(x + p.x, y + p.y);
}

template <typename T>
Vec2<T> Vec2<T>::operator-(Vec2<T> p) {
  return Vec2(x - p.x, y - p.y);
}

template <typename T>
T Vec2<T>::dot(Vec2<T> p) {
  return x * p.x + y * p.y;
}

template <typename T>
bool Vec2<T>::is_paralell(Vec2<T> p) {
  return x * p.y == y * p.x;
}

template <typename T>
bool Vec2<T>::is_vertical(Vec2<T> p) {
  return this->dot(p) == (T)0;
}

int main() {
  int q, x, y;
  Vec2<int> p0, p1, p2, p3;
  cin >> q;
  REP(i, q) {
    cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
    if ((p1 - p0).is_paralell(p3 - p2)) {
      cout << "2" << endl;
    } else if ((p1 - p0).is_vertical(p3 - p2)) {
      cout << "1" << endl;
    } else {
      cout << "0" << endl;
    }
  }
}


Measured memory_bytes: 3104
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;

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

    char a, b;
    cin >> a >> b;

    if(a > b) {
        cout << ">" << endl;
    }else if(a < b){
        cout << "<" << endl;
    }else{
        cout << "=" << endl;
    }


    return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

S = raw_input()[::-1]

ans = 0
cnt = 0
for c in S:
    if c == 'W':
        cnt += 1
    else:
        ans += cnt

print ans

Measured memory_bytes: 3548
#include <stdio.h>
 int edge[10][10];
 int size[10];
 int used[10];
 int v,e;
 int dfs(int x,int n){
 	if(used[x]) return 0;
 	if(n==v-1) return 1;
 	int res=0;
 	used[x]=1;
 	for(int i=0;i<size[x];i++){
 		res+=dfs(edge[x][i],n+1);
 	}
 	used[x]=0;
 	return res;
 }
 int main(void)
 {
 	scanf("%d %d",&v,&e);
 	for(int i=0;i<e;i++){
 		int a,b;
 		scanf("%d %d",&a,&b);
 		edge[a][size[a]++]=b;
 		edge[b][size[b]++]=a;
 	}
 	printf("%d\n",dfs(1,0));
 	return 0;
 }

Measured memory_bytes: 128
#include<stdio.h>
 
#define N 25
 
typedef struct{
  int p,s,deg,dep,h,left,right;
}Node;
 
int depth(Node *, int);
int height(Node *, int);
 
int main(){
  int i,n,id;
  Node T[N],tmp;
 
  scanf("%d",&n);
  for(i=0; i<n; i++){
    T[i].p = -1;
    T[i].dep = 0;
    T[i].deg = 0;
    T[i].s = -1;
  }
  for(i=0; i<n; i++){
    scanf("%d",&id);
    scanf("%d%d", &T[id].left, &T[id].right);
    T[T[id].left].p = id;
    T[T[id].right].p = id;
    if(T[id].left != -1){
      T[id].deg++;
      T[T[id].left].s = T[id].right;
    }
     if(T[id].right != -1){
      T[id].deg++;
      T[T[id].right].s = T[id].left;
    }
  }
 
  for(i=0; i<n; i++){
    T[i].dep = depth(T,i);
    T[i].h = height(T,i);
  }
   
  for(i=0; i<n; i++){
    if(T[i].p == -1)  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, root\n", i, T[i].p, T[i].s, T[i].deg, T[i].dep, T[i].h);
    else if(T[i].deg != 0)  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, internal node\n" , i, T[i].p, T[i].s, T[i].deg, T[i].dep, T[i].h);
    else  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, leaf\n" , i, T[i].p, T[i].s, T[i].deg, T[i].dep, T[i].h);
  }
 
  return 0;
}
 
int depth(Node *T, int i){
 
  if(T[i].p == -1) return 0;
 
  return depth(T, T[i].p) + 1;
   
}
 
int height(Node *T, int i){
  int righth=0,lefth=0;
  if(T[i].right != -1) righth = height(T, T[i].right) + 1;
  if(T[i].left != -1) lefth = height(T, T[i].left) + 1;
  if(righth >= lefth) return righth;
  else return lefth;
}

Measured memory_bytes: 600
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  ll yuta = 0;
  ll ap = -1;
  rep(i, n) {
    ll a;
    cin >> a;
    if (ap + 1 < a) {
      cout << -1 << endl;
      return 0;
    }
    if (ap + 1 == a && i > 0)
      yuta++;
    else
      yuta += a;
    ap = a;
  }

  cout << yuta << endl;

  return 0;
}


Measured memory_bytes: 3600
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int IsPrime(int);

int main() {
  int a[10000];
  int i, n, cnt = 0;
  // input the number
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if(IsPrime(a[i]) == 1) cnt++;
  }

  // output
  printf("%d\n", cnt);
  return 0;
}

int IsPrime(int a) {
  int i;
  
  if(a < 2) return 0;
  else if (a == 2) return 1;
  else if (a % 2 == 0) return 0;

  for(i = 3; i <= sqrt(a); i += 2) {
    if(a % i == 0) {
      return 0;
    }
  }

  return 1;
}



Measured memory_bytes: 2032
#include<cstdio>
#include<vector>
#include<algorithm>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int k, a, b;
	while(scanf("%d%d%d", &k, &a, &b)==3)
	{
		bool ans=(b/k-(a-1)/k)>0;

		printf("%s\n", ans?"OK":"NG");
	}
	return 0;
}


Measured memory_bytes: 1664
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n = INT()
a = LIST()
b = LIST()
dif = sum(b) - sum(a)
if dif < 0:
    print('No')
    exit()
cnt1 = 0
cnt2 = 0
for i in range(n):
    tmp = b[i] - a[i]
    if tmp > 0:
        cnt2 += (tmp + 1) // 2
    else:
        cnt1 += -tmp
if dif < cnt1 or dif < cnt2:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 6744
#include<iostream>
#include<algorithm>
using namespace std;
 
 
// 262144 = 2^18
int tree[262144]; 
 
int dfs(int a,int b,int k,int l,int r){
  if(r<a || b<l)return 0;
  if(a<=l && r<=b)return tree[k];
  int m=(l+r)/2;
  return dfs(a,b,k*2+1,l,m)+dfs(a,b,k*2+2,m+1,r);
}
 
int getSum(int a,int b){
  // 131072 = 2^17
  return dfs(a,b,0,0,131071);
}
 
void update(int i,int x){
  // 131072 = 2^17
  i+=(131072-1);
  tree[i]+=x;
  while(i){
    i=(i-1)/2;
    tree[i]+=x;
  }
}
 
int n,q;
int a,b,c;
int main(){
  cin>>n>>q;

  for(int i=0;i<q;i++){
    cin>>a>>b>>c;
    if(a==1){
      cout<<getSum(b,c)<<endl;
    }else{
      update(b,c);
    }
  }
  return 0;
}

Measured memory_bytes: 1960
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll n,a,b,c,d;
std::map<ll, ll> mp;

ll solve(ll x){
	if(mp.count(x)){
		return mp[x];
	}
	if(!x){
		return mp[x] = 0ll;
	}
	mp[x] = INFLL;
	if(INFLL/d>=x){
		mp[x] = x*d;
	}
	mp[x] = std::min(mp[x],solve(x/2)+a+d*(x%2));
	if(x%2){
		mp[x] = std::min(mp[x],solve(x/2+1)+a+d*(2-x%2));
	}
	mp[x] = std::min(mp[x],solve(x/3)+b+d*(x%3));
	if(x%3){
		mp[x] = std::min(mp[x],solve(x/3+1)+b+d*(3-x%3));
	}
	mp[x] = std::min(mp[x],solve(x/5)+c+d*(x%5));
	if(x%5){
		mp[x] = std::min(mp[x],solve(x/5+1)+c+d*(5-x%5));
	}
	// printf("%lld %lld\n",x,mp[x]);
	return mp[x];
}

int main(void){
	int t,i,j,k;
	std::cin >> t;
	while(t--){
		std::cin >> n >> a >> b >> c >> d;
		std::cout << solve(n) << std::endl;
		mp.clear();
	}
	return 0;
}


Measured memory_bytes: 4452
#include <stdio.h>
 
#define N 44
 
int main(){
 
  int i,n;
  int F[N];
 
  scanf("%d",&n);
  
    F[0] = 1;
    F[1] = 1;
    
    for(i = 2;i <= n;i ++)
      {
	F[i] = F[i-2] + F[i-1];
      }
    
  printf("%d\n",F[n]);
  
  return 0;

}

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


const int MAXS = 30000;

struct huj 
{
	int w, s, v;
	bool operator <(const huj& b) const {
		return w + s < b.w + b.s;
	}
};

int main()
{
	int n;
	cin >> n;
	vector<huj> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i].w >> a[i].s >> a[i].v;
	}
	
	sort(a.begin(), a.end());
	vector<ll> dp(MAXS);
	for (int i = 0; i < n; i++)
	{
		for (int w = min(a[i].s, MAXS-1 - a[i].w); w >= 0; w--)
		{
			dp[w + a[i].w] = max(dp[w + a[i].w], dp[w] + a[i].v);
		}
	}
	
	ll ans = 0;
	for (int i = 0; i < MAXS; i++)
	{
		ans = max(ans, dp[i]);
	}
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 512
import math
n = int(input())
  
a = math.floor((n / 11))*2
amari = n % 11
if amari == 0:
  print(a)
  exit(0)
  
if amari <= 6:
  print(a + 1)
  exit(0)

if amari > 6:
  print(a + 2)
  exit(0)

print(a)


Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<utility>
#define MAX 500002
using namespace std;
int parent(int i) {
	return i / 2;
}

int left(int i) {
	return 2 * i;
}

int right(int i) {
	return (2 * i) + 1;
}

int H;

void maxHeapify(int A[], int i,int H) {
	int l = left(i);
	int r = right(i);
	int largest;
	
	//左の子、自分、右の子で値が最大のノードを選ぶ
	if (l < H + 1 && A[l] > A[i]) {
		largest = l;
	}
	else {
		largest = i;
	}
	if (r < H + 1 && A[r] > A[largest]) {
		largest = r;
	}
	if (largest != i) {		//iの子の方が値が大きい場合
		swap(A[i], A[largest]);
		maxHeapify(A, largest,H); //再帰的に呼び出し
	}
}

void buildMaxHeap(int A[],int H) {
	for (int i = H / 2; i >0; i--) {
		maxHeapify(A, i,H);
	}
	
}
int main() {
	int A[MAX], x;
	cin >>H;

	for(int j = 1; j < H + 1; j++) {
	    scanf("%d", &x);
		A[j] = x;
	}
	buildMaxHeap(A,H);

	for (int i = 1; i < H + 1; i++) {
		printf(" %d", A[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 5040
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<int> a(n + 1), b(n + 1), p(n + 1);
    for (int i = 1; i <= n; i++) {
        a[i] = 30000 * i;
        int x;
        cin >> x;
        p[x] = i;
    }
    for (int i = 1; i < n + 1; i++) {
        b[i] = 30000 * (n - i) + p[i];
    }
    for (int i = 0; i < n; i++) {
        cout << a[i + 1] << " ";
    }
    cout << endl;
    for (int i = 0; i < n; i++) {
        cout << b[i + 1] << " ";
    }
}


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


int main(){
  int K;
  cin >> K;
  queue<ll> q;

  for(int i=1;i<10;i++) {
    q.push(i);
  }

  int n = 0;
  while( !q.empty() ){
    ll v = q.front(); q.pop();
    n++;
    if (n == K) {
      cout << v << endl;
      break;
    }
    ll nv = v % 10;
    if ( nv != 0 )
      q.push( v*10+ nv-1 );
    q.push( v*10+ nv );
    if ( nv != 9 )
      q.push( v*10+ nv+1 );
  }
}


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

#define Ms(s, n) memset(s, n, sizeof(s))
#define Rp(i,l,m) for(int i=l; i<m; ++i)
#define Rpd(i,l,m) for(int i=l; i>=m; --i)
#define Rpp(i,l,m) for(int i=l; i<=m; i++)
#define RpAll(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define All(a) (a).begin(), (a).end()
#define Fi first
#define Se second
#define Pb push_back
#define Pf push_front
#define Is insert
#define Sz(a) int((a).size())
#define ooi INT_MAX
#define ool LLONG_MAX
typedef long long ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
const int MOD = (int) 1e9 + 7;
const ld PI = acos((ld) -1);
inline ll gcd(ll a,ll b) {ll r;while(b){r=a%b;a=b;b=r;}return a;}
inline ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
inline ll fpow(ll n,ll k){ll r=1; for(;k;k>>=1){if(k&1)r=r*n%MOD;n=n*n%MOD;}return r;}
const int base = 311;
const int N = 2e5 + 5;

ll n, m, k, test, a[N], f[N];
double b[200];
void Solve(){
    cin >> n;
    ld s = 0;
    for(int i = 1; i<=n; i++){
        ld x;
        cin >> x;
        s += 1/x;
    }
    s = 1/s;
    cout << s;

}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed;
    Solve();
    return 0;
}




















Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
inline int rd() {
    char ch=getchar(); int i=0,f=1;
    while(!isdigit(ch)) {if(ch=='-')f=-1; ch=getchar();}
    while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=getchar();}
    return i*f;
}
const int N=2e5+50,INF=0x3f3f3f3f;
int n,col[N],fa[N],sze[N];
int d1[N]; //子树最远点
int d2[N]; //父亲最远点
int d3[N]; //经过存在黑点的子树最近点
int d4[N]; //经过存在黑点的父亲最近点
int d5[N]; //不经过某子树最远点
int d6[N]; //下界 
vector <int> edge[N]; 
inline void dfs1(int x,int f) {
    fa[x]=f; sze[x]=col[x];
    if((x!=1 && edge[x].size()==1) || (x==1 && !edge[x].size())) {
        d1[x]=0; 
        d3[x]=(col[x]?0:INF);
        return;
    }
    int mx=0,mx2=INF;
    for(auto v:edge[x]) {
        if(v==f) continue;
        dfs1(v,x); sze[x]+=sze[v];
        mx=max(mx,d1[v]); 
        if(d3[v]<INF) mx2=min(mx2,d1[v]);
    }
    d1[x]=mx+1; d3[x]=mx2+1; 
    if(col[x]) d3[x]=min(d3[x],d1[x]); 
}
inline void dfs2(int x,int f) {
    d2[x]=max(d2[x],(f!=0)+d2[f]);
    if(f) d5[x]=max(d5[x],d2[x]-1);
    int mx,mx2;
    mx=-1;
    for(int e=0;e<edge[x].size();++e) {
        int v=edge[x][e]; if(v==f) continue;
        d2[v]=max(d2[v],mx+2);
        mx=max(mx,d1[v]);
    }
    mx=-1;
    for(int e=edge[x].size()-1;e>=0;e--) {
        int v=edge[x][e]; if(v==f) continue;
        d2[v]=max(d2[v],mx+2);
        mx=max(mx,d1[v]);
    }
    for(auto v:edge[x]) if(v!=f) dfs2(v,x);
}
int main() { 
    n=rd();
    memset(d3,0x3f,sizeof(d3));
    memset(d4,0x3f,sizeof(d4));
    for(int i=1;i<n;i++) {
        int x=rd(), y=rd();
        edge[x].push_back(y);
        edge[y].push_back(x); 
    }
    string s; cin>>s; int bz=0;
    for(int i=0;i<n;i++) col[i+1]=s[i]-'0', bz|=col[i+1];
    if(!bz) {puts("0"); return 0;}
    dfs1(1,0); 
    dfs2(1,0);
    long long ans=0;
    for(int i=1;i<=n;i++) {
        if(col[i]) d6[i]=0;
        else d6[i]=min(d3[i],(sze[i]==sze[1])?INF:d2[i]);
        int u=max(d1[i],d2[i])-1;
        for(auto v:edge[i]) {
            if(v==fa[i]) u=min(u,d1[i]+1);
            else u=min(u,d5[v]+1);
        } 
        if(u>=d6[i]) ans=ans+u-d6[i]+1;
    }
    cout<<ans+1;
}

Measured memory_bytes: 24836
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[20];cin>>s;
    int n=strlen(s);
    if(n<4)puts("No");
    else
    {
        if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I')puts("Yes");
        else puts("No");
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int read() {
	int x; scanf("%d", &x); return x;	
}
const int maxn = 2e5 + 10;
const int INF = 1e9;
int mod = 1e9 + 7;
using namespace std;

int a[maxn], n;
int main() {
	#ifdef LOCAL
		freopen("1.in", "r", stdin);
	#endif
	n = read();
	int ans = 0;
	for (int i = 1; i <= n; ++i) a[i] = read(), ans += (i & 1 && a[i] & 1);
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 3760
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<utility>
#include<bitset>
#include<complex>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>

using namespace std;

#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=a; i<=b; ++i)
#define FOR(i,a,b) for(int i=a; i<b; ++i)
#define MP make_pair
typedef long long LL;
typedef pair<int,int> pii;

const int maxn = 3e5;

int n;
LL arr[maxn+2];
LL f1[maxn+2], f2[maxn+2];

struct Nd1 {
	LL x;
	Nd1(): x(0) {}
	Nd1(LL _x) { x = _x; }
	bool operator<(const Nd1 &a) const {
		return x > a.x;
	}
};

struct Nd2 {
	LL x;
	Nd2(): x(0) {}
	Nd2(LL _x) { x = _x; }
	bool operator<(const Nd2 &a) const {
		return x < a.x;
	}
};

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n*3; ++i)
		scanf("%lld", arr+i);

	LL sum;

	sum = 0;
	priority_queue< Nd1 > que1;
	for(int i = 1; i <= n; ++i) {
		sum += arr[i];
		que1.push( Nd1(arr[i]) );
	}
	f1[n] = sum;
	for(int i = n+1; i <= n*2; ++i) {
		Nd1 tmp = que1.top();
		if(tmp.x < arr[i]) {
			sum = sum - tmp.x + arr[i];
			que1.pop();
			que1.push( Nd1(arr[i]) );
		}
		f1[i] = sum;
	}

	sum = 0;
	priority_queue< Nd2 > que2;
	for(int i = n*2 + 1; i <= n*3; ++i) {
		sum += arr[i];
		que2.push( Nd2(arr[i]) );
	}
	f2[n*2+1] = sum;
	for(int i = n*2; i >= n+1; --i) {
		Nd2 tmp = que2.top();
		if(tmp.x > arr[i]) {
			sum = sum - tmp.x + arr[i];
			que2.pop();
			que2.push( Nd2(arr[i]) );
		}
		f2[i] = sum;
	}

	/*
	for(int i = n; i <= n*2; ++i)
		printf("f1[%d] = %lld\n", i, f1[i]);

	printf("\n");
	for(int i = n+1; i <= n*2+1; ++i)
		printf("f1[%d] = %lld\n", i, f1[i]);
		*/

	LL ans = -(1LL << 60);
	for(int i = n; i <= n*2; ++i)
		ans = max(ans, f1[i] - f2[i+1]);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 7668
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {
	
	static int N;
	static long[] bit;
	
	static void update(int x, long v){
		while(x <= N) {
			bit[x] = Math.max(bit[x], v);
			x += x&-x;
		}
	}
	
	static long query(int i) {
		long ans = 0;
		while(i > 0) {
			ans = Math.max(ans, bit[i]);
			i -= i&-i;
		}
		return ans;
	}
	
	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		
		N = Integer.parseInt(br.readLine());
		int[] h = new int[N]; int[] a = new int[N];
		
		st = new StringTokenizer(br.readLine());
		for(int i=0; i<N; i++) {
			h[i] = Integer.parseInt(st.nextToken());
		}
		
		st = new StringTokenizer(br.readLine());
		for(int i=0; i<N; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}
		
		long[] dp = new long[N];
		bit = new long[N+1];
		
		dp[0] = a[0];
		update(h[0], a[0]);
		for(int i=1; i<N; i++) {
			dp[i] = query(h[i]) + a[i];
			update(h[i], dp[i]);
		}
		
		long ans = 0;
		for(int i=0; i<N; i++) {
			ans = Math.max(ans, dp[i]);
		}
		System.out.println(ans);
		
	}
}


Measured memory_bytes: 59040
#include<bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <iomanip>
*/ 
using namespace std;

#define endl "\n"
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define re(i,a) for(ll i=0; i<a; ++i)
#define tr(i,v) for(auto &i: v)
#define mem(a,val) memset(a,val,sizeof(a))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define in(v,n) vll v(n);re(i,n) cin>>v[i]
#define printVec(v,s) cout << s; tr(i, v) cout << i << " ";
#define sz(a) int((a).size())
#define dbgv(c, v) cout << c << " = " << v << endl;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<ll, ll> pll;
typedef vector< pll > vpll;
typedef vector< ll > vll;
typedef complex<double> point;

const long long MOD = 1000000007;
const long long inf = 1e18;

ll n,m,x;
vector<vll> a;
vll c;

ll foo(ll i, ll currCost, vll currSkills){
    if(i == n) return inf;
    vll tempSkills(m);
    ll mini=inf;
    re(j,m){
        tempSkills[j] = currSkills[j] + a[i][j];
        mini = min(mini, tempSkills[j]);
    }
    if(mini >= x) return currCost + c[i];
    return min( foo(i+1, currCost, currSkills), foo(i+1, currCost + c[i], tempSkills));
}

void solve(){
	cin>>n>>m>>x;
    c= vll(n);
    a = vector<vll>(n);
    vector<vll> b = vector<vll>(n);
    re(i, n){
        a[i] = (vll(m));
        b[i] = (vll(m));
    }

    map<ll, vll> cind;

    re(i, n){
        cin>>c[i];
        cind[c[i]].pb(i);
        re(j, m){
            cin >> b[i][j];
        }
    }

    sort(all(c));

    map<ll, ll> ind;

    re(i, n) ind[c[i]] = 0;

    re(i, n){
        a[i] = b[cind[c[i]][ind[c[i]]]];
        ind[c[i]]++;
    }

    vll curSKil(n, 0);
    ll ans = foo(0, 0, curSKil);

    if(ans > 1e12) cout << "-1";
    else cout << ans;
}

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	#endif 
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    	solve();
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 3796
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	cin>>n;
	int player[n];
	rep(i,n)player[i]=0;
	int card[3][n];
	rep(i,n)rep(j,3)cin>>card[j][i];
	rep(i,3){
		int check[101];
		rep(j,101)check[j]=0;
		rep(j,n)check[card[i][j]]++;
		rep(j,101){
			if(check[j]==1){
				rep(k,n){
					if(card[i][k]==j)player[k]+=card[i][k];
				}
			}
		}
	}
	rep(i,n)cout<<player[i]<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int n;
    cin >> n;
    int A[n];
    REP(i,n) cin >> A[i];
    int ruisekiwa[n + 1];
    ruisekiwa[0] = 0;
    REP(i,n) ruisekiwa[i + 1] = ruisekiwa[i] + A[i];
    int zenhan[n],kouhan[n];

    int summ = A[0] + A[1];
    int tmp_sum = A[0];
    int id = 1;
    FOR(i,2,n){
        while( (tmp_sum + A[id]) * 2 <= ruisekiwa[i] ) tmp_sum += A[id], id ++;
        if( max(tmp_sum,ruisekiwa[i] - tmp_sum) <= max(tmp_sum + A[id] , ruisekiwa[i] - tmp_sum - A[id]) ) zenhan[i] = max(tmp_sum,ruisekiwa[i] - tmp_sum);
        else{
            tmp_sum += A[id];
            id ++;
            zenhan[i] = max(tmp_sum,ruisekiwa[i] - tmp_sum);
        }
    } 

    summ = A[n-1] + A[n-2];
    tmp_sum = A[n-1];
    id = n -2;
    REPR(i,n-2){
        while( (tmp_sum + A[id]) * 2 <= ruisekiwa[n] - ruisekiwa[i] ) tmp_sum += A[id], id--;
        if( max(tmp_sum,ruisekiwa[n] - ruisekiwa[i] - tmp_sum) <= max(tmp_sum + A[id],ruisekiwa[n] - ruisekiwa[i] - tmp_sum - A[id])) kouhan[i] = max(tmp_sum,ruisekiwa[n] - ruisekiwa[i] - tmp_sum);
        else{
            tmp_sum += A[id];
            id --;
            kouhan[i] = max(tmp_sum,ruisekiwa[n] - ruisekiwa[i] - tmp_sum);
        }
    }

    int ans = INF;
    FOR(i,2,n-1){
        chmin(ans, max(zenhan[i],kouhan[i]) - min(ruisekiwa[i] - zenhan[i],ruisekiwa[n] - ruisekiwa[i] - kouhan[i]) );
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 6528