akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();

		String[] strAry = str.split(" ");

	    int a = Integer.parseInt(strAry[0]);
	    int b = Integer.parseInt(strAry[1]);
	    int c = Integer.parseInt(strAry[2]);
        String ans = "";

        if(a < b && b < c) {

        	ans = "Yes";

        } else {

        	ans = "No";

        }

        System.out.println(ans);

	}
}

Measured memory_bytes: 24184
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#define mid ((l + r) / 2)
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
const double pi = acos(-1.0);

const int maxn = 200 + 5;
int n, l, value[maxn], sum;

int main() {
    ios_base :: sync_with_stdio(false);
    cin >> n >> l;
    int Min = 205, ans;
    for(int i = 1; i <= n; i ++) {
        value[i] = l - 1 + i;
        if(abs(value[i]) < Min) {
            Min = abs(value[i]);
            ans = i;
        }
        sum += value[i];
    }
    cout << sum - value[ans] << endl;
    return 0;
}

Measured memory_bytes: 256
A, B = map(int,input().split())
L = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1]
ind_a = L.index(A)
ind_b = L.index(B)
if ind_a > ind_b:
  print("Alice")
elif ind_a < ind_b:
  print("Bob")
else:
  print("Draw")

Measured memory_bytes: 3060
import java.util.*;
import java.io.*;

public class Main {

