akhauriyash/Code-Regression huggingface dataset:
//#include <tourist>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
//-std=c++14
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
struct edge {
    int to, cost;
};
int n, b, c;
vector<int> a;
vector<int> color(200,0);
vector<vector<int> > e(200);
ll d[200][200];
// 2部グラフ判定
bool dfs(int i,int c) {
    color[i] = c;
    for(auto x:e[i]) {
        if (color[i] == color[x]) return false;
        if (color[x] == 0 && !dfs(x,-c)) return false;
    }
    return true;
}
void warshall_floyd(int n) {
  for (int k = 0; k < n; k++){       // 経由する頂点
    for (int i = 0; i < n; i++) {    // 始点
      for (int j = 0; j < n; j++) {  // 終点
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    vector<string> s;
    for (int i = 0; i < n; i++)
    {
        string temp;
        cin >> temp;
        s.push_back(temp);
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            d[i][j]=INF;
            if(s[i][j]=='1'){
                e[i].push_back(j);
                d[i][j]=1;
            }
            if(i==j)d[i][j]=0;
        }
    }
    if(!dfs(0,1)) return cout<<-1<<"\n",0;
    ll ans=0;
    warshall_floyd(n);
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
               if(d[i][j]==INF)continue;
               ans=max(ans,d[i][j]);
        }
    }
    cout << ans+1 << "\n";
}



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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))
#define uniq(v) (v).erase(unique(all(v)), (v).end())
#define rsort(v) sort(all(v)); reverse(all(v))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template<typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template<typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template<typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template<typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template<typename T> inline T power(T x, i64 n) { T r = 1; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template<typename T> istream& operator>>(istream &is, vector<T> &v) { for (auto &x : v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }

i64 diff(i64 a, i64 b, i64 c) {
  vi64 v = {a, b, c};
  sort(all(v));
  return v[2] - v[0];
}

void solve() {
  i64 H, W; cin >> H >> W;
  i64 ans = 1e18;
  reps(i, H - 1) {
    i64 h = H - i, w = W;
    i64 a, b, c;
    a = i * w;
    {
      i64 w1 = w / 2, w2 = w - w1;
      b = h * w1, c = h * w2;
      amin(ans, diff(a, b, c));
    }
    {
      i64 h1 = h / 2, h2 = h - h1;
      b = w * h1, c = w * h2;
      amin(ans, diff(a, b, c));
    }
  }
  reps(i, W - 1) {
    i64 h = H, w = W - i;
    i64 a, b, c;
    a = h * i;
    {
      i64 w1 = w / 2, w2 = w - w1;
      b = h * w1, c = h * w2;
      amin(ans, diff(a, b, c));
    }
    {
      i64 h1 = h / 2, h2 = h - h1;
      b = w * h1, c = w * h2;
      amin(ans, diff(a, b, c));
    }
  }
  cout << ans << '\n';
}


Measured memory_bytes: 256
package main

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

func partition(xs []int, p int, r int) int {
	x := xs[r]
	as := xs[:r]
	i := p - 1 // 前パーティションの最後の要素のポインタ
	j := p
	for j < len(as) {
		target := as[j]
		if target <= x {
			i++
			as[j] = as[i]
			as[i] = target
		}
		j++
	}
	xs[r] = xs[i+1]
	xs[i+1] = x
	return i + 1
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	n, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return n
}

func printArray(xs []int, q int) {
	ss := make([]string, len(xs))
	for i, x := range xs {
		if i == q {
			ss[i] = "[" + strconv.Itoa(x) + "]"
		} else {
			ss[i] = strconv.Itoa(x)
		}
	}
	fmt.Println(strings.Join(ss, " "))
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt(sc)
	xs := make([]int, n)
	for i := 0; i < n; i++ {
		xs[i] = nextInt(sc)
	}
	q := partition(xs, 0, n-1)
	printArray(xs, q)
}



