akhauriyash/Code-Regression huggingface dataset:
def dequeue(queue, k)
  max = 0
  fetch_count = [queue.size, k].min
  0.upto(fetch_count) do |a|
    0.upto(fetch_count) do |b|
      break if a + b > fetch_count
      arr = []
      q = queue.dup
      a.times { arr << q.shift }
      b.times { arr << q.pop }

      arr.sort!

      dump_count = k - a - b
      while !arr.empty? && dump_count > 0 && arr[0] < 0
        arr.shift
        dump_count -= 1
      end

      max = [max, arr.inject(:+)].max unless arr.empty?
    end
  end
  max
end

n, k = gets.split.map(&:to_i)
queue = gets.split.map(&:to_i)
puts dequeue(queue, k)

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

#include <bits/stdc++.h>
using namespace std;

template<typename T>
void cmpmax(T& reference, T value) {
	reference = max(reference, value);
}

template<typename T>
void cmpmin(T& reference, T value) {
	reference = min(reference, value);
}

const ll mod = 1000000007;

static const ll INF = 1e15;

int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> vs(n);
	rep(i, n)cin >> vs[i];
	sort(vs.begin(), vs.end());
	vector<int> dp(k + 1, -1);
	for (int i = 0; i < vs[0]; i++) {
		dp[i] = false;
	}
	for (int i = vs[0]; i < k + 1; i++) {
		bool win = false;
		for (int j = 0; j < n; j++) {
			auto next = i - vs[j];
			if (next >= 0) {
				if (dp[next] == false) {
					win = true;
				}
			}			
		}
		dp[i] = win;
	}
	if (dp[k]) {
		cout << "First" << endl;
	}
	else {
		cout << "Second" << endl;
	}
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {

    size_t N;
    cin >> N;
    vector<long long> a(N + 1);
    vector<long long> dp(N + 1, 0);
    vector<long long> prev(N + 1, 0);
    for (size_t i = 1; i <= N; ++i) cin >> a[i];
    prev[1] = a[1];
    for (size_t i = 3; i <= N; ++i) prev[i] = a[i] + prev[i - 2];

    for (size_t i = 2; i <= N; ++i) {
        if ((i & 1) == 0) {
            dp[i] = max(prev[i - 1], dp[i - 2] + a[i]);
        } else {
            dp[i] = max(dp[i - 1], dp[i - 2] + a[i]);
        }
    }
    
    cout << dp[N];
    return 0;
}

Measured memory_bytes: 7988
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
#define double long double
using namespace std;

typedef long long i64;

double getAns(int n, double d1, double x) {
    if (n == 0) {
        return 0;
    }
    double ans = d1 + (n - 1) * 0.5 * x;
    return ans + getAns(n - 2,
                        d1 + (2 * d1 + 5 * x) / n,
                        x + (9 * x - 5 * x) / n);
}

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, d1, diff;
    cin >> n >> d1 >> diff;

    cout << setprecision(10) << fixed;
    cout << getAns(2 * n, d1, diff) << '\n';
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int a[1001];
int main(){
    int n,m;
    while(cin>>n>>m,n){
        rep(i,n) cin>>a[i];
        int mx=-1;
        rep(i,n)rep(j,n)if(i!=j){
            int sum=a[i]+a[j];
            if(sum<=m&&mx<sum) mx=sum;
        }
        if(mx==-1) cout<<"NONE"<<endl;
        else cout<<mx<<endl;
    }
    return 0;
}


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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

bool ans(vector<int> &h){
	int d = h[1] - h[0];
//	for(auto e : h)cerr << e << " "; cerr << endl;
	for(int i = 1; i < h.size(); i++){
		if(h[i] - h[i-1] != d)return false;
	}
	return true;
}

signed main(){
	while(true){
		int n; cin >> n;
		if(n == 0 )break;
		vector<int> h(n+1);
		for(auto &e : h)cin >> e;
		for(int i = 0; i < n+1; i++){
			vector<int> tmp;
			for(int j = 0; j < n+1; j++){
				if(i == j)continue;
				tmp.push_back(h[j]);
			}
			if(ans(tmp)){
				cout << h[i] << endl;
				break;
			}
		}
	}

	return 0;
}




Measured memory_bytes: 3156
N=int(input())
A= [int(s) for s in input().split()]
B= [int(s) for s in input().split()]
C= [int(s) for s in input().split()]

#print(N,A,B,C)

k=0
for i in range(N-1):
  if A[i]==A[i+1]-1:
    if i == 0:
      k=k+C[A[0]-1]
	
    else:
      k=k+C[A[i]-1]

  
print(sum(B)+k)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define x real()
#define y imag()
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
typedef pair<double,int> D;
const double EPS = 1e-8;

P p[100];
double r[100],d[100];
int n,s,g;

double dot(P a, P b){ return real(conj(a)*b); }

double cross(P a, P b){ return imag(conj(a)*b); }

int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

bool isIntersect(L s1, L s2){
  return ( ccw(s1.first,s1.second,s2.first) * ccw(s1.first,s1.second,s2.second) <= 0 &&
           ccw(s2.first,s2.second,s1.first) * ccw(s2.first,s2.second,s1.second) <= 0 );
}

double getDistanceSP(L s, P p){
  if(dot(s.second - s.first, p - s.first) < -EPS) return abs(p - s.first);
  if(dot(s.first - s.second, p - s.second) < -EPS) return abs(p - s.second);
  return abs(cross(s.second - s.first, p - s.first) / abs(s.second - s.first)); }

