akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
using namespace std;

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

const ll MX = 100001;

ll N, M;
vector<int> vis(MX, 0);
vector<int> g[MX];

void dfs(int u){
    if(vis[u]) return;
    vis[u] = 1;
    for(int v : g[u]){
        if(vis[v]) continue;
        dfs(v);
    }
}

int main(){
    //freopen("in.txt", "r", stdin);
    cin>>N>>M;
    for(int i=0; i<M; i++){
        int u, v;
        cin>>u>>v;
        g[u].push_back(v); 
        g[v].push_back(u);
    }

    int ans = 0;
    for(int u=1; u<=N; u++){
        if(!vis[u]){
            ans++;
            dfs(u);
        }
    }

    cout<<ans - 1<<endl;

    return 0;
}





Measured memory_bytes: 9516
N = int(input())
A = list(map(int, input().split(' ')))
B = list(map(int, input().split(' ')))
plusSubject = []

sumA = sum(A)
sumB = sum(B)

if sumA < sum(B):
    print('-1')
    exit()
ans = 0
totalMinus = 0
for a, b in zip(A, B):
    if a-b > 0:
        plusSubject.append(a-b)
    elif a-b < 0:
        totalMinus += a-b
        ans += 1

plusSubject = sorted(plusSubject, reverse=True)

for plus in plusSubject:
    if totalMinus >= 0:
        break
    totalMinus += plus
    ans += 1
print(ans)


Measured memory_bytes: 18356
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

