akhauriyash/Code-Regression huggingface dataset:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def f():
    n,t = list(map(int,input().split()))
    a = list(map(int,input().split()))
    m = 0
    mc = inf
    r = 0
    for c in a:
        if mc > c:
            mc = c
            continue
        if c - mc > m:
            m = c - mc
            r = 1
            continue
        if c - mc == m:
            r += 1
    return r

print(f())


Measured memory_bytes: 19148
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;

// 10^9 = 2^30;
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll allxor = 0;
  rep(i, n) allxor = allxor^a[i];
  rep(i, n) {
    ll ans = 0;
    ll cur = a[i];
    ans = allxor ^ a[i];
    cout << ans << endl;
  }

}

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

#define ll long long

const int mxN = 1e3, mxW = 1e5;
ll N, W, w[mxN], v[mxN], dp[mxN+1][mxW+1];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> W;
	for(int i = 0; i < N; ++i)
		cin >> w[i] >> v[i];
	for(int i = 1; i <= N; ++i){
		for(int j = 1; j <= W; ++j){
			dp[i][j] = dp[i-1][j];
			if(j>=w[i-1])
				dp[i][j] = max(dp[i][j], dp[i-1][j-w[i-1]]+v[i-1]);
		}
	}
	cout << dp[N][W] << '\n';
	return 0;
}



Measured memory_bytes: 81740
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Read, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::str::FromStr;

// abd.rs --- ABD
// author: Seong Yong-ju <sei40kr@gmail.com>

#[allow(unused_macros)]
macro_rules! get {
  ($t:ty) => {
    {
      let mut line: String = String::new();
      stdin().read_line(&mut line).unwrap();
      line.trim().parse::<$t>().unwrap()
    }
  };
  ($($t:ty),*) => {
    {
      let mut line: String = String::new();
      stdin().read_line(&mut line).unwrap();
      let mut iter = line.split_whitespace();
      (
        $(iter.next().unwrap().parse::<$t>().unwrap(),)*
      )
    }
  };
  ($t:ty; $n:expr) => {
    (0..$n).map(|_|
                get!($t)
    ).collect::<Vec<_>>()
  };
  ($($t:ty),*; $n:expr) => {
    (0..$n).map(|_|
                get!($($t),*)
    ).collect::<Vec<_>>()
  };
  ($t:ty ;;) => {
    {
      let mut line: String = String::new();
      stdin().read_line(&mut line).unwrap();
      line.split_whitespace()
        .map(|t| t.parse::<$t>().unwrap())
        .collect::<Vec<_>>()
    }
  };
  ($t:ty ;; $n:expr) => {
    (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
  };
}

#[allow(unused_macros)]
macro_rules! debug {
  ($($a:expr),*) => {
    println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
  }
}

#[allow(dead_code)]
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")
}

#[allow(dead_code)]
fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) {
    let out = stdout();
    let writer = BufWriter::new(out.lock());
    f(writer);
}

fn main() {
    let n = get!(u32);
    assert!(1 <= n);
    assert!(n <= 1998);
    let ans = if n <= 999 { "ABC" } else { "ABD" };

    with_bufwriter(|mut out| writeln!(out, "{}", ans).unwrap());
}


Measured memory_bytes: 4352
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}

console.log(main());
function main(){
  var n = o.a();
  var l = o.a();
  var s = 0, z = l;
  for(var i = 1; i <= n; i++){
    var t = l+i-1;
    s += t;
  }
  if(l>0)s-=l;
  else if(t<0)s -= t;
  return s;
}

Measured memory_bytes: 21064
import java.util.Scanner;

public class Main
{

	public static void main(String[] args)
	{
		Scanner in =new Scanner(System.in);
		int w,h,x,y,r;
		w=in.nextInt();
		h=in.nextInt();
		x=in.nextInt();
		y=in.nextInt();
		r=in.nextInt();
		
		if( ((x+r)>w) || ((x-r) < 0) || ((y+r) > h) || ((y-r)<0))
			System.out.println("No");
		else {
			System.out.println("Yes");
		}
	}

}

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