    public static void main(String[] args) {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        try {
            StringTokenizer st = new StringTokenizer(in.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            if (a == b) {
                System.out.println(a+b);
            } else if (a > b) {
                System.out.println(a + a - 1);
            } else {
                System.out.println(b + b - 1);
            }
        } catch (IOException ex) {

        }
    }

}

Measured memory_bytes: 23252
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
  int n, x;
  vector<int> v;
  while(cin >> n >> x && (n || x)){
    int count = 0;
    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
        for(int k=j+1;k<=n;k++){
          int sum = i + j + k;
          if(sum == x)
            count++;
        }
      }
    }
    v.push_back(count);
  }

  for(int i=0;i<v.size();i++){
    cout << v[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 1216
#![allow(non_snake_case)]

use std::io;

fn main() {
    let sin = io::stdin();
    loop {
        let mut buf = String::new();
        sin.read_line(&mut buf).ok();
        let mut ws = buf.split_whitespace();
        let n: u32 = ws.next().unwrap().parse().unwrap();
        let x: u32 = ws.next().unwrap().parse().unwrap();

        if x == 0 && n == 0 {
            break;
        } else {
            let mut cnt = 0;
            for i in 1..n-1 {
                for j in i+1..n {
                    for k in j+1..n+1 {
                        if x == i+j+k {
                            cnt += 1;
                        }
                    }
                }
            }
            println!("{}", cnt);
        }
    }
}



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

int main(){
    ll k,n,ans;
    string s;
    cin >> k >> s;
    if(s.length() <= k){
        cout << s;
    }else{

        cout << s.substr(0,k) << "...";
    }

    return 0;
}


Measured memory_bytes: 3624
#!/usr/bin/env python3

from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    a = list(map(int, input().split()))
    ave = sum(a) / n
    ans = 0
    for i in range(n):
        ai = a[i]
        if abs(ai - ave) < abs(a[ans] - ave):
            ans = i
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 62012
using System;
using System.Linq;

class Program {
  static bool D(string s) {
    foreach (var c in s) {
      if (c == '-') return false;
    }
    return true;
  }

  static void Main() {
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int a = arr[0];
    int b = arr[1];
    var s = Console.ReadLine();
    if (D(s.Substring(0, a)) && s.Substring(a, 1) == "-" && D(s.Substring(a + 1))) {
      Console.WriteLine("Yes");
    } else {
      Console.WriteLine("No");
    }
  }
}

Measured memory_bytes: 13396
import sys
sys.setrecursionlimit(10**6)

class Edge:
	def __init__(self, v1, v2, w):
		self.v1 = v1
		self.v2 = v2
		self.w = w
	def __repr__(self):
		return 'Edges({},{},{})'.format(self.v1, self.v2, self.w)

def dfs(edges, v, visited, i, m, r):
	m[0 if i<r else 1] = min(m[0 if i<r else 1], v[i])
	for edge in edges[i]:
		if visited[edge.v2]:
			if (v[i] + v[edge.v2]) != edge.w:
				return False
			continue
		visited[edge.v2] = True
		v[edge.v2] = edge.w - v[i]
		if not dfs(edges, v, visited, edge.v2, m, r):
			return False
	return True

r, c = map(int, input().split())
edges = [list() for _ in range(r + c)]
v = [0] * (r + c)
visited = [False] * (r + c)
n = int(input())
for _ in range(n):
	ri, ci, ai = map(int, input().split())
	ri, ci = ri-1, ci-1
	edges[ri].append(Edge(ri, r+ci, ai))
	edges[r+ci].append(Edge(r+ci, ri, ai))

flag = True
for i in range(r + c):
	if visited[i]:
		continue
	m = [10**10, 10**10]
	if (not dfs(edges, v, visited, i, m, r)) or sum(m) < 0:
		flag = False
if flag:
	print('Yes')
else:
	print('No')


Measured memory_bytes: 162468
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

c11,c12,c13 = na()
c21,c22,c23 = na()
c31,c32,c33 = na()
flag = 1
for row_1 in range(c11+1):
    col_1 = c11 - row_1
    col_2 = c12 - row_1
    row_2 = c21 - col_1
    col_3 = c13 - row_1
    if row_2 + col_2 != c22 or row_2 + col_3 != c23:
        flag = 0
        break
    row_3 = c31 - col_1
    if row_3 + col_2 != c32 or row_3 + col_3 != c33:
        flag = 0
        break
if flag:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int K;
  string S, ans;
  cin >> K >> S;
  
  if(S.size() > K){
    ans = S.substr(0, K);
    ans += "...";
  }else{
    ans = S;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <limits>

using namespace std;

int main()
{
  cin.ignore(numeric_limits<streamsize>::max(), '\n');
  string t, h;
  int taro = 0, hanako = 0;
  while (cin >> t >> h) {
    if (t.compare(h) > 0)
      taro += 3;
    else if (t.compare(h) < 0)
      hanako += 3;
    else
      taro += 1, hanako += 1;
  }
  cout << taro << " " << hanako << endl;
}


Measured memory_bytes: 3168
#include<vector>
#include<iostream>
#include<fstream>
#include<string>
#include<cassert>
#include<algorithm>
#include<random>
#include<map>
#include<set>
#include <bitset>

using namespace std;

//int mod = 998244353;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int>vi;
typedef vector<ll>vl;
typedef vector<char>vc;
typedef vector<string>vs;
typedef vector<vector<int>>vvi;
typedef vector<vector<char>>vvc;
typedef vector<vector<ll>>vvl;
typedef vector< pair<ll, ll>>vpll;
typedef vector< pair<ld, ld>>vpld;
typedef vector< pair<int, int>>vpi;
typedef pair<ld, ld>pld;
#define mp make_pair
#define pb push_back

int mod=998244353;
int sum(int a, int b)
{
	int c = a + b;
	if (c >= mod)
	{
		c -= mod;
	}
	return c;
}
int dif(int a, int b)
{
	int c = a - b;
	if (c < 0)
	{
		c += mod;
	}
	return c;
}
int mlt(int a, int b)
{
	ll c = a * 1LL * b;
	return c % mod;
}
int ibit(int n, int i)
{
	return ((n >> i) & 1);
}
void outp(vvi &ou)
{
	for (int i = 0; i < ou.size(); i++)
	{
		for (int j = 0; j < ou[i].size(); j++)
		{
			cout << ou[i][j] << ' ';
		}
		cout << '\n';
	}
}

void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n;
	//cin >> n;
	string s;
	cin >> s;
	n = s.length() + 1;
	vector<int>lb(n), rb(n);
	lb[0] = 0;
	for (int i = 0; i < n - 1; i++)
	{
		if (s[i] == '<')
		{
			lb[i + 1] = lb[i] + 1;
		}
		else
		{
			lb[i + 1] = 0;
		}
	}
	s[n - 1] = 0;
	for (int i = n-2; i >=0; i--)
	{
		if (s[i] == '>')
		{
			rb[i] = rb[i+1] + 1;
		}
		else
		{
			rb[i] = 0;
		}
	}
	ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		ans += max(lb[i], rb[i]);
	}
	cout << ans << endl;
}
int main()
{
	solve();
	int n;
	cin >> n;
}

Measured memory_bytes: 4740
let solve m a r c h =
    m * a * r
    + m * a * c
    + m * a * h
    + m * r * c
    + m * r * h
    + m * c * h
    + a * r * c
    + a * r * h
    + a * c * h
    + r * c * h

let rec get_input_aux n m a r c h =
    if n = 0 then solve m a r c h
    else
        match (read_line ()).[0] with
        | 'M' -> get_input_aux (n - 1) (m + 1) a r c h
        | 'A' -> get_input_aux (n - 1) m (a + 1) r c h
        | 'R' -> get_input_aux (n - 1) m a (r + 1) c h
        | 'C' -> get_input_aux (n - 1) m a r (c + 1) h
        | 'H' -> get_input_aux (n - 1) m a r c (h + 1)
        |  _  -> get_input_aux (n - 1) m a r c h

let get_input n = get_input_aux n 0 0 0 0 0

let () =
    let n = read_int () in
    get_input n
    |> string_of_int
    |> print_endline


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

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException{
        try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String s;
            while (!"0 0".equals(s = br.readLine())) {
                int[] arr = Arrays.stream(s.split(" ")).mapToInt(Integer::parseInt).toArray();
                int a = arr[0];
                int b = arr[1];

                if (a > b) {
                    int tmp = b;
                    b = a;
                    a = tmp;
                }

                System.out.printf("%d %d%n", a, b);
            }
        }
    }
}



Measured memory_bytes: 38568
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

class WeightedUnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.weight = [0] * (n+1)


    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    def union(self, x, y, w=1):
        rx = self.find(x)
        ry = self.find(y)
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def diff(self, x, y):
        return self.weight[x] - self.weight[y]


