akhauriyash/Code-Regression huggingface dataset:
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var s = next();
	myout(s.slice(0,3));
}


Measured memory_bytes: 30108
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    rep(0, i, N)
    {
        cin >> a.at(i);
    }
    sort(all(a));
    reverse(all(a));
    int b = 0, c = 0;
    rep(0, i, N)
    {
        if (i % 2 == 0)
        {
            b += a.at(i);
        }
        else
        {
            c += a.at(i);
        }
    }
    cout << b - c << endl;
}

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


// vがi番目 <==> v以下の個数がi個以上、かつvはそのようなもののうち最小
// v以下の個数を数えるには？
ll countLE(ll v, vector<ll>& A){
    ll num = 0;  // doubled, includes (v, v)
    for(ll i=0; i < A.size(); i++){
        if(A[i] == 0){
            if(v >= 0){
                num += A.size();
            }
        }else if(A[i] > 0){
            ll b = -1;
            ll u = A.size();
            while(u - b > 1){
                ll piv = (u + b)/2;
                if(A[i]*A[piv] <= v){
                    b = piv;
                }else{
                    u = piv;
                }
            }
            // bではv以下、uではそれよりおおきくなってる
            num += b + 1;
        }else{
            ll b = -1;
            ll u = A.size();
            while(u - b > 1){
                ll piv = (u + b)/2;
                if(A[i]*A[piv] > v){
                    b = piv;
                }else{
                    u = piv;
                }
            }
            // bではvよりおおきい、uではv以下になってる
            num += A.size() - u;
        }
    }
    // subtract (v, v)
    for(ll i=0; i < A.size(); i++){
        if(A[i]*A[i] <= v){
            // counted double
            num--;
        }
    }
    // div 2
    num /= 2;
    return num;
}


// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    // Failed to predict input format
    ll N, K;
    cin >> N >> K;
    vector<ll> A = vector<ll>(N);
    for(int i=0; i < N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    ll b = -1123456789012345678LL;
    ll u = 1123456789012345678LL;
    // 左はそれ以下のものがk個未満、右はそれ以下のものがk個以上
    while(u - b > 1){
        ll piv = (u + b)/2;
        if(countLE(piv, A) < K){
            b = piv;
        }else{
            u = piv;
        }
        // cout << b << " " << u << " " << piv << endl;
    }
    // u
    
    cout << u << endl;
    return 0;
}


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

using namespace std;

int main() {
    int A, B, H, M;
    cin >> A >> B >> H >> M;

    long double hour = (long double) M / 60 + H;
    //cout << hour << "h" << endl;
    long double zishin = (360 / 12) * hour;
    long double hunshin = (360 / 1) * hour;
    //cout << zishin << ":" << hunshin << endl;
    while(zishin >= 360){
        zishin -= 360;
    }
    while(hunshin >= 360){
        hunshin -= 360;
    }
    //cout << zishin << ":" << hunshin << endl;
    long double diff = zishin - hunshin;
    if(diff < 0) diff *= -1;
    diff *= ((long double) M_PI / 180);
    //cout << diff << ":" <<cos(diff) << endl;

    double ans = pow(pow(A, 2.0)+pow(B, 2.0)-2*A*B*cos(diff),0.5);
    printf("%.16lf\n", ans);
    //cout << ans << endl;
}

Measured memory_bytes: 4100
package main

import (
	f "fmt"
)

func main() {
	var N, K int
	f.Scanf("%d %d", &N, &K)

	var d, s int
	A := make([]int, N)
	for i := 0; i < K; i++ {
		f.Scanf("%d", &d)
		for j := 0; j < d; j++ {
			f.Scanf("%d", &s)
			A[s-1] = 1
		}
	}

	var count int
	for i := 0; i < N; i++ {
		if A[i] == 0 {
			count++
		}
	}

	f.Println(count)
}

Measured memory_bytes: 2416
#include<stdio.h>
int main()
{
	int a, b, A, B, n, i;
	while (1){
		A = 0;
		B = 0;
		scanf("%d", &n);
		if (n == 0)
			break;
		for (i = 0; i < n; i++){
			scanf("%d %d", &a, &b);
			if (a>b)
				A = A + a + b;
			else if (a == b){
				A = A + a;
				B = B + b;
			}
			else
				B = B + a + b;
		}
		printf("%d %d\n", A, B);
	}
	return 0;
}

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

using namespace std;

