akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Dynamic;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            int N = intArray[0];
            int Y = intArray[1];
            if(10000 * N < Y)
            {
                Console.WriteLine("-1 -1 -1");
                return;
            }
            else if(10000 * N == Y)
            {
                Console.WriteLine(Y / 10000 + " 0 0");
                return;
            }
            for(int i = 0; i <= N; i++)
            {
                for(int j = 0; j <= N -i; j++)
                {
                    int l = N - (i + j);
                    if (i + j + l == N && (10000 * i) + (5000 * j) + (1000 * l) == Y)
                    {
                        Console.WriteLine(i + " " + j + " " + l);
                        return;
                    }
                }
            }
            Console.WriteLine("-1 -1 -1");
        }
    }
}


//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 28240
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let k = read::<usize>();

    println!("{}", if n % k == 0 { 0 } else { 1 })
}

Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define INF 10000000000
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> p;

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

int main(void) {
    ll n;
    cin >> n;
    ll a[3*n], i;
    ll sum=0;
    for(i=0; i<3*n; i++) {
        cin >> a[i];
    }
    sort(a, a+3*n);
    ll cnt=0;
    for(i=3*n-2; cnt!=n; i-=2) {
        sum+=a[i];
        cnt++;
    }
    
    
    cout << sum << endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n, m, a, b;
  cin >> n >> m >> a >> b;
  vs res(n, string(m, '.'));
  if (n % 2) {
    for (int i = 0; i + 1 < m && a > 0; i += 2) {
      res[n-1][i] = '<';
      res[n-1][i+1] = '>';
      --a;
    }
  }
  if (m % 2) {
    for (int i = (res[n-1][m-1] == '.' ? n - 1 : n - 2); i >= 1 && b > 0; i -= 2) {
      res[i-1][m-1] = '^';
      res[i][m-1] = 'v';
      --b;
    }
  }
  int s = (n - n % 2) * (m - m % 2), need = 2 * a + 2 * b;
  bool eq = s == need && a % 2 && b % 2;
  bool ok1 = m > 1 && m % 2 && res[0][m-1] == '.';
  bool ok2 = n > 1 && n % 2 && res[n-1][m-1] == '.';
  if (s < need || (eq && !ok1 && !ok2)) {
    cout << "NO\n"; return 0;
  }
  if (eq) {
    if (ok1) {
      res[0][m-2] = '<'; res[0][m-1] = '>';
      res[0][m-3] = '^'; res[1][m-3] = 'v';
    } else if (ok2) {
      res[n-2][m-1] = '^'; res[n-1][m-1] = 'v';
      res[n-3][m-2] = '<'; res[n-3][m-1] = '>';
    }
    --a; --b;
  }
  for (int i = 0; i + 1 < n; i += 2) for (int j = 0; j + 1 < m; j += 2) {
    if (res[i][j] != '.' || res[i][j+1] != '.' || res[i+1][j] != '.' || res[i+1][j+1] != '.') continue;
    if (a) {
      for (int l = 0; l < 2 && a; ++l) {
        res[i + l][j] = '<';
        res[i + l][j+1] = '>';
        --a;
      }
    } else if (b) {
      for (int l = 0; l < 2 && b; ++l) {
        res[i][j + l] = '^';
        res[i+1][j + l] = 'v';
        --b;
      }
    }
  }
  cout << "YES\n";
  for (int i = 0; i < n; ++i) cout << res[i] << endl;
  return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
 
#define mod 1000000000
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vs vector<string>
#define psi pair<string,ll>
#define pii pair<ll,ll>
#define vsi vector<psi>
#define vii vector<pii>
#define mp make_pair
#define pb push_back
#define rep(n) for(long i=0;i<n;i++)
#define repr(n) for(long i=(n-1);i>=0;i--)
#define fori(i,a,b) for(auto i=a;i<=b;i++)
#define ford(i,b,a) for(auto i=b;i>=a;i--)
#define mset(a,i) memset(a,i,sizeof(a))
#define minv(a) min_element(a.begin(),a.end())
#define maxv(a) max_element(a.begin(),a.end())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define sotit(a) sort(a.begin(),a.end());
#define sot(a) sort(a,a+n);
#define ff first
#define maxheap(v) priority_queue<v>
#define minheap(v) priority_queue<v, vector<v>, greater<v>>
#define ss second
#define endl "\n"
#define NL cout<<endl;
#define printmat(a,m,n) for(int i=0;i<m;i++){       \
							for(int j=0;j<n;j++){   \
								cout<<a[i][j]<<" "; \
							}                       \
							cout<<endl;             \
						}
#define dbgn(x) cout<<" $ "<<x<<" $ "<<endl;
#define dbg(x) cout<<" $ "<<x<<" $ ";
#define all(v) v.begin(),v.end()
#define len(s) (ll)(s.size())
#define show(a,n) for(int i=0;i<n;i++){ cout<<a[i]<<" "; } NL
#define fast_io() cin.sync_with_stdio(false);cout.sync_with_stdio(false);cin.tie(NULL);
 
// lower_bound - which does not compare less than val
// upper_bound - which compares greater than val