Measured memory_bytes: 5516
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
  string  s;
  cin>>s;
  if((s[0]==s[1]&&s[0]==s[2])||(s[1]==s[2]&&s[1]==s[3])){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
 
public class Main {
public static void main(String[] args) throws IOException {
  Scanner sc = new Scanner(System.in);
  PrintWriter pw = new PrintWriter(System.out);
  
  int dishes = sc.nextInt();
  int[] dishOrder = new int[dishes];
  int[] bSat = new int[dishes];
  int[] cSat = new int[dishes-1];
  for (int i = 0; i < dishes; i++) {
    dishOrder[i] = sc.nextInt();
  }
  for (int i = 0; i < dishes; i++) {
    bSat[i] = sc.nextInt();
  }
  for (int i = 0; i < dishes-1; i++) {
    cSat[i] = sc.nextInt();
  }
  int count = 0;
  count += bSat[dishOrder[0]-1];
  for (int i = 1; i < dishes; i++) {
    count += bSat[dishOrder[i]-1];
    if (dishOrder[i-1] + 1 == dishOrder[i]) {
      count += cSat[dishOrder[i-1]-1];
    }
  }
  pw.println(count);
  
  sc.close();
  pw.close();
}
}

Measured memory_bytes: 22868
import Control.Applicative
import Data.Maybe

calc :: String -> Maybe Int
calc s = let
    [a',op,b'] = words s
    a = read a'
    b = read b'
    in
        case op of
            "+" -> Just $ a+b
            "-" -> Just $ a-b
            "*" -> Just $ a*b
            "/" -> Just $ a `div` b
            _ -> Nothing


main = getContents >>=
    mapM_ (print . fromJust) . takeWhile isJust . map calc . lines

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

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

typedef long long ll;

void solve(long long N, long long M, std::vector<long long> p,
           std::vector<std::string> S)
{
    int AC[100005] = {};
    int WA[100005] = {};

    rep(i, M)
    {
        if (AC[p[i]] != 0)
        {
            continue;
        }
        else if (S[i] == "AC")
        {
            AC[p[i]]++;
        }
        else if (S[i] == "WA")
        {
            WA[p[i]]++;
        }
    }

    int ans = 0;
    int pena = 0;
    rep(i, 100005)
    {
        ans += AC[i];
        if (AC[i] != 0)
        {
            pena += WA[i];
        }
    }
    cout << ans << " " << pena << endl;
}

int main()
{
    long long N;
    scanf("%lld", &N);
    long long M;
    scanf("%lld", &M);
    std::vector<long long> p(M);
    std::vector<std::string> S(M);
    for (int i = 0; i < M; i++)
    {
        scanf("%lld", &p[i]);
        std::cin >> S[i];
    }
    solve(N, M, std::move(p), std::move(S));
    return 0;
}


Measured memory_bytes: 7296
/* ITP1_1-D 
*/

/* ????????¨
????????\???????????????????????° i ??????????????????
??????i ??¨?????° 60 ?????°????????????????????????????????´??°??¨??? i ?????£??\?????????
??????
??????????¨??????????????????°??¢??°??§????£?????????????
??????
*/

#include <stdio.h>
#define COUNT 3

void re_put(int, unsigned);

int main(void)
{
	unsigned i;
	fscanf(stdin, "%u", &i);
	
	re_put(COUNT, i);
	fputc('\n', stdout);
	
	return 0;
}

void re_put(int cou, unsigned X)
{
	if (1 < cou) re_put(cou - 1, X / 60);
	
	if (cou == 1) fprintf(stdout, "%u", X);
	else fprintf(stdout, ":%u", X % 60);
	
	
}

Measured memory_bytes: 612
#include<stdio.h>

int main(void)
{
int W,H,x,y,r;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

if(x-r<0||y-r<0||x+r>W||y+r>H)
{
printf("No\n");
}
else{
printf("Yes\n");
}
return 0;
}

Measured memory_bytes: 580
/** @Date    : 2017-07-06 09:56:44
  * @FileName: atcoder077 D 组合.cpp
  * @Platform: Windows
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version : $Id$
  */
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;
const LL mod = 1e9 + 7;

LL a[N];
LL inv[N];
LL fa[N];
LL n;

void init()
{
	fa[0] = fa[1] = 1;
    inv[1] = 1;
    for(LL i = 2; i < N; i++)
    {
        fa[i] = fa[i-1] * i % mod;
        inv[i] = (mod - mod / i) * inv[mod % i] % mod;
    }
    inv[0] = 1;
    for(int i = 1; i < N; i++)
    	(inv[i] *= inv[i - 1]) %= mod;
}

LL C(LL n, LL k)
{
	LL ans = 0;
	if(k > n)
		return ans;
	ans = ((fa[n] * inv[k] % mod) * inv[n - k]) % mod;
	return ans;
}
int main()
{
	init();
	while(cin >> n)
	{
		map<LL, int>q;
		LL p = 0;
		for(int i = 1; i <= n + 1; i++)
		{
			scanf("%lld", a + i);
			if(!q[a[i]])
				q[a[i]] = i;
			else 
				p = i;
		}
		for(int i = 0; i <= n; i++)
		{
			LL ans = 0;
			ans = (ans + C(n + 1, i + 1)) % mod;
			ans = (ans - C(n - p + q[a[p]], i)) % mod;
			while(ans < 0)
				ans += mod;
			printf("%lld\n", ans);
		}
	}
    return 0;
}

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

const ll mod = 998244353;
const int MAXK = 10;
const int MAXN = 200015;

ll k, n, BIT[MAXN];
pll in[MAXK];


inline int lowbit(int);
void solve();
void modify(ll,ll);
ll query(ll);

int main(){
    ios::sync_with_stdio(0), cin.tie(0);
    while (cin >> n) solve();
    return 0;
}

void solve() {
    cin >> k;
    for (int i = 0; i < k; ++i) cin >> in[i].first >> in[i].second;
    sort(in, in + k);

    // init
    for (int i = 0;  i <= n + 5; ++i) BIT[i] = 0;

    modify(1, 1);
    modify(2, -1);

    for (int i = 1; i < n; ++i) {
        ll now = query(i), l, r;

        for (int j = 0; j < k; ++j) {
            l = in[j].first; r = in[j].second;
            l = i + l; r = i + r;
            if (l > n) break;
            r = min(r, n);
            modify(l, now);
            modify(r+1, -now);
            //cout << i << ' ' << l << ' ' << r << ' ' << now << '\n';
        }

    }


    ll ans = query(n);
    cout << ans << '\n';
}

inline int lowbit(ll v) {
    return v & (-v);
}

void modify(ll id, ll v) {
    v = ((v % mod) + mod) % mod;
    while (id <= n)  {
        BIT[id] += v;
        BIT[id] = ((BIT[id] % mod) + mod) % mod;
        id += lowbit(id);
    }
}

ll query(ll id) {
    ll ans = 0;
    while (id) {
        ans += BIT[id];
        ans %= mod;
        id -= lowbit(id);
    }
    return ans;
}


Measured memory_bytes: 5208
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
using namespace std;
#define inf 1e200
int a[200001][6];
int n;
int GetManhattan(int p[][6], int n, int dem)
{
	int ans = 0, Min, Max;
	int i, j, k;
	for (i = 0; i < (1 << (dem)); i++) {    //用二进制形式遍历所有可能的运算情况
		Min = inf, Max = -inf;
		for (j = 0; j < n; j++) {    //遍历每一个点
			int sum = 0;
			for (k = 0; k < 2; k++) {    //因为是五维的，所以有4个运算符
				//提取当前运算符
				int t = i & 1 << k;    //1为+，0为-
				if (t) sum += p[j][k];
				else sum -= p[j][k];
			}
			if (sum > Max) Max = sum;
			if (sum < Min) Min = sum;
		}
		if (Max - Min > ans)
			ans = Max - Min;
	}
	return ans;
}
#pragma warning(disable:4996)
int main() {
	scanf("%d", &n);
		for (int i = 0; i < n; i++)
			for (int j = 0; j < 2; j++) scanf("%d", &a[i][j]);
		int ans = GetManhattan(a, n, 2);
		printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 8512
#include <iostream>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
  double w,h,x,y;
  cin >> w >> h >> x >> y;
  
  double ans = (w*h)/2;
  
  int num = (w==2*x && h==2*y)? 1 : 0;
  
  printf("%.10f %d\n",ans,num);
  
}

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N;
bool dp [101] [10001];

int main()
{
	scanf("%d",&N);
	vector<int> A(N);
	FOR(i,0,N){
		scanf("%d",&A [i]);
	}

	dp [0] [0] = true;
	FOR(i,0,N) FOR(j,0,10001) if(dp [i] [j]){
		dp [i + 1] [j + A [i]] = true;
		dp [i + 1] [j] = true;
	}

	int ans = 0;
	for(int i = 10000;i >= 0;i--) if(i % 10 && dp [N] [i]){
		chmax(ans,i);
	}
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 1024
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let n: usize = read();
    let p: Vec<usize> = read_vec();
    let mut count = 0;

    for i in 0..n-2 {
      if (p[i] < p[i+1] && p[i+1] < p[i+2])|| (p[i+2] < p[i+1] && p[i+1] < p[i]) {
        count += 1;
      }
    }

    println!("{}", count)
}


Measured memory_bytes: 4352
import sys
import collections
ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())