int main()
{
    long long a, b, n, q, h, s, d;
    while(~scanf("%lld%lld%lld%lld", &q, &h, &s, &d))
    {
        scanf("%lld", &n);
        a=min(min(q*4, h*2), s);
        b=min(a*2, d);
        printf("%lld\n", n/2*b+(n%2)*a);
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define int long long int
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mii map<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
#define FOR(i,a,n) for(int i=a;i<n;i++)
#define FORD(i,a,n) for(int i=n-1;i>=0;i--)
using namespace std;
 
 
int32_t main(){
 
    
    int n,a[100001];
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int dp[n+1]; // dp[i] reps cost to reach a[i]
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
       dp[i]=min((dp[i-1]+abs(a[i]-a[i-1])),(dp[i-2]+abs(a[i]-a[i-2])));
    }
    
        cout<<dp[n-1];

 
    return 0;
 
}


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

int main(){
  int n,m; cin>>n >>m;
  vector<int> cnt(m,0);
  for(int i=0;i<n;i++){
    int k; cin>>k;
    for(int j=0;j<k;j++){
      int a; cin>>a; a--;
      cnt[a]++;
    }
  }
  
  int ans = 0;
  for(int i=0;i<m;i++){
    if(cnt[i] == n){
      ans++;
    }
  }
  cout<<ans<<endl;
}

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

int main()
{
    char n[4];
    cin >> n;

    if (n[0] == n[1])
    {
        if (n[0] == n[2])
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
    else if (n[1] == n[2])
    {
        if (n[1] == n[3])
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }else
    {
        cout << "No" << endl;
    }
    
}


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

int main(void){
	int N, M, P;
	int sum, ans;
	int X[1001];

	while(scanf("%d %d %d", &N, &M, &P) != EOF){
		if(N == 0 && M == 0 && P == 0)  break;

		sum = 0;
		for(int i = 0; i < N; i++){
			cin >> X[i];
			sum += X[i];
		}

		P = 100 - P;

		if(X[M-1] == 0)	ans = 0;
		else ans = sum * P / X[M-1];

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

Measured memory_bytes: 1248
from sys import stdin
import heapq

N = int(stdin.readline().rstrip())
A = [int(input()) for i in range(N)]


tmp = heapq.nlargest(2, A)

for i in range(N):
    if tmp[0] == A[i]:
        print(tmp[1])
    else:
        print(tmp[0])

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

#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VB vector<bool>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

const std::string YES = "YES";
const std::string Yes = "Yes";
const std::string NO = "NO";
const std::string No = "No";

bool inside(int y, int x, int H, int W) { return 0 <= y && y < H && 0 <= x && x < W; }

// 4近傍（右, 下, 左, 上）
const std::vector<int> dy = { 0, -1, 0, 1 };
const std::vector<int> dx = { 1, 0, -1, 0 };

using namespace std;


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

    string s;
    VVI dp;
    while(getline(cin, s)) {
        replace(s.begin(), s.end(), ',', ' ');
        int n;
        stringstream ss;
        ss << s;
        vector<int> v;
        while(ss >> n){
            v.push_back(n);
        }
        dp.push_back(v);
    }
    FOR(i, 1, dp.size()) {
        FOR(j, 0, dp[i].size()) {
            if (dp[i - 1].size() < dp[i].size()) {
                if (0 <= j - 1 and j - 1 < dp[i - 1].size()) {
                    dp[i][j] += max(dp[i - 1][j], dp[i - 1][j - 1]);
                } else {
                    dp[i][j] += dp[i - 1][j];
                }
            }
            else {
                if (0 <= j + 1 and j + 1 < dp[i - 1].size()) {
                    dp[i][j] += max(dp[i - 1][j], dp[i - 1][j + 1]);
                } else {
                    dp[i][j] += dp[i - 1][j];
                }
            }
        }
    }
    cout << dp[dp.size() - 1][0] << endl;
    return 0;
}


Measured memory_bytes: 3228
#include<iostream>
#include<vector>
#include<cmath>
#include<stdio.h>
#include<string>
#include <algorithm>
using namespace std;

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

	bool cnt = false;

	vector<vector<int>> d(n, vector<int>(2));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 2; j++) {
			cin >> d[i][j];
		}
		if (i > 1) {
			if (d[i - 2][0] == d[i - 2][1] && d[i - 1][0] == d[i - 1][1] && d[i][0] == d[i][1]) {
				cnt = true;
			}
		}
	}

	if (cnt == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <cstring>

using namespace std;

int main() {
    int n;
    cin>>n;
    int k;
    cin>>k;
    int q[n+2];
    for (int i=1; i<=n; i++)
        cin>>q[i];
        
    int dp[n+2];
    memset(dp,0x3f3f3f3f,sizeof(dp));
    
    dp[1] = 0;
    dp[2] = abs(q[1]-q[2]);
    
    for (int i=3; i<=n; i++){
        for (int j=1; j<=k; j++){
            if (i-j<1) break;
            dp[i] = min(dp[i], dp[i-j] + abs(q[i]-q[i-j]));
        }
        //cout<<i<<" "<<dp[i]<<endl;
    }
        
        
    cout<<dp[n];
}

Measured memory_bytes: 4376
n = int(input())
al = list(map(int, input().split()))

res = [0]*n
m = n //2

if n % 2 ==0:
    for i in range(m):
        res[i] = al[-1-i*2]    
    for j in range(m):
        res[m+j]= al[j*2]
           
else:
    for i in range(m+1):
        res[i] = al[-1-i*2]
    for j in range(m):
        res[m+1+j] = al[1+j*2]


ress=""
for k in range(n):
    ress +=str(res[k])
    ress +=" "

print(ress[:-1])

Measured memory_bytes: 26180
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 1000000000
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
//int fx[]={0,0,1,-1};
//int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
const int N=100010;
int main()
{
    IOS;
    ll s;cin>>s;
    ll b=1e9;
    ll x=(b-s%b)%b;
    ll y=(s+x)/b;
    cout<<"0 0 1000000000 1 "<<x<<" "<<y<<endl;
}








Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) < (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007LL
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589


#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}
pll Dir[8] = { //移動
	{ 0 ,1 },{ -1 ,0 },{ 1 ,0 },{ 0 ,-1 },
	{ 1 ,1 },{ 1 ,-1 },{ -1 ,1 },{ -1 ,-1 }
};

//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL

struct Edge {
	int from, to;
	ll w;
};
typedef vector<vector<Edge>> Graph;

#define chmax(a,b) ((a) = max(a,b))
#define chmin(a,b) ((a) = min(a,b))
int dp[3001][3001] = {};
pii fr[3001][3001] = {};
string s, t;

int func(int i, int j) {
	if (i < 0 || j < 0) return 0;
	if (dp[i][j] != -1) return dp[i][j];

	int ret = 0;

	if (func(i - 1, j) > ret) {
		ret = func(i - 1, j);
		fr[i][j] = fr[i-1][j];
	}
	if (func(i - 1, j- 1) > ret) {
		ret = func(i - 1, j - 1);
		fr[i][j] = fr[i - 1][j - 1];
	}
	if (func(i, j - 1) > ret) {
		ret = func(i, j - 1);
		fr[i][j] = fr[i][j - 1];
	}

	if (s[i] == t[j]) {
		if (ret < func(i - 1, j - 1) + 1) {
			ret = func(i - 1, j - 1) + 1;
			fr[i][j] = { i, j };
		}
	}

	return dp[i][j] = ret;
}


signed main(void) {
	Fill(dp, -1);
	Fill(fr, MP( -1,-1 ));
	cin >> s >> t;

	func(s.length() - 1, t.length() - 1);
	string ans;
	pii cur = {s.length() - 1, t.length() - 1};
	while (cur.first >= 0 && cur.second >= 0) {
		cur = fr[cur.first][cur.second];
		if (cur.first >= 0 && cur.second >= 0) {
			ans+= s[cur.first];
			cur.first--, cur.second--;
		}
	}
	reverse(ALL(ans));
 	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 106240
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A= sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		if(Math.abs(A-C)<=D||(Math.abs(A-B)<=D&&Math.abs(B-C)<=D)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21972
#include<stdio.h>
#include<string.h>

int main()
{
	char S[99];
	int len;
	scanf("%s", S);
	len =strlen(S);
	
	int r;
	int c = 0;
	for(r=0; r<len; r++){
		if(S[r]==S[len-1-r]) c++;
	}
	
	int d = 0;
	for(r=0; r<(len-1)/2; r++){
		if(S[r]==S[(len-3)/2 - r] && S[(len+1)/2 + r] == S[len-1-r]) d++;
	}
	
	if(c==len && 2*d == len-1) printf("Yes");
	else printf("No");
	
	return 0;
}



Measured memory_bytes: 128
#define  _USE_MATH_DEFINES

#define  rep(i, n) for(int i = 0; i < n; i++)
#define  repx(i, a, n) for(int i = a; i < n; i++)
#define  loop while(1)
#define  lli long long int
#define  aryout(ary) rep(i, ary.size()) cout << ary[i] << (i < ary.size() - 1 ? " " : "\n");
#define  arysort(v) sort(v.begin(), v.end())
#define  aryreverse(v) reverse(v.begin(),v.end())
#define  arysum(v) accumulate(v.begin(), v.end(), 0)
 
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <utility>
#include <set>

using namespace std;

int main() {

  int n, m;
  cin >> n >> m;

  vector<int> v(n);
  lli ans = 0;

  rep(i, n) {
    int y;
    cin >> y;
    ans += y;
    v[i] = y;
  }

  vector<int> v2(n);
  rep(i, n) {
    while (v[i] > 0) {
      int x = v[i] % 2 == 0 ? v[i] / 2 : v[i] / 2 + 1;
      v2.push_back(x);
      v[i] /= 2;
    }
  }
  sort(v2.begin(), v2.end());
  //aryout(v2);

  int k = v2.size();
  rep(i, m) {
    if (i >= k) break;
    ans -= v2[k - i - 1];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 14612
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let dist2 xs ys =
    List.zip xs ys
    |> List.sumBy (fun (x, y) -> pown (abs (x - y)) 2)

let isInt x =
    Seq.ofList [1..x]
    |> Seq.tryFind (fun y -> y * y = x)
    |> Option.isSome

[<EntryPoint>]
let main _ =
    let [n;d] = reads int
    let xss = Array.map (fun _ -> reads int) [|1..n|]
    seq {
        for i = 0 to n - 2 do
            for j = i + 1 to n - 1 do
                if isInt (dist2 xss.[i] xss.[j]) then yield ()
    }
    |> Seq.length
    |> printfn "%i"
    0

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

string s[150];
int cnt=0;

void dfs(string str,int a,int b,int j,int y){
  if(a==j && b==y){
    bool flag=0;
    for(int i=0; i<cnt; i++){
      if(s[i]==str){
        flag++;
      }
    }
    if(flag==0){
      s[cnt]=str;
      cnt++;
    }
  }

  string str1=str;
  string str2=str;

  if(a>=4 && b>=4){
    if(a<j){
      str1.push_back('A');
      dfs(str1,a+1,b,j,y);
    }
    if(b<y){
      str2.push_back('B');
      dfs(str2,a,b+1,j,y);
    }
  }else{
    if(a==4 && b<y){
      str1.push_back('B');
      dfs(str1,a,b+1,j,y);
    }else if(a<j){
      str1.push_back('A');
      dfs(str1,a+1,b,j,y);
    }
    if(b==4 && a<j){
      str2.push_back('A');
      dfs(str2,a+1,b,j,y);
    }else if(b<y){
      str2.push_back('B');
      dfs(str2,a,b+1,j,y);
    }
  }
}

int main(){
  int j,y;
  cin >> j >> y;

  string str;

  dfs(str,0,0,j,y);

  for(int i=0; i<cnt; i++){
    cout << s[i] << '\n';
  }

  return 0;
}



Measured memory_bytes: 3164
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T &v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  int n; in(n);
  vector<int> A(n);
  loop(i,0,n) in(A[i]);
  
  ll ans = 0;
  int sum = 0;
  int r = 0;
  loop(l,0,n) {
    while (r < n and (sum + A[r]) == (sum ^ A[r])) sum += A[r++];
    ans += r-l;
    if (r <= l) r = l + 1;
    sum -= A[l];
  }
  print(ans);
  return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> data(H + 2, vector<char>(W + 2));
  
  for (int i = 0; i < H + 2; i++) {
  	for (int j = 0; j < W + 2; j++) {
    	if (i == 0 || j == 0 || i == H + 1 || j == W + 1) {
        	data.at(i).at(j) = '.';
        }
        else {
        	cin >> data.at(i).at(j);
        } 
    }
  }
  
  int num = 0;
  for (int i = 1; i < H + 1; i++) {
  	for (int j = 1; j < W + 1; j++) {
    	for (int k = -1; k <= 1; k++) {
        	for (int l = -1; l <= 1; l++) {
            	if (data.at(i + k).at(j + l) == '#') {
                	num++;
                }
            }
        }
        if (data.at(i).at(j) == '#') {
        	cout << '#';
        }
        else {
        	cout << num;
        }
        num = 0;
    }
    cout << endl;
  }
}


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

// 最大公約数を求める
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}


// aのn乗のMOD
ll modpow(ll a,ll n){
    ll res = 1;
    while(n>0){
        // &１つはビット積
        if(n&1) res = res * a%MOD;
        a = a*a%MOD;
        n>>=1;
    }
    return res;
}

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	
	ll N,K;
	cin>>N>>K;
    ll ans = 0;
    ll s[K+1]={};
    ll n,k;
    rep(i,K){
        n = K-i;
        s[n] = modpow(K/n,N);
        k=2;
        while(n*k<=K){
            s[n] -= s[n*k];
            ++k;
        }
        while(s[n]<0){
            s[n]+=MOD;
        }
        ans += (n*s[n])%MOD;
        ans%=MOD;
    }

    cout<<ans<<"\n";

	
	return 0;
}

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

int main()
{	
	ios_base::sync_with_stdio(0);
	int k,s;
	while(cin>>k>>s){
		int ans = 0;
		for(int i=0; i<=k; i++){
			for(int j=0; j<=k; j++){
				if(i+j>s) break;
				int need = s - i - j;
				if(need>=0 && need<=k)
					ans++;
			}
		}
		cout<<ans<<endl;
	}
}



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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> Asum(N+1);

  ll len = 0;
  for(ll i = 0; i < N; i++){
    cin >> A[i];
    len += A[i];
  }

  Asum[0] = 0;
  for(ll i = 0; i < N; i++){
    Asum[i+1] = Asum[i] + A[i];
  }

  bool en_0 = false;
  ll ind_ = 0;
  ll ans;
  if(len % 2 == 0){
    ll tmp_len = 0;
    for(ll i = 0; i < N; i++){
      tmp_len += A[i];
      if(tmp_len == len/2){
        en_0 == true;
      }
      if(tmp_len > len/2){
        ind_ = i;
        ans =  A[ind_] - abs(Asum[i+1-1] - (Asum[N] - Asum[i+1]));
        break;
      }
    }
  }else{
    ll tmp_len = 0;
    for(ll i = 0; i < N; i++){
      tmp_len += A[i];
      if(tmp_len >= (len+1)/2){
        ind_ = i;
        ans =  A[ind_] - abs(Asum[i+1-1] - (Asum[N] - Asum[i+1]));
        break;
      }
    }
  }

  if(en_0){
    cout << 0 << endl;
  }else{
    cout << ans << endl;
  }

  


  return 0;
}


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

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



int main(void){

	int N, K; cin >> N >> K;

	double ans = 0.0;
	FOR(i,1,N+1){
		int n = ceil(log2(K/(double)i));
		// if(i == 5) return 0;
		if(n < 1) ans += 1.0;
		else ans +=  (double)pow(0.5,n);
	}
	ans *= (1.0/N);

	cout << setprecision(15)  << ans << endl;

	


	return 0;

}


Measured memory_bytes: 256
def select(a,n):
	ct=0
	for i in range(n-1):
		minv=i
		for j in range(i+1,n):
			if a[j]<a[minv]:
				minv=j
		t=a[i]
		a[i]=a[minv]
		a[minv]=t
		if a[i]!=a[minv]:
			ct+=1
	return a,ct

n=int(input())
table=list(map(int,input().split()))
b,c=select(table,n)
print(*b)
print(c)


Measured memory_bytes: 5604
import java.util.*;
import java.math.BigDecimal;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        double n = sc.nextInt();
        double m = sc.nextInt();
        double d = sc.nextInt();
        double g = n - d;
        double ans = 0;
        if (g < 1) {
            ans = 0;
        } else if (g == n) {
            ans = ((m - 1) / n);
        } else {
            ans = (2 * g * (m - 1)) / (n * n);
        }
        System.out.println(BigDecimal.valueOf(ans).toPlainString());
    }    
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
int n,T,t,c,ans;
int main(){
    ans = 1000000;
    cin>>n>>T;
    for (int i=1;i<=n;i++){
        cin>>c>>t;
        if (t<=T) ans = min(ans,c);
    }
    if (ans == 1000000) puts("TLE");else cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int ans;

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=n; i>=0; i--)
	{
		for(int j=0; i+j<=m&&j<=n; j++)
		{
			if(m-i-j>n)continue;
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
def vary_for_flag(a, b, flag):
    if flag == False:
        return a-b
    else:
        return a+b
def str_for_num(num):
    if num == 0:
        return "+"
    else:
        return "-"
A = input()
a = []
for i in range(4):
    b = int(A[i])
    a.append(b)
for i in range(2):
    if i == 0:
        first_flag = True
    else:
        first_flag = False
    for j in range(2):
        if j == 0:
            second_flag = True
        else:
            second_flag = False
        for k in range(2):
            if k == 0:
                third_flag = True
            else:
                third_flag = False
            temp = vary_for_flag(vary_for_flag(vary_for_flag(a[0], a[1], first_flag), a[2], second_flag), a[3], third_flag)
            if temp == 7:
                break
        else:
            continue
        break
    else:
        continue
    break
print("{}{}{}{}{}{}{}=7".format(a[0],str_for_num(i),a[1],str_for_num(j),a[2],str_for_num(k),a[3]))

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int MOD = 1e9+7;

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

    int s,w;
    cin >> s >> w;
    cout << ( w>=s ? "unsafe" : "safe" ) << endl; 

    return 0;
}


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

int main(void)
{
    ll a,b,n;
    cin >> a>>b>>n;
    
    
    cout << a*(b-1<n?b-1:n)/b << endl;
    return 0;
}


Measured memory_bytes: 3624
fun main(args: Array<String>) {

    val t1 = readLine()!!.split(" ").map { it.toInt() }
    val t2 = readLine()!!.split(" ").map { it.toInt() }
    val t3 = readLine()!!.split(" ").map { it.toInt() }

    val t4 = listOf(t1[0], t2[0], t3[0])
    val t5 = listOf(t1[1], t2[1], t3[1])
    val t6 = listOf(t1[2], t2[2], t3[2])

    val t7 = listOf(t1[0], t2[1], t3[2])
    val t8 = listOf(t1[2], t2[1], t3[0])

    val N = readLine()!!.toInt()
    val b = (1..N).map { readLine()!!.toInt() }

    val t = listOf(t1, t2, t3, t4, t5, t6, t7, t8)

    val answer = if (t.any { b.containsAll(it) }) "Yes" else "No"

    println(answer)
}

Measured memory_bytes: 37856
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define endl "\n"
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;

ll dp[2][21010]={};


string a2(string s,int k,int i){
    if(s.size()-1-k==0&&s[0]=='9'){
        string temp="";
        rep(i,s.size()){
            temp=temp+"0";
        }
        s="1"+temp;
    }else if(s.size()-1-k==0){
      
        s[0]=s[0]+1;
    }else{
        if(s[s.size()-1-k]=='9'){
            s=a2(s,k+1,i);
            if(s[s.size()-2-k]=='0'){
                s[s.size()-1-k]='0';
            }else{
                s[s.size()-1-k]=s[s.size()-2-k]-1;
            }
        }else{
          if(abs(s[s.size()-2-k]-s[s.size()-1-k]-1)<=1){
          	s[s.size()-1-k]=s[s.size()-1-k]+1;
          }else{
          	s=a2(s,k+1,i);
            if(s[s.size()-2-k]=='0'){
                s[s.size()-1-k]='0';
            }else{
                s[s.size()-1-k]=s[s.size()-2-k]-1;
            }
          }
        }
    }
    return s;
}
int main(){
    ll a,b=0;;
    string s="9";
    cin>>a;
    if(a<10){
        cout<<a<<endl;
        return 0;
    }
    rep(i,a-9){
        s=a2(s,0,i);
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	while(1){
		int x,y;
		cin>>x>>y;
		if(x == 0 && y==0) break;

		if(x>y) swap(x,y);
		cout<<x<<" "<<y<<endl;
	}
	return 0;
}


Measured memory_bytes: 3048
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
F = list(map(int,input().split()))
F.sort(reverse=True)

sa = sum(A)
if K >= sa:
    print(0)
    exit()

def isok(b):
    k = 0
    for a,f in zip(A,F):
        if a > b//f:
            k += a-(b//f)
            if k > K:
                return False
    return True

ok = 10**12+1
ng = 0

while ok-ng > 1:
    m = (ok+ng)//2
    if isok(m):
        ok = m
    else:
        ng = m
print(ok)

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

int main()
{
    int n , m;
    cin>>n>>m;
    int* likes = new int[m+1]();
    for(int i=0;i<n;i++)
    {
        int k;
        cin>>k;
        for(int i=0;i<k;i++)
        {
            int t;
            cin>>t;
            likes[t]++;
        }
    }
    int ans =0;
    for(int i=0;i<=m;i++)
    {
        if( likes[i] == n)
            ans++;
    }
    cout<<ans;
}

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

#define MYNULL -2000

typedef struct {
    int x;
    int y;
} set;
    

int main(){
    while (1){
    int n;
    cin >> n;
    if (n == 0) break;
    set mymap[200];
    int zero = n;
    int biggestX, biggestY, smallestX, smallestY;

    for (int i = 0; i < 200; i++)
	    mymap[i].x = mymap[i].y = MYNULL;

    mymap[0].x = mymap[0].y = 0;
    
    for (int s = 1; s < n; s++){
	
	int ni, di;
	cin >> ni >> di;
	
	switch (di){
	case 0:
	    mymap[s].x = mymap[ni].x - 1;
	    mymap[s].y = mymap[ni].y;
	    break;
	case 1:
	    mymap[s].x = mymap[ni].x;
	    mymap[s].y = mymap[ni].y - 1;
	    break;
	case 2:
	    mymap[s].x = mymap[ni].x + 1;
	    mymap[s].y = mymap[ni].y;
	    break;
	case 3:
	    mymap[s].x = mymap[ni].x;
	    mymap[s].y = mymap[ni].y + 1;
	    break;
	}
    }

//    for (int v = 0; v < n; v++){
//	cout << "mymap[" << v << "] = " << mymap[v].x << ", " << mymap[v].y << endl;
//    }
    // solve
    // take biggest x
    biggestX = biggestY = -200000;
    smallestX = smallestY = 200000;

    for (int i = 0; i < n; i++){
	if (mymap[i].x != MYNULL && mymap[i].y != MYNULL){
	    if (biggestX < mymap[i].x)
		biggestX = mymap[i].x;
	    if (biggestY < mymap[i].y)
		biggestY = mymap[i].y;
	    if (smallestX > mymap[i].x)
		smallestX = mymap[i].x;
	    if (smallestY > mymap[i].y)
		smallestY = mymap[i].y;
	}
	
    }

//    cout << biggestX  << "-" << smallestX << " " << biggestY << "-" << smallestY << endl;
    cout << biggestX - smallestX + 1 << " " << biggestY - smallestY + 1 << endl;
    }
}

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

/*
struct Edge
{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    vector<vector<char>> C(2, vector<char>(3));
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> C[i][j];
        }
    }

    if (C[0][0] != C[1][2] || C[0][1] != C[1][1] || C[0][2] != C[1][0])
        cout << "NO" << endl;
    else
        cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 3576
class Card
  def initialize(str)
    tmp = str.split("")
    @mark = tmp[0]
    @number = tmp[1].to_i
  end

  def description
    "#{@mark}#{@number}"
  end

  attr_reader :mark, :number
end

def bubble_sort(c, n)
  0.upto(n-1).each {|i|
    (n-1).downto(i+1).each {|j|
      if c[j].number < c[j-1].number
        c[j], c[j-1] = c[j-1], c[j]
      end
    }
  }
  c
end

def selection_sort(c, n)
  0.upto(n-1).each {|i|
    minj = i
    i.upto(n-1).each {|j|
      minj = j if c[j].number < c[minj].number
    }
    c[i], c[minj] = c[minj], c[i]
  }
  c
end

def extract_duplicate(cards)
  dups = cards.group_by{|c| c.number}.reject{|k,v| v.one?}
  dups.keys.sort.map {|k| dups[k].map(&:description)}
end

def is_stable?(org_dup, other_dup)
  org_dup == other_dup ? "Stable" : "Not stable"
end

n = gets.to_i
cards = gets.split(" ").map {|x| Card.new x}
o_dup = extract_duplicate cards

bs = bubble_sort cards.dup, n
ss = selection_sort cards.dup, n

bs_dup = extract_duplicate bs
ss_dup = extract_duplicate ss

puts bs.map(&:description).join(" ")
puts is_stable? o_dup, bs_dup
puts ss.map(&:description).join(" ")
puts is_stable? o_dup, ss_dup

Measured memory_bytes: 8780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF 1000000000

int main() {
    int a,b;
    cin >> a >> b;
    if (a>8 or b>8){
        cout << ":(" << endl;
    }
    else {
        cout << "Yay!" << endl;
    }
}

Measured memory_bytes: 3556
#include <iostream>
#include <cstdio>
#include <bitset>
#define M 8005
using namespace std;

int x, y, z, c;
string s;
bitset<M * 2> bs[2];
int main() {
	int i;
	cin >> s >> x >> y;
	for (i = 0; s[i] == 'F'; i++);
	bs[0][i + M] = bs[1][M] = 1;
	for (; i <= s.size(); i++) {
		if (s[i] == 'F') c++;
		else bs[z] = (bs[z] << c) | (bs[z] >> c), z = !z, c = 0;
	}
	cout << (bs[0][x + M] & bs[1][y + M] ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>


using namespace std;


int gcd(int a, int b) {
	if (a < b) swap(a, b);
	return b ? gcd(b, a % b) : a;
}

int main() {

	int N;
	cin >> N;
	vector<int> A(N+2);
	vector<int> left(N+2);
	vector<int> right(N+2);
	for (int i = 1; i <= N; i++)
		cin >> A[i];

	A[0] = A[N + 1] = 0;

	left[0] = A[0];
	for (int j = 1; j <= N; j++) {
		left[j] = gcd(left[j-1], A[j]);
	}

	right[N+1] = A[N+1];
	for (int j = N; j >= 1; j--) {
		right[j] = gcd(right[j + 1], A[j]);
	}

	int max = left[N];
	for (int i = 1; i <= N; i++) {
		int ans = gcd(left[i - 1], right[i + 1]);
		if (ans > max)
			max = ans;
	}
	cout << max << endl;

	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);++(i))
#define all(x) (x).begin(),(x).end()
#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define yes(n) cout << ((n) ? "yes" : "no") << endl

using namespace std;
using ll = long long;
using P = pair<int, int>;

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

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

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) {
    ll g = GCD(a, b);
    return a / g * b;
}

vector<int> is_prime;

void sieve(ll m, vector<int> &is_prime) {
    is_prime[0] = 0;
    is_prime[1] = 0;

    for (int i=2;i<m;++i) {
        if (!is_prime[i]) continue;
        for (int j=i*2;j<m;j+=i) is_prime[j] = 0;
    }
}


int main() {
    int x;
    cin >> x;
    is_prime.assign(2 * x, 1);
    sieve(2 * x, is_prime);

    for (int i=x;i<2*x;++i) {
        if (is_prime[i]) {
            cout << i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 1024
N, K = map(int, input().rstrip().split(' '))
result = 0.0

def get_n(num, K):
    now_score = num
    for i in range(20):
       if now_score >= K:
           return i
       now_score *= 2

for i in range(1, N+1):
    n = get_n(i, K)
    i_score = (1/N) * ((1/2)**n)
    result += i_score

print(result)

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

int main(){
  int n, k;
  cin >> n >> k;
  int cnt = 0;
  int a;
  rep(i,n){
    cin >> a;
    if(a>=k)
      cnt++;
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>

int main(int argc, char **argv)
{

    std::string s;
    std::cin >> s;

    std::vector<char> ans;
    for(int i = 0; i < s.size(); i++){
        if(i % 2 == 0) ans.push_back(s.at(i));
    }

    std::string ss(ans.begin(), ans.end());
    std::cout << ss << std::endl;
}


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

#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
vector<int> dy = {1, 0, -1, 0};
vector<int> dx = {0, 1, 0, -1};
typedef pair<int, int> PII;

int main() {
    int h, w;
    cin >> h >> w;
    int num_brack = 0;
    vector<string> grah(h);
    for(int i = 0; i < h; i++){
        cin >> grah.at(i);
    }
    rep(i, h) rep(j, w){
        if(grah.at(i).at(j) == '#') num_brack++;
    }
    vector<vector<int>> dist(h, vector<int>(w, -1));
    queue<PII> q;
    q.emplace(0, 0);
    dist.at(0).at(0) = 0;

    while(!q.empty())
    {
        auto v = q.front();
        q.pop();
        rep(i, 4){
            int ny = v.first + dy.at(i);
            int nx = v.second + dx.at(i);
            if(0 <= ny && 0 <= nx && ny < h  && nx < w  && dist.at(ny).at(nx) == -1 && grah.at(ny).at(nx) != '#'){
                dist.at(ny).at(nx) = dist.at(v.first).at(v.second) + 1;
                q.emplace(ny, nx);
            }
        }
    }
    auto size = 0;
    rep(i, h){
        size += grah.at(i).size();
    }
    if(dist.at(h-1).at(w-1) == -1) {
        cout << "-1" << endl;
        return 0;
    }
    cout << size - num_brack - (dist.at(h-1).at(w-1) + 1) << endl;
    
    return 0;

}

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

int main()
{
  int N;
  cin >> N;
  vector<ll> a(N+2);
  vector<ll> b(N+1);
  rep(i,N+1) cin >> a[i];
  rep(i,N) cin >> b[i];
  ll ans =0;
  rep(i,N+1){
    if(b[i]>a[i]){
      ll diff = min(a[i+1],b[i]-a[i]);
      a[i+1] -= diff;
      ans += a[i]+diff;
      b[i] -= a[i];
      a[i] = 0;
    }else{
      ans += b[i];
      a[i] -= b[i];
      b[i]=0;
    }
  }
  cout << ans << endl;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

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

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

while(x != NIL){
    y = x;
    if(z -> key < x -> key)
      x = x -> left;
    else
      x = x -> right;
 }
    z -> parent = y;
    if(y == NIL)
      root = z;
    else if(z -> key < y -> key)
      y -> left = z;
    else
      y -> right = z;
}





void inorder(Node u){
  if(u ==  NIL) return;
  inorder(u -> left);
  printf(" %d",u -> key);
  inorder(u -> right);
}
void preorder(Node u){
  if(u == NIL) return;
  printf(" %d",u -> key);
  preorder(u -> left);
  preorder(u -> right);  
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = find(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }
  
  return 0;
}

Measured memory_bytes: 19364
import sys
 
 
r,D,x_2000 = sys.stdin.readline().strip().split()
r = int(r)
D = int(D)
x_2000 = int(x_2000)

def calc(x_i):
    X = r*x_i - D
    return(X)
    
x = x_2000
cnt = 0
f=1
while(f==1):
    x = calc(x)
    print(x)
    cnt += 1
    if(cnt==10):
        f=0

Measured memory_bytes: 3060
h,w=map(int,input().split(" "))

if(h==1 or w==1):
    print(1)
    exit()

a=w*(h//2)

if(h%2==1):
    if(w%2==0):
        a=a+(int(w/2))
    else:
        a=a+(int(w/2)+1)
print(int(a))


Measured memory_bytes: 2940
n, m = map(int, input().split())
a = [list(input()) for _ in range(n)]
b = [list(input()) for _ in range(m)]

def dfs(x: int, y: int, i: int, j: int) -> bool:
    if i-x == m:
        return True
    if j-y == m:
        return True

    if a[i][j] != b[i-x][j-y]:
        return False

    if not dfs(x, y, i, j+1):
        return False
    if not dfs(x, y, i+1, j):
        return False
    if not dfs(x, y, i+1, j+1):
        return False

    return True

ans = "No"
for i in range(n-m+1):
    for j in range(n-m+1):
        if a[i][j] == b[0][0]:
            x = i
            y = j
            if dfs(x, y, i, j):
                ans = "Yes"
                break

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const int maxn=20000+5;
int n,x,y,ans[maxn];
int main(){
	cin>>n>>x>>y;
	for(int i=1;i<=n;i++)
		for(int j=1;j<i;j++)
		{
			int dist1=i-j;
			int dist2=abs(x-j)+abs(y-i)+1;
			int dist=min(dist1,dist2);
			ans[dist]++;
		}
	for(int i=1;i<=n-1;i++)cout<<ans[i]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int n,q,a,f[100010],b,c;
long long sum;

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a);
        sum+=a;
        f[a]++;
    }
    scanf("%d",&q);
    while(q--)
    {
        scanf("%d %d",&b,&c);
        sum-=b*(long long)f[b];
        sum+=c*(long long)f[b];
        f[c]+=f[b];
        f[b]=0;
        printf("%lld\n",sum);
    }
    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <queue>
#include <vector>
#include <tuple>
#include <algorithm>
using namespace std;

typedef tuple<int,int,int,int,int,int> T;//<cost,A,B,C,y,x>
#define INF 1e8

int main(){
    int h,w;
    int map[10][10];//[y][x]
    int minimum[6][6][6][10][10];//[テ、ツクツ甘ゥツ敖「テ」ツ?ョテァツ崢ョ][テ・ツ債療・ツ青妥」ツ?江[テヲツ敖アテ・ツ青妥」ツ?江[][y][x]
    priority_queue<T,vector<T>,greater<T>> que;
    while(cin>>h>>w,h){
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                cin>>map[i][j];
            }
        }
        int start_y,start_x,end_y,end_x;
        cin>>start_y>>start_x>>end_y>>end_x;
        while(!que.empty())que.pop();
        que.push(T(0,1,2,3,start_y,start_x));
        fill(minimum[0][0][0][0],minimum[6][0][0][0],INF);
        while(!que.empty()){
            T t = que.top(); que.pop();
            int cost=get<0>(t), A=get<1>(t),B=get<2>(t),C=get<3>(t), y=get<4>(t), x=get<5>(t);
            if(cost>minimum[A-1][B-1][C-1][y][x]) continue;
            int penalty;
            //テ・ツ個?
            if(y){
                int newA=B,newB=7-A,newC=C;
                penalty=cost+(7-newA)*map[y-1][x];
                if(penalty<minimum[newA-1][newB-1][newC-1][y-1][x]){
                    minimum[newA-1][newB-1][newC-1][y-1][x]=penalty;
                    que.emplace(penalty,newA,newB,newC,y-1,x);
                }
            }
            //テ・ツ債?
            if(y!=h-1){
                int newA=7-B,newB=A,newC=C;
                penalty=cost+(7-newA)*map[y+1][x];
                if(penalty<minimum[newA-1][newB-1][newC-1][y+1][x]){
                    minimum[newA-1][newB-1][newC-1][y+1][x]=penalty;
                    que.emplace(penalty,newA,newB,newC,y+1,x);
                }
            }
            //テヲツ敖ア
            if(x!=w-1){
                int newA=7-C,newB=B,newC=A;
                penalty=cost+(7-newA)*map[y][x+1];
                if(penalty<minimum[newA-1][newB-1][newC-1][y][x+1]){
                    minimum[newA-1][newB-1][newC-1][y][x+1]=penalty;
                    que.emplace(penalty,newA,newB,newC,y,x+1);
                }
            }
            //ティツ・ツソ
            if(x){
                int newA=C,newB=B,newC=7-A;
                penalty=cost+(7-newA)*map[y][x-1];
                if(penalty<minimum[newA-1][newB-1][newC-1][y][x-1]){
                    minimum[newA-1][newB-1][newC-1][y][x-1]=penalty;
                    que.emplace(penalty,newA,newB,newC,y,x-1);
                }
            }
        }
        int ans=INF;
        for(int i=0;i<6;i++)for(int j=0;j<6;j++)for(int k=0;k<6;k++)ans=min(ans,minimum[i][j][k][end_y][end_x]);
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 3096