akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

/* originally written by SugarDragon5 */
struct UnionFind{
    vi data;
    UnionFind(int size):data(size,-1){}
    bool unite(int x,int y){
        x=root(x);y=root(y);
        if(x!=y){
            if(data[y]<data[x])swap(x,y);
            data[x]+=data[y];data[y]=x;
        }
        return x!=y;
    }
    bool find(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0?x:data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};

int main() {
    int a = ri();
    int b = ri();
    int res = (b<a)?a-1:a;
    cout << res << endl;

 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define RSORT(x) sort((x).rbegin(), (x).rend())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N,K;
    cin>>N>>K;
    ll x=N%K;
    ll y=K-x;
    cout<< min(x,y) <<"\n";


}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

#pragma region
typedef long long ll;
#define MEM(a, b) memset(a, (b), sizeof(a))
#define rep(i, begin, end)                              \
    for (__typeof(end) i = (begin) - ((begin) > (end)); \
         i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define REP(i, j) rep(i, 0, j)
#define testcase \
    int _;       \
    cin >> _;    \
    while (_--)
#define io                            \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    if (fopen("./input.txt", "r")) freopen("./input.txt", "r", stdin);
#define en '\n'
#pragma endregion

int main() {
    io;
    int n;
    cin >> n;
    if (n % 1000) {
        cout << 1000 - (n % 1000);
    } else {
        cout << 0;
    }
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <complex>
#include <cmath>
#include <vector>

using namespace std;

typedef complex<double> xy_t;

vector< xy_t> v;

double heron(xy_t p1, xy_t p2, xy_t p3){
    double a = abs(p2-p1);
    double b = abs(p3-p2);
    double c = abs(p1-p3);
    double s = (a+b+c)/2;
    return sqrt(s*(s-a)*(s-b)*(s-c));
}

int main(){
    double x,y;
    char c;
    while(cin >> x >> c >> y){
        complex<double> tmp(x,y);
        v.push_back(tmp);
    }
    double sum = 0;
    for(int i=1;i<v.size()-1;i++){
        sum += heron(v[0],v[i],v[i+1]);
    }
    cout << sum << endl;
}

Measured memory_bytes: 1304
main = do
    [n,x] <- map read . words <$> getLine
    print $ solve n x

solve 0 0 = 0
solve 0 _ = 1
solve n x | x == 1 = 0
          | x <= 1 + a = solve (n-1) (x-1)
          | x == 2 + a = b + 1
          | x <= 2 + 2 * a = b + 1 + solve (n-1) (x-2-a)
          | x == 3 + 2 * a = 2*b+1
     where f 0 = 1
           f l = 2 * f (l-1) + 3
           p 0 = 1
           p l = 2 * p (l-1) + 1
           a = f (n-1)
           b = p (n-1)

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

int main(){
    int W, H, x, y, r, flag = 0;
    cin >> W >> H >> x >> y >> r;
    if(x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H) flag = 1;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3100
/**
 * Created by yoshiwaratomohiro on 2017/06/18.
 */
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int H=scan.nextInt();
        int W=scan.nextInt();
        int h=scan.nextInt();
        int w=scan.nextInt();

        int area=h*w;
        int[][] box = new int[H][W];
        long sum=0;

        int INF=1000000000;

        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                if(i%h==h-1&&j%w==w-1){
                    box[i][j]=INF*-1;
                }else{
                    if(i%h==0&&j%w==0){
                        box[i][j]=INF-area+1;
                    }else{
                        box[i][j]=1;
                    }

                }
                sum+=box[i][j];

            }

        }
        if(sum>0){
            System.out.println("Yes");
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    System.out.print(box[i][j]);
                    if(j<W-1){
                        System.out.print(" ");
                    }
                }
                System.out.println("");
            }

        }else{
            System.out.println("No");
        }
    }
}


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

int x, s, t;

int main()
{
	cin >> x;

	s = x / 100;
	t = x % 100;

	if (s > t / 5 || s * 5 == t)
		cout << 1 << endl;
	else
		cout << 0 << endl;

	return 0;
}

Measured memory_bytes: 256
from sys import exit
H, W = map(int, input().split())
slist = [["."] * (W + 2), ]
for _ in range(H):
    line = list(input())
    line.insert(0, ".")
    line.append(".")
    slist.append(line)
slist.append(["."] * (W + 2))
points = ((0, -1), (0, 1), (-1, 0), (1, 0))
flg = True
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if slist[i][j] == "#":
            counter = 0
            for x, y in points:
                if slist[i - x][j - y] == "#":
                    counter += 1
                    break
            else:
                print("No")
                exit()
print("Yes")


Measured memory_bytes: 3064
# https://atcoder.jp/contests/abc136/tasks/abc136_c

N = gets.to_i
Hs = gets.split.map(&:to_i)

cond = true
(N - 2).downto(0) do |i|
  d = Hs[i + 1] - Hs[i]
  cond = false if d < -1
  Hs[i] -= 1 if d == -1
end

puts cond ? 'Yes' : 'No'