int main(){
    int x;
    cin>>x;
    if(x<1200)cout<<"ABC"<<endl;
    else cout<<"ARC"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>
#include <string>
#include <sstream>

using namespace std;

int main(void){

    string year,month,day;

    string S;
    cin>>S;
    stringstream ss(S);
    getline(ss,year,'/');
    getline(ss,month,'/');
    getline(ss,day,'/');

    int y,m,d;
    y=stoi(year);
    m=stoi(month);
    d=stoi(day);

    string ans="TBD";

    if(y<=2018||(y==2019&&m<=4)){ans="Heisei";}

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

Measured memory_bytes: 256
def InsertSort(A, n, g, cnt):
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v
    return cnt
        
def ShellSort(A, n):
    cnt = 0
    G = [1]
    h = G[0]
    while True:
        h = h*3 + 1
        if h > n:
            break
        G.append(h)
    print(len(G))
    print(' '.join(reversed(list(map(str, G)))))
    for h in reversed(G):
        cnt = InsertSort(A, n, h, cnt)
    print(cnt)
            
n = int(input())
A = []
for _ in range(n):
    A.append(int(input()))
    
ShellSort(A, n)

for num in A:
    print(num)


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

using namespace std;
using Graph = vector<vector<int>>;
using Grid= vector<vector<char>>;
using vin= vector<int>;
using ll=long long;
using vll= vector<ll>;
using vbl=vector<bool>;
using vch=vector<char>;
using pinin=pair<int ,int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rell(i,n) for (ll i=0; i< (ll)(n); i++)
#define sort(x) sort(x.begin(), x.end());
#define rese(x) reverse(x.begin(), x.end());

string yes="Yes",no="No";

int main() {
  ll n;
  cin>>n;
  ll sum=0;
  vll x(n);
  rell(i,n){
      cin>>x[i];
      sum+=x[i];
  }
  ll p=sum/n;
  if(sum<=n*p+n/2){
      
  }
  else p+=1;
  ll ans=0;
  rell(i,n){
      ans+=(x[i]-p)*(x[i]-p);
  }
  cout<<ans<<endl;
  
}


Measured memory_bytes: 3616
n, k = gets.split(" ").map(&:to_i)

ans = 0

1.upto(n) do |i|
  next unless (i * 2) % k == 0 

  m = i / k

  c = ((i + n) / k) - m

  next if c < 0

  ans += c * c
end

puts ans


Measured memory_bytes: 1788
a = '1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'.split(', ')
print(a[int(input()) - 1])

Measured memory_bytes: 2940
class MyNode
  attr_accessor :v, :parent, :left_child, :right_child

  def initialize v, parent, left_child, right_child
    @v = v
    @parent = parent
    @left_child = left_child
    @right_child = right_child
  end
end

def insert(root_node, v)
  p = nil
  x = root_node
  while x
    p = x
    if v < x.v
      x = x.left_child
    else
      x = x.right_child
    end
  end
  node = MyNode.new(v, p, nil, nil)
  if p
    if node.v < p.v
      p.left_child = node
    else
      p.right_child = node
    end
  else
    root_node = node
  end

  return root_node
end

def find(root_node, v)
  return true if root_node.v == v
  if v < root_node.v && root_node.left_child
    return find(root_node.left_child, v)
  end
  if v > root_node.v && root_node.right_child
    return find(root_node.right_child, v)
  end
  return false
end

def make_pre node, vs
  vs << node.v
  make_pre node.left_child, vs if node.left_child
  make_pre node.right_child, vs if node.right_child
  vs
end

def make_in node, vs
  make_in node.left_child, vs if node.left_child
  vs << node.v
  make_in node.right_child, vs if node.right_child
  vs
end

_ = gets
root = nil
while l = gets
  command, val = l.chomp.split(' ')
  if command == 'insert'
    root = insert(root, val.to_i)
  elsif command == 'print'
    puts ' ' + make_in(root, []).join(' ')
    puts ' ' + make_pre(root, []).join(' ')
  elsif command == 'find'
    puts find(root, val.to_i) ? 'yes' : 'no'
  end
end


Measured memory_bytes: 59240
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 998244353
using namespace std;
int main() {
    ll n, k;
    cin >> n >> k;
    map<ll, ll> mp;
    for(int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        mp[a] += b;
    }
    for(auto e : mp) {
        if(k > e.second) {
            k -= e.second;
        } else {
            cout << e.first << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 4224
from collections import defaultdict, deque
N = int(input())
G = defaultdict(lambda: [])
for _ in range(N-1):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)


def bfs(v):
    seen = [0]*(N+1)
    queue = deque()
    dist = [-1]*(N+1)
    dist[v] = 0
    seen[v] = 1
    queue.append(v)
    while queue:
        q = queue.popleft()
        for nx in G[q]:
            if seen[nx]:
                continue
            dist[nx] = dist[q] + 1
            seen[nx] = 1
            queue.append(nx)
        # if not G[q]:
        #     queue.popleft()
        #     continue
        # g = G[q].popleft()
        # if seen[g]:
        #     continue
        # seen[g] = 1
        # dist[g] = dist[q] + 1
        # queue.append(g)
    return dist

d_1 = bfs(1)
d_N = bfs(N)
f = 1
s = 1
for v in range(2, N):
    if d_1[v] <= d_N[v]:
        f += 1
    else:
        s += 1
if f > s:
    print("Fennec")
else:
    print("Snuke")

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

#define BeatMeScanf    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tc(x)          int x; cin >> x; while(x--)
#define ll             long long
#define vi             vector<int>
#define pii            pair<int,int>
#define mii            map<int,int>
#define inf            1<<28
#define mem(x,y)       memset(x, y, sizeof(x))
#define ps(x,y)        fixed<<setprecision(y)<<x
#define show(val)      cout<< #val << " -> " << val << endl
#define Case           cout<< "Case "<< ++cs << ": "
#define all(v)         (v).begin(), (v).end()
#define rall(v)        (v).rbegin(), (v).rend()
#define MOD            1000000007
#define MAX            100005

int main()
{
	BeatMeScanf;
	double r;
	cin >> r;
	double ans = 2.00*3.14159265358979323*r;
	cout<< fixed<<setprecision(10)<<ans <<'\n';
	return 0;
}


Measured memory_bytes: 3800
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<stdio.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<set>
#include<math.h>
#include<stack>
#include<sstream>
#include<queue>
#include<list>
#include<iomanip>
#include<bitset>
#include<limits.h>
#define MOD  1000000007
#define BIG  200001
#define ii pair<int,int>
#define iii pair<int,pair<int,int> >
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define vi vector<int>
#define pi pair<int,int>
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define all(n) n.begin(),n.end()

typedef  long long ll;
using namespace std;

int main()
{
    // freopen("input.txt", "r", stdin);
    IO ;
 int n ;
 string str  ;
 cin >> n >> str ;
 int mx = -1  , a = 0  ;
 for(int i = 1 ; i<n ; i++){
        string s , s1 ;
         int arr[27] ={}, arr1[27] = {};

    for(int y = 0 ; y<i ;y++){
        s+= str[y] ;
        arr[str[y]-'a']++;
    }
    for(int y =i ; y<n ; y++ ){
        s1 +=str[y] ;
        arr1[str[y]-'a']++;
    }
    for(int y =0 ; y<26 ; y++){
        if(arr[y]>0 && arr1[y]>0)a++;

    }
 mx = max(mx , a) ;
 a=0 ;
 }
 cout << mx << endl ;
    return 0 ;
}


Measured memory_bytes: 256
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n=n0()
print("Yes" if str(n).count('7')>0 else "No")

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

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

typedef struct node * Node;
#define NIL NULL

Node root;

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

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

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

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

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

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

  if(x != NIL){
    x->parent = y->parent;
  }

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

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

  free(y);
}

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: 20444
#include <algorithm>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <thread>
#include <tuple>
#include <type_traits>
#include <vector>


#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    sort(a.begin(), a.end(), greater<int>());

    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (i == 0)
            continue;
        else if (i == 1)
            ans += a[0];
        else
            ans += a[i / 2];
    }

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


Measured memory_bytes: 3676
n,m = map(int, input().split())
mini = 0
maxi = 10**9
for i in range(m):
    l,r = map(int, input().split())
    if mini < l:
        mini = l
    if r < maxi:
        maxi = r
t = maxi -mini + 1
if maxi < mini:
    print(0)
else:
    print(t)

Measured memory_bytes: 9204
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;//typo用
using uintl = unsigned long long;
using itn = int;//typo用
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a) - 1; i >= (intl)(b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl//1次元配列の出力
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl//二次元配列の出力
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = acos(-1);
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl kai(intl k){//k!を求める関数,
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl digit10(intl a){//aを10進数で表したときの桁数を求める関数
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}

signed main(){
    cout << fixed << setprecision(10);
    intl n,k;
    cin >> n >> k;
    intl a[n];
    rep(i,n)cin >> a[i];
    intl b[n + 1];
    rep(i,k){
        bool f = true;
        m0(b);
        rep(j,n){
            if(a[j] != n)f = false;
            b[max(0LL,j - a[j])]++;
            b[min(n,j + a[j] + 1)]--;
        }
        if(f)break;
        rep(i,n)a[i] = b[i];
        rep(i,n - 1){
            a[i + 1] += a[i];
        }
    }
    rep(i,n)cout << a[i] << " ";
    return 0;
}


Measured memory_bytes: 6760
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    // distancia - soma
    unordered_map<int, int> f;
    int n;
    cin >> n;
    vi v(n);
    for(auto& x : v) cin >> x;
    for(int i = 1; i < n; ++i) {
        int d = i;
        int soma = (v[0] + v[i]);
        f[d - soma]++;
    }
    long long ans = 1ll * f[0];
    for(int i = 1; i < n; ++i) {
        // vamos tirar o cara i
        int d = i;
        int soma = v[0] + v[i];
        f[d - soma]--;
        // quanto eu mudo a soma em relacao ao primeiro
        int delta = (v[0] - v[i]);
        // sei que a soma relativa mudou em +delta
        // e que a distancia relativa mudou em -i
        int target = 0;
        target -= i; // distancia diminuiu
        target += delta;
        ans += 1ll * f[-target];
    }
    cout << ans << '\n';

    return 0;
}



Measured memory_bytes: 19324
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
using namespace std;
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb(X) push_back(X)
#define x first
#define y second
#define all(x) (x).begin(), (x).end()
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
typedef long long ll;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef pair<int, int> pii;
//ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}


const int INF = 1e9 + 7;
int _;

int main() {
	INIT
	ll a, b= 0;
	cin >> a;
	ll c = a / 500;
	b += c * 1000;
	ll d = a % 500;
	b += ( d / 5) * 5;
	cout << b;
	return 0;
}
/*
rep (i, 0, n) {
		if (i) cout << ' ';
		cout << A[i];
	}
*/

Measured memory_bytes: 256
package main

import(
	"fmt"
	"sort"
)

func main(){
	var n int
	fmt.Scanln(&n)
	d:=make([]int,n)
	for i:=0;i<n;i++{
		fmt.Scan(&d[i])
	}
	sort.Ints(d)
	fmt.Println(d[n/2]-d[n/2-1])
}

Measured memory_bytes: 5504
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int z = 0;
		
		if (a-b >= c ) {
			z = 0;
			System.out.println(z);
		} else {
			z = c - (a-b);
			System.out.println(z);
		}
		
	}

}