int main() {
	fast_io()
 
	ll t;
	//cin>>t;
	t=1;
	while(t--){
		string s;
		cin>>s;
		ll n=len(s);
		ll a[n],b[n+1];
		mset(a,0);
		mset(b,0);
		if(s[n-1]=='>'){
			a[n-1]=1;
		}
		for(int i=n-2;i>=0;i--){
			if(s[i]=='>'){
				a[i]=a[i+1]+1;
			}
			else{
				a[i]=0;
			}
		}
		for(int i=1;i<=n;i++){
			if(s[i-1]=='<'){
				b[i]=b[i-1]+1;
			}
			else{
				b[i]=0;
			}
		}
		ll ans=0,c=0;
		// for(auto i:a){
		// 	cout<<i<<" ";
		// }
		// NL

		// for(auto i:b){
		// 	cout<<i<<" ";
		// }
		// NL
		for(int i=0;i<n;i++){
			if(i>0&&s[i-1]=='<'&&s[i]=='>'){
				ans+=max(a[i],b[i]);
			}
			else if(s[i]=='<'){
				//cout<<b[i]<<s[i];
				ans+=b[i];
			}
			else{
				ans+=a[i];
				//cout<<a[i]<<s[i];
			}
		}
		if(s[n-1]=='<'){
			ans+=b[n];
			//cout<<b[n];
		}
		else{
			//cout<<0;
		}
		//NL
		cout<<ans;
	}
	return 0;
}



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

const int MOD = 1000000007;

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