Measured memory_bytes: 8580
#include <stdio.h>
#include <string.h>
//https://www.khanacademy.org/computing/computer-science/algorithms
//http://www.toi2015.sat.psu.ac.th/files/news/?¢???????¢????????????????-TOI11.pdf
int main(){
	int a;
	scanf("%d",&a);
	printf("%d\n",a*a*a);
	return 0;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;


int main(){
  ll n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];


  rep(i, n) sort(all(s[i]));

  map<string, ll> ma;
  rep(i, n) ma[s[i]]++;

  ll sum = 0;

  for(auto x : ma) sum += x.second*(x.second-1)/2;


  cout << sum << endl;


  return 0;
}



Measured memory_bytes: 16640
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long 


using namespace std;

int MOD = 1000000007;
int main(){
  int n;
  int k;
  cin >> n >> k;
  vector<ll> a(n+1);
  for( int i = 0 ; i < n ; i++ ){
    cin >> a[i];	  
  }
  vector<vector<ll>> dp(n+100,vector<ll> (k+100,0));
  for( int i = 0 ; i <= a[0] ; i++ ) dp[0][i] = 1;
  for( int i = 1 ; i < n ; i++ ){
    for( int j = 0 ; j <= k ; j++ ){
      if( j <= a[i] ){//[0,a[i]]
        if( j == 0 ) dp[i][j] = dp[i-1][j];
        else{
          dp[i][j] = (dp[i][j-1] + dp[i-1][j]) % MOD;
        }
      }
      else{
        dp[i][j] = (dp[i][j-1]  - dp[i-1][j-a[i]-1] + MOD + dp[i-1][j] ) % MOD;
      }
    }
  }
///  for( int i = 0 ; i < n ; i++ ){
///    for( int j = 0 ; j <= k ; j++ ){
///      cout << dp[i][j] << " " ;
///    }
///    cout << endl;
///  }
  //cout << dp[n-1][k]  << endl;
  cout << dp[n-1][k] % MOD   << endl;
  return 0;
}


Measured memory_bytes: 159088
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6,inf=1e9;
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  char c;cin>>c;
  char d=c+1;cout<<d<<endl;
  
  return 0;
}

Measured memory_bytes: 764
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T3;
const int INF = 1000000000;

int main(){
	ll n,m;
	cin >> n >> m;
	vector<pair<ll,ll>> ab;
	for(ll i = 0;i < n;i++){
		ll a,b;
		cin >> a >> b;
		ab.push_back(make_pair(a,b));
	}

	sort(ab.begin(),ab.end());

	ll ans = 0;
	for(ll i = 0;i < n;i++){
		ll a = ab[i].first;
		ll b = ab[i].second;
		ll plus = min(m,b);
		if(plus == 0)break;
		ans += a * plus;
		m -= plus;
	}

	cout << ans << endl;
}


Measured memory_bytes: 2420
//@Author- sitanshu
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair 
#define mii map<int, int>
#define umii unordered_map<int, int>
#define vi vector<int>
#define vl vector<ll>
#define clr(val) memset(val,0,sizeof(val))
const ll MAX = 1000009, MOD = 1e9 + 7;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);


void solve()
{
    int n;
    cin >> n;
    int arr[n], dp[n];
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        if (i == 0)
        dp[i] = 0;
        else if (i == 1)
        dp[i] = abs(arr[i]-arr[i-1]);
        else
        {
            dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));
        }
        
    }   

    cout << dp[n-1] << endl;
}