n = ni()
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

lis = make_divisors(n)
ans = 0
for i in lis:
    if i - 1 == 0:
        continue
    if i - 1 > n // i:
        ans += i - 1
print(ans)


Measured memory_bytes: 3564
#include<stdio.h>
int main (){
  long ans;
  long h,w;
  scanf("%ld%ld",&h,&w);
  if(h%2==1 && w%2==1){
    ans=(h*w+1)/2;
  }else{
    ans=h*w/2;
  }
  if(h==1 || w==1){
    ans = 1;
  }
  printf("%ld\n",ans);
  return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        boolean judge = k <= (int) Math.ceil(n / 2.0);
        String result = judge ? "YES" : "NO";

        // 出力
        System.out.println(result);
    }
}


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

int binpow(int n, int k) {
    if (k == 0) return 1;
    if (k == 1) return n;
    if (k % 2 == 0) {
        int nn = binpow(n, k / 2);
        return nn*nn;
    }
    if (k % 2 == 1) {
        return n * binpow(n, k - 1);
    }
}

void solve() {
    int n, s;
    cin >> n >> s;
    vector<int> v(n);
    vector<long long> dp(s), dp1(s);
    long long res = 0;
    long long mod = 998244353;
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    for (int i = 0; i < s; i++) {
        dp[i] = 0;
        dp1[i] = 0;
    }
    for (int i = 0; i < n; i++) {
        if (v[i] == s) {
            res += (i + 1) * (n - i);
            continue;
        }
        if (v[i] > s) continue;
        for (int j = 0; j < s; j++) {
            if (j + v[i] == s) {
                res += dp[j] * (n - i);
                res %= mod;
            }
            if (j + v[i] < s) {
                dp1[j + v[i]] += dp[j];
                dp1[j + v[i]] %= mod;
            }
        }
        dp1[v[i]] += i + 1;
        dp1[v[i]] %= mod;
        for (int j = 0; j < s; j++) {
            dp[j] += dp1[j];
            dp1[j] = 0;
            dp[j] %= mod;
        }
    }
    cout << res << endl;
}

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


Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<string>
#include<vector>
#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<fstream>
#include<sstream>
#include<queue>
#include<iterator>
#include<stack>