int main() {
    int N, M;
    cin >> N >> M;
    if (N == M) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if(a==5)
    {
        if((b==5 && c==7)||(b==7 && c==5))
            printf("YES\n");
        else
            printf("NO\n");
    }
    else if(a==7)
    {
        if(b==5 && c==5)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 256
#ifndef __cplusplus
    cat << EOF
#endif
#include <bits/stdc++.h>
using namespace std;

#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define overload_rep(arg0, arg1, arg2, name, ...) name
#define all(box) box.begin(), box.end()

template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if(lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if(lhs > rhs) { lhs = rhs; return 1; } return 0; }

constexpr int inf = (1 << 30) - 1;

int N;
string S;
vector<int> graph[2000];

struct solver {
    int mini, maxi;
    solver(const int& mi = 0, const int& ma = 0) : mini(mi), maxi(ma) { }
};

bool operator < (const solver& s, const solver& t) {
    if(s.mini == t.mini) return s.maxi < t.maxi;
    else return s.mini < t.mini;
}

bool can_make_x(const solver& s, const int& x) {
    if(s.mini % 2 != x % 2) return false;
    return s.mini <= x && x <= s.maxi;
}

void add(solver& s, const int& x) {
    s.mini += x;
    s.maxi += x;
}

solver merge(solver s, solver t) {
    if(t < s) swap(s, t);
    int mini, maxi = s.maxi + t.maxi;
    if(s.maxi >= t.mini) mini = maxi % 2;
    else mini = t.mini - s.maxi;
    return solver(mini, maxi);
}

int solve_from_v(const int& v) {
    vector<int> count_children(N, 0);
    function<solver(int, int)> dfs = [&](const int& u, const int& p) {
        solver res;
        if(S[u] == '1') ++count_children[u];
        for(const int& x : graph[u]) {
            if(x == p) continue;
            res = merge(res, dfs(x, u));
            count_children[u] += count_children[x];
        }
        add(res, count_children[u]);
        return res;
    };
    solver now;
    for(const int& x : graph[v]) now = merge(now, dfs(x, v));
    if(!can_make_x(now, 0)) return inf;
    return now.maxi / 2;
}

int main() {

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

    int ans = inf;
    rep(i, N) chmin(ans, solve_from_v(i));
    cout << (ans == inf ? -1 : ans) << '\n';

}


Measured memory_bytes: 512
! 2019.9.28 
!
      program answer
      implicit none
      integer :: N_i
      integer,allocatable,dimension(:) :: A_i
      integer,allocatable,dimension(:) :: ans_i
      integer :: i
! read
      read(*,*) N_i
      allocate(A_i(N_i),ans_i(N_i))
      read(*,*) (A_i(i),i=1,N_i)
!
      do i=1,N_i
        ans_i(A_i(i)) = i
      end do
      write(*,*) (ans_i(i),i=1,N_i) 
      end program answer

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 5e5 + 10;
const int LINF = LLONG_MAX;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a;
    cin >> a;
    if(a/100 == 4 or a/100 == 5){
    	cout << 8;
    }
    if(a/100 == 6 or a/100 == 7){
    	cout << 7;
    }
    if(a/100 == 8 or a/100 == 9){
    	cout << 6;
    }
    if(a/100 == 10 or a/100 == 11){
    	cout << 5;
    }
    if(a/100 == 12 or a/100 == 13){
    	cout << 4;
    }
    if(a/100 == 14 or a/100 == 15){
    	cout << 3;
    }
    if(a/100 == 16 or a/100 == 17){
    	cout << 2;
    }
    if(a/100 == 18 or a/100 == 19){
    	cout << 1;
    }
    return 0;
}
 

Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
public class Program{
  public static void Main(){
    string[] MD1 = Console.ReadLine().Split(' ');
    string[] MD2 = Console.ReadLine().Split(' ');
    int[] MD = new int[2];
    int[] md = new int[2];
    for (var i = 0; i < MD1.Length; i++)
    {
      int a = int.Parse(MD1[i]);
      MD[i] = a;
    }
    for (var i = 0; i < MD2.Length; i++)
    {
      int a = int.Parse(MD2[i]);
      md[i] = a;
    }
    if (md[1] == 1)
    {
      Console.WriteLine(1);
    }
    else
    {
      Console.WriteLine(0);
    }
  }
}

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


const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

// 桁DPの遷移先(2は遷移なし)
// 引数は順に上限または下限のビット、遷移前の状態、今回のビット
int rc(int lim, int s, int b){
    if(lim){
        return (!s && b) ? 0 : 1;
    }else{
        if(!b) return s;
        return 2-s;
    }
}

int64_t calc(int64_t X, int64_t Y){
    int64_t dp[62][3][3][3] = {0};
    dp[61][0][0][0] = 1;
    for(int d=60; d>=0; d--) for(int a=0; a<2; a++) for(int b=0; b<2; b++) for(int c=0; c<2; c++){
        vector<pair<int, int>> cand = {{1, 1}, {0, 1}, {0, 0}};
        for(auto& p : cand){
            int x = p.first, y = p.second;
            if(c == 0 && x+y == 1) continue;
            add(dp[d][rc(nth_bit(X, d), a, x)][rc(nth_bit(Y, d), b, y)][c|(x+y==2)], dp[d+1][a][b][c]);
        }
    }
    int64_t ans = 0;
    for(int a=0; a<2; a++) for(int b=0; b<2; b++) for(int c=0; c<2; c++) add(ans, dp[0][a][b][c]);
    return ans;
}

int main(){
    int64_t L, R;
    cin >> L >> R;
    int64_t ans = (calc(R, R) - calc(L-1, R) + MOD) % MOD;
    cout << ans << endl;
}


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

int t, n, k;
int a[100000];

int main(){
  cin >> t;
  for(int i=0; i<t; i++){
    cin >> n >> k;
    for(int j=0; j<n; j++){
      cin >> a[j];
    }
    int b[100000];
    for(int l=0; l<n-1; l++){
      b[l]=a[l+1]-a[l];
      
    }
    
    sort(b, b+n-1);
    int sum=0;
    for(int m=0; m<n-k; m++){
      sum +=b[m];
    }    
    cout << sum << endl;
  }

  
}

Measured memory_bytes: 1952
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <cstdio>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define ct(string) cout << string << endl
#define all(vec) vec.begin(), vec.end()

int main() {
    int n;
    cin >> n;
    vector<vector<int> > happy(n, vector<int>(3));
    vector<vector<int> > dp(n+1, vector<int>(3, 0));
    rep(i,n) rep(j,3) cin >> happy.at(i).at(j);
    rep(i,n) {
        rep(j,3) {
            dp.at(i+1).at(j) = max(dp.at(i).at((j+1)%3)+happy.at(i).at(j), dp.at(i).at((j+2)%3)+happy.at(i).at(j));
        }
    }
    ct(max(max(dp.at(n).at(0), dp.at(n).at(1)), dp.at(n).at(2)));
}


Measured memory_bytes: 11136
# input
N = int(input())
A = list(map(int, input().split()))

l, r, sum, ans = 0, 0, 0, 0
 
while r < N:
    if sum + A[r] == sum ^ A[r]:
        sum += A[r]
        ans += r - l + 1
        r += 1
    else:
        sum -= A[l]
        l += 1
 
print(ans)

Measured memory_bytes: 24840
program main
  implicit none
  integer :: i, j, Nmax, Wmax
  integer(16),allocatable,dimension(:) :: v, DP
  integer,allocatable,dimension(:) :: w
  read*, Nmax, Wmax
  allocate(v(Nmax), w(Nmax), DP(0:Wmax))

  do i = 1, Nmax
    read*, w(i), v(i)
  enddo

  DP = 0
  do i = 1, Nmax
    do j = Wmax, 0, -1
      if(j >= w(i))then
        DP(j) = max(DP(j - w(i)) + v(i), DP(j))
      endif
    enddo
  enddo
  print*, DP(Wmax)
end program

Measured memory_bytes: 1792
#include<stdio.h>
main(){
  int n,a[5],i,j,flg=0;
  char b[10][6];
  while(scanf("%d",&n)!=EOF){
    if(flg!=0)printf("\n");
    flg=1;
    for(i=0;i<10;i++){
      for(j=0;j<6;j++){
	if(i==2)b[i][j]='=';
	else b[i][j]='*';
      }
    }
    a[4]=n%10 ,a[3]=n%100/10 ,a[2]=n%1000/100;
    a[1]=n%10000/1000, a[0]=n/10000;

    for(i=0;i<5;i++){
      if(a[i]>=5)b[0][i]=' ';
      else b[1][i]=' ';
      switch(a[i]){
      case 0:
      case 5:
	b[3][i]=' ';
	break;
      case 1:
      case 6:
	b[4][i]=' ';
	break;
      case 2:
      case 7:
	b[5][i]=' ';
	break;
      case 3:
      case 8:
	b[6][i]=' ';
	break;
      case 4:
      case 9:
	b[7][i]=' ';
	break;
      }
    }
    for(i=0;i<8;i++){
      for(j=0;j<5;j++)printf("%c",b[i][j]);
      printf("\n");
    }
  }
  return 0;
}

Measured memory_bytes: 572
#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 double PI = acos(-1);

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double th = double(h*60+m)/720 * 2*PI;
  double tm = double(m)/60 * 2*PI;
  double xh = a*cos(th), yh = a*sin(th);
  double xm = b*cos(tm), ym = b*sin(tm);
  double dx = xh-xm, dy = yh-ym;
  double ans = sqrt(dx*dx + dy*dy);
  printf("%.10f\n", ans);
  return 0;
}