int main(){
    int n;
    long long c;
    cin >> n >> c;
    long long x[n],v[n];
    for(int i=0; i<n; i++){
        cin >> x[i] >> v[i];
    }
    long long right[n],left[n];
    long long max_r[n],max_l[n];
    long long sum = 0;
    for(int i=0; i<n; i++){
        sum += v[i];
        right[i] = sum-x[i];
    }
    max_r[0] = right[0];
    for(int i=1; i<n; i++){
        if(right[i] > max_r[i-1]) max_r[i] = right[i];
        else max_r[i] = max_r[i-1];
    }
    sum = 0;
    for(int i=0; i<n; i++){
        sum += v[n-1-i];
        left[n-1-i] = sum-(c-x[n-1-i]);
    }
    max_l[n-1] = left[n-1];
    for(int i=n-2; i>=0; i--){
        if(left[i] > max_l[i+1]) max_l[i] = left[i];
        else max_l[i] = max_l[i+1];
    }
    long long ans = 0;
    for(int i=0; i<n-1; i++){
        long long tmp = right[i]-x[i]+max_l[i+1];
        ans = max(ans,tmp);
    }
    for(int i=n-1; i>=1; i--){
        long long tmp = left[i]-(c-x[i])+max_r[i-1];
        ans = max(ans,tmp);
    }
    auto p = max_element(right,right+n);
    ans = max(ans,*p);
    p = max_element(left,left+n);
    ans = max(ans,*p);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4992
-- Drawing Lots
import Control.Monad
import Data.List.Split

main :: IO ()
main =
  readLn >>= \w ->
  readLn >>= \n ->
  replicateM n getLine >>= \ss ->
  putStr $ solve ss w

solve :: [String] -> Int -> String
solve ss = unlines . map show . swapM (map toTuple ss) . amida

swapM :: [(Int, Int)] -> [Int] -> [Int]
swapM ls xs = foldl swap xs ls

swap :: [Int] -> (Int, Int) -> [Int]
swap xs (i,j) = [swap' a b | (a,b) <- zip [1..length xs] xs]
  where
    swap' a b | a == i = xs !! (j - 1)
              | a == j = xs !! (i - 1)
              | otherwise = b

amida :: Int -> [Int]
amida = \w -> [1..w]

toTuple :: String -> (Int, Int)
toTuple xs = (a,b)
  where
    [a,b] = map read . splitOn "," $ xs

Measured memory_bytes: 4224
#include <iostream>

using namespace std;

int main(){
  int n,m,p;
  while(cin >> n >> m >> p,n||m){
    int i,x[n],sum=0;
    --m;
    for(i=0;i<n;i++){
      cin >> x[i];
      sum+=x[i]*100;
    }
    sum-=(sum*p/100);
    if(x[m]==0)cout << 0 << endl;
    else cout << sum/x[m] << endl;
  }
  return 0;
}



Measured memory_bytes: 3036
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k, x ;
  cin >> k >> x ;
  if(k*500>=x){
    yes() ;
  }
  else{
    no() ;
  }
  
  
  
  return 0 ;
}




Measured memory_bytes: 256
#include <iostream>
#define rep(i) for(i=0;i<5;i++)
using namespace std;
int main(){
  int a[5],i;
  while(cin>>a[0],a[0]){
    int b[3]={0};
    b[a[0]-1]++;
    for(i=1;i<5;i++){
      cin>>a[i];
      b[a[i]-1]++;
    }
    if(b[0]&&b[1]&&!b[2])rep(i)cout<<((a[i]==1)?1:2)<<endl;
    else if(b[0]&&!b[1]&&b[2])rep(i)cout<<((a[i]==3)?1:2)<<endl;
    else if(!b[0]&&b[1]&&b[2])rep(i)cout<<((a[i]==2)?1:2)<<endl;
    else rep(i)cout<<'3'<<endl;
  }
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#include <set>
#include <vector>
using namespace std;
#define rep(i,n) for(ll i = 0; i < n; ++i)
#define Rep(i,n) for(ll i = 0; i <= n; ++i)

#define yes "yes"
#define Yes "Yes"
#define no "no"
#define No "No"

namespace mydef
{
  void say(string some){
    cout << some << "\n";
  }
} // namespace mydef
using namespace mydef;
using P = pair<int,int>;
typedef long long ll;
const int INF = 1001001001;
const long double PI=3.14159265358979323846;

//ここから書く

const int M = 1001001;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> cnt(M);
  for(int x : a){
    if (cnt[x] != 0)
    {
      cnt[x] = 2;
      continue;
    }
    for(int i = x; i < M; i+=x)cnt[i]++;
  }
  int ans = 0;
  for(int x : a){
    if(cnt[x] == 1) ans++;
  }
  cout << ans << endl;

  return 0;
}




Measured memory_bytes: 7872
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)

void chmax(ll& a, ll b) { a = max(a, b); }
void chmin(ll& a, ll b) { a = min(a, b); }