using namespace std;

#define st first
#define nd second
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REV(a) reverse(a.begin(),a.end())
#define SORT(a) sort(a.begin(),a.end())
#define inf (int)1e9
#define linf (long long)1e18

typedef long long ll;
typedef short int si;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<pli> vpli;


set<int> ha;
int main() {
		int n;
		cin>>n;
		int a;
		cin>>a;
		ha.insert(a);
		FOR(i,1,n){
				cin>>a;
				if(ha.find(a)==ha.end())ha.insert(a);
				else ha.erase(a);
		}
		cout<<ha.size()<<endl;







		return 0;
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0)->sync_with_stdio(false);
	int n; cin >> n;
	int maxP, minP, maxS, minS;
	maxP = maxS = INT_MIN;
	minP = minS = INT_MAX;
	while (n--) {
		int x, y; cin >> x >> y;
		maxP = max(maxP, x + y);
		minP = min(minP, x + y);
		maxS = max(maxS, x - y);
		minS = min(minS, x - y);
	}
	cout << max(maxP - minP, maxS - minS) << '\n';
    return 0;
}


Measured memory_bytes: 3632
using System;

namespace NTL1_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = scan[0];
            var a = scan;
            int ans = 1;
            for (int i = 0; i < n; i++)
            {
                int g = gcd(ans, a[i]);
                ans = g * (ans / g) * (a[i] / g);
            }
            Console.WriteLine(ans);
        }
        static int gcd (int x, int y)
        {
            if (x > y)
            {
                int t = x;
                x = y;
                y = t;
            }
            while (y > 0)
            {
                int r = x % y;
                x = y;
                y = r;
            }
            return x;
        }

        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }
}

Measured memory_bytes: 9256
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}

}

#[allow(unused_imports)]
use input::*;