Measured memory_bytes: 35620
#include<bits/stdc++.h>
using namespace std;
const int N=210;

int n,k,mod,ans,L[N],R[N],fac[N],f[N][N],sum[N][N];

int add(int a,int b) {
	return a+b>=mod?a+b-mod:a+b;
}

int solve(int n,int k) {
	if(n==1) return 1;
	int ways=0;
	for(int a=1;a<=n-1;a++) {
		int b=n-a;
		for(int i=1;i<=a;i++) L[i]=0,R[i]=b;
		L[1]=1;R[a]=0;
		for(int i=1;i<=a;i++) R[i]=min(R[i],k-i+1);
		bool fl=1;
		for(int i=1;i<=b;i++) {
			if(k-i+1>=a) continue;
			if(k-i+1<0) { fl=0;break; }
			L[a-k+i-1]=max(L[a-k+i-1],b-i+1);
		}
		for(int i=1;i<=a;i++)
			if(L[i]>R[i]) { fl=0;break; }
		if(!fl) continue;
		memset(f,0,sizeof(f));
		memset(sum,0,sizeof(sum));
		f[0][b]=1;
		for(int i=b;~i;i--) sum[0][i]=1;
		for(int i=1;i<=a;i++) {
			for(int j=L[i];j<=R[i];j++) f[i][j]=sum[i-1][j];
			for(int j=b;~j;j--) sum[i][j]=add(sum[i][j+1],f[i][j]);
		}
		ways=add(ways,f[a][0]);
	}
	return 1ll*ways*fac[n-1]%mod;
}

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n>>k>>mod;
	fac[0]=1;for(int i=1;i<N;i++) fac[i]=1ll*fac[i-1]*i%mod;
	int ans=0,ways=1;
	for(int i=0;i<=n&&i<=k;i++) {
		ans=(ans+1ll*solve(n-i,k-i)*ways)%mod;
		ways=1ll*ways*(n-i)%mod;
	}
	cout<<ans;
	return 0;
}


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