int main() {
    ll n; cin >> n;
    string s = to_string(n);
    int x = 0;
    rep(i, s.size()) {
        x += s[i] - '0';
    }
    
    if(n%x == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, c, cnt;
int d[500020];
vector<pair<int, int> > a[500020];
map<int, int> g[100020];
deque<int> q;
int get(int x, int y) {
	if (g[x].count(y)) {
		return g[x][y];
	}
	return g[x][y] = ++cnt;
}
void add(int x, int y, int z) {
	a[x].push_back(make_pair(y, z));
	a[y].push_back(make_pair(x, z));
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) {
		get(i, 0);
	}
	for (int i = 0; i < m; i++) {
		scanf("%d%d%d", &x, &y, &c);
		int x0 = get(x, 0), xc = get(x, c);
		int y0 = get(y, 0), yc = get(y, c);
		add(xc, yc, 0);
		add(x0, yc, 1);
		add(xc, y0, 1);
	}
	memset(d, -1, sizeof d);
	d[1] = 0;
	q.push_back(1);
	while (q.size()) {
		int u = q.back();
		q.pop_back();
		for (pair<int, int> i: a[u]) {
			if (d[i.first] == -1 || d[i.first] > d[u] + i.second) {
				d[i.first] = d[u] + i.second;
				if (i.second == 1) {
					q.push_front(i.first);
				} else {
					q.push_back(i.first);
				}
			}
		}
	}
	printf("%d\n", d[n] >> 1);
	return 0;
}


Measured memory_bytes: 60544
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

def yn(b):
    print("Yes" if b==1 else "No")
    return

def resolve():
    readline=sys.stdin.readline

    #n,m,k=map(int, readline().rstrip().split())
    x=list(map(int, readline().rstrip().split()))
    #n=int(readline())
    #ss=readline().rstrip()
    #yn(1)
    for i in range(len(x)):
        if x[i]==0:
            print(i+1)
            return

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 16164
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;

class Program
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N;
    void solve()
    {
        var T = cin.scanint;
        int ans = 0;
        for (int i = 0; i < 100; i++)
        {
            if (T[0] <= i && i < T[1] && T[2] <= i && i < T[3])
            {
                ans++;
            }
        }
        WriteLine(ans);
    }
}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 11216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @author Lin
 * @version 1.0
 * @date 2020/8/3 15:56
 */
public class Main
{
	static long INF = 123245452356732L;
	public static void main(String[] args) throws IOException
	{
		String next = Reader.nextLine();
		StringBuffer stringBuffer = new StringBuffer();
		while (!"0 0".equals(next))
		{
			int n = Integer.parseInt(next.split(" ")[0]);
			int m = Integer.parseInt(next.split(" ")[1]);
			long ans = INF;
			long[][] dis_1 = new long[n][n];
			long[][] dis_2 = new long[n][n];
			for (int i = 0; i < n; i++)
			{
				Arrays.fill(dis_1[i], INF);
				Arrays.fill(dis_2[i], INF);
				dis_1[i][i] = 0;
				dis_2[i][i] = 0;
			}
			for (int i = 0; i < m; i++)
			{
				String[] line = Reader.nextLine().split(" ");
				int u = Integer.parseInt(line[0]) - 1;
				int v = Integer.parseInt(line[1]) - 1;
				int cost = Integer.parseInt(line[2]);
				if ("L".equals(line[3]))
				{
					dis_1[u][v] = cost;
					dis_1[v][u] = cost;
				} else
				{
					dis_2[u][v] = cost;
					dis_2[v][u] = cost;
				}
			}
			floyd(dis_1, n);
			floyd(dis_2, n);
			int len = Reader.nextInt();
			int[] linked = new int[len];
			for (int i = 0; i < len; i++)
			{
				linked[i] = Reader.nextInt() - 1;
			}
			long[][] dp = new long[len][n];
			for (int i = 0; i < n; i++)
			{
				dp[0][i] = dis_2[linked[0]][i];
			}
			for (int i = 1; i < len; i++)
			{
				for (int j = 0; j < n; j++)
				{
					dp[i][j] = (dp[i - 1][j] + dis_1[linked[i - 1]][linked[i]]);

					for (int k = 0; k < n; k++)
					{

						dp[i][j] = Math.min(dp[i][j], (dp[i - 1][k] + dis_1[linked[i-1]][k]+dis_2[k][j] + dis_1[j][linked[i]]));
					}
				}
			}
			for (int i = 0; i < n; i++)
			{
				ans = Math.min(ans, dp[len - 1][i]);
			}
			System.out.println(ans);
			next = Reader.nextLine();
		}
	
	}

	private static void floyd(long[][] dis, int n)
	{
		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				for (int k = 0; k < n; k++)
				{
					dis[j][k] = Math.min(dis[j][i] + dis[i][k], dis[j][k]);
				}
			}
		}
	}

	static class Reader
	{
		static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		static StringTokenizer tokenizer = new StringTokenizer("");

		static String nextLine() throws IOException
		{// 读取下一行字符串
			return reader.readLine();
		}

		static String next() throws IOException
		{// 读取下一个字符串
			while (!tokenizer.hasMoreTokens())
			{
				tokenizer = new StringTokenizer(reader.readLine());
			}
			return tokenizer.nextToken();
		}

		static int nextInt() throws IOException
		{// 读取下一个int型数值
			return Integer.parseInt(next());
		}

		static long nextLong() throws IOException
		{// 读取下一个int型数值
			return Long.parseLong(next());
		}

		static double nextDouble() throws IOException
		{// 读取下一个double型数值
			return Double.parseDouble(next());
		}
	}
}



Measured memory_bytes: 68912
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}



