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

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(int i=0;i<j;i++)
#define rep1(i,j) for(int i=1;i<=j;i++)
#define rep0d(i,j) for(int i=j-1;i>=0;i--)
#define MAX 1000000007

using namespace std;


int main() {
	int n, m;
	cin >> n >> m;
	if(n<m){
		cout<<0;
	}else{
		cout<<10
          ;
	}
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> a(n);
  int cnt = 0, zero = 0;
  long long ans = 0;
  REP(i, n) {
    cin >> a[i];
    if (a[i] < 0) ++cnt;
    else if (a[i] == 0) ++zero;
    ans += abs(a[i]);
  }
  if (cnt % 2 == 0 || zero >= 1) {
    cout << ans << '\n';
    return 0;
  }
  int hiku = INF;
  REP(i, n) {
    hiku = min(hiku, abs(a[i]));
  }
  ans -= hiku;
  ans -= hiku;
  cout << ans << '\n';
  return 0;
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

signed main(){
  int n;
  cin >> n;

  vvi a(n, vi(n));
  rep(i, 0, n) rep(j, 0, n) cin >> a[i][j];

  vi dp(1<<n);
  dp[0] = 1;
  rep(i, 0, 1<<n){
    int cnt = 0;
    rep(j, 0, n) if(i & 1<<j) cnt++;
    rep(j, 0, n){
      if(i & (1<<j)) continue;
      if(a[cnt][j]){
        (dp[i | (1<<j)] += dp[i]) %= mod;
      }
    }
  }

  cout << dp[(1<<n)-1] << endl;

  return 0;
}


Measured memory_bytes: 16640
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
using namespace std;
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repb(i,r,l) for(int i=r;i>l;i--)
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator
const int MxN = 1e6+10;
char O[MxN],E[MxN];
void solve() {
    cin>>O>>E;
    for(int i=0;i<MxN;i++) {
        if(O[i]) cout<<O[i];
        if(E[i]) cout<<E[i];
    }
    cout<<endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using edge = pair<int, ll>;
using graph = vector<vector<int>>;
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
  ll n;cin >>n;
  vector<ll> c(n), s(n), f(n);
  for(int i = 0; i <n; ++i){
    cin >>c[i] >> s[i]>> f[i];
  }
  
  for(int i = 0; i < n; ++i){
    int now=0;
    for(int j = i; j < n-1; ++j){
      int dept = s[j];
      if(now>s[j])dept=((now+f[j]-1)/f[j])* f[j];
      now=dept+c[j];
    }
    cout << now << endl;
  }
}


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

ll solve(string s){
  ll ans=0;
  ll x=1; 
  int st=0;
  for(int i=0;i<s.length();i++){
    if(s[i]!='+'){
      x*=10;
    }else{
      x/=10;
      for(int j=st;j<=i;j++){
        ans+=(s[j]-'0')*x;
        x/=10;
      }
      x=1;
      st=i+1;
    }
  }
  x/=10;
  for(int i=st;i<s.length();i++){
    ans+=(s[i]-'0')*x;
    x/=10;
  }
  //cout<<s<<" "<<ans<<endl;
  return ans;
}


int main(){
  string s;
  cin>>s;
  int S=s.length()-1;
  ull ans=0;
  for(int i=0;i<(1<<S);i++){
    string tmp=s;
    int count=1;
    for(int j=0;j<S;j++){
      if((i>>j)&1){
        tmp.insert(j+count,"+");
        count++;
      }
    }
    ans+=solve(tmp);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
use whiteread::parse_line;

fn main() {
    let (k, n): (i32, usize) = parse_line().unwrap();
    let a: Vec<i32> = parse_line().unwrap();
    let mut dist: i32 = 0;

    for i in 0..n - 1 {
        if a[i + 1] - a[i] > dist {
            dist = a[i + 1] - a[i];
        }
    }
    if k - a[n - 1] + a[0] > dist {
        dist = k - a[n - 1] + a[0];
    }
    println!("{}", k - dist);
}


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

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

	if (m/2 < n) {
		cout << m / 2 << endl;
	}
	else {
		cout << n + (m - n * 2) / 4 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
// 有點不耐煩會破壞偉大的計劃

#include <bits/stdc++.h>

#define append push_back

using namespace std;
using ll = long long;

const int N = 1e5 + 3;
const int M = 1e6 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e14 + 9;
const int SM = 1e3 + 5;
const int logN = 22, BL = 400;
const double EPS = 1e-9, PI = acos(-1);
const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1};
const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1};

void debug() {
	cerr << "\n";
}
template<typename Type1, typename... Type2>
void debug(Type1 a, Type2... b) {
    cerr << a << " ";
    debug(b...);
}

int main() {
//    freopen(".in", "r", stdin);
//    freopen(".out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    long long h; cin >> h;

    long long k = 1ll * log2(h) + 1ll;

    cout << (1ll << k) - 1ll;

    return 0;
}


Measured memory_bytes: 3752
#include<stdio.h>

#define MAX_N 200001

void merge_sort (long int array[],long int left,long int right) {
  long int i, j, k, mid;
  long int work[MAX_N];  
  if (left < right) {
    mid = (left + right)/2; 
    merge_sort(array, left, mid);  
    merge_sort(array, mid+1, right);  
    for (i = mid; i >= left; i--) { work[i] = array[i]; } 
    for (j = mid+1; j <= right; j++) {
      work[right-(j-(mid+1))] = array[j]; 
    }
    i = left; j = right;
    for (k = left; k <= right; k++) {
      if (work[i] < work[j]) { array[k] = work[i++]; }
      else                   { array[k] = work[j--]; }
    }
  }
}

int main(void){

    long int N,A[MAX_N],i;

    scanf("%ld",&N);
    for(i = 0;i < N;i++){
        scanf("%ld",&A[i]);
    }

    merge_sort(A,0,N-1);

    for(i = 1;i < N;i++){
        if(A[i] == A[i-1]){
            printf("NO\n");
            return 0;
        }
    }

    printf("YES\n");
    return 0;
}

Measured memory_bytes: 29824
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>














ll h,w,sz[6],res;


void f(ll h,ll w)
{
	for(ll i=1,j=h-1;i<=h;i++,j--)
	{
		sz[1]=i*w;
		if(w%2==0||j%2==0)
		{
			sz[2]=(j*w)/2;
			sz[3]=sz[2];
		}
		else
		{
			sz[2]=((j*w)-min(j,w))/2;
			sz[3]=sz[2]+min(j,w);
		}
		sort(sz+1,sz+4);
		res=min(res,sz[3]-sz[1]);
	}
}


void solve()
{
	cin>>h>>w;
	res=h*w;
	f(h,w);
	f(w,h);
	cout<<res<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

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

using namespace std;

//#define FILE_IO

typedef long long LL;

LL N, S;

LL f(LL B, LL N)
{
    if(N < B)   return N;
    return f(B, N / B) + (N % B);
}

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%lld%lld", &N, &S);

    if(N < S)
    {
        printf("-1\n");
        return 0;
    }

    if(N == S)
    {
        printf("%lld\n", N + 1);
        return 0;
    }

    LL mlt = N - S;
    LL i = 0;
    for(i = 2; i * i <= N; i++)
    {
        if( f(i, N) == S )
        {
            printf("%lld\n", i);
            return 0;
        }
    }

    for(; i >= 1; i--)
        if( mlt % i == 0 )
        {
            if( f(mlt / i + 1, N) == S )
            {
                printf("%lld\n", mlt / i + 1);
                return 0;
            }
        }



    printf("-1\n");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n";
#pragma GCC optimize "trapv"
using namespace std;
typedef long long int ll;
int mx =1e6+100;
int main()
{
    double d,t,s;
    cin>>d>>t>>s;
    double t1 = double(d)/double(s);
    if(t1<=t){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3720
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.BigInteger;

public class Main {

    public static void main(String[] args) {
        try {
            InputReader in;
            PrintWriter out;
            boolean useOutput = false;
            // if (System.getProperty("ONLINE_JUDGE") == null) useOutput = true;
            if (useOutput) {
                FileInputStream fin = new FileInputStream(new File("src/testdata.in"));
                in = new InputReader(fin);
                FileOutputStream fout = new FileOutputStream(new File("src/testData.out"));
                out = new PrintWriter(fout);
            } else {
                InputStream inputStream = System.in;
                in = new InputReader(inputStream);
                OutputStream outputStream = System.out;
                out = new PrintWriter(outputStream);
            }
            Solver solver = new Solver();
            solver.solve(in, out);
            out.close();
            // fin.close();
            // fout.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    static class Solver
    {

        public void solve (InputReader cin, PrintWriter cout)
        {
            try {
                int n;
                n = cin.nextInt();
                long sum = 0;
                long result = 0;
                TreeMap<Long, Integer> mp = new TreeMap<>();
                mp.put(0L, 0);
                for (int i = 0; i < n; ++i) {
                    sum = sum + cin.nextLong();
                    if (mp.containsKey(sum)) {
                        mp.put(sum, mp.get(sum) + 1);
                    } else {
                        mp.put(sum, 0);
                    }
                    result += mp.get(sum);
                }
                cout.println(result);

            } catch (RuntimeException e) {
                e.printStackTrace();
                return;
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }

        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong () {
            return Long.parseLong(next());
        }

        public double nextDouble () {
            return Double.parseDouble(next());
        }

    }

}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int a, b, c, d;cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << endl;
    return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
use proconio::input;
use std::collections::HashMap;
// use std::cmp::max;
// use std::cmp::min;


fn main() {
    input! {
        A: i64,
        B: i64,
        C: i64,
        D: i64,
    }

    let mut is_on_map = vec![0i64; 1000];

    for i in A..B + 1 {
        is_on_map[i as usize] = 1;
    }

    let mut ans = 0;
    for i in C..D + 1 {
        if is_on_map[i as usize] == 1 {
            ans += 1;
        }
    }

    // 間隔を数えるので植木算
    if ans == 0 {
        ans = 0;
    } else {
        ans -= 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2156
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long n = sc.nextLong();
		long m = sc.nextLong();
		
		long min = Math.min(n, m/2);
		System.out.println(min+(m-2*min)/4);
	}

}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  string s; cin >> s;
  int n = SZ(s);
  int k = n;
  map<int, int> m;
  REP(i, n) {
    m[s[i]]++;
  }

  ll ans = 0;
  REP(i, n) {
    // cout << k << ":" << m[s[i]] << endl;
    ans += k - m[s[i]];
    m[s[i]]--;
    k--;
  }
  cout << ans + 1 << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdlib>
#include<cmath>

using namespace std;

int main()
{
    int h,m,s;
    
    while(cin >> s)
    {
        m = s/60;
        s = s%60;
        h = m/60;
        m = m%60;
        
        cout << h << ":" << m << ":" << s << endl;
    }
    
}

Measured memory_bytes: 1160
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
using large = long long;

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

    auto s = vector<string>(n);
    auto table = map<string, int>();
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
        table[s[i]]++;
    }

    auto counter = large(0);
    for (const auto &kv : table) {
        if (kv.second <= 1)
            continue;
        auto c = (large(kv.second) * (kv.second - 1)) / 2;
        counter += c;
    }

    cout << counter;
    return 0;
}


Measured memory_bytes: 18176
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let (n,m) = scan "%d %d" Tuple2.make
let routes = Array.of_list @@ scan_lines m "%d %d" Tuple2.make

module UnionFind = struct
  let empty n = Array.init n id

  let root t n =
    let rec aux c =
      if c = t.(c) then c
      else let p = aux t.(c) in t.(c) <- p; p in
    aux n

  let unite t v0 v1 =
    let w0 = root t v0 in
    let w1 = root t v1 in
    t.(w1) <- w0

  let same t v0 v1 =
    root t v0 = root t v1
end

let () =
  ListL.map (0 ++^ m) ~f:(fun k ->
      let uf = UnionFind.empty n in
      ArrayL.iteri routes ~f:(fun i (a,b)->
          if i <> k then
            UnionFind.unite uf (pred a) (pred b)
        );
      ListL.map (0++^n) ~f:(fun i ->
          ListL.map (0++^n) ~f:(fun j ->
              UnionFind.same uf i j
            )
        ) |> List.concat
      |> ListL.fold_left ~init:true ~f:(&&))
  |> ListL.map  ~f:(fun s -> if s then 0 else 1)
  |> List.sum
  |> Printf.printf "%d\n"


Measured memory_bytes: 5760
N = int(input())
import math
ans = 0
for k in range(1, int(math.sqrt(N) + 1)):
    # print(k - 1, N // k - 1)
    m = N // k - 1
    if m != 0:
        if N % k == 0 and N // m == N % m:
            ans += m

print(ans)


Measured memory_bytes: 40556
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i,N) for(ll i=0;i<N;++i)

struct Node {
	Node(){};
	~Node() {
		delete left;
		delete right;
	};	
	long long key; 
	Node *parent;
	Node *left;
	Node *right;
};

// root node is not nullptr
void insert(Node *root, Node *z) {
	Node *y = nullptr;
	Node *x = root;
	while (x != nullptr) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
	z->parent = y;
	if (z->key < y->key) {
		y->left = z;
	} else {
		y->right = z;
	}
}

bool find(Node *root, ll key) {
	if (root == nullptr) return false;
	if (root->key == key) return true;
	Node *ptr = key < root->key ? root->left : root->right;
	return find(ptr, key);
}

Node* find_using_loop(Node *root, ll key) {
	while (root != nullptr && key != root->key) {
		if (key < root->key) root = root->left;
		else root = root->right;
	}
	return root;
}

void print_by_preorder(Node *node) {
	if (node == nullptr) return;
	cout << " " << node-> key; 
	print_by_preorder(node->left);
	print_by_preorder(node->right);
}

void print_by_inorder(Node *node) {
	if (node == nullptr) return;
	print_by_inorder(node->left);
	cout << " " << node-> key; 
	print_by_inorder(node->right);
}

int main () {
	ll m;
	cin >> m;
	Node *root = new Node();
	REP(i,m) {
		string s;
		cin >> s;
		ll key;
		if (s[0] == 'i') {
			cin >> key;
			// initialize root node
			if (i==0) {
				// root node
				root->left = root->right = nullptr;
				root->key = key;
				continue;
			}
			Node *node = new Node();
			node->key = key;
			node->left = nullptr; // caution
			node->right= nullptr; // caution
			insert(root, node);
		} else if (s[0] == 'p') {
			print_by_inorder(root);
			cout << endl;
			print_by_preorder(root);
			cout << endl;
		} else if (s[0] == 'f') {
			cin >> key;
			//1.
			//cout << (find(root, key) ? "Yes" : "No") << endl;
			//2.
		  Node *t = find_using_loop(root, key);	
			if (t == nullptr) {
				cout << "no" << endl;
			} else {
				cout << "yes" << endl;
			}
		}
	}
	delete root; 
	return 0;
}




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

using namespace std;

const int maxn = 200010;
int n,m,num,minn[maxn],ans = maxn;
map<pair<int,int>,int> M;
vector <int> V[maxn];

int main()
{
    scanf("%d%d%d",&n,&m,&num);
    for (int i = 1; i <= m; i++)
        minn[i] = maxn;
    for (int i = 1; i <= m; i++)
    {
        V[i].push_back(n + 1);
        M[make_pair(n + 1,i)] = 1;
    }
    for (int i = 1; i <= n; i++)
        M[make_pair(i,m + 1)] = 1;
    for (int i = 1; i <= num; i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        V[y].push_back(x);
        M[make_pair(x,y)] = 1;
    }
    int curx = 1,cury = 1;
    while (1)
    {
        minn[cury] = min(minn[cury],curx);
        bool flag = false;
        if (!M.count(make_pair(curx + 1,cury)))
        {
            flag = true;
            curx++;
        }
        if (!M.count(make_pair(curx,cury + 1)))
        {
            flag = true;
            cury++;
        }
        if (!flag)
            break;
    }
    for (int i = 1; i <= m; i++)
    {
        sort(V[i].begin(),V[i].end());
        //cout << i << " " << minn[i] << endl;
        vector<int>::iterator it = upper_bound(V[i].begin(),V[i].end(),minn[i]);
        if (it == V[i].end())
            continue;
        ans = min(ans,(*it) - 1);
    }
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 49920
#include <bits/stdc++.h>
using namespace std;
struct iofix
{
   ios_base::Init i;
   iofix() {
      cin.sync_with_stdio(0);
      cin.tie(0);
      cout.sync_with_stdio(0);
      cout.tie(0);
      cout.precision(10);
      cout << fixed;
   }
} iofix;

void solve(){
     int64_t N; cin >> N;
     cout << ( (N % 1000 == 0) ? 0 : (1000 - N % 1000) );
}

int main(){
// #ifndef Judge
//     freopen("in.txt","r",stdin);
//     freopen("out.txt","w",stdout);
// #endif
   	solve();

 #ifndef Time
     cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
 #endif
   return 0;
}

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

using namespace std ;

#define IOS ios::sync_with_stdio(0); cin.tie(0), cout.tie(0)
#define ll long long int 

#define fr first
#define se second

#define all(v) v.begin(),v.end() 
#define rall(v) v.rbegin(),v.rend()
#define sz(v) v.size() 

#define pb push_back
#define mp make_pair 

#define PI 3.141592653589793238



ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b / gcd(a,b) ;}


//bool valid(int x, int y){return x > 0 && x < 9 && y > 0 && y < 9;}

int foo(int x){
  int cn = 0;
  while(x){
    cn++;
    x /= 10;
  }
  return cn;
}

int cntr = 0, mm = INT_MAX;
vector<int>v(5);
int main(){
  for(int i = 0 ; i < 5 ; i++)
    cin >> v[i];
  sort(all(v));
  do{
    cntr += v[0];
    for(int i = 1; i < 5 ;i++){
      for(int j = v[i]; j%10 != 0 ; j++)
        cntr++;
      cntr += v[i];
    }
    mm = min(cntr, mm);
    cntr = 0;
  }while(next_permutation(all(v)));
  cout << mm;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back 
#define N 100010
using namespace std;
int dp[N], A[N], n;
int fun(int a){
	if(a >= n)
		return 1e9;
	if(a == n - 1){
		return 0;
	}
	if(dp[a] != -1)
		return dp[a];
	return dp[a] = min(abs(A[a] - A[a + 1]) + fun(a + 1), abs(A[a] - A[a + 2]) + fun(a + 2));
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> A[i];
	memset(dp, -1, sizeof(dp));
	cout << fun(0) << '\n';

}

Measured memory_bytes: 2560
# 配列に入れて、2周目は2ずつ、3周目は2^2ずつ...と飛ばしながら見ていく
N=int(input())
stone=[0]*(2**N)
for i in range(2**N):
  stone[i]=int(input())
  
for i in range(N):
  for j in range(0,2**N,(2**i)*2):
    s1=stone[j]
    s2=stone[j+(2**i)]
    if s1!=s2:
      stone[j]=abs(s1-s2)
print(stone[0])

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

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

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

      // N 個のリングのおいしさは、L, L + 1, L + 2, ..., L + N - 1
    int t = iota(L, L + N).reduce!((a, b) => abs(a) < abs(b) ? a : b);
    int ans = iota(L, L + N).sum - t;
    writeln(ans);
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;

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

    map<int, int> m;
    for (int i = 1; i <= N; i++) {
        ++m[i % K];
    }

    for (map<int, int>::iterator itr = m.begin(); itr != m.end(); ++itr) {
        // cout << "* " << itr->first << ", " << itr->second << endl;
    }

        long long ans = 0;
    for (int a = 0; a < K; a++) {
        int b = (K - a) % K;
        int c = (K - a) % K;
        if ((b + c) % K != 0) {
            continue;
        }
        // cout << a << ", " << b << ", " << c << endl;
        ans += m[a] * m[b] * m[c];
    }

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


Measured memory_bytes: 7788
# import copy
#
N = input()
A = input().split()
n = int(N)
Int_A = [int(a) for a in A]

k = 0

for a in Int_A:
    k ^= a

if k == 0:
    print("Yes")
else:
    print("No")


#
# result = [Int_A[0]]
# Int_A.remove(Int_A[0])
#
#
# def check(a):
#     if len(Int_A) == 1:
#         if result[0] == Int_A[0] ^ a:
#             print("Yes")
#             exit()
#         return []
#
#     res = []
#     co_other = copy.deepcopy(Int_A)
#     for o in Int_A:
#         co_other.remove(o)
#         if a ^ o in co_other:
#             res.append(o)
#         co_other.append(o)
#     del co_other
#
#     return res
#
#
# def deep_check(depth):
#
#     resp = check(result[depth - 1])
#
#     if len(resp) == 0:
#         depth -= 1
#         return
#
#     for k in resp:
#         result.append(k)
#         Int_A.remove(k)
#         depth += 1
#         deep_check(depth)
#         result.remove(k)
#         Int_A.append(k)
#     depth -= 1
#     return
#
#
# deep_check(1)
# print('No')


Measured memory_bytes: 14212
#include <bits/stdc++.h>
using namespace std;
#define lli long long int


int main () {
	string t,p;
	int lt,lp;
	cin >> t >> p;

	lt = t.size();
	lp = p.size();

	for(int i=0;i<lt-lp+1;i++){
		for(int j=0;j<lp;j++){
			if(t[i+j]!=p[j]){
				break;
			}else if(j==lp-1){
				cout << i << endl;
			}
		}
	}



	return 0;
}

Measured memory_bytes: 3192
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
template<class T> inline void cmax(T &x,T y) { if(y>x) x=y; }
int sign(int x) { return x&1?-1:1; }
const int N=1e5+10;
ll f[N][3];
int A[N],n;
char op[N][2];
int main() {
	rd(n); rd(A[1]),op[1][0]='+';
	for(int i=2;i<=n;++i) {
		scanf("%s",op[i]);
		rd(A[i]);
	}
	memset(f,-0x3f,sizeof(f));
	f[0][0]=0;
	for(int i=1;i<=n;++i)
		for(int j=0;j<3;++j) {
			//f[i-1][j]
			if(op[i][0]=='-') {
				if(j<2) cmax(f[i][j+1],f[i-1][j]+sign(j+1)*A[i]);
				cmax(f[i][j],f[i-1][j]+sign(j+1)*A[i]);
				if(j>0) cmax(f[i][j-1],f[i-1][j]+sign(j+1)*A[i]);
			}
			else {
				cmax(f[i][j],f[i-1][j]+sign(j)*A[i]);
				if(j>0) cmax(f[i][j-1],f[i-1][j]+sign(j)*A[i]);
			}
		}
	ll ans=-1e18;
	for(int j=0;j<3;++j) cmax(ans,f[n][j]);
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
long long oll = 0;
#define ll long long
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb push_back
#define pii pair<int,int>
#define lcm(a,b) a*b/__gcd(a,b)
#define fl(i,a,b) for(int i = a;i < b;i++)
#define lf(i,a,b) for(int i = b;i >= a;i--)
#define MEM(x,y) memset(x,y,sizeof(x))
#define mp make_pair

void solve()
{
    int n,m;
    cin>>n>>m;
    int ans = n*(n-1)/2 + m*(m-1)/2;
    cout << ans << "\n";
}

int main()
{
    //FIO;
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    solve();
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10000000)

N,X,Y=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())

memo={}
def func(n,last,turn):  #n:カードの残り枚数、last:前の手番が最後に引いたスコア、turn: 0先手の番 1後手の番
    #print "func(",n,",",last,",",turn,")"
    if (n,turn) in memo:
        return memo[(n,turn)]
    if n==1:
        ret=abs(last-A[N-n])
    elif turn==0:
        ret=max( func(n-1,last,0) , func(n-1,A[N-n],1) ) #手番がXのまま  手番がYに移動
    elif turn==1:
        ret=min( func(n-1,last,1) , func(n-1,A[N-n],0) ) #手番がYのまま  手番がXに移動
    memo[(n,turn)]=ret
    return ret


print func(N,Y,0)

Measured memory_bytes: 4712
def examA():
    N = I()
    A = LI()
    d = defaultdict(int)
    d[0] = 1; cur = 0
    for i in A:
        cur +=i
        d[cur] +=1
#    print(d)
    ans = 0
    for i in d.values():
        ans +=i*(i-1)//2
    print(ans)
    return


import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examA()


Measured memory_bytes: 103372
#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() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;
    vector<int> v(N);
    int ans = 0;
    rep(i, N) cin >> v[i];
    int mins = 1e9;
    for(int i = 1; i <= N; i++) {
        if(v[i-1] < mins){
            mins = min(mins, v[i - 1]);
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = (ll)1e9+7;
ll n;

int main(){
    cin >> n;
    if(n==1) cout << 0;
    else if(n==2) cout << 2;
    else{
        ll t=1LL; ll e=1LL; ll ni=1LL;
        for(int i=0; i<n; i++){
            e*=8; e%=mod;
            ni*=9; ni%=mod;
            t*=10; t%=mod;
        }
        t-=ni; t-=ni; t+=e; t%=mod; t+=mod; t%=mod; cout << t;
    }
}


Measured memory_bytes: 3556
#ALDS1_1-A
def print_A(A,N):
    stri = ""
    for i in range(N-1):
        stri+=str(A[i])+" "
    stri+=str(A[N-1])
    print(stri)

def insertionSort(A,N):
    for i in range(N-1):
        v=A[i+1]
        j=i
        while j>=0 and A[j]>v:
            A[j+1]=A[j]
            j-=1
        A[j+1]=v
        print_A(A,N)

N=int(input())
A=[int(x) for x in input().split()]
print_A(A,N)
insertionSort(A,N)

Measured memory_bytes: 7624
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<stack>
#include<bitset>
#include<vector>
#include<algorithm>
#include<iostream>
#include<deque>
using namespace std;
namespace mine
{
	typedef long long ll;
	#define double long double
	const int INF=0x3f3f3f3f;
	const ll LLINF=0x3f3f3f3f3f3f3f3fll;
	ll qread()
	{
		ll ans=0;char c=getchar();int f=1;
		while(c<'0' or c>'9') {if(c=='-') f=-1;c=getchar();}
		while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
		return ans*f;
	}
	void write(ll num)
	{
		if(num<0) {num=-num;putchar('-');}
		if(num>9) write(num/10);
		putchar('0'+num%10);
	}
	void write1(ll num){write(num);putchar(' ');}
	void write2(ll num){write(num);puts("");}
	#define FR first
	#define SE second
	#define MP make_pair
	#define pr pair<ll,int>
	#define PB push_back
	#define vc vector
	void chmax(int &x,const int y) {x=x>y?x:y;}
	void chmin(int &x,const int y) {x=x<y?x:y;}
	const int MOD=998244353;
	void add(int &x,int y){x+=y;if(x>=MOD) x-=MOD;if(x<=-MOD) x+=MOD;}
	ll qpower(ll x,ll e)
	{
		ll ans=1;
		while(e)
		{
			if(e&1) ans=ans*x%MOD;
			x=x*x%MOD;e>>=1;
		}
		return ans;
	}
	ll inv(ll x){return qpower(x,MOD-2);}
	const int MAX_N=1e4+10;

	int n,a[MAX_N];
	bool check(int p)
	{
		for(int t=0;t<p-1;t++)
		{
			ll sum=0;for(int i=t;i<=n;i+=p-1) sum=(sum+a[i])%p;
			if(sum) return 0;
		}
		return 1;
	}
	
	bool isp(int n)
	{
		for(int i=2;i*i<=n;i++) if(n%i==0) return 0;
		return 1;
	}
	int gcd(int x,int y){return y==0?x:gcd(y,x%y);}
	vc<int> ans;
	void main()
	{
		n=qread();int d=0;for(int i=n;i>=0;i--) a[i]=qread(),d=gcd(d,abs(a[i]));
		for(int i=2;(ll)i*i<=d;i++) if(d%i==0)//debug 爆int
		{
			ans.PB(i);
			while(d%i==0) d/=i;
		}
		if(d>1) ans.PB(d);
		for(int i=2;i<=n;i++) if(a[0]%i==0 and isp(i) and check(i)) ans.PB(i);
		sort(ans.begin(),ans.end());
		for(int t=0;t<(int)ans.size();t++) if(t==0 or ans[t-1]!=ans[t]) write2(ans[t]);//debug
	}
};
signed main()
{
	//freopen("a.in","r",stdin);
	srand(time(0));
	mine::main();
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=1;i++)
	{
		cout<<a[n]-a[1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long; using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>; using vvi = vector<vector<int>>;
using vl = vector<ll>; using vvl = vector<vector<ll>>;
using pii = pair<int,int>; using pll = pair<ll,ll>;
#define FOR(i,a,b) for(ll i = (a); i < (ll)(b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define eb(val) emplace_back(val)
const double PI = acos(-1);
const double EPS = 1e-10;
const ll MOD = 1e9+7;
//#define int ll
void cioacc(){//accelerate cin/cout
  cin.tie(0);
  ios::sync_with_stdio(false);
}
struct segment_tree{
  //dataはこの二分木の本体で、各ノードの値を持っている
  //data[i]に対し、data[(i-1)/2]は親であり、
  //逆にdata[2*i+1],data[2+i+2]は子である。
  vl data;
  //funcはこの木で用いられるモノイドである。
  //モノイドとは単位元を持つ2項演算のこと。
  function<ll(ll,ll)> func;
  //nはdataのサイズ決定に関わる変数
  //nはdataの葉ノードのサイズ
  //但し、二分木の葉の性質から、nは2の冪乗でなければならない。
  //data全体のサイズは2*n+1
  ll n,
  //identitiyはfuncに対する単位元
  identity;
  //下はこのstructのコンストラクタ
  //sizeは計算区間の最大の幅(元の問題の区間)
  //このsizeによりも、この木の葉ノードの数は多い必要がある。
  //idは単位元,fはモノイドである
  segment_tree(ll size,ll id,function<ll(ll,ll)> f):func(f),identity(id){
    //2^n>=sizeとなる最初の2の冪乗nを探す
    //これが葉ノードのサイズである
    n = 1;
    while(n<size) n*=2;
    data.assign(2*n+1,id);
  }
  //update(i,x)でi番目の値をxに更新し、
  //その後、木の根の方まで更新する。
  void update(ll i,ll x){
    data[i+=n-1]=x;//data[i+n-1]がi番目の葉ノード
    while(i>0){
      i = (i-1)/2;//親ノードに移動
      data[i]=func(data[2*i+1],data[2*i+2]);//各子ノードの2項演算でそのノードを更新
    }
  }
  void update2(ll i,ll x){
    i += n-1;
    data[i]=func(data[i],x);//data[i+n-1]がi番目の葉ノード
    while(i>0){
      i = (i-1)/2;//親ノードに移動
      data[i]=func(data[2*i+1],data[2*i+2]);//各子ノードの2項演算でそのノードを更新
    }
  }
  //find(a,b)で区間[a,b)における二項演算の結果を返す
  //根から葉に向かって実行する
  ll find(ll a,ll b,ll k=0,ll l=0,ll r=-1){
    //区間[l,r)は現在見ている値が受け持つ探索範囲
    //data[k]は現在見ている値
    //イメージは[a,b)に完全に収まる、ないし完全に外に出るまで探索区間を分割していく感じ
    if(r<0) r = n;//最初は左端から右端まで
    if(r<=a||b<=l) return identity;//探索範囲[l,r)が区間[a,b)外の時、単位元を返す。
    if(a<=l&&r<=b) return data[k];//探索範囲[l,r)が区間[a,b)内の時、今の値を返す。
    //どちらでもない時、子同士をfuncで演算した結果を返す。
    ll vl = find(a,b,2*k+1,l,(l+r)/2);//左の子ノードに移動
    ll vr = find(a,b,2*k+2,(l+r)/2,r);//右の子ノードに移動
    return func(vl,vr);
  }
};
struct range_add_query{
  segment_tree rsq;
  range_add_query(ll size):rsq(size+1,0,[](ll a,ll b)->ll{return a+b;}){}
  void add(ll s,ll t,ll x){
    rsq.update2(s,x);
    rsq.update2(t,-x);
  }
  ll get(ll a){
    return rsq.find(0,a+1);
  }
};
signed main(){
  ll n,q;
  cin >> n >> q;
  range_add_query rsq(n);
  REP(i,q){
    bool com;
    cin >> com;
    if(!com){
      ll s,t,x;
      cin >> s >> t >> x;
      s--;
      rsq.add(s,t,x);
    }else{
      ll i;
      cin >> i;
      --i;
      cout << rsq.get(i) << endl;
    }
  }
}




Measured memory_bytes: 4892
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
  string s, answer;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0') answer.push_back('0');
    if (s[i] == '1') answer.push_back('1');
    if (s[i] == 'B') {
      if (answer.length() == 0)
        continue;
      else
        answer.pop_back();
    }
  }

  cout << answer << endl;
}


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

int main() {
  string s, t;
  cin >> s;
  int a = s.size();
  rep(i,a) t += 'x';
  cout << t << endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n'
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
	ll n;
	ll x[105], y[105];
	ll h[105];
	ll i, j, k;
	cin>>n;
	FOR0(i, n)
	{
		cin>>x[i]>>y[i]>>h[i];
	}
	ll ax, ay, ah;
	int flag;
	FOR0(i, 101)
	{
		FOR0(j, 101)
		{
			ll H;
			ll dx, dy;
			FOR0(k, n)
			{
				if(h[k]!=0)
				{
					dx = llabs(i - x[k]);
					dy = llabs(j - y[k]);
					H = h[k] + dx + dy;
					if(H>=1)
						break;
					else 
						continue;
				}
			}
			flag = 1;
			FOR0(k, n)
			{
				dx = llabs(i - x[k]);
				dy = llabs(j - y[k]);
				if(h[k]!=0&&h[k] + dx + dy != H)
				{
					flag = 0;
					break;
				}
				else if(h[k]==0 && dx + dy < H)
				{
					flag = 0;
					break;
				}
			}
			if(flag)
			{
				ax = i;
				ay = j;
				ah = H;
				break;
			}
		}
		if(flag)
			break;
	}
	cout<<ax<<" "<<ay<< " "<< ah;
}


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

#define EQ(a,b) (abs((a)-(b)) < EPS)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define sz size()
#define all(a) (a).begin(),(a).end()

using namespace std;
typedef long double D;
typedef complex<D> P;
typedef pair<P,P> L;
typedef vector<P> Poly;
typedef pair<P,D> C;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<D,int> pdi;

const D EPS = 1e-10;
const D PI = acos(-1);

namespace std{
  bool operator<(const P &a,const P &b){
    return EQ(real(a),real(b))?imag(a)<imag(b):real(a)<real(b);
  }
  bool operator==(const P &a, const P &b){return EQ(a,b);}
}

//for vector
inline P unit(P p){return p/abs(p);}

inline pair<P,P> norm(P p){return make_pair(p*P(0,1),p*P(0,-1));}

inline D dot(P x, P y){return real(conj(x)*y);}

inline D cross(P x, P y){return imag(conj(x)*y);}

//rotate a point counter-clockwise on the origin
inline P rotate(P v, D s){
  return P(real(v)*cos(s) - imag(v)*sin(s), real(v)*sin(s) + imag(v)*cos(s) );
}

//for line(segment)
int ccw(P a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 1;   //counter clockwise
  if (cross(b,c)<-EPS) return -1; //clockwise
  if (dot(b, c)<-EPS) return 2;   //c--a--b on line
  if (abs(b)+EPS<abs(c)) return -2;   //a--b--c on line
  return 0;                       //on segment
}

inline bool orth(L a,L b){return abs(dot(a.fs-a.sc,b.fs-b.sc))<EPS;}

inline bool para(L a,L b){return abs(cross(a.fs-a.sc,b.fs-b.sc))<EPS;}

inline D line_dis(L a,P x){return abs(cross(a.sc-a.fs,x-a.fs))/abs(a.sc-a.fs);}

inline P line_cp(L a,L b){
  return a.fs+(a.sc-a.fs)*cross(b.sc-b.fs,b.fs-a.fs)/cross(b.sc-b.fs,a.sc-a.fs);
}

inline D seg_p_dis(L a,P x){
  if(dot(a.sc-a.fs,x-a.fs)<EPS)return abs(x-a.fs);
  if(dot(a.fs-a.sc,x-a.sc)<EPS)return abs(x-a.sc);
  return abs(cross(a.sc-a.fs,x-a.fs))/abs(a.sc-a.fs);
}

inline D seg_seg_dis(L a,L b){
  D res = 1e10;
  res = min(res,seg_p_dis(a,b.fs));
  res = min(res,seg_p_dis(a,b.sc));
  res = min(res,seg_p_dis(b,a.fs));
  res = min(res,seg_p_dis(b,a.sc));
  return res;
}

int main(){
  int n[2];
  P p[2][100];
  L l[2][100];

  rep(i,2){
    cin >> n[i];
    rep(j,n[i]){
      int x,y;
      cin >> x >> y;
      p[i][j] = P(x,y);
      if(j==0)l[i][j] = L(P(0,1000*i), p[i][j]);
      else l[i][j] = L(p[i][j-1], p[i][j]);
    }
    l[i][n[i]] = L(p[i][n[i]-1], P(1000,1000*i));
  }

  D ans = 1e5;
  rep(i,n[0]+1){
    rep(j,n[1]+1){
      ans = min(ans, seg_seg_dis(l[0][i], l[1][j]));
    }
  }

  cout << fixed << setprecision(10) << ans << endl;
}

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

using ll = long long;
using ld = long double;

const int N = 1e5 + 69;

int r, c, n;
vector<pair<int, int>> sisi[5];
int cnt[N], lol[N];
stack<int> st;

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

  cin >> r >> c >> n;
  for(int i = 1; i <= n; i++) {
    for(int j = 0; j < 2; j++) {
      int x, y;
      cin >> x >> y;
      if(y == 0 && x < r) {
        sisi[1].emplace_back(x, i);
      } else if(x == r && y < c) {
        sisi[2].emplace_back(y, i);
      } else if(y == c && x > 0) {
        sisi[3].emplace_back(x, i);
      } else if(x == 0 && y > 0) {
        sisi[4].emplace_back(y, i);
      }
    }
  }
  for(int i = 1; i <= 4; i++) {
    if(i <= 2) {
      sort(sisi[i].begin(), sisi[i].end());
    } else {
      sort(sisi[i].begin(), sisi[i].end());
      reverse(sisi[i].begin(), sisi[i].end());
    }
  }
  for(int i = 1; i <= 4; i++) {
    for(auto j : sisi[i]) {
      cnt[j.second]++;
    }
  }
  bool ok = true;
  for(int i = 1; i <= 4; i++) {
    for(auto j : sisi[i]) {
      if(cnt[j.second] < 2)
        continue;
      if(lol[j.second] == 0) {
        st.push(j.second);
        lol[j.second] = 1;
      } else {
        if(!st.empty() && st.top() != j.second) {
          ok = false;
          break;
        } else {
          st.pop();
        }
      }
    }
    if(!ok)
      break;
  }
  cout << (ok ? "YES" : "NO") << '\n';
  return 0;
}

Measured memory_bytes: 6068
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  string s; cin>>s;
  string ans;
  for(int i = 0; i < (int)s.size(); i++) {
    if(i % 2 == 0) {
      ans += s[i];
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=1LL<<60;
const double EPS = 1e-10;
const ll mod=1000000007;
//const ll mod=998244353;
vector<ll> v[100010];
ll dp[100010][2]={};
ll dfs(ll i,ll par,ll color){
    if(dp[i][color]!=0) return dp[i][color];
    dp[i][color]=1;
    for(auto x:v[i]){
        if(x==par) continue;
        if(color==0) dp[i][color]*=(dfs(x,i,0)+dfs(x,i,1));
        if(color==1) dp[i][color]*=dfs(x,i,0);
        dp[i][color]%=mod;
    }
    return dp[i][color];
}

int main(void){
    ll n;
    cin>>n;
    for(int i=0;i<n-1;i++){
        ll x,y;
        cin>>x>>y;
        x--,y--;
        v[x].push_back(y);
        v[y].push_back(x);
    }
    cout<<(dfs(0,-1,0)+dfs(0,-1,1))%mod<<endl;
}

Measured memory_bytes: 19052
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100009;
int dp[102][102][302];
int n,W;
int w[102],v[102];
int offset=0;
int Magic(int pos,int cnt,int sum)
{
    if(pos>n)
    {
        int wgt=(cnt*offset)+sum;
        if(wgt<=W)return 0;
        else return -inf;
    }
    int &ret=dp[pos][cnt][sum];
    if(ret!=(-1))return ret;
    ret=Magic(pos+1,cnt,sum);
    ret=max(ret,v[pos]+Magic(pos+1,cnt+1,sum+w[pos]));
    return ret;
}
 main()

{
    fast
    memset(dp,-1,sizeof dp);
    cin>>n>>W;
    f(i,1,n)
    {
        cin>>w[i]>>v[i];
    }
    offset=w[1];
    f(i,1,n)
    {
       w[i]-=offset;
    }
    cout<<Magic(1,0,0)<<endl;
    return 0;

}





































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

ll X,K,D;

int main(){
	cin>>X>>K>>D;
	X=abs(X);
	if(X/D<=K){
		K-=X/D;
		X%=D;
		if(K&1){
			cout<<abs(X-D)<<endl;
		}
		else{
			cout<<X<<endl;
		}
	}
	else{
		cout<<X-K*D<<endl;
	}
}


Measured memory_bytes: 3672