Measured memory_bytes: 4056
/*Tree Walk
Binary trees are defined recursively. A binary tree T is a structure defined on a finite set of nodes that either

contains no nodes, or
is composed of three disjoint sets of nodes:
- a root node.
- a binary tree called its left subtree.
- a binary tree called its right subtree.
Your task is to write a program which perform tree walks (systematically traverse all nodes in a tree) based on the following algorithms:

Print the root, the left subtree and right subtree (preorder).
Print the left subtree, the root and right subtree (inorder).
Print the left subtree, right subtree and the root (postorder).
Here, the given binary tree consists of n nodes and evey node has a unique ID from 0 to n-1.

Input
The first line of the input includes an integer n, the number of nodes of the tree.

In the next n linen, the information of each node is given in the following format:

id left right

id is the node ID, left is ID of the left child and right is ID of the right child. If the node does not have the left (right) child, the left(right) is indicated by -1

Output
In the 1st line, print "Preorder", and in the 2nd line print a list of node IDs obtained by the preorder tree walk.

In the 3rd line, print "Inorder", and in the 4th line print a list of node IDs obtained by the inorder tree walk.

In the 5th line, print "Postorder", and in the 6th line print a list of node IDs obtained by the postorder tree walk.

Print a space character before each node ID.

Constraints
1 ≤ n ≤ 25*/
#include <iostream>
#include <cstdio>
using namespace std;
#define MAX 10000
#define NIL -1

struct Node{
	int parent;
	int left;
	int right;
};

Node T[MAX];
int n;

void preParse(int u){
	if(u==NIL)
		return;
	printf(" %d",u);
	preParse(T[u].left);
	preParse(T[u].right);
} 

void inParse(int u){
	if(u==NIL)
		return;
	inParse(T[u].left);
	printf(" %d",u);
	inParse(T[u].right);
}

void postParse(int u){
	if(u==NIL)
		return;
	postParse(T[u].left);
	postParse(T[u].right);
	printf(" %d",u);
}

int main(){
	int root=0;
	int v,l,r;
	cin>>n;
	for(int i=0;i<n;i++)
		T[i].parent=NIL;//初始化每个节点
	
	for(int i=0;i<n;i++){
		scanf("%d %d %d",&v,&l,&r);
		T[v].left=l;
		T[v].right=r;
		if(l!=NIL)
			T[l].parent=v;
		if(r!=NIL)
			T[r].parent=v;
	} 
	
	for(int i=0;i<n;i++)//寻找根结点 
		if(T[i].parent==NIL)
			root=i; 
			
	cout<<"Preorder"<<endl;
	preParse(root);
	cout<<endl;
	cout<<"Inorder"<<endl;
	inParse(root);
	cout<<endl;
	cout<<"Postorder"<<endl;
	postParse(root);
	cout<<endl;
	
	return 0;
}


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

#define si(v) v.size()
#define all(v) v.begin(), v.end()
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep2(i, n, m) for (ll i = n; i <= (n); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (m); --i)

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

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  string a, b, c; cin >> a >> b >> c;
  if (a.back() == b.front() && b.back() == c.front()) cout << "YES\n";
  else cout << "NO\n";
  
  return (0);
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()



int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    n=min(n,(b-1));
    ll ans=a*n;
    ans/=b;
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]

count = 0
for i in range(len(b)):
    count += min(a[i], b[i])
    if a[i]<b[i] :
        count += min(a[i+1], b[i]-a[i])
        a[i+1] = max(0, a[i+1]-(b[i]-a[i]))
print(count)

Measured memory_bytes: 18624
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt(), i, j, k, l;
		boolean flag = true;
		String[] a = new String[n], b = new String[m];
		for(i = 0; i < n; i++) a[i] = sc.next();
		for(i = 0; i < m; i++) b[i] = sc.next();
		
		for(i = 0; i < n-m+1; i++){
			for(j = 0; j < n-m+1; j++){
				for(k = 0; k < m; k++){
					for(l = 0; l < m; l++){
						if(a[i+k].charAt(j+l) != b[k].charAt(l)){
							flag = false;
						}
					}
				}
				if(flag){
					System.out.println("Yes");
					System.exit(0);
				}
				flag = true;
			}
		}
		System.out.println("No");
	}
}

Measured memory_bytes: 21844
#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
#define IOS std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define FRE freopen("in.txt", "r", stdin);
#define endl "\n"
#define PI acos(-1.0)
typedef long long LL;
typedef pair<int, int> PII;
const double eps = 1e-8;
const int inf = 0x3f3f3f3f;
const int N = 2e5 + 10, M = 1010;

LL a[N];
map<LL, LL> cnt;

void solve() {
	int n;
	cin >> n;
	LL res = 0;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		res += cnt[i - a[i]];
		cnt[a[i] + i]++;
	}
	cout << res << endl;
}

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


Measured memory_bytes: 27840
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<ll,ll> P;
//ll const INF=1001001001;
//ll const INF=1001001001001001001;
ll const MOD=1000000007;

ll S;
ll X[3];
ll Y[3];