int main() {
	vector<string> num;
	string a, b; cin >> a >> b;
	num.push_back(a);
	num.push_back(b);
	sort(num.begin(), num.end());

	if (a.length() < b.length()) cout << "LESS";
	else if (a.length() > b.length()) cout << "GREATER";
	else {
		if (a == b) cout << "EQUAL";
		else if (num[0] == a) cout << "LESS"; 
		else cout <<"GREATER";
	}
	
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
//abc112_a.cpp
//Sat Oct 20 22:11:02 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n,a,b;
	cin >> n;

	if (n==1){
		cout << "Hello World" << endl;
	}else{
		cin >> a >> b;
		cout << a+b << endl;
	}

}

Measured memory_bytes: 256
def main():
    class unionfind():
        # size:要素数,tree：unionfind木
        def __init__(self, size):  # self,要素数
            self.size = size
            self.tree_root = list(range(self.size))
            self.tree_depth = [1]*self.size
            self.tree_size = [1]*self.size

        # rootを探す
        def root(self, index):
            temp_list = []
            temp = self.tree_root[index]
            while index != temp:
                temp_list.append(index)
                index = temp
                temp = self.tree_root[index]
            for i in temp_list:
                self.tree_root[i] = index
            return index

        # 結合
        def unite(self, index1, index2):
            r1 = self.root(index1)
            r2 = self.root(index2)
            if r1 != r2:
                d1, d2 = self.tree_depth[r1], self.tree_depth[r2]
                if d1 <= d2:
                    self.tree_root[r1] = r2
                    self.tree_depth[r2] = max(d1+1, d2)
                    self.tree_size[r2] += self.tree_size[r1]
                else:
                    self.tree_root[r2] = r1
                    self.tree_depth[r1] = max(d2+1, d1)
                    self.tree_size[r1] += self.tree_size[r2]

        # 同じか判定
        def same(self, index1, index2):
            r1 = self.root(index1)
            r2 = self.root(index2)
            return r1 == r2

    n, m, k = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in [0]*m]
    cd = [list(map(int, input().split())) for _ in [0]*k]
    u = unionfind(n)

    for a, b in ab:
        u.unite(a-1, b-1)

    friend = [u.tree_size[u.root(i)]-1 for i in range(n)]

    for a, b in ab:
        friend[a-1] -= 1
        friend[b-1] -= 1
    for c, d in cd:
        if u.same(c-1, d-1):
            friend[c-1] -= 1
            friend[d-1] -= 1
    print(*friend)


main()

Measured memory_bytes: 109272
while 1:
	H, W = map(int, raw_input().split())
	if H == W == 0:
		break
	for i in range(H):
		if i % 2 == 0:
			if W % 2 == 0:
				print "#." * (W/2)
			else:
				print "#." * (W/2) + "#"
		else:
			if W % 2 == 0:
				print ".#" * (W/2)
			else:
				print ".#" * (W/2) + "."
		
	print ""

Measured memory_bytes: 4212
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

void yes(int n){
    cout << "Yes" << endl;
}

void no (int n){
    cout << "No" << endl;
}

int main() {
    int n; cin >> n;
    vector<int> ar;
    vector<int> al;
    rep(i,n){
        int a; cin >> a;
        if (n % 2 == 1){
            if (i % 2 == 0) al.emplace_back(a);
            else ar.emplace_back(a);
        }
        else {
            if (i % 2 == 0) ar.emplace_back(a);
            else al.emplace_back(a);
        }
    }
    reverse(al.begin(),al.end());
    rep(i,ar.size()) al.emplace_back(ar[i]);
    printvec(al);
}

Measured memory_bytes: 4748
import java.util.Scanner;

class Main {
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        int c = stdIn.nextInt();
        int x = stdIn.nextInt();
        int y = stdIn.nextInt();
        int price = 0;
        
        if((a + b + 1) / 2 > c){
            if(x > y){
                price = c * y * 2;
                if(a > c * 2)
                    price += c * (x - y) * 2;
                else
                    for(int i = 0; i < x - y; i++)
                        price += a;
            }
            else{
                price = c * x * 2;
                if(b > c * 2)
                    price += c * (y - x) * 2;
                else
                    for(int i = 0; i < y - x; i++)
                        price += b;
            }
        }
        else{
            for(int i = 0; i < x; i++)
                price += a;
         
            for(int i = 0; i < y; i++)
                price += b;
        }
            
        System.out.println(price);
    }
}

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

using namespace std;