double getDistanceSS(L s1, L s2){
  if(isIntersect(s1,s2)) return 0.0;
  return min( min(getDistanceSP(s1, s2.first), getDistanceSP(s1, s2.second)),
              min(getDistanceSP(s2, s1.first), getDistanceSP(s2, s1.second)));
}

double slv(){
  for(int i=0;i<n;i++)cin>>p[i].x>>p[i].y>>d[i]>>r[i];
  
  priority_queue<D,vector<D>,greater<D> > Q;
  int used[100]={};
  Q.push(D(0,s-1));
  while(!Q.empty()){
    double cs=Q.top().first;
    int pos=Q.top().second;
    Q.pop();
    if(used[pos]++)continue;
    if(pos==g-1)return cs;
    
    for(int i=0;i<n;i++){
      if(i==pos)continue;

      for(int j=0;j<5;j++){
	
	double na=M_PI*(d[i]+72*j+90)/180;
	double na1=M_PI*(d[i]+72*(j+2)+90)/180;
	L S=L(P(r[i]*cos(na),r[i]*sin(na))+p[i],P(r[i]*cos(na1),r[i]*sin(na1))+p[i]);
	for(int k=0;k<5;k++){
	  double nb=M_PI*(d[pos]+72*k+90)/180;
	  double nb1=M_PI*(d[pos]+72*(k+2)+90)/180;
	  L G=L(P(r[pos]*cos(nb),r[pos]*sin(nb))+p[pos],P(r[pos]*cos(nb1),r[pos]*sin(nb1))+p[pos]);
	  Q.push(D(cs+getDistanceSS(S,G),i));
	}
      }
    }
  }
}

int main(){
  while(cin>>n>>s>>g,n)printf("%.8lf\n",slv());
  return 0;
}

Measured memory_bytes: 10400
a,b,k = map(int,input().split())
k -= 1
aa = min(a+k,b)
bb = max(b-k,a)
if aa < bb:
	[print(i) for i in range(a,aa+1)]
	[print(i) for i in range(bb,b+1)]
else:
	[print(i) for i in range(a,b+1)]

Measured memory_bytes: 3060
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = input()
# print(n)

if n[-1] == '2' or n[-1] == '4' or n[-1] == '5' or n[-1] == '7' or n[-1] == '9':
    print('hon')
    exit()
if n[-1] == '0' or n[-1] == '1' or n[-1] == '6' or n[-1] == '8':
    print('pon')
    exit()
if n[-1] == '3':
    print('bon')


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

int main(){
  int n;cin >> n;
  int h[n];rep(i,n)cin >> h[i];
  int ans = 1;
  for(int i=1;i<n;i++){
    bool f = true;
    for(int j=0;j<i;++j){
      if(h[i] < h[j])f = false;
    }
    if(f == true)ans += 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    char s[n + 1], t[n + 1];
    scanf("%s%s",s,t);
    for(int i = 0; i < n; i++)
        printf("%c%c",s[i],t[i]);
    return 0;
}

Measured memory_bytes: 128
Public Class Program
  Shared Sub Main()
    Dim n As Long = Long.Parse(Console.ReadLine())
    Dim h As Long() = Array.ConvertAll(Of String, Long)(Console.ReadLine().Split(" "), AddressOf Long.Parse)
    Dim ans As Long = 0
    Dim moveCount As Long = 0
    For i As Long = 0 To n - 2
      If h(i) >= h(i + 1) Then
        moveCount += 1
      Else
        If ans < moveCount Then ans = moveCount
        moveCount = 0
      End If
    Next
    If ans < moveCount Then ans = moveCount
    Console.WriteLine(ans.ToString())
  End Sub
End Class

Measured memory_bytes: 27356
package main

import (
    "fmt"
)

func main() {
    var S string
    fmt.Scan(&S)
    left := 0
    right := 0
    ans := make([]int, len(S))
    for i := 0; i < len(S); i++ {
        if S[i] == 'R' {
            left++
        } else {
            right++
        }
        if i == len(S)-1 {
            ans[i-right] = (left+1)/2 + right/2
            ans[i-right+1] = (right+1)/2 + left/2
            break
        }
        if S[i] == 'L' && S[i+1] == 'R' {
            ans[i-right] = (left+1)/2 + right/2
            ans[i-right+1] = (right+1)/2 + left/2
            left = 0
            right = 0
        }
    }
    for i, val := range ans {
        fmt.Print(val)
        if i == len(ans)-1 {
            fmt.Print("\n")
        } else {
            fmt.Print(" ")
        }
    }
}



Measured memory_bytes: 4736
#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>;

const ll INF = 1001001001001001001;
//const ll INF = 50;


int main(){
    int v,e;
    cin >> v >> e;
    ll G[v][v];
    rep(i,v) rep(j,v) G[i][j]=INF;

    vector<vector<int>> to(v);
    vector<vector<ll>> weight(v);

    rep(i,v) rep(j,v){
        if(i==j) G[i][j]=0;
        else G[i][j]=INF;
    }

    rep(i,e) {
        int s,t; ll d;
        cin >> s >> t >> d;
        to[s].push_back(t);
        weight[s].push_back(d);
        G[s][t] =d;
    }

    /*
    cout << "graph" << endl;
    rep(i,v){
        rep(j,v) cout << G[i][j] << " ";
        cout << endl;
    }*/


    for(int i = 0; i<v; ++i){

        //cout << "now " << i<< endl;
        //新規追加の最短距離の更新
        rep(k,to[i].size()){
                int temp = to[i][k];
                //cout << "temp " << temp << endl;
                if(temp>i) continue;
                for(int j=0;j<i; ++j){
                    G[i][j] = min(G[i][j],G[i][temp]+G[temp][j]);
                }
                /*
                cout << "graph1" << endl;
                rep(i,v){
                    rep(j,v) cout << G[i][j] << " ";
                    cout << endl;
                    }
                    */
            }
        //以前の頂点の最短経路の見直し
        rep(j,v){
            rep(k,v){
                //if(j>=v) continue;
                //if(k>=v) continue;
                G[j][k]=min(G[j][k],G[j][i]+G[i][k]);
            }
        }
        /*
        cout << "graph" << endl;
        rep(i,v){
            rep(j,v) cout << G[i][j] << " ";
            cout << endl;
            }
            */
    }

    /*
    cout << "graph" << endl;
    rep(i,v){
        rep(j,v) cout << G[i][j] << " ";
        cout << endl;
    }
    */

   //do NegativeCycles exist?
    rep(i,v){
        if (G[i][i]<0){
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }

    rep(i,v){
        rep(j,v){
            if(G[i][j]>(INF-100100100100100)) cout << "INF";
            else cout << G[i][j];
            if(j!=v-1) cout << " ";
            else cout << endl;
        }
        //cout << endl;
    }

    
}


Measured memory_bytes: 3324
package main

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

func main() {
	var n int
	fmt.Scan(&n)

	stdin := bufio.NewScanner(os.Stdin)
	stdin.Scan()
	s := stdin.Text()
	stringSeq := strings.Split(s, " ")
	floatSeq := convStringSeqToFloatSeq(stringSeq)
	sumResult := sum(floatSeq)
	fmt.Println(1 / sumResult)

}

func convStringSeqToFloatSeq(stringSeq []string) []float64 {
	floatSeq := make([]float64, len(stringSeq))
	for i, v := range stringSeq {
		intValue, _ := strconv.Atoi(string(v))
		floatSeq[i] = 1 / float64(intValue)
	}
	return floatSeq
}

func sum(floatSeq []float64) float64 {
	var result float64
	for _, v := range floatSeq {
		result += v
	}
	return result
}


Measured memory_bytes: 640
import java.util.*;

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 max = Math.max(Math.max(a, b), c);
    
    System.out.println(a+b+c-max);
  }
}

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

