akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>

const int maxn = 1e4 + 5;
const int inf = 0x3f3f3f3f;

struct edge {
    int to, cap, cost, rev;
};
int n, m, res, f, N, k;
vector<edge> g[maxn];
int h[maxn], dis[maxn], prevv[maxn], preve[maxn], vis[maxn];

inline void add_edge(int from, int to, int cap, int cost) {
    // printf("%d %d %d %d\n", from, to, cap, cost);
    g[from].emplace_back(edge{to, cap, cost, (int)g[to].size()});
    g[to].emplace_back(edge{from, 0, -cost, (int)g[from].size() - 1});
}

void min_cost_flow(int s, int t, int F) {
    fill(h, h + N, 0);
    while (f < F) {
        queue<int> que;
        fill(dis, dis + N, inf);
        memset(vis, 0, sizeof(vis));
        dis[s] = 0;
        que.push(s);
        while (!que.empty()) {
            int v = que.front();
            que.pop();
            vis[v] = 0;
            for (int i = 0; i < (int)g[v].size(); i++) {
                edge &e = g[v][i];
                if (e.cap > 0 && dis[e.to] > dis[v] + e.cost + h[v] - h[e.to]) {
                    dis[e.to] = dis[v] + e.cost + h[v] - h[e.to];
                    prevv[e.to] = v;
                    preve[e.to] = i;
                    if (!vis[e.to]) {
                        que.push(e.to);
                        vis[e.to] = 1;
                    }
                }
            }
        }
        if (dis[t] == inf) break;
        for (int i = 0; i < N; i++) h[i] += dis[i];
        int d = F - f;
        for (int v = t; v != s; v = prevv[v])
            d = min(d, g[prevv[v]][preve[v]].cap);
        f += d;
        res += d * h[t];
        for (int v = t; v != s; v = prevv[v]) {
            edge &e = g[prevv[v]][preve[v]];
            e.cap -= d;
            g[v][e.rev].cap += d;
        }
    }
}

int val[maxn], a[maxn], pos[maxn];

inline int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (!isdigit(ch)) {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
    return f * x;
}

int main() {
    scanf("%d %d %d", &m, &n, &k);
    for (int i = 1; i <= n; i++) val[i] = read();
    for (int i = 1; i <= k; i++) a[i] = read();
    if (m == 1) {
        for (int i = 1; i <= k; i++) {
            if (a[i] != a[i - 1]) res += val[a[i]];
        }
        printf("%d\n", res);
        return 0;
    }
    N = k + 2;
    add_edge(0, 1, m - 1, 0);
    add_edge(k, N - 1, m - 1, 0);
    for (int i = 1; i <= k; i++) {
        if (i < k) add_edge(i, i + 1, inf, 0);
        if (pos[a[i]]) {
            if(pos[a[i]] < i - 1) add_edge(pos[a[i]], i - 1, 1, -val[a[i]]);
            else res -= val[a[i]];
        }
        pos[a[i]] = i;
        res += val[a[i]];
    }
    min_cost_flow(0, N - 1, m - 1);
    printf("%d\n", res);
}


Measured memory_bytes: 4580
#include <bits/stdc++.h>
using namespace std;
#define sci1(a) scanf("%d",&a)
#define sci2(a,b) scanf("%d %d",&a,&b)
#define sci3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define scs(s) scanf("%s",s)
#ifndef GET_MACRO

#define GET_MACRO(__1,__2,__3,NAME,...) NAME