fn main() {
    let n: usize;
    input!(n);
    let mut v = input_vector::<usize>();
    let mut i = 1;
    let mut ans = 0;
    while i < n {
        if v[i - 1] == i {
            v.swap(i - 1, i);
            ans += 1;
        }
        i += 1;
    }
    if v[n - 1] == n {
        ans += 1;
    }

    p(ans);
}

Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
typedef long long LL;
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

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

	vector<int> p(n);
	rep(i, n) cin >> p[i];

	int count = 0;
	for (int i = 1; i < n - 1; i++)
	{
		vector<int> check = { p[i - 1],p[i],p[i + 1] };
		sort(ALL(check));

		if (p[i] == check[1]) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//Optimisations
#pragma GCC target ("avx2")
#pragma GCC optimization ("unroll-loops")
#pragma GCC optimize("O2")
//shortcuts for functions
#define pb push_back
#define mp make_pair
#define ff first 
#define ss second
#define all(v) v.begin(),v.end()
#define prec(n) fixed<<setprecision(n)
#define n_l '\n'
// make it python 
#define gcd __gcd
#define append push_back
#define str to_string
// utility functions shortcuts
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define sswap(a,b) {a=a^b;b=a^b;a=a^b;}
#define swap(a,b) {auto temp=a; a=b; b=temp;}
#define init(dp) memset(dp,-1,sizeof(dp));
#define set0(dp) memset(dp,0,sizeof(dp));
#define bits(x) __builtin_popcount(x)
#define SORT(v) sort(all(v))
#define endl "\n"
#define forr(i,n) for(ll i=0;i<n;i++)
// declaration shortcuts
typedef long long int ll;
#define int ll
// Constants
constexpr int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};
constexpr ll INF = 1999999999999999997; 
constexpr int inf= INT_MAX;
constexpr int MAXSIZE = int(1e6)+5;
constexpr auto PI  = 3.14159265358979323846L;
constexpr auto oo  = numeric_limits<int>::max() / 2 - 2;
constexpr auto eps = 1e-6;
constexpr auto mod = 1000000007;
constexpr auto MOD = 1000000007;
constexpr auto MOD9 = 1000000009;
constexpr auto maxn = 100006;
//void IOfile(){
//freopen(file_name, reade_mode, stdin);
//freopen(file_name, write_mode, stdout);
//}
void fastio(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}

int a[maxn];
int ans[maxn];
int32_t main(){
	fastio();
	int n;
	cin >> n;
	int sum = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		if(i & 1) sum += 2 * a[i];
		else sum -= 2 * a[i];
		a[i] *= 2;
	}
	ans[1] = sum / 2;
	cout << ans[1] << " ";
	for(int i = 1; i < n; i++ ){
		ans[i + 1] = a[i] - ans[i];
		cout << ans[i + 1] << " ";
	}
}

Measured memory_bytes: 5180
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define n_max 1000000


int main(){
    int n;
    string s;
    int q;
    cin >> n >> s >> q;
    int k;
    int M_size=0;
    llong m,d,cnt;
    llong ans;
    REP(ii,q){
        ans=m=d=cnt=0;
        cin >> k;
        REP(i,n){
            if(s[i] =='D') d+=1;
            else if(s[i] == 'M'){
                m+=1;
                cnt+=d;
            }
            else if(s[i] == 'C'){
                ans+=cnt;
                
            }
            if( i+1 - k >=0){
                if(s[i+1-k] == 'D'){
                    d-=1;
                    cnt-=m;
                }
                else if( s[i+1-k] == 'M'){
                    m-=1;
                }
            }
        }
        cout << ans <<  endl;
    }
}

Measured memory_bytes: 1412
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>

using namespace std;

#define square(s) (s)*(s)
#define scast(type,e) static_cast<type>(e)
template<class T>
using vec = vector<T>;

int main() {
	int n, d;
	cin >> n >> d;
	vec<vec<int>> X(n);
	for (int i = 0; i < n; i++) {
		X[i].resize(d);
		for (int j = 0; j < d; j++) {
			cin >> X[i][j];
		}
	}
	
	auto solve = [&](int l, int r)->bool {
		int sum = 0;
		for (int i = 0; i < d; i++) {
			sum += square(X[l][i] - X[r][i]);
		}
		auto res = sqrt(sum);
		return res - scast(double, scast(int, res)) == 0;
	};

	int res = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			if (solve(i,j))res++;
		}
	}
	cout << res << endl;

	return 0;
}

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

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n;
string s;