int main(){
    cin>>S;

    X[1]=Y[2]=(ll)ceil(sqrt(S));
    Y[1]=1;
    X[2]=X[1]*Y[2]-S;

    rep(i,3) cout<<X[i]<<' '<<Y[i]<<' ';
    cout<<endl;

    //cout<<abs(X[1]*Y[2]-Y[1]*X[2])<<endl;
}

Measured memory_bytes: 3668
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());

        int sumA = A * N;
        
        System.out.println((sumA >= B ? B : sumA)); 

        sc.close();
    }
    
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<58;
ll func(ll A, ll B, ll C){
  if(A % 2 == 1 || B % 2 == 1 || C % 2 == 1) return 0;
  if(A == B && A == C) return -1;
  return func((B+C)/2,(C+A)/2,(A+B)/2) + 1;
}
 
int main(){
    ll A, B, C;
  	ll ans = 0;
  	cin >> A >> B >> C;
  	ans = func(A,B,C);
  	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void) {
  int x,y,W,H,r;
  cin >> W >> H >> x >> y >> r;

  bool isOK = true;
  if (x - r < 0){
    isOK = false;
  }else if(x + r > W){
    isOK = false;
  }else if(y - r < 0){
    isOK = false;
  }else if(y + r > H){
    isOK = false;
  }

  if (isOK == false){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }


  return 0;
}



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

int main(){
    string N;
    cin >> N;
    bool if_all_9 = true;
    for(int i = 1; i < N.size(); i++){
        if(N[i] != '9'){
            if_all_9 = false;
            break;
        }
    }
    if(!if_all_9 && N[0] != '1'){
        cout << (N[0] - '1') + (N.size() - 1) * 9 << endl;
    }else if(!if_all_9){
        cout << (N.size() - 1) * 9 << endl;
    }else{
        cout << (N[0] - '0') + (N.size() - 1) * 9 << endl;
    }   
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>
#include <iostream>
#include <fstream>
#include <cassert>
#include <climits>

#include <memory>
#include <vector>
#include <queue>
using namespace std;

#define DEBUG (0)

#if DEBUG
#define DPRINTF(...) do { \
    printf("D(L%d) %s: ", __LINE__, __func__); \
    printf(__VA_ARGS__); \
  } while (false)
#else
#define DPRINTF(...)
#endif // DEBUG


struct Vertex {
  Vertex() :
    id_(-1),
    visited_(0),
    distance_(-1),
    adjNum_(-1) { }

  int id_;
  bool visited_;
  int distance_;
  int adjNum_;
  unique_ptr<int[]> adjIds_;

  void set(int id, vector<int> ids);
  void printInfo();
  void printDistance();
};


void Vertex::set(int id, vector<int> ids)
{
  id_ = id;
  adjNum_ = ids.size();

  if (adjNum_ == 0)
    return;

  adjIds_ = unique_ptr<int[]>(new int[adjNum_]);

  for (int i = 0; i < adjNum_; i++)
    adjIds_[i] = ids[i];
}


void Vertex::printInfo()
{
  DPRINTF("%d %d", id_, adjNum_);
  for (int i = 0; i < adjNum_; i++)
    printf(" %d", adjIds_[i]);
  cout << endl;
}


void Vertex::printDistance()
{
  printf("%d %d\n", id_, distance_);
}


void bfs(Vertex vertices[])
{
  const int startId = 1;
  queue<int> idQueue;

  idQueue.push(startId);

  int distance = 0;

  while (!idQueue.empty()) {

    DPRINTF("queue size %lu\n", idQueue.size());

    const size_t numOfThisDist = idQueue.size();

    for (size_t i = 0; i < numOfThisDist; i++)
    {
      int id = idQueue.front();
      idQueue.pop();

      DPRINTF("%zu  id %d\n", i, id);

      Vertex &vtx = vertices[id];

      if (vtx.visited_)
        continue;

      vtx.visited_ = true;
      vtx.distance_ = distance;

      for (int j = 0; j < vtx.adjNum_; j++)
        idQueue.push(vtx.adjIds_[j]);

    }

    distance++;
  }
}


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

  DPRINTF("%d\n", n);

  // do not use [0], it's empty
  Vertex vertices[n+1];

  for (int i = 1; i <= n; i++)
  {
    int node, adjNum;

    cin >> node >> adjNum;

    vector<int> adjs;

    for (int j = 0; j < adjNum; j++)
    {
      int v;
      cin >> v;
      adjs.push_back(v);
    }

    vertices[i].set(node, adjs);

    cin.ignore();

  }

#if DEBUG
  for (int i = 1; i <= n; i++)
    vertices[i].printInfo();
#endif // DEBUG

  bfs(vertices);

  for (int i = 1; i <= n; i++)
    vertices[i].printDistance();

  return 0;

}



Measured memory_bytes: 3236
#include <stdio.h>
#include <stdlib.h>
int main() {
	int i, j, g, r, **map,x;
	scanf("%d %d", &g, &r);
	map = malloc(sizeof(int*)*g + 1);
	for (i = 0; i < g+1; i++)
		map[i] = malloc(sizeof(int)*r + 1);
	for (i = 0; i < g + 1; i++) {
		for (j = 0; j < r + 1; j++)
			map[i][j] = 0;
	}
	for (i = 0; i < g; i++) {
		for (j = 0; j < r; j++) {
			scanf("%d", &x);
			map[i][j] = x;
		}
	}
	for (i = 0; i < g; i++) {
		for (j = 0; j < r; j++) {
			map[i][r] += map[i][j];
			map[g][j] += map[i][j];
		}
		map[g][r] += map[i][r];
	}
	for (i = 0; i < g; i++) {
		for (j = 0; j < r; j++)
			printf("%d ", map[i][j]);
		printf("%d\n",map[i][r]);
	}
	for (i = 0; i < r; i++)
		printf("%d ",map[g][i]);
	printf("%d\n", map[g][r]);
}


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

