akhauriyash/Code-Regression huggingface dataset:
/*
#include <stdio.h>
#define N -1;

typedef struct{
  int id;
  int left;
  int right;
}t;

typedef struct{
  int id;
  int pid;
  int sb;
  int d;
  int h;
  int cc;
}T;

int main()
{
  int n,i,a,*p;
  T Tree[25];
  t tree[25];
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    Tree[i].id = -1;
    Tree[i].pid = -1;
    Tree[i].sb = -1;
    Tree[i].d = -1;
    Tree[i].h = -1;
    Tree[i].cc = -1;
  }

  for(i=0;i<n;i++){
    scanf("%d",&a);
    tree[a].id = a;
    scanf("%d%d",&tree[a].left,&tree[a].right);
  }

  for(i=0;i<n;i++){
    if(tree[i].left!=-1 && tree[i].right==-1){
      Tree[tree[i].left].pid = tree[i].id;
      Tree[i].cc = 1;
    }
    else if(tree[i].right!=-1 && tree[i].left==-1){
      Tree[tree[i].right].pid = tree[i].id;
      Tree[i].cc = 1;
    }
    else if(tree[i].left!=-1 && tree[i].right!=-1){
      Tree[tree[i].left].pid = tree[i].id;
      Tree[tree[i].right].pid = tree[i].id;
      Tree[i].cc = 2;
      Tree[tree[i].left].sb = tree[i].right;
      Tree[tree[i].right].sb = tree[i].left;
    }
    else Tree[i].cc = 0;
  }

  for(i=0;i<n;i++){
    if(Tree[i].pid==-1){
      Tree[i].d = 0;
      p = &Tree[i];
    }
  }
*/
  
#include<stdio.h>
#define NIL -1

typedef struct node{
  int pa;
  int l;
  int r;
  int d;
  int h;
}Node;

Node T[30];


void setDepth(int u,int d){
  if(u == NIL){
    return;
  }

  T[u].d = d;
  setDepth(T[u].l,d+1);
  setDepth(T[u].r,d+1);
}

int setHeight(int u){
  int h1 = 0;
  int h2 = 0;

  if(T[u].l != NIL){
    h1 = setHeight(T[u].l)+1;
  }
  if(T[u].r != NIL){
    h2 = setHeight(T[u].r)+1;
  }
  return T[u].h = (h1 > h2 ? h1 : h2);
}

int getSibling(int u){
  if(T[u].pa == NIL)return NIL;
  if(T[T[u].pa].l != u && T[T[u].pa].l != NIL)return T[T[u].pa].l;
  if(T[T[u].pa].r != u && T[T[u].pa].r != NIL)return T[T[u].pa].r;
  return NIL;
}

int main(){
  int n,i,j,v,l,r,root,deg;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].pa = NIL;
  }  

  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].l = l;
    T[v].r = r;
    if(l != NIL)T[l].pa = v;
    if(r != NIL)T[r].pa = v;
  }

  for(i=0;i<n;i++){
    if(T[i].pa == NIL ){
      root = i;
    }
  }
  setDepth(root,0);
  setHeight(root);

  for(i=0;i<n;i++){
    deg = 0;
    printf("node %d: parent = %d, sibling = %d, ",i,T[i].pa,getSibling(i));
    if(T[i].l != NIL)deg++;
    if(T[i].r != NIL)deg++;
    printf("degree = %d, depth = %d, height = %d, ",deg,T[i].d,T[i].h);
    if(T[i].pa == NIL)printf("root\n");
    else if(T[i].l == NIL && T[i].r == NIL)printf("leaf\n");
    else printf("internal node\n");
  }
  return 0;
}

    




Measured memory_bytes: 2128
N=int(input())
a=[*map(int,input().split())]
d=[[0]*21 for _ in[0]*~-N]
d[0][a[0]]=1
for i in range(1,N-1):
 for j in range(21):
  d[i][j]=(21>j+a[i]and d[i-1][j+a[i]])+(0<=j-a[i]and d[i-1][j-a[i]])
print(d[N-2][a[N-1]])


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

#define int long long

signed main(){
  int l,r;
  cin >> l >> r;
  
  int mn = 2019LL;
  int n = min(l+2019LL, r);
  
  for(int  i = l;i<n;i++){
    for(int j = i+1;j<=n;j++){
        mn = min(mn, (i*j)%2019);
    }
  }
  cout << mn << endl;
  return 0;
}
  

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