int main()
{
    //OJ;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    t = 1;
    while(t--)
    {
        solve();
    }  
    return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long
#define MOD (int)(1e9+7)
#define ceil(x, y) (x%y==0? (x/y) : (x/y+1))
#define FOR(i, N) for(int i = 0; i < N; ++i)
#define FOR1(i, N) for(int i = 1; i <= N; ++i)
#define vi vector <int>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mset(a, v) memset(a, v, sizeof(a))
#define all(v) (v).begin(), (v).end()
#define INF 2e18
#define EPS 1e-9
#define MAX 200009
#define int long long
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef cc_hash_table<int, int, hash<int>> ht; // while using, comment #define int long long  */

void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
using namespace std;
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    	freopen("in2.txt", "r", stdin);
    	freopen("out.txt", "w", stdout);
    #endif

	int T=1;
	//cin >> T;
	FOR1(tt, T)
	{
		//cout << "Case #" << tp << ": ";
		int h, w, k;
		cin >> h >> w >> k;
		char m[h][w];
		FOR(i, h){
			string s; cin >> s;
			FOR(j, w){
				m[i][j] = s[j];
			}
		}

		char copy[h][w];
		int ans = 0;

		for(int ci = 0; ci < (1<<h); ci++){
			for(int cj = 0; cj < (1<<w); cj++){
				// only last 6 bits matter atmost
				// dbg(ci, cj);
				FOR(i, h){
					FOR(j, w){
						copy[i][j] = m[i][j];
					}
				}

				for(int i = 0; i < h; i++){
					if(ci & (1 << i)){
						// i-th row is chosen
						for(int j = 0; j < w; j++) copy[i][j] = '!'; // red
					}
				}

				for(int j = 0; j < w; j++){
					if(cj & (1 << j)){
						// j-th col is chosen
						for(int i = 0; i < h; i++) copy[i][j] = '!';
					}
				}

				// both row and col marked
				int black = 0;
				FOR(i, h){
					FOR(j, w){
						if(copy[i][j] == '#') black++;
					}
				}
				if(black == k) ans++;

			}
		}
		cout << ans;
		cout<<'\n';
	}
	return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
int main() {
  int n;
  cin >> n;
  int zero = 0;
  map<pair<ll,ll>,P> mp;
  rep(i,n) {
    ll x, y;
    cin >> x >> y;
    if (x == 0 && y == 0) {
      zero++;
      continue;
    }
    ll g = gcd(x,y);
    x /= g;
    y /= g;
    if (y < 0) x = -x, y = -y;
    if (y == 0 && x < 0) x = -x, y = -y;
    bool rot90 = (x <= 0);
    if (rot90) {
      ll tmp = x;
      x = y; y = -tmp;
    }
    if (rot90) mp[{x,y}].first++;
    else mp[{x,y}].second++;
  }
 
  mint ans = 1;
  for (auto p : mp) {
    int s = p.second.first;
    int t = p.second.second;
    mint now = 1;
    now += mint(2).pow(s) - 1;
    now += mint(2).pow(t) - 1;
    ans *= now;
  }
  ans -= 1;
 
  ans += zero;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 16132
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>

using namespace std;
using ll = long long;
using ld = long double;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll a, b, c;
  cin >> a >> b >> c;

  if((c - a - b) >= 0 && a * b * 4 < (c - a - b)*(c - a - b)) cout << "Yes" << endl;
  else cout << "No" << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 256
package main

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

type Alds14d struct {
	packet []int
}

func main() {
	a := &Alds14d{}
	a.main()
}

func NewAlds14d() *Alds14d {
	a := &Alds14d{}
	return a
}

func (a *Alds14d) main() {
	scanner := bufio.NewScanner(os.Stdin)
	fmt.Println(a.solve(scanner))
}

// can load in k tracks of capacity P that can carry n packet
func (a *Alds14d) calcMaxPacketNumber(P, k, n int) int {
	// packet num
	i := 0

	// 1. トラックごとに
	// per track
	for j := 0; j < k; j++ {

		// total of weight
		s := 0

		// 2. 詰めるだけpacketを積む
		for s+a.packet[i] <= P {
			s += a.packet[i]

			i++

			// 3. パケットの最大数までたどりついたらおわり
			// end of packet num
			if i == n {
				// can load n packet
				return n
			}
		}
	}

	// 4. 最大までたどり着かなかったら、途中までの個数が積むことができた個数
	return i
}

func (a *Alds14d) solve(scanner *bufio.Scanner) int {

	scanner.Split(bufio.ScanWords)
	scanner.Scan()
	n, _ := strconv.Atoi(scanner.Text())

	scanner.Scan()
	k, _ := strconv.Atoi(scanner.Text())

	a.packet = make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		a.packet[i], _ = strconv.Atoi(scanner.Text())
	}

	// over limit
	//capacity := 0
	//for {
	//	capacity++
	//
	//	num, valid := a.calcRequiredNumber(capacity, n)
	//	if ! valid {
	//		continue
	//	}
	//	if num <= k {
	//		break
	//	}
	//}

	left := 1
	right := 100000 * 100000
	mid := (left + right) / 2
	for right-left > 0 {
		num := a.calcMaxPacketNumber(mid, k, n)

		if n == num {
			// 必要な個数を乗せることができるので、Pを下げて検索
			// i == nの判定を行っているので、numがnを超えることはない
			right = mid
		} else {
			// Pが不足するので、より大きい値で検索
			left = mid + 1
		}

		mid = (left + right) / 2
	}

	return mid
}



Measured memory_bytes: 2336
n = gets.split.map(&:to_i)
gate = [1,n[0]]
for i in 0..n[1]-1
  inst = gets.split.map(&:to_i)
  if inst[0] > gate[0]
    gate[0] = inst[0]
  end
  if inst[1] < gate[1]
    gate[1] = inst[1]
  end
end
puts [gate[1]-gate[0]+1,0].max


Measured memory_bytes: 3836
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = SS()

    if S.count('x') <= 7:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    resolve()


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

int main() {
    string S;
    long long K;
    cin>>S>>K;
    string SS=S+S;
    int S_num=0;
    int SS_num=0;
    int sflug=1, ssflug=1;
    bool onazi=false;
    rep(i,S.size()-1){
        if(S[i]==S[i+1]){
            sflug++;
        }else{
            S_num+=sflug/2;
            sflug=1;
        }
    }
    if(S.size()==sflug){
        onazi=true;
    }
    S_num+=sflug/2;

    rep(i,SS.size()-1){
        if(SS[i]==SS[i+1]){
            ssflug++;
        }else{
            SS_num+=ssflug/2;
            ssflug=1;
        }
    }
    SS_num+=ssflug/2;

    long long ans = S_num+(SS_num-S_num)*(K-1);
    if(onazi){
        cout << (S.size()*K)/2<<endl;
    }else{
        cout <<ans<<endl;
    }
}
//2053-

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

const int N = 1e5 + 100;
#define int long long

int n, m, x[N], a[N];
int s[N], p[N];
int tot, k;
int bel[N], dep[N];
int vis[N];
vector <int> v[N];

void dfs(int u, int depth) {
  dep[u] = depth;
  vis[u] = 1;
  bel[u] = tot;
  v[tot].push_back(u);
  if (!vis[p[u]]) {
    dfs(p[u], depth + 1);
  }
}

signed main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%lld", &x[i]);
  }
  for (int i = 1; i < n; i++) {
    s[i] = x[i + 1] - x[i];
    p[i] = i;
  }
  scanf("%lld %lld", &m, &k);
  for (int i = 1; i <= m; i++) {
    scanf("%lld", &a[i]);
    swap(p[a[i]], p[a[i] - 1]);
  }
  for (int i = 1; i < n; i++) {
    if (vis[i] == 0) {
      tot++;
      dfs(i, 0);
    }
  }
  printf("%lld\n", x[1]);
  int cur = x[1];
  for (int i = 1; i < n; i++) {
    cur += s[v[bel[i]][(dep[i] + k) % v[bel[i]].size()]];
    printf("%lld\n", cur);
  }
  return 0;
}