int main()
{
	for (unsigned a, b; cin >> a >> b;) {
		unsigned count = 1;
		for (a = (a + b) / 10; a; a /= 10) {
			count++;
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cassert>

//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;

//std::cout << std::fixed << std::setprecision(10)
//std::ios::sync_with_stdio(false);
//constexpr long long MOD = 1000000007;

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

void dfs(int a, int index, std::vector<int>& visit, const std::vector<std::vector<int>>& edges, std::unordered_set<int>& ans)
{
  visit[a] = index;
  ans.insert(a);
  for(auto& b: edges[a])
    if(!visit[b])
      dfs(b, index, visit, edges, ans);
}

int main()
{
  int N, M, K;
  std::cin >> N >> M >> K;
  std::vector<std::vector<int>> edges(N);
  while(M--)
  {
    int a, b;
    std::cin >> a >> b;
    --a; --b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  std::vector<std::vector<int>> blocks(N);
  while(K--)
  {
    int a, b;
    std::cin >> a >> b;
    --a; --b;
    blocks[a].push_back(b);
    blocks[b].push_back(a);
  }
  std::vector<int> visit(N, 0);
  std::vector<std::unordered_set<int>> ans;
  for(int i = 0; i < N; ++i)
  {
    if(!visit[i])
    {
      std::unordered_set<int> s;
      dfs(i, ans.size() + 1, visit, edges, s);
      ans.push_back(std::move(s));
    }
  }
  for(int i = 0; i < N; ++i)
  {
    int j = visit[i] - 1;
    auto& s = ans[j];
    int blockCnt = 0;
    for(auto a: blocks[i])
      if(s.find(a) != s.end())
        ++blockCnt;
    std::cout << (s.size() - blockCnt - edges[i].size() - 1) << " ";
  }
  std::cout << std::endl;
  return 0;
}



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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define test(t) int t;cin>>t;while(t--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
const int MOD = 1e9+7,MAX = 1e5+5;
ll powN(ll a,ll p,ll b)
{
	if(p==0) return 1;
	ll z=powN(a,p/2,b);
	z=(z*z)%b;
	if(p%2) z=(z*a)%b;
	return z;
}
vector<bool> is_prime(MAX+1, true);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
        	for (j = i * i; j <= MAX; j += i)
            	is_prime[j] = false;
    	}
	}
}
ll modInv(ll a)
{
	return powN(a,MOD-2,MOD);
}


int main()
{
	int n;
	cin>>n;
	cout<<n*n<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include <sstream>
#include <vector>

using namespace std;

typedef long long ll;
/****************************************/
int main()
{
    int n;
    ll a,b,x,y;
    scanf("%d%lld%lld%lld%lld",&n,&a,&b,&x,&y);
    ll da=a,xiao=a;
    n--;
    while(n--){
        if(a<b){
            da+=y;
            xiao+=x;
            a=(da+xiao)/2;
        }
        else{
            da-=x;
            xiao-=y;
            a=(da+xiao)/2;
        }
        //printf("%lld %lld ***\n",xiao,da);
    }
    if(xiao<=b&&b<=da){
        printf("YES\n");
    }
    else printf("NO\n");
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
 
typedef long long ll;

#define rep(i,n) for(ll i = 0; i < n; i++)

using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

int main(){
  int N, A[100010] = {};
  cin >> N;
  rep(i,N){
    cin >> A[i];
  }
  sort(A,A+N);
  
  int ans = 0, cnt = 1;
  rep(i,N){
    if(i+1<N && A[i+1] == A[i]) cnt++;
    else{
      if(cnt >= A[i]) ans += cnt - A[i];
      else{
	ans += cnt;
      }
      cnt = 1;
    }
  }
  cout << ans << endl;
  
}


Measured memory_bytes: 640
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<int> h(n);
    REP(i,n) cin>>h[i];
    int tallest = 0;
    int ans = 0;
    REP(i,n){
        if(h[i]>=tallest) ans++;
        tallest = max(tallest, h[i]);
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    x,y,s = map(int,input().split(" "))
    if x == 0 and y == 0 and s == 0:
        break
    cost = 0
    for i in range(s*100//(100+x),s+1):
        for j in range(1,i//2+1):
            if (j*(100+x)//100) + ((i-j)*(100+x)//100) == s:
                cost = max(cost,(j*(100+y)//100 + (i-j)*(100+y)//100))
            else:
                continue
    print(cost)

Measured memory_bytes: 6720
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main() {

    int H, A;
    cin >> H >> A;

    cout << (H + A - 1) / A << endl;
    return 0;
}

Measured memory_bytes: 256
/* ex3_2
   YSK722 */

#include <stdio.h>

int main(void){
    int number;
    scanf("%d", &number);
    if(number <= 0 || 1000 <= number){  // numberが定義域外のとき
        return 1;                       // 処理終了
    }
    if(number % 10 == 3){  // numberの1の位が3のとき
        printf("bon\n");   // "bon"と出力
    }
    else if(number % 10 == 0
            || number % 10 == 1
            || number % 10 == 6
            || number % 10 == 8){  // numberの1の位が0,1,6,8のとき
        printf("pon\n");           // "pon"と出力
    }
    else{                 // numberの1の位が2,4,5,7,9のとき
        printf("hon\n");  // "hon"と出力
    }
        return 0;
}

Measured memory_bytes: 1648
#include<stdio.h>
#define n 100000
#define q 50000

int main(){

  int S[n],T[q];
  int l,r,x,y,count=0,i,m;

  scanf("%d",&x);
  for(i=0;i<x;i++)
    scanf("%d",&S[i]);

  scanf("%d",&y);
  for(i=0;i<y;i++)
    scanf("%d",&T[i]);

  for(i=0;i<y;i++){
    l=0;
    r=x;
    while(l<r){
      m=(l+r)/2;
      if(S[m]==T[i]){
	count++;
	break;
      }
      else if(T[i]<S[m])r = m;
      else l = m+1;
    }
  }
  
  printf("%d\n",count);

  return 0;
}

Measured memory_bytes: 1184
n = int(input())
s = list(input())
if n == 1:
  print(1)
  exit()
i,j = 0,1
ans = 1
while i<j:
  if s[i]==s[j]:
    j+=1
  else:
    ans+=1
    i=j
    j+=1
  if j==n:
    break
print(ans)    

Measured memory_bytes: 4084
n = (int)(input())
s = input()

ret = ""
retc = ''
for i in range(len(s)):
    c = ord(s[i])
    if c + n > ord('Z'):
        retc = c + n - ord('Z') + ord('A') - 1
    else:
        retc = c + n
    ret += chr(retc)

print("{}".format(ret))

Measured memory_bytes: 9152
#include<iostream>
#include<vector>
#define ll long long
using namespace std;

unsigned GetDigit(unsigned num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

int main(){
    ll X,Y;
    string S;
    cin >> X >> Y;
    for(ll i=0; i<=X; i++){
        if(2*i + 4*(X-i) == Y){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3620
while gets do
  s=$_.chomp.split(/[+=]/)
  t =("0".."9").to_a.select {|x|
    s0=s[0].gsub(/X/,x)
    s1=s[1].gsub(/X/,x)
    s2=s[2].gsub(/X/,x)
    reg=Regexp.new("^(0|[1-9][0-9]*)$")
    s0=~reg and s1=~reg and s2=~reg and s0.to_i + s1.to_i == s2.to_i}
  puts (t.length==0) ? "NA" : t[0]
end

Measured memory_bytes: 10508
let read f = stdin.ReadLine() |> f
let x = read int

let dp : bool array = Array.zeroCreate 100001
for i = 0 to 5 do
    dp.[100+i] <- true

for i = 200 to x do
    for j = 100 to 105 do
        match dp.[i-j] with
        | true -> dp.[i] <- true
        | false -> ()

if dp.[x] then 1 else 0
|> printfn "%d"

Measured memory_bytes: 14044
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define Num 1000000007
// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n;
    cin >> n;
    int a[n][n] = {0};
    rep(i,n){
        rep(j,n){
            a[i][j]=0;
        }
    }
    rep(i, n)
    {
        int u, k;
        cin >> u >> k;
        rep(j, k)
        {
            int hoge;
            cin >> hoge;
            a[u-1][hoge-1] = 1;
        }
    }
    rep(i, n)
    {
        rep(j, n)
        {
            cout << a[i][j];
            if (j != n - 1)
                cout << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 3076
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;

using namespace std;


signed main(){
    int n;
    cin>>n;
    int c=0,a;
    rep(i,n){
        cin>>a;
        if(a%2==1)c++;
    }
    if(c%2==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
}

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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

// ポテンシャルつきUnionFindTree
// T: 可換群
template<typename T>
class UnionFindTreeWithPotential {
    const int n;
    std::vector<int> par, size;
    std::vector <T> diff_potential;
public:
    // 要素数と加法単位元を指定して初期化
    UnionFindTreeWithPotential(int n) : n(n), par(n), size(n), diff_potential(n) {
        for (int i = 0; i < n; i++) {
            par[i] = i;
            size[i] = 1;
            diff_potential[i] = T();
        }
    }

    // 要素iが属する集合を表す木の根を求める
    int getRoot(int i) {
        if (par[i] == i) {
            return i;
        } else {
            int r = getRoot(par[i]);
            diff_potential[i] += diff_potential[par[i]];
            return par[i] = r;
        }
    }

    // 要素iのポテンシャル
    T getPotential(int i) {
        getRoot(i);
        return diff_potential[i];
    }

    // 要素iと要素jのポテンシャル差
    T getDiff(int i, int j) {
        return getPotential(j) - getPotential(i);
    }

    // getDiff(i, j) = dとなるように要素iと要素jの属する集合を併合
    void unite(int i, int j, T d) {
        d -= getDiff(i, j);
        i = getRoot(i);
        j = getRoot(j);
        if (i == j)return;
        if (size[i] < size[j])swap(i, j), d = -d;
        par[j] = i;
        size[i] += size[j];
        diff_potential[j] = d;
    }

    // 要素iと要素jが同じ集合に属するか否か
    bool isSame(int i, int j) {
        return getRoot(i) == getRoot(j);
    }

    // 要素iが属する集合の大きさ
    int getSize(int i) {
        return size[getRoot(i)];
    }
};

int N, M;
int L[220000], R[220000], D[220000];

signed main() {
    cin >> N >> M;
    UnionFindTreeWithPotential<int> uf(N + 1);
    for (int i = 0; i < M; i++) {
        cin >> L[i] >> R[i] >> D[i];
        if (uf.isSame(L[i], R[i])) {
            if (uf.getDiff(L[i], R[i]) != D[i]) {
                cout << "No" << endl;
                return 0;
            }
        } else {
            uf.unite(L[i], R[i], D[i]);
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 7424
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;

using namespace std;

int main() {
	int N;
	cin >> N;
	vector<ll> a(N);
	ll sum = 0;
	REP(i, N) {
		cin >> a[i];
		sum += a[i];
	}

	ll x = a[0], y = sum - a[0];
	ll ans = abs(x - y);
	FOR(i, 1, N-2) {
		x += a[i];
		y -= a[i];
		ans = min(ans, abs(x - y));
	}

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


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

int main(){
    string s;
    cin >> s;
    int k = (int)s.size();
    char x;
    int cnt = 0;
    int ans = 0;
    for (int i = 0; i < k; i++){
        x = s[i];
        if (x == 'p'){
            if (cnt > 0) cnt--;
            else{
              cnt++;
              ans--;
            }
        }
        else{
            if (cnt > 0){
                cnt--;
                ans++;
            }
            else{
                cnt++;
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 512
#include <iostream>
#include <fstream>

using namespace std;

int main(){
    int N,X,res;

    cin >> N >> X;
    int m;
    int imin = 1001;
    int zan = X;

    for(int i = 0; i < N; i++)
    {
        cin >> m;
        zan = zan -m;
        if(m < imin)
        {
            imin = m;
        }
    }

    res = (zan / imin) + N;

    cout << res << endl;
    return 0;
}



Measured memory_bytes: 256
///スマホコーディング
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
typedef long long ll;
const int inf=1e9;
int main(){
  int n,a;cin>>n>>a;
  cout<<n*n-a<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<sstream>
#include<stack>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
#define ALL(a)  (a).begin(),(a).end()
const int MOD = 1000000007;
const ll INF = (1LL << 60);
string s, t, u; ll n, m = 6, k, q = 0, ans, sum =1,b,c = INF; 
vector<ll> enum_div(int n) {
    vector<ll> ret;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}
int main() {
    cin >> n >> m;
    vector<ll> rr = enum_div(m);
    sort(ALL(rr));
    if (n == 1) {
        cout << m << endl;
        return 0;
    }
    for(int i = rr.size() -1;i >= 0;i-- ){
        if (rr[i] <= m / n) {
            sum = rr[i];break;
        }
    }
    cout << sum << endl;
}

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

typedef long long ll;
const int maxn = 2e5+9;
const int mod = 1e9+7;

int main(void){
    ll n, k; scanf("%lld%lld", &n, &k);
    ll a[maxn];
    ll ans = 1;
    ll sum[maxn];
    
    for(int i=1; i<=n; ++i) scanf("%lld", &a[i]);
    
    sort(a+1, a+1+n);
    
    int fh=1, l=1, r=n;
    
    if(k&1) {
        ans = a[n];
        if(a[n]<0) fh = -1;
        k--;
        r--;
    }
    
    while(k) {
        ll s1 = a[l] * a[l+1], s2 = a[r] * a[r-1];
        if(s1*fh>s2*fh) {
            ans = (ans * (s1 % mod)) % mod;
            l += 2;
        } else {
            ans = (ans * (s2 % mod)) % mod;
            r -= 2;
        }
        k -= 2;
    }
    ans = (ans + mod) % mod;
    printf("%lld\n", ans);

    return 0;
}


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

#define Fast           ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO             freopen("in.txt", "r", stdin)
#define FC             freopen("out.txt", "w", stdout)
#define aise           cout<<"aise"<<endl
#define pb             push_back
#define pf             push_front
#define ppb            pop_back
#define ppf            pop_front
#define mp             make_pair
#define ll             long long
#define all(x)         x.begin(), x.end()
#define mset(v, a)     memset(v, a, sizeof(v))
#define pll            pair< ll, ll >
#define pd             pair< double, double >
#define ff             first
#define ss             second
#define pi             acos(-1.0)
#define mxN            2010
#define inf            1e14
#define mod            1000000007
#define tc             ll tc;scanf("%lld",&tc);while(tc--)

//NCR iterative
/*voidcomb_table(intN)
{
    for(inti=0; i<=N; ++i)
    {
        for(intj=0; j<=i; ++j)
        {
            if(j==0or j==i)
            {
                C[i][j]=1LL;
            }
            else
            {
                C[i][j]=(C[i-1][j-1]+C[i-1][j]);
            }
        }
    }
}*/


//NCR recursive
/*ll dp[55][55];

ll NCR(ll n,ll r)
{

    if(n==r)
        return dp[n][r]=1;
    if(r==0)
        return dp[n][r]= 1;
    if(r==1)
        return dp[n][r]=n ;
    if(dp[n][r] != -1)
        return dp[n][r];
    return dp[n][r] = NCR(n-1,r)+NCR(n-1,r-1);
}*/

//Sieve:
/*bool Flag[1000010];
vector<ll> Prime;

void sieve()
{

    ll val=sqrt(1000010);
    for(ll i=4;i<=1000005; i+=2) Flag[i]=1;
    for(ll i=3;i <= val;i+=2)
    {

        if(Flag[i]==0)
        {

            for(ll j=i*i;j<=1000005;j+=i) Flag[j]=1;
        }
    }
    Flag[1]=1;
    for(ll i=1;i<=1000000;i++)
        if(Flag[i]==0) Prime.pb(i);
}*/


//Conversion
/*string bin(ll x)
{

    string ret;
    while(x)
    {

        ll t=x%2;
        char c;
        if(t==1)
            c='1';
        else
            c='0';
        ret.pb(c);
        x/=2;
    }
    reverse(all(ret));
    return ret;
}*/

/*ll lcm(ll x, ll y)
{

    ll ret=__gcd(x,y);
    return (x*y)/ret;
}*/

/*ll dx[]= {0,0,1,-1};
ll dy[]= {1,-1,0,0};*/

int main()
{
    ll n, x,y;
    cin >> n >> x >> y;
    vector<ll> v(n+1, 0);
    for(ll i=1;i<=n;i++)
    {

        for(ll j=i+1;j<=n;j++)
        {

            ll d1=j-i;
            ll d2=abs(i-x)+abs(j-y)+1;
            d1=min(d1,d2);
            v[d1]++;
        }
    }
    for(ll i=1;i<=n-1;i++) cout << v[i] << endl;
}


Measured memory_bytes: 3620
using System;

namespace AtCoderBeginnerContest175
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = Console.ReadLine();

			var count = 0;
			var max = 0;
			for (var i = 0; i < 3; i++)
			{
				if (input[i] == 'R')
				{
					count++;
					if(count > max)
					{
						max = count;
					}
				}
				else
				{
					count = 0;
				}
			}

			Console.WriteLine(max);
		}
	}
}


Measured memory_bytes: 25956
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()
#define print(s) cout << (s) << endl

bool isPrime(int n) {
    if (n == 2) return true;
    else if (n % 2 == 0) return false;
    for (int i = 3; i <= sqrt(n); i+=2) {
        if (n % i == 0) return false;
    }
    return true;
}

int main() {
    vector<long> v;
    v.push_back(2);
    int i = 3;
    while(v.size() < 10000) {
        if (isPrime(i)) {
            v.push_back(v.back() + i);
        }
        i+=2;
    }
    int n;
    while(cin >> n, n) {
        cout << v[n-1] << endl;
    }
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;

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

int main() {
    ios::sync_with_stdio(false);
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));

    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    int ans = INT_MAX;
    for (int b = 1; b < pow(2, n); b++) {
        vector<int> aa(m);
        int tmpans = 0;
        int cb = b;

        int i = 0;
        while (cb > 0) {
            // printf("b=%d, cb=%d, cb&1=%d\n", b, cb, cb & 1);
            if ((cb & 1) == 1) {
                tmpans += c[i];
                for (int j = 0; j < m; j++) {
                    aa[j] += a[i][j];
                }
            }
            cb = cb >> 1;
            i++;
        }

        int tmpx = 0;
        for (int aai : aa) {
            if (aai >= x) {
                tmpx++;
            }
        }
        // printf("b=%d, tmpx=%d, ans=%d\n", b, tmpx, tmpans);
        if (tmpx == m) {
            // printf("i=%d, tmpx=%d,tmpans:%d\n", i, tmpx, tmpans);
            ans = min<int>(ans, tmpans);
        }
    }

    if (ans == INT_MAX) {
        ans = -1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    string s;
    cin >> s;
    if (s == "AAA" || s == "BBB") cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
MOD=10**9+7
t=[]
r=[]
for i in range(0,n+1):
    t.append(i)
for i in range(n,-1,-1):
    r.append(i)

fr=0
af=0
for i in range(0,k-1):
    fr+=t[i]
    af+=r[i]

ans=0
for i in range(k-1,n+1):
    fr+=t[i]
    #print(fr)
    af+=r[i]
    ans+=(af-fr+1)%MOD

print(ans%MOD)


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

class Node
{
  public:
  int p = -1, s = -1, l, r, d, h;
};

int getDepth(vector<Node>& nodes, Node& cur, int d)
{
  cur.d = d;
  int hl = 0, hr = 0;
  if (cur.l != -1) hl = getDepth(nodes, nodes.at(cur.l), d + 1) + 1;
  if (cur.r != -1) hr = getDepth(nodes, nodes.at(cur.r), d + 1) + 1;
  return cur.h = hl > hr ? hl : hr;
}

int main()
{
  int n, r;
  cin >> n;
  vector<Node> nodes(n);
  for (int i = 0; i < n; i++) {
    int id, l, r;
    cin >> id >> l >> r;
    nodes.at(id).l = l;
    if (l != (-1)) {
      nodes.at(l).p = id; nodes.at(l).s = r;
    }
    nodes.at(id).r = r;
    if (r != (-1)) {
      nodes.at(r).p = id; nodes.at(r).s = l;
    }
  }
  while(n--) {
    r = nodes.at(n).p == -1 ? n : r;
  }
  getDepth(nodes, nodes.at(r), 0);
  for (auto itr = nodes.begin(); itr != nodes.end(); ++itr) {
    int deg = 0;
    deg += (itr->l != -1) + (itr->r != -1);
    cout << "node " << ++n    << ": "
    << "parent = "  << itr->p << ", "
    << "sibling = " << itr->s << ", "
    << "degree = "  << deg    << ", "
    << "depth = "   << itr->d << ", "
    << "height = "  << itr->h << ", ";
    if (itr->p == -1) cout << "root" << endl;
    else if (itr->h == 0)  cout << "leaf" << endl;
    else cout << "internal node" << endl;
  }
  return 0;
}

Measured memory_bytes: 3024
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
#define forn(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define fore(i,b,a)for(int i=(b),_a=(a);i>=_a;i--)
#define rep(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define vpii vector<pii>
#define m_p make_pair
#define re return
#define pb push_back
#define si set<int>
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
#define mod 1000000007
#define INF 1000000007
#define x1 XZVJDFADSPFOE
#define y1 GASDIJSLDAEJF
#define x2 DFDAJKVOHKWIW
#define y2 PSFSAODSXVNMQ
#define LLINF 0x3f3f3f3f3f3f3f3fLL
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
ll quickpower(ll n,ll k){
	ll ans=1;
	while(k){
		if(k%2){
			ans*=n;
			ans%=mod;
		}
		n*=n;
		n%=mod;
		k/=2;
	}
	return ans;
}
string int_to_string(int n)
{
	string s="";
	while(n)
	{
		int now=n%10;
		s+=now+'0';
		n/=10;
	}
	reverse(s.begin(),s.end());
	return s;
}
int string_to_int(string s)
{
	int n=0;
	rep(i,s.size())
	{
		n*=10;
		n+=s[i]-'0';
	}
	return n;
}
int main()
{
	ios::sync_with_stdio(0);
	//think twice,code once
	ll n,k;
	cin>>n>>k;
	cout<<min(n%k,k-n%k)<<endl;
	return 0;
}



Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**6)


class Node:
    def __init__(self, p, l, r):
        self.p = p
        self.l = l
        self.r = r


N = int(input())
T = [Node(-1, -1, -1) for _ in range(N)]


def preorder_parse(u):
    if u == -1:
        return
    print(' ' + str(u), end='')
    preorder_parse(T[u].l)
    preorder_parse(T[u].r)


def inorder_parse(u):
    if u == -1:
        return
    inorder_parse(T[u].l)
    print(' ' + str(u), end='')
    inorder_parse(T[u].r)


def postorder_parse(u):
    if u == -1:
        return
    postorder_parse(T[u].l)
    postorder_parse(T[u].r)
    print(' ' + str(u), end='')


def main():
    for _ in range(N):
        v, l, r = map(int, input().split())
        T[v].l = l
        T[v].r = r
        if l != -1:
            T[l].p = v
        if r != -1:
            T[r].p = v

    root = 0
    for i, t in enumerate(T):
        if t.p == -1:
            root = i

    print('Preorder')
    preorder_parse(root)
    print('')
    print('Inorder')
    inorder_parse(root)
    print('')
    print('Postorder')
    postorder_parse(root)
    print('')


if __name__ == '__main__':
    main()



Measured memory_bytes: 5624
#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>;

int main(){
	string s;
	cin >> s;
	int counts = 0;
	int time = s.size()/2;
	rep(i,time){
		if(s[i] != s[s.size()-i-1]) counts++;
	}
	cout << counts << endl;
}

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

struct grid{
  char g[12][12];
  int turn;
};

void fill(grid &gr,char cell,char color,int fx,int fy){
  if(gr.g[fy][fx] != cell){
    return;
  }
  gr.g[fy][fx] = color;
  fill(gr,cell,color,fx+1,fy);
  fill(gr,cell,color,fx-1,fy);
  fill(gr,cell,color,fx,fy+1);
  fill(gr,cell,color,fx,fy-1);
}

bool check(grid &gr,char cell,int x,int y){
  bool flag = 1;
  for(int i=1;i<=y;i++){
    for(int j=1;j<=x;j++){
      if(cell != gr.g[i][j]){
        flag = 0;
        break;
      }
    }
  }
  return flag;
}

int main(){
  while(1){
    int x,y;
    cin >> x >> y;
    if(x==0 && y==0)
      break;
    grid first;
    for(int i=1;i<=y;i++){
      for(int j=1;j<=x;j++){
          cin >> first.g[i][j];
      }
    }

    first.turn = 0;
    queue<grid> q;
    q.push(first);

    while(1){
      grid G = q.front();
      q.pop();
      char cell;
      cell = G.g[1][1];
      if(check(G,cell,x,y)){
        cout << G.turn << endl;
        break;
      }
      if(cell != 'R'){
        grid tmp = G;
        tmp.turn = tmp.turn+1;
        fill(tmp,cell,'R',1,1);
        q.push(tmp);
      }
      if(cell != 'G'){
        grid tmp = G;
        tmp.turn = tmp.turn+1;
        fill(tmp,cell,'G',1,1);
        q.push(tmp);
      }
      if(cell != 'B'){
        grid tmp = G;
        tmp.turn = tmp.turn+1;
        fill(tmp,cell,'B',1,1);
        q.push(tmp);
      }
    }
  }
  return 0;
}


Measured memory_bytes: 40228
// V - Subtree
// https://atcoder.jp/contests/dp/tasks/dp_v
// https://www.youtube.com/watch?v=r9hbdyVkz-I
#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int main(){
    char a;
    cin>>a;
    if(a>='a') cout<<'a';
    else cout<<'A';
    cout<<endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional>
using namespace std;
int main(void){
    int N;
    cin>>N;
    string S;
    for(int i=0;i<N;i++){
        cin>>S;
        if(S=="Y"){
            cout<<"Four"<<endl;
            return 0;
        }
    }
    cout<<"Three"<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	char str[3];
	int i, sum;
	
	scanf("%s", str);
	
	sum = 0;
	for (i = 0; i < 3; i++){
		if (str[i] == '1'){
			sum++;
		}
	}
	
	printf("%d\n", sum);
	
	return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int h = sc.nextInt();
    int w = sc.nextInt();
    int cnt = 0;
    for(int i = 0;i < n;i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      if(h<=a&&w<=b)cnt++;
    }
    System.out.println(cnt);
  }
}

Measured memory_bytes: 25424
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<math.h>


#define CI cin >>
#define CO cout <<
#define E << endl;

using namespace std;

int main(void) {
	double r = 0;
	double PI = acos(-1);
	CI r;
	printf("%.7lf %.7lf",r * r * PI,2 * r * PI);
}

Measured memory_bytes: 3172
#include <iostream>
#include <vector>
#include <map>

using namespace std;
const int N = 1000 * 1000 + 1;
map<int, int> a;

int main(){
   // ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    int s = 0;
    for(int i = 0;i < n;i ++){
        int x;
        cin>>x;
        map<int, int>::iterator it = a.find(x);
        if(it!=a.end()){
            if(it->second > 0)it->second--;else it->second++;
        }else{
            a.insert(make_pair(x, 1));
        }
    }
    for(auto i : a)s += i.second;
    cout<<s;
    return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>

#define MAX 10000

int parent(int);
int left(int);
int right(int);

int main()
{
  int H, i, A[MAX];

  scanf("%d", &H);
  
  for( i = 1 ; i <= H ; i++ ) scanf("%d", &A[i]);

  for( i = 1 ; i <= H ; i++ ){
    printf("node %d: key = %d, ", i, A[i]);
    if( parent(i) >= 1 ) printf("parent key = %d, ", A[parent(i)]);
    if( left(i) <= H ) printf("left key = %d, ", A[left(i)]);
    if( right(i) <= H ) printf("right key = %d, ", A[right(i)]);
    printf("\n");
  }

  return 0;
}

int parent(int i)
{
  return i / 2;
}

int left(int i)
{
  return 2 * i;
}

int right(int i)
{
  return 2 * i + 1;
}

Measured memory_bytes: 608
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	ll N, M;
	cin >> N >> M;
	vector<ll>A(N);
	vector<ll>B(N);
	vector<pair<ll,ll>>V(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i] >> B[i];
		V[i].first = A[i];
		V[i].second = B[i];
	}
	sort(V.begin(), V.end());
	ll sum = 0;
	ll count = 0;
	for (int i = 0; i < N; ++i) {
		if (M <= count+V[i].second) {
			cout << sum + (M - count)*V[i].first << endl;
			return 0;
		}
		else {
			count += V[i].second;
			sum += V[i].first*V[i].second;
		}
	}
	return 0;
}


Measured memory_bytes: 3328