akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean high=false;
		boolean low=false;
		int zero=0;
		long sum=0;
		ArrayList<Integer> llist=new ArrayList<>();
		ArrayList<Integer> hlist=new ArrayList<>();
		for(int i=0; i<n; i++){
			int a=sc.nextInt();
			sum+=Math.abs(a);
			if(a>0){
				hlist.add(a);
				high=true;
			}else if(a<0){
				llist.add(a);
				low=true;
			}else{
				zero++;
			}
		}
		if(sum==0){
			System.out.println(sum);
			for(int i=1; i<zero; i++){
				System.out.println("0"+" "+"0");
			}
			return;
		}
		int cl=0;
		int ch=0;
		String s="";
		if(!(high && low)){
			if(zero>0){
				if(low){
					hlist.add(-llist.get(cl++));
					s="0 "+String.valueOf(llist.get(0));
					zero--;
				}else{
					llist.add(-hlist.get(ch++));
					s="0 "+String.valueOf(hlist.get(0));
					zero--;
				}
			}else{
			if(low){
				Collections.sort(llist);
				Collections.reverse(llist);
				hlist.add(llist.get(0)-llist.get(1));
				cl+=2;
				sum+=2*llist.get(0);
				s=String.valueOf(llist.get(0))+" "+String.valueOf(llist.get(1));
			}else{
				Collections.sort(hlist);
				llist.add(hlist.get(0)-hlist.get(1));
				ch+=2;
				sum-=2*hlist.get(0);
				s=String.valueOf(hlist.get(0))+" "+String.valueOf(hlist.get(1));
			}
			}
		}
		int ii=0;
		int jj=0;
		System.out.println(sum);
		if(!s.equals("")){
			System.out.println(s);
		}
		int lsize=llist.size();
			while(lsize>cl+1){
				ii=hlist.get(ch++);
				jj=llist.get(cl++);
				hlist.add(ii-jj);
				System.out.println(ii+" "+jj);
			}
		int hsize=hlist.size();
			while(hsize>ch+1){
				 ii=llist.get(cl++);
				 jj=hlist.get(ch++);
				llist.add(ii-jj);
				System.out.println(ii+" "+jj);
			}
			System.out.println(hlist.get(ch)+" "+llist.get(cl));
		for(int i=0; i<zero; i++){
			System.out.println(sum+" "+0);
		}
	}
}


Measured memory_bytes: 68192
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
BC = [list(map(int, input().split())) for _ in range(Q)]

ans = sum(A)
d = {}
for a in A:
    try:
        d[a] += 1
    except:
        d[a] = 1

for b, c in BC:
    try:
        pre_c = d[b]
        d[b] = 0
    except:
        print(ans)
        continue

    ans += (c - b) * pre_c
    try:
        d[c] += pre_c
    except:
        d[c] = pre_c
    print(ans)

Measured memory_bytes: 35932
#include <bits/stdc++.h>
#define X first
#define Y second
#define PB pop_back
#define LL long long
#define pii pair<LL,LL>
#define MEM(x,y) memset(x,y,sizeof(x))
#define bug(x) cout<<"debug "#x" is "<<x<<endl;
#define FIO ios::sync_with_stdio(false);
#define ALL(x) x.begin(),x.end()
#define LOG 25
#define lson(x) ((x)<<1)
#define rson(x) ((x)<<1|1)
#define vi vector<long long>

using namespace std;
typedef long long ll;
const ll mod=1e9;
const ll inf = 1e18+7;
const int maxn = 3e6+7;

int main(){
    FIO
    ll a,b,n;
    cin>>a>>b>>n;
    std::default_random_engine random(time(NULL));
    std::uniform_int_distribution<ll> dis1(0, n);
    ll ans=0;
    for(int i=0;i<maxn;i++){
        ll x = dis1(random);
        ans=max(ans,(a*x)/b-a*(x/b));
    }
    cout<<ans<<endl;
    return 0;
}
/**
5
6
7
1 2 2 4
2 4 3 3
3 4 2 4
1 3 4 1
4 6 2 1
3 5 2 0
5 4 3 2
**/


Measured memory_bytes: 3608
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main()
        {
            int s, m, h;
            s = int.Parse(Console.ReadLine());
            h = s / 3600;
            m = s / 60-60*h;
            s = s % 60;
            Console.WriteLine("{0}:{1}:{2}",h,m,s);
        }
    }
}



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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;
//const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
int MOD = 998244353;
const int maxn = (int) 1e5 + 20;
const int maxm = (int) 1e6 + 20;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL mod = MOD)
{
    if(n < 0) a = fp(a, mod - 2, mod), n = -n;
    LL res = 1; for(; n; n >>= 1, a = a * a % mod) if(n & 1) res = res * a % mod; return res;
}

struct Mint
{
    LL x;
    Mint() {x = 0;}
    Mint(int _x): x(_x) {}
    Mint(LL _x): x(_x) {}
    Mint operator - () const{
        return Mint(MOD - x);
    }
    Mint operator + (const Mint &rhs) const{
        LL res = x + rhs.x; if(res >= MOD) res -= MOD; return Mint(res);
    }
    Mint operator - (const Mint &rhs) const{
        LL res = x - rhs.x; if(res < 0) res += MOD; return Mint(res);
    }
    Mint operator * (const Mint &rhs) const{
        return Mint(x * rhs.x % MOD);
    }
    Mint operator / (const Mint &rhs) const{
        return Mint(x * fp(rhs.x, -1) % MOD);
    }
    bool operator == (const Mint &rhs) const{
        return x == rhs.x;
    }
    bool operator != (const Mint &rhs) const{
        return x != rhs.x;
    }
    friend ostream& operator << (ostream &out, const Mint &rhs){
        return out << rhs.x;
    }
    friend istream& operator >> (istream &in, Mint &rhs){
        return in >> rhs.x;
    }
};