int main()
{
    int A, B;
    cin >> A>>B;
if((A+(A-1))>=(A+B)&&(A+(A-1))>=(B+(B-1)))
   cout << A+(A-1);
   else
    if((A+(A-1))<=(B+(B-1))&&B+(B-1)>=(A+B))
    cout << B+(B-1);
else
    if((A+(A-1))<=A+B&&B+(B-1)<=(A+B))

    cout << A+B;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

int main(){

  int a, b, c, d;

  cin >> a >> b >> c >> d;

    if(abs(a-b) <= d && abs(b-c)<= d) cout << "Yes" << endl;

    else if(abs(a-c)<=d) cout << "Yes" << endl;

    else cout << "No" << endl;


  return 0;
}


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


int main() {

    int n, a, b;
    cin >> n >> a >> b;
    cout << min(a * n, b) << endl;
    return 0;
}

Measured memory_bytes: 256
L, R = map(int,input().split())
l = L % 2019
r = R % 2019
A = []
if R//2019 - L//2019 >= 1:
    print(0)
else:
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            a = i * j
            A.append(a%2019)
    print(min(A))


Measured memory_bytes: 75416
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,i,k,j;
    cin>>n>>k;
    ll x[n],y[n];
    for(i=0;i<n;i++)
    {
        cin>>x[i];
    }
    for(i=0;i<n;i++)
    {
            if(i==0)
            {
                y[i]=0;
            }
            else if(i==1)
            {
                y[i]=(abs(x[i]-x[i-1]));
            }
            else
            {
               y[i]=y[i-1]+abs(x[i]-x[i-1]);
                for(j=2;j<=k && i-j>=0;j++)
                {
                    y[i]=min(y[i],y[i-j]+abs(x[i]-x[i-j]));
                } 
            }
            
    }
    for(i=0;i<n;i++)
    {
       // cout<<y[i]<<" ";
    }
    cout<<y[n-1]<<"\n";
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>

using namespace std;
typedef long long ll;

int main()
{
	const int NMax = 40;
	const int SumMax = NMax * 10;
	
	int N, Ma, Mb;
	int a[NMax+1];
	int b[NMax+1];
	int c[NMax+1];
	cin >> N >> Ma >> Mb;
	for(int i = 1; i < N+1; i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	
	static int DP[NMax+1][SumMax+1][SumMax+1];
	for(int i = 0; i < N+1; i++){
		for(int j = 0; j < SumMax+1; j++){
			for(int k = 0; k < SumMax+1; k++){
				DP[i][j][k] =  j == 0 && k == 0 ? 0 : INT_MAX / 2;
			}
		}
	}
	
	for(int i = 1; i < N+1; i++){
		for(int j = 0; j < SumMax+1; j++){
			for(int k = 0; k < SumMax+1; k++){
				if(j-a[i] >= 0 && k-b[i] >= 0){
					DP[i][j][k] = DP[i-1][j-a[i]][k-b[i]] + c[i];
				}
				DP[i][j][k] = min(DP[i][j][k], DP[i-1][j][k]);
			}
		}
	}
	
	int ans = INT_MAX;
	for(int i = 1; Ma * i <= SumMax && Mb * i <= SumMax; i++){
		for(int j = 1; j < N+1; j++){
			ans = min(ans, DP[j][Ma*i][Mb*i]);
		}
	}
	
	if(ans >= INT_MAX / 2){
		cout << "-1" << endl;
	}else{
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 25984
s = input()

maxV = 0
length = 0
isChecking = False

for i in range(len(s)):
    if isChecking:
        if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
            length += 1
            if length > maxV:
                maxV = length
        else:
            isChecking = False
    else:
        if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
            isChecking = True
            length = 1
            if length > maxV:
                maxV = length

print(maxV)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define ll long long int

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> a(n);
    for(auto &x:a)cin>>x;
    vector<int> dp(n+1,1e9+10);
    dp[0]=0;
    for(int i=1;i<n;i++){
        for(int j=1;j<=k;j++){
            if(i-j<0)continue;
            dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
        }
    }
    cout<<dp[n-1]<<"\n";
    return 0;
}


Measured memory_bytes: 4012
// clang-format off
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using G = vector<vector<ll>>;
#define G(i, j) i, vector<ll>(j)
#define Gv(i, j, k) i, vector<ll>(j, k)
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i,n) for(ll i=n-1; i>=0; --i)
#define rrep1(i,n) for(ll i=n; i>0; --i)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define SORT_DESC(x) sort((x).rbegin(),(x).rend())
#define pb push_back
#define mp make_pair
#define coutl cout<<fixed<<setprecision(10)
#define ANS(ans) cout<<ans<<endl
#define END(ans) ANS(ans); return
const ll LINF = (1LL << 62) - 1;
const int INF = (1 << 30) - 1;
template<class T>inline bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if (b<a){a=b;return 1;}return 0;}
const long long MOD = 1000000007;
// clang-format on

void add(ll &a, const ll &b) {
  a += b;
  if (a >= MOD)
    a -= MOD;
}

void solve(long long H, long long W, std::vector<std::string> a) {
  G dp(G(H + 1, W + 1));
  dp[0][0] = 1;
  rep(i, H) rep(j, W) {
    if (i + 1 < H && a[i + 1][j] == '.')
      add(dp[i + 1][j], dp[i][j]);
    if (j + 1 < W && a[i][j + 1] == '.')
      add(dp[i][j + 1], dp[i][j]);
  }
  ANS(dp[H - 1][W - 1]);
}

// clang-format off
int main() {
  long long H;
  scanf("%lld",&H);
  long long W;
  scanf("%lld",&W);
  vector<string> a(H);
  for(int i = 0 ; i < H ; i++){
    std::cin >> a[i];
  }
  solve(H, W, std::move(a));
  return 0;
}


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

#define vi vector<int>
#define vii vector<int, int>
#define ll long long
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...) 42
#endif
const int MOD=1e9+7;