int main() {
  vector<vector<int>> A(3, vector<int>(3));
  vector<vector<int>> C(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> A.at(i).at(j);
    }
  }
  
  int N;
  cin >> N;
  
  vector<int> b(N);
  for(int i=0; i<N; i++){
    cin >> b.at(i);
  }
  
  bool flag=false;
  
  for(int z=0; z<N; z++){
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
        if(b.at(z) == A.at(i).at(j)){
          C.at(i).at(j) = 111;
        }
      }
    }
  }
  
  for (int i = 0; i < 3; i++) {
    if(C.at(i).at(0)==111 && C.at(i).at(1)==111 && C.at(i).at(2)==111)
      flag=true;
    if(C.at(0).at(i)==111 && C.at(1).at(i)==111 && C.at(2).at(i)==111)
      flag=true;
  }
  if(C.at(0).at(0)==111 && C.at(1).at(1)==111 && C.at(2).at(2)==111)
    flag=true;
  if(C.at(0).at(2)==111 && C.at(1).at(1)==111 && C.at(2).at(0)==111)
    flag=true;
  
  
  if(flag == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}

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

//上無限
const long long Inf = 1LL << 60;

#define tmax(n,l,m) std::max(n,std::max(l,m))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


long long dp[110][100100] = {0};
int N;
long long W, weight[110], value[110];


int main()
{

    cin >> N >> W;
    for(int i = 0;i < N;++i)
        cin >> weight[i] >> value[i];
    
    for(int i = 0;i < N; ++i)
    {
        for(int sumW = 0;sumW <= W; ++sumW)
        {
            if(sumW - weight[i] >= 0)
            {
                chmax(dp[i + 1][sumW],dp[i][sumW - weight[i]] + value[i]);
            }
            chmax(dp[i+1][sumW],dp[i][sumW]);
        }
    }
    cout << dp[N][W] <<endl;
}

