akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define MAXN 1000

bool visiting[MAXN-1][MAXN];
bool visited[MAXN-1][MAXN];

void resetBool() {
  for (int i=0; i<MAXN; i++) {
    for (int j=0; j<MAXN; j++) {
      visiting[i][j] = false;
    }
  }
}

int d[MAXN-1][MAXN];

typedef struct match{
  int a;
  int b;
  struct match *ta;
  struct match *tb;
} match;

match *createMatch(int a, int b, match *ta, match *tb) {
  match *m = malloc(sizeof(match));
  m->a = a;
  m->b = b;
  m->ta = ta;
  m->tb = tb;
  return m;
}

void freeMatch(match *m) {
  if(m!=NULL) free(m);
}

void addTA(match *m, match *ta) {
  if(m!=NULL) m->ta = ta;
}

void addTB(match *m, match *tb) {
  if(m!=NULL) m->tb = tb;
}

match *m[MAXN-1][MAXN];

int dfs(int i, int j) {
  if (visited[i][j]) return d[i][j];
  visiting[i][j] = true;
  if (m[i][j]->ta == NULL && m[i][j]->tb == NULL) {
    d[i][j] = 1;
    visited[i][j] = true;
    visiting[i][j] = false;
    return 1;
  } else if (m[i][j]->ta != NULL && m[i][j]->tb == NULL) {
    if (visiting[m[i][j]->ta->a][m[i][j]->ta->b]) return -1;
    int next = dfs(m[i][j]->ta->a, m[i][j]->ta->b);
    if (next==-1) return -1;
    d[i][j] = next+1;
    visited[i][j] = true;
    visiting[i][j] = false;
    return d[i][j];
  } else if (m[i][j]->ta == NULL && m[i][j]->tb != NULL) {
    if (visiting[m[i][j]->tb->a][m[i][j]->tb->b]) return -1;
    int next = dfs(m[i][j]->tb->a, m[i][j]->tb->b);
    if (next==-1) return -1;
    d[i][j] = next+1;
    visited[i][j] = true;
    visiting[i][j] = false;
    return d[i][j];
  }
  if (visiting[m[i][j]->ta->a][m[i][j]->ta->b] || visiting[m[i][j]->tb->a][m[i][j]->tb->b]) return -1;
  int nexta = dfs(m[i][j]->ta->a, m[i][j]->ta->b);
  int nextb = dfs(m[i][j]->tb->a, m[i][j]->tb->b);
  if (nexta==-1 || nextb==-1) return -1;
  d[i][j] = (nexta > nextb) ? nexta+1 : nextb+1;
  visited[i][j] = true;
  visiting[i][j] = false;
  return d[i][j];
}

int main() {
  int n;
  scanf("%d", &n);
  int a[n-1], ans = 0;
  for (int i=0; i<n-1; i++) {
    for (int j=i+1; j<n; j++) {
      m[i][j] = createMatch(i, j, NULL, NULL);
    }
  }
  for (int i=0; i<n; i++) {
    match *tmp = NULL;
    for (int j=0; j<n-1; j++) scanf("%d", a+j);
    for (int j=n-2; j>=0; j--) {
      if (a[j] > i+1) {
        addTA(m[i][a[j]-1], tmp);
        tmp = m[i][a[j]-1];
      } else {
        addTB(m[a[j]-1][i], tmp);
        tmp = m[a[j]-1][i];
      }
    }
  }
  for (int i=0; i<n-1; i++) {
    for (int j=i+1; j<n; j++) {
      int l = dfs(i, j);
      if (l==-1) {
        printf("-1\n");
        return 0;
      }
      ans = (l > ans) ? l : ans;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 28928
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::cmp::Ordering;

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn main() {
    input! {
        n: u32
    }
    let mut base = 0;
    let mut ans = 0;
    loop {
        let val = base * base;
        if val > n {
            break;
        }
        ans = val;
        base += 1;
    }
    println!("{}", ans);
} 


Measured memory_bytes: 4352
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N, M;
    cin >> N >> M;
    
    vvi to(N, vi());
    REP(i, M) {
        int a, b;
        cin >> a >> b;

        a--; b--;

        to[a].emplace_back(b);
        to[b].emplace_back(a);
    }

    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    vector<int> dist(N, -1);
    dist[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    vi ans(N, -1);
    ans[0] = 0;
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int nv : to[v]) {
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
            ans[nv] = v;
        }
    }

    for (int d : ans) {
        if (d == -1) {
            cout << "No" << endl;
            return 0;
        }
    }

    
    cout << "Yes" << endl;
    FOR(i, 1, N) cout << ans[i]+1 << endl;

    return 0;
}


Measured memory_bytes: 10720
#include <iostream>
#include <stdlib.h>
using namespace std;

main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if ((abs (a-b) <= d && abs (b-c) <= d) || abs (a-c) <= d) cout << "Yes";
	else cout << "No";
}