#define MAXN 1000001	
ll spf[MAXN];

void sieve() 
{ 
     
} 


int main(){
		

	ll n;
	cin>>n;
	ll ar[n];
	
	ll *count = new ll[MAXN]();
	for(int i=0;i<n;i++){
	 	cin>>ar[i];
	 	count[ar[i]]++;
	}
	//sort(ar,ar+n);
	int ans=0;
	
	bool *visited = new bool[MAXN]();
	for(int i=1;i<MAXN;i++){
		
		if(count[i]==0||visited[i]){
			continue;
		}
		if(count[i]==1&&!visited[i]){
			ans++;
		}
			
		for(int j=i;j<MAXN;j+=i){
				visited[j] = true;
		}
		
	}	
	
	cout<<ans;
//	cout<<ans;
	
	
	return 0;
}


Measured memory_bytes: 13984
#include "bits/stdc++.h"
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#define int ll
// #define double long double
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll > 
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define mod  1000000007
#define N   200005
#define MAX 300005
#define mod1 1000000007
#define mod2 998244353
#define bitcnt __builtin_popcountll
#define PI acos(-1)
//#define endl "\n"
#define inf 1e+15

signed main(){
  fast;
  int a,b;
  cin>>a>>b;
  if(a<=5) cout<<0<<endl;
  else if(a>=6&&a<=12) cout<<(b/2)<<endl;
  else cout<<b<<endl;



}
  


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  int d = b - a;
  int m = (1 + d) * d / 2;
  cout << m - b << endl;
  return 0;
}

Measured memory_bytes: 256
# ABC144D - Water Bottle
from math import atan, degrees


def main():
    A, B, X = map(int, input().split())
    if A ** 2 * B >= 2 * X:
        C = 2 * X / (A * B)
        ans = degrees(atan(B / C))
    else:
        C = 2 * (B - (X / A ** 2))
        ans = degrees(atan(C / A))
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
/*
Cerberus97
Hanit Banga
*/

#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 10;

ll a[N], b[N], temp[N];
int parent[N], sz[N];
vector<int> g[N];
vector<int> pend[N];

bool check(ll s_mon, int n);
int dsu_find(int x);
void dsu_join(int x, int y);

int main() {
	fast_cin();
	int n, m;
	cin >> n >> m;
	ll bsum = 0;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i] >> b[i];
		bsum += b[i];
	}
	for (int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	int lo = 0, hi = 1e9;
	while (lo <= hi) {
		int mid = (lo + hi) / 2;
		if (check(mid, n)) {
			hi = mid - 1;
		} else {
			lo = mid + 1;
		}
	}
	cout << hi + 1 + bsum;
	// cout << check(100, n) << endl;
}

bool check(ll s_mon, int n) {
	memset(temp, 0, sizeof(temp));
	for (int i = 1; i <= n; ++i) {
		parent[i] = i;
		sz[i] = 1;
		pend[i].clear();
	}
	for (int i = 1; i <= n; ++i) {
		// cout << i << ' ';
		if (dsu_find(i) != i or s_mon < a[i] - b[i]) {
			// cout << "skipped\n";
			continue;
		}
		// cout << endl;
		int ind = i;
		ll w = s_mon;
		priority_queue<pll, vector<pll>, greater<pll>> pq;
		pq.push({a[i] - b[i], i});
		while (!pq.empty()) {
			auto cur = pq.top();
			// cout << cur.first << ' ' << cur.second << ' ' << dsu_find(cur.second) << ' ' << w << endl;
			pq.pop();
			int comp = dsu_find(cur.second);
			if (cur.first > w) {
				pend[ind].pb(cur.second);
				while (!pq.empty()) {
					pend[ind].pb(pq.top().second);
					pq.pop();
				}
			} else if (sz[comp] == 1) {
				dsu_join(ind, cur.second);
				ind = dsu_find(ind);
				w += b[cur.second];
				for (auto &v : g[cur.second]) {
					if (dsu_find(v) != ind) {
						pq.push({a[v] - b[v], v});
					}
				}
			} else {
				w += temp[comp];
				dsu_join(ind, cur.second);
				ind = dsu_find(ind);
				for (auto &v : pend[comp]) {
					if (dsu_find(v) != ind) {
						pq.push({a[v] - b[v], v});
					}
				}
			}
		}
		temp[ind] = w - s_mon;
		// cout << ind << ' ' << dsu_find(ind) << ' ' << sz[ind] << endl;
		if (sz[ind] == n) {
			return true;
		}
	}
	return false;
}

int dsu_find(int x) {
	if (x == parent[x]) {
		return x;
	}
	parent[x] = dsu_find(parent[x]);
	return parent[x];
}