int n, m;
Mint dp[6666][6666 + 6666];

void work()
{
    cin >>n >>m;
    MOD = m;

    int mid = 6666;
    dp[0][mid] = Mint(1);

    for(int i = 1; i <= n * 3; i++)
    {
        for(int j = mid - i / 2; j <= mid + i; j++)
        {
            dp[i][j] = dp[i - 1][j - 1];
            if(i >= 2) dp[i][j] = dp[i][j] + dp[i - 2][j + 1] * Mint(i - 1);
            if(i >= 3) dp[i][j] = dp[i][j] + dp[i - 3][j] * Mint(i - 1) * Mint(i - 2);
        }
    }

    Mint ans = Mint(0);
    for(int j = mid; j <= mid + n * 3; j++) ans = ans + dp[n * 3][j];
    cout <<ans <<endl;
}


int main(int argc, char **argv)
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
//    pre();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


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

int main() {
	int N, a;
	cin >> N;
	vector<int> A;
	for(int i=0;i<N;i++){
		cin >> a;
		if(a % 2 == 0){
			A.push_back(a);
		}
	}

	for(auto num:A){
		if(num % 3 != 0 && num % 5 != 0){
			cout << "DENIED" << endl;
			return 0;
		}
	}
	cout << "APPROVED" << endl;

}


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

#define INF (1LL << 63)

int main(){
    int N;
    cin >> N;
    vector<vector<pair<int,int>>> G(N);
    vector<int> col(N,-1);
    col[0] = 0;

    rep(i,N-1){
        int a,b,w;
        cin >> a >> b >> w;
        a--, b--;
        G[a].push_back({b,w});
        G[b].push_back({a,w});
    }

    vector<bool> visited(N,false);
    queue<int> Q;
    Q.push(0);
    while(!Q.empty()){
        int now = Q.front(); Q.pop();
         if(visited[now]) continue;
        visited[now] = true;
        for(pair<int,int> e : G[now]){
            if(visited[e.first]) continue;
            if(e.second%2) col[e.first] = !col[now];
            else col[e.first] = col[now];
            Q.push(e.first);
        }
    }

    for(auto c : col) {
        cout << c << endl;
    }
}


Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,k;
  cin >> a >> b >> k ;

  for (int i=0 ; i<k;i++){
    if (i % 2 == 0){
      if (a%2 == 1) a--;
      b += a/2;
      a /= 2;
    }
    else{
      if (b%2 == 1) b--;
      a += b/2;
      b /= 2;
    }
  }

  cout << a << " " << b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define f1 first
#define s2 second
#define pb push_back
#define mp make_pair
#define ll long long
#define fri(a) freopen(a,"r",stdin);
#define fro(a) freopen(a,"w",stdout);
const int N=1e5;

int n,ans,a;
vector<int>dizi;

int main(){
	//fri("in.txt");
	//fro("out.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		dizi.pb(a);
	}
	sort(dizi.begin(),dizi.end());
	for(int i=0;i<n;i++){
		for(int p=i+1;p<n;p++){
			auto j=lower_bound(dizi.begin(),dizi.end(),dizi[i]+dizi[p]);
			ans+=j-(dizi.begin()+p+1);
		}
		
	}
	//cout<<dizi[n-1]<<endl;
	cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
 