int main()
{
    _FastIO;
    cout.precision(14);
    cin >> n;
    double ans = 0.0;
    for(int i = 0; i < n; i++){
        double x;
        cin >> x;
        ans += (1.0 * 1.0 / x);
    }
    ans = 1.0 * 1.0 / ans;
    cout << fixed << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n+1, 0), b(n+1, 0);
    rep(i,n){
        cin >> a[i+1];
        a[i+1] += a[i];
    }
    rep(i,n) cin >> b[i];
    int ans = 0;
    for(int i = n-1; i >= 0; i--){
        b[i] += b[i+1];
    }
    rep(i,n){
        chmax(ans, a[i+1] + b[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iostream>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <complex>
#include <cassert>
#include <random>
#include <cstring>
#include <numeric>
#define ll long long
#define ld long double
#define null NULL
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < n; ++i)
#define sz(a) (int)a.size()
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1 | 1
template<class T> int gmax(T &a, T b) { if (b > a) { a = b; return 1; } return 0; }
template<class T> int gmin(T &a, T b) { if (b < a) { a = b; return 1; } return 0; }
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A>
string to_string(A v) { bool first = true; string res = "{"; for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); } res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << to_string(H); debug_out(T...); }
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int MAXN = 105;
int B[MAXN];
int A[MAXN];
int main() {
    int n;
    while(~scanf("%d", &n)) {
        for(int i = 1; i < n; ++i) {
            scanf("%d", &B[i]);
        }

        for(int i = 1; i <= n; ++i) {
            if(i == 1) A[i] = B[i];
            else if(i == n) A[i] = B[i - 1];
            else A[i] = min(B[i], B[i-1]);
        }

        int sum = 0;
        for(int i = 1; i <= n; ++i) {
            sum += A[i];
        }

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

    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <vector>

using namespace std;
int main() {
	int n, a, b,aa=0,bb=0;
	for (;;) {
		cin >> n;
		if (n == 0) return 0;

		for (int i = 0; i < n; i++) {
			cin >> a >> b;
			if (a > b)aa += a + b;
			else if (b > a)bb += a + b;
			else if (a == b) {
				aa += a;
				bb += b;
			}
			
		}
		cout << aa << " " << bb << endl;
		aa = 0; bb = 0;
	}
	return 0;
}

Measured memory_bytes: 2992
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class BIncrementDecrement {
public:
    void solve(std::istream &in, std::ostream &out) {
        int n;
        in >> n;
        string str;
        in >> str;
        int x = 0, res = 0;
        trav(c, str) {
            x += c == 'I' ? 1 : -1;
            ckmax(res, x);
        }
        out << res << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    BIncrementDecrement solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <limits>
#include <unordered_map>

using namespace std;
using str = string;

#define rep(a,l,r) for(int a=(l);a<(r);a++)
#define get cin>>
#define put cout<<

void run() {

	long a; get a;
	long b; get b;

	if (a + b == 15) {
		put "+";return;
	}

	if (a * b == 15) {
		put "*"; return;
	}

	put "x"; return;

}

int main() {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);run();return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn = 1010;
int n;
LL x[maxn],y[maxn],u[maxn],v[maxn],bs[35];
void work(){
    cin >> n;
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
    LL sum = (x[0] + y[0]) % 2;
    for (int i = 0; i < n; i++) if ((x[i] + y[i] - sum) % 2 != 0) {cout<<"-1"<<endl;return;}

    if (sum == 0) {
      cout << 32 << endl;
      for (int i = 30; i > -1; i--) cout<<bs[i]<<" ";
      cout << 1 << endl;
      for (int i = 0; i < n; i++) x[i]++;
    }else {
      cout << 31 << endl;
      for (int i = 30; i > -1; i--) cout<<bs[i]<<" ";
      cout << endl;
    }

    for (int i = 0; i < n; i++) u[i] = x[i] + y[i], v[i] = x[i] - y[i];

    for (int i = 0; i < n; i++) {
        for (int j = 30; j > -1; j--) {
            if (u[i] > 0 && v[i] > 0) {cout << 'R'; u[i] -= bs[j];  v[i] -= bs[j];}//x[i] > y[i] & x[i] > 0
            else if (u[i] > 0 && v[i] < 0) {cout << 'U'; u[i] -= bs[j];  v[i] += bs[j];}//y[i] > x[i] & y[i] > 0
            else if (u[i] < 0 && v[i] > 0) {cout << 'D'; u[i] += bs[j];  v[i] -= bs[j];}//x[i] > y[i] && y[i] < 0
            else {cout << 'L'; u[i] += bs[j];  v[i] += bs[j];}//x[i] < y[i] & x[i] < 0;
      }
      if (sum == 0) cout << 'L';
      cout << endl;
    }
}
int main(){
    bs[0] = 1;
    for (int i=1;i<32;i++) bs[i] = bs[i-1] << 1;
//    for (int i=0;i<32;i++) cout<<bs[i]<<endl;
    work();
    return 0;
}



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

int main(){
    int a,b;
    cin>>a>>b;
    int add=a+b;
    int sub=a-b;
    int mul=a*b;
    int res=max(max(add,sub),mul);
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int num1 = scan.nextInt();
        int num2 = scan.nextInt();
        int num3 = scan.nextInt();

        for(int i = 0; i<10;i++){
            num3 = num1*num3 - num2;
            System.out.println(num3);
        }
    }
}

Measured memory_bytes: 20564
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000001;
const long long LINF = 1e18;
const int MAX = 510000;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b)cout << "YES" << endl;
	else {
		cout << "NO" << endl;
	}
		return 0;
}

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

ll powmd(ll a,ll b)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b=b>>1;
    }
    return(ans);
}