Measured memory_bytes: 79360
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<functional>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N,M;
vector<P> connectVec[100010];
ll potential[100010];
bool finish=false;
void SetPot(ll now){
    if(finish)return;
    for(auto p:connectVec[now]){
        if(finish)break;
        ll v=p.first;
        ll d=p.second;
        if(potential[v]==INF){
            potential[v]=potential[now]+d;
            SetPot(v);
        }else if(potential[v]!=potential[now]+d){
            cout<<"No"<<endl;
            finish=true;
        }
        if(finish)break;
    }
}
int main(){
    cin>>N>>M;
    for(ll i=0;i<M;i++){
        ll l,r,d;
        cin>>l>>r>>d;
        l--;r--;
        connectVec[l].push_back(P(r, d));
        connectVec[r].push_back(P(l,-d));
    }
    for(ll i=0;i<N;i++){
        potential[i]=INF;
    }
    for(ll i=0;i<N;i++){
        if(potential[i]!=INF)continue;
        potential[i]=0;
        SetPot(i);
    }
    if(finish)return 0;
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const int MAX = 100000;
const int inf = 2000000000;

struct Card{
    char suit;
    int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(Card A[], int left, int mid, int right){
    int n1 = mid-left;
    int n2 = right-mid;
    for(int i=0; i<n1; i++) L[i] = A[left+i];
    for(int i=0; i<n2; i++) R[i] = A[mid+i];
    L[n1].value = R[n2].value = inf;
    int i = 0, j = 0;
    for(int k=left; k<right; k++){
        if(L[i].value <= R[j].value) A[k] = L[i++];
        else A[k] = R[j++];
    }
}

void mergeSort(Card A[], int left, int right){
    int mid;
    if(left+1 < right){
        mid = (left + right)/2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int partition(Card A[], int p, int r){
    Card x = A[r];
    int i=p-1;
    for(int j=p; j<r; j++){
        if(A[j].value <= x.value){
            i++;
            swap(A[j], A[i]);
        }
    }
    swap(A[r], A[i+1]);

    return i+1;
}

void quickSort(Card A[], int p, int r){
    if(p < r){
        int q = partition(A, p, r);
        quickSort(A, p, q-1);
        quickSort(A, q+1, r);
    }
}

int main(){
    Card A[MAX], B[MAX];
    char s[10];
    bool stable = true;

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

    int v;
    for(int i=0; i<n; i++){
        scanf("%s %d", s, &v);
        A[i].suit = B[i].suit = s[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, 0, n);
    quickSort(B, 0, n-1);

    for(int i=0; i<n; i++){
        if(A[i].suit != B[i].suit) stable = false;
    }

    if(stable == true) printf("Stable\n");
    else printf("Not stable\n");
    for(int i=0; i<n; i++){
        printf("%c %d\n", B[i].suit, B[i].value);
    }

    return 0;
}


Measured memory_bytes: 5524
a,b,c = map(int,input().split())

ans=0
max_num=max(a,b,c)
min_num=min(a,b,c)
mid_num=a+b+c-max_num-min_num

ans += max_num-mid_num

mid_num= max_num
min_num= min_num + ans

if (max_num-min_num)%2==0:
  ans += (max_num-min_num)//2
else:
  ans += (max_num-min_num)//2+2
print(ans)

Measured memory_bytes: 3064
import java.util.*;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] nums=new int[3];
        for(int i=0;i<3;i++){
            nums[i]=sc.nextInt();
        }
        Arrays.sort(nums);
        if(nums[0]==5&&nums[1]==5&&nums[2]==7){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
    
 
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const int mod = 100000;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vector<vector<int>> ans(h, vector<int>(w, INF));
  queue<P> q;
  auto update = [&](P now) {
    int i = now.first, j = now.second;
    rep(k, 2) {
      int ni = i+di[k], nj = j+dj[k];
      if(ni >= h || nj >= w) continue;
      if(s[i][j] == '.' && s[ni][nj] == '#') {
        if(chmin(ans[ni][nj], ans[i][j]+1)) q.push(P(ni, nj));
      }
      else if(chmin(ans[ni][nj], ans[i][j])) q.push(P(ni, nj));
    }
  };
  ans[0][0] = ((s[0][0]=='.')?0:1);
  q.push(P(0, 0));
  while(!q.empty()) {
    P now = q.front(); q.pop();
    update(now);
  }
  cout << ans[h-1][w-1] << endl;
}

Measured memory_bytes: 3696
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <time.h>

using namespace std;
int main(){
  clock_t start = clock();
  int d;
  cin >> d;
  vector<int> c(26),tmp(26);
  vector<vector<int>> s;
  for(int i=0;i<26;i++){
    cin >> c[i];
  }
  for(int i=0;i<d;i++){
    for(int j=0;j<26;j++){
      cin >> tmp[j];
    }
    s.push_back(tmp);
  }
  vector<int> t(d,1);
  
  vector<int> v(d+1,0),last(26,0);
  for(int i=1;i<d+1;i++){
    for(int j=1;j<=26;j++){
      int v_tmp = v[i-1] + s[i-1][j-1];
      for(int k=0;k<26;k++){
        if(k!=j-1){
          v_tmp -= c[k] * (i - last[k]);
        }
      }
      if(v[i]==0||v_tmp>v[i]){
        v[i] = v_tmp;
        t[i-1] = j;
      }
    }
    last[t[i-1]-1] = i;
  }
  
  clock_t end = clock();
  int change = d-3;
  int vfirst;
  while((double)(end-start)/CLOCKS_PER_SEC<0.5&&v[d]<0){
    change--;
    for(int i=1;i<=26;i++){
      t[change] = i;
      vector<int> last_tmp(26,0);
      for(int j=1;j<=change;j++){
        last_tmp[t[j-1]-1] = j;
      }
      
      for(int ji=change+1;ji<d+1;ji++){
        vfirst = v[ji];
        for(int j=1;j<=26;j++){
          int v_tmp = v[ji-1] + s[ji-1][j-1];
          for(int k=0;k<26;k++){
            if(k!=j-1){
              v_tmp -= c[k] * (ji - last_tmp[k]);
            }
          }
          if(v[ji]==vfirst||v_tmp>v[ji]){
            v[ji] = v_tmp;
            t[ji-1] = j;
          }
        }
        last_tmp[t[ji-1]-1] = ji;
      }
    }
    end = clock();
  }
  
  //cout << v[d] << endl;
  for(int i=0;i<d;i++){
    cout << t[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3708
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    E=[[] for _ in range(n)]
    for _ in range(n-1):
        u,v,w=map(int,input().split())
        u-=1; v-=1; w%=2
        E[u].append((v,w))
        E[v].append((u,w))

    d=[0]*n
    def dfs(v,p):
        for nv,w in E[v]:
            if(nv==p): continue
            d[nv]=d[v]^w
            dfs(nv,v)
    dfs(0,-1)
    print(*d,sep='\n')
resolve()

Measured memory_bytes: 161200
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;


int main(){
    int m,n;
    cin >> n >> m;
    vector<map<int,int>> d(n+1);
    vector<map<int,vector<int>>> e(n+1);
    rep(i,m){
        int p,q,c;
        cin >> p >> q >> c;
        e[p][c].push_back(q);
        e[q][c].push_back(p);
        d[p][c]=inf;
        d[q][c]=inf;
    }
    rep(i,n+1) d[i][-1]=inf;
    d[1][-1]=0;
    queue<pair<pp,int>> q;
    q.push(make_pair(make_pair(1,-1),0));
    while (!q.empty()){
        int f=q.front().first.first,g=q.front().first.second,h=q.front().second;
        q.pop();
        if (g==-1){
            for(auto itr = d[f].begin(); itr != d[f].end(); ++itr){
                if (itr->second>h+1) {
                    q.push(make_pair(make_pair(f,itr->first),h+1));
                    d[f][itr->first]=h+1;
                }
            }
        }
        else {
            rep(i,e[f][g].size()){
                if (d[e[f][g][i]][g]>h){
                    q.push(make_pair(make_pair(e[f][g][i],g),h));
                    d[e[f][g][i]][g]=h;
                }
            }
            if (d[f][-1]>h) {
                q.push(make_pair(make_pair(f,-1),h));
                d[f][-1]=h;
            }
        }
    }
    if (d[n][-1]==inf) cout << -1 << endl;
    else cout << d[n][-1] << endl;
}


Measured memory_bytes: 78080
import static java.util.Comparator.comparing;

import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==========================================================
    int N, M;
    Map<Integer, List<Integer>> map = new HashMap<>();
    int[] memo;
    boolean[] f;
    int calc(int now) {
//    	out.println("calc start  now = " + now);
    	if(memo[now] != -1) {
//    		out.println("   return memo = " + memo[now]);
    		return memo[now];
    	}
    	int ans = 0;
    	List<Integer> list = map.get(now);
    	if(list == null)	return 0;
    	for(int y : list) {
    		if(f[y])	continue;
    		f[y] = true;
    		ans = Math.max(ans, calc(y) + 1);
    		f[y] = false;
    	}
//    	out.println("  --> now = " + now + "  return " + ans + "\n");
    	return memo[now] = ans;
    }
    public void solve() {
    	N = ni();
    	M = ni();
    	memo = new int[N];
    	f = new boolean[N];
    	int x, y;
    	List<Integer> list;
    	for (int i = 0; i < M; i++) {
			x = ni() - 1;
			y = ni() - 1;
			list = map.get(x);
			if(list == null) {
				list = new ArrayList<>();
				map.put(x, list);
			}
			list.add(y);
		}
    	int ans = 0;
    	Arrays.fill(memo, -1);
    	for (int i = 0; i < N; i++) {
        	Arrays.fill(f, false);
        	f[i] = true;
			ans = Math.max(ans, calc(i));
		}
    	out.println(ans);
    }
    // ------------------------------------------
    // 入力
    // ------------------------------------------
    public int ni() {
    	return sc.nextInt();
    }
    public long nl() {
    	return sc.nextLong();
    }
    public String ns() {
    	return sc.next();
    }
    public char[] nc() {
    	return sc.next().toCharArray();
    }
    public int[] ndi(int N) {
    	int[] ans = new int[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ni();
		}
    	return ans;
    }
    public long[] ndl(int N) {
    	long[] ans = new long[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = nl();
		}
    	return ans;
    }
    public String[] nds(int N) {
    	String[] ans = new String[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ns();
		}
    	return ans;
    }
    public char[][] ndc(int N) {
    	char[][] ans = new char[N][];
    	for (int i = 0; i < N; i++) {
			ans[i] = nc();
		}
    	return ans;
    }
    public int[][] nddi(int N, int S) {
    	int[][] ans = new int[N][S];
    	for (int i = 0; i < N; i++) {
			for (int j = 0; j < S; j++) {
				ans[i][j] = ni();
			}
		}
    	return ans;
    }
}


Measured memory_bytes: 113020
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
#define endl "\n"
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"")<<i;f=1;}cout<<endl;}while(0)
using datas=pair<ll,ll>;
using tdata=pair<ll,datas>;

int main(){
  ll i,j=0,N,K,x;
  cin>>N;
  K=pow(2,N);
  multiset<ll> se;
  rep(i,K){
    cin>>x;
    se.insert(-x);
    j=max(j,x);
  }
  K=1;
  vec v(1,-j);
  se.erase(-j);
  rep(i,N){
    v.resize(K*2);
    rep(j,K){
      auto itr=se.upper_bound(v[j]);
      if(itr==se.end()){
        cout<<"No"<<endl;
        return 0;
      }
      v[j+K]=*itr;
      se.erase(itr);
    }
    K*=2;
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 15736
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys

INF = float('inf')


def solve(L: int):
    return L**3 / 27


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = int(next(tokens))  # type: int
    print(f'{solve(L)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 74904
#include <stdio.h>

int main(void)
{
	double weight;
	
	while (scanf("%lf", &weight) != EOF){
		if (weight <= 48) printf("light fly\n");
		else if (weight <= 51) printf("fly\n");
		else if (weight <= 54) printf("bantam\n");
		else if (weight <= 57) printf("feather\n");
		else if (weight <= 60) printf("light\n");
		else if (weight <= 64) printf("light welter\n");
		else if (weight <= 69) printf("welter\n");
		else if (weight <= 75) printf("light middle\n");
		else if (weight <= 81) printf("middle\n");
		else if (weight <= 91) printf("light heavy\n");
		else printf("heavy\n");
	}
	
	return (0);
}

Measured memory_bytes: 0
package main
import (
    "bufio"
    "fmt"
    "os"
    "strconv"
    "strings"
)

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func main() {
    l := getStdinIntArr()
    a, b := l[0], l[1]
    fmt.Println(a*b)
}


func getStdin() string {
    return readLine()
}
func getStdinInt() int {
    str := getStdin()
    res, _ := strconv.Atoi(str)
    return res
}
func getStdinIntArr() []int {
    str := getStdin()
    list := strings.Split(str, " ")
    res := make([]int, len(list))
    for idx, v := range list {
        res[idx], _ = strconv.Atoi(v)
    }
    return res
}
func getStdinArr() []string {
    str := getStdin()
    list := strings.Split(str, " ")
    return list
}
func getStdinIntArr64() []int64 {
    str := getStdin()
    list := strings.Split(str, " ")
    res := make([]int64, len(list))
    for idx, v := range list {
        res[idx], _ = strconv.ParseInt(v, 10, 64)
    }
    return res
}
func readLine() string {
    buf := make([]byte, 0, 0)
    for {
        l, p, e := sc.ReadLine()
        if e != nil {
            panic(e)
        }
        buf = append(buf, l...)
        if !p {
            break
        }
    }
    return string(buf)
}

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



int main(int argc, char const *argv[])
{
    int a,b,c;
    cin >> a >> b >> c;
    if (a < b && b < c)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    
   return 0;


}



Measured memory_bytes: 3096
#include "bits/stdc++.h"
using namespace std;
typedef pair<long long, long long> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
long long gcd(long long A, long long B) {
  	if (B == 0) return A;
  	else return gcd(B, A % B);
}
long long lcm(long long A, long long B) {
  	return A / gcd(A, B) * B;
}
int main() {
	long long N; cin >> N;
  	vector<long long>A(N);
  	for (long long i = 0; i < N; i++) cin >> A.at(i);
  	long long ans = 1;
  	sort(A.begin(), A.end());
  	for (long long i = 0; i < N; i++) {
      	ans = lcm(ans, A.at(i));
    }
  	cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

type t struct {
	X int
	H int
}
type byX []t

func (a byX) Len() int           { return len(a) }
func (a byX) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a byX) Less(i, j int) bool { return a[i].X < a[j].X }

func main() {
	N := readInt()
	D := readInt()
	A := readInt()
	XH := make([]t, N)
	for i := 0; i < N; i++ {
		XH[i].X = readInt()
		XH[i].H = (readInt() + A - 1) / A
	}

	sort.Sort(byX(XH))
	result := 0
	cs := make([]int, N+1)
	for i := 0; i < N; i++ {
		x, h := XH[i].X, XH[i].H
		if i != 0 {
			cs[i] += cs[i-1]
		}
		h -= cs[i]
		if h <= 0 {
			continue
		}
		result += h
		cs[i] += h

		ok := i
		ng := N
		for ng-ok != 1 {
			m := ok + (ng-ok)/2
			if XH[m].X <= x+2*D {
				ok = m
			} else {
				ng = m
			}
		}
		cs[ng] -= h
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


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

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

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    ll q, h, s, d; cin>>q>>h>>s>>d;
    ll n; cin>>n;

    if(n == 1){
        cout << min({q*4, h*2, s}) << endl;
        return 0;
    }

    ll MIN=min({q*8, h*4, s*2, d});
    if(MIN != d){
        if(MIN == q*8) cout << 4*n*q << endl;
        else if(MIN == h*4) cout << 2*n*h << endl;
        else cout << s*n << endl;
    }
    else{
        ll MIN2=min({q*4, h*2, s});
        if(n%2 == 0) cout << n*d/2 << endl;
        else cout << (n-1)*d/2 + MIN2 << endl;
    }
}

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

int main(){
    int n;
    cin >> n;
    int g;
    int wa;
    vector <vector <int>> ans(2);
    if(n%2==0){
        g=n/2;
        wa=n+1;
        rep(i,n){
            rep(j,n){
                if(i>=j){
                    continue;
                }
                else if(j==n-i-1){
                    continue;
                }
                else{
            ans[0].push_back(i+1);
            ans[1].push_back(j+1);
                }
        }
        }
        
    }
    else{
        --n;
        rep(i,n){
            rep(j,n){
                if(i>=j){
                    continue;
                }
                else if(j==n-i-1){
                    continue;
                }
                
                else{
            ans[0].push_back(i+1);
            ans[1].push_back(j+1);
                }
        }
        }
        rep(i,n){
            ans[0].push_back(i+1);
            ans[1].push_back(n+1);
        }
    }

    ll l;
    l=ans[0].size();
    cout << l << endl;
    rep(i,l){
        cout << ans[0][i] << " " << ans[1][i] << endl;
    }
    

    return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    vector<vector<int>> v(3, vector<int>(3));
    REP(i, 3){
        REP(j, 3){
            cin >> v[i][j];
        }
    }

    vector<vector<bool>> b(3, vector<bool>(3, false));

    int n;
    cin >> n;
    REP(x, n){
        int a;
        cin >> a;
        REP(i, 3){
            REP(j, 3){
                if(v[i][j] == a){
                    b[i][j] = true;
                }
            }
        }
    }

    bool ans = false;
    REP(i, 3){
        if(b[i][0] && b[i][1] && b[i][2]){
            ans = true;
        }
        if(b[0][i] && b[1][i] && b[2][i]){
            ans = true;
        }
    }

    if(b[0][0] && b[1][1] && b[2][2]) ans = true;
    if(b[0][2] && b[1][1] && b[2][0]) ans = true;

    cout << (ans ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  vector<vector<int>> ver(h, vector<int>(w, -1)), hor(h, vector<int>(w, -1));
  rep(y,h) rep(x,w) { //水平方向
    if (s[y][x] == '#') continue;
    if (hor[y][x] != -1) continue;
    int i = x, cnt = 0;
    while (true) {
      if (i >= w || s[y][i] == '#') break; //壁にぶつかるまで進む
      cnt++; i++;
    }
    for (int j = x; j < i; ++j) {
      hor[y][j] = cnt;
    }
  }
  rep(y,h) rep(x,w) { //垂直方向
    if (s[y][x] == '#') continue;
    if (ver[y][x] != -1) continue;
    int i = y, cnt = 0;
    while (true) {
      if (i >= h || s[i][x] == '#') break; //壁にぶつかるまで進む
      cnt++; i++;
    }
    for (int j = y; j < i; ++j) {
      ver[j][x] = cnt;
    }
  }
  // rep(y,h) {
  //   rep(x,w) {
  //     cout << hor[y][x] << " ";
  //   }
  //   cout << endl;
  // }
  int ans = 0;
  rep(y,h) rep(x,w) {
    chmax(ans, ver[y][x]+hor[y][x]-1);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 35968