//////////////////////// code starts ///////////////////////

int main(){
    IOS;
    #ifdef LOCAL
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    #endif
    int k;
    cin >> k;
    ll ans = 0;

    for (int i =1; i <= k; i++){
        for (int j = 1; j <= k; j++){
            for (int kk = 1; kk <= k ; kk++){
                ans += __gcd(i, __gcd(j, kk));
            }
        }
    }

    cout << ans << endl;

    #ifdef LOCAL
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
}




Measured memory_bytes: 3652
N = int(input())
S = input()

if N >= 3:
    e = 0
    for i in range(N-2):
        for j in range(1, N//2+1):
            if i+2*j <= N-1:
                if S[i] != S[i+j] and S[i+j] != S[i+2*j] and S[i] != S[i+2*j]:
                    e += 1
            else:
                break
else:
    e = 0

R = S.count("R")
G = S.count("G")
B = S.count("B")

print(R*G*B-e)

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

#define true 1
#define false 0


int isPoor(int num[]){
	int sameCounter=0;
	for(int i = 0; i< 2; i++){
		for(int j = i+1; j < 3; j++){
			if(num[i] == num[j]){
				sameCounter++;
			}
		}
	}
	if(sameCounter == 1){
		return true;
	}
	else{
		return false;
	}
}
int main(){
	int isCorrect = true;
	int a[3];
	int ans;
	fscanf(stdin,"%d%d%d",&a[0],&a[1],&a[2]);
	ans = isPoor(a);
	if(ans){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
inf = float('inf')

n, k = map(int, input().split())
h = list(map(int, input().split())) + [inf] * k

dp = [inf] * (n + k)
dp[0] = 0

# 配る
for i in range(n - 1):
    for j in range(1, k + 1):
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]))
print(dp[n - 1])


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


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

    int L, R, d;
    cin >> L >> R >> d;

    int result = 0;
    result = (R/d) - ((L-1)/d);
    // for(int i = L; i <= R; i++)
    // {
    //     if(i % d == 0) result++;
    // }
    std::cout << result << "\n";
    return 0;
}


Measured memory_bytes: 3644
from collections import Counter

N = int(input())
S = []
for i in range(N):
    S.append(input())

count = Counter(S).most_common()
mode = count[0][1]
count.sort()
##print("--")
for i in range(len(count)):
    if count[i][1] == mode:
        print(count[i][0])


Measured memory_bytes: 45036
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		int j=0;
		for(int i=0;i<5;i++)
		{
			string s;
			cin>>s;
			if(s=="0")
			{
				j=i+1;
			}
		}	
		cout<<j<<endl;
	}
	return 0;
}

Measured memory_bytes: 3624
from math import factorial

h, w, a, b = map(int, input().split())
MOD = 10**9+7

fact = [1]

# 累積乗を作る
for i in range(1, h+w-1):
    fact.append(fact[-1] * i % MOD)

# 累積乗の逆元
inv_fact = [pow(fact[-1], MOD-2, MOD)] # x^(-1) = x^(10^9+5) % (10^9+7), フェルマーの小定理
for i in range(h+w-2, 0, -1): # xが最大の場合を求め、後ろ向きに計算していく
    inv_fact.append(inv_fact[-1] * i % MOD)
inv = list(reversed(inv_fact)) # 逆順に取得

#print(fact, inv_fact, inv)
def comb(x, y):
    return (fact[x] * inv[y] * inv[x-y])

ans = 0
for x in range(b, w):
    ans += ((comb((h-a-1 + x), x)) * (comb((a-1 + w-x-1), a-1)) % MOD)
    ans %= MOD

print(ans)


Measured memory_bytes: 20524
#include <iostream>
#include <algorithm>
#include <math.h>
using namespace std;

int main(){
    int h, m, s;
    cin >> s;
    h = s / 3600;
    s = s % 3600;
    m = s / 60;
    s = s % 60;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}


Measured memory_bytes: 3120
# D - Preparing Boxes

N = int(input())
A = [int(a) for a in input().split()]

ans = [0] * N
for i in reversed(range(1, N + 1)):
    x = 0
    for j in range(i, N + 1, i):
        x += ans[j - 1]
    if x % 2 != A[i - 1]:
        ans[i - 1] = 1

print(ans.count(1))
print(*[i for i in range(1, N + 1) if ans[i - 1] == 1])


Measured memory_bytes: 13044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)
#define bg begin()
#define ed end()
#define all(x) x.bg, x.ed
#define vi vector<int>
template <class t, class u>
bool chmax(t &a, u b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class t, class u>
bool chmin(t &a, u b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}

ll mod = 1000000007;

int calcCost(int b, vi &a)
{
    int ans = 0;
    rep(i, a.size())
    {
        ans += (a[i] - b) * (a[i] - b);
    }
    return ans;
}

signed main()
{
    int n;
    cin >> n;
    vi a(n);
    rep(i, n)
    {
        cin >> a[i];
    }
    ll ans = INT_MAX;
    for (int i = -100; i <= 100; i++)
    {
        chmin(ans, calcCost(i, a));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let n = i.read::<usize>();
    let mut abc = Vec::new();
    for _ in 0..n {
        abc.push(i.read3::<usize, usize, usize>());
    }
    writeln!(o, "{}", solve(&abc)).unwrap();
}
fn solve(abc: &[(usize, usize, usize)]) -> usize {
    let mut h = abc[0];
    for abc in abc.iter().skip(1) {
        h = (
            max(h.1, h.2) + abc.0,
            max(h.0, h.2) + abc.1,
            max(h.0, h.1) + abc.2,
        );
    }
    max(h.0, max(h.1, h.2))
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_line().parse().ok().unwrap()
        }
        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()      //昇順
#define RALL(obj) (obj).rbegin(), (obj).rend()   //降順
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    ll n, m, mod = 1000000007;
    cin >> n >> m;
    vector<ll> dp(max(2, (int)n));
    bool a[n] = {};
    rep(i, m){
        ll temp;
        cin >> temp;
        a[temp - 1] = true;
    }
    dp[0] = 1; dp[1] = 2;
    if(a[0]){
        dp[0] = 0;
        dp[1] = 1;
    }
    if(a[1]) dp[1] = 0;
    for(ll i = 2; i < n; i++){
        dp[i] = (dp[i - 1] + dp[i - 2]) % mod;
        if(a[i]) dp[i] = 0;
    }
    print(dp[n - 1]);
}


Measured memory_bytes: 1152
#include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, id, lc[100009], rc[100009], deg[100009], p[100009], d[100009], s[100009], dp[100009]; bool vis[100009];
void rec(int pos) {
	vis[pos] = true;
	if (lc[pos] != -1) rec(lc[pos]);
	if (rc[pos] != -1) rec(rc[pos]);
}
void solve(int pos) {
	if (lc[pos] != -1) {
		d[lc[pos]] = d[pos] + 1;
		solve(lc[pos]);
		p[lc[pos]] = pos;
		s[lc[pos]] = rc[pos];
		dp[pos] = dp[lc[pos]] + 1;
	}
	if (rc[pos] != -1) {
		d[rc[pos]] = d[pos] + 1;
		solve(rc[pos]);
		p[rc[pos]] = pos;
		s[rc[pos]] = lc[pos];
		dp[pos] = max(dp[pos], dp[rc[pos]] + 1);
	}
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &id);
		scanf("%d%d", &lc[id], &rc[id]);
	}
	int root = -1;
	for (int i = 0; i < n; i++) {
		if (!vis[i]) {
			rec(i);
			root = i;
		}
		if (lc[i] != -1) deg[i]++;
		if (rc[i] != -1) deg[i]++;
	}
	solve(root); p[root] = s[root] = -1;
	for (int i = 0; i < n; i++) {
		printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n", i, p[i], s[i], deg[i], d[i], dp[i], (i == root ? "root" : (deg[i] ? "internal node" : "leaf")));
	}
	return 0;
}

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

int main()
{
	string sentence;
	string::size_type a, b, i;
	int c, d;

	getline(cin, sentence);
	i = 0;
	while (1) {
		a = sentence.find("apple", i);
		b = sentence.find("peach", i);
		if( a==string::npos && b==string::npos ) break;
		if (a<b) {
			sentence.replace(a, 5, "peach");
			i = a+5;
		} else {
			sentence.replace(b, 5, "apple");
			i = b+5;
		}
	}
	cout<<sentence<<endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <math.h>

using namespace std;

typedef long long int ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
const int MOD = 1000000007;
const int INF = INT_MAX;



int main(int argc, char const *argv[])
{
    int a, b, c;
    cin >> a >> b >> c;

    if (a+b < c){
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
    }



    return 0;
}




//              g++ -std=c++1z  ]

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const ll mod=1000000007,MAX=100003,INF=1<<30;

int main(){
    
    int N;cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    A.push_back(INF);
    int ans=0,now=0,i=0;
    while(now<N){
        while(A[i]>=A[i+1]) i++;
        ans=max(ans,i-now);
        i++;
        now=i;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
var
    a:array['A'..'F']of integer=(10,11,12,13,14,15);
    x,y,z:char;
begin
    read(x,z,y);
    if a[x]>a[y] then writeln('>')
    else if a[x]=a[y] then writeln('=')
         else writeln('<');
end.

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int a[100];
    int c[100] = {0};
    int cnt = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        if (a[i] == 1) {
            c[cnt]++;
        } else {
            cnt++;
        }
    }
    int Max = 0;
    for (int i = 0; i < n; i++) {
        Max = (c[i] > Max) ? c[i] : Max;
    }
    cout << Max+1 << endl;
    return 0;
}



Measured memory_bytes: 3092
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
using namespace std;

typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(a) a.begin(),a.end()

int main() {
	int n, a;
	cin >> n >> a;
	cout << n * n - a << endl;
	return 0;
}

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

A=[(1+p[i])*p[i]/(2*p[i]) for i in range(N)]

edge=A[0]
s=sum(A[:K])
max_s=s
for i in range(1,N-K+1):
  s=s-edge+A[i+K-1]
  max_s=max(max_s,s)
  edge=A[i]
print(max_s)

Measured memory_bytes: 77448
def calc_max_profit(data):
    """
    http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_1_D
    :param data: ??????????????????
    :return:
    """
    maxv = data[1] - data[0]
    minv = data[0]
    for j in range(1, len(data)):
        maxv = max(maxv, data[j] - minv)
        minv = min(minv, data[j])
    return maxv


if __name__ == '__main__':
    # ???????????\???
    num = int(input())
    data = []
    for i in range(num):
        data.append(int(input()))
    # data = [5, 3, 1, 3, 4, 3]
    # data = [4, 3, 2]

    # ??????
    result = calc_max_profit(data)

    # ???????????????
    print('{0}'.format(result))

Measured memory_bytes: 15596
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <ctime>
#include <map>
#include <stack>
#include <sstream>
#include <set>
#include <cmath>
#include <functional>
#include <memory.h>

// pi = atan(1)*4;

#define INTMAX 2100000000

using namespace std;

int main(void)
{
	string o, e;
	string res = "";

	cin >> o >> e;

	while (1)
	{
		if (o.length() != 0)
		{
			res += o[0];
			o.erase(o.begin());
		}
		
		if (e.length() != 0)
		{
			res += e[0];
			e.erase(e.begin());
		}

		if (o.length() == 0 && e.length() == 0)
		{
			break;
		}
	}

	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 256
// --------------------------------------------
// ****************  gzhffIThh  ***************
// --------------------------------------------
// #pragma GCC optimize(2)
// #pragma GCC optimize(3)

#include <iostream>
#include <cstdio>
#include <queue>
#include <vector>
#include <cstring>
#include <algorithm>

using namespace std;

int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);  
         
        string s, t;
        cin >> s >> t;

        int ans = 2001;
        for (int i = 0; i < s.size() - t.size() + 1; i++) {
                int tmp = 0;
                for (int st = i; st < i + t.size(); st++) {
                        if (s[st] != t[st - i]) ++tmp;
                }
                ans = min(ans, tmp);
        }
        cout << ans;
          
        return 0; 
}

Measured memory_bytes: 3644
N=int(input())
l=[[] for i in range(N)]
color=[0]*N
mem=[]
for i in range(N-1):
   a,b=list(map(int,input().split()))
   a-=1;b-=1
   l[a].append(b)
   mem.append(b)
from collections import deque
que=deque([0])
while que:
   node=que.popleft()
   c=1
   for i in l[node]:
      if color[node]==c:
         c+=1
      color[i]=c
      c+=1
      que.append(i)
print(max(color))
for i in mem:
   print(color[i])

Measured memory_bytes: 22920
a,b,k = map(int,input().split())
if 2*k >= (b-a)+1:
  for i in range(a,b+1):
    print(i)
else:
  for i in range(a,a+k):
    print(i)
  for i in range(b-k+1,b+1):
    print(i)

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

int main(){
  int n,c,k;
  int ans=0,start;

  cin>>n>>c>>k;
  vector<int> t(n);
  for(int i=0;i<n;i++) cin>>t[i];
  sort(t.begin(),t.end());
  for(int i=0;i<n;){
    start=i;
    ans++;
    while(i<n && t[i]-t[start]<=k && i-start<c) i++;
  }
  cout<<ans;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define len(x) (int) (x.size())
using namespace std;
typedef long long ll;

int main(){
    map<int, int> inArray;
    int x, n, val;

    cin >> x >> n;
    for(int i = 0; i < n; i++) {
        cin >> val;
        inArray[val] = 1;
    }

    int fans = 102, ans = 102;
    for(int i = 0; i <= 101; i++) {
        if(inArray[i] == 0 && abs(x-i) < ans) {
            ans = abs(x-i);
            fans = i;
        }
    }
    cout << fans << '\n';

    return 0;
}

Measured memory_bytes: 3636