akhauriyash/Code-Regression huggingface dataset:
R, C, K = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(K)]

items = [[0] * (C + 1) for _ in range(R + 1)]
for r, c, v in X:
    items[r][c] = v

dp0 = [[0] * (C + 1) for _ in range(R + 1)]
dp1 = [[0] * (C + 1) for _ in range(R + 1)]
dp2 = [[0] * (C + 1) for _ in range(R + 1)]
dp3 = [[0] * (C + 1) for _ in range(R + 1)]
for i in range(1, R + 1):
    for j in range(1, C + 1):
        dp0[i][j] = max(dp0[i - 1][j], dp1[i - 1][j], dp2[i - 1][j], dp3[i - 1][j])

        dp3[i][j] = max(dp3[i][j], dp3[i][j - 1])
        dp2[i][j] = max(dp2[i][j], dp2[i][j - 1])
        dp1[i][j] = max(dp1[i][j], dp1[i][j - 1])
        dp0[i][j] = max(dp0[i][j], dp0[i][j - 1])

        if items[i][j]:
            dp3[i][j] = max(dp3[i][j], dp2[i][j] + items[i][j])
            dp2[i][j] = max(dp2[i][j], dp1[i][j] + items[i][j])
            dp1[i][j] = max(dp1[i][j], dp0[i][j] + items[i][j])

print(max(dp0[-1][-1], dp1[-1][-1], dp2[-1][-1], dp3[-1][-1]))