void dsu_join(int x, int y) {
	x = dsu_find(x);
	y = dsu_find(y);
	if (x == y) {
		return;
	}
	if (sz[x] < sz[y]) {
		parent[x] = y;
		sz[y] += sz[x];
	} else {
		parent[y] = x;
		sz[x] += sz[y];
	}
}

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

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

	for(int a = 0; a <= n; a++){
		for(int b = 0; b <= n-a; b++){
			int c = n-a-b;
			if(10000*a+5000*b+1000*c == y){
				cout << a << " " << b << " " << c << endl;
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;int n,i,j,k[9999999];main(){scanf("%d",&n);for (i=0; i<n;i++){scanf("%d",&k[i]);}sort(k,k+n);for (i=0;i<n;i++){if(i){printf(" ");}printf("%d",k[i]);}printf("\n");}

Measured memory_bytes: 9380
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)


def main():
    n = int(input()[-1])
    if n in [2, 4, 5, 7, 9]:
        print("hon")
    elif n in [3]:
        print("bon")
    else:
        print("pon")

main()


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

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

    int n, d;
    cin >> n >> d;

    int ans = 0, i = 0;

    while (i < n) {
        ans++;
        i += 2 * d + 1;
    }

    cout << ans << endl;

    return 0;
}


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


struct unionfind{
    vector<int> parent;
    vector<int> rank;
    vector<ll> size;

    unionfind (int N) {
        parent = vector<int>(N);
        iota(parent.begin(), parent.end(), 0);
        rank = vector<int>(N, 0);
        size = vector<ll>(N, 1);
    }
    int root(int x) {
        if (parent[x] == x) return x;
        parent[x] = root(parent[x]);
        return parent[x];
    }
    
    bool same(int x, int y){
        return root(x) == root(y);
    }
    
    void unite(int x, int y){
        x = root(x);
        y = root(y);
        if (x == y) return;
        if (rank[x] > rank[y]) {
            parent[y] = x;
            size[x] += size[y];
        }
        else {
            parent[x] = y;
            size[y] += size[x];
            if (rank[x] == rank[y]) rank[y] += 1;
        }
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    unionfind pre(N+1);
    unionfind ans(N+1);
    for (int i = 1; i <= N; i++) cin >> pre.size[i];
    ans.size = pre.size;
    vector<pair<ll, pair<int, int>>> edge(M);
    vector<vector<pair<int, ll>>> nb(N+1);
    for (int i = 0; i < M; i++) {
        int A, B, Y;
        cin >> A >> B >> Y;
        edge[i] = {Y, {A, B}};
        nb[A].push_back({B, Y});
        nb[B].push_back({A, Y});
    }
    sort(edge.begin(), edge.end());
    
    vector<bool> cand(M, false);
    vector<bool> use(M, false);
    for (int i = 0; i < M; i++) {
        int A = edge[i].second.first;
        int B = edge[i].second.second;
        ll Y = edge[i].first;
        pre.unite(A, B);
        if (pre.size[pre.root(A)] >= Y) cand[i] = true;
    }
    
    for (int i = M-1; i >= 0; i--) {
        if (!cand[i] || use[i]) continue;
        use[i] = true;
        int A = edge[i].second.first;
        int B = edge[i].second.second;
        ll Y = edge[i].first;
        if (ans.same(A, B)) continue;
        ans.unite(A, B);
        queue<int> q;
        q.push(A);
        q.push(B);
        while (!q.empty()) {
            int now = q.front();
            q.pop();
            for (auto p : nb[now]) {
                int nxt = p.first;
                int c = p.second;
                if (c > Y) continue;
                if (ans.same(now, nxt)) continue;
                ans.unite(now, nxt);
                q.push(nxt);
            }
        }
    }
    int cut = 0;
    for (int i = 0; i < M; i++) {
        int A = edge[i].second.first;
        int B = edge[i].second.second;
        int Y = edge[i].first;
        if (!ans.same(A, B) || ans.size[ans.root(A)] < Y) {
            cut++;
        }
    }
    cout << cut << endl;
    return 0;
}

Measured memory_bytes: 12544
import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val h = scanner.nextInt()
    val w = scanner.nextInt()
    val a = scanner.nextInt()
    val b = scanner.nextInt()
    var str = ""
    var str2 = ""
    //var countW = IntArray(h)
    //var countH = IntArray(w)
    val array = Array(h, {Array(w, {0})})
    for(j in 0..w-1) {
        if(j < a) {
            str+="0"
            str2+="1"
        }
        else {
            str+="1"
            str2+="0"
        }
    }
    for(i in 0..h-1){
        if(i < b) println(str)
        else println(str2)
    }
}

Measured memory_bytes: 39208
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
template <typename T>inline bool chmax(T &a, T b){if (a < b){a = b;return 1;}return 0;}
template <typename T>inline bool chmin(T &a, T b){if (a > b){a = b;return 1;}return 0;}

int main(){
    ll n, m;
    cin >> n >> m;
    Graph G(n);
    rep(i, m)
    {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    queue<ll> que;
    que.push(0);
    vector<bool> visit(n, false);
    vector<ll> dist(n);

    while (que.size())
    {
        ll now = que.front();
        que.pop();
        visit[now] = true;

        for (auto next : G[now])
        {
            if (visit[next] == true)
                continue;

            dist[next] = dist[now] + 1;
            que.push(next);
        }
    }

    if (dist[n - 1] == 2)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;

    return 0;
}

Measured memory_bytes: 18116
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

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

int main() {
    

    
    int a;
    string s;
    cin >> a >> s;
    if (a >= 3200)
    {
        cout << s << endl;
    }
    else
    {
        cout << "red" << endl;
    }
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<ll>
#define vvll vector<vll>
#define mll map<ll,ll>
#define f(i,m,n) for(i=m;i<n;i++)
#define ee endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define take(v,n) for(i=0;i<n;i++) cin>>v[i];
#define NO() cout<<"NO"<<endl
#define YES() cout<<"YES"<<endl
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sot(v) sort(v.begin(),v.end());
bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}

ll powe(ll x, ll y){
    ll res = 1;
    while (y > 0){
        if (y & 1) res = res*x;
        y = y>>1;
        x = x*x;
    }
    return res;
}

void solve()
{
    ll i,j,k=0,n,l;
    cin>>n;
    vll v(n);
    mll m;
    ll sum=0;
    for(i=0;i<n;i++) 
    {
        cin>>v[i];
        sum+=v[i];
        m[v[i]]++;
    }
    ll q;
    cin>>q;
    ll x,y;
    while(q--)
    {
        cin>>x>>y;
        k=m[x];
        m[x]=0;
        sum-=k*x;
        m[y]+=k;
        sum+=k*y;
        cout<<sum<<ee;
    }
}

int main() {
    fast;
    ll i,j,l,k,t,n;
    t=1;
    while(t--)
    solve();
}


Measured memory_bytes: 10100
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
// C 86
int main(){
    int n; cin >> n;
    vector<int> t(110000), x(110000), y(110000);
    rep(i,n){
        cin >> t[i+1] >> x[i+1] >> y[i+1];
    }
    bool can = true;
    rep(i,n){
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1]-x[i]) + abs(y[i+1] - y[i]);
        if(dt < dist) can = false;
        if(dist%2 != dt%2) can = false;   
    }
    
    if(can) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}