int main(){
  ll l,r;
  cin >> l >> r;

  ll ans = 2020;
  for(ll i = l; i <= r; i++){
    if(i-l > 2019) break;
    for(ll j = l; j <= r; j++){
      if(i==j) continue;
      if(j-l>2019) break;
      ans = min(ans, (i*j)%2019);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
mod = 10**9 + 7

def iip(listed = False):
    ret = [int(i) for i in input().split()]
    if len(ret) == 1 and not listed:
        return ret[0]
    return ret

def soinsuu_bunkai(n):
    ret = []
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):
    if n <=0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n-r+1, n+1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r+1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        #print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):
    return power(n, mod-2)

def power(n, p):
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p//2) ** 2) % mod
    if p % 2 == 1:
        return (n * power(n, p-1)) % mod

#####################################################ライブラリ集ここまで

def main():
    s = input()
    if s[2] != s[3]:
        print("No")
        return 0
    if s[4] != s[5]:
        print("No")
        return 0
    print("Yes")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    int t,n,i,j,a,sum=0;
    cin>>n>>a;
    int ss[n];
    for(i=0;i<n;i++)cin>>ss[i];
    sort(ss,ss+n);
    for(i=0;i<a;i++)
    {
        sum+=ss[i];
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3628
/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

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

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pil pair<int,ll>
const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const double pi=2*acos(0.0);
const double esp=1e-9;
int Set(int N,int pos) {
    return N=N | (1<<pos);
}
int reset(int N,int pos) {
    return N= N & ~(1<<pos);
}
bool check(int N,int pos) {
    return (bool)(N & (1<<pos));
}

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

int main() {

    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    ///cin>>test;
    for(int cs=1; cs<=test; ++cs) {
       int a,b;
       cin>>a>>b;
       int l1,l2;bool ck=false;
       for(int i=0;i<=a;++i){
          l1=i*4,l2=(a-i)*2;
          if(l1+l2==b){
            ck=true;
            break;
          }
       }
       if(ck){
        cout<<"Yes"<<endl;
       }
       else{
        cout<<"No"<<endl;
       }
    }
    return 0;
}



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

using namespace std;

int main(void){
  int n, c = 0;
  int i, j, k;

  cin >> n;
  for(i = 1; i <= n; i++){
    if(i < 10){
      c++;
    }
    else if(i < 100){
      
    }
    else if(i < 1000){
      c++;
    }
    else if(i < 10000){
      
    }
    else if(i < 100000){
      c++;
    }
  }

  cout << c << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
import copy
from collections import deque


input = sys.stdin.readline

N = int(input())
h = list(map(int, input().split()))
count = 0

def water(array):
    global count
    if array != []:
        minimum = min(copy.deepcopy(array))
        count += minimum
        for i in range(len(array)):
            array[i] -= minimum
    indx = [i for i, x in enumerate(array) if x == 0]
    if len(indx) == 0:
        return None
    elif len(indx) == 1:
        water(array[:indx[0]])
        water(array[indx[0]+1:])
    elif len(indx) > 1:
        water(array[:indx[0]])
        water(array[indx[-1]+1:])
        for i in range(len(indx)-1):
            water(array[indx[i]+1:indx[i+1]])

water(h)
print(count)

Measured memory_bytes: 3572
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl;
#define INF 1ll<<60;
#include <map>
#include <math.h>

using ll = long long;
using namespace std;

int main(){
    int n, c, k, t;
    cin >> n >> c >> k;
    vector<int> vec;
    rep(i, n){
        int t; cin >> t;
        vec.push_back(t);
    }
    sort(vec.begin(), vec.end());

    int passe = 1, bus=1, first_time = vec[0];
    reps(i, 1, n){
        if(vec[i]-first_time > k || passe>=c){
                bus++;
                first_time = vec[i];
                passe=1;
            }
        else passe++;
        }
    cout << bus << endl;
}


Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <tuple>
#include <unordered_map>

std::vector<std::vector<int>> t_arr;
std::vector<int> visited;
std::vector<int> depth_arr;

int dfs(int current, int depth, std::unordered_map<int, int>& parents, std::vector<int>& loop){
  //std::cout << current << std::endl;
  int max_depth = -1, max_node = -1;
  for(auto&& it: t_arr[current]){
    //if(visited[it]) continue;
    if(parents.count(it) > 0){
      if(max_depth < parents[it]){
        max_depth = parents[it];
        max_node = it;
      }
    }
  }
  if(max_depth >= 0){
    loop.push_back(max_node);
    loop.push_back(current);
    depth_arr[max_node] = depth+1;
    depth_arr[current] = depth;
    return 1;
  }
  parents[current] = depth;
  for(auto&& it: t_arr[current]){
    if(visited[it]) continue;
    int dfsa = dfs(it, depth+1, parents, loop);
    if(dfsa == 1){
      if(loop[0] == current) return 2;
      loop.push_back(current);
      depth_arr[current] = depth;
      return 1;
    }else if(dfsa == 2){
      return 2;
    }
  }
  parents.erase(current);
  visited.at(current) = 1;
  return 0;
}

int main(){
  int N,M;
  std::cin >> N >> M;
  t_arr = std::vector<std::vector<int>>(N);
  for(int i = 0; i < M; i++){
    int a,b;
    std::cin >> a >> b;
    a--; b--;
    t_arr[a].push_back(b);
  }
  visited = std::vector<int>(N);
  depth_arr = std::vector<int>(N, -1);

  std::vector<int> loop;
  for(int n = 0; n < N; n++){
    if(visited[n]) continue;
    std::unordered_map<int,int> parents;
    if(dfs(n, 0, parents, loop)){
      break;
    }
  }
  if(loop.size() == 0){
    std::cout << -1 << std::endl;
  }else{
    std::vector<int> l2;
    l2.push_back(loop[loop.size()-1]);
    int current = l2[0];
    while(current != loop[0]){
      int min_d = -1, min_n = -1;
      for(auto&& it: t_arr[current]){
        if(depth_arr[it] == -1) continue;
        if(depth_arr[it] > min_d){
          min_d = depth_arr[it];
          min_n = it;
        }
      }
      l2.push_back(min_n);
      current = min_n;
    }

    std::cout << l2.size() << std::endl;
    for(auto&& it: l2){
      std::cout << it+1 << " ";
    }
    std::cout << std::endl;
  }

  return 0;
}



Measured memory_bytes: 512
s = gets.chomp
Q = gets.chomp.to_i
r = Array.new(0)
r.push("")
r.push("")
x = 0
for i in 1..Q do
    str = gets.split
    if str[0] == "1"
        x += 1
        x %= 2
    else
        if str[1] == "1"
            y = (x+1)%2
            r[y] << str[2]
        else
            r[x] << str[2]
        end
    end
end
if x % 2 == 0
    s << r[0]
    s.reverse!
    s << r[1]
    s.reverse!
else
    s << r[0]
    s.reverse!
    s << r[1]
end
puts s

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1<<25;
const ll INFL = 1223372036854775807;
const ll mod = 1000000007;



vector <int> dx = { 1,-1,0,0,1,1,-1,-1 };
vector<int> dy = { 0,0,1,-1,1,-1,1,-1 };



int main() {

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

	cout << 100 << ' ' << 100 << endl;

	VVC v(100, VC(100, '.'));

	REP(i, 50)REP(j, 100)v[i][j] = '#';

	a--;
	b--;


	REP(i, 50){
		REP(j, 100) {
			if (a == 0)break;
			bool c = true;
			REP(k, 8) {
				int ny = i + dy[k], nx = j + dx[k];
				if (ny < 0 || 48 <= ny || nx < 0 || 100 <= nx)continue;
				if (v[ny][nx] == '.')c = false;
			}
			if (c) {
				v[i][j] = '.';
				a--;
			}
			if (a == 0)break;
		}
		if (a == 0)break;
	}

	FOR(i, 53,100) {
		REP(j, 100) {
			if (v[i][j] == '#')continue;
			if (b == 0)break;
			bool c = true;
			REP(k, 8) {
				int ny = i + dy[k], nx = j + dx[k];
				if (ny < 51 || 100 <= ny || nx < 0 || 100 <= nx)continue;
				if (v[ny][nx] == '#')c = false;
			}
			if (c) {
				v[i][j] = '#';
				b--;
			}
			if (b == 0)break;
		}
		if (b == 0)break;
	}

	REP(i, 100) {
		REP(j, 100)cout << v[i][j];
		cout << endl;
	}



	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const int MOD_N = 1000000000 + 7;

    public static void Main()
    {
        var s = Console.ReadLine();

        var first = ToInt(s[0]) * 10 + ToInt(s[1]);
        var second = ToInt(s[2]) * 10 + ToInt(s[3]);

        if (1 <= first && first <= 12)
        {
            if (1 <= second && second <= 12)
            {
                Console.WriteLine("AMBIGUOUS");
            }
            else
            {
                Console.WriteLine("MMYY");
            }
        }
        else
        {
            if (1 <= second && second <= 12)
            {
                Console.WriteLine("YYMM");
            }
            else
            {
                Console.WriteLine("NA");
            }
        }
    }

    private static int ToInt(char c) => c - '0';
}


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

int main(){
   string s;    cin >> s;
   int n = s.size()-1;
   ll sum=0;
   for(int i=0; i<(1<<n); i++){
       ll tmp=0;
       for(int j=0; j<n; j++){
           tmp += (s.at(j)-'0');
           if(i & 1<<j){
               sum += tmp;
               tmp = 0;
           }
           tmp *= 10;
       }
       sum += tmp+s.at(s.size()-1)-'0';
   }
   cout << sum << endl;
}

Measured memory_bytes: 256
N = int(input())
args = list(map(int, input().split()))

c = 0
isOdd = False
while True:
    for i in range(N):
        if args[i] % 2 == 1:
            isOdd = True
        args[i] /= 2
    if isOdd:
        break
    c += 1

print(c)


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

int main()
{
	string S;
	cin >> S;
	int len = S.length();

	int ans = len;
	for (int i = 1; i < len; i += 1) {
		if (S[i] != S[i - 1]) {
			int v = max(i, len - i);
			ans = min(ans, v);
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  ll n, k;
  cin >> n >> k;
  ll ar[n];
  for(ll x = 0; x < n; x++) {
  	cin >> ar[x];
  }
  
  ll dp[k+1];
  memset(dp, -1, sizeof(dp));
  dp[0] = 0;
  
  for(ll x = 1; x <= k; x++) {
    ll f = 0;
    for(ll y = 0; y < n; y++) {
      if(x >= ar[y]) {
        if(dp[x-ar[y]] == 0) {
          f = 1;
          break;
        }
      }
    }
    if(f == 1) {
      dp[x] = 1;
    }
    else {
      dp[x] = 0;
    }
  }
  
  if(dp[k] == 1) {
  	cout << "First";
  }
  else {
  	cout << "Second";
  }
}

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

int main() {
  int N,K;
  int ans = 1;

  cin >> N;
  cin >> K;
  for (int i=0; i<N; i++){
      if (ans*2 <= ans + K) {
          ans *= 2;
      } else {
          ans += K;
      }
  }   
  cout << ans << endl;
}

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

int main()
{
char x[100002];
int i;

memset( x, '\0', sizeof(x));
scanf("%s", x);
for(i=0; x[i] != '\0'; i+=2)
printf("%c", x[i]);
printf("\n");
return 0;
}

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

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef long double LD;
typedef pair<LD, LD> PLDLD;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define CLR(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()

LL INF=1e15+7;

int main()
{
    /*int n,m;
    cin>>n>>m;
    vector<PLL> p(n),q(n);
    REP(i,n)
    {
        LL a,b;
        cin>>a>>b;
        p[i]=PLL(a,b);
    }
    REP(i,m)
    {
        LL a,b;
        cin>>a>>b;
        q[i]=PLL(a,b);
    }

    REP(i,n)
    {
        int ans=0;
        LL mdis=INF,dis;
        REP(j,m)
        {
            dis=abs(p[i].first-q[j].first) + abs(p[i].second - q[j].second);
            if(dis<mdis)
            {
                mdis=dis;
                ans=j;
            }
        }
        cout<<ans+1<<endl;

    }*/

    int a,b;
    cin>>a>>b;
    cout<<(a+b)%24<<endl;
}



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

int dp[101][100 * 100 + 1], w[100], v[100];

int main()
{
	int n, W;
	cin >> n >> W;
	for (int i = 0; i < n; ++i)cin >> v[i] >> w[i];
	fill(dp[0], dp[0] + 10001, 0x3f3f3f3f);
	dp[0][0] = 0;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j <= 10000; ++j){
			if (j < v[i])dp[i + 1][j] = dp[i][j];
			else dp[i + 1][j] = min(dp[i][j], dp[i][j - v[i]] + w[i]);
		}
	}
	int res = 0;
	for (int i = 0; i <= 10000; ++i)if (dp[n][i] <= W)res = i;
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 7056
#include "bits/stdc++.h"
using namespace std;

#define timesaver ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
typedef long long ll ;
typedef long double ldb ;
 
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define nl "\n"
 
#define all( x ) x.begin(),x.end()
#define sz( x ) ( int )( x ).size( )
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );

int main( ) {
	timesaver ;
	ll n, m, a;
	cin >> n >> m;
	while(m--) {
		cin >> a;
		if(n-a < 0){
			cout << -1;
			return 0;
		}
		n -= a;
	}
	cout << n;
  return 0;
}

Measured memory_bytes: 3616
N,M=map(int,input().split())

if N%2==1:
    S=1
    L=N
    for i in range(M):
        print(S+i,L-i)
else:
    S=1
    L=N
    for i in range(M):
        if S+i>N/4:
            print(S+i,L-i-1)
        else:
            print(S+i,L-i)

Measured memory_bytes: 69736
#include <stdio.h>

int main(void)
{
	char s[4];

	scanf("%s", s);

	if (s[0] == s[1] && s[1] == s[2])
	{
		printf("No\n");
	}
	else
	{
		printf("Yes\n");
	}

	return 0;
}

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

int main() {
  int n,m,c;
  cin >> n >> m >> c;
  vector<int> b(m);
  for(int i=0;i<m;i++){
    cin >> b.at(i);
  }
  vector<vector<int>> data(n, vector<int>(m));
  int ans=0;
  for (int i = 0; i < n; i++) {
    int sum=0;
    for (int j = 0; j < m; j++) {
      cin >> data.at(i).at(j);
      sum=sum+(data.at(i).at(j))*b.at(j);
    }
    if(sum+c>0)
    ans++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
	char *a; int N, i, j;
	
	while(scanf("%d",&N) && N!=0){
		a=(char*)malloc((2*N+1)*sizeof(char));
		a[1]=0; for(i=2; i<=2*N; i++) a[i]=1;
		for(i=2; i<=(int)sqrt(2*N); i++){
			if(a[i]!=0) for(j=2*i; j<=2*N; j+=i) a[j]=0;
		}
		for(j=0, i=N+1; i<=2*N; i++) j+=a[i];
		free(a);
		printf("%d\n",j);
	}
}

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

int main(){
    string w;
    cin >> w;
    set<char> se;
    for(char c : w){
        if(se.find(c) == se.end()) se.insert(c);
        else se.erase(c);
    }
    if(se.empty()) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;
int main()
{
    int a, b, c,x ;
    cin >> a >> b >> c;
  x =max(a, max(b, c));
    cout << a + b + c - x << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long dp[100099][3];
int n,k,a[100099][3];
int main()
{
   cin>>n;
   for (int i=0;i<n;i++)
   {
       cin>>a[i][0]>>a[i][1]>>a[i][2];
   }
   dp[0][0]=a[0][0];
   dp[0][1]=a[0][1];
   dp[0][2]=a[0][2];
   for (int i=1;i<n;i++)
   {
       for (int j=0;j<3;j++)
       {
           for (int k=0;k<3;k++)
           {
               if (k==j) continue;
               dp[i][k]=max(dp[i][k],dp[i-1][j]+a[i][k]);
           }
       }
   }
   cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}


Measured memory_bytes: 3712
A,V=map(int, input().split())
B,W=map(int, input().split())
T=int(input())

if V>W:
	if abs(B-A)<=((V-W)*T):
		print("YES")
	else:
		print("NO")

else:
	print("NO")


# 2darray [[0] * 4 for i in range(3)]

Measured memory_bytes: 9072
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int MAXN=2000;
const int INF=(int)1e9+5;
int n,k,q,A[MAXN+5],ans=INF;
void SOLVE(int x)
{
    vector<int> pri;
    int i=0;
    while(i<n)
    {
        vector<int> que;
        while(A[i]<x && i<n) i++;
        while(A[i]>=x && i<n) que.push_back(A[i++]);
        if(que.size()>=k)
        {
            sort(que.begin(),que.end());
            for(int j=0;j<(int)que.size()-k+1;j++)
                pri.push_back(que[j]);
        }
    }
    sort(pri.begin(),pri.end());
    if((int)pri.size()>=q)
        ans=min(ans,pri[q-1]-pri[0]);
}
int main()
{
    scanf("%d%d%d",&n,&k,&q);
    for(int i=0;i<n;i++)
        scanf("%d",&A[i]);
    for(int i=0;i<n;i++)
        SOLVE(A[i]);
    printf("%d\n",ans);
    return 0;
}

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

int n,m;
int ans;
vector<int> neighbors[100];
set< set<int> > used;
int weight[100][100];

void dfs(set<int> vs){
	if( used.count(vs) ) return;
	used.insert(vs);
	
	int score = 0;
	if( vs.size() > 1 ){
		for( auto &&i : vs ){
			int c = 1e9;
			for( auto &&j : vs ){
				if( i != j ) {
					c = min(weight[i][j],c);
				}
			}
			score += c;
		}
	}
	ans = max(ans,score);
	

	const int representative = *vs.begin();
	
	int cost[100];
	for( auto &&i : neighbors[representative])
		 cost[i] = 1e9;
	
	for( auto &&i : vs ){
		for( auto &&j : neighbors[representative]){
			cost[j] = min(weight[i][j],cost[j]);
		}
	}
	for( auto &&i : neighbors[representative])
		if( !vs.count(i) and cost[i] > 0 ){
			set<int> nvs = vs;
			nvs.insert(i);
			dfs(nvs);
		}
	
}

int main(){
	cin >> n >> m;
	for(int i = 0 ; i < m ; i++){
		int a,b,c;
		cin >> a >> b >> c;
		--a,--b;
		weight[a][b] = c;
		weight[b][a] = c;
		neighbors[a].push_back(b);
		neighbors[b].push_back(a);
	}
	ans = 0;
	for(int i = 0 ; i < n ; i++){
		dfs({i});
	}
	cout << ans << endl;

}

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

int main() {
    int64_t N, K;
    cin >> N >> K;
    vector<int64_t> A(N);

    mt19937_64 engine(0);
    uniform_int_distribution<> dist(0, 0);

    for (int64_t& a : A) {
        cin >> a;
//        a = dist(engine);
    }

    auto print = [&](){
        for (int64_t i = 0; i < N; i++) {
            cout << A[i] << " \n"[i == N - 1];
        }
    };

    for (int64_t k = 0; k < K; k++) {
        vector<int64_t> new_A(N + 1, 0);

        for (int64_t i = 0; i < N; i++) {
            //A[i]の寄与は
            int64_t min_index = max(i - A[i], (int64_t)0);
            int64_t max_index = min(i + A[i], N - 1);
            new_A[min_index]++;
            new_A[max_index + 1]--;
        }

        for (int64_t i = 1; i <= N; i++) {
            new_A[i] += new_A[i - 1];
        }

        new_A.pop_back();

        A = new_A;

        int64_t cnt = count(A.begin(), A.end(), N);
        if (cnt == N) {
            break;
        }
    }
    print();
}

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
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; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    long double W, H, x, y;
    cin >> W >> H >> x >> y;

    int cnt = 0;
    if (x + x == W && y + y == H) {
        cnt = 1;
    }

    long double ans = (W * H) / 2.0;

    cout << fixed << setprecision(6) << ans << " " << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n, m, k;
    cin>>n>>m>>k;
    lli i, j, p ,q, ans=0;
    string s[n];
    
    for(i=0;i<n;i++) cin>>s[i];
    
    for(i=0;i<pow(2, n);i++)
    {
        for(j=0;j<pow(2, m);j++)
        {
            lli tot = 0;
            for(p=0;p<n;p++)
            {
                for(q=0;q<m;q++)
                {
                    if(((s[p][q] == '#') && ((i & (1LL<<p)) == 0)) && ((j & (1LL<<q)) == 0)) tot++;
                }
            }
            if(tot == k) ans++;
        }
    }
    cout<<ans;
    return 0;
}

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

import sys
import itertools
from copy import deepcopy

def input():
    return sys.stdin.readline()

def count_black(combi, field, h, w):

    height_list = []
    width_list = []
    for num in combi:
        if num <= h:
            height_list.append(num)
        else:
            width_list.append(num-(h))

    #print(height_list)
    #print(width_list)

    for line in height_list:
        for i in range(w):
            field[line-1][i] = "x"

    for row in width_list:
        for i in range(h):
            field[i][row-1] = "x"

    black_cnt = 0
    for line in field:
        black_cnt += line.count("#")

    return black_cnt





def resolve():
    h, w, k = map(int, input().split())
    field = [list(input().rstrip()) for i in range(h)]
    # field[y][x]

    lst = []

    for i in range(1, h+1):
        lst.append(i)

    lst_length = len(lst)
    for j in range(1, w+1):
        lst.append(lst_length+j)


    # 全列挙
    p = []
    for i in range(len(lst)):
        p.append(itertools.combinations(lst, i+1))

    ans_num = 0

    for v in p:
        for vv in v:
            temp_field = deepcopy(field)
            black_num = count_black(vv, temp_field, h, w)
            if black_num == k:
                ans_num += 1

    # 最後にまったく修正しない場合
    black_cnt = 0
    for line in field:
        black_cnt += line.count("#")

    if black_cnt == k:
        ans_num += 1

    print(ans_num)

if __name__ == "__main__":
    resolve()



Measured memory_bytes: 73096
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
using namespace std;

typedef long long lld;
int N, par[101010]; lld st[101010], dy[101010];
vector<int> con[101010];

void dfs(int ix){
	int islf=1, deg=0; lld sum=0, mx=0;
	for(int &e : con[ix]){
		deg++;
		if(e == par[ix])continue;
		islf=0, par[e]=ix;
		dfs(e); sum+=dy[e];
		if(mx<dy[e])mx=dy[e];
	}
	if(islf)dy[ix]=st[ix];
	else if(deg==1)dy[ix]=sum-st[ix];
	else{
		dy[ix]=st[ix]*2-sum;
		if(st[ix]>sum || dy[ix]<0 || max(mx,dy[ix]) > st[ix])puts("NO"), exit(0);
	}
}

int main(){
	scanf("%d", &N);
	for(int i=0; i<N; i++)scanf("%lld", &st[i]);
	for(int i=1; i<N; i++){
		int s, e;
		scanf("%d%d", &s, &e), s--, e--;
		con[s].push_back(e), con[e].push_back(s);
	}
	par[0]=-1; dfs(0);
	puts(dy[0]?"NO":"YES");
	return 0;
}

Measured memory_bytes: 14336
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;

bool augment(const Graph& g, int u,
			 vector<int>& matchTo, vector<bool>& visited) {
  if(u < 0) return true;
  FOR(e, g[u]) if(!visited[e->dst]) {
	visited[e->dst] = true;
	if(augment(g, matchTo[e->dst], matchTo, visited)) {
	  matchTo[e->src] = e->dst;
	  matchTo[e->dst] = e->src;
	  return true;
	}
  }
  return false;
}

int bipartiteMatching(const Graph& g, int L) {
  const int n = g.size();
  vector<int> matchTo(n, -1);
  int match = 0;
  REP(u, L) {
	vector<bool> visited(n);
	if(augment(g, u, matchTo, visited)) ++ match;
  }

  return match;
}

int main() {
  int blue[500], red[500];
  int m, n;
  
  while(cin >> m >> n && (m|n)) {
	Graph g(m+n);
	REP(i, m) cin >> blue[i];
	REP(i, n) cin >> red[i];
	
	REP(i, m) REP(j, n) {
	  if(__gcd(blue[i], red[j]) > 1) {
		g[i].push_back(Edge(i, m+j, 1));
		g[m+j].push_back(Edge(m+j, i, 1));
	  }
	}
	
	cout << bipartiteMatching(g, m) << endl;
  }
  return 0;
}

Measured memory_bytes: 6792
#include <bits/stdc++.h>
#define pii pair <int, int>
#define pb push_back
#define mp make_pair
using namespace std;

int N, W;
long long res;
int We[103], Ve[103];
long long Rucsac[100005]; // fac
int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i ) {
        cin >> We[i] >> Ve[i];
    }
    for (int i = 0; i <= 100000; ++i) Rucsac[i] = 2e11;
    Rucsac[Ve[0]] = We[0];
    res = Ve[0];
    for (int i = 1; i < N; ++i) {
        for (int j = res; j > 0; --j) {
            if (Rucsac[j] != 2e11) {
                long long x = j + Ve[i];
                long long y = Rucsac[j] + We[i];
                if (y <= W) res = max(res, x);
                Rucsac[x] = min(Rucsac[x], y);

            }
        }
        res = max(res, (long long)Ve[i]);
        Rucsac[Ve[i]] = min(Rucsac[Ve[i]], (long long)We[i]);
    }
    cout << res;
    return 0;
}



Measured memory_bytes: 1024
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc =  new Scanner(System.in);

    String s = sc.next();

    char[] c = s.toCharArray();

    if(c[2]==c[3]&&c[4]==c[5]){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }

  }
}

Measured memory_bytes: 24916
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int ans = 0;
        for (int i=0;i<N;i++) {
            int A = Integer.parseInt(sc.next());
            if (A==(i+1)) {
                ans++;
                if (i!=N-1) {
                    int pass = Integer.parseInt(sc.next());
                }
                i++;
            }
        }
        System.out.println(ans);
    }
}

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

int main(void){
    string S;
    cin>>S;
    int ans=0;
    for(int i=0;i<S.size();i++){
        if(S[i]=='+')
            ans++;
        else if(S[i]=='-')
            ans--;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
    char s[5];
    cin >> s;
    sort(s,s+4);
    if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pll;
const int N = 305, MAX = 1e18;
ll n, m, l, q;
pll ans[N][N];
vector<pll>adj[N];
void dij(int src)
{
    ans[src][src] = {0, -l};
    set<pair<pll, ll>>q;
    q.insert({{0, -l}, src});
    while(q.size())
    {
        pll old_pair = q.begin()->F;
        int v = q.begin()->S;
        q.erase(q.begin());
        for(auto edge : adj[v])
        {
            int to = edge.F;
            ll len = edge.S;
            if(len > l) continue;
            pll new_pair = old_pair;
            if(-old_pair.S < len)
            {
                new_pair.F++;
                new_pair.S = -l;
            }
            new_pair.S += len;
            if(new_pair < ans[src][to])
            {
                q.erase({ans[src][to], to});
                ans[src][to] = new_pair;
                q.insert({ans[src][to], to});
            }
        }
    }
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m >> l;
    for(int i = 1;i <= n;++i)
        for(int j = 1;j <= n;++j)
            ans[i][j] = {MAX, MAX};
    while(m--)
    {
        int u, v, c;
        cin >> u >> v >> c;
        adj[u].emplace_back(v, c);
        adj[v].emplace_back(u, c);
    }
    for(int i = 1;i <= n;++i)
        dij(i);
    cin >> q;
    while(q--)
    {
        int u, v;
        cin >> u >> v;
        cout << (ans[u][v].F == MAX ? -1 : ans[u][v].F) << '\n';
    }
    return 0;
}


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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rep1r(i, n) for (int i = ((int)(n)); i > 0; --i)

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

#define SORT(v, n) sort(v, v + n);
// #define SORT(v, n) stable_sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

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

#define MAX 100000
int parent(int i) { return i / 2; }
int left(int i) { return 2 * i; }
int right(int i) { return 2 * i + 1; }

int main() {
    int H, i, A[MAX + 1];
    cin >> H;
    rep1(i, H) cin >> A[i];

    rep1(i, H) {
        cout << "node " << i << ": key = " << A[i] << ", ";
        if (parent(i) >= 1) cout << "parent key = " << A[parent(i)] << ", ";
        if (left(i) <= H) cout << "left key = " << A[left(i)] << ", ";
        if (right(i) <= H) cout << "right key = " << A[right(i)] << ", ";
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 3120
// 2016-12-05
#include <iostream>
#include <cmath>
using namespace std;

int main() {
	int e, x, y, z, m;
	while (cin >> e, e) {
		m = 1000000;
		for (z = 0; z * z * z <= e; z++) {
			y = (int)sqrt(e - z * z * z);
			x = e - z * z * z - y * y;
			m = min(m, x + y + z);
		}
		cout << m << endl;
	}
	return 0;
}

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

using namespace std;

int main() {

	int ans = 0;
	int buf = 0;
	char c;

	c = getchar();

	while (c != '\n') {
		if (c == 'S') {
			buf++;
		}
		else {
			if (buf > 0) {
				buf--;
			}
			else {
				ans++;
			}
		}
		c = getchar();
	}
	ans += buf;

	printf("%d\n", ans);

	return 0;

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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





int main() {
    string s;
    cin >> s;
    
    while(s != "#"){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        a--;b--;c--;d--;
        
        vector<string> x(9);
        int y = 0;
        REP(i, s.size()){
            if(s[i] == 'b'){
                x[y] += 'b';
            }
            else if(s[i] == '/'){
                y++;
            }
            else{
                REP(j, s[i] - '0'){
                    x[y] += '.';
                }
            }
        }
        
        x[a][b] = '.';
        x[c][d] = 'b';
        
        string ans;
        REP(i, y + 1){
            for(ll j = 0; j < x[i].size();){
                if(x[i][j] == '.'){
                    ll c = 0;
                    for(; j < x[i].size() && x[i][j] == '.'; j++){
                        c++;
                    }
                    ans += (c + '0');
                }
                else{
                    ans += 'b';
                    j++;
                }
            }
            if(i < y){
                ans += '/';
            }
        }
        cout << ans << '\n';
        
        cin >> s;
    }
}


Measured memory_bytes: 3200
n, channel = map(int, input().split())
STC = []
for _ in range(n):
    s, t, c = map(int, input().split())
    STC.append([2*s,2*t,c])

STC = sorted(STC, key=lambda x: (x[2], x[1]))
# print(STC)

now_s = STC[0][0]
now_t = STC[0][1]
now_c = STC[0][2]

All_bangumi = []

for i in range(1,n):
    if now_c == STC[i][2]:
        if now_t == STC[i][0]:
            now_t = STC[i][1]
            if i == n-1:
                All_bangumi.append([now_s, now_t])
        else:
            All_bangumi.append([now_s, now_t])
            now_s = STC[i][0]
            now_t = STC[i][1]

    else:   
        All_bangumi.append([now_s, now_t])
        now_s = STC[i][0]
        now_t = STC[i][1]
        now_c = STC[i][2]
        if i == n-1:
            All_bangumi.append([now_s, now_t])

if n == 1:
    All_bangumi.append([STC[0][0], STC[0][1]])

for i in range(len(All_bangumi)):
    All_bangumi[i][0] = All_bangumi[i][0] -1


Imos = [0 for _ in range(2*(10**5)+1)]
for i in range(len(All_bangumi)):
    Imos[All_bangumi[i][0]] += 1
    Imos[All_bangumi[i][1]] -= 1

Imos_rui = [0]
for i in range(len(Imos)):
    Imos_rui.append(Imos_rui[-1]+Imos[i])

print(max(Imos_rui))

Measured memory_bytes: 38048
#include <bits/stdc++.h>
#define PI 3.1415926535897
using namespace std;
typedef long long ll;
const int INF = 1000000000;
const ll LINF = 1000000000000000000; //1e18
const double EPS = 1e-10;

int main(void)
{
    int x;
    cin >> x;

    vector<bool> expo(x + 1);
    expo[1] = true;

    for (int i = 2; i <= x; i++)
    {
        int v = i * i;
        while (v <= x)
        {
            expo[v] = 1;
            v *= i;
        }
    }

    for (int i = x; i >= 1; i--)
    {
        if (expo[i])
        {
            cout << i << endl;
            return (0);
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
#define INF 100000000
int max(int a,int b){
	if(a>b){
		return a;
	}else{
		return b;
	}
}

int main(){
	int set;
	cin>>set;
	for(;set>0;set--){
		int n,up=0,down=0,a,b;
		cin>>n;
		cin>>a;
		for(int i=1;i<n;i++){
			cin>>b;
			if(a<b){
				up=max(up,b-a);
			}else{
				down=max(down,a-b);
			}
			a=b;
		}
		cout<<up<<' '<<down<<endl;
	}
	return 0;
}	

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



long long int time(long long int hp,long long int num,long long int times){
  if(hp==1){return num+times;}
  else return time(hp/2,num*2,times+num);
}

int main(){
   long long int H;
cin >> H;

   cout<<time(H,1,0)<<endl;

   return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    cout << N*(N-1)/2 << endstr;
    return 0;
}


Measured memory_bytes: 256