Measured memory_bytes: 453396
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
int main(){
  char b;
  cin >> b;
  if(b=='A'){
    cout<<'T'<<endl;
  }else if(b=='T'){
    cout<<'A'<<endl;
  }else if(b=='G'){
    cout<<'C'<<endl;
  }else{
    cout<<'G'<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int K,S;
  cin >> K >> S;
  
  int count = 0;
  for(int x = 0; x <= K; x++){
    for(int y = 0; y <= K; y++){
      int z = S - x - y;
      if(z >= 0 && z <= K){
        count++;
      }
    }
  }
    
    cout << count << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;
ll D;
set<pair<ll, ll>> S0, S1, S2;
vector<pair<ll, ll>> V0, V1;
void f(ll x, ll y) {
	if (!S2.insert({x,y}).second) return;
	vector<pair<ll, ll>> S3;
	for (auto i = S0.lower_bound({x - D, y - D}); i != S0.end(); ++i) {
		if (i->first != x - D || i->second > y + D) break;
		S3.push_back(*i);
	}
	for (auto i = S0.lower_bound({x + D, y - D}); i != S0.end(); ++i) {
		if (i->first != x + D || i->second > y + D) break;
		S3.push_back(*i);
	}
	for (auto i = S1.lower_bound({y - D, x - D}); i != S1.end(); ++i) {
		if (i->first != y - D || i->second > x + D) break;
		S3.push_back({i->second, i->first});
	}
	for (auto i = S1.lower_bound({y + D, x - D}); i != S1.end(); ++i) {
		if (i->first != y + D || i->second > x + D) break;
		S3.push_back({i->second, i->first});
	}
	for (auto p : S3) {
		S0.erase({p.first, p.second});
		S1.erase({p.second, p.first});
	}
	for (auto x : S3) {
		f(x.first, x.second);
	}
}
ll g(ll x, ll y) {
	ll r = 0;
	{
		auto i = lower_bound(V0.begin(), V0.end(), make_pair(x - D, y - D));
		auto j = upper_bound(V0.begin(), V0.end(), make_pair(x - D, y + D));
		r += j - i;
	}
	{
		auto i = lower_bound(V0.begin(), V0.end(), make_pair(x + D, y - D));
		auto j = upper_bound(V0.begin(), V0.end(), make_pair(x + D, y + D));
		r += j - i;
	}
	{
		auto i = upper_bound(V1.begin(), V1.end(), make_pair(y - D, x - D));
		auto j = lower_bound(V1.begin(), V1.end(), make_pair(y - D, x + D));
		r += j - i;
	}
	{
		auto i = upper_bound(V1.begin(), V1.end(), make_pair(y + D, x - D));
		auto j = lower_bound(V1.begin(), V1.end(), make_pair(y + D, x + D));
		r += j - i;
	}
	return r;
}
int main() {
	int N, A, B;
	cin >> N >> A >> B;
	--A; --B;
	vector<ll> X(N), Y(N);
	for (int i = 0; i < N; ++i) {
		int x, y;
		cin >> x >> y;
		X[i] = x + y;
		Y[i] = x - y;
		S0.insert({X[i], Y[i]});
		S1.insert({Y[i], X[i]});
	}
	V0 = vector<pair<ll, ll>>(S0.begin(), S0.end());
	V1 = vector<pair<ll, ll>>(S1.begin(), S1.end());
	D = max(abs(X[A] - X[B]), abs(Y[A] - Y[B]));
	f(X[A], Y[A]);
	ll r = 0;
	for (auto x : S2) {
		r += g(x.first, x.second);
	}
	cout << r / 2 << endl;
}


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

int main(){
  int n;
  cin >> n;
  int ans = 0;
  vector<int> a(n);
  vector<int> b(n);
  vector<int> c(n);
  rep(i,n)cin >> a[i];
  rep(i,n)cin >> b[i];
  rep(i,n-1)cin >> c[i];

  rep(i,n){
    ans += b[a[i]-1];
    // cout << ans <<  endl;
    if(i >= 1){
      if(a[i]-a[i-1] == 1){
        ans += c[a[i-1]-1];
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;

int main(){
  string s;
  int ans=0;
  cin >> s;
  for(int i=0;i<s.length();i++){
    if(s[i]=='2')ans++;
  }

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


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

#define ll long long
#define pb push_back

int main() {
    string s, t;
    cin >> s >> t;
    int first = s.length();
    int second = t.length();
    int counter = 0;
    vector<int> v;
    for (int i = 0; i <= first - second; i++){
        for (int j = 0; j < second; j++){
            if (s[i + j] == t[j]){
                counter++;
            }
        }
        v.push_back(counter);
        counter = 0;
    }
    cout << second - *max_element(v.begin(), v.end());
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

// 最大公約数
ll gcd(ll a, ll b)
{
   if (a%b == 0) {
       return(b);
   } else {
       return(gcd(b, a%b));
   }
}

// 最小公倍数
ll lcm(ll a, ll b){
   return a * b / gcd(a, b);
}

void solve() {
    ll n; cin >> n;
    ll a; cin >> a;
    rep(i, 1, n){
        ll b; cin >> b;
        a = gcd(a, b);
    }
    cout << a << endl;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 256
mod reader {
    use std::fmt::Debug;
    use std::str::FromStr;
    use std::collections::VecDeque;
    use std::io::{self, Read};

    fn _read_line() -> String {
        let mut buf = String::new();
        io::stdin().read_to_string(&mut buf);
        buf
    }

    fn _read_vec_deque_string() -> VecDeque<String> {
        _read_line().split_whitespace().map(|s| s.to_string()).collect()
    }

    pub struct Reader {
        buf: VecDeque<String>
    }

    impl Reader {
        pub fn new() -> Reader {
            Reader {buf: VecDeque::new()}
        }

        fn update_buf(&mut self) {
            if self.buf.is_empty() {
                self.buf = _read_vec_deque_string();
            }
        }

        pub fn next<T>(&mut self) -> T where T: FromStr, T::Err: Debug {
            self.update_buf();
            self.buf.pop_front().unwrap().parse::<T>().unwrap()
        }

        pub fn nextN<T>(&mut self, n: usize) -> Vec<T> where T: FromStr, T::Err: Debug {
            let mut vec: Vec<T> = Vec::with_capacity(n);
            for i in 0..n {
                vec.push(self.next());
            }
            vec
        }
    }
}

mod data {
    pub struct UnionFind {
        root : Vec<usize>
    }

    impl UnionFind {
        pub fn new(size : usize) -> UnionFind {
            UnionFind {root : (0..size).collect()}
        }

        pub fn find(&mut self, x : usize) -> usize {
            let xroot = self.root[x];
            if x != xroot {
                self.root[x] = self.find(xroot);
            }
            self.root[x]
        }

        pub fn unite(&mut self, x : usize, y : usize) {
            let xroot = self.find(x);
            self.root[xroot] = self.find(y);
        }

        pub fn same(&mut self, x : usize, y : usize) -> bool {
            self.find(x) == self.find(y)
        }
    }
}

fn with_large_stack(func : fn() -> ()) {
    use std::thread::Builder;
    let builder = Builder::new();
    let th = builder.stack_size(10000000);

    th.spawn(move || {
        func();
    }).unwrap().join();
}

fn main() {
    with_large_stack(_main);
}

fn _main() {
    let mut reader = reader::Reader::new();
    let rgb: Vec<i32> = reader.nextN(3);
    println!("{}", if (rgb[1] * 10 + rgb[2]) % 4 == 0 {
        "YES"
    } else {
        "NO"
    });
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  ld avg = 0.0;
  rep(i, n) {
    cin >> v[i];
    avg += v[i];
  }
  avg /= n;
  int target = round(avg);

  int cost = 0;
  rep(i, n) { cost += (v[i] - target) * (v[i] - target); }

  cout << cost;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <bitset>
#include <utility>
#include <sstream>
#include <fstream>
#include <stack>
#include <cstdlib>
#include <complex>
#include <set>

using namespace std;

#define INF 1070000000LL
#define pb push_back
#define irep(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) irep(i,0,n)

typedef long long lint;
typedef pair<int, int> pint;
struct Edge{
    int to,weight;
};
typedef vector<vector<Edge> > Graph;
    

int main(){
    int x,y,z,k;
    cin >> x >> y >> z >> k;
    vector<lint> a(x);
    rep(i,x)cin >> a[i];
    vector<lint> b(y);
    rep(i,y)cin >> b[i];
    vector<lint> c(z);
    rep(i,z)cin >> c[i];

    priority_queue<lint> d;
    rep(i,x)rep(j,y)d.push(a[i]+b[j]);

    priority_queue<lint> all;
    rep(j,min(k,x*y)){
	auto top = d.top();
	rep(i,z){
	    all.push(c[i]+top);
	}
	d.pop();
    }

    rep(i,k){
	auto top = all.top();
	cout << top << endl;
	all.pop();
    }
}


Measured memory_bytes: 43368
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c=(int) a/b;
        int d=(int)a%b;
        double r=(double)a/b;
        System.out.printf("%d %d %f\n",c,d,r);
        
    }
}

Measured memory_bytes: 26228
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	total := 1
	bad := 1
	var a int
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		total *= 3
		if a%2 == 0 {
			bad *= 2
		}
	}

	fmt.Println(total - bad)
}


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

using namespace std;
using ll = long long int;
const int MOD = 1e6 + 3;

ll mpow(ll a, ll n, ll m = MOD)
{
	ll r = 1;
	while (n)
	{
		if (n&1) r = (r*a)%m;
		a = (a*a)%m;
		n >>= 1;
	}
	return r;
}

ll fac[MOD + 2];

void init()
{
	fac[0] = 1;
	for (ll i = 1; i <= MOD; ++i)
		fac[i] = (fac[i-1] * i)%MOD;
}

void solve()
{
	init();
	int q; cin >> q;
	while (q--)
	{
		ll x, d, n; cin >> x >> d >> n;
		if (x == 0) cout << 0 << '\n';
		else if (d == 0) cout << mpow(x, n) << '\n';
		else
		{
			ll ans = mpow(d, n);
			ll start = x * mpow(d, MOD-2) % MOD;
			if (start + n - 1 >= MOD) ans = 0;
			else
			{
				ans *= fac[start + n - 1];
				ans %= MOD;
				ans *= mpow(fac[start - 1], MOD-2);
				ans %= MOD;
			}
			cout << ans << '\n';
		}
	}
}

//  ---------------------Template---------------------------
void InputSetup()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
}

int main(void)
{
	auto start = chrono::high_resolution_clock::now();

	InputSetup();
	solve();

	auto finish = chrono::high_resolution_clock::now();
	cerr << "Time elapsed: " << (chrono::duration<long double>(finish-start)).count() << "s\n";
}
//  ---------------------Template---------------------------

Measured memory_bytes: 8704
#include <bits/stdc++.h>
using namespace std;
/// 最大値を更新
template<class T> inline bool chkMax(T& a, T b){
  if(a < b){
    a = b;
    return true;
  }
  return false;
}

int main() {
  int num;
  long long maxW;
  cin >> num >> maxW;
  
  long long w[num+1] = {0};
  long long v[num+1] = {0};
  long long dp[num+1][maxW+1];
  
  for(int i = 0; i < num; i++){
    cin >> w[i] >> v[i];
  }
  
  for(int i = 0; i < num+1; i++){
    for(int j = 0; j < maxW+1; j++){
      dp[i][j] = 0;
    }
  }
  
  for(int i = 0; i < num; i++){
    for(int sumW = 0; sumW <= maxW; sumW++){
      if(sumW - w[i] >= 0){
        chkMax(dp[i+1][sumW], dp[i][sumW - w[i]] + v[i]);
      }
      
      chkMax(dp[i+1][sumW], dp[i][sumW]);
    }
  }
  cout << dp[num][maxW];
}


Measured memory_bytes: 79104
#include <iostream>
#include <deque>

using namespace std;

int main() {
    int n;
    cin >> n;
    deque<int> v;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        switch (a) {
            case 0: {
                int d, x;
                cin >> d >> x;
                if (d == 0)v.push_front(x);
                else v.push_back(x);
                break;
            }
            case 1: {
                int b;
                cin >> b;
                cout << v[b] << endl;
                break;
            }
            case 2: {
                int d;
                cin >> d;
                if (d == 0)v.pop_front();
                else v.pop_back();
                break;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 4632
#include <cstdint>
#include <iostream>

using namespace std;

int main()
{
    int64_t s, c;
    cin >> s >> c;

    auto scc = min(s, c / 2);
    s -= scc;
    c -= 2 * scc;

    scc += c / 4;

    cout << scc << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (int)(s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
constexpr long long INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}

int A,B,C,D,E,F,G,X,Y,Z,N,M,W;
string s,t;

signed main(){
	string s;
	cin >> s;
	bool ng = false;
	REP(i,s.size()){
		if(i%2){
			if(!(s[i]=='L'||s[i]=='U'||s[i]=='D'))ng = true;
		}else{
			if(!(s[i]=='R'||s[i]=='U'||s[i]=='D'))ng = true;
		}
	}
	if(ng){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>

using namespace std;


int main(){
   string s;
   cin>>s;
   int ans=700;
   for(int i=0;i<3;i++){
      if(s.at(i)=='o'){
         ans+=100;
      }
   }
   cout<<ans<<endl;
   
   
   
}

Measured memory_bytes: 256
#include <stdio.h>
int main (void){
    int i;
    char m[1001];
    scanf("%s",m);
    for(i=0;i<1000;i++){
        if(m[i]=='\0')break;
        m[i]=m[i]-3;
        if(m[i]<65){
            m[i]=m[i]+26;
        }
    }
    printf("%s\n",m);
return 0;
}

Measured memory_bytes: 524
#include <iostream>

using namespace std;

long long A[200005];
long long bitcnt[21];

int main()
{
    long long N;
    long long ans = 0;
    long long l = 0, r = 0;
    cin >> N;
    bool flag;
    for (int i = 0; i < N; i++, r++)
    {
        flag = true;
        cin >> A[i];
        for (long long j = 0; j <= 20; j++)
        {
            bitcnt[j] += (A[i] & (1LL << j)) ? 1 : 0;
            if(bitcnt[j] > 1)
            {
                flag = false;
            }
        }
        if(flag == true)
        {
            ans += r - l + 1;
            //cout << "r:" << r << " l:" << l << endl;
            //cout << "ans:" << ans << endl;
        }
        else
        {
            while (1)
            {
                bool flag2 = true;
                for (long long j = 0; j <= 20; j++)
                {
                    bitcnt[j] -= (A[l] & (1LL << j)) ? 1 : 0;
                    if (bitcnt[j] > 1)
                    {
                        flag2 = false;
                    }
                }
                l++;
                if (flag2 == true)
                {
                    ans += r - l + 1;
                    break;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(a) a, a+sizeof(a)/sizeof(a[0])
using namespace std;

ll gcd(ll n, ll m) {
	if (m == 0) return n;
	return gcd(m, n % m);
}

ll lcm(ll n, ll m) {
	return m / gcd(n, m) * n;
}

int dp[100010];
int main(void) {
	int n, m;
	cin >> n >> m;

	vector<int> c(m);
	for (int i = 0; i < m; i++)
		cin >> c[i];

	for (int i = 1; i < 100010; i++)
		dp[i] = 1000000000;

	for (auto i : c) {
		for (int j = i; j < n+1; j++)
			dp[j] = min(dp[j], dp[j - i] + 1);
	}
	cout << dp[n] << endl;
	return 0;
}


Measured memory_bytes: 3480
# -*- coding: utf-8 -*-
# https://atcoder.jp/contests/abc138/tasks/abc138_d


def main():
    n, q = map(int, input().split())
    values = [0] * n
    links = [[] for _ in range(n)]

    for _ in range(n - 1):
        a, b = map(int, input().split())
        links[a - 1].append(b - 1)
        links[b - 1].append(a - 1)

    for _ in range(q):
        p, x = map(int, input().split())
        values[p - 1] += x

    s = [(0, -1)]
    while s:
        i, p = s.pop()
        for j in links[i]:
            if j == p:
                continue
            values[j] += values[i]
            s.append((j, i))

    print(*values)


main()


Measured memory_bytes: 110080
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
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 (a > b) { a = b; return 1; } return 0; }

ll rui(ll a,ll b){
     ll ans=1;
     while(b>0){
        if(b&1) ans=ans*a;
        a=a*a;
        b/=2;
    }
     return ans;
}

int main() {
    ll X; cin >> X;
    vector<ll> vc;
    ll A = MOD, B=MOD;
    ll i = 0;
    while(true){
        ll x = rui(i, 5);
        if(x > 10e15) break;
        vc.push_back(x);
        i++;
    }
    rep(i, vc.size()){
        rep(j, vc.size()){
            ll a = vc[i], b = vc[j];
            if(a - b == X)    A = i, B = j;
            
            if(a -(-b) == X) A = i, B = -j;
            if((-a) -b == X) A = -i, B = j;
            if((-a) -(-b) == X) A = -i, B = -j;
            if(A != MOD) break;
        }
    }
    cout << A << " " << B << ln;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
  int r, c;
  cin >> r >> c;
  vector<vector<int> > a(r + 1, vector<int>(c + 1, 0));
  for (int i = 0; i < r; i++){
    for (int j = 0; j < c; j++){
      cin >> a[i][j];
      a[i][c] += a[i][j];
      a[r][j] += a[i][j];
      a[r][c] += a[i][j];
    }
  }
  for (int i = 0; i <= r; i++){
    for (int j = 0; j <= c; j++){
      cout << a[i][j];
      if (j < c){
        cout << ' ';
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 3128
///
// File:  alds1_7_a.cpp
// Author: ymiyamoto
//
// Created on Fri Oct 13 00:56:58 2017
//

#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

static const int32_t null = -1;

struct tree_t {
  int32_t parent;
  int32_t left_child;
  int32_t right_sibling;

  tree_t()
  {
    parent = null;
    left_child = null;
    right_sibling = null;
  }
};

static vector<tree_t> tree;

string children(int32_t index)
{
  if (tree[index].left_child == null) {
    return "[]";
  } else {
    string ret = "[";
    int32_t right = tree[index].left_child;
    while (right != null) {
      if (right != tree[index].left_child) ret += ", ";
      ret += to_string(right);
      right = tree[right].right_sibling;
    }

    return ret + "]";
  }
}

string name(int32_t index)
{
  if (tree[index].parent == null) {
    return "root";
  } else if (tree[index].left_child == null) {
    return "leaf";
  } else {
    return "internal node";
  }
}

uint32_t depth(uint32_t index)
{
  uint32_t count = 0;
  int32_t parent = tree[index].parent;
  while (parent != null) {
    count += 1;
    parent = tree[parent].parent;
  }

  return count;
}

int32_t main()
{
  uint32_t n;
  cin >> n;

  tree.resize(n);

  for (uint32_t i = 0; i < tree.size(); i++) {
    int32_t id, k;
    cin >> id >> k;

    vector<int32_t> children;
    for (int32_t j = 0; j < k; j++) {
      int32_t c;
      cin >> c;
      children.push_back(c);
      tree[c].parent = id;

      if (j == 0) {
        tree[id].left_child = children[j];
      }
    }

    for (uint32_t j = 0; j + 1 < children.size(); j++) {
      tree[children[j]].right_sibling = children[j + 1];
    }
  }

  for (int32_t i = 0; i < (int32_t)tree.size(); i++) {
    cout << "node " << i << ": parent = " << tree[i].parent << ", ";
    cout << "depth = " << depth(i) << ", " << name(i) << ", ";
    cout << children(i) << endl;
  }

  return 0;
}

Measured memory_bytes: 5660
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=read::<String>().as_bytes().iter().filter(|c|**c as char=='o').count();
    println!("{}",a*100+700)
}


Measured memory_bytes: 4352
N = int(input())
A = list(map(float, input().split()))

A.sort(reverse = True)

while len(A) > 1:
  x = A[-1]
  A.pop()
  y = A[-1]
  A.pop()
  A.append((x + y) / 2)
  A.sort(reverse = True)

print(A[0])

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

using namespace std;

typedef long long LL;

int n,a[1005],b[1005];
bool f[1005],g[1005];
bool flag[1005];
vector<int> v;

int main()
{
	memset(f,false,sizeof(f));
	memset(g,false,sizeof(g));
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%d",&a[i]);
	LL sum1=0,sum2=0,ans;
	bool ff;
	ff=false;
	for (int i=1;i<=n;i+=2) 
	{
		if (a[i]>=0) ff=true;
		if (a[i]>=0) sum1+=a[i];
		if (a[i]>=0) f[i]=true;
	}
	if (!ff)
	{
		int pos=1;
		for (int i=1;i<=n;i+=2) if (a[i]>a[pos]) pos=i;
		sum1=a[pos];
		f[pos]=true;
	}
	ff=false;
	for (int i=2;i<=n;i+=2) 
	{
		if (a[i]>=0) ff=true;
		if (a[i]>=0) sum2+=a[i];
		if (a[i]>=0) g[i]=true;
	}
	if (!ff)
	{
		int pos=2;
		for (int i=2;i<=n;i+=2) if (a[i]>a[pos]) pos=i;
		sum2=a[pos];
		g[pos]=true;
	}
	ans=max(sum1,sum2);
	printf("%lld\n",ans);
	if (sum1>sum2)
	{
		memset(flag,false,sizeof(flag));
		while (true)
		{
			int sum=0;
			for(int i=1;i<=n;++i) if (!flag[i])
			{
				++sum;b[sum]=i;
			}
			if (sum==1) break;
			if (!f[b[1]])
			{
				v.push_back(1);
				flag[b[1]]=true;
				continue;
			}
			if (!f[b[sum]])
			{
				v.push_back(sum);
				flag[b[sum]]=true;
				continue;
			}
			for (int i=2;i<sum;++i)
			{
				if (f[b[i-1]]&&f[b[i+1]])
				{
					flag[b[i-1]]=true;
					flag[b[i+1]]=true;
					v.push_back(i);
					f[b[i]]=true;
					break;
				}
				if ((!f[b[i-1]])&&(!f[b[i+1]]))
				{
					flag[b[i-1]]=true;
					flag[b[i+1]]=true;
					v.push_back(i);
					break;
				}
			}
		}
	}
	else
	{
		memset(flag,false,sizeof(flag));
		while (true)
		{
			int sum=0;
			for(int i=1;i<=n;++i) if (!flag[i])
			{
				++sum;b[sum]=i;
			}
			if (sum==1) break;
			if (!g[b[1]])
			{
				v.push_back(1);
				flag[b[1]]=true;
				continue;
			}
			if (!g[b[sum]])
			{
				v.push_back(sum);
				flag[b[sum]]=true;
				continue;
			}
			for (int i=2;i<sum;++i)
			{
				if (g[b[i-1]]&&g[b[i+1]])
				{
					flag[b[i-1]]=true;
					flag[b[i+1]]=true;
					v.push_back(i);
					g[b[i]]=true;
					break;
				}
				if ((!g[b[i-1]])&&(!g[b[i+1]]))
				{
					flag[b[i-1]]=true;
					flag[b[i+1]]=true;
					v.push_back(i);
					break;
				}
			}
		}
	}
	printf("%d\n",(int)v.size());
	for (int i=0;i<v.size();++i) printf("%d\n",v[i]);
	return 0;
}

Measured memory_bytes: 384
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int x, y;
  cin >> x >> y;
  string ans;
  if (x == y) ans = "Draw";
  else if (x == 1 || (x > y && y != 1)) ans = "Alice";
  else if (y == 1 || x < y) ans = "Bob";
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <deque>
#include <queue>
using namespace std;

int visited[100100] = {0};
vector<vector<int>> con(100100);
int N, M;
int X, Y, Z;

void dfs(int x) {
    int len = con[x].size();
    for (int i=0; i<len; ++i) {
        if (visited[con[x][i]] == 0) {
            visited[con[x][i]] = 1;
            dfs(con[x][i]);
        }
    }
}

int main() {
    cin >> N >> M;
    for (int i=0; i<M; ++i) {
        cin >> X >> Y >> Z;
        con[X].push_back(Y);
        con[Y].push_back(X);
    }
    int ans = 0;
    for (int i=1; i<=N; ++i) {
        if (visited[i] == 1) continue;
        else {
            ++ans;
            dfs(i);
        }
    }

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

Measured memory_bytes: 9216
#include <bits/stdc++.h>
#include <list>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, a, p, ag;
bool nps[1000005], pw = true;
list<int> pl;
int main(){
	for(int i=2; i<=1000000; i++) if(!nps[i]){
		if(i<=1000) pl.push_back(i);
		for(int j=i*2; j<=1000000; j+=i) nps[j] = true; 
	}
	scanf("%d", &n);
	rep(i,n){
		scanf("%d", &a);
		ag = i ? gcd(ag,a) : a;
		for(auto it = pl.begin(); it != pl.end(); ){
			int t = *it;
			if(a % t == 0){
				while(a % t == 0) a /= t;
				nps[t] = true;
				it = pl.erase(it);
			}else ++it;
		}
		if(nps[a]) pw = false;
		else if(a != 1) nps[a] = true;
	}
	printf("%s coprime\n", pw ? "pairwise" : ag == 1 ? "setwise" : "not");
}

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

int d;
int x[12][12];

int is_integer(int i, int j) {
  int dist = 0, inc = 1;
  rep (k, d) dist += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
  while (inc * inc <= dist) {
    if (inc * inc == dist) return 1;
    inc++;
  }
  return 0;
}

int main() {
  int n;
  cin >> n >> d;
  int ans = 0;
  rep (i, n) rep (j, d) cin >> x[i][j];
  rep (i, n) rep (j, i) ans += is_integer(i, j);
  cout << ans << endl;
  return 0;
}

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

int main(){
	int w,h,n;
	cin >>w>>h>>n;
	int a,b,c;
	int l=0,r=w,u=h,d=0;
	for(int i =0 ; i< n;i++) {
		cin >> a >> b >> c;
		switch (c) {
		case 1:
			if(l<a)
				l=a;
			break;
		case 2:
			if(r>a)
				r=a;
			break;
		case 3:
			if(d<b)
				d=b;
			break;
		case 4:
			if(u>b)
				u=b;
			break;
		}
	}
	cout << max(r-l,0)*max(u-d,0) << endl;
	
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

const int MAX_N = 100000;
const int MAX_W = 10000;

bool C(long long lim, int n, int k, long long w[MAX_N]){
    int i = 0;
    rep(j,k){
        long long s = 0;
        while(s + w[i] <= lim){
            s += w[i];
            i++;
            if(i == n) return true;
        }
    }
    return false;
}


int main(){
    int n, k;
    long long w[MAX_N];
    cin >> n >> k;
    rep(i,n) cin >> w[i];

    long long right = MAX_W * MAX_N, left = 0;
    while(right - left > 1){
        long long mid = (right + left) / 2;
        if(C(mid, n, k, w)) right = mid;
        else left = mid;
    }
    cout << left + 1 << endl;
}

Measured memory_bytes: 3828
n = int(input())
a = list(reversed(list(map(int, input().split()))))

dp = [0]*n
for i in range(n):
    now = a[i]
    if i%2 == 0:
        dp[i//2] = now
    else:
        dp[-(i//2 + 1)] = now
print(" ".join(map(str, dp)))


Measured memory_bytes: 29732
n = gets.to_i
cards = gets.chomp.split.map(&:to_i)
puts cards.join(" ")
for i in (1 .. n - 1)
    card = cards[i]
    j = i - 1    
    while j >= 0 && cards[j] > card
        cards[j + 1] = cards[j]
        j -= 1
    end
    cards[j + 1] = card
    puts cards.join(" ")
end

Measured memory_bytes: 8848
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())


#n = ip()                              #入力整数1つ
#a,b= (int(i) for i in input().split())      #入力整数横2つ
#k,a,b = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
a = input().split()                          #入力文字配列

#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意

b = ''.join([a[0],a[1]])
c = int(b)
j(pow(int(np.sqrt(c)),2) == c)

Measured memory_bytes: 13560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test
{

    class Program
    {
        static void Main(string[] args)
        {
            List<int> resultList = new List<int>();

            string input;
            while ((input = Console.ReadLine()) != null)
            {
                string[] array = input.Split(',');
                int v1 = 0;
                int v2 = 0;
                List<int> distanceList = new List<int>();
                double totalDistance = 0;

                for (int i = 0; i < 12; i++)
                {
                    switch (i)
                    {
                        case 10:
                            v1 = int.Parse(array[i]);
                            break;
                        case 11:
                            v2 = int.Parse(array[i]);
                            break;
                        default:
                            distanceList.Add(int.Parse(array[i]));
                            totalDistance += int.Parse(array[i]);
                            break;
                    }                        
                }

                //走行距離
                double mileage = totalDistance * v1 / (v1 + v2);

                int kukan = 1;

                foreach (int d in distanceList)
                {
                    if ((mileage -= d) <= 0)
                    {
                        break;
                    }

                    kukan++;
                }

                resultList.Add(kukan);
            }

            foreach (int a in resultList)
            {
                Console.WriteLine(a);
            }


        }

        
    }
}

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

#define long long long

using namespace std;

const int N = 1e3+5;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const char dir[4] = {'L', 'D', 'R', 'U'};

int n, X[N], Y[N];

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d %d", X + i, Y + i);
    
    bool chk = (X[1] + Y[1]) & 1;
    for(int i = 2; i <= n; i++) if(((X[i] + Y[i]) & 1) != chk) {
        printf("-1\n");
        return 0;
    }
    if(!chk) {
        printf("32\n");
        printf("1 ");
        for(int i = 1; i <= n; i++) --X[i];
    } else printf("31\n");
    for(int i = 0; i <= 30; i++) printf("%d ", 1 << i);
    printf("\n"); 

    for(int i = 1; i <= n; i++) {
        long x = X[i], y = Y[i];
        vector<char> ans;
        for(int j = 30; ~j; j--) {
            long now = 1ll << j;
            for(int k = 0; k < 4; k++) if(abs(x + now * dx[k]) + abs(y + now * dy[k]) <= now - 1) {
                x += now * dx[k], y += now * dy[k];
                ans.emplace_back(dir[k]);
                break;
            }
        }
        if(!chk) ans.emplace_back('R');
        reverse(ans.begin(), ans.end());
        for(char c : ans) printf("%c", c);
        printf("\n");
    }


    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
void call(int n);
int main(){
    int n;
    cin>>n;
    call(n);
}
void call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}


Measured memory_bytes: 3116
s = input()
S = []
for i in range(len(s)):
    S.append(s[i])
j = 0

while True:
    if S[j] == "B" and j != 0:
        del S[j - 1]
        del S[j - 1]
        j = 0
    elif S[j] == "B" and j == 0:
        del S[j]
    else:
        if j == len(S) - 1 or len(S) == 1:
            break
        j = j + 1

print("".join(S))

Measured memory_bytes: 3064
n=int(input())
s=str(input())
 
def isThere(suji):
    flag1=False
    flag2=False
    flag3=False
    for i in s:
        if flag2==True and suji[2]==i:
            flag3=True
            break
        if flag1==True and suji[1]==i:
            flag2=True
        if suji[0]==i:
            flag1=True
    return flag3 
 
candidate=list(range(1000))
candidate=['0'+'0'+str(candidate[i]) if candidate[i]<10 else ('0'+str(candidate[i]) if 9<candidate[i]<100 else str(candidate[i])) for i in range(1000)]
ans=0
for suji in candidate:
    if isThere(suji):
        ans+=1
print(ans)

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

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x,y;
	cin >> x >> y;
	int t1 = ( y - 2 * x ) / 2;
	if( y - 2 * x < 0 || ( y - 2 * x ) % 2 != 0 )
	{
		cout << "No" << '\n';
		return 0;
	}
	int t2 = x - t1;
	if( t2 < 0 )
	{
		cout << "No" << '\n';
	}else cout << "Yes" << '\n';
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>

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



int main(){
    int n; cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int maxh = 0;
    int ans = 0;
    rep(i,n){
        if (h[i] >= maxh) {
            ans++;
            maxh = max(maxh , h[i]);
        }
    }
    cout << ans << endl;
    
}



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

#define ll long long
#define endl "\n"

int main ()
{

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

    int n, m, k;
    cin >> n >> m >> k;
    
    vector <int> a, b;
    
	a.emplace_back(0);
    b.emplace_back(0);
    
    for (int i=0; i<n; i++){
    	int aa;
    	cin >> aa;
    	a.emplace_back(a.back() + aa);
	}
	
	for (int i=0; i<m; i++){
    	int aa;
    	cin >> aa;
    	b.emplace_back(b.back() + aa);
	}    
	
	int ans = 0;
	int j = m;
	for (int i=0; i<=n; i++){
		while (a[i] + b[j] > k and j > 0) j--;
		if (a[i] + b[j] <= k){
			ans = max(ans, i + j);
		}
	}
	
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 7920
def main():
    args = input().split()

    list = []
    for x in args:
        if x == "+":
            b = list.pop()
            a = list.pop()
            list.append(a + b)
        elif x == "-":
            b = list.pop()
            a = list.pop()
            list.append(a - b)
        elif x == "*":
            b = list.pop()
            a = list.pop()
            list.append(a * b)
        else:
            list.append(int(x))

    print(list[0])

if __name__ == "__main__":
    main()


Measured memory_bytes: 5600
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
typedef long long ll;
 
vector<pair<int, int>> to[100010];
bool visited[100010];
ll dist[100010];
int main() {
    int n,m,k;
    cin>>n>>m>>k;
    vector<ll>a(n);
    vector<ll>b(m);
    rep(i,0,n)cin>>a[i];
    ll t = 0;
    int j = 0;
    rep(i,0,m){
        cin>>b[i];
        t+=b[i];
        j++;
        if(t>k){
           t-=b[i];
           j--;
           break;
        }
    }
    int ans = 0;
    rep(i,0,n+1){
        while( j>0 && t>k){
            j--;
            t-=b[j];
        }
         
        if(t>k)break;
        t+=a[i];
        ans = max(ans, i+j);
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define FORV(a, A) for (auto &a : A)

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

void Main() {
  int n;  // [1, 2e5]
  cin >> n;
  map<string, int> m;
  rep(i, n) {
    string s;
    cin >> s;
    m[s]++;
  }
  int mx = 0;
  for (auto itr = m.begin(); itr != m.end(); ++itr) {
    mx = max(mx, itr->second);
  }
  vector<string> ans;
  for (auto itr = m.begin(); itr != m.end(); ++itr) {
    if (itr->second == mx) ans.emplace_back(itr->first);
  }
  sort(ans.begin(), ans.end());
  for (auto s : ans) cout << s << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 25584
k,n=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
A=a[-1]
iti=k-A
hantei=10**9
for i in range(1,n-1):
  #右回り
  sr=k+a[i-1]-a[i]
  #左回り
  sl=k-(a[i+1]-a[i])
  if hantei>sr:
    hantei=sr
  if hantei>sl:
    hantei=sl
if hantei>(a[-1]-a[0]):
  hantei=(a[-1]-a[0])
print(hantei)
  

Measured memory_bytes: 26444
// 最長共通部分列
// O(|S||T|)

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()


int LongestCommonSubsequence(const string &s, const string &t) {
  int n = (int)s.size();
  int m = (int)t.size();

  vector<vector<int>> dp(n + 1, vector<int> (m + 1, 0));
  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= m; j++) {
      dp[i][j] = max(dp[i][j], dp[i - 1][j]);
      dp[i][j] = max(dp[i][j], dp[i][j - 1]);
      dp[i][j] = max(dp[i][j], dp[i - 1][j - 1]);
      if(s[i - 1] == t[j - 1]) dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1);
    }
  }
  
  return dp[n][m];
}


int main() {
  int q; cin >> q;
  for(int i = 0; i < q; i++) {
    string s, t; cin >> s >> t;
    cout << LongestCommonSubsequence(s, t) << endl;
  }
  return 0;
}




Measured memory_bytes: 6852
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <map>
#include <iostream>
#include <queue>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(const void *a, const void *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(const void *a, const void *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(const void* left, const void* right) {return strcmp((char *)left,(char *)right);}
int downchar(const void* left, const void* right) {return strcmp((char *)right,(char *)left);}
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1){
            res *= a; if(mod>=1) res %= mod;
        }
        a *= a; if(mod>=1) a %= mod;
        n >>= 1;
    }
    return res;
}
void initialize(){
    
}
int main(void){
  initialize();
  ll n,m,i,j,k;
  int a[LIMIT2]={0},b[LIMIT1]={0};
  char s[LIMIT1];
  std::vector<ll> p[LIMIT1];
  std::queue<ll> que;
  ll result[LIMIT1]={0};
  ll visited[LIMIT1]={0};
  
  scanf("%lld %lld",&n,&m);
  rep(i,m){
    scanf("%d %d",&a[i],&b[i]);
    a[i]--;
    b[i]--;
    p[a[i]].push_back(b[i]);
    p[b[i]].push_back(a[i]);
  }
  que.push(0);
  result[0]=0;
  while(!que.empty()){
    i = que.front();
    que.pop();
    if(visited[i]>=1) continue;
    visited[i]=1;
    while(!p[i].empty()){
      j = p[i][p[i].size()-1];
      p[i].pop_back();
      if(visited[j]>=1||result[j]>=1) continue;
      result[j]=i+1;
      que.push(j);
    }
  }
  printf("Yes\n");
  for(i=1;i<n;i++){
    printf("%lld\n",result[i]);
  }
  return 0;
}



Measured memory_bytes: 20652
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;
struct edge {
    int to;
    int cap;
    int rev;
};

vector <edge> edges[202];
int level[202];
int iter[202];

void add_edge(int from, int to, int cap){
    edges[from].push_back((edge){to, cap, (int) edges[to].size()});
    edges[to].push_back((edge) {from, 0, (int) edges[from].size() - 1});
}

void bfs(int s){
    memset(level, -1, sizeof(level));
    queue <int> q;
    level[s] = 0;
    q.push(s);
    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(int i = 0; i < edges[v].size(); i++){
            edge &e = edges[v][i];
            if(e.cap > 0 && level[e.to] < 0){
                level[e.to] = level[v] + 1;
                q.push(e.to);
            }
        }
    }
}

int dfs(int v, int t, int f){
    if(v == t){
        return f;
    }

    for(int &i = iter[v]; i < edges[v].size(); i++){
        edge &e = edges[v][i];
        if(e.cap > 0 && level[v] < level[e.to]){
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                edges[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int dinic(int s, int t){
    int flow = 0;
    while(true){
        bfs(s);
        if(level[t] < 0){
            return flow;
        }
        memset(iter, 0, sizeof(iter));
        while(true){
            int f = dfs(s, t, INT_MAX);
            if(f <= 0){
                break;
            }
            flow += f;
        }
    }
    return 0;
}

int a[100];
int b[100];
int c[100];
int d[100];
int main(void){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i] >> b[i];
    }
    for(int i = 0; i < N; i++){
        cin >> c[i] >> d[i];
    }

    for(int i = 0; i < N; i++){
        add_edge(0, i + 1, 1);
    }
    for(int i = 0; i < N; i++){
        add_edge(1 + N + i, 2 * N + 1, 1);
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            if(a[i] < c[j] && b[i] < d[j]){
                add_edge(i + 1, 1 + N + j, 1);
            }
        }
    }
    cout << dinic(0, 2 * N + 1) << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, m, in, sum = 0;
	vector<double> vec;
	cin >> n >> m;
	for (int i = 0; i < n; ++i) {
		cin >> in;
		vec.push_back(in);
		sum += in;
	}
	bool b = true;
	sort(vec.begin(), vec.end(), greater<int>());
	double a = m * 4;
	double c = (double)sum / a;
	for (int i = 0; i < m; ++i) {
		if (vec[i] < c)
		{
			b = false;
			break;
		}
	}
	string str;
	if (b) str = "Yes";
	else str = "No";
	cout << str << "\n";
	   
	//system("pause");
	
	return 0;
}

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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 200010, M = 10, mod = 1e9 + 7;

int n;
int a[N], b[N];

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++ ) scanf("%d", a + i);
	
	vector<int> res;
	for (int i = n; i; i -- )
	{
		int cnt = 0;
		for (int j = i; j <= n; j += i) cnt += b[j];
		
		b[i] = (cnt % 2) ^ a[i];
		if (b[i]) res.push_back(i);
	}
	
	cout << res.size() << endl;
	for (auto u : res) cout << u << ' ';
	puts("");
	return 0;
}

Measured memory_bytes: 3064
#include<set>   
#include<map>  
#include<stack> 
#include<cmath>   
#include<cstdio>   
#include<queue>   
#include<vector>   
#include<climits>   
#include<cstring>   
#include<iostream>   
#include<algorithm>   
using namespace std;
#define MAXN 100
#define INF 0x3f3f3f3f 
int read()  
{  
    int f=1,x=0;  
    char c=getchar();  
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}  
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();}  
    return f*x;  
}
struct node{
	int x,y;
}red[MAXN+5],blue[MAXN+5];
bool vis[2*MAXN+5];
vector<int> G[2*MAXN+5];
int n,match[2*MAXN+5];
bool DFS(int u){
	for(int i=0;i<int(G[u].size());i++){
		int v=G[u][i];
		if(vis[v]) continue;
		vis[v]=1;
		if(!match[v]||DFS(match[v]))
		{
			match[v]=u;
			match[u]=v;
			return 1;
		}
	}
	return 0;
}
int main(){
	n=read();
	for(int i=1;i<=n;i++)
		red[i].x=read(),red[i].y=read();
	for(int i=1;i<=n;i++)
	{
		blue[i].x=read(),blue[i].y=read();
		for(int j=1;j<=n;j++)
			if(red[j].x<blue[i].x&&red[j].y<blue[i].y)
				G[n+i].push_back(j),G[j].push_back(n+i);
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		if(!match[i])
		{
			memset(vis,0,sizeof vis);
			if(DFS(i)) ans++;
		}
	printf("%d\n",ans);
	return 0;  
} 


Measured memory_bytes: 504
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
#define ll long long
#define MOD 1000000007
#define INF 0x3fffffff
#define mod(x) (x%MOD)
#define CLR(a,x) memset(a,x,sizeof(a)
#define FILL(a,n,x) fill(a,a+n,x)
#define WHILE() int T;scanf("%d",&T);while(T--)
const double PI = acos(-1.0);
string s;
int w;
int main()
{
    //freopen("DATA.c", "r", stdin);
    ios::sync_with_stdio(false); cin.tie();cout.tie();
    cin>>s>>w;
    for(int i=0;i<s.size();i++){
        if(i%w==0){
            cout<<s[i];
        }
    }
    cout<<endl;
    return 0;
}


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

int main()
{
	ios::sync_with_stdio(false);
	int n,m;
	cin>>n>>m;
	int a[n];
	int sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	double aver=sum*1.0/(4.0*m);
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]>=aver)
			cnt++;
	}
	if(cnt>=m)
		cout<<"Yes";
	else cout<<"No";
	
  	return 0;
}
 

Measured memory_bytes: 256