Measured memory_bytes: 256
a,b,c = map(int,input().split())
if a == b and b == c:
    if a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
        print(-1)
    else:
        print(0)
else:
    ans = 0
    while True:
        if a % 2 == 0 and b % 2 == 0 and c % 2 == 0:
            ans += 1
            A = b / 2 + c / 2
            B = c / 2 + a / 2
            C = a / 2 + b / 2
            a = A
            b = B
            c = C
        else:
            break
    print(ans)

Measured memory_bytes: 3064
ONE = '1'.freeze
MOD = (10**9) + 7
def inv(x)
  res = 1 # 最終的に x^(MOD-2) になる変数です
  beki = x # x^2^n を格納する変数です
  # MOD-2の２進数展開を下位のbitから見ていきます。
  (MOD - 2).to_s(2).reverse.chars do |digest|
    # bitが立っている <=> digest == ONE
    # なら resにbekiを掛けます。
    # ここで、掛け算は計算の都度MODを取れます
    res = (beki * res) % MOD if digest == ONE
    # 次のループに備えて、自乗を計算します。
    # 計算の都度MODを取れます(とても大事なので二回言います)
    beki = (beki * beki) % MOD
  end
  res
end

def fact(s, e)
  (s..e).reduce(1) { |r, i| (r * i) % MOD }
end

def nCk(n, k)
  (fact(k + 1, n) * inv(fact(1, n - k) % MOD)) % MOD
end


## C(n,k) mod p (n>>>k version) ##
def frac(n,k)
  a=1
  b=1
  k.times do |i|
    b*=i+1
    b%=MOD
  end
  k.times do |i|
    j=i+1
    a*=n-i
    a%=MOD
  end
  a*inv(b)%MOD
end

n, a, b = gets.chomp.split(" ").map(&:to_i)

## a**b mod p by 繰り返し二乗法 ##
def pow(a,b)
  return 1 if b==0
  return a*pow(a,b-1)%MOD if b%2==1
  return pow(a**2%MOD,b/2)
end


ans=pow(2,n)-1
ans+=MOD-frac(n,a)
ans+=MOD-frac(n,b)
puts ans%MOD

Measured memory_bytes: 3836
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    x = kwargs["x"]
    n = kwargs["n"]
    P = kwargs["P"]

    for i in range(len(P)):
        P[i] -= x

    res = 0

    while True:
        if not res in P:
            break

        res *= -1

        if not res in P:
            break

        res *= -1

        res -= 1

    res += x
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["x"], kwargs["n"] = [int(i) for i in cin]
    cin = input().split()
    kwargs["P"] = [int(i) for i in cin]

    cout = main(kwargs)
    print(cout)

Measured memory_bytes: 31184
//for(int i=0;i<n;i++)cin>>arr[i];
//for(int i=0;i<n;i++)cout<<arr[i]<<" ";

