akhauriyash/Code-Regression huggingface dataset:
import scala.collection.mutable

object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  val Array(n, m, r, q) = readLine.trim.split(' ').map(_.toInt)
  val cards = Array.tabulate(n){_ ⇒ Nil: List[(Int, Int)]}
  for (_ ← 0 until m){
    val Array(a, b, c) = readLine.trim.split(' ').map(_.toInt)
    cards(b - 1)::=(a - 1, c)
  }
  val minChangeCost = Array.tabulate(r){_ ⇒ Array.tabulate(n){_ ⇒ Long.MaxValue}}
  for (i ← 0 until r){
    val memo = minChangeCost(i)
    val queue = mutable.PriorityQueue()(Ordering.by[(Int, Long), Long](_._2).reverse)
    for (j ← (i + r - 1) % r until n by r){
      memo(j) = 0L
      queue.enqueue((j, 0L))
    }
    while (queue.nonEmpty){
      val (top, distance) = queue.dequeue()
      if (memo(top) == distance){
        for ((to, cost) ← cards(top)){
          if (memo(to) - cost > distance){
            memo(to) = distance + cost
            queue.enqueue((to, distance + cost))
          }
        }
      }
    }
  }
  println(
    (for (_ ← 0 until q) yield {
      val Array(x, y, z) = readLine.trim.split(' ').map(_.toInt)
      minChangeCost.map{memo ⇒
        if (memo(x - 1) < z - memo(y - 1)) z - memo(x - 1) - memo(y - 1)
        else 0L
      }.max
    }).sum
  )


  implicit class Extension[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


Measured memory_bytes: 494028
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
#include <tuple>
#include<map>

using namespace std;
int main() {
	string s, ans;

	cin >> s;

	for (int i = 0; i < s.size(); ++i) {
		if (s.at(i) == '0') { ans.push_back('0'); }
		else if (s.at(i) == '1') { ans.push_back('1'); }
		else if (s.at(i) == 'B' && ans.size() >0) { ans.pop_back(); }
	}

	cout << ans << endl;

}

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

const int c[][8] = {
    {0, 0, 0, 0, 0, 0, 0, 0},
    {0, 0, 300, 500, 600, 700, 1350, 1650},
    {0, 6, 0, 350, 450, 600, 1150, 1500},
    {0, 13, 7, 0, 250, 400, 1000, 1350},
    {0, 18, 12, 5, 0, 250, 850, 1300},
    {0, 23, 17, 10, 5, 0, 600, 1150},
    {0, 43, 37, 30, 25, 20, 0, 500},
    {0, 58, 52, 45, 40, 35, 15, 0},
};
const int bt = 60 * 17 + 30;
const int lt = 60 * 19 + 30;

int main() {
    int s;
    while (cin >> s, s) {
        bool half = false;
        int hh, mm;
        cin >> hh >> mm;
        int time = 60 * hh + mm;
        half |= (bt <= time && time <= lt);
        int t;
        cin >> t >> hh >> mm;
        time = 60 * hh + mm;
        half |= (bt <= time && time <= lt);
        half &= (c[t][s] <= 40);
        int ans = c[s][t];
        if (half) {
            ans /= 2;
            if (ans % 50 != 0) {
                ans += 50 - (ans % 50);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
int xx=10000000007;
int a[120];
int main()
{
    int n;
    cin>>n;
    int su=xx,c=0;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        if(a[i]>=c)
            c=a[i];
        if(a[i]<=su)
            su=a[i];
    }
        int ans=xx;
        for(int i=su; i<=c; i++)
        {
            int sum=0;
            for(int j=1; j<=n; j++)
                sum+=(a[j]-i)*(a[j]-i);
            ans=min(sum,ans);

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


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

int main(){

  int N;
    cin>>N;
    vector<int> A(N+1),B(N);
    long int ans=0,ans2=0;
    for(int i=0;i<N;i++){
        cin>>B[i];
        if(i%2==0){
            if(A[i]+B[i]>0) A[i+1]=A[i]+B[i];
            else{
                A[i+1]=1;
                ans=ans+1-(A[i]+B[i]);
            }
        }
        if(i%2==1){
            if(A[i]+B[i]<0) A[i+1]=A[i]+B[i];
            else{
                A[i+1]=-1;
                ans=ans+(A[i]+B[i])+1;
            }
        }
        }
    for(int i=0;i<N;i++){
        B[i]*=-1;
        A[i]=0;
    }
    A[N]=0;
    for(int i=0;i<N;i++){
        if(i%2==0){
            if(A[i]+B[i]>0) A[i+1]=A[i]+B[i];
            else{
                A[i+1]=1;
                ans2=ans2+1-(A[i]+B[i]);
            }
        }
        if(i%2==1){
            if(A[i]+B[i]<0) A[i+1]=A[i]+B[i];
            else{
                A[i+1]=-1;
                ans2=ans2+(A[i]+B[i])+1;
            }
        }
    }
    
    cout<<min(ans,ans2)<<endl;
    }
    


Measured memory_bytes: 1024
n = int(input())
d = {'M':0,'A':0,'R':0,'C':0,'H':0}
for _ in range(n):
  s= input()
  if s[0] in d:
    d[s[0]] += 1
march = list('MARCH')
from itertools import combinations

ans = 0
for a,b,c in combinations(march,3):
  ans += d[a]*d[b]*d[c]
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define N 400050
#define int long long
#define pb push_back
#define x first
#define y second
#define all(v) v.begin(),v.end()
#define coffee prince
#define sz(a) (int)a.size()
#define ll long long
#define SIZE N
using namespace std;
ll n,ans;
set< ll > pr;
bool che(int x){
  if(x<2||x>n)return 0;
    ll m = n;
    while((m%x)==0){
        m/=x;
    }
    m%=x;
    if(m==1)return 1;
    return 0;
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n;
    ll val= n-1;
    for(ll i=2;i*i<=val;i++){
        if(val%i)continue;
        pr.insert(i);
        pr.insert(val/i);
    }
    pr.insert(n);
    pr.insert(n-1);
    for(ll i=2;i*i<=n;i++){
        if(n%i)continue;
        pr.insert(i);
        ll j = n/i;
        pr.insert(j);
    }
    for(auto ch : pr)
        if(che(ch))ans++;
    cout<<ans;
        return 0;
}


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


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

    string a,b; cin >> a >> b;
    int c;

    a += b;
    c = stoi(a);

    int d;
    d = sqrt(c);

    if(c == d * d) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define ld long double
#define pll pair<ll, ll>
#define pii pair<int, int>
#define f first
#define se second
#define pb push_back
#define ft fflush(stdout)
 
 
using namespace std;
 
 
const int N = 2e5 + 123;
const int PLS = 3e5 + 123;
const int mod = 1e9 + 7;
const ll inf = 1e16;


ll n, a[N], dp[N];


int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    dp[1] = 0;
    dp[2] = abs(a[1] - a[2]);
    for (int i = 3; i <= n; i++)
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
    cout << dp[n];
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b)for(int i=a;i<b;++i)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int h,w,a,b;
	cin>>h>>w>>a>>b;
	vector<vector<int>> ans(h,vector<int>(w,0));

	if(h==1){
		rep(i,a)ans[0][i]=1;
	}else if(w==1){
		rep(i,b)ans[i][0]=1;
	}else{
		rep(i,b)rep(j,a)ans[i][j]=1;
		repi(i,b,h)repi(j,a,w)ans[i][j]=1;
	}
	rep(i,h){
		rep(j,w)cout<<ans[i][j];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 5120
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long s = sc.nextLong();
        long c = sc.nextLong();
        long ans = Math.min(s,c/2);
        s -= ans;
        c -= (ans * 2);
        
        if (s == 0) {
            ans += c/4;
        }

        System.out.println(ans);

        sc.close();
    }
}





Measured memory_bytes: 23764
package main

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

func main() {
	sc := NewScanner()
	N := sc.NextInt()

	s := 0
	for i := 0; i <= N; i++ {
		s += i
		if s >= N {
			fmt.Println(i)
			return
		}
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
s = list(input())
mods = [0]*(len(s))
countRemainder = [0] * 2019
cnt = 0


m = 1
mod = 0
for i in range(len(s)):
    mod += int(s[len(s) - i - 1]) * m

    mod %= 2019
    m *= 10
    m %= 2019

    countRemainder[mod] += 1

countRemainder[0] += 1

for i in range(2019):
    cnt += int(countRemainder[i] * (countRemainder[i] - 1) / 2)

print(cnt)



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

using namespace std;

typedef long long llint;

const int MAXN = 3005;
const int MOD = 1000000007;

int n, m, sol;
int dp[MAXN][MAXN][2];

int add (int x, int y) {x += y; if (x >= MOD) return x - MOD; return x;}

int calc (int pos, int val, bool flg) {
    if (pos == m) return flg;
    if (dp[pos][val][flg] != -1) return dp[pos][val][flg];
    int res = 0;
    if (val > 0) {
        res = add(res, calc(pos + 1, val, flg | (val == 1)));
        res = add(res, calc(pos + 1, val - 1, flg | (val == 1)));
    }
    if (val < n) {
        res = add(res, calc(pos + 1, val, flg | (val == 0)));
        res = add(res, calc(pos + 1, val + 1, flg | (val == 0)));
    }
    return dp[pos][val][flg] = res;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    memset(dp, -1, sizeof dp);
    cin >> n >> m;
    for (int i = 0; i <= n; i++) {
        sol = add(sol, calc(0, i, 0));
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 71168
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //required
// #include <ext/pb_ds/tree_policy.hpp> //required

#define dbg(x) cerr<<#x": "<<x<<"\n"
#define dbg_v(x, n) do{cerr<<#x"[]: ";for(int _=0;_<n;++_)cerr<<x[_]<<" ";cerr<<'\n';}while(0)
#define dbg_ok cerr<<"OK!\n"

#define st first
#define nd second

// using namespace __gnu_pbds; 
using namespace std;

// template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; // ordered_set <int> s;
template<class T> ostream& prnt(ostream& out, T v) { out << v.size() << '\n'; for(auto e : v) out << e << ' '; return out;}
template<class T> ostream& operator<<(ostream& out, vector <T> v) { return prnt(out, v); }
template<class T> ostream& operator<<(ostream& out, set <T> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, map <T1, T2> v) { return prnt(out, v); }
template<class T1, class T2> ostream& operator<<(ostream& out, pair<T1, T2> p) { return out << '(' << p.st << ' ' << p.nd << ')'; }

const int N = 100100;
const int MOD = 1e9 + 7;
long long n, k, m, dp[(1 << 26) + 10], f[N], ans;
string s;

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	cin >> s;
	for(auto i : s) f[i - 'a']++;

	dp[0] = 1;
	for(int msk = 1; msk < (1 << 26); msk++) {
		int mm = msk;
		int k = 0;
		while(mm % 2 == 0 && mm > 0) mm /= 2, k++;
		mm = msk ^ (1 << k);
		dp[msk] = (dp[mm] * f[k]) % MOD;
		ans += dp[msk];
		ans %= MOD;
	}
	cout << ans << '\n';
}	


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

int main() {
	int ans = 0;
	char c;
	while (cin >> c) {
		if (ans >> c - 'a' & 1) {
			cout << "no" << endl;
			return 0;
		}
		ans |= 1 << c - 'a';
	}
	cout << "yes" << endl;
}

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

int main() {
  string s; cin >> s;
  int l=s.length();
  vector<int>V(l,0);
  for (int i=0; i<l; i++){
    V[i]+=pow(10,i);
    for (int j=0; j<i; j++){
      V[i]+=pow(2,j)*pow(10,i-j-1);
    }
  }
  long long ans=0;
  for (int i=0; i<l; i++){
    ans += V[i]*pow(2,l-i-1)*(s[l-i-1]-'0');
  }
  cout << ans << "\n";
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;
#define lli long long int
#define numberofdigits(x) floor(log10(x)) + 1

int main()
{
    lli n,k,i,a[200005];
    cin>>n>>k;
    for(i=1;i<=n;i++)
        cin>>a[i];
    for(i=k+1;i<=n;i++)
    {
        if(a[i]>a[i-k])
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    return 0;
}

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

#define ll long long

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

	int a, b, c, d;
    cin >> a >> b >> c >> d;
    int flag = 0;
    while(a>0||c>0){
        if(flag==0){
            c-=b;
            flag=1;
        }else{
            a-=d;
            flag=0;
        }
    }
    if(flag==0){
        cout << "Yes";
    }else{
        cout << "No";
    }
    

	return 0;
}


Measured memory_bytes: 3636
N,m=map(int,input().split())
s= set([int(input()) for i in range(m)])
INF=1000000007

dp=[0]*(N+1)
dp[0]=1
if 1 not in s:
  dp[1]=1
else:
  dp[0]
for i in range(2,N+1):
  if i in s:
    continue
  dp[i]=dp[i-1]+dp[i-2]
  dp[i]=dp[i]%INF
  
print(dp[N])

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

typedef pair <int,int> pii;
typedef vector <pii> vpii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef long long int lli;
typedef pair<lli,lli> plli;
typedef vector <plli> vplli;
typedef vector <lli> vlli;
typedef vector <vlli> vvlli;
typedef vector <string> vs;
typedef vector <bool> vb;

#define rep(i, n) for( i = 0; i < (n); ++i)
#define repA(i, a, n) for( i = a; i <= (n); ++i)
#define repD(i, a, n) for( i = a; i >= (n); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sortr(x) sort(x.begin(),x.end(),greater <int> ())
#define mod 1000000007
#define ff first
#define ss second
#define fill(a,c)  memset(a, c, sizeof (a))
#define formap(i,v) for(auto &i: v)
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl(v) cout<<#v<<" = \n"; { int c=0; formap(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it<<endl;} cerr<<endl
#define dbgstlp(v) cout<<#v<<" = \n"; { int c=0; formap(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it.first<<" , "<<it.second<<endl;} cerr<<endl
#define PI  3.14159265358979323846
#define pb push_back



int main() {
    cin.sync_with_stdio(0);cin.tie(0);
    cin.exceptions(cin.failbit);
    
    int i,j,k,n;
    cin>>n>>k;
    vi a(n),ans;
    rep(i,n)cin>>a[i];
    repA(i,k,n-1){
         if (a[i]>a[i-k])ans.pb(1);
         else ans.pb(0);
    }
    vs val={"No","Yes"};
    rep(i,ans.size()){
         cout<<val[ans[i]]<<endl;
    }
    
    
    
    
    
    
    
    
    
     
   
   
	return 0;
}


Measured memory_bytes: 5028
package main

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

var infty = 1000000000

var scanner = bufio.NewScanner(os.Stdin)

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

func nextInt() int {
	n, err := strconv.Atoi(nextString())
	if err != nil {
		fmt.Printf("strconv.Atoi failed: %v\n", err)
	}
	return n
}

type DirectedGraphNodeID int

type DirectedGraphNode struct {
	key       DirectedGraphNodeID
	parent    *DirectedGraphNode
	adjacents []*DirectedGraphNode

	l int
	h int
}

var currentMaxNodeID = 0

func getLowestCommonAncestor(leftNode, rightNode *DirectedGraphNode) *DirectedGraphNode {
	if leftNode.l <= rightNode.l && rightNode.h <= leftNode.h {
		return leftNode
	} else if rightNode.l <= leftNode.l && leftNode.h <= rightNode.h {
		return rightNode
	}
	return getLowestCommonAncestor(leftNode.parent, rightNode)
}

func fillRange(parent *DirectedGraphNode) (int, int) {
	currentMaxNodeID++
	if len(parent.adjacents) == 0 {
		parent.l = currentMaxNodeID
		parent.h = currentMaxNodeID
	} else {
		parent.l = currentMaxNodeID
		for _, adjacent := range parent.adjacents {
			_, _ = fillRange(adjacent)
			// fmt.Println(adjacent.key, l, h, parent.l, parent.h)
		}
		currentMaxNodeID++
		parent.h = currentMaxNodeID
	}
	return parent.l, parent.h
}

func main() {
	scanner.Split(bufio.ScanWords)

	nNodes := nextInt()
	nodes := make([]*DirectedGraphNode, nNodes)
	for iNode := 0; iNode < nNodes; iNode++ {
		node := DirectedGraphNode{
			key: DirectedGraphNodeID(iNode),
			l:   infty,
			h:   -infty,
		}
		nodes[iNode] = &node
	}
	for iNode := 0; iNode < nNodes; iNode++ {
		nChildren := nextInt()
		parentNode := nodes[iNode]
		for iChild := 0; iChild < nChildren; iChild++ {
			iChildNode := nextInt()
			childNode := nodes[iChildNode]
			childNode.parent = parentNode
			parentNode.adjacents = append(parentNode.adjacents, childNode)
		}
	}

	fillRange(nodes[0])

	nQueries := nextInt()
	for iQuery := 0; iQuery < nQueries; iQuery++ {
		leftNodeID := DirectedGraphNodeID(nextInt())
		rightNodeID := DirectedGraphNodeID(nextInt())

		leftNode := nodes[leftNodeID]
		rightNode := nodes[rightNodeID]
		lca := getLowestCommonAncestor(leftNode, rightNode)
		fmt.Println(lca.key)
	}

	// for _, node := range nodes {
	// 	fmt.Println(node.key, node.l, node.h)
	// }
}



Measured memory_bytes: 25588
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
struct ArticulationPoints{
  int n,timer;
  vector<vector<int> > G;
  vector<int> used,pre,par,low;
  set<int> ap;
  ArticulationPoints(){}
  ArticulationPoints(int sz):
    n(sz),G(sz),used(sz),pre(sz),par(sz),low(sz){}
  
  void add_edge(int from,int to){
    G[from].push_back(to);
    G[to].push_back(from);
  }
  
  void dfs(int v,int p){
    pre[v]=low[v]=timer;
    timer++;
    used[v]=1;
    for(int u:G[v]){
      if(!used[u]){
	par[u]=v;
	dfs(u,v);
	low[v]=min(low[v],low[u]);
      }else if(u!=p){
	low[v]=min(low[v],pre[u]);
      }
    }
  }
  
  void build(){
    fill(used.begin(),used.end(),0);
    ap.clear();
    timer=1;
    dfs(0,-1);
    int np=0;
    for(int i=1;i<n;i++){
      int p=par[i];
      if(p==0) np++;
      else if(pre[p]<=low[i]) ap.insert(p);
    }
    if(np>1) ap.insert(0);
  }
};
//END CUT HERE

signed main(){
  int v,e;
  cin>>v>>e;
  ArticulationPoints ap(v);
  for(int i=0;i<e;i++){
    int s,t;
    cin>>s>>t;
    ap.add_edge(s,t);
  }
  ap.build();
  for(int i:ap.ap) cout<<i<<endl;
  return 0;
}

/*
  verified on 2017/10/29
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_3_A&lang=jp
*/

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

const int maxn = 300005;
int a[maxn], top, n, K;

int main() {
	scanf("%d%d", &K, &n);
	if (!(K&1)) {
		printf("%d ", K / 2);
		rep (i, 2, n) printf("%d ", K);
		return 0;
	}
	rep (i, 1, n) a[i] = (K + 1) / 2;
	top = n;
	rep (i, 1, n / 2)
		if (a[top] == 1) top--;
		else {
			a[top]--;
			while (top < n) a[++top] = K;
		}
	rep (i, 1, top) printf("%d ", a[i]);
	
	return 0;
}

Measured memory_bytes: 3456
#include <vector>
#include <iostream>
#include <cmath>
#include <iomanip>
#include <string>
#include <utility>
#include <stack>
#include <numeric>
#include <random>
#include <algorithm>
#include <queue>
#include <functional>
#include <iterator>
#include <list>
#include <unordered_map>
#include <deque>
#include <math.h>
#include <tgmath.h>
using namespace std;

#define rep(i, b, e) for(i = b; i < e; ++i)
#define repr(i, b, e) for (i = b; i >= e; --i)
#define ull unsigned long long int
#define ll long long int
#define pint pair<int, int>

#define M_DEBUG 1
#define PI 3.141592653589793

#define E '\n'

#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << "\n";}
#define INF (1e18)

const ll MAX = 1000000000;
const ll MOD = 1e9 + 7;

ll a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;

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;
}

ll aabs(ll a) {
    if (a < 0) return -a;
    return a;
}

//fast power
ll calc(ll a, ll b) {
    if (b == 0) return 1;
    else if (b % 2 == 0) {
        ll d = calc(a, b / 2);
        return (d * d) % MOD;
    }
    else return (a * calc(a, b - 1)) % MOD;
}

//fast combination
ll comb(ll n, ll a) {
    ll b = 1, c = 1;
    for (ll i = 1; i <= a; ++i) {
        b = b * i % MOD;
        c = c * (n - i + 1) % MOD;
    }

    return c * calc(b, MOD - 2) % MOD;
}

ll comb2(ll a) {
    ll b = a / 2;
    if (a % 2) {
        b = (a - 1) / 2;
        return (b * a);
    }
    return (b * (a - 1));
}

int kyotsu(string ss, int st, int ed, string ss2) {
    int ans = 0;
    for ( int i = st; i < ed; ++i ) {
        if (i - st >= ss2.size()) return ans;
        if (ss[i] == ss2[i - st] || ss[i] == '?') {
            ans++;
        } else {
            return -1;
        }
    }
    return ans;
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> k >> n;
    vector<ll> aa(n, 0);
    rep (i, 0, n) cin >> aa[i];

    c = k - aa[n - 1] + aa[0];
    rep (i, 0, n - 1) {
        if (c < aa[i + 1] - aa[i])
            c = aa[i + 1] - aa[i];
    }

    if (c < k - aa[n - 1])
        c = k - aa[n - 1];

    k -= c;


    cout << k << endl;

    

    
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
using namespace std;
int vis[2000005];
int mx;
int ans;
int a[300005];
 main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
           int n;
           cin>>n;
           for(int i =0; i<n; i++){
            cin>>a[i];
            vis[a[i]]++;
            mx = max(mx,a[i]);
           }
           for(int i =0; i<n; i++){
                int flag = 1;
                vis[a[i]]--;
                for(int j =1; j*j<=a[i]; j++){
                    if(a[i] % j == 0 ){
                        if(vis[j])flag = 0;

                    int cur = a[i]/j;
                    if(vis[cur]){
                        flag = 0;
                    }

                    }
                }
                    vis[a[i]]++;

           ans+=flag;
           }
           cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 12976
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] s = sc.nextLine().toCharArray();
		int a = 0;
		int x = s.length / 2;
		if (s.length % 2 == 1) {
			int i = 1;
			while (x + i < s.length && s[x + i] == s[x - i] && s[x + i] == s[x]) {
				i++;
			}
			a += i;
		} else {
			int i = 0;
			while (x + i < s.length && s[x + i] == s[x - 1 - i]) {
				i++;
			}
			a += i;
		}

		System.out.println(x + a);
	}
}


Measured memory_bytes: 25932
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
  ll n;
  cin>>n;
  ll a[n+5];
  ll tuyoi=0,nomal=0,yowa=0;
  rep(i,n){
    cin>>a[i];
    if(a[i]%4==0){
      tuyoi++;
    }
    else if(a[i]%2==0){
      nomal++;
    }
    else{
      yowa++;
    }
  }
  if(nomal==0){
    if(yowa-1<=tuyoi){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
  else{
    if(yowa<=tuyoi){
       cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
}
      


Measured memory_bytes: 4312
#include <bits/stdc++.h>
#define N 100005
#define For(i,x,y) for(int i=(x);i<=(y);++i)
#define Rof(i,x,y) for(int i=(x);i>=(y);--i)
#define NosoL return puts("No"),0
#define SoL return puts("Yes"),0
using namespace std;
int a[4][N],cnt[2],to[N],n,c[N];
char buffer[10000010],*hed;
char Getchar(){ return *hed++; }
int rd(){
    register int x=0;
    char c;do c=Getchar();
    while(!isdigit(c));
    do{ x=(x<<1)+(x<<3)+(c^48);c=Getchar(); }while(isdigit(c));
    return x;
}
void ins(int x){ for(int i=x;i<=n;i+=(i&(-i))) c[i]++; }
int qry(int x){ int res=0;for(int i=x-1;i;i-=(i&(-i)))res+=c[i];return res; }
int main(){
	int len=fread(buffer,1,10000000,stdin);
    hed=buffer;
	n=rd();
	For(i,1,3) For(j,1,n) a[i][j]=rd();
	For(i,1,n){
		if(abs(a[1][i]-a[2][i])!=1 || abs(a[2][i]-a[3][i])!=1) NosoL;
		For(j,1,3) if(a[j][i]%2!=(i+3*j-3)%2) NosoL;
		if(a[1][i]%3==1 && a[1][i]>a[2][i]) NosoL;
		if(a[1][i]%3==0 && a[1][i]<a[2][i]) NosoL;
		to[i]=(a[2][i]+1)/3;
		cnt[i&1]^=(a[1][i]>a[3][i]); 	
	}
	For(i,1,n) if(to[i]%2!=i%2) NosoL;
	for(int i=n-(n%2==0);i>=1;i-=2){
		int x=qry(to[i]);
		cnt[0]^=(x&1);
		ins(to[i]);
	}
	For(i,1,n) c[i]=0;
	for(int i=n-(n&1);i>=1;i-=2){
		int x=qry(to[i]);
		cnt[1]^=(x&1);
		ins(to[i]);
	}
	if(!cnt[0] && !cnt[1]) SoL;
	else NosoL;
}

Measured memory_bytes: 5760
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        BigDecimal bd = new BigDecimal(sc.next());
        bd = bd.multiply(new BigDecimal("100.0"));
        BigInteger bi = bd.toBigInteger();
        long b = Long.parseLong(bi.toString());
        long ans = (a*b)/100;
        System.out.println(ans);
    }
}


Measured memory_bytes: 36172
#include <iostream>
using namespace std;
 
int main(){ 
    int N;
    int card[9];
    
    for(int j=0;j<=8;j++)
    {
        cin>>card[j];
    }
    cin>>N;
    int num[N];

    for(int i=0;i<=N;i++)
    {
        cin>>num[i];
    }
    
    for(int a=0;a<=8;a++)
    {
        for(int b=0;b<=N-1;b++)
        {
            if (card[a]==num[b])
            {
                card[a]=1000;
            }
            
        }
        
    }

if ((card[0]==1000&&card[1]==1000&&card[2]==1000)||(card[3]==1000&&card[4]==1000&&card[5]==1000)||(card[6]==1000&&card[7]==1000&&card[8]==1000)||(card[0]==1000&&card[3]==1000&&card[6]==1000)||(card[1]==1000&&card[4]==1000&&card[7]==1000)||(card[2]==1000&&card[5]==1000&&card[8]==1000)||(card[0]==1000&&card[4]==1000&&card[8]==1000)||(card[2]==1000&&card[4]==1000&&card[6]==1000))
{
    cout<<"Yes"<<endl;
}
else
{
    cout<<"No"<<endl;
}

    
    return 0;
}

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

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define rep(i, n) for (int i = 0; i < (int)(n); ++ i)

const int mxn = 1 << 18, mo = 1e9 + 7;

int qp(int x, int n) { int ans = 1; for (; n; n >>= 1, x = 1LL * x * x % mo) if (n & 1) ans = 1LL * ans * x % mo; return ans; }
int inv(int x) { return qp(x, mo - 2); }

int k, n, ans = 0;
int p[mxn], ma[mxn], mb[mxn], dfn[mxn];

void pre(int u, int l, int r, int ml) {
	static int tme = 0;
	dfn[u] = tme ++;
	mb[u] = ml;
	if (l + 1 == r) return ;
	int m = (l + r) >> 1;
	pre(u << 1, l, m, 1LL * ml * (u << 1) % mo);
	pre(u << 1 | 1, m, r, 1LL * ml * (u << 1 | 1) % mo);
}

int lca(int u, int v) { int x = 32 - __builtin_clz(u ^ v); return v >> x; }
int getfa(int u) { return u >> 1; }
int dep(int u) { return 32 - __builtin_clz(u); }
bool subt(int u, int v) {
	int du = dep(u), dv = dep(v);
	if (dv <= du) return 0;
	v >>= (dv - du);
	if (u != v) return 0;
	return 1;
}

bool comp(pair <int, pair <int, int> > a, pair <int, pair <int, int> > b) {
	return dfn[a.first] < dfn[b.first];
}

void virtree(vector <pair <int, pair <int, int> > > pnt) {
	sort(pnt.begin(), pnt.end(), comp);
	int psz = pnt.size();
	rep(i, psz - 1) pnt.pb(mp(lca(pnt[i].first, pnt[i + 1].first), mp(0, -1)));
	sort(pnt.begin(), pnt.end(), comp);
	int stk[20], top = 0;
	vector <int> fa(pnt.size());
	vector <vector <int> > g(pnt.size());
	rep(i, pnt.size()) {
		while (top && !subt(pnt[stk[top - 1]].first, pnt[i].first)) -- top;
		if (top) fa[i] = stk[top - 1], g[fa[i]].pb(i);
		else fa[i] = -1;
		stk[top ++] = i;
	}
	vector <int> dp[2];
	rep(c, 2) dp[c].resize(pnt.size());
	for (int i = (int) pnt.size() - 1; ~i; -- i) {
		int u = pnt[i].first;
		int s = pnt[i].second.first;
		int tp = pnt[i].second.second;
		if (tp >= 0) (dp[tp][i] += 1LL * s * mb[u] % mo) %= mo;
		if (~fa[i]) rep(c, 2) (dp[c][fa[i]] += dp[c][i]) %= mo;
		int ii = inv(1LL * mb[getfa(u)] * mb[u] % mo);
		if (g[i].size() == 2) {
			(ans += 1LL * dp[0][g[i][0]] * dp[1][g[i][1]] % mo * ii % mo) %= mo;
			(ans += 1LL * dp[1][g[i][0]] * dp[0][g[i][1]] % mo * ii % mo) %= mo;
		}
	}
}

void dfs(int u, int l, int r) {
	if (l + 1 == r) { ma[l] = u; return ; }
	int m = (l + r) >> 1;
	dfs(u << 1, l, m);
	dfs(u << 1 | 1, m, r);
	vector <pair <int, pair <int, int> > > pnt;
	for (int i = l; i < m; ++ i) pnt.pb(mp(p[i] + n, mp(1LL * ma[i] * u % mo, 0)));
	for (int i = m; i < r; ++ i) pnt.pb(mp(p[i] + n, mp(ma[i], 1)));
	virtree(pnt);
	for (int i = l; i < r; ++ i) ma[i] = 1LL * ma[i] * u % mo;
}

int main() {
	scanf("%d", &k); n = 1 << (k - 1);
	rep(i, n) scanf("%d", &p[i]), -- p[i];
	mb[0] = 1; pre(1, 0, n, 1); dfs(1, 0, n);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 24280
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define rrep1(i,n) for(int i = (n); i >= 1; --i)
#define REP(i,n,m) for(int i = (n); i < (m); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cerr << v << " "; cerr << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << v << " "; cerr << endl; } 
#define debugP(vec) for(auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl;
#define debug2DP(vec2D) for(auto vec : vec2D) { for (auto v : vec) cerr << "(" << v.first << "," << v.second << ") "; cerr << endl; } 

const char en = '\n';

typedef long long ll;

constexpr ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
constexpr ll MOD = 1000000007;

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

int main() {
	ll n; cin >> n;
	vector<ll> as(n);
	rep(i, n) { cin >> as[i]; if (as[i] == 0) { cout << 0 << endl; return 0; } }

	ll ans = 1;
	rep(i, n) {
		ll a = as[i];
		ans *= a;
		if (max(ans,a) > 1000000000000000000 || (ans > 1000000000 && a > 1000000000) || ans < (ll) 0) { cout << -1 << endl; return 0; }
	}
	cout << ans << endl;
}


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

const ll maxs = 2e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){
    
}

ll n;
ll a[maxs];
ll dp[maxs][4];
bool vis[maxs][4];

ll go(ll pos,ll have){
    if(pos >= n){
        if(have <= 1)
            return 0;
        return -oo;
    }
    ll& ans = dp[pos][have];
    if(vis[pos][have])
        return ans;
    vis[pos][have] = true;

    if(!have)
        ans =  a[pos] + go(pos+2,have);
    else
        ans = max(a[pos] + go(pos+2,have) , go(pos+1,have-1) );
    
    return ans;

}

void solve(){
    cin >> n;
    for(ll i=0;i<n;i++)
        cin >> a[i];
    
    ll ans = go(0,1 + (n&1));
    
    cout << ans << endl;
}

int main(){
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

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

using namespace std;
#ifdef ONLINE_JUDGE
#define cerr if(false)cerr
#endif
#define int long long
#define ld1 long double
#define watch(x) cerr << (#x) << " is " << (x) << endl
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL),cout<<setprecision(14);
#define cint int t;cin>>t;while(t--)
#define vint vector<int>
#define all(v) (v).begin(), (v).end()
#define pii pair<int,int>
#define pb push_back
#define N 50011
#define mm0(X) memset((X), 0, sizeof((X)))
#define mm1(X) memset((X), -1, sizeof((X)))
#define MAXN (int)1e6 + 11
#define INF (int)1e9
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define endl '\n'

const int mod=1000000007;
int powmod(int a,int b) {int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int sqr(int j){
    return j*j*j*j*j;
}
void solve(){
    int x;
    cin>>x;
    for(int i=-1000;i<1000;i++){
        for(int j=-1000;j<1000;j++){
            if((sqr(i)-sqr(j))==x){
                cout<<i<<" "<<j<<endl;
                return;
            }
        }
    }
}

int32_t main() {
    faster;

#ifndef ONLINE_JUDGE
    READ("inp.txt");
    WRITE("out.txt");
    double beg=clock();
#endif

    int t=1;
//    cin>>t;

    while(t--){
        solve();
    }

#ifndef ONLINE_JUDGE
    double end=clock();
    cerr<<"*** Total time = "<<(end-beg)/CLOCKS_PER_SEC;
#endif
}


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

int main(){
  ll n,m,a,i;
  cin >> n >> m;
  for(i=0;i<m;i++){
    cin >> a;
    n-=a;
  }
  if(n<0)n=-1;
  cout << n;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int H, W, K;
string maps[10];

int dp[10][11][1001];
// [i][j][k] := y が [i, j) の区間で最後にカットしたのが j = k であるときの最小


int sum[11][1001];

int main() {
	cin >> H >> W >> K;
	REP(i, H) cin >> maps[i];
	
	REP(i, H) REP(j, W) sum[i + 1][j + 1] += maps[i][j] == '1';
	
	REP(i, H + 1) REP(j, W) sum[i][j + 1] += sum[i][j];
	REP(j, W + 1) REP(i, H) sum[i + 1][j] += sum[i][j];
	
	// REP(i, H + 1) {
	// 	REP(j, W + 1) printf("%d ", sum[i][j]);
	// 	puts("");
	// }
	
	int ans = INF;
	REP(s, 1<<H) {
		vector<int> itv;
		itv.emplace_back(0);
		FOR(i, 1, H) if (s >> i & 1 ^ s >> (i - 1) & 1) {
			itv.emplace_back(i);
		}
		itv.emplace_back(H);
		
		vector<int> c(itv.size() - 1);
		
		int cur = c.size() - 1;
		int cx = 0;
		bool zero = true, muri = false;
		while (cx < W) {
			bool ng = false;
			REP(i, itv.size() - 1) {
				int i1 = itv[i], i2 = itv[i + 1], x1 = cx, x2 = cx + 1;
				c[i] += sum[i2][x2] - sum[i1][x2] - sum[i2][x1] + sum[i1][x1];
				if (c[i] > K) { ng = true;  break; }
			}
			if (ng) {
				if (zero) { muri = true; break; }
				REP(i, c.size()) c[i] = 0;
				++cur;
				zero = true;
			}
			else {
				zero = false;
				++cx;
			}
		}
		if (!muri) chmin(ans, cur);
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
text = []
while True:
  s = input()
  if s == "END_OF_TEXT":
    break
  text.append(s)

x, y = 0, 0
buff = ""
while True:
  c = input()
  if c == "-":
    break

  elif c == "a":
    x = 0

  elif c == "e":
    x = len(text[y])

  elif c == "p":
    if y == 0:
      x = 0
    else:
      x = 0
      y -= 1

  elif c == "n":
    if y == len(text) - 1:
      x = 0
    else:
      y += 1
      x = 0

  elif c == "f":
    if x != len(text[y]):
      x += 1
    elif y != len(text) - 1:
      y += 1
      x = 0

  elif c == "b":
    if x != 0:
      x -= 1
    elif y != 0:
      y -= 1
      x = len(text[y])

  elif c =="d":
    if x < len(text[y]):
      text[y] = text[y][:x] + text[y][x + 1:] 
    elif y != len(text) - 1:
      text[y] = text[y] + text[y + 1]
      text = text[:y + 1] + text[y + 2:]

  elif c == "k":
    if x < len(text[y]):
      buff = text[y][x:]
      text[y] = text[y][:x]
    elif y != len(text) - 1:
      text[y] = text[y] + text[y + 1]
      text = text[:y + 1] + text[y + 2:]
      buff = "\n"

  elif c =="y":
    if buff == "\n":
      new_row = text[y][x:]
      text[y] = text[y][:x]
      text = text[:y + 1] + [new_row] + text[y + 1:]
      x = 0
      y += 1
    else:
      text[y] = text[y][:x] + buff + text[y][x:]
      x += len(buff)

print(*text, sep="\n")


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

long long N, D;
long long X[12][12];

int main(){
	cin >> N >> D;
	for(long long i = 0; i < N; i++){
		for(long long j = 0; j < D; j++){
			cin >> X[i][j];
		}
	}
	long long count = 0;

	for(long long i = 0; i < N; i++){
		for(long long j = i+1; j < N; j++){
			long sumi = 0;
			for(long long idx = 0; idx < D; idx++){
				sumi += (X[i][idx] - X[j][idx]) *  (X[i][idx] - X[j][idx]);
			}
			long sq = sqrt(sumi);
			if(abs(sq*sq - sumi) < 0.001){
				count++;
			}
		}
	}

	cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a), i##_end_ = (b); i <= i##_end_; ++i)
#define drep(i, a, b) for(int i = (a), i##_end_ = (b); i >= i##_end_; --i)
#define clar(a, b) memset((a), (b), sizeof(a))
#define debug(...) fprintf(stderr, __VA_ARGS__)
typedef long long LL;
typedef long double LD;
int read() {
    char ch = getchar();
    int x = 0, flag = 1;
    for (;!isdigit(ch); ch = getchar()) if (ch == '-') flag *= -1;
    for (;isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x * flag;
}
void write(int x) {
    if (x < 0) putchar('-'), x = -x;
    if (x >= 10) write(x / 10);
    putchar(x % 10 + 48);
}

const int Maxn = 200009;
int n, b[Maxn], q;
struct node {
	int l, r;
}s[Maxn];

inline void init() {
	n = read();
	rep (i, 1, n) b[i] = read();
	q = read();
	rep (i, 1, q) s[i].l = read(), s[i].r = read();
}

int cmp(node a, node b) { return a.l < b.l || a.l == b.l && a.r < b.r; }

int suf0[Maxn], suf1[Maxn];

struct SGMTtree {
	int tree[Maxn << 2];
#define lc(x) ((x) << 1)
#define rc(x) ((x) << 1 | 1)
#define ls rt << 1, l, mid
#define rs rt << 1 | 1, mid + 1, r
	void pushup(int rt) {
		tree[rt] = min(tree[lc(rt)], tree[rc(rt)]);
	}
	void build(int rt, int l, int r) {
		tree[rt] = 0x3f3f3f3f;
		if (l == r) return;
		int mid = (l + r) >> 1;
		build(ls), build(rs);
		pushup(rt);
	}
	void modify(int rt, int l, int r, int pos, int x) {
		if (l == r) {
			tree[rt] = min(x, tree[rt]);
			return ;
		}
		int mid = (l + r) >> 1;
		(pos <= mid) ? modify(ls, pos, x) : modify(rs, pos, x); 
		pushup(rt);
	}
	int query(int rt, int l, int r, int P, int Q) {
		if (P > Q) return 0x3f3f3f3f;
		if (P <= l && r <= Q) return tree[rt];
		int mid = (l + r) >> 1;
		if (Q <= mid) return query(ls, P, Q);
		else if (P >= mid + 1) return query(rs, P, Q);
		else return min(query(ls, P, Q), query(rs, P, Q));
	}
#undef lc
#undef rc
#undef ls
#undef rs
}SGT1, SGT2;

int dp[Maxn];

inline void solve() {
	sort(s + 1, s + q + 1, cmp);
	rep (i, 1, n) suf0[i] = suf0[i - 1] + (b[i] == 0);
	rep (i, 1, n) suf1[i] = suf1[i - 1] + (b[i] == 1);

	clar(dp, 0x3f), dp[0] = 0;
	SGT1.build(1, 0, n), SGT2.build(1, 0, n);
	SGT1.modify(1, 0, n, 0, dp[0]), SGT2.modify(1, 0, n, 0, dp[0]);		

	rep (i, 1, q) {
		int res = SGT1.query(1, 0, n, s[i].l, s[i].r) + suf0[s[i].r];
		int res1 = SGT2.query(1, 0, n, 0, s[i].l - 1) + suf0[s[i].r] - suf0[s[i].l - 1] + suf1[s[i].l - 1];
		dp[i] = min(res, res1);
		SGT1.modify(1, 0, n, s[i].r, dp[i] - suf0[s[i].r]);
		SGT2.modify(1, 0, n, s[i].r, dp[i] - suf1[s[i].r]);
	}

	int ans = 0x3f3f3f3f;
	rep (i, 0, q) ans = min(ans, dp[i] + suf1[n] - suf1[s[i].r]);
	cout << ans << endl;
}

int main() {
//	freopen("catheral.in", "r", stdin);
//	freopen("catheral.out", "w", stdout);

	init();
	solve();

	return 0;
}


Measured memory_bytes: 11264
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
     
const int maxn(4005);
const int mod(998244353);

inline void Inc(int &x, int y) {
    x = x + y >= mod ? x + y - mod : x + y;
}

inline void Dec(int &x, int y) {
    x = x - y < 0 ? x - y + mod : x - y;
}

inline int Add(int x, int y) {
    return x + y >= mod ? x + y - mod : x + y;
}

inline int Sub(int x, int y) {
    return x - y < 0 ? x - y + mod : x - y;
}

inline int Pow(ll x, int y) {
    ll ret = 1;
    for (; y; y >>= 1, x = x * x % mod)
        if (y & 1) ret = ret * x % mod;
    return ret;
}

int n, fac[100000], inv[100000], ans, f[maxn][maxn];
char s[maxn];

inline int C(int x, int y) {
	if (x < 0 || y < 0 || y > x) return 0;
	return (ll)fac[x] * inv[y] % mod * inv[x - y] % mod;
}

int main() {
	int i, j, k, cb, cr, mx = 99999;
	inv[0] = inv[1] = 1;
    for (i = 2; i <= mx; ++i) inv[i] = (ll)(mod - mod / i) * inv[mod % i] % mod;
    for (i = 2; i <= mx; ++i) inv[i] = (ll)inv[i - 1] * inv[i] % mod;
    for (i = fac[0] = 1; i <= mx; ++i) fac[i] = (ll)fac[i - 1] * i % mod;
	scanf(" %s", s + 1), n = strlen(s + 1);
	f[0][0] = 1, cb = cr = 0;
	for (i = 1; i <= n; ++i) {
		if (s[i] == '0') cr += 2;
		else if (s[i] == '1') ++cr, ++cb;
		else cb += 2;
		for (j = 0; j <= min(cr, i); ++j) {
			if (i - j > cb) continue;
			if (j) Inc(f[i][j], f[i - 1][j - 1]);
			Inc(f[i][j], f[i - 1][j]);
		}
	}
	for (j = 0; j <= min(cr, n); ++j) Inc(ans, (ll)f[n][j] * C(n, cr - j) % mod);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 32256
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

#define int long long

signed main(){
    map<int,int> data;
    vector<int> res;
    int n=0;
    cin >> n;
    for(int i=0;i<n;i++){
        int temp=0;
        cin >> temp;
        if(data[temp]==1){
            data[temp]--;
            res.push_back(temp);
        }else{
            data[temp]++;
        }
    }
    sort(res.begin(),res.end(),greater<int>());
    if(res.size()<2){
        cout << 0 << endl;
    }else{
         cout << res[0]*res[1] << endl;
    }
    return 0;
}


Measured memory_bytes: 6528
#include <stdio.h>

int pow_int(int a, int x){
    int ex = 1;
    for(int i = 0; i < x; i++){
        ex *= a;
    }
    return ex;
}

int main(void){
    int d, n;
    scanf("%d %d", &d, &n);
    n = (n == 100)? n + 1 : n + 0;
    printf("%d\n", pow_int(100, d) * n);
    return 0;
}

Measured memory_bytes: 128
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	vector<vector<int>> city(N);
	vector<int> P(M), Y(M);
	for (int i = 0; i < M; i++) {
		cin >> P[i] >> Y[i];
		P[i]--;
		city[P[i]].emplace_back(Y[i]);
	}
	
	for (int i = 0; i < N; i++) {
		sort(city[i].begin(), city[i].end());
		city[i].erase(unique(city[i].begin(), city[i].end()), city[i].end());
	}

	for (int i = 0; i < M; i++) {
		int id = lower_bound(city[P[i]].begin(), city[P[i]].end(), Y[i]) - city[P[i]].begin();
		cout << setw(6) << setfill('0') << P[i] + 1 << setw(6) << setfill('0') << id + 1 << "\n";
	}

	return 0;
}

Measured memory_bytes: 7808
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;


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



int main() {

	int a, b;
	cin >> a >> b;

	if (a <= 8 && b <= 8) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}
	


	return 0;
}



Measured memory_bytes: 256
//#include <limits.h>
//#include <math.h>
#include <stdio.h>

int main(void) {
  int a, b,ans;
  scanf("%d %d",&a,&b);
  switch (a+b)
  {
  case 4:
    ans=2;
    break;
  case 3:
    ans=3;
    break;
  case 5:
    ans=1;
    break;
  default:
    break;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128