const int INF = 1001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int h, n;
    cin >> h >> n;
    vi hp(n), mp(n);
    rep(i, n) cin >> hp[i] >> mp[i];
    vvi dp(n+1, vi(h+1, INF));
    dp[0][0] = 0;
    rep(i, n) rep(j, h+1) {
        chmin(dp[i+1][j], dp[i][j]);
        chmin(dp[i+1][min(j+hp[i], h)], dp[i+1][j] + mp[i]);
    }
    cout << dp[n][h] << endl;
}

Measured memory_bytes: 39424
#include <iostream>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
    long long a,b,c;
    while(~scanf("%lld",&a))
    {
        while(1)
        {
            b=sqrt(a);
            c=b*b;
            if(a==c)
            {
                printf("%lld\n",a);
                break;
            }

            else
                a--;
        }

    }

    return 0;
}


Measured memory_bytes: 256
import sys,collections as cl,bisect as bs,heapq as hq
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
  return list(map(int,input().split()))
def m(): #複数文字
  return map(int,input().split())
def onem(): #Nとかの取得
  return int(input())
def s(x): #圧縮
  a = []
  if len(x) == 0:
    return []
  aa = x[0]
  su = 1
  for i in range(len(x)-1):
    if aa != x[i+1]:
      a.append([aa,su])
      aa = x[i+1]
      su = 1
    else:
      su += 1
  a.append([aa,su])
  return a
def jo(x): #listをスペースごとに分ける
  return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
  return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
  ll = 0
  rr = r
  while True:
    mid = (ll+rr)//2

  if rr == mid:
    return ll
  if (ここに評価入れる):
    rr = mid
  else:
    ll = mid+1
"""

q = onem()

b = 0

AR = []
AL = []

ans = 0



for i in range(q):
  a = l()
  if len(a) == 1:
    if len(AR) == len(AL):
      print(min(AR[0]*-1,AL[0]),ans + b)
    else:
      print(AR[0]*-1,ans + b)

  else:
    b += a[2]
    if AR == []:
      AR.append(-a[1])
    else:
      if len(AR) == len(AL):
        if AL[0] < a[1]:
          ans += a[1]-AL[0]
          hq.heappush(AL,a[1])
          ppp = hq.heappop(AL)
          hq.heappush(AR,ppp*-1)
        else:
          if -1*AR[0] > a[1]:
            ans += (-1*AR[0] - a[1])
          hq.heappush(AR,a[1]*-1)

      else:
        if (AR[0]* -1) > a[1]:
          ans += (-1*AR[0] - a[1])
          hq.heappush(AR,a[1]*-1)
          ppp = hq.heappop(AR)*-1
          hq.heappush(AL,ppp)
        else:
          ans += (AR[0] + a[1])
          hq.heappush(AL,a[1])







Measured memory_bytes: 80216
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

# mを法とするaの乗法的逆元
def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m

# nCr mod m
# modinvが必要
# rがn/2に近いと非常に重くなる
def combination(n, r, mod=10 ** 9 + 7):
    r = min(r, n - r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i + 1, mod) % mod
    return res

n, k = map(int, input().split())
dat = list(map(int, input().split()))
datAfter = [0] * n
datSelf = [0] * n
numAfter = 0
numSelf = 0
m = 10**9 + 7
for i in range(n):
    for j in range(i+1, n):
        if dat[i] > dat[j]:
            numAfter += 1
for i in range(n):
    for j in range(n):
        #print(dat[i], dat[j])
        if dat[i] > dat[j]:
            numSelf += 1
res = 0
res += numAfter * k
res += numSelf * combination(k, 2)
res %= m
#print(numSelf, numAfter, res)
print(res)

Measured memory_bytes: 41836