int main(){
    string s;
    cin>>s;
    int m[s.length()];
    ll white=0;
    ll ans=0;
    int flag=0;
    for (ll i = (ll)s.length()-1; i >=0; --i) {
        if(s[i]=='B')m[i]=1;
        else m[i]=0;
    }
    for (ll i = (ll)s.length()-1; i >=0; --i) {
        if(!m[i])flag=1;
        if(flag) {
            if (!m[i])white++;
            if (m[i])ans += white;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1412
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int m[100];

int main()
{
	int N, X, ans = 0;

	cin >> N >> X;
	rep(i, N) {
		cin >> m[i];
		X -= m[i];
	}
	ans = N;

	sort(m, m + N);

	ans += X / m[0];

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto rck = readln.split.to!(int[]);
    auto R = rck[0];
    auto C = rck[1];
    auto K = rck[2];
    auto MAP = new long[][](R, C);
    foreach (_; 0..K) {
        auto rcv = readln.split.to!(int[]);
        auto r = rcv[0]-1;
        auto c = rcv[1]-1;
        long v = rcv[2];
        MAP[r][c] = v;
    }

    auto DP = new long[][][](R+1, C+1, 4);
    foreach (r; 0..R) {
        foreach (c; 0..C) {
            foreach (k; 0..4) {
                if (k < 3) {
                    DP[r][c+1][k+1] = max(DP[r][c+1][k+1], DP[r][c][k] + MAP[r][c]);
                    DP[r+1][c][0] = max(DP[r+1][c][0], DP[r][c][k] + MAP[r][c]);
                }
                DP[r][c+1][k] = max(DP[r][c+1][k],  DP[r][c][k]);
                DP[r+1][c][0] = max(DP[r+1][c][0], DP[r][c][k]);
            }
        }
    }
    long r;
    foreach (k; 0..4) r = max(r, DP[R][C-1][k]);
    writeln(r);
}

Measured memory_bytes: 657044
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
using ll = long long;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1001001001;
constexpr long long INFL = (1LL<<60);
constexpr double eps = (1e-9);

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

  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  sort(a.rbegin(), a.rend());

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

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4000
n=int(input())
a=list(map(int,input().split()))
ans=0
count_plus=0
sum_plus=0
for i in range(n):
    if i%2 == 0:
        if a[i]+sum_plus > 0:
            sum_plus += a[i]
        else:
            count_plus += 1-a[i]-sum_plus
            sum_plus = 1
    else:
        if a[i]+sum_plus < 0:
            sum_plus += a[i]
        else:
            count_plus += 1+a[i]+sum_plus
            sum_plus=-1

count_minus=0
sum_minus=0
for i in range(n):
    if i%2 != 0:
        if a[i]+sum_minus > 0:
            sum_minus += a[i]
        else:
            count_minus += 1-a[i]-sum_minus
            sum_minus = 1
    else:
        if a[i]+sum_minus < 0:
            sum_minus += a[i]
        else:
            count_minus += 1+a[i]+sum_minus
            sum_minus=-1
            
print(min(count_plus,count_minus))

Measured memory_bytes: 85584
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
#include <atcoder/all>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}

vector<ll> yakusu(ll n){
  vector<ll> ret;
  for(ll p = 1; p*p <= n; p++){
    if(n%p == 0){
      ret.push_back(p);
      if(p*p != n){
        ret.push_back(n/p);
      }
    }
  }
  sort(all(ret));
  return ret;
}

int main(void){
  fast_io
  cout<<fixed<<setprecision(15);

  int n,m;
  cin>>n>>m;
  atcoder::scc_graph G(n);
  rep(i,m){
    int a,b;cin>>a>>b;
    G.add_edge(a,b);
  }
  auto result = G.scc();
  cout<<result.size()<<endl;
  rep(i,result.size()){
    int num = result[i].size();
    auto row = result[i];
    cout<<num<<" ";
    rep(j,num){
      cout<<row[j]<<" ";
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 40596
//#if 1
//#include"pch.h"
//#define _CRT_SECURE_NO_WARNINGS
//#endif
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<iostream>
using namespace std;
int main() {
	int N, M, X;
	int A[100];
	int l = 0, r = 0;
	cin >> N >> M >> X;
	for (int i = 0; i < M; i++) {
		cin >> A[i];
		if (A[i]< X)l++;
		else if (A[i]> X)r++;
	}
	cout << min(l, r) << endl;


	return(0);
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations,product#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def binr(x): return bin(x)[2:]
def bitcount(x): #xは64bit整数
    x= x - ((x >> 1) & 0x5555555555555555)
    x= (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x= (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f 
    x+= (x >> 8); x+= (x >> 16); x+= (x >> 32) 
    return x & 0x7f

def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列


    s=input()
    print(num2alp(alp2num(s)+1))



if __name__ == "__main__":
    main()

Measured memory_bytes: 76540
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

int main(int argc, char *argv[]) {
  int hand[5], card[13];
  int yaku[5];
  while(scanf("%d,%d,%d,%d,%d",
              hand+0, hand+1, hand+2, hand+3, hand+4) == 5) {

    memset(card, 0, sizeof(int) * 13);
    memset(yaku, 0, sizeof(int) * 5);
    for (int i = 0; i < 5; i++)
      card[hand[i]-1]++;
    int j = 0;
    for (int i = 0; i < 13; i++)
      if (card[i] != 0)
        yaku[j++] = card[i];
    sort(yaku+0, yaku+j);

    j--;
    if (yaku[j] == 4) {
      cout << "four card" << endl;
    } else if (yaku[j] == 3 && yaku[j-1] == 2) {
      cout << "full house" << endl;
    } else if (yaku[j] == 3) {
      cout << "three card" << endl;
    } else if (yaku[j] == 2 && yaku[j-1] == 2) {
      cout << "two pair" << endl;
    } else if (yaku[j] == 2) {
      cout << "one pair" << endl;
    } else {
      sort(hand+0, hand+5);
      if ((hand[0]+1 == hand[1] &&
           hand[1]+1 == hand[2] &&
           hand[2]+1 == hand[3] &&
           hand[3]+1 == hand[4]) ||
          (hand[0] == 1 &&
           hand[1] == 10 &&
           hand[2] == 11 &&
           hand[3] == 12 &&
           hand[4] == 13))
        cout << "straight" << endl;
      else
        cout << "null" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end() 
#define asn ans
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;

int main() {
	int n, m, x; CI n >> m >> x;
	vector<int> a(m); CI a;
	int memo[101] = {};
	int cleft = 0 , cright = 0;
	REP(i, m) {
		memo[a[i]] = 1;
	}
	REP(i, x) {
		if (memo[i])cleft++;
	}
	FOR(i, x + 1, n) {
		if (memo[i])cright++;
	}
	CO min(cleft, cright) EN;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Pair = Tuple!(int, "a", int, "b");

void main() {
    int N, M, L;
    scan(N, M, L);

    auto dist = new long[][](N, N);
    foreach (i ; 0 .. N) {
        foreach (j ; 0 .. N) {
            if (i != j) dist[i][j] = inf6;
        }
    }

    foreach (i ; 0 .. M) {
        int ai, bi, ci;
        scan(ai, bi, ci);
        ai--, bi--;
        dist[ai][bi] = dist[bi][ai] = ci;
    }

    foreach (k ; 0 .. N) {
        foreach (i ; 0 .. N) {
            foreach (j ; 0 .. N) {
                chmin(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    auto d = new int[][](N, N);
    foreach (i ; 0 .. N) {
        foreach (j ; 0 .. N) {
            if (i == j) {
                d[i][j] = 0;
                continue;
            }
            d[i][j] = dist[i][j] <= L ? 1 : inf;
        }
    }

    foreach (k ; 0 .. N) {
        foreach (i ; 0 .. N) {
            foreach (j ; 0 .. N) {
                chmin(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int Q;
    scan(Q);

    while (Q--) {
        int si, ti;
        scan(si, ti);
        si--, ti--;
        writeln(d[si][ti] < inf ? d[si][ti] - 1 : -1);
    }
}






void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 7036
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use text_io::*;

fn main() {
    let n: usize = read!();
    let mut vec = Vec::with_capacity(n);

    for _ in 0..n {
        let m: u128 = read!();
        if m == 0 {
            println!("0");
            std::process::exit(0);
        } else {
            vec.push(m);
        }
    }

    let mut acc = 1;
    for v in vec {
        if acc * v > 1000000000000000000 {
            println!("-1");
            std::process::exit(0);
        } else {
            acc *= v;
        }
    }

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


Measured memory_bytes: 3732
import sys

start = 0
for l in sys.stdin:
    if start == 0:
        start += 1
    else:
        list1 = list(map(int, l.split()))
        break
count = 0
for i in list1:
    while True:
        if i%2 == 0:
            count += 1
            i = i/2
        else:
            break
print(count)

Measured memory_bytes: 4212
n, m = map(int, input().split())
if n >= m:
    print(0)
else:
    x = [int(i) for i in input().split()]
    x.sort()
    d = x[- 1] - x[0]
    y = []
    for i in range(m - 1):
        y.append(x[i + 1] - x[i])
    y.sort(reverse=True)
    for i in range(n - 1):
        d -= y[i]
    print(d)

Measured memory_bytes: 19832
n=int(input())
b=list(map(int,input().split()))
ope=[[] for i in range(n)]
Q=int(input())
for i in range(Q):
    l,r=map(int,input().split())
    ope[r-1].append(l-1)

res=b.count(0)

Data=[(-1)**((b[i]==1)+1) for i in range(n)]
for i in range(1,n):
    Data[i]+=Data[i-1]
Data=[0]+Data

for i in range(n):
    ope[i].sort(reverse=True)

# N: 処理する区間の長さ
N=n+1
N0 = 2**(N-1).bit_length()
data = [None]*(2*N0)
INF = (-2**31, -2**31)
# 区間[l, r+1)の値をvに書き換える
# vは(t, value)という値にする (新しい値ほどtは大きくなる)
def update(l, r, v):
    L = l + N0; R = r + N0
    while L < R:
        if R & 1:
            R -= 1
            if data[R-1]:
                data[R-1] = max(v,data[R-1])
            else:
                data[R-1]=v

        if L & 1:
            if data[L-1]:
                data[L-1] = max(v,data[L-1])
            else:
                data[L-1]=v
            L += 1
        L >>= 1; R >>= 1
# a_iの現在の値を取得
def _query(k):
    k += N0-1
    s = INF
    while k >= 0:
        if data[k]:
            s = max(s, data[k])
        k = (k - 1) // 2
    return s
# これを呼び出す
def query(k):
    return _query(k)[1]

for i in range(n+1):
    update(i,i+1,(-Data[i],-Data[i]))
if ope[0]:
    update(1,2,(0,0))

for i in range(1,n):
    val=query(i)
    update(i+1,i+2,(val+Data[i]-Data[i+1],val+Data[i]-Data[i+1]))
    for l in ope[i]:
        val=query(l)
        update(l+1,i+2,(val,val))



print(n-(res+query(n)+Data[n]))

Measured memory_bytes: 135396
N,M = map(int,input().split())
swis = [list(map(int,input().split()))[1:] for _ in range(M)]
need = list(map(int,input().split()))

ans = 0
for i in range(1<<N):#すいっちのくみあわせ
  for j in range(M):#でんきゅうをみてく
    rel=0
    for k in swis[j]:
      if i & (1<<(k-1)) != 0:
        rel+=1
        
    if rel%2 != need[j]:
        break
  else:
     ans+=1
      
print(ans)
        


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
int main() {
  int a,b;
  cin>>a>>b;
  int count=0;
  int kazu=1;
  while(kazu<b){
    count++;
    kazu+=(a-1);
  }
  cout<<count;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  ll a;
  cin>>a;
  cout<<a+a*a+a*a*a<<endl;
  return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int const mod = 1e9+7;

int h,w;
bool a[1001][1001];
int dp[1001][1001];

int solve(int x, int y){
    if (y == w-1 && x == h-1) return 1;
    else if (!a[x][y]) return dp[x][y] = 0;
    else if (dp[x][y] != -1) return dp[x][y];
    int aux = 0,aux2 = 0;
    if (x < h-1) aux = solve(x+1,y);
    if (y < w-1) aux2 = solve(x,y+1);
    return dp[x][y] = (aux+aux2)%mod;
}

int main(int argc, char const *argv[]) {
    cin >> h >> w;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            char c; cin >> c;
            if (c == '.') a[i][j] = 1;
            else a[i][j] = 0;
            dp[i][j] = -1;
        }
    }
    cout << solve(0,0) << endl;
    return 0;
}


Measured memory_bytes: 5248
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

class Main {

	static int n;
	static double[] x1, y1, x2, y2;
	static double sx, sy, gx, gy;
	static ArrayList<Integer>[] g;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int q = sc.nextInt();
		while (q-- > 0) {
			long x0, y0, x1, y1, x2, y2, x3, y3;
			x0 = sc.nextLong();
			y0 = sc.nextLong();
			x1 = sc.nextLong();
			y1 = sc.nextLong();
			x2 = sc.nextLong();
			y2 = sc.nextLong();
			x3 = sc.nextLong();
			y3 = sc.nextLong();
			Point p0 = new Point(x0, y0);
			Point p1 = new Point(x1, y1);
			Point p2 = new Point(x2, y2);
			Point p3 = new Point(x3, y3);
			if (linesIntersect(p0, p1, p2, p3)) {
				System.out.println(1);
			} else {
				System.out.println(0);
			}
		}
		// ArrayList<Point> ps = new ArrayList<>();
		// n = sc.nextInt();
		// x1 = new double[n];
		// y1 = new double[n];
		// x2 = new double[n];
		// y2 = new double[n];
		// for (int i = 0; i < n; ++i) {
		// x1[i] = sc.nextDouble();
		// y1[i] = sc.nextDouble();
		// x2[i] = sc.nextDouble();
		// y2[i] = sc.nextDouble();
		// ps.add(new Point(x1[i], y1[i]));
		// ps.add(new Point(x2[i], y2[i]));
		// }
		//
		// for (int i = 0; i < n; ++i) {
		// for (int j = i + 1; j < n; ++j) {
		//
		// }
		// }

	}

	static class Point {
		long x, y;
		int id;

		public Point(long x, long y) {
			this.x = x;
			this.y = y;
		}
	}

	static boolean linesIntersect(Point s1, Point d1, Point s2, Point d2) {
		long prd1 = crossProduct(s1, d1, s1, d2) * crossProduct(s1, d1, s1, s2);
		long prd2 = crossProduct(s2, d2, s2, s1) * crossProduct(s2, d2, s2, d1);
		if (prd1 == 0 && prd2 == 0) {
			if (((s2.x - s1.x) * (s2.x - d1.x) <= 0 && (s2.y - s1.y) * (s2.y - d1.y) <= 0)
					|| ((d2.x - s1.x) * (d2.x - d1.x) <= 0 && (d2.y - s1.y) * (d2.y - d1.y) <= 0)
					|| ((s1.x - s2.x) * (s1.x - d2.x) <= 0 && (s1.y - s2.y) * (s1.y - d2.y) <= 0)
					|| ((d1.x - s2.x) * (d1.x - d2.x) <= 0 && (d1.y - s2.y) * (d1.y - d2.y) <= 0)) {
				return true;
			} else
				return false;
		} else
			return ((crossProduct(s1, d1, s1, d2) * crossProduct(s1, d1, s1, s2)) <= 0)
					&& ((crossProduct(s2, d2, s2, s1) * crossProduct(s2, d2, s2, d1) <= 0));
	}

	static long crossProduct(Point s1, Point d1, Point s2, Point d2) {
		return (d1.x - s1.x) * (d2.y - s2.y) - (d1.y - s1.y) * (d2.x - s2.x);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 40056
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define print_array(ary, size) cout << ary[0]; rep1(i, 1, size - 1) cout << ' ' << ary[i]; cout << endl;
typedef long long ll;
typedef unsigned long long ull;


#define NIL (-1)

typedef struct {
	int parent;
	int left;
	int right;
	int depth;
	int height;
} Node;

Node node[25];

void setDepth(int id, int dep)
{
	node[id].depth = dep;
	if (node[id].left != NIL) setDepth(node[id].left, dep + 1);
	if (node[id].right != NIL) setDepth(node[id].right, dep + 1);
}

int setHeight(int id)
{
	int h1 = 0, h2 = 0;

	if (node[id].left != NIL) h1 = setHeight(node[id].left) + 1;
	if (node[id].right != NIL) h2 = setHeight(node[id].right) + 1;

	node[id].height = max(h1, h2);
	return max(h1, h2);
}

int getSibling(int id)
{
	int parent = node[id].parent;
	int sibling;

	if (parent == NIL) return -1;

	if (node[parent].left == id) sibling = node[parent].right;
	else sibling = node[parent].left;

	return sibling;
}

int getDegree(int id)
{
	int degree = 0;

	if (node[id].left != NIL) degree++;
	if (node[id].right != NIL) degree++;

	return degree;
}

void printType(int id)
{
	int parent = node[id].parent;
	int left = node[id].left;
	int right = node[id].right;
	string type;

	if (parent == NIL) type = "root";
	else if (left == NIL && right == NIL) type = "leaf";
	else type = "internal node";

	cout << type << endl;
}

int main()
{
	int n, id, left, right, root = 0;
	int parent, sibling, degree, depth, height;

	cin >> n;

	rep(i, n) {
		node[i].parent = NIL;
		node[i].left = NIL;
		node[i].right = NIL;
		node[i].depth = NIL;
	}

	rep(i, n) {
		cin >> id >> left >> right;
		node[id].left = left;
		node[id].right = right;
		node[left].parent = id;
		node[right].parent = id;
	}

	rep(i, n) if (node[i].parent == NIL) root = i;
	setDepth(root, 0);
	setHeight(root);

	rep(i, n) {
		parent = node[i].parent;
		sibling = getSibling(i);
		degree = getDegree(i);
		depth = node[i].depth;
		height = node[i].height;

		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", i, parent, sibling, degree, depth, height);
		printType(i);
	}

	return 0;
}


Measured memory_bytes: 3252
H,W = map(int,input().split())
S = [['.']*(W+2),]
for _ in range(H):
  S.append(['.'] + list(input()) + ['.'])
S.append(['.']*(W+2))

for h in range(1,H+1):
  for w in range(1,W+1):
    if S[h][w] == '.':
      num = 0
      for hx,wx in [(0,-1), (0,1), (-1,0), (1,0),(1,-1), (1,1), (-1,1), (-1,-1)]:
        if S[h+hx][w+wx] == '#':
          num += 1
        S[h][w] = str(num)

for h in range(1,H+1):
  print(''.join(S[h][1:-1]))

Measured memory_bytes: 40304
#include<iostream>

int main(){
    int L, R;
    std::cin >> L >> R;
    
    int begin = L % 2019;
    int end = R % 2019;
    if(R > L + 2019){
        end = begin + 2019;
    }else if(R % 2019 <= begin){
        end = (R % 2019) + 2019;
    }else{
        end = R % 2019;
    }
    
    int min = 2019;
    for(int i=begin;i<=end;i++){
        for(int j=i+1;j<=end;j++){
            int tmp = (i * j) % 2019;
            if(tmp < min){
                min = tmp;
            }
        }
    }
    
    std::cout << min << std::endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	int m,n,i;
	cin>>m>>n;
	i=(m-1)*(n-1);
	cout<<i<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
vector<ll> vx,vy;
pair<ll,ll> p[50];
ll N,K,ans{numeric_limits<ll>::max()};
ll llabs(ll a){return a<0?-a:a;}
int main(){
    cin>>N>>K;
    for(int i{};i<N;++i){
        ll x,y;cin>>x>>y;
        p[i].first=x,p[i].second=y;
        vx.push_back(x),vy.push_back(y);
    }
    sort(vx.begin(),vx.end());
    sort(vy.begin(),vy.end());
    vx.erase(unique(vx.begin(),vx.end()),vx.end());
    vy.erase(unique(vy.begin(),vy.end()),vy.end());
    for(int i{};i<vx.size();++i)
        for(int j{i};j<vx.size();++j)
            for(int k{};k<vy.size();++k)
                for(int l{k};l<vy.size();++l){
                    int cnt{};
                    for(int n{};n<N;++n){
                        ll x{p[n].first},y{p[n].second};
                        if(x>=vx[i]&&x<=vx[j]&&y>=vy[k]&&y<=vy[l])
                            ++cnt;
                    }
                    if(cnt>=K)ans=min(ans,llabs(vx[j]-vx[i])*llabs(vy[l]-vy[k]));
                }
    cout<<ans<<endl;
}
                        


Measured memory_bytes: 256
n, q = map(int, input().split())
s = input()
flg = 0

ac_list = [0]

for i in range(0, len(s)-1):
    if s[i] == 'A' and s[i+1] == 'C':
        ac_list.append(ac_list[i]+1)
    else:
        ac_list.append(ac_list[i])

#print(ac_list)

for i in range(q):
    l, r = map(int, input().split())
    print(ac_list[r-1] - ac_list[l-1])


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n,0);
  rep(i,0,n) cin >> a[i];
  sort(a.begin(), a.end(), greater<int>());
  vector<int> b;
  b.push_back(a[0]);
  rep(i,1,n) {
    rep(j,0,2) {
      b.push_back(a[i]);
    }
    if (b.size() >= n) break;
  }
  ll ans = 0;
  rep(i,0,n-1) {
    ans += b[i];
  }
  printf("%lld\n", ans);
  return 0;
}


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

int max(int x, int y) {
  return (x > y) ? x : y;
}

int main() {
  int a, b, c;
  int r, l;

  r = l = 0;
  while (scanf("%d,%d,%d", &a, &b, &c)==3) {
    if (a*a+b*b==c*c) r++;
    if (a==b) l++;
  }
  printf("%d\n", r);
  printf("%d\n", l);

  return 0;
}

Measured memory_bytes: 1024
import itertools

def resolve():
    n, m = map(int, input().split())
    S = [[0] * n for i in range(n)]

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

    ans = 0
    for p in itertools.permutations(range(n)):
        if p[0] != 0:
            break
        tmp = 1
        for i in range(n-1):
            tmp *= S[p[i]][p[i + 1]]
        ans += tmp

    print(ans)

if __name__ == '__main__':
    resolve()

Measured memory_bytes: 3064
/*
  AtCoder Beginner Contest 084
  B - Postal Code
*/

#include<iostream>
using namespace std;

int A, B;
string S;

int main() {
  scanf("%d %d", &A, &B);
  cin >> S;

  bool check = true;
  for (int i = 0; i < A; ++i) {
    if (!('0' <= S[i] && S[i] <= '9')) check = false;
  }

  if (S[A] != '-') check = false;

  for (int i = A + 1; i < A + B + 1; ++i) {
    if (!('0' <= S[i] && S[i] <= '9')) check = false;
  }

  if (check) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 256
using System;
class Program
{
    static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = new int[n];
        string[] input = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++)
        {
            a[i] = int.Parse(input[i]);
        }

        int[] b = new int[n];
        input = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++)
        {
            b[i] = int.Parse(input[i]);
        }

        int[] c = new int[n];
        input = Console.ReadLine().Split(' ');
        for (int i = 0; i < n - 1; i++)
        {
            c[i] = int.Parse(input[i]);
        }

        int sum = 0;
        int pre = n;
        for (int i = 0; i < n; i++)
        {
            sum += b[a[i]-1];
            if(pre + 1 == a[i]-1)
            {
                sum += c[pre];
            }
            pre = a[i]-1;
        }
        Console.WriteLine(sum);
    }
}

Measured memory_bytes: 11092
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
LL MOD = 1000000007LL;
int a[50];
int main() {
	int N;
	cin >> N;
	int M_idx = 0, m_idx = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		if (a[m_idx] > a[i]) m_idx = i;
		if (a[M_idx] < a[i]) M_idx = i;
	}
	cout << 2 * N - 2 << endl;
	if (abs(a[M_idx]) >= abs(a[m_idx])) {
		for (int i = 0; i < N; i++) {
			if (i == M_idx) continue;
			cout << (M_idx + 1) << " " << (i + 1) << endl;
		}
		for (int i = 1; i < N; i++) {
			cout << i << " " << (i + 1) << endl;
		}
	}
	else {
		for (int i = 0; i < N; i++) {
			if (i == m_idx) continue;
			cout << (m_idx + 1) << " " << (i + 1) << endl;
		}
		for (int i = N - 1; i > 0; i--) {
			cout << (i + 1) << " " << i << endl;
		}
	}
}

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

#define ll long long
#define maxd 100000000000001

int main() {
    int n, m;
    cin >> n >> m;
    int l, r;
    ll c;
    vector<pair<int, ll>> adj[n + 1];
    set<pair<ll, int>> s;
    for (int i = 0; i < m; i++) {
        cin >> l >> r >> c;
        adj[l].emplace_back(r, c);
    }
    ll d[n + 1], temp;
    for (int i = 2; i <= n; i++) {
        d[i] = maxd;
        s.insert({maxd, i});
    }
    d[1] = 0;
    s.insert({0, 1});
    for (int i = 1; i < n; i++) {
        temp = s.begin()->first;
        for (auto p:adj[i]) {
            r = p.first;
            c = p.second;
            if (temp + c < d[r]) {
                s.erase({d[r], r});
                d[r] = temp + c;
                s.insert({d[r], r});
            }
        }
        s.erase({d[i], i});
    }
    if (d[n] == maxd) cout << "-1\n";
    else cout << d[n] << "\n";
    return 0;
}

Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL << 60;
constexpr auto mod = 1000000007;
constexpr auto MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n, m, x;
    cin >> n >> m >> x;
    VI f(n + 1, 0), b(n + 1, 0);
    int a;
    FOR(i, 0, m) {
        cin >> a;
        f[a]++;
        b[a]++;
    }

    FOR(i, 0, n) {
        b[i + 1] += b[i];
        f[n - 1 - i] += f[n - i];
    }
    cout << min(f[0] - f[x], b[n] - b[x]) << "\n";
}

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



void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


int gcd(int a, int b){
  int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

long int modpow(long int a,long int n,long int mod){
  long int ans=1;
  while(n>0){
    if(n & 1){
      ans=ans*a%mod;
    }
    a=a*a%mod;
    n/=2;
  }
  return ans;
}

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

int main(void){
  int r,g,b,n;
  scanf("%d%d%d%d",&r,&g,&b,&n);
  int ans=0;
  for(int i=0;r*i<=n;i++){
    for(int j=0;g*j<=n-r*i;j++){
      if((n-(r*i+g*j))%b==0){
        ans++;
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1696
#include <stdio.h>

int main(){
  long long int N;
  scanf("%lld",&N);
  long long int P=2LL;
  long long int min=N-1LL;
  long long int M;
  
  while(P*P<=N){
    if(N%P==0LL){
      M=(P-1LL)+(N/P-1LL);
      if(M<min) min=M;
    }
    P++;
  }
  printf("%lld\n",min);
  return 0;
}

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

int main(){
    int k, a, b;
    bool flag=false;
    cin >> k >> a >> b;
    int tmp=k;
    while(tmp<=b){
        if(tmp>=a){
            flag=true;
            break;
        }
        tmp+=k;
    }
    if(flag){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }
}

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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// ordered_set X;
// *X.find_by_order(i) = ith largest element (counting from zero)
// X.order_of_key(k) = number of items in X < k (strict lt)

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

    vll A(N);
    for (int i=0;i<N;i++) cin >> A[i];

    vvi adj(N);

    for (int i=0;i<N-1;i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    if (N == 2) {
        if (A[0] == A[1]) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
        return 0;
    }

    int rt = 0;
    while (adj[rt].size() == 1) rt++;

    vi parent(N, -1);
    vvi children(N);
    vi order;
    queue<int> bfs;

    bfs.push(rt);
    parent[rt] = rt;

    while (!bfs.empty()) {
        int cur = bfs.front();
        bfs.pop();
        
        order.push_back(cur);

        for (int nbr : adj[cur]) {
            if (parent[nbr] == -1) {
                parent[nbr] = cur;
                children[cur].push_back(nbr);
                bfs.push(nbr);
            }
        }
    }

    reverse(order.begin(), order.end());

    for (int v : order) {
        // cout << v << endl;

        if (children[v].size() == 0) continue;

        ll pstones = A[v];
        ll cstones = 0;
        
        for (int c : children[v]) cstones += A[c];

        ll b = cstones - pstones;
        ll a = pstones - b;

        // cout << pstones << " " << cstones << " " << a << " " << b << endl;

        if (a < 0 || b < 0) {
            cout << "NO" << endl;
            return 0;
        }
        
        ll mc = 0;
        for (int c : children[v]) mc = max(mc, A[c]);

        ll sc = cstones - mc;

        ll pairs = 0;
        if (mc > sc) pairs = sc;
        else pairs = cstones/2;

        if (pairs < b) {
            cout << "NO" << endl;
            return 0;
        }

        A[v] = a;
    }

    if (A[rt] == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;

}


Measured memory_bytes: 12792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const unsigned int M = 1000000007;
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int a[3];
    while(cin>>a[0]>>a[1]>>a[2]){
        sort(a,a+3);
        if(a[0]+a[1]==a[2])cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a=0,b,c,d;
  cin >>a>>b;
  c=a+a+b+b;
  if(a%3==0||b%3==0||c%3==0) cout <<"Possible\n";
  else cout <<"Impossible\n";
  return (0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)x.size())
#define FOR(i,a,b) for (int i=a;i<=b;++i)
#define FORD(i,a,b) for (int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
typedef pair<int,int> pa;
typedef vector<int> vec;
void getint(int &v){
    char ch,fu=0;
    for(ch='*'; (ch<'0'||ch>'9')&&ch!='-'; ch=getchar());
    if(ch=='-') fu=1, ch=getchar();
    for(v=0; ch>='0'&&ch<='9'; ch=getchar()) v=v*10+ch-'0';
    if(fu) v=-v;
}
LL ans;
bool ok[500010],u[500010];
int n,he,ta,q[20000010],a[500010],b[500010],las[500010],nxt[500010];
bool ck(int x){
	if (ok[x]) return 0;
	if (u[x]) return 0;
	return (b[x]>b[las[x]]+b[nxt[x]]);
}
int main(){
	scanf("%d",&n);
	FOR(i,1,n) scanf("%d",&a[i]);
	FOR(i,1,n) scanf("%d",&b[i]);
	FOR(i,1,n){
		if (a[i]==b[i]) ok[i]=1;
		if (b[i]<a[i]) return puts("-1"),0;
	}
	FOR(i,1,n) las[i]=i-1;
	las[1]=n;
	FOR(i,1,n) nxt[i]=i+1;
	nxt[n]=1;
	FOR(i,1,n) if (ck(i)) q[++ta]=i,u[i]=1;
	while (he!=ta){
		int x=q[++he];
		u[x]=0;
		int re=b[x]-a[x];
		if (re<b[las[x]]+b[nxt[x]]) return puts("-1"),0;
		b[x]-=re/(b[las[x]]+b[nxt[x]])*(b[las[x]]+b[nxt[x]]);
		ans+=re/(b[las[x]]+b[nxt[x]]);
		if (b[x]==a[x]) ok[x]=1;
		if (ck(las[x])) q[++ta]=las[x],u[q[ta]]=1;
		if (ck(nxt[x])) q[++ta]=nxt[x],u[q[ta]]=1;
	}
	FOR(i,1,n) if (a[i]!=b[i]) return puts("-1"),0;
	cout<<ans<<endl;
	return 0;
}

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

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

long long MOD = 1000000000 + 7;

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  if(abs(x-a) <= abs(x-b)){
    cout << "A" << endl;
  } else { 
    cout << "B" << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back

using namespace std;

typedef pair< int, int > P;
typedef pair< int, P > iP;
typedef long long LL;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const int MOD = (10^9 + 7);

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

int a[1000005];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int s;
    cin >> s;
    int i = 2;
    a[0] = -1;
    a[1] = s;
    while(1) {
        if(a[i - 1]% 2) {
            a[i] = a[i - 1] * 3 + 1;
        } else {
            a[i] = a[i - 1] / 2;
        }
        bool flag = false;
        for(int j = i - 1; j >= 1; --j) {
            if(a[i] == a[j]) {
                cout << i << endl;
                flag = true;
                break;
            }
        }
        if(flag) break;
        ++i;
    }


    

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
int main(){
  string s,t;
  cin >> s >> t;
  int a=s.size();
  int b=t.size();
  if(b!=a+1){
    cout << "No" << endl;
    return 0;
  }
  if(t.substr(0,a)!=s){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
}

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

int main(){
  ll n, W;
  cin >> n >> W;
  ll w[n], v[n], w1;
  rep(i,n) {
    cin >> w[i] >> v[i];
    if(i == 0) w1 = w[i];
    w[i] -= w1;
  }
  vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(n+1, vector<ll>(2*n+1,0)));
  rep(i, n){
   rep(j, n){
     rep(k, 2*n+1){
      if(k-w[i] >= 0) dp[i+1][j+1][k] = max(dp[i+1][j+1][k], dp[i][j][k-w[i]]+v[i]);
      dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k]);
     }
    }
  }
  ll ans = 0;
  rep(i, n+1) {
    ll a = W - i*w1;
    if(a > 2*n) ans = max(ans, dp[n][i][2*n]);
    else if(a >= 0) ans = max(ans, dp[n][i][a]);
  }
  cout << ans << endl;
  return 0;
}


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

string s;

int main(){
	cin>>s;
	int ans=0;
	for(int i=0;i<(int)s.size()/2;i++)
		if(s[i]!=s[(int)s.size()-1-i]) ans++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
mod = 998244353
def cmb(n, r, mod=mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NN = 10**5 # 使うデータによって変える
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, NN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )


import sys
input = sys.stdin.readline

S = list(input().rstrip())

L = len(S)
dp = [[0]*(L+1) for _ in range(L+1)]
dp[0][0] = 1
rmax = [0, 0]
rmin = [0, 0]
rsum = 0
for i, s in enumerate(S):
    p = int(s)
    rsum += p
    if p == 0:
        rmin[1] += 2
    elif p == 1:
        rmax[1] += 1
        rmin[1] += 1
    else:
        rmax[1] += 2
    if rmax[1] > 0:
        rmax[0] += 1
        rmax[1] -= 1
    if rmin[1] > 0:
        rmin[0] += 1
        rmin[1] -= 1
    for j in range(i+1):
        if rmax[0] >= j+1:
            dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % mod
        if rmin[0] >= (i+1) - j:
            dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % mod


ans = 0
for j in range(L+1):
    ans = (ans + dp[L][j] * cmb(L, rsum-j)) % mod
print(ans)

Measured memory_bytes: 121240
import sys
import numpy as np
from itertools import product

input = sys.stdin.readline

N = int(input())

F = [list(map(int,input().split())) for _ in range(N)]
P = [list(map(int,input().split())) for _ in range(N)]

f = np.array(F)
p = np.array(P)

def cal(f, p, v):
    total = 0
    max_total = -10**10
    c = np.dot(f, v.T)
    for ci in c.T:
        total = sum([p[i,cii] for i, cii in enumerate(ci)])
        max_total = max(total, max_total)
    return max_total

v = np.array(list(product([0,1],repeat=10)))
v[0] = np.array([0,0,0,0,0,0,0,0,0,1])

print(cal(f, p, v))


Measured memory_bytes: 13292
#include<bits/stdc++.h>
using namespace std;
int N;
int  binary(int key,vector<int> s){
    int left = 0;
    int right = N;
    while(left<right){
        int mid = (left+right)/2;
        if(s[mid]==key) return mid;
        else if(key<s[mid]) right = mid;
        else left = mid+1;
    }
    return -1;
}
int main(){
    cin >> N;
    vector<int> s(N);
    for(auto &i:s) cin >> i;
    sort(s.begin(),s.end());
    int q;cin >> q;
    int ans = 0;
    for(int i=0;i<q;i++){
        int data;cin >> data;
        if(binary(data,s)!=-1) ans++;
    }
    cout << ans << endl;
}


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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=ll(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) ll(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set

int main(){
    ll n;
    cin >> n;
    vector<ll> b(n-1);
    REP(i, n-1) cin >> b[i];
    ll ans= b[n-2] + b[0];
    for(ll i = n-2; i >= 1; i--){
        ans += min(b[i], b[i-1]);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3544