n,m=map(int,input().split())
lrd=[list(map(int,input().split())) for i in range(m)]

uf=WeightedUnionFind(n)
for i in range(m):
    l,r,d=lrd[i]
    uf.union(l,r,d)
    # print(uf.par)
    # print(uf.weight)

for i in range(m):
    l,r,d=lrd[i]
    if not uf.same(l,r):
        print("No")
        break
    if uf.diff(l,r)!=d:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 134108
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
 int n,m;
 cin>>n>>m;
 V<ll> a(n);
 for(int i=0;i<m;i++)cin>>a[i];
 sort(all(a));
 ll ma=a[n-1];
 ll sum=0;
 for(int i=0;i<n-1;i++)sum+=a[i];
 cout<<max(ma-sum-1,0ll)<<endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << x << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n){
        cin >> a[i];
    }
    ll ans = 0;
    ans += a[0]-1;
    ll hoge = 2;
    int pos = 1;
    while(pos < n){
        if(a[pos] < hoge){
            pos++;
        }else if(a[pos] == hoge){
            hoge++;
            pos++;
        }else if(a[pos] > hoge){
            ans += (a[pos]-1)/hoge;
            pos++;
        }
    }
    cout << ans << endl;
}

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

#define M 1000003
long long array[M];

long long ctol(char c) {
  if (c == 'A') {
    return 1LL;
  } else if (c == 'C') {
    return 2LL;
  } else if (c == 'G') {
    return 3LL;
  } else if (c == 'T') {
    return 4LL;
  } else {
    return -1LL;
  }
}

long long getKey(string s) {
  long long key = 0;
  for (int i = 0; i < s.size(); i++) {
    key *= 10LL;
    key += ctol(s[i]);
  }
  return key;
}

int hash1(long long key) {
  return (int)(key % M);
}

int hash2(long long key) {
  return (int)(1 + key % (M-1));
}

int myHash(long long key, int i) {
  return (hash1(key) + i*hash2(key)) % M;
}

void insert(string s) {
  long long key = getKey(s);
  int h;
  for (int i = 0; i < M; i++) {
    h = myHash(key, i);
    if (array[h] == -1) {
      array[h] = key; 
      break;
    }
  }
}

bool find(string s) {
  long long key = getKey(s);
  int h;
  for (int i = 0; i < M; i++) {
    h = myHash(key, i);
    if (array[h] == key) {
      return true;
    } else if (array[h] == -1) {
      return false;
    }
  }
  return false;
}

int main() {
  for (int i = 0; i < M; i++) array[i] = -1;
  int n; cin >> n;
  string q, s;
  for (int i = 0; i < n; i++) {
    cin >> q >> s;
    if (q == "insert") {
      insert(s);
    } else if (q == "find") {
      cout << (find(s) ? "yes" : "no") << endl;
    }
  } 
}




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


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

    int cnt = 0;
    for (int i=0; i<N; ++i) {
        for (int j=0; j<N; ++j) {
            if (4*i + 7*j == N) cnt++;
        }
    }

    if (cnt) cout << "Yes" << endl;
    else cout << "No" << endl;
}




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

int main(){
	int n;
	long int sum = 0;
	cin >> n ;
	int* a = new int[n];
	for(int i = 0; i < n ; i++){
		cin >> a[i];
		sum +=a[i];

	}
	sort(a,a + n);
	cout << a[0] << " " << a[ n - 1] << " " << sum << endl;

	
	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
const long long MOD =1000000000+7;

int main()
{
	int n;
		cin >>n;
	int sum=0;

	int bef=n;
	while(bef >0){
		sum+=bef%10;
		bef/=10;
	}
	


	cout <<((n%sum==0)?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    
    int n;
    cin >> n;
    if (n%2==0)
    {
    	cout << "0.5" << endl;
    }
    else
    {
    	cout << (float)(n+1)/(2*n) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

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 PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).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);

#define CLR(a) memset((a), 0 ,sizeof(a))

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string str;
	int a, b, c, d, s;
	
	cin >> str;
	
	a = (int)(str[0]-'0');
	b = (int)(str[1]-'0');
	c = (int)(str[2]-'0');
	d = (int)(str[3]-'0');
	
	if (a+b+c+d == 7)
		cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
	else if (a+b+c-d == 7)
		cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
	else if (a+b-c+d == 7)
		cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
	else if (a+b-c-d == 7)
		cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
	else if (a-b+c+d == 7)
		cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
	else if (a-b+c-d == 7)
		cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
	else if (a-b-c+d == 7)
		cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
	else if (a-b-c-d == 7)
		cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
	
	return 0;
}


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

int n;
double xa, ya, xb, yb, xc, yc, xd, yd, d1, d2;

int main() {
	scanf("%d",&n);
	rep(i,n) {
		scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd);
		if (xa==xb) d1 = 1e200;
		else d1 = (yb-ya)/(xb-xa);
		if (xc==xd) d2 = 1e200;
		else d2 = (yd-yc)/(xd-xc);
		if (abs(d1-d2)<1e-10) printf("YES\n");
		else printf("NO\n");
	}
}


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };


int main(){cout<<fixed<<setprecision(10);
          string a,b;
           cin>>a>>b;
           bool aok=false;
           if(a.size()>b.size())aok=true;
           else if(a.size()==b.size()){
             if(a==b){
              cout<<"EQUAL"<<endl;
               return 0;
             }
            aok=(a>b); 
           }
           if(aok){
             cout<<"GREATER"<<endl;
           }
           else cout<<"LESS"<<endl;
}

Measured memory_bytes: 3628
N = int(input())
A = [int(_) for _ in input().split()]

for i in range(N):
    A[i] -= i + 1

A.sort()

import math

if N % 2 == 1:
    a = A[N // 2]
else:
    a = (A[(N // 2) - 1]+ A[(N // 2)]) // 2

# a1 = math.ceil(sum(A) / N)
# a2 = math.floor(sum(A) / N)

ans = sum([abs(x - a) for x in A])
print(ans)

Measured memory_bytes: 26356
import sys,math
input=sys.stdin.readline
n=int(input())
s=input()
mod=998244353
r=0
g=0
b=0
rg=0
gb=0
br=0
ans=1
for i in range(3*n):
    if s[i]=="R":
        if gb:
            ans*=gb
            gb-=1
        elif g:
            ans*=g
            g-=1
            rg+=1
        elif b:
            ans*=b
            b-=1
            br+=1
        else:
            r+=1

    if s[i]=="G":
        if br:
            ans*=br
            br-=1
        elif r:
            ans*=r
            r-=1
            rg+=1
        elif b:
            ans*=b
            b-=1
            gb+=1
        else:
            g+=1
    if s[i]=="B":
        if rg:
            ans*=rg
            rg-=1
        elif g:
            ans*=g
            g-=1
            gb+=1
        elif r:
            ans*=r
            r-=1
            br+=1
        else:
            b+=1
    ans%=mod

k=math.factorial(n)
print(ans*k%mod)


Measured memory_bytes: 52444
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  string s,t;
  cin >> s >> t;
  int ans = 0;
  rep(i,3){
    if(s[i] == t[i]) ans++;
  }
   cout << ans << endl;
}

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

using namespace std;
#define ll long long


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int r;
    cin >> r;
    cout << fixed << setprecision(3) << (long double) acos(-1) * 2 * r << endl;
    return 0;
}

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

int main(){
    long long N, K, Q;
    cin >> N >> K >> Q;

    long long A[Q];
    for(int i=0; i<Q; i++){
        cin >> A[i];
    }

    vector<long long> Point(N, 0);
    
    for(int i=0; i<Q; i++){
        Point[A[i]-1] += 1;
    }

    for(int j=0; j<N; j++){
        if(Q - Point[j] < K){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }

    return 0;
}

Measured memory_bytes: 4776
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
const ll INF=1000000010;
const ll MOD=1000000007;
const ll LINF=1000000000000000000;
int xx[110],yy[110],hh[110];
int main(){
	int n;cin>>n;
	for(int i=0;i<n;i++)cin>>xx[i]>>yy[i]>>hh[i];
	for(int y=0;y<=100;y++){
		for(int x=0;x<=100;x++){
			int h=-1;
			bool f=true;
			for(int i=0;i<n;i++){
				if(hh[i]>0){
					if(h!=-1){
						if(abs(x-xx[i])+abs(y-yy[i])+hh[i]!=h){
							f=false;
							break;
						}
					}else{
						h=abs(x-xx[i])+abs(y-yy[i])+hh[i];
					}
				}else{
					if(h!=-1){
						if(h-abs(x-xx[i])-abs(y-yy[i])>0){
							f=false;
							break;
						}
					}
				}
			}
			if(!f)continue;
			for(int i=0;i<n;i++){
				if(hh[i]>0){
						if(abs(x-xx[i])+abs(y-yy[i])+hh[i]!=h){
							f=false;
							break;
						}
				}else{
						if(h-abs(x-xx[i])-abs(y-yy[i])>0){
							f=false;
							break;
						}
				}
			}
			if(f){
				if(h<1)continue;
				cout<<x<<" "<<y<<" "<<h<<endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    string s;
    cin>>n>>s;
    int a[26]={0};
    for(int i=0;i<n;i++){
    	a[s[i]-'a']++;
    }
    ll ans=1;
    for(int i=0;i<26;i++){
    	//cout << a[i]<<endl;
    	ans*=(a[i]+1);
    	ans%=mod;
    }
    cout << ans-1<<endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int H, A;
    cin >> H >> A;

    cout << (H + A - 1) / A << endl;
    return 0;
}

Measured memory_bytes: 3568
n, k = [int(i) for i in input().split()]
def decNbin(t, n):
  a = []
  while t!= 0:
    a.append(t % n)
    t  = t // n
  a.reverse()
  return a
print(len(str("".join(map(str, decNbin(n, k))))))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; cin >> n;
    ll a[3*n];
    rep(i, 3*n) cin >> a[i];
    ll left[2*n], right[2*n];
    priority_queue<ll> back;
    priority_queue<ll, vector<ll>, greater<ll>> front;
    ll sum = accumulate(a, a+n, 0LL);
    left[n-1] = sum;    
    rep(i, n) front.push(a[i]);
    FOR(i, n, 2*n){
        front.push(a[i]);
        sum += a[i];
        sum -= front.top();
        front.pop();
        left[i] = sum;
    }
    sum = accumulate(a+2*n, a+3*n, 0LL);
    right[2*n-1] = sum;
    FOR(i, 2*n, 3*n) back.push(a[i]);
    for(int i = 2*n-1; i >= n; i--){
        back.push(a[i]);
        sum += a[i];
        sum -= back.top();
        back.pop();
        right[i-1] = sum;
    }
    ll ans = -1e18;
    FOR(i, n-1, 2*n){
        ll tmp = left[i] - right[i];
        ans = max(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 5876
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int i,j,k;
		int point = N-1;
		String w,w2;
		StringBuilder sb = new StringBuilder();
		for(i = 0;i < N;i++){
			sb.append("a");
		}
		w = sb.toString();
		System.out.println(w);
		for(i = 0;i < N-1;i++){
			w2 = w.substring(0,point);
			w2 += "b";
			Addabc(N,w2);
			point--;
		}
	}
	public static void Addabc(int max,String w2){
		char buf = 'a';
		String buf2 = "a";
		if(w2.length() == max){
			System.out.println(w2);
		}else{
			int i = 0;
			while(w2.contains(buf2)){
				buf += i;
				buf2 = String.valueOf(buf);
				w2 += buf2;
				Addabc(max,w2);
				i = 1;
				w2 = w2.substring(0,(w2.length()) - 1);
			}
		}
	}
}


Measured memory_bytes: 45508
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char> cvec;
typedef vector<double> dvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
#define fs first
#define sc second
int main()	{
  int n;
  cin>>n;
  map<string,int>mp;
  int mx=0;
  vector<string> s(n);
  rep(i,n){
    cin>>s[i];
    mp[s[i]]++;
    mx=max(mx,mp[s[i]]);
  }
  for(auto dic:mp){
    if(dic.sc==mx)
      cout<<dic.fs<<endl;
  }
}

Measured memory_bytes: 26752
import qualified Data.Map as MP
import Data.Maybe
import Data.List

primeFactor :: MP.Map Int Int -> Int -> MP.Map Int Int
primeFactor m n = loop n 2 m
    where
        loop :: Int -> Int -> MP.Map Int Int ->  MP.Map Int Int
        loop n i m
            | n `rem` i == 0 = inner n i m
            | i * i > n = if n /= 1 
                then search n m
                else m 
            | otherwise = loop n (i+1) m
        
        inner ::  Int -> Int -> MP.Map Int Int -> MP.Map Int Int
        inner n i m
            | n `rem` i == 0 = let m' = search i m in inner (n `quot` i) i m'
            | otherwise = loop n (i+1) m
        
        search :: Int -> MP.Map Int Int -> MP.Map Int Int 
        search k m = case MP.lookup k m of
            Just _ -> MP.adjust (+1) k m
            Nothing -> MP.insert k 1 m

solve :: Int -> Int
solve n = loop m
    where
        m = foldl' primeFactor MP.empty [2..n] 
        mulMod a b = (a * b) `rem` (10^9+7)
        loop :: MP.Map Int Int -> Int
        loop m 
            | MP.null m = 1
            | otherwise =
                let 
                    ((_, v), m') = MP.deleteFindMin m
                in
                    mulMod (v+1) $ loop m'

main = do
    n <- readLn :: IO Int
    print $ if n == 1 then 1 else solve n


Measured memory_bytes: 1020
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque, defaultdict
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np    # cumsum
# from bisect import bisect_left, bisect_right

def solve():
    S = LS()
    d = defaultdict(lambda: 0)
    # print(len(S))
    for s in S:
        d[s] += 1
    # print(d)
    ans = INF
    for c, n in d.items():
        cnt = 0
        mx = 0
        for s in S:
            if c == s:
                mx = max(mx, cnt)
                cnt = 0
                continue
            cnt += 1
        mx = max(mx, cnt)
        # print(c, mx)
        ans = min(ans, mx)
    print(ans)

if __name__ == '__main__':
    solve()


Measured memory_bytes: 9316
import java.util.Scanner;

public class Main {
	private static int N;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			N = sc.nextInt();
			String M = sc.next();
			if (N == 0) {
				sc.close();
				break;
			}

			String log = DFS(M, 0, "");
			int ans = Integer.parseInt(log.split(" ")[0]);
			if (ans == -1) {
				System.out.println("error");
				continue;
			}

			String[] pieces = log.split(" ")[1].split(",");
			int testsum = 0;
			for (int i = 0; i < pieces.length; i++) {
				if (!pieces[i].equals("")) {
					testsum += Integer.parseInt(pieces[i]);
				}
			}
			if (testsum > ans) {
				System.out.println("rejected");
				continue;
			}

			System.out.print(ans);
			for (int i = 0; i < pieces.length; i++) {
				if (!pieces[i].equals("")) {
					System.out.print(" " + pieces[i]);
				}
			}
			System.out.println();

		}

	}

	static String DFS(String rest, int sum, String log) {
		int ans = -1;
		String logger = "";
		for (int i = 1; i <= rest.length(); i++) {
			int p = Integer.parseInt(rest.substring(0, i));
			if (i == rest.length()) {
				if (sum + p <= N) {
					if (sum + p > ans) {
						ans = sum + p;
						logger = log + "," + rest.substring(0, i);
					} else if (sum + p == ans) {
						logger = logger + "," + log + ","
								+ rest.substring(0, i);
					}
				}
			} else if (sum + p <= N) {
				String t = DFS(rest.substring(i), sum + p,
						log + "," + rest.substring(0, i));
				int tmp = Integer.parseInt(t.split(" ")[0]);
				if (tmp <= N && tmp > 0) {
					if (ans < tmp) {
						ans = tmp;
						logger = t.split(" ")[1];
					} else if (ans == tmp) {
						logger = logger + "," + t.split(" ")[1];
					}
				}
			}

		}

		return String.valueOf(ans) + " " + logger;

	}
}

Measured memory_bytes: 21616
/*
  mail: mleautomaton@foxmail.com
  author: MLEAutoMaton
  This Code is made by MLEAutoMaton
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
char s[12];
int main()
{
	scanf("%s",s+1);
	int n=strlen(s+1);
	int last=0,ans=0;
	for(int i=1;i<=n;i++)
	{
		if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){++last;ans=max(ans,last);}
		else last=0;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
/*
   AtCoder Submission
*/

#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

/* typedefs */
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<string,int> si;
typedef pair<int,ii> iii;
typedef vector <si> vsi;
typedef vector <ii> vii;
typedef vector <int> vi;
typedef vector <char> vc;
typedef vector <string> vs;
typedef map <string,vs> msvs;
typedef map <string,int> msi;
typedef map <string,string> mss;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N;
    cin >> N;
    
    unsigned long long a_i;
    ll sol = 0;

    for(int j = 0; j < N; j++){
        cin >> a_i;
        for(int i = 1; i <= 32; i++){
            if(a_i % (int)pow(2, i) != 0){
                sol += i - 1;
                break;
            }
        }
    }

    cout << sol << endl;

    return 0;
}


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

int main() {
  int T,D,tA,tB,dA,dB;
  scanf("%d %d %d %d %d %d",&T,&D,&tA,&tB,&dA,&dB);
  double dTemp = 999999999999.9;
  for(int i = 0; i < 10000; i++) {
    for(int j = 0; j < 10000; j++) {
      if(i == 0 && j == 0) continue;
      if(dA * i + dB * j > D) break;
      int vA = dA * i;
      int vB = dB * j;
      dTemp = min(fabs(T - ((double)tA * vA + (double)tB * vB) / (double)(vA + vB)),dTemp);
    }
  }
  printf("%.20f\n",dTemp);
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;





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


    ll n; cin>>n;

    vector<int> v;
    int res = 0;


    for (ll i=2; i*i<=n; i++) {
	if (n%i==0) {
	    int x=0;
	    while (n%i==0) {
		x++;
		n=n/i;
	    }
	    v.push_back(x);
	}
    }
    if (n>1) v.push_back(1);


    for (int x: v) {
	int i=1;
	int cur=0;
	while (1) {
	    x-=i;
	    if (x<0) break;
	    i++;
	    cur++;
	}
	res+=cur;
    }

    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3648
//https://atcoder.jp/contests/agc039/tasks/agc039_a
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
int main() {
#if LOCAL&01
    //std::ifstream in("./test/sample-1.in"); //input.txt
    std::ifstream in("./input.txt"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
//    cin.tie(0);
//    ios::sync_with_stdio(false);
#endif
    string S; cin>>S;
    ll T; cin>>T;
    //先頭
    ll hlen=1;
    char hch=S[0];
    char fch=S.back();

    auto check_all_same = [&]{
        char c = S.at(0);
        FOR(i,1,S.size()){
            if(c!=S.at(i)){
                return false;
            }
        }
        return true;
    };
    auto get_num = [&](ll st, ll ed){
        ll ret=0;
        ll sc=1;
        char c = S.at(st);
        FOR(i,st+1,ed+1){
            if(c==S.at(i)){
                ++sc;
            } else {
                ret += (sc/2);
                sc = 1;
            }
            c=S.at(i);
        }
        ret += (sc/2);
        return ret;
    };
    auto get_head = [](const string& str){
        ll ret = 1;
        char c=str.at(0);
        FOR(i,1,str.size()) {
            if (str.at(i)==c){
                ++ret;
            }else{
                break;
            }
        }
        return ret;
    };
    ll ans = 0;
    ll tmp=get_num(0,S.size()-1);
    if (check_all_same()){
        //全部同じ
        dump("same");
        ans = S.size() * T / 2;
    } else if (hch==fch){
        ll hnum = get_head(S);
        auto Sr=S; std::reverse(Sr.begin(),Sr.end());
        ll fnum = get_head(Sr);
        auto aida = get_num(hnum,S.size()-fnum-1);
        ans= hnum / 2 + fnum / 2 + aida * T + ((hnum+fnum)/2) * (T-1);        
    } else {
        ans=tmp * T;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <queue>
#include <vector>
#include <map>
using namespace std;
map<unsigned long long,int>M;
const unsigned long long key=1e9+7,N=260000;
unsigned long long invkey;
char ch[N+10];
int n;
unsigned long long quick(unsigned long long k1,unsigned long long k2){
	unsigned long long k3=1;
	while (k2){
		if (k2&1) k3*=k1;
		k1*=k1; k2>>=1;
	}
	return k3;
}
unsigned long long mul=0,add=0;
unsigned long long getall(){
	unsigned long long k1=1,ans=0;
	for (int i=1;i<=n;i++)
		if (ch[i]=='+') ans+=k1;
		else if (ch[i]=='-') ans-=k1;
		else if (ch[i]=='>') k1*=key;
		else k1*=invkey;
	return ans;
}
unsigned long long getb(unsigned long long ke,unsigned long long a,unsigned long long b){
	return (ke-b)*quick(a,(1ull<<63)-1);
}
int main(){
	scanf("%d",&n);
	scanf("%s",ch+1);
	invkey=quick(key,(1ull<<63)-1);
	unsigned long long ke=getall();
	unsigned long long a=1,b=0;
	long long ans=0;
	for (int i=n;i;i--){
		ans+=M[getb(ke,a,b)];
		M[getb(0,a,b)]++;
		if (ch[i]=='+') b++;
		else if (ch[i]=='-') b--;
		else if (ch[i]=='>') b*=key,a*=key;
		else if (ch[i]=='<') b*=invkey,a*=invkey;
	}
	ans+=M[getb(ke,a,b)];
	cout<<ans<<endl;
}

Measured memory_bytes: 31744
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            map.put(i + 1, a[i]);
        }

        long sum = 0;
        for (int i = 1; i <= n; i++) {
            int k = map.get(i);
            if (!map.containsKey(k)) {
                continue;
            }
            if (i == map.get(k)) {
                sum++;
            }
        }
        System.out.println(sum / 2);
    }

}


Measured memory_bytes: 65288
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

n = readi()
a = readl()
b = readl()
c = readl()

index = -99
count = 0
for i in range(n):
    t = a[i] - 1
    count += b[t]
    if index + 1 == t:
        count += c[index]
    index = t
print(count)

Measured memory_bytes: 6864
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,s;

long long lcm(long long x,long long y){
	return x*y/__gcd(x,y);
}

int main(){
	cin>>a>>b>>c>>d;
	s=b/c-(a-1)/c+b/d-(a-1)/d-b/lcm(c,d)+(a-1)/lcm(c,d);
	s=b-a+1-s;
	cout<<s;
	
	return 0;
}

Measured memory_bytes: 256
// 5/28
// 過去問ガリガリ
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

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

    vector<int> A(N);
    rep(i, N) cin >> A[i];

    int K = 0;
    rep(i, N) {
        if (A[i] == K + 1) K++;;
        
    }

    if (K == 0) cout << -1 << endl;
    else cout << N - K << endl;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
const int N = 200010, MP = 20;
int n,stx,sty;
struct edge {
  int la,b;
};
struct tree {
  edge con[N << 1];
  int tot,fir[N];
  void add(int from,int to) {
    con[++tot] = (edge) {fir[from],to};
    fir[from] = tot;
  }
  int dep[N],anc[N][MP];
  void dfs(int pos,int fa) {
    dep[pos] = dep[fa] + 1;
    anc[pos][0] = fa;
    for (int i = 1 ; i < MP ; ++ i) {
      anc[pos][i] = anc[anc[pos][i-1]][i-1];
      if (!anc[pos][i]) break;
    }
    for (int i = fir[pos] ; i ; i = con[i].la) {
      if (con[i].b == fa) continue;
      dfs(con[i].b,pos);
    }
  }
  int lca(int x,int y) {
    if (dep[x] < dep[y]) swap(x,y);
    for (int i = MP - 1 ; i >= 0 ; -- i)
      if (dep[anc[x][i]] >= dep[y])
	x = anc[x][i];
    if (x == y) return x;
    for (int i = MP - 1 ; i >= 0 ; -- i)
      if (anc[x][i] != anc[y][i])
	x = anc[x][i], y = anc[y][i];
    return anc[x][0];
  }
  int askdis(int x,int y) {
    int z = lca(x,y);
    return dep[x] + dep[y] - 2 * dep[z];
  }
  void fsd(int pos,int fa,int dep);
} rd,blu;
int ans;
void tree::fsd(int pos,int fa,int dep) {
  if (ans != -1) ans = max(ans,blu.askdis(pos,sty) * 2);
  if (dep >= blu.askdis(pos,sty))
    return;
  for (int i = fir[pos] ; i ; i = con[i].la) {
    if (con[i].b == fa) continue;
    if (blu.askdis(pos,con[i].b) >= 3) {
      ans = -1;
      return;
    }
    fsd(con[i].b,pos,dep+1);
  }
}
int main() {
  int x,y;
  scanf("%d%d%d",&n,&stx,&sty);
  for (int i = 1 ; i < n ; ++ i) {
    scanf("%d%d",&x,&y);
    rd.add(x,y);
    rd.add(y,x);
  }
  for (int i = 1 ; i < n ; ++ i) {
    scanf("%d%d",&x,&y);
    blu.add(x,y);
    blu.add(y,x);
  }
  blu.dfs(1,0);
  rd.fsd(stx,0,0);
  printf("%d\n",ans);
  return 0;
}


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

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

use std::cmp::min;

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

    if k % 2 == 0 {
        println!("{}", (k / 2) * (k / 2));
    } else {
        println!("{}", (k / 2) * (k / 2 + 1));
    }
}


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

void main_()
{
    int N;
    cin >> N;
    vector<int> Bs;
    copy_n(istream_iterator<int>(cin), N - 1, back_inserter(Bs));
    vector<int> As;
    As.push_back(Bs.front());
    transform(
        begin(Bs), end(Bs) - 1,
        begin(Bs) + 1, back_inserter(As),
        [](int n1, int n2) { return min(n1, n2); });
    As.push_back(Bs.back());

    cout << accumulate(begin(As), end(As), 0) << endl;
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <typeinfo>
#include <functional>
#include <iomanip>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;
typedef long long ll;


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

	bool r = true;
	if (S.size() % 2 != 0)
	{
		r = false;
	}

	for (int i = 0; i < S.size(); i++)
	{
		if (i % 2 == 0)
		{
			if (S.at(i) != 'h')
			{
				r = false;
			}
		}
		else
		{
			if (S.at(i) != 'i')
			{
				r = false;
			}
		}
	}

	if (r)
	{
		cout << "Yes" << endl;
	
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  int keep = 1;
  for(int i=1;i<=n;++i){
    int tmp;cin>>tmp;
    if(keep==tmp){
      keep++;
    }
  }
  if(keep==1){
    cout<<-1<<endl;
  }else{
    cout<<1+n-keep<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
def answer(n: int, s: str, t: str) -> str:
    new_str = ''
    for i in range(n):
        new_str += f'{s[i]}{t[i]}'

    return new_str


def main():
    n = int(input())
    s, t = input().split()
    print(answer(n, s, t))


if __name__ == '__main__':
    main()


Measured memory_bytes: 9060
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string n;
    cin>>n;
    bool f=0;
    long long s=0 , a ;
    for (int i=0 ; i<n.size() ; ++i)
    {
        if (n[i]=='A'&&f==0)
        {
            f=1;
        }
        if (f==1)
        {
            s+=1;
            if (n[i]=='Z')
            {
                a=s;
            }
        }
    }
    cout<<a<<endl;
}


Measured memory_bytes: 3740
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};

// vector<int> par(0),depth(0),siz(0);
// void init(int n){
//     par.resize(n);
//     depth.resize(n,0);
//     siz.resize(n,1);
//     rep(i,n) par[i]=i;
// }
// int find(int n){
//     if(par[n]==n) return n;
//     return par[n]=find(par[n]);
// }
// void unite(int x,int y){
//     x=find(x);
//     y=find(y);
//     if(par[x]==par[y]) return;
//     siz[x]+=siz[y];
//     siz[y]=siz[x];
//     if(depth[x]<depth[y]) par[x]=par[y];
//     else{
//         par[y]=par[x];
//         if(depth[x]==depth[y]) depth[x] ++;
//     }
// }
// bool same(int x,int y){
//     return find(x)==find(y);
// }
// int size(int x){
//     return siz[find(x)];
// }

struct union_find{
    vector<int> par;
    vector<int> depth;
    vector<int> siz;

    union_find(int n) : par(n) , depth(n,0) , siz(n,1){
        rep(i,n) par[i]=i;
    }

    int find(int x){
        if(par[x]==x) return x;
        return par[x]=find(par[x]);
    }

    void unite(int x,int y){
        x=find(x);
        y=find(y);
        if(x==y) return;
        siz[x] +=siz[y];
        siz[y] =siz[x];
        if(depth[x]<depth[y]) par[x]=par[y];
        else{
            par[y]=par[x];
            if(depth[x]==depth[y]) depth[x] ++;
        }
    }

    bool same(int x,int y){
        return find(x)==find(y);
    }
    int size(int x){
        return siz[find(x)];
    }
};

int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    int n,m;
    cin>>n>>m;
    int x,y,z;
    union_find uf(n);
    rep(i,m){
        cin>>x>>y>>z;
        x --,y --;
        uf.unite(x,y);
    }
    rep(i,n) uf.find(i);
    map<int,int> a;
    int cnt=0;
    rep(i,n){
        if(a[uf.par[i]]==1) continue;
        a[uf.par[i]]=1;
        cnt ++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 6144