int main()
{
    ll n;
    cin>>n;
    if(n<2)
    {
        cout<<0<<"\n";
    }
    else
    {
        ll ans=powmd(9,n)%mod;
        ans=(ans+powmd(9,n))%mod;
        ans=(ans-powmd(8,n)+mod)%mod;
        ans=(powmd(10,n)-ans+mod)%mod;
        cout<<ans<<"\n";
    }
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
typedef long long lint;

struct Edge {
    int from, to;
    int w;
    Edge() {}
    Edge(int f, int t, int w) : from(f), to(t), w(w) {}
    void print() const {
        cout << from << " " << to << " " << w << endl;
    }
};

int main() {
    int L;
    cin >> L;
    int last = 0;
    while ((1<<last) <= L) {
        ++last;
    }
    // 1 ~ last まで 1 2 4 8 ... でつなげる
    vector<Edge> ans;
    for (int i = 1; i < last; i++) {
        ans.emplace_back(i, i+1, 0);
        ans.emplace_back(i, i+1, 1<<(i-1));
    }
    int w = 1<<(last-1);
    for (int i = last-1; i >= 1; i--) {
        if ((L>>(i-1)) & 1) {
            ans.emplace_back(i, last, w);
            w += 1<<(i-1);
        }
    }
    cout << last << " " << ans.size() << endl;
    for (const Edge& e : ans) {
        e.print();
    }
    return 0;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;

  vector<int> A(N);

  vector<int> m(N);
  for (int i = 0; i < N; i++) {
    m[i] = 0;
  }

  for (int i = 0; i < N - 1; i++) {
    int a;
    cin >> a;
    m[a-1]++;
  }

  for (int i = 0; i < N; i++) {
    cout << m[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 4476
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll a, b, c;
  cin >> a >> b >> c;
  (a+b+c >= 22) ?cout << "bust" : cout << "win";
  return 0;
} //good night.

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl

const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};

struct LowestCommonAncestor {

  int V, MAX_LOG_V;
  vector<vector<int>> edge;

  vector<vector<int>> parent;
  vector<int> depth;

  LowestCommonAncestor(int V, int MAX_LOG_V = 17) : V(V), MAX_LOG_V(MAX_LOG_V) {
    edge.resize(V);
    parent.resize(MAX_LOG_V);
    REP(i, MAX_LOG_V) parent[i].resize(V);
    depth.resize(V);
  }

  void add_edge(int a, int b) {
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  void dfs(int v, int par, int dep) {
    parent[0][v] = par;
    depth[v] = dep;
    for (auto child : edge[v]) {
      if (child != par) dfs(child, v, dep + 1);
    }
  }

  void init(int root = 0) {
    dfs(root, -1, 0);
    for (int k = 0; k + 1 < MAX_LOG_V; k++) {
      for (int v = 0; v < V; v++) {
        if (parent[k][v] < 0) {
          parent[k+1][v] = -1;
        } else {
          parent[k+1][v] = parent[k][parent[k][v]];
        }
      }
    }
  }

  int run(int u, int v) {
    if (depth[u] > depth[v]) swap(u, v);
    for (int k = 0; k < MAX_LOG_V; k++) {
      if ((depth[v] - depth[u]) >> k & 1) {
        v = parent[k][v];
      }
    }
    if (u == v) return u;

    for (int k = MAX_LOG_V - 1; k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }

  int get_cntup_node(int v, int cnt) {
    for (int k = MAX_LOG_V - 1; k >= 0; k--) {
      if (cnt >> k & 1) {
        v = parent[k][v];
      }
    }
    return v;
  }
};

int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N; cin >> N;
  LowestCommonAncestor lca(N);
  REP(i, N) {
    int K; cin >> K;
    REP(_, K) {
      int c; cin >> c;
      lca.add_edge(i, c);
    }
  }

  lca.init();

  int Q; cin >> Q;
  REP(i, Q) {
    int u, v; cin >> u >> v;
    int anc = lca.run(u, v);
    cout << anc << endl;
  }

  return 0;
}

Measured memory_bytes: 18368
// Author: πα

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

const int N = 22;
char g[N][N];
long dp[N][N];
bool vis[N][N];

void dfs(int x, int y, long k = 0)
{
    if(vis[x][y] or g[x][y] != '.' or dp[x][y] == k)
        return;
    vis[x][y] = 1;
    dp[x][y] = min(dp[x][y], k);
    dfs(x+1, y, k+1);
    dfs(x-1, y, k+1);
    dfs(x, y+1, k+1);
    dfs(x, y-1, k+1);
    vis[x][y] = 0;
}

int main()
{
    int n, m;
    long ans = 0;
    cin >> n >> m;
    for(int i = 1; i <= n; ++i)
        cin >> g[i]+1;
    for(int x = 1; x <= n; ++x)
        for(int y = 1; y <= m; ++y)
            if(g[x][y] == '.')
            {
                memset(dp, -1, sizeof(dp));
                dfs(x, y);
                for(int i = 1; i <= n; ++i)
                    for(int j = 1; j <= m; ++j)
                        if(g[i][j] == '.')
                            ans = max(ans, dp[i][j]);          
            }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
long long algae(long long year);
long long d, r;
long long arr[20];
long long main()
{
    for(long long i=0; i<20; i++)
        arr[i] = -1;
    scanf("%lld %lld %lld", &r, &d, &arr[0]);
    for(long long i=1; i<=10; i++)
        printf("%lld\n", algae(i));
    return 0;
}

long long algae(long long year)
{
    if(arr[year]!=-1)
        return arr[year];
    else
        return (arr[year] = algae(year-1)*r - d);
}

Measured memory_bytes: 128
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
    #include <iostream>
    #include <cstdlib>
    #include <bits/stdc++.h>
    #include<algorithm>
    using namespace std;
    int main(){
        int n,i,j,x;
        long long int ans=0,a[200010],b[200010];
        b[0]=0;
        cin >> n;
        long long int MOD=1000000007;
        
        for(i=0;i<n;i++)
        {
            cin >> a[i];
        }
        for(i=1;i<n+1;i++)
        {
            b[i]=a[i-1]+b[i-1];
            b[i]=b[i]%MOD;
        }
        for(i=0;i<n;i++)
        {
            x=i+1;
            ans+=a[i]*(b[n]-b[x]+MOD)%MOD;
            ans=ans%MOD;
        }
        cout << ans << endl;
    }

Measured memory_bytes: 6748
a, b, k = gets.chomp.split.map(&:to_i)

cnt = 0
n = [a, b].min
i = n
while i>0 do
  if a%i == 0 and b%i ==0
    cnt+=1
    if cnt == k
      p i
      exit
    end
  end
  i-=1
end  

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> ii;

int main(){
    int n, a, b;
    scanf("%d %d %d", &n, &a, &b);
    if ((a-b)%2 == 0) printf("Alice\n");
    else printf("Borys\n");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define repr(i,x,n) for(int i=x; i<(n); i++)
#define ALL(x) (x).begin(),(x).end()-1
#define INF 1e9
typedef long long ll;
using VI = vector<int>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main()
{
    string a,b;
    cin>>a>>b;
    int c=a.length();
    b.erase( --b.end() );
    if (a==b)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
    return 0;
}

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

typedef long long ll;
#define pii pair<int ,int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 1005

int n;

int main()
{
    _FastIO;
    cin >> n;
    bool flag = true;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        if(x % 2 == 0 && (x % 3 && x % 5)){
            flag = false;
        }
    }
    if(flag){
        cout << "APPROVED" << endl;
    }
    else
        cout << "DENIED" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

int main(){

    size_t n;
    std::cin >> n;

    std::vector<size_t> x(n);
    for(auto&& e : x){
        std::cin >> e;
    }

    auto v = x;

    std::sort(v.begin(), v.end());

    auto left = v.at(n / 2 - 1);
    auto right = v.at(n / 2);

    for(const auto& e : x){
        if(e <= left){
            std::cout << right << std::endl;
        }else{
            std::cout << left << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 5376
#include <iostream>
#include <string>
#include<vector>
int main()
{
    int n;
    std::cin >> n;

    std::vector<int> p(n);
    for (int i = 0; i < n; i++) {
        std::cin >> p[i];
    }

    int ans = 0;
    for (int i = 1; i < n - 1; i++)
    {
        if (p[i] > p[i - 1] && p[i] < p[i + 1] || p[i] < p[i - 1] && p[i] > p[i + 1])
        {
            ans++;
        }
    }

    std::cout << ans << "\n";
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

int main() {
    int H, W, h, w;
    cin >> H >> W >> h >> w;

    int s[501];
    if (H % h != 0) {
        for (int i = 0; i <= H; i++) {
            s[i] = (i % h == 0 ? 0 : 500) - i / h;
        }
        cout << "Yes" << '\n';
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << s[i + 1] - s[i] << " \n"[j == W - 1];
            }
        }
    } else if (W % w != 0) {
        for (int j = 0; j <= W; j++) {
            s[j] = (j % w == 0 ? 0 : 500) - j / w;
        }
        cout << "Yes" << '\n';
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                cout << s[j + 1] - s[j] << " \n"[j == W - 1];
            }
        }
    } else {
        cout << "No" << endl;
    }

    return 0;
}

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

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

Measured memory_bytes: 256