#endif // GET_MACRO
#define ll long long
#define sci(...) GET_MACRO(__VA_ARGS__,sci3,sci2,sci1)(__VA_ARGS__)
#define LSB(i) ((i)&(-i))
#define mp(a,b) make_pair(a,b)
#define bit_set0(m,i) (m&(~(1<<i)))
int ans[200000],bl[200000],data[200000];
void DFS(vector<vector<int> >&g,int node,int prv){
    if(bl[node]==1)return;
    int i;
    prv+=data[node];
    ans[node]=prv;
    bl[node]=1;
    for(i=0;i<g[node].size();i++){
        DFS(g,g[node][i],prv);
    }
    return;
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    vector<vector<int> >g;
    int n,q,i,j,u,v,p,x;
    sci(n,q);
    g.resize(n);
    for(i=1;i<n;i++){
        sci(u,v);
        u--;
        v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    memset(data,0,sizeof(data));
    for(i=0;i<q;i++){
        sci(p,x);
        data[p-1]+=x;
    }
    memset(bl,0,sizeof(bl));
    DFS(g,0,0);
    for(i=0;i<n;i++){
        printf("%d ",ans[i]);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 25088
from math import sqrt

n = int(input())
x = [int(arg) for arg in input().split()]
y = [int(arg) for arg in input().split()]

p_1 = sum([abs(x[i]-y[i]) for i in range(n)])
p_2 = sqrt(sum([abs(x[i]-y[i])**2 for i in range(n)]))
p_3 = pow(sum([abs(x[i]-y[i])**3 for i in range(n)]), 1.0/3.0)
p_inf = max([abs(x[i]-y[i]) for i in range(n)])
print(p_1)
print(p_2)
print(p_3)
print(p_inf)



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

void solve() {
  int64 H, W;
  cin >> H >> W;
  vector<string> f(H);
  REP(i, H) {
    cin >> f[i];
    REP(j, W) {
      if (f[i][j] != '.') {
        f[i][j] -= 'A';
      }
    }
  }
  vector<pair<PII, PII>> mp(26, make_pair(PII(INF, INF), PII(-INF, -INF)));
  REP(i, H) {
    REP(j, W) {
      if (f[i][j] != '.') {
        PLL lu, rd;
        tie(lu, rd) = mp[f[i][j]];
        lu = PII(min(lu.fs, i), min(lu.sc, j));
        rd = PII(max(rd.fs, i), max(rd.sc, j));
        mp[f[i][j]] = make_pair(lu, rd);
      }
    }
  }
  vector<int64> in(26, 0);
  vector<int64> G[26];
  REP(c, 26) {
    PII lu, rd;
    tie(lu, rd) = mp[c];
//    cout << x.fs << " (" << lu.fs << " " << lu.sc << ") (" << rd.fs << " " << rd.sc << ") " << endl;
    FOR(i, lu.fs, rd.fs+1) {
      FOR(j, lu.sc, rd.sc+1) {
        if (c != f[i][j]) {
          if (f[i][j] == '.') {
            cout << "SUSPICIOUS" << endl;
            return;
          } else {
            G[f[i][j]].push_back(c);
            in[c]++;
          }
        }
      }
    }
  }
  queue<int> fr;
  REP(i, 26) if (in[i]==0) fr.push(i);
  int64 rest = 26-fr.size();
  while (fr.size()) {
    int v = fr.front(); fr.pop();
    for (auto& u : G[v]) {
      in[u]--;
      if (in[u] == 0) {
        fr.push(u);
        rest--;
      }
    }
  }
  if (rest == 0) {
    cout << "SAFE" << endl;
  } else {
    cout << "SUSPICIOUS" << endl;
  }
}

int main(void) {

  int64 T;
  cin >> T;
  REP(_, T) {
    solve();
  }
}


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

int main() {
  int a,b,c,d;
  d == 0;
  
  cin >> a >> b >> c;
  
  if ( a == b && b == c && a == c){
    d = 1;
  }else if(a != b && b != c && a != c){
    d = 1;
  }else if(a == b || b == c || a == c){
	d = 0;
  }
  
  if (d == 1){
    cout << "No" << endl;
  }else if (d == 0){
    cout << "Yes" << endl;
  }
  
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<deque>
#include<queue>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
//using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;

using lli = long long int;
using ulli = unsigned long long int;

#define INF 999999999;

#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

int A, B, C, X, Y;
int ab2, a1b1;
int ans, add;

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

	cin >> A >> B >> C >> X >> Y;

	ab2 = min(C*2, A+B);

	ans = min(X, Y) * ab2;

	dbug(ans)dbugln;
	if(X > Y){
		add += abs(X-Y) * min(ab2, A);
	}else{
		add += abs(X-Y) * min(ab2, B);
	}
	dbug(add)dbugln;

	cout << ans+add;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
typedef long long int ll;

int read_int()
{
	int i;
	scanf("%d", &i);
	return i;
}

int read_lint()
{
	ll i;
	scanf("%lld", &i);
	return i;
}

int a[200000];
int bits[31];

int main()
{
	int n = read_int();

	for (int i = 0; i < n; i++)
	{
		a[i] = read_int();
		int mask = 1;
		for (int j = 0; j < 31; j++)
		{
			// printf("%d %d -> %d\n", a[i], mask, a[i] & mask);
			if (a[i] & mask)
			{
				bits[j] = bits[j] ^ 1;
			}
			mask <<= 1;
		}
	}

	for (int i = 0; i < n; i++)
	{
		int ans = 0;
		int mask = 1;
		for (int j = 0; j < 31; j++)
		{
			int bit = 0;
			if (a[i] & mask)
			{
				bit = 1;
			}
			ans += mask * (bit ^ bits[j]);
			// printf("%d %d %d %d\n", a[i], mask, bits[j], (a[i] & mask) ^ bits[j]);
			mask <<= 1;
		}
		printf("%d\n", ans);
	}

	return 0;
}


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

int main(){
    string s;
    cin >> s;
    int len= s.size();
    ll ans=0;

    for(int t=0; t<1<<(len-1); t++){
        ll num=s[0]-'0';
        for(int i=0; i<len-1; i++){
            if(t&(1<<i)){
                ans+=num;
                num=0;
            }
            num=num*10+s[i+1]-'0';
        }
        ans+=num;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

type IO struct {
	scanner *bufio.Scanner
	writer  *bufio.Writer
}

func NewIO() (*IO, func()) {
	io := &IO{
		scanner: newScanner(),
		writer:  newWriter(),
	}
	return io, func() { io.writer.Flush() }
}

func newScanner() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Buffer(make([]byte, 1000005), 1000005)
	s.Split(bufio.ScanWords)
	return s
}

func newWriter() *bufio.Writer {
	return bufio.NewWriter(os.Stdout)
}

func (io *IO) ScanString() string {
	if !io.scanner.Scan() {
		panic("scan string failed")
	}
	return io.scanner.Text()
}

func (io *IO) ScanStrings(n int) []string {
	strs := make([]string, n)
	for i := 0; i < n; i++ {
		strs[i] = io.ScanString()
	}
	return strs
}

func (io *IO) ScanInt() int {
	return int(io.ScanInt64())
}

func (io *IO) ScanInts(n int) []int {
	ints := make([]int, n)
	for i := 0; i < n; i++ {
		ints[i] = io.ScanInt()
	}
	return ints
}

func (io *IO) Scan2DInts(x, y int) [][]int {
	ints := make([][]int, y)
	for i := 0; i < y; i++ {
		ints[i] = io.ScanInts(x)
	}
	return ints
}

func (io *IO) ScanInt64() int64 {
	i, err := strconv.ParseInt(io.ScanString(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *IO) ScanFloat64() float64 {
	i, _ := strconv.ParseFloat(io.ScanString(), 64)
	return i
}

func (io *IO) ScanFloat64s(n int) []float64 {
	floats := make([]float64, n)
	for i := 0; i < n; i++ {
		floats[i] = io.ScanFloat64()
	}
	return floats
}

func (io *IO) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func main() {
	io, flush := NewIO()
	defer flush()

	a, b := io.ScanInt(), io.ScanInt()
	for i := 0.0; i <= 10000; i++ {
		if int(i*0.08) == a && int(i*0.1) == b {
			io.Println(i)
			return
		}
	}
	io.Println(-1)
}


Measured memory_bytes: 640
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = [0] * N
    for i in range(N-1):
        ans[A[i]-1] += 1
    
    for i in range(N):
        print(ans[i])


if __name__ == '__main__':
    main()

Measured memory_bytes: 94252
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <cstdio>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
ll mod = 998244353;
int main(void){
    ll n, k;
    cin >> n >> k;
    vector<pair<ll,ll>> vec;
    rep(i, k){
        ll l, r;
        cin >> l >> r;
        vec.push_back({l, r});
    }
    sort(all(vec));
    ll dp[200100] = {0};
    dp[0] = 1;
    dp[1] = -1;
    ll now = 0;
    rep(i, n){
        now += dp[i];
        //while(now < 0) now += mod;
        now %= mod;
        rep(j, vec.size()){
            if(i + vec[j].first < n){
                dp[i + vec[j].first] += now;
                dp[i + vec[j].first] %= mod;
            }
            if(i + vec[j].second + 1 < n){
                dp[i + vec[j].second + 1] -= now;
                //while(dp[i + vec[j].second + 1] < 0) dp[i + vec[j].second + 1] += mod;
                dp[i + vec[j].second + 1] %= mod;
            } 
        }
    }
    while(now < 0) now += mod;
    cout << now % mod << endl;
}



Measured memory_bytes: 5180
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>

#define ll long long
#define mod 1000000007

using namespace std;

int main() {
    int n;
    cin >> n;
    int count = 0;
    for(int i = 0; i < n; i++){
        int p;
        cin >> p;
        if(i+1 != p) count++;
    }

    if(count == 0 || count == 2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

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

int main() {
  ll n, ans = 0;
  cin >> n;

  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];

  sort(a.rbegin(), a.rend());

  queue<ll> q;
  q.push(a[0]);

  for (int i = 1; i < n; i++) {
    ans += q.front();
    q.pop();
    q.push(a[i]);
    q.push(a[i]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 6428
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let a: i64 = input();
    let b: i64 = input();
    let x: i64 = input();

    let mut m = b / x - a / x;
    if a % x == 0 {
        m += 1;
    }
    println!("{}", m);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

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

ll gcd(ll a, ll b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}

int main(void) {
	int n, i, lcm, ans;
	cin >> n;
	lcm = 360 * n / gcd(360, n);
	ans = lcm / n;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3608
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

string to_string(long n){
  stringstream ss;
  ss << n;
  return ss.str();
}

double value(long long n){
  string n_string = to_string(n);
  long sn = 0;
  REP(i,n_string.length()){
    sn += n_string[i]-'0';
  }
  return n  * 1.0 / sn;
}

long long pow10(int n){
  switch(n){
    case 0: return 1;
    case 1: return 10;
    case 2: return 100;
    case 3: return 1000;
    case 4: return 10000;
    case 5: return 100000;
    case 6: return 1000000;
    case 7: return 10000000;
    case 8: return 100000000;
    case 9: return 1000000000;
    case 10: return 10000000000;
    case 11: return 100000000000;
    case 12: return 1000000000000;
    case 13: return 10000000000000;
    case 14: return 100000000000000;
    default: return 1;
  }
}

int main(){
  long k;
  cin >> k;
  long long n = 1;
  REP(i,k){
    cout << n << endl;
    double min_s = value(n+1);
    for(int j = 1; j <= 14; j++){
      long long temp = n + pow10(j);
      if(value(temp)<min_s){
        min_s = value(temp);
      }else{
        n+=pow10(j-1);
        break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#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;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#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())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//pair sort
bool compare_by_b(pair<LL, LL> a, pair<LL, LL> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}


void solve(long long A, long long B, long long C, long long X){
    LL ans=0;
    REP(i, A+1){
        REP(j, B+1){
            REP(k, C+1){
                if(i*500+j*100+k*50 == X)ans++;
            }
        }
    }
    cout<<ans<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long X;
    scanf("%lld",&X);
    solve(A, B, C, X);
    return 0;
}


Measured memory_bytes: 256
#define __mode_debug__
/*   ξ
     ll
   ＿ll＿
 ／  ∞  ＼
│*  Ａ  *│
│*  Ｃ  *│
│*  祈  *│
│*  願  *│
│*      *│
 ￣￣￣￣￣    */
//C++14 (GCC 5.4.1)
#include <bits/stdc++.h>
using namespace std;
#ifdef __mode_debug__
    #define DBG
#else
    #define DBG if(false)
#endif

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)

template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

//DUMP
//  ostream vector<T> , vector<vector<T>> , set<T> ,queue<T> , priority_queue<T> , pair<T,U> , map<T,U>
template<class T> ostream& operator<<(ostream&os,vector<T>&vec){os<<"{ ";rep(i,vec.size()) os<<((i==0)?"":", ")<<i<<":"<<vec[i];os<<" }";return os;}
template<class T> ostream& operator<<(ostream&os,vector<vector<T>>&vec){os<<"{"<<endl;rep(i,vec.size())os<<"\t   "<<i<<":"<<vec[i]<<((i==vec.size()-1)? "":",")<<endl;os<<"\t }";return os;}
template<class T> ostream& operator<<(ostream&os,set<T>&p){os<<"{ ";repi(itr,p)  os<<((itr==p.begin())?"":", ")<<*itr;os<<" }";return os;}
template<class T> ostream& operator<<(ostream&os,queue<T>&p){queue<T> q(p);os<<"[< "<<(q.empty()?" <]":"");while(!q.empty()){os<<q.front();q.pop();os<< (q.empty() ? " <]" : ", ");}return os;}
template<class T> ostream& operator<<(ostream&os,priority_queue<T>&p){priority_queue<T> q(p);os<<"[< "<<(q.empty()?" <]":"");while(!q.empty()){os<<q.top();q.pop();os<< (q.empty() ? " <]" : ", ");}return os;}
template<class T,class U> ostream& operator<<(ostream&os,pair<T,U>&p){os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T,class U> ostream& operator<<(ostream&os,map<T,U>&p){os<<"{ ";repi(itr,p)os<<((itr==p.begin())?"":", ")<<itr->first<<":"<<itr->second;os<<" }";return os;}
void dump_f(string &nm){cerr<<endl;}
template<class T,class... Ts> void dump_f(string &nm,T &&x,Ts&&... ts){int l=nm.find_first_of(',');string name(nm,0,l),nx(nm,l+1,-1);cerr<<"  "<<name<<"\t:"<<x<<endl;dump_f(nx,forward<Ts>(ts)...);}
template<class... Ts> void dump_m(int &&ln,string &&nm,Ts&&... ts){cerr<<"[ln:"<<ln<<"]"<<endl;dump_f(nm,forward<Ts>(ts)...);}
#define dump(...) DBG dump_m(__LINE__,#__VA_ARGS__,__VA_ARGS__)

#define lower_bound_idx(V,c) distance(V.begin(),lower_bound(V.begin(),V.end(),c))


int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    ll A,B,K;
    cin >>A>>B>>K;

    //-----------------------------------
    K-=A;
    if(K<0){
      A=-K;
      K=0;
    }else{
      A=0;
      K-=B;
      if(K<0){
        B=-K;
        K=0;
      }else{
        B=0;
      }
    }

    cout << A<<" "<<B<<endl;
    return (0);
}


Measured memory_bytes: 256
# 参考URL https://note.nkmk.me/python-union-find/
class UnionFind():
    # parents
    # 各要素の親要素の番号を格納するリスト
    # 要素が根（ルート）の場合は-(そのグループの要素数)を格納する
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # find(x)
    # 要素xが属するグループの根を返す
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    # union(x, y)
    # 要素xが属するグループと要素yが属するグループとを併合する
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # size(x)
    # 要素xが属するグループのサイズ（要素数）を返す
    def size(self, x):
        return -self.parents[self.find(x)]

    # same(x, y)
    # 要素x, yが同じグループに属するかどうかを返す
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # members(x)
    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    # roots()
    # すべての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    # group_count()
    # グループの数を返す
    def group_count(self):
        return len(self.roots())

    # all_group_members
    # {ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    # __str__()
    # print()での表示用
    # ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

from sys import stdin
def input():
    return stdin.readline().strip()

n, m = map(int, input().split())

uf = UnionFind(n)

for _ in range(m):
    i, j = map(int, input().split())
    uf.union(i-1, j-1)

ans = 0
for i in uf.roots():
    j = uf.size(i)
    if ans < j:
        ans = j

print(ans)

Measured memory_bytes: 87164
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;

template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int N, k, height[(int)1e5 + 105], opt[(int)1e5 + 105];

int main(){
  FAST_IO  
  cin >> N >> k;
  for(int rep = 0; rep < N; ++rep) cin >> height[rep];
  for(int rep = 0; rep < N; ++rep) opt[rep] = INF;

  opt[0] = 0;
  for(int idx = 0; idx < N - 1; ++idx){
    for(int s = 1; s <= k; ++s){
      min_self(opt[idx + s], opt[idx] + abs(height[idx + s] - height[idx]));
    }
  }

  cout << opt[N - 1] << '\n';
  return 0;
}

Measured memory_bytes: 1024
N, Y=map(int, input().split())
ans=[-1, -1, -1]
for i in range(0, N+1):
  for j in range(i, N+1):
    if 10000*i+5000*(j-i)+1000*(N-j)==Y:
      ans=[i, j-i, N-j]
      
print(' '.join(map(str, ans)))

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(A: int, B: int):
    print(max([A+B, A-B, A*B]))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;

int main() {
	int a, b, h, m;
	double t, tt, hi, d, ans;
	double pi = 3.141592653589793;
	cin >> a >> b >> h >> m;
	t = h * 30;
	tt = m * 6;
	t = t + 0.5 * m;
	if (t > 360)t = t - 360;
	t = abs(t - tt);
	if (t > 180)t = 360 - t;
	//cout << "t=" << t << endl;
	if (t > 90) {
		//cout << "planA";
		t = 180 - t;
		t = pi*t / 180;
		hi = sin(t)*b;
		d = a + b * cos(t);
		ans = d * d + hi * hi;
		ans = sqrt(ans);
	}
	else if (t == 90) {
		t = pi*t / 180;
		//cout << "planB";
		ans = a * a + b * b;
		ans = sqrt(ans);
	}
	else if (t > 0) {
		t = pi*t / 180;
		//cout << "planC" << endl;
		//cout << cos(t) << " " << sin(t) << endl;
		hi = b * sin(t);
		d = abs(a - b * cos(t));
		ans = d * d + hi * hi;
		ans = sqrt(ans);
		//cout << hi << " " << d << endl;
	}
	else {
		//cout << "planD";
		ans = abs(a - b);
	}
	cout << fixed << setprecision(15) << ans << endl;
	return 0;
}

Measured memory_bytes: 4036
import sys

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

for i in range(m):
  a,b=map(int,input().split())
  l[a-1].append(b)
# print(l)


for i in l[0]:
  for j in l[i-1]:
    if j==n:
      print("POSSIBLE")
      sys.exit()

print("IMPOSSIBLE")



Measured memory_bytes: 33544
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 123456;
int num[MAXN];
LL D[MAXN], sz[MAXN];
vector<int> G[MAXN];
map<LL, int> mp;

bool cmp(int a, int b) {
     return D[a] > D[b];
}

LL dfs(int cur, LL dis) {
   LL sum = 0;
   for (int i : G[cur]) {
       sum += dfs(i, dis + 1);
   }
   return sum + dis;
}

int main() {
    int N;
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) {
        num[i] = i;
        sz[i] = 1;
        scanf("%lld", &D[i]);
        mp[D[i]] = i;
    }
    sort(num + 1, num + 1 + N, cmp);
    for (int i = 1; i < N; i++) {
        int cur = num[i];
        LL cur_D = D[cur];
        LL par_D = cur_D - N + 2 * sz[cur];
        if (mp.find(par_D) == mp.end()) return !printf("-1\n");
        int par = mp[par_D];
        G[par].push_back(cur);
        sz[par] += sz[cur];
    }
    LL check = dfs(num[N], 0);
    if (check != D[num[N]]) return !printf("-1\n");
    for (int i = 1; i <= N; i++) {
        for (int j : G[i]) {
            printf("%d %d\n", i, j);
        }
    }
    return 0;
}


Measured memory_bytes: 18176
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s,t="Yes";int n;cin>>n>>s;
  if(n%2==0){
    for(int i=0;i<n/2;i++){if(s.at(i)!=s.at(i+n/2))t="No";}
  }
  else t="No";
  cout<<t<<endl;
}


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

int main()
{
    int N;
    cin>>N;
    
    for(int i=1;i<=N;i++){
        int x=i;
        if(x%3==0){
            cout<<" "<<i;
        }else{
            while(1){

                if(x%10==3){
                    cout<<" "<<i;
                    break;
                }
                x/=10;
                if(x<1)break;
            }
        }
    }
    cout<<endl;


    return 0;
}


Measured memory_bytes: 3096
N = int(input())
L = list(map(int,input().split()))
counter = 0
for i in range(0,N-2):
    for j in range(i+1,N-1):
        if L[i] == L[j]:
            continue
        for k in range(j+1,N):
            if L[j] == L[k] or L[i] == L[k]:
                continue
            else:
                longest = max(L[i],L[j],L[k])
                if 2*longest < L[i]+L[j]+L[k]:
                    counter += 1
print(counter)

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

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> c(n);

    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }

    int t = 0;
    for (int i = 0; i < n; i++) {
        if (v[i] > c[i]) {
            t += v[i] - c[i];
        }
    }
    
    cout << t << endl;
}

Measured memory_bytes: 256
X, Y, Z, K = map(int, input().split())
xyz = []
xyz.append(list(map(int, input().split())))
xyz.append(list(map(int, input().split())))
xyz.append(list(map(int, input().split())))
for v in xyz:
    v.sort()
    v.reverse()

ans = []
for x in range(X):
    for y in range(Y):
        if x*y > K:
            break
        for z in range(Z):
            if x*y*z > K:
                break
            ans.append(xyz[0][x]+xyz[1][y]+xyz[2][z])

ans.sort()
ans.reverse()
print("\n".join([str(v) for v in ans[:K]]))


Measured memory_bytes: 105100
// C - Walk on Multiplication Table
#include <stdio.h>
typedef long long ll;

int main(void){
    ll i=1, n, ans=0;
    scanf("%lld", &n);
    ans = n-1;
    for(i=1; i<=sqrt(n); i++){
        if(n%i==0){ans=i;}
    }
    printf("%lld\n", ans+n/ans-2);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main()
{
    int x,i,j,t;
    scanf("%d",&x);
    for(i=x;;i++)
    {
        t=1;
        for(j=2;j<=i/2;j++)
        {
            if(i%j!=0)
                continue;
            else
                {
                    t=0;
                    break;
                }
        }
        if(t!=0)
            {
                printf("%d",i);
                break;
            }
    }
}

Measured memory_bytes: 128
X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

import heapq

heap = []
heapq.heappush(heap, (-(A[0]+B[0]+C[0]), 0, 0, 0))
added = set([(0, 0, 0)])

for _ in range(K):
    p, i, j, k = heapq.heappop(heap)
    if (i+1, j, k) not in added and i+1<X:
        heapq.heappush(heap, (-(A[i+1]+B[j]+C[k]), i+1, j, k))
        added.add((i+1, j, k))
    if (i, j+1, k) not in added and j+1<Y:
        heapq.heappush(heap, (-(A[i]+B[j+1]+C[k]), i, j+1, k))
        added.add((i, j+1, k))
    if (i, j, k+1) not in added and k+1<Z:
        heapq.heappush(heap, (-(A[i]+B[j]+C[k+1]), i, j, k+1))
        added.add((i, j, k+1))
    print(-p)

Measured memory_bytes: 4948
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  std::vector<int64_t> a(n, 0), b(n, 0);
  for (int i = 0; i < n; i++) {
    int m1;
    cin >> m1;
    a[i] = m1;
  }
  for (int i = 0; i < n; i++) {
    int m1;
    cin >> m1;
    b[i] = m1;
  }
  std::vector<int64_t> remainder;
  int64_t shortage = 0;
  int64_t result   = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] - b[i] < 0) {
      shortage += (b[i] - a[i]);
      result++;
    } else if (a[i] - b[i] > 0) {
      remainder.push_back(a[i] - b[i]);
    }
  }
  std::sort(remainder.begin(), remainder.end(), std::greater<int64_t>());

  for (auto x : remainder) {
    if (shortage <= 0) {
      cout << result << endl;
      return 0;
    }
    shortage -= x;
    result++;
  }
  if (shortage <= 0) {
    cout << result << endl;
    return 0;
  }
  cout << -1 << endl;

  return 0;
}


Measured memory_bytes: 2428
class Graph:
    def __init__(self):
        self.g = {}
        self.node = set()

    def addEdge_single(self, x, y, w):
        self.g[(x, y)] = w
        self.node.add(x)
        self.node.add(y)

    def addEdge(self, x, y, w):
        self.addEdge_single(x, y, w)
        self.addEdge_single(y, x, w)

    def dijkstra(self, start):
        open = {start: 0}
        closed = {}
        prev = {start: -1}
        while len(open) > 0:
            x = Graph.select_min(open)
            m = open[x]
            del open[x]
            closed[x] = m
            for (y, w) in self.edge(x):
                if y in open:
                    if open[y] > m + w:
                        open[y] = m + w
                        prev[y] = x
                elif y not in closed:
                    open[y] = m + w
                    prev[y] = x
            # print("open:  {}".format(open))
            # print("closed:{}".format(closed))
            # print("prev:  {}".format(prev))
            # print("-----")
        return closed, prev

    @staticmethod
    def select_min(S):
        m = -1
        for a in S:
            if m == -1 or m > S[a]:
                x = a
                m = S[a]
        return x

    def edge(self, x):
        G = self.g
        return [(b, G[(a, b)]) for (a, b) in G if a == x]


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

AB = []
for _ in range(M):
    a, b = [int(x) for x in input().split()]
    AB.append((a, b))

ans = 0
for i in range(M):
    g = Graph()
    for j in range(M):
        if i != j:
            g.addEdge(AB[j][0], AB[j][1], 1)
    w, p = g.dijkstra(1)
    if len(w) != N:
        ans += 1
    # print("w:{}, len:{}".format(w, len(w)))

print(ans)


Measured memory_bytes: 3188
module Main
  ( main
  )
where

import           Control.Applicative
import           Control.Monad
import           Data.List
import           Data.Array
import           Data.Char

main = do
  [n, m] <- map (read :: String -> Int) . words <$> getLine
  coords1 <- forM [1..n] (\i -> (\[x, y] -> (x, y)) . map (read :: String -> Int) . words <$> getLine)
  coords2 <- zip [1..m] <$> forM [1..m] (\i -> (\[x, y] -> (x, y)) . map (read :: String -> Int) . words <$> getLine)
  forM_ coords1 (\t -> print $ calcNearest t coords2)

calcNearest::(Int, Int) -> [(Int, (Int, Int))] -> Int
calcNearest (a, b) coords = snd . minimum $ map (\(index, (x, y)) -> (abs (x - a) + abs (y - b), index)) coords

Measured memory_bytes: 1020
#include <stdio.h>
#include <string.h>

char s[11];

int main() {
  scanf("%s", s);
  int len = strlen(s);
  char ans[11];
  for (int i = 0; i < 11; i++) {
    ans[i] = '\0';
  }

  int j = 0;
  for (int i = 0; i < len; i++) {
    if (s[i] == 'B') {
      if (j) {
        j--;
        ans[j] = '\0';
      }
    } else {
      ans[j] = s[i];
      j++;
    }
  }

  printf("%s\n", ans);

  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define repp(i,n) for(int i=1;i<=n;i++)

const ll mod = 998244353;

int main() {
	multiset<int> s;
	int N; scanf("%d",&N);
	repp(i,N){
		int x; scanf("%d",&x); s.insert(x);
	}
	while( s.size() >= 2 ){
		int mx = *s.rbegin();

		if( mx <= 0 ){
			printf("Impossible\n");
			return 0;
		}

		int cnt = 0;
		for(auto e : s) if( e == mx ) cnt++;
		if( cnt < 2 || (mx==1&&cnt>=3) || (mx>1&&cnt==sz(s))){
			printf("Impossible\n");
			return 0;
		}
		
		s.erase(mx);
		
		if( sz(s) ){
			int nmx = *s.rbegin();
			if( nmx < mx-1 ){
				printf("Impossible\n");
				return 0;
			}	
		}
		
		vector<int> v; 
		for(auto& e : s) v.pb(e);
		s.clear();
		for(auto e : v) s.insert(e-1);
	}

	if( s.size() == 1 ){
		if( *s.begin() == 0 ){
			printf("Possible\n"); return 0;
		}
		else{
			printf("Impossible\n"); return 0;
		}
	}

	printf("Possible\n");

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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;
}

const int MAX_N=1010;
const int MAX_X=5010;

int N;
vector<vector<int>> G(MAX_N);
vector<int> X(MAX_N);
vector<Pii> data(MAX_N);
bool can=true;

void dfs(int v){
    bitset<MAX_X> bit(1);
    int sum=0;
    for (auto nv:G[v]){
        dfs(nv);
        bitset<MAX_X> bit2=bit;
        bit2<<=data[nv].first;
        bit<<=data[nv].second;
        bit|=bit2;
        sum+=data[nv].first+data[nv].second;
    }
    for (int i=X[v];i>=0;--i){
        if (bit.test(i)){
            data[v]=Pii(X[v],sum-i);
            break;
        }
        if (i==0) can=false;
    }
}

int main(){
    cin >> N;
    rep(i,N-1){
        int p;
        cin >> p;
        G[p-1].push_back(i+1);
    }
    rep(i,N) cin >> X[i];
    dfs(0);
    if (can) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 896
use std::io::*;
use std::str::FromStr;
use std::cmp;
use std::collections::HashMap;
use std::collections::HashSet;
use std::char;
use std::cmp::{min, max};
use itertools::Itertools;
use std::ops::{Add, AddAssign};
use num_integer::{Integer, gcd, lcm};
use std::collections::VecDeque;

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")
}

fn read_tuple2<T: FromStr, S: FromStr>() -> (T, S) {
    let a = read();
    let b = read();
    (a, b)
}

fn read_tuple3<T: FromStr, S: FromStr, R: FromStr>() -> (T, S, R) {
    let a = read();
    let b = read();
    let c = read();
    (a, b, c)
}

fn lower_bound<T: Copy, F>(v: &Vec<T>, f: F) -> Option<usize> where
    F: Fn(T) -> bool
{
    let mut left = 0;
    let mut right = v.len() - 1;
    if !f(v[left]) {
        return None;
    }
    if f(v[right]) {
        return Some(right);
    }
    loop {
        if right - left == 1 {
            return Some(left);
        }
        let mid = (left + right) / 2;
        if f(v[mid]) {
            left = mid;
        } else {
            right = mid;
        }
    }
}

fn main() {
    let n:u32 = read();
    let ts:Vec<u64> = (0..n).map(|_|read()).collect();
    let mut ans = 1;
    for t in ts {
        ans = lcm(ans, t)
    }
    println!("{}", ans);
}



Measured memory_bytes: 2152
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vll vector<ll>
#define vllv vector<vector<ll>> 
#define sz size()
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
// ll fact(ll n){ll s=1; for(ll i=1;i<=n;i++)s*=i; return s;}
// ll ceil1(ll n,ll m){if(n%m==0){return n/m;}return n/m +1;}
// // vll factor(ll n){
// //     vll ans;
// //     if(n>0)ans.pb(1);if(n==2)ans.pb(2);
// //     for(ll i=2;i*i<=n;i++){if(n%i==0){ans.pb(i);if(n/i!=i)ans.pb(n/i);}}if(n>2)ans.pb(n);
// //     return ans;
// // }
// ll nCr(ll n, ll r) 
// { 
//     return fact(n) / (fact(r) * fact(n - r)); 
// } 
// void dfs(vllv &v,ll k,vll &par,vll &dis,ll p)
// {
 
//     par[k]=p;
//     dis[k]=dis[p]+1;
//     for(ll i=0;i<v[k].sz;i++){
//         if(v[k][i]!=p){
//             dfs(v,v[k][i],par,dis,k);
//         }
//     }
// }
// bool sortbysec(const pair<int,int> &a,const pair<int,int> &b){return (a.second<b.second);} 


void solve()
{
	ll n;
	cin>>n;
	ll a[n];
	vll c(n+1,0);
	for(ll i=1;i<n;i++)
	{
		cin>>a[i];
		c[a[i]]++;
	}
	for(ll i=1;i<=n;i++)
	{
		cout<<c[i]<<endl;
	}
       return;
}

int main()
{
    ll q;
    q=1;
    // cin>>q;
    while(q--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 6376
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll n, k;
	cin >> n >> k;

	if (k % 2) {
		ll a = n / k;
		out(a * a * a);
	}
	else {
		ll a = n / k;
		ll b = (n + k / 2) / k;
		out(a * a * a + b * b * b);
	}

	return 0;
}

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

int main()
{
   ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i;
    cin>>n;
    ll a[n+5],dp[n+5],dpp[n+5];
    vector<ll> v;
   for(i=0;i<n;i++){
       cin>>a[i];
   }
   for(i=0;i<n;i++){
       if(i==0){
           dp[i] = a[i];
           continue;
       }
       dp[i]=__gcd(dp[i-1],a[i]);
   }
   for(i=n-1;i>=0;i--){
       if(i==n-1){
           dpp[i]= a[i];
           continue;
       }
       dpp[i]=__gcd(dpp[i+1],a[i]);
   }
   for(i=0;i<n;i++){
       if(i==0){
           v.push_back(dpp[1]);
           continue;
       }
       if(i==n-1){
           v.push_back(dp[n-2]);
           continue;
       }
       v.push_back(__gcd(dp[i-1],dpp[i+1]));
   }
   cout<<*(max_element(v.begin(),v.end()));
    
}


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

struct Section{
    int64_t a;
    int64_t b;
};

class MergableSectionList {
public:
    MergableSectionList() = default;

    void insert(const int64_t a, const int64_t b) {
        assert(a <= b);
        auto i = section_map.insert(std::make_pair(a, b));
        if(!i.second && i.first->second < b) {
            i.first->second = b;
        }
    }

    std::vector<Section> merge() const {
        if(section_map.size()) {
            auto i = section_map.begin();
            int64_t a = i->first;
            int64_t b = i->second;
            auto result = std::vector<Section>();

            ++i;

            for( ; i != section_map.end(); ++i) {
                if(i->first <= b + 1) {
                    b = std::max(b, i->second);
                } else {
                    result.push_back(Section { a, b });
                    a = i->first;
                    b = i->second;
                }
            }

            result.push_back(Section { a, b });

            return result;
        } else {
            return std::vector<Section>();
        }
    }

    uint64_t merged_length() const {
        const auto v = merge();
        uint64_t x = 0;
        for(const auto s: v) {
            x += s.b - s.a + 1;
        }
        return x;
    }
private:
    std::map<int64_t, int64_t> section_map;
};


uint64_t solve(int64_t n, int64_t x, int64_t d) {
    if (d == 0) {
        if (x == 0) {
            return 1;
        } else {
            return n + 1;
        }
    }
 
    if (d < 0) {
        d = -d;
        x = -x;
    }

    auto section_map = std::unordered_map<uint64_t, MergableSectionList>();

    for(int64_t k = 0; k <= n; ++k) {
        auto a = (k * (k - 1)) / 2;
        auto b = k * (2 * n - k - 1) / 2;

        auto kx = x < 0 ? -x * k : x * k;
        
        auto q = x < 0 ? -(kx / d) : kx / d;
        auto r = kx % d;

        auto i = section_map.find(r);
        if(i == section_map.end()) {
            auto section_list = MergableSectionList();
            section_list.insert(a + q, b + q);
            section_map[r] = section_list;
        } else {
            i->second.insert(a + q, b + q);
        }
    }

    uint64_t s = 0;
    for(const auto i: section_map) {
        s += i.second.merged_length();
    }
    return s;
}

int main() {
    int64_t n, x, d;
    std::cin >> n >> x >> d;

    std::cout << solve(n, x, d);

    return 0;
}


Measured memory_bytes: 30408