Measured memory_bytes: 13044
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdlib.h>
#include<set>

using namespace std;

int main(void)
{
    int N;
    cin>>N;
    long int a[N+1],b[N];
    for(int i=0;i<N+1;i++){
        cin>>a[i];
    }
    for(int i=0;i<N;i++){
        cin>>b[i];
    }
    
    long int sum=0;
    
    for(int i=0;i<N;i++){
        if(a[i]<=b[i]){
            sum+=a[i];
            long int rest=b[i]-a[i];
            if(a[i+1]<=rest){
                sum+=a[i+1];
                a[i+1]=0;
            }
            else{
                sum+=rest;
                a[i+1]-=rest;
            }
        }
        else{
            sum+=b[i];
        }
    }
    cout<<sum<<endl;
    
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <regex>
#include <utility> // pair
#include <algorithm> // swap
#include <numeric> // accumulate
#include <cmath> // pow
#include <iomanip> // setprecision
#include <sstream> // stringstream
using namespace std;

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

signed main() {
  string str;
  cin >> str;
  int len = str.length();
  int patterns = 1 << (len-1);
  long long sum = 0;
  rep(i, patterns) {
    string s(str);
    string buf = "";
    rep(j, len) {
      buf += s[j];
      if(((i>>j)&1) == 1) {
        sum += stoll(buf);
        buf = "";
      }
    }
    if(!buf.empty()) {
      sum += stoll(buf);
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 504
class MultiSet:
    def __init__(self, n):
        self.N = n
        self.n = 1<<n.bit_length()
        self.data = [0] * (self.n + 1)
        self.num = 0
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):#iをx個追加
        while i <= self.n:
            self.data[i] += x
            i += i & -i
        self.num+=1
    def search(self, k):#k番目の数を取得
        if k<1:
            return 0
        if k >self.num:
            return self.N+1
        x,sx = 0,0
        step = self.n
        while step:
            y = x+step
            sy = sx+self.data[y]
            if sy < k:
                x,sx = y,sy
            step >>= 1
        return x+1
    def show(self):#debug用
        res = []
        for i in range(1, self.N+1):
            c = self.sum(i)-self.sum(i-1)
            for _ in range(c):
                res.append(i)
        return res
class BIT:
    def __init__(self, n):
        self.N = n
        self.n = 1<<n.bit_length()
        self.data = [0] * (self.n + 1)
        self.S = 0
        
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def add(self, i, x):
        self.S+=x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
import bisect
Q = int(input())
compress_list = []
query = []
for _ in range(Q):
    c, *ab = map(int, input().split())
    if c == 1:
        a, b = ab
        compress_list.append(a)
        query.append((c, a, b))
    else:
        query.append([c])
compress_list.sort()
M = MultiSet(len(compress_list))
B = BIT(len(compress_list))
S = 0
for q in query:
    if q[0] == 1:
        a, b = q[1], q[2]
        S+=b
        i = bisect.bisect_right(compress_list, a)
        M.add(i, 1)
        B.add(i, a)
    else:
        if M.num%2 == 0:
            k = M.num//2
            i = M.search(k)
            n1 = M.sum(i-1)
            x = compress_list[i-1]
            s = B.S
            s1 = B.sum(i-1)+(k-n1)*x
            s2 = s-s1
            f = s2-s1+S
        else:
            k = M.num//2+1
            i = M.search(k)
            n1 = M.sum(i-1)
            x = compress_list[i-1]
            s = B.S
            s1 = B.sum(i-1)+(k-n1)*x
            s2 = s-s1
            f = s2-s1+x+S
        print(x, f)












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

using namespace std;

int main()
{
    int a,b;

    cin>>a;
    cin>>b;
    int arr[a];
    for(int i=0;i<a;i++){

        cin>>arr[i];
    }
    int sum=0;
    int cnt=1;
    for(int y=0;y<a;y++){

        sum=arr[y]+sum;
        if(sum<=b)
        {
            cnt++;
        }
    }
    cout<<cnt<<endl;



	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
using ll=long long;

const ll INF = pow(10,18)+1;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

template<typename T> bool chmin(T& a, T b) {return a > b ? a = b, true : false;}
template<typename T> bool chmax(T& a, T b) {return a < b ? a = b, true : false;}
 
int main(){
    int N, M;
    cin >> N >> M;
    int A[35][35];
    int K[35];
    REP(i,N){
        cin >> K[i];
        REP(j,K[i]){
            cin >> A[i][j];
        }
    }
    int ans = 0;
    FOR(k,1,31){
        int count = 0;
        REP(i,N){
            REP(j,K[i]){
                if(A[i][j]==k) count++;
            }
        }
        if(count==N) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{
    int A[7]={1,3,5,7,8,10,12},B[4]={4,6,9,11},C[1]={2},x,y;
    cin>>x>>y;

    int f=0;

    for(int i=0;i<7;i++){
        if(A[i]==x)f++;
        if(A[i]==y&&f==1){
            cout<<"Yes"<<endl;
            return 0;
        }
    }

    f=0;
    for(int i=0;i<4;i++){
        if(B[i]==x)f++;
        if(B[i]==y&&f==1){
            cout<<"Yes"<<endl;
            return 0;
        }
    }

    cout<<"No"<<endl;

    return 0;
}


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

const int N = 100 * 1000 + 5;
int n;

int a[N];


int bmm(int x, int y) {
	if (y == 0) {
		return x;
	}
	return bmm(y, x % y);
}

int solve() {
	//cout << "75 " << endl;
	int c = 0;
	long long s = 0;
	bool b = false;
	for (int i = 0; i < n; i++) {
		s += a[i];
		c += a[i] % 2;
		if (a[i] == 1) {
			b = true;
		}

	}
	if (n == 1) {
		if (a[0] == 1) {
			return 2;
		}
		else {
			return 1;
		}
	}
	if (s % 2 != n % 2) {
		return 1;
	}
	else {
		if (b || c != 1) {
			return 2;
		}
		else {
			int x = 0;
			for (int i = 0; i < n; i++) {
				if (a[i] % 2)
					a[i]--;
				x = bmm(x, a[i]);
			}
			for (int i = 0; i < n; i++) {
				a[i] /= x;
			}
			return 3 - solve();
		}
	}

}


int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	int ans = solve();
	if (ans == 1) {
		cout << "First";
	}
	else {
		cout << "Second";
	}


}


Measured memory_bytes: 4008
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int  d,  mx =0,c=0, ans = 0, i, j, x, y, x1, x2;
  string s, t;
  cin >> s >> t;
   for(i=0;i<=(s.size()-t.size());i++)
   {
    c=0;
    for(j=0;j<t.size();j++)
    {
       if(s[i+j]==t[j])  c++;
    }
    x=t.size()-c;
    mx=max(mx,c);
   }
   cout<<t.size()-mx<<endl;
}

Measured memory_bytes: 3596
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long h=sc.nextLong();
		int n=sc.nextInt();
		//long n=sc.nextLong(),y=sc.nextLong();
		long sum=0;
		for(int i=0;i<n;i++) {
			sum+=sc.nextInt();
		}
		if(sum>=h) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}


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

int main()
{
    int n, t, a, h[1000];
    scanf("%d", &n);
    scanf("%d%d", &t, &a);
    int i;
    double dtmin = 1e18;
    int ans = 0;
    for (i=0; i<n; i++)
    {
        scanf("%d", &h[i]);
        double dt = fabs(t - h[i]*0.006 - a);
        if (dt < dtmin) {
            dtmin = dt;
            ans = i + 1;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
n=int(input())
a=[int(i) for i in input().split()]
c=0
d=[]
for i in range(n):
    d.append(a[i]-i-1)
d.sort()
#print(d)
if n%2==1:
    b=d[int((n+1)/2)-1]
else:
    b=int(((d[int(n/2-1)]+d[int(n/2)]))/2)
for i in range(n):
    c=c+abs(a[i]-b-i-1)
#print(b)
print(c)


Measured memory_bytes: 25172
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < N; i++)
using namespace std;
int main()
{
    int N;
    cin >> N;
    vector<int> l(N), r(N);
    rep(i, N)
    {
        cin >> l[i] >> r[i];
    }
    int sum = 0;
    rep(i, N)
    {
        sum += (r[i] - l[i] + 1);
    }
    cout << sum << endl;
}


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

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int ans = 0;
    int lst = a[0];
    int cur = 0;
    for (int i = 1; i < n; i++) {
        if (a[i] <=  lst) {
            cur++;
        } else {
            ans = max(ans, cur);
            cur = 0;
        }
        lst = a[i];
    }
    ans = max(ans, cur);
    cout << ans;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
int N;
vector<i64> A;

vector<i64> sum;
int main(){
  cin >> N;
  A.resize(N + 1);
  sum.resize(N + 1,0);
  rep(i,1,N){
    cin >> A[i];
    sum[i] = sum[i - 1] + A[i];
  }

  i64 ans = -1;

  rep(i,2,N - 2){
    int lc;
    int rc;
    lc = lower_bound(sum.begin() + 1,sum.end(),sum[i] / 2) - sum.begin();
    rc = lower_bound(sum.begin() + 1,sum.end(),(sum[N] + sum[i]) / 2) - sum.begin();
    for(int l = max(lc - 1,0);l <= min(lc + 1,i - 1);l++){
      for(int r = max(rc - 1,i + 1);r <= min(rc + 1,N - 1);r++){
        vector<i64> a = {sum[l],sum[i] - sum[l],sum[r] - sum[i],sum[N] - sum[r]};
        sort(all(a));
        if(ans == -1){
          ans = a.back() - a.front();
        }
        else{
          ans = min(ans , a.back() - a.front());
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3328
import java.io.*;
import java.util.*;

class Main {

    int n, m, p;
    int dst[] = null;

    //sからeへの時計回り距離
    int CWDist ( int s, int e ) { return e - s < 0 ? e - s + n : e - s; }
    //sからeへの反時計回り距離
    int CCWDist ( int s, int e ) { return s - e < 0 ? s - e + n : s - e; }

    //時計回りで次の買い物場所
    int CWNext ( int i ) { return i == m-1 ? dst[0] : dst[i+1]; }
    //反時計回りで次の買い物場所
    int CCWNext ( int i ) { return i == 0 ? dst[m-1] : dst[i-1]; }

    //pからtへ時計回り tからeへ反時計回りで行ったときの距離
    int CWTurn ( int p, int t, int e ) { return CWDist( p, t ) + CCWDist( t, e ); }
    //pからtへ反時計回り tからeへ時計回りで行ったときの距離
    int CCWTurn ( int p, int t, int e ) { return CCWDist( p, t ) + CWDist( t, e ); }

    void solve(){

	Scanner sc = new Scanner(System.in);
	n = sc.nextInt();
	m = sc.nextInt();
	p = sc.nextInt();
	dst = new int[m];
	for ( int i=0; i<m; ++i ) dst[i] = sc.nextInt();
	Arrays.sort( dst );
	
	int s = 0;
	while ( s < m ) {
	    if ( dst[s] > p ) break;
	    ++s;
	}

	int cwNext  = s == m ? dst[0] : dst[s];
	int ccwNext = s == 0 ? dst[m-1] : dst[s-1];

	int dist = Math.min( CCWDist(p, cwNext), CWDist(p, ccwNext) );

	for ( int i=0; i<m; ++i ) {
	    dist = Math.min( dist, CWTurn(p, dst[i], CWNext(i)) );
	    dist = Math.min( dist, CCWTurn(p, dst[i], CCWNext(i)) );
	}

	System.out.println( 100*dist );

    }

    public static void main(String[] a) { new Main().solve(); }
}



Measured memory_bytes: 41404
using System;

namespace abc141B
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string N = Console.ReadLine();
            int m = N.Length;
            string temp = "";
            string Ans = "Yes";
            for(int n = 0; n <= m-1; n++)
            {
                temp = N.Substring(n, 1);
                if(n % 2 == 0 && temp == "L")
                {
                    Ans = "No";
                }
                if(n % 2 == 1 && temp == "R")
                {
                    Ans = "No";
                }
            }
            Console.WriteLine(Ans);
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
 
#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main() {
    int bingo[3][3];
    REP(i, 3) {
        REP(j, 3) {
            cin >> bingo[i][j];
        }
    }

    int N;
    cin >> N;
    REP(idx, N) {
        int tmp;
        cin >> tmp;

        REP(i, 3) {
            REP(j, 3) {
                if(bingo[i][j] == tmp) {
                    bingo[i][j] = -1;
                }
            }
        }
    }

    bool flag = false;
    REP(i, 3) {
        bool flag2 = true;
        REP(j, 3) {
            flag2 &= bingo[i][j] == -1;
        }

        flag |= flag2;
    }

    REP(i, 3) {
        bool flag2 = true;
        REP(j, 3) {
            flag2 &= bingo[j][i] == -1;
        }

        flag |= flag2;
    }

    flag |= bingo[0][0] == -1 && bingo[1][1] == -1 && bingo[2][2] == -1;
    flag |= bingo[2][0] == -1 && bingo[1][1] == -1 && bingo[0][2] == -1;

    cout << (flag ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char t;
int a,b;
int main()
{
    cin>>a>>b;
    for(int s=0;s<a;s++)
    {
        cin>>t;
        if(t<'0' || t>'9')
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cin>>t;
    if(t!='-')
    {
        cout<<"No"<<endl;
        return 0;

    }
    for(int i=0;i<b;i++)
    {
        cin>>t;
        if(t<'0' || t>'9')
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl; 
    return 0;
}

Measured memory_bytes: 256
import { readFileSync } from 'fs'

function permutation<T>(list: T[], n: number = list.length) {
  if (n === 0) return []
  if (n === 1) return list.map(v => [v])

  let result = [] as T[][]

  list.forEach((value, index) => {
    const otherValues = list.filter((_, i) => i !== index)
    const remainList = permutation(otherValues, n - 1).map((list) => [value, ...list])

    result.push(...remainList)
  })

  return result
}

function main(input: string) {
  const [[N], ...list] = input.split('\n').map(v => v.split(' ').map(Number))

  if (N === 1) {
    console.log(1)
    return
  }

  const data = permutation(list, 2)
    .map(([[ax, ay], [bx, by]]) => [ax - bx, ay - by])
    .map(v => JSON.stringify(v))

  const countList = Array.from(new Set(data))
    .map(str => data.filter(v => v === str).length)

  const max = Math.max(...countList)

  console.log(N - max)
}

main(readFileSync('/dev/stdin', 'utf8').trim())


Measured memory_bytes: 9600
x,y = map(int,input().split())
mod =10**9+7

a=(-x+2*y)//3
b=(2*x-y)//3
n=a+b

def fact(x,p):
    ret=1
    for i in range(1,x+1):
        ret*=i
        ret%=p
    return ret


if a+2*b==x and b+2*a==y and a>=0 and b>=0:
    ans=fact(n,mod) * pow(fact(b,mod),mod-2,mod)*pow(fact(a,mod),mod-2,mod)
    print(ans%mod)
else:
    print("0")

Measured memory_bytes: 38512
n=int(input())
lists=list(map(int,input().split()))
mini_list=[0 for i in range(n+1)]
#mini_list[i]=iだんめに行くまでに払う最小のコスト
#帰るは一段上がるか二段上がるかのどちらかしかできない
mini_list[1]=0
mini_list[2]=abs(lists[0]-lists[1])
for i in range(3,n+1):
    mini_list[i]=min(mini_list[i-2]+abs(lists[i-1]-lists[i-3]),mini_list[i-1]+abs(lists[i-1]-lists[i-2]))
print(mini_list[-1])

Measured memory_bytes: 13928
#!/usr/bin/python3
# -*- coding: utf-8 -*-



N,K = map(int, input().split())
Vn = list(map(int, input().split()))

def get_sum(a,b):
  # a個取って、b個捨てる
  ret = 0
  for i in range(a+1):
    v = sorted(Vn[:i]+Vn[N-a+i:])
    for j in range(min(a,b)):
      v[j] = max(v[j],0)
    ret = max(ret,sum(v))
  return ret


def main():
  ans = 0
  for n in range(min(N,K)+1):
    ans = max(ans, get_sum(n, max(K-n,0)))
  return ans


if __name__ == "__main__":
  print(main())

Measured memory_bytes: 41068
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;

int N;
vector<int> adj[100000];
map<pair<int, int>, int> color;
pair<int, int> adj_arr[100000];


int dfs(int now, int from_idx, int from_col){
    int next_col = 1;
    int neigh_max_K = 0;
    for(int i = 0; i < adj[now].size(); i++){
        int next_idx = adj[now][i];
        if(next_idx == from_idx){
            continue;
        }
        if(next_col == from_col){
            next_col++;
        }
        color[make_pair(now, next_idx)] = next_col;
        color[make_pair(next_idx, now)] = next_col;
        neigh_max_K = max(neigh_max_K, dfs(next_idx, now, next_col));
        next_col++;
    }
    next_col--;
    return max(next_col, neigh_max_K);
}


int main(){
    cin >> N;
    for(int i = 0; i < N - 1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
        adj_arr[i] = make_pair(a, b);
    }
    int K = dfs(0, -1, 0);
    cout << K << endl;
    for(int i = 0; i < N - 1; i++){
        int a = adj_arr[i].first, b = adj_arr[i].second;
        cout << color[adj_arr[i]] << endl;
    }
}

Measured memory_bytes: 21376
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	static class TreeWalk {
		public void treewalk (InputReader ir) {
			
			int n = ir.nextInt();
			Node[] node = new Node[n];
			
			for (int i = 0; i < n; i++) {
				int id = ir.nextInt();
				node[id] = new Node();
				node[id].left = ir.nextInt();
				node[id].right = ir.nextInt();
			}
			
			Parent (node, n);
			int root = 0;
			for (int i = 0; i < n; i++) {
				if (node[i].parent == -1) {
					root = i;
					break;
				}
			}
			StringBuilder sb = new StringBuilder();
			
			sb.append("Preorder\n");
			Preorder (node, sb, root);
			System.out.println(sb);
			sb.setLength(0);
			sb.append("Inorder\n");
			Inorder (node, sb, root);
			System.out.println(sb);
			sb.setLength(0);
			sb.append("Postorder\n");
			Postorder (node, sb, root);
			System.out.println(sb);
			
			
			
		}
		
		static void Parent (Node[] node, int n) {
			
			for (int i = 0; i < n; i++) {
				if ( node[i].left != -1 && node[i].right != -1) {
					node[node[i].left].parent = i;
					node[node[i].right].parent = i;
				} else if (node[i].left != -1) {
					node[node[i].left].parent = i;
				} else if (node[i].right != -1) {
					node[node[i].right].parent = i;
				}
			}
			
		}
		
		static void Preorder (Node[] node, StringBuilder sb, int pos) {
			sb.append(" ").append(pos);
			if (node[pos].left != -1) Preorder (node, sb, node[pos].left);
			if (node[pos].right != -1) Preorder (node, sb, node[pos].right);
		}
		
		static void Inorder (Node[] node, StringBuilder sb, int pos) {
			if (node[pos].left != -1) Inorder (node, sb, node[pos].left);
			sb.append(" ").append(pos);
			if (node[pos].right != -1) Inorder (node, sb, node[pos].right);
		}
		
		static void Postorder (Node[] node, StringBuilder sb, int pos) {
			if (node[pos].left != -1) Postorder (node, sb, node[pos].left);
			if (node[pos].right != -1) Postorder (node, sb, node[pos].right);
			sb.append(" ").append(pos);
		}
		
	}
	
	static class Node {
		int parent;
		int left;
		int right;
		public Node() {
			parent = -1;
			left = -1;
			right = -1;
		}
		
	}
	
	static class InputReader {
		BufferedReader br;
		StringTokenizer st;
		
		public String nextString() {
			
			 while (!st.hasMoreTokens()) {
	                try {
	                    st = new StringTokenizer(br.readLine(), " ");
	                } catch (IOException e) {
	                    throw new InputMismatchException();
	                }
	            }
			return st.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(nextString());
		}
					
		public InputReader (InputStream inputStream) {
			br = new BufferedReader (new InputStreamReader (inputStream));
			st = new StringTokenizer ("");
		}
		
	}
	
	public static void main (String[] args) {
		InputStream inputStream = System.in;
		InputReader in = new InputReader (inputStream);
		TreeWalk obj = new TreeWalk();
		obj.treewalk(in);
	}
	
	
}



Measured memory_bytes: 24476
#include<iostream>
#include<vector>
main(){
  int n;
  std::cin>>n;
  std::vector<int_fast64_t> a(n);
  for(auto& ai:a)std::cin>>ai;
  
  int_fast64_t allxor = 0;
  for(auto ai:a)allxor ^= ai;
  
  for(auto ai:a)std::cout<< (allxor^ai) <<std::endl;
}


Measured memory_bytes: 4756
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

struct H{
  vector<int> dat;
  void insert(int x){
    int i=(int)dat.size();
    dat.push_back(x);
    while(i>0){
      auto p=(i-1)/2;
      if(dat[p]<dat[i]){
        swap(dat[p], dat[i]);
        i=p;
      }else{
        break;
      }
    }
  }
  int front(){
    return dat[0];
  }
  void remove(){
    swap(dat[0], dat[dat.size()-1]);
    dat.pop_back();
    int len=(int)dat.size();
    int i=0;
    while(i*2+1<len){
      if(i*2+2<len){
        int j=(dat[i*2+1]>dat[i*2+2] ? i*2+1 : i*2+2);
        if(dat[i]<dat[j]){
          swap(dat[i], dat[j]);
          i=j;
        }else{
          break;
        }
      }else{
        if(dat[i]<dat[i*2+1]){
          swap(dat[i], dat[i*2+1]);
          i=i*2+1;
        }else{
          break;
        }
      }
    }
  }

};

int main(){
  H h;
  while(1){
    string s; cin>> s;
    if(s[0]=='e'){
      if(s[1]=='n') break;
      cout<< h.front()<< endl;
      h.remove();
    }else{
      int x; cin>> x;
      h.insert(x);
    }
  }
}



Measured memory_bytes: 6964
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

using namespace std;
using ll = long long int;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = deque<bool>;
using pii = pair<int, int>;
using pll = pair < ll, ll>;


#define FOR(i,N) for(int i=0;i<N;i++)
#define FOR2(i, N) for(int i=1;i<=N;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define mt make_tuple
#define all(x) x.begin(), x.end() 


//cin.tie(nullptr);
//ios_base::sync_with_stdio(false);
//cout << fixed << setprecision(10);
//double pi = 3.141592653589793238;

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


int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	
	int H, W; int numofdot = 0;
	cin >> H >> W;
	vvi m(H + 2, vi(W + 2, -1));
	vvi visited(H + 2, vi(W + 2, -1));
	FOR2(i, H) {
		FOR2(j, W) {
			char x; cin >> x;
			if (x == '.') { m[i][j] = 0; numofdot++; }
		}
	}

	visited[1][1] = 0;
	queue<tuple<int,int,int>> q;//i,j,dis
	q.push(mt(1, 1, 0));

	while (!q.empty()) {
		int i = get<0>(q.front());
		int j = get<1>(q.front());
		int d = get<2>(q.front());
		q.pop();

		FOR(k, 4) {
			int ii = i + dy[k];
			int jj = j + dx[k];
			int dd = d + 1;

			if (visited[ii][jj] == -1 && m[ii][jj] == 0) {
				visited[ii][jj] = dd;
				q.push(mt(ii, jj, dd));
			}
		}
	}

	int a = visited[H][W];
	if (a == -1) {
		cout << -1 << endl;
	}
	else {
		cout << numofdot - a-1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		
		int[] x = new int[n];
		
		
		int ave = 0;
		for(int i = 0; i < n; i++) {
			x[i] = stdIn.nextInt();
			ave += x[i];
		}
		
		ave = (int)Math.round((double)ave/n);
		
		int sum = 0;
		for(int i = 0; i < n; i++) {
			sum += (x[i]-(ave))*(x[i]-(ave));
		}
		System.out.println(sum);
		
	}

}


Measured memory_bytes: 22612
n,m=map(int,input().split())

to = [[] for i in range(n)]
for i in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
cnt = 0
def search(i,visited):
    global cnt
    if len(visited)==n:
        cnt += 1
    for v in to[i]:
        if v not in visited:
            search(v,visited+[v])
search(0,[0])
print(cnt)

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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef string ss;
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    ll a,b,c,d;
    cin >> a >> b >> c>> d;
    cout << a*b - c*b - a*d + c*d << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
N = int(input())
A = sorted(list(map(int, input().split())))

if 0 in A:
    print(0)
    sys.exit()

ans = 1
for a in A:
    ans *= a
    if ans > 10**18:
        print(-1)
        sys.exit()
else:
    print(ans)

Measured memory_bytes: 21796