#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main()
{
  int n;
  cin>>n;
  long long int sum=0;
  for(int i=1;i<n+1;i++)
  {
      if(i%5==0&&i%3==0)continue;
      else if(i%5==0)continue;
      else if(i%3==0)continue;
      else sum+=i;
      
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#define  PI  3.141592653589793
int main(void){
    double r, s, l;
    scanf("%lf", &r);
    s=r*r*PI;
    l=2*r*PI;
    
    printf("%lf %lf", s, l);
    
    return 0;
}



Measured memory_bytes: 2100
import itertools


def dijkstra(v, G):
    import heapq

    ret = [10 ** 10] * len(G)
    ret[v] = 0
    q = [(ret[i], i) for i in range(len(G))]
    heapq.heapify(q)

    while len(q):
        tmpr, u = heapq.heappop(q)
        if tmpr == ret[u]:
            for w, l in G[u]:
                if ret[w] > ret[u] + l:
                    ret[w] = ret[u] + l
                    heapq.heappush(q, (ret[w], w))
    return ret


N, M, R = map(int, input().split())
r = list(map(int, input().split()))
NE = [[] for _ in range(N)]
for _ in range(M):
    A, B, C = map(int, input().split())
    NE[A - 1].append((B - 1, C))
    NE[B - 1].append((A - 1, C))

RE = [[0] * R for _ in range(R)]
for iR in range(R):
    for jR in range(iR + 1, R):
        lR = dijkstra(r[iR] - 1, NE)[r[jR] - 1]
        RE[iR][jR] = lR
        RE[jR][iR] = lR

ans = 10 ** 10
for p in itertools.permutations(range(R)):
    ans = min(ans, sum([RE[p[i]][p[i + 1]] for i in range(R - 1)]))

print(ans)


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

int main()
{
    string s;
    cin >> s;

    int ans = 0;
    if (s[0] == 'R')
        ans++;

    if (s[0] == 'R' && s[1] == 'R')
        ans++;

    if (s[1] == 'R' && s[2] == 'R')
        ans++;

    if (s[0] == 'S' && s[2] == 'R')
        ans++;

    if (s[0] == s[2] && s[0] == 'S' && s[1] == 'R')
        ans++;

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


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

#define loop(x) for(int i = 0; i < x; i++)
#define deb(x) cout<< #x << x << endl;
#define ll long long
using namespace std;

ll f(int W, vector<ll> wt, vector<ll> vls) {
    vector<ll> dp(W + 1);
    
    for(int i = 0; i < vls.size(); i++) {
        for(ll j = W - wt[i]; j >= 0; j--) {
            dp[j + wt[i]] = max(dp[j + wt[i]], dp[j] + vls[i]);
        }
    }
    ll r = dp[0];
    for(auto x : dp) {
        r = max(r, x);
    }
    return r;
}

int main() {


    int t = 1;
    //cin>>t;
    while(t--) {
        // FOR ARRAY
        // int n;
        // cin>>n;
        // string arr;
        // for(int i = 0; i < n; i++) {
        //     char x;
        //     cin>>x;
        //     arr.push_back(x);
        // }
        // f(arr);

        // FOR MATRIX
        // int row, col;
        // cin>>row;
        // cin>>col;
        // vector<vector<int>> arr(row, vector<int>(col, 0));
        // for(int i = 0; i < row; i++) {
        //     for(int j = 0; j < col; j++) {
        //         cin>>arr[i][j];
        //     }
        // }
        // f(arr);
        
        //FOR MATRIX
        int W, n;
        cin>>n;
        cin>>W;
        vector<ll> vls(n, 0), wts(n, 0);
        for(int j = 0; j < n; j++) {
            cin>>wts[j];
            cin>>vls[j];
        }
    
        cout<<f(W, wts, vls)<<endl;

    }
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int mod = 1e9+7;
int main()
{
    int h,w;
    cin>>h>>w;
    vector <string > input(h);
    for(int i=0;i<h;i++)
    {
        cin>>input[i];
    }
    int flag = 0;
    vector <vector <int> > dp(h,vector <int> (w,0));
    for(int i=0;i<h;i++)
    {
        if(input[i][0] == '.' && flag == 0)
            dp[i][0] = 1;
        if(input[i][0] == '#')
        {
            dp[i][0] = 0;
            flag = 1;
        }
    }
    flag = 0;
    for(int i=0;i<w;i++)
    {
        if(input[0][i] == '.' && flag == 0)
            dp[0][i] = 1;
        if(input[0][i] == '#')
        {
            dp[0][i] = 0;
            flag = 1;
        }
    }
    for(int i=1;i<h;i++)
    {
        for(int j=1;j<w;j++)
        {
            if(input[i][j] == '.')
            {
                dp[i][j] = (dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
            }
        }
    }
    cout<<dp[h-1][w-1]<<endl;
    return 0;
}

Measured memory_bytes: 5248
def solve(a, b, angle)
  ang = 1.0 * angle / 180 * Math::PI
  c = Math.sqrt(a ** 2 + b ** 2 - 2 * a * b * Math.cos(ang))
  area = 0.5 * a * b * Math.sin(ang)
  h = b * Math.sin(ang)
  [area, a + b + c, h]
end

def main
  a, b, ang = gets.split(/\s/).map(&:to_i)
  puts solve(a, b, ang)
end

main

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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;
typedef pair<int, int> i_i;

ll f(int N, vector<int> a, vector<int> b, int x) {
	ll sum = 0;
	rep(i, N) if ((x & a[i]) == a[i]) sum += b[i];
	return sum;
}

int main() {
	int N; ll x; cin >> N >> x;
	vector<int> a(N), b(N);
	rep(i, N) scanf("%d%d", &a[i], &b[i]);
	ll ans = f(N, a, b, x);
	rep(k, 30) if (x>>k & 1) {
		ll y = x;
		y >>= k + 1;
		y <<= k + 1;
		y |= (1<<k) - 1;
		ans = max(ans, f(N, a, b, y));
	}
	cout << ans << endl;
}


Measured memory_bytes: 1920
package main

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

func main() {
	var answer int
	line := nextLine();
	number, _ := strconv.Atoi(line)
	if number%2 == 0{
		seed := number/2
		answer = seed*seed
	}else if number%2 == 1{
		seed := (number -1)/2
		answer = seed*seed + seed
	}
	fmt.Println(answer)
}

func nextLine() string {

	var sc = bufio.NewScanner(os.Stdin);
	sc.Scan()
	return sc.Text()
}


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

int main(){
	int n;
	while(cin>>n,n){
		int ans=0;
		FOR(i,1,n){
			int total=0;
			FOR(j,i,n){
				total+=j;
				if(total>n){
					break;
				}else if(total==n){
					ans++;
					break;
				}
			}
		}
		cout<<ans<<endl;
	}
}

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

int main() {
    int n, x, i, j, k;
    
    while(true) {
        cin >> n >> x;
        if (n == 0 && x == 0) break;
        int count = 0;
        
        for (i = 1; i <= n; i++) {
            for (j = i + 1; j <= n; j++) {
                for (k = j + 1; k <= n; k++) {
                    if (i + j + k == x) {
                        count++;
                    }
                }
            }
        }
        cout << count << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
void solve(long long N, long long K, std::vector<long long> a, std::vector<long long> b){
  vector<pair<ll,ll>>x(N);
  for (int i = 0; i < N; i++) {
    x[i] = make_pair(a[i],b[i]);
  }
  sort(all(x));
  ll ans=0;
  for (int i = 0; i < N; i++) {
    ans += x[i].second;
    if(ans >= K){
      cout << x[i].first << endl;
      return;
    }
  }
}

int main(){
    long long N;
	scanf("%lld",&N);
	long long K;
	scanf("%lld",&K);
	std::vector<long long> a(N);
	std::vector<long long> b(N);
	for(int i = 0 ; i < N ; i++){
		scanf("%lld",&a[i]);
		scanf("%lld",&b[i]);
	}
    solve(N, K, std::move(a), std::move(b));
}


Measured memory_bytes: 3328
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

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

int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int a[100000], b[100000];
	vector<P> v;
	for(int i=0; i<m; i++){
		scanf("%d %d", &a[i], &b[i]);
		v.push_back(P(a[i], b[i]));
	}
	sort(v.begin(), v.end());
	int ans=1;
	int b0=v[0].second;
	for(int i=0; i<m; i++){
		if(v[i].first>=b0){
			ans++;
			b0=v[i].second;
		}else{
			b0=min(b0, v[i].second);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1912
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

N = int(input())
slowest = float('inf')
for i in range(5):
    a = int(input())
    slowest = min(slowest, a)

remain = N-slowest
diff = -(-remain // slowest)
print(5 + diff)

Measured memory_bytes: 3060
from collections import deque
 
def bfs(h, w, s, sx, sy):
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    d = [[-1] * w for _ in range(h)]
    d[sx][sy] = 0
    que = deque()
    que.append((sx, sy))
 
    while que:
        x, y = que.popleft()
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if 0 <= nx < h and 0 <= ny < w and s[nx][ny] != '#' and d[nx][ny] == -1:
                que.append((nx, ny))
                d[nx][ny] = d[x][y] + 1
 
    md = 0
    for i in range(h):
        for j in range(w):
          md = max(md, d[i][j])
 
    return md
 
h, w = [int(_) for _ in input().split()]
s = [0] * h
for i in range(h):
    s[i] = list(input())
 
ans = 0
 
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            ans = max(ans, bfs(h, w, s, i, j))
 
print(ans)

Measured memory_bytes: 3316
function Main(input){
	function compareFunc(a, b) {
	  return a - b;
	}
    //console.log(input);
	input = input.trim().split(' ').sort();
	input.sort(compareFunc);
    var bc =parseInt(input[2]+input[1],10);
    var a = parseInt(input[0],10)
    console.log(bc+a);
}

Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
int main(){
    map<int,int> mp;
    int n,a;
    while(cin>>n){
        mp.clear();
        int ans=0;
        while(n--){
            cin>>a;
            ++mp[a];
        }
        for(auto i=mp.begin();i!=mp.end();++i){
            int t=i->second;
            if(t&1) ++ans;
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  ll a,b;
  cin>>a>>b;
  vector<string> v(a);
  string in;
  FOR(i,0,a){
    cin>>in;
    v[i]=in;
  }
  int flag=0;
  char x;
  vector<int> keya(a,0);
  vector<int> keyb(b,0);


  FOR(i,0,a){
    x='.';
    flag=0;
    FOR(j,0,b){
      if(x!=v[i][j]) flag=1;
    }
    keya[i]=flag;
  }

  FOR(i,0,b){
    x='.';
    flag=0;
    FOR(j,0,a){
      if(x!=v[j][i]) flag=1;
    }
    keyb[i]=flag;
  }

  FOR(i,0,a){
    FOR(j,0,b){
      if(keya[i]==1 && keyb[j]==1){
        cout<<v[i][j];
      }
    }
    if(keya[i]==1)cout<<endl;
  }

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define clz(a) __builtin_clz(a) // count leading zeroes
#define ctz(a) __builtin_ctz(a) // count trailing zeroes
#define popc(a) __builtin_popcount(a) // count set bits (binary me 1 kitne hai) (if longlong popcount ll)
#define ln "\n"
#define dbg(x) cerr<<#x<<" = "<<x<<endl
#define dbg2(x,y) cerr<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl;
#define dbgstl32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it<<ln;} cerr<<endl
#define dbgstlp32(v) cerr<<#v<<" = \n"; { int c=0; forstl(it,v) \
cerr<<"    Term "<< ++c <<" = "<<it.fi<<" , "<<it.se<<ln;} cerr<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(n) n.begin() , n.end() 
#define tfi first.first
#define tse first.second
#define tth second
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32; 
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef map<int,int> m32;
typedef pair< pair<int,int> , int> tri;

#pragma GCC optimize ("-O2")
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); }
const int LIM = 2e5+5 ,MOD = 1e9+7;
//int n , m , t , x ,y ;
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

	ll n, wei;
	cin >> n >> wei;

	int w[n+1], v[n+1];
	forn(i,n) cin >> w[i+1] >> v[i+1];

	ll dp[n+1][wei+1];

	forn(i,n+1) dp[i][0]=0;
	forn(i,wei+1) dp[0][i]=0;

	forsn(j,1,wei+1) forsn(i,1,n+1){
		if(j >= w[i]) dp[i][j] = max( dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
		else dp[i][j] = dp[i-1][j];
	}

	cout << dp[n][wei];

}

Measured memory_bytes: 79232
#include "bits/stdc++.h"
using namespace std;
typedef long long int lli;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define ff first
#define ss second
#define pi pair<lli,lli>
#define pii pair<pi,lli>
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 1e5 + 5;

int main() {
	IOS
	int T = 1;
	// cin >> T;
	while(T--)
	{
		int n;
		cin >> n;
		lli a[n];
		for (int i = 0; i < n; i++)
			cin >> a[i];
		sort(a, a + n);
		lli ans = a[n-1];
		int j = n-2;
		for (int i = n - 3; i>=0;)
		{
			if (i >= 0)
			{
				ans = ans + a[j];
				i--;
			}
			if (i >= 0)
			{
				ans = ans + a[j];
				i--;
			}
			j--;
		}
		cout << ans << endl;
		
		
	}
	
	return 0;
}

Measured memory_bytes: 5204
#include <stdio.h>
                                                                                                
  
int main(void){
                                                                                                
   
    int n, m, i;
   
    int r[51] = {0};

    int a[51], b[51];
   
      
    scanf("%d %d", &n ,&m);
   
    
    for( i = 0 ; i < m ; i = i + 1 ){

        scanf("%d %d", &a[i], &b[i]);

        }


    for( i = 0 ; i < m ; i = i + 1 ){
   
        r[a[i] - 1] += 1;

        r[b[i] - 1] += 1;

        }
   

    for( i = 0 ; i < n ; i = i + 1 ){

        printf("%d\n", r[i] );

        }


    return 0;
                                                          
}

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

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define REP(i, n) FOR(i, 0, n)

struct Edge {
    int src, dst;
};
using Graph = vector<vector<Edge>>;

void print_float(double x, int precision=15) {
    cout.setf(ios::fixed);
    cout.precision(precision);
    cout << x << '\n';
}

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

    int N, M, P;
    while (cin >> N >> M >> P) {
        double p = P/100.0;
        Graph graph(N);
        vector<Edge> edges;
        REP(i, M) {
            int u, v; cin >> u >> v; --u; --v;
            edges.push_back((Edge){u, v});
        }

        vector<double> dp(1<<N);
        REP(S, 1<<N) {
            double q = 0;
            for (int T = (S-1)&S; T; T = (T-1)&S) {
                if ((T&-T) != (S&-S)) continue;
                int k = 0;
                REP(i, M) {
                    int x = 1 << edges[i].src;
                    int y = 1 << edges[i].dst;
                    if ((x&S) && (y&S) && !(x&T) != !(y&T))
                        ++k;
                }
                q += dp[T] * pow(p, k);
            }
            dp[S] = 1 - q;
        }
        print_float(dp[(1<<N)-1]);
    }
}

Measured memory_bytes: 3472
/*
@author: sharrad99
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define	PI 3.141592653589793238462643383279502884197169399375105820974944592307816406286
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pll pair<ll,ll>
#define vll vector<ll>
#define vbl vector<bool>
#define vpll vector<pll>
#define pb push_back
#define eb emplace_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(x) x.begin(),x.end()
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define mod 1000000007
#define INF 1000000000000000
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set_pll;
#define ook order_of_key
#define fbo find_by_order
/*  
	Query 1 - order_of_key(k) : Number of items strictly smaller than k.
	Query 2 - find_by_order(k) : K-th element in the set (counting from zero).
	less<ll> means Query 1 will return numbers strictly less than k.
	greater<ll> means Query 1 will return numbers strictly greater than k.
*/
ll powmod(ll x, ll n){
	ll res = 1;
	while(n){
		if(n & 1){
			res *= x;
			res %= mod;
		}
		x *= x;
		x %= mod;
		n >>= 1;
	}
	return res;
}
ll invmod(ll a){
	return powmod(a, mod - 2);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin >> n;
	string s, t;
	cin >> s >> t;
	string r;
	for(ll i = 0; i < n; i++){
		r.pb(s[i]);
		r.pb(t[i]);
	}
	cout << r;
}

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

#define MAX 2000001
#define VMAX 10000

int main(int argc, char const *argv[]) {


  int i;
  int n;
  int C[VMAX+1];
  int *A,*B;
  scanf("%d",&n);

  A = malloc(sizeof(int)*n+1);
  B = malloc(sizeof(int)*n+1);

  for( i = 0 ; i <= VMAX ; i++ ){
    C[i] = 0;
  }

  for( i = 0 ; i < n ; i++ ){
    scanf("%d",&A[i+1]);
    C[A[i+1]]++;
  }

  for( i = 1 ; i < VMAX ; i++ ){
    C[i] = C[i-1] + C[i];
  }

  for( i = 1 ; i <= n ; i++ ){
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }

  for( i = 1 ; i <= n ; i++ ){
    if( i > 1 ){
      printf(" ");
    }
    printf("%d",B[i]);
  }
  printf("\n");

  return 0;
}

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

int main(){
    long long int N;
    long long int sum=0;
    cin >> N;
    for(long long int i=1;i<=N;i++){
        if(i%3==0 || i%5==0){
            continue;
        } else {
            sum +=i;
        }  
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

void
solve() {
  int n, k;
  cin>>n>>k;

  bool have[105] = {false};
  int t, d;
  for (int i=0; i<k; i++) {
    cin>>d;

    for (int j=0; j<d; j++) {
      cin>>t;
      have[t] = true;
    }
  }

  int ans = 0;
  for (int i=1; i<=n; i++)
    if (!have[i])
      ans++;
  cout<<ans<<endl;
}

int 
main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);

  int t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 3644
import java.util.Scanner

import scala.collection.immutable


object Main {

  def read(): (Int, IndexedSeq[Int]) = {
    val sc: Scanner = new Scanner(System.in)
    val n = sc.nextInt
    val arr = (1 to n).map { _ =>
      sc.nextInt
    }
    sc.close()
    (n, arr)
  }


  def solve(n: Int, arr: IndexedSeq[Int]): Double = {
    val reversedNums = for(i <- arr) yield {
      1.toDouble / i
    }
    1 / reversedNums.sum
  }


  def main(args: Array[String]): Unit = {
    val (a, s) = read()
    println(solve(a, s))
  }

}


Measured memory_bytes: 25540
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    string s;
    cin >> s;

    int res = 0;
    rep(i, 4) if (s[i] == '2') res++;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
    int a, b;

    scanf("%d %d", &a, &b);

    if(a == b) {
        printf("Draw");
    } else if(a == 1) {
        printf("Alice");
    } else if(b == 1) {
        printf("Bob");
    } else if(a > b) {
        printf("Alice");
    } else {
        printf("Bob");
    }

    return 0;
}


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

#define reint register int
#define coint const int

using namespace std;

typedef long long ll;

coint SIZE = 100000 + 5;

struct Job {
    int a, b;

    bool operator < (const Job &j) const { return a < j.a; }
};

priority_queue<int> pq;
int n, m;
Job li[SIZE];

inline int getint(void) {
    reint x = 0, ch = getchar();
    for (; ch < '0' || ch > '9'; ch = getchar());
    for (; ch >= '0' && ch <= '9';
        x = (x << 1) + (x << 3) + (ch - '0'), ch = getchar());
    return x;
}

int main(void) {
    n = getint(), m = getint();
    for (reint i = 1; i <= n; ++i) {
        coint a = getint(), b = getint();
        li[i] = (Job){a, b};
    }
    sort(li + 1, li + n + 1);
    int ind = 0;
    ll ans = 0;
    for (reint i = 1; i <= m; ++i) {
        for (; ind < n && li[ind + 1].a <= i; ++ind) {
            const Job j = li[ind + 1];
            pq.push(j.b);
        }
        if (!pq.empty()) ans += pq.top(), pq.pop();
    }
    printf("%lld\n", ans);
    return 0;
}



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

int main(){
  char s;
  int sum = 0;
  int ans;
  
  for(int i = 0; i <= 200000; i++){
    cin >> s;
    if((int)s >= 48){
      sum += ((int)s-48);
      s = (char)47;
    }else{
      break;
    }
  }
  //printf("\n");
  ans = sum % 9;
  //printf("%d, %d\n", sum, ans);
  if(ans == 0)cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	string s; cin>>s;
	if(s[a]!='-') {
		cout << "No" << endl;
		return 0;
	}
	if(s.size()!=a+b+1) {
		cout << "No" << endl;
		return 0;
	}
	for (int i=0; i<a+b+1; i++)
		if(i!=a&&!isdigit(s[i])) {
			cout << "No" << endl;
			return 0;
		}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#line 2 "header.hpp"

//%snippet.set('header')%
//%snippet.fold()%
#ifndef HEADER_H
#define HEADER_H

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

// varibable settings
const long long INF = 1e18;
template <class T> constexpr T inf = numeric_limits<T>::max() / 2.1;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define _rrep(i, n) rrepi(i, 0, n)
#define rrepi(i, a, b) for (ll i = (ll)((b)-1); i >= (ll)(a); --i)
#define r_rep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(i, a) for (auto &&i : a)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(...) make_tuple(__VA_ARGS__)
#define ub upper_bound
#define lb lower_bound
#define lpos(A, x) (lower_bound(all(A), x) - A.begin())
#define upos(A, x) (upper_bound(all(A), x) - A.begin())
template <class T> inline void chmax(T &a, const T &b) { if ((a) < (b)) (a) = (b); }
template <class T> inline void chmin(T &a, const T &b) { if ((a) > (b)) (a) = (b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }

#define cdiv(a, b) (((a) + (b)-1) / (b))
#define is_in(x, a, b) ((a) <= (x) && (x) < (b))
#define uni(x) sort(all(x)); x.erase(unique(all(x)), x.end())
#define slice(l, r) substr(l, r - l)

typedef long long ll;
typedef long double ld;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;

template <typename T>
using PQ = priority_queue<T, vector<T>, greater<T>>;
void check_input() { assert(cin.eof() == 0); int tmp; cin >> tmp; assert(cin.eof() == 1); }

#if defined(PCM) || defined(LOCAL)
#else
#define dump(...) ;
#define dump_1d(...) ;
#define dump_2d(...) ;
#define cerrendl ;
#endif

#endif /* HEADER_H */
//%snippet.end()%
#line 2 "solve.cpp"
template<class T=ll> using vec = vector<T>;
struct Fast { Fast() { std::cin.tie(0); ios::sync_with_stdio(false); } } fast;


int solve() {
    ll n;cin>>n;
    ll x,t;cin>>x>>t;
    cout << cdiv(n, x)*t << endl;
    return 0; 
}


int main(){/*{{{*/
    solve();
    check_input();
    return 0;
}/*}}}*/


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define int long long  
#define INF 1145141919810893
signed main(){
    string N;
    cin >> N;
    if(N[0]==1){
        cout << 9*(N.size()-1);
    }else if(N.size()==1){
        cout << N[0]-'0';
    }else if(N.size()==2){
        cout << max(N[0]-'0'+N[1]-'0',(N[0]-'0')+8);
    }else{
        if(N[1]==0){
            cout << (N[0]-'0')-1 + 9*(N.size()-1);
        }else{
            int sum1 = max((N[0]-'0')+(N[1]-'0')-1 + 9*(N.size()-2),(N[0]-'0')-1 + 9*(N.size()-1));
            int sum2=0;
            REP(i,N.size()){
                sum2+=(N[i]-'0');
            }
           // cout << sum2 << " ";
            cout << max(sum1,sum2) << endl;
        }
    }
	return 0;
}


Measured memory_bytes: 256
def minplus(array , count):
    if len(array) == 0:
        return count
    if len(array) == 1:
        return array[0] + count
    count += min(array)
    temparray = [y - min(array) for y in array]
    zeroindex = temparray.index(0)
    return minplus(temparray[:zeroindex],count) + minplus(temparray[zeroindex + 1:],0)

N =  int(input())
hn = [int(x) for x in input().split() ]

print(minplus(hn,0))


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

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> X(N + 5);

  for(int i = 0; i < N; i++) cin >> X[i];

  long long int ans;
  long long int min = 100000000;
  for(int i = 0; i <= 100; i++){
    int P = i;
    ans = 0;
    for(int j = 0; j < N; j++){
      ans += (X[j] - P) * (X[j] - P);
    }
    if(ans < min) min = ans;
  }

  cout << min;

}





Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.System.out;

public class Main{
    static MyReader in = new MyReader();

    public static void main(String[] args){
        final int N = in.i();
        int[] P = in.ii(N);
        int[] q = new int[N + 1];
        for(int i = 0; i < N; i++) {
            q[P[i]] = i + 1;
        }

        long ans = 0;
        int[] l = new int[N + 2];
        int[] r = new int[N + 2];
        for(int i = 0; i < N + 1; i++){
            l[i + 1] = i;
            r[i] = i + 1;
        }
        r[N + 1] = N + 1;

        for(int i = 0; i < N; ){
            int v = q[++i];
            int l1 = l[v];
            int r1 = r[v];
            long l2 = l[l1];
            long r2 = r[r1];
            ans += i * ((v - l1) * (r2 - r1) + (r1 - v) * (l1 - l2));
            l[r1] = l1;
            r[l1] = r1;
        }
        out.println(ans);
    }

    static class MyReader extends BufferedReader{
        MyReader(){
            super(new InputStreamReader(System.in));
        }

        String s(){
            try{return readLine();}catch(IOException e){return "";}
        }

        int i() {
            return Integer.parseInt(s());
        }

        long l() {
            return Long.parseLong(s());
        }

        int[] ii(final int N) {
            int[] a = new int[N];
            int i = 0;
            String s = s();
            for (int j = 0; j < a.length; j++) {
                boolean minus = s.charAt(i) == '-';
                i += minus ? 1 : 0;
                int k = 0;
                while (true) {
                    try {
                        int h = s.charAt(i++) - '0';
                        if (h < 0 || 9 < h) break;
                        k = 10 * k + h;
                    } catch (Exception e) { break; }
                }
                a[j] = minus ? -k : k;
            }
            return a;
        }

        long[] ll(final int N) {
            long[] a = new long[N];
            int i = 0;
            String s = s();
            for (int j = 0; j < a.length; j++) {
                boolean minus = s.charAt(i) == '-';
                i += minus ? 1 : 0;
                long k = 0;
                while (true) {
                    try {
                        int h = s.charAt(i++) - '0';
                        if (h < 0 || 9 < h) break;
                        k = 10 * k + h;
                    } catch (Exception e) { break; }
                }
                a[j] = minus ? -k : k;
            }
            return a;
        }
    }
}


Measured memory_bytes: 40060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<int> enum_div(int n) {
    std::vector<int> ret;
    for (int i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i != 1 && i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    int N, A, B;
    cin >> N >> A >> B;
    cout << min(A, B) << " " << max(0, A + B - N) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define abs(x)  ((x)>=0 ? (x) : ((x)*-1))


int main(){

    int N, K, i, j;
    scanf("%d", &N);

    long long int B[N], ans = 0;
    for (i=0; i<N; i++){
        scanf("%lld", &B[i]);
    }

    long long int min=10000000000, min_sequence;
    int mi_num=0;
    for (i=0; i<N; i++){
        if (abs(B[i]) < min){
            min = abs(B[i]);
            min_sequence = i;
        }
        if (B[i] < 0) mi_num++;
    }

    if (mi_num%2 == 0){
        for (i=0; i<N; i++){
            ans += abs(B[i]);
        }
    }else{
        for (i=0; i<N; i++){
            ans += abs(B[i]);
        }
        ans -= 2*abs(B[min_sequence]);
    }
 

    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
using namespace std;
 
int main() {
  string s1,s2,s3;
  cin >> s1 >> s2 >> s3;
  if(s1[s1.length()-1]==s2[0]&&s2[s2.length()-1]==s3[0])cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
//  ######    ##   ######    ##   ##    ##
//  ##  ##   ###   ##  ##   ###   ###   ##
//  ######  ####   ######  ####   ##### ##
//  ##     ## ##   ##     ## ##   ## #####
//  ##    ##  ##   ##    ##  ##   ##   ###
#include<bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(b);i++)//no need to declare variable i
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(d);j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for((a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRvl(c) for (vl::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvll(c) for (vll::iterator it = (c).begin(); it != (c).end(); it++)
#define mod 1000000007
#define gc getchar_unlocked
#define pc putchar_unlocked3
#define pb(a) push_back((a))
 


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



int main()
{
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    */
    
    lo t;
    //cin>>t;
    //while(t--)
        solve();




}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BTwoArrays solver = new BTwoArrays();
        solver.solve(1, in, out);
        out.close();
    }

    static class BTwoArrays {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            int[] b = new int[n];
            long x = 0;
            long y = 0;
            long sum = 0;

            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
                x += a[i];

            }

            for (int i = 0; i < n; i++) {
                b[i] = in.nextInt();
                y += b[i];
            }

            for (int i = 0; i < n; i++) {
                if (a[i] < b[i]) {
                    sum += ((b[i] - a[i]) - 1 + 2) / 2;
                }
            }
            out.println(sum <= (y - x) ? "Yes" : "No");

        }

    }
}



Measured memory_bytes: 42192
def split(heights)
  res = []
  this = []
  h = heights.dup
  until h.empty?
    if h[0] == 0
      unless this.empty?
        res << this
        this = []
      end
    else
      this << h[0]
    end
    h.shift
  end
  unless this.empty?
    res << this
  end
  res
end

def solve(spans)
  spans.inject(0) do |acc, span|
    minimum = span.min
    acc + minimum + solve(split(span.map { |n| n - minimum }))
  end
end

n = gets.to_i
heights = gets.split.map(&:to_i)

p solve(split(heights))


Measured memory_bytes: 2172
#C - Prison(ABC127)
N,M=map(int, input().split())
l,r=map(int, input().split())
for i in range(M-1):
    L,R=map(int,input().split())
    l=max(L,l)
    r=min(r,R)
if r-l+1>0:
    print(r-l+1)
else:
    print(0)

Measured memory_bytes: 3060
# coding: utf-8
a, b, c, k = map(int, input().split())
x = 0
y = k

if y <= a:
    x += k
    print(x)
else:
    x += a
    y -= a
    if y <= b:
        print(x)
    else: 
        x -= k - (a + b)
        print(x)


Measured memory_bytes: 9172
#include <iostream>
#include <cstring>
#define MOD 1000000007
using namespace std;

char s[200010];
int n, a;

int main(void){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>s;
	for (int i = 0; s[i]; ++i){
		if(s[i]=='S')a++;
		else if(s[i]=='T')a--;
		if(a<0)a=0;
		n++;
	}
	cout<<2*a;
	return 0;
}

Measured memory_bytes: 512