akhauriyash/Code-Regression huggingface dataset:
from itertools import chain, combinations


def powerset(iterable):
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))


n = int(input())
x = []
for i in range(n):
    xi = []
    a = int(input())
    for j in range(a):
        xij, yij = map(int, input().split())
        xi.append((xij-1, bool(yij)))
    x.append(xi)

res = 0
for cands in powerset(range(n)):
    cands = set(cands)
    for c in cands:
        flagc = True
        for xc, yc in x[c]:
            if yc != (xc in cands):
                flagc = False
                break
        if not flagc:
            break
    else:
        res = max(len(cands), res)
print(res)


Measured memory_bytes: 3064
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
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=998244353;
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; }
V<int> v,w;
int m;
int L,ans;
int dp[520][100005];
void dfs(int cur,int V,int W){
    if(cur<=m){
        chmax(ans,dp[cur][L-W]+V);
        return;
    }
    dfs(cur/2,V,W);
    if(W+w[cur]<=L){
        dfs(cur/2,V+v[cur],W+w[cur]);
    }
}
int main(){
    int n;
    cin>>n;
    v.resize(n+1);w.resize(n+1);
    for(int i=1;i<=n;i++)cin>>v[i]>>w[i];
    m=min((1<<9),n);
    for(int i=1;i<=m;i++){
        for(int j=0;j<=100000;j++){
             chmax(dp[i][j],dp[i/2][j]);
             if(j+w[i]<=100000){
                 chmax(dp[i][j+w[i]],dp[i/2][j]+v[i]);
             }
        }
        for(int j=0;j<=100000;j++){
            chmax(dp[i][j+1],dp[i][j]);
        }
    }
    int q;
    cin>>q;
    int a;
    while(q--){
        cin>>a>>L;
        ans=0;
        dfs(a,0,0);
        cout<<ans<<"\n";
    }

}

Measured memory_bytes: 204828
N,Q = map(int, input().split())
import copy
import sys

sys.setrecursionlimit(10**6)
es = [[] for i in range(N)]

for i in range(N-1):
    a,b = map(int, input().split())
    a,b = a-1, b-1
    es[a].append(b)
    es[b].append(a)


point = [0] * N

for i in range(Q):
    p,x = map(int, input().split())
    point[p-1] += x 

ans = [0] * N
ans[0] = point[0] # 一番上の根なのでこれだけ
visited = [False] * N
visit_cnt = 1
from collections import deque
nexts = deque([0])
while len(nexts) >= 1:
    now = nexts.popleft()
    visited[now] = True

    for next in es[now]:
        if visited[next] == True:
            continue
        nexts.append(next)
        ans[next] = ans[now] + point[next]


print(*ans)

Measured memory_bytes: 63732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<x<<endl
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
typedef vector<int> vi;

int L[4][2001][2001],f[2001][2001];
int h,w;

int main(void){
    cin>>h>>w;
    rep(i,h)rep(j,w){
        char ib;
        cin>>ib;
        if(ib=='#')f[i][j]=0;
        else f[i][j]=1;
        rep(k,4)L[k][i][j]=f[i][j];
    }
    rep(i,h)rep(j,w){
        if(i>0)if(L[0][i][j]==1)L[0][i][j]+=L[0][i-1][j];
        if(j>0)if(L[1][i][j]==1)L[1][i][j]+=L[1][i][j-1];
        if(i>0)if(L[2][h-i-1][j]==1)L[2][h-i-1][j]+=L[2][h-i][j];
        if(j>0)if(L[3][i][w-j-1]==1)L[3][i][w-j-1]+=L[3][i][w-j];
    }
    //rep(i,h){p("\n");rep(j,w)cout<<L[3][i][j];}
    int ma=0;
    rep(i,h)rep(j,w){
        int score=0;
        rep(k,4)score+=L[k][i][j];
        ma=max(ma,score-3);
    }
    p(ma);
    return 0;
}


Measured memory_bytes: 78464
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
     
      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      
      if((a + b + c) >= 22){
        System.out.println("bust");
      }else{
        System.out.println("win");
      }
      
      sc.close();
    }
}


Measured memory_bytes: 21204
#include <iostream>
#include <cmath>
using namespace std;
int main(){
	int n,jj;
	double j;
	cin>>n;
	for(int i=n;i>0;i--){
		j=sqrt((double)i);
		j=fmod(j,1.0);
		if(j==0){
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

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

#ifndef DEBUG
#define endl '\n'
#define debug(...)
#else
#define debug(...) __VA_ARGS__
#endif
#define debugf(...) debug(printf(__VA_ARGS__);)

const int N = 1e5 + 5;
vector<int> a, b, c;

using ll = long long;

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

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

    a.resize(A); b.resize(B); c.resize(C);
    for (int i = 0; i < A; i++)
        cin >> a[i];
    for (int i = 0; i < B; i++)
        cin >> b[i];
    for (int i = 0; i < C; i++)
        cin >> c[i];

    sort(a.rbegin(), a.rend()); reverse(a.begin(), a.begin()+X);
    sort(b.rbegin(), b.rend()); reverse(b.begin(), b.begin()+Y);
    sort(c.rbegin(), c.rend());

    debug(
        for (int i = 0; i < X; i++)
            cout << a[i] << ' ';
        cout << endl;
        for (int i = 0; i < Y; i++)
            cout << b[i] << ' ';
        cout << endl;
    )

    int i = 0, j = 0;
    for (int x : c) {
        int d1 = i >= X ? -1 : (x - a[i]);
        int d2 = j >= Y ? -1 : (x - b[j]);
        if (d1 > d2 && d1 > 0) {
            a[i] = x;
            i++;
        } else if (d2 > 0) {
            b[j] = x;
            j++;
        }
    }

    debug(
        for (int i = 0; i < X; i++)
            cout << a[i] << ' ';
        cout << endl;
        for (int i = 0; i < Y; i++)
            cout << b[i] << ' ';
        cout << endl;
    )

    ll ans = 0;
    for (int i = 0; i < X; i++)
        ans += a[i];
    for (int i = 0; i < Y; i++)
        ans += b[i];

    cout << ans << endl;





    return 0;
%>

Measured memory_bytes: 1408
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a < b)  
        if(b < c){
            cout << a << " " << b << " " << c<<endl;
        }else{
            cout << a << " " << c << " " << b<<endl;
        }
    else
        if(b < c){
            if(a<c){
                cout << b << " " << a << " " << c<<endl;
            }else{ 
                cout << b << " " << c << " " << a<<endl;
            }
        }else{
            cout << c << " " << b << " " << a<<endl;
            
        }
}


Measured memory_bytes: 3116
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp::max;
fn main() {
    input!{
        K: usize,
        N: usize,
        A: [usize; N],
    }
    let mut distance = K -A[N-1] + A[0];
    for i in 0..N-1{
        let d =  A[i+1] - A[i];
        distance = max(distance, d);
    }
    println!("{}", K -distance);
}


Measured memory_bytes: 8444
// atcoder/arc070/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

template<typename T>
struct PrefixSum {
  vector<T> sum;
  PrefixSum(vector<T> v) {
    sum.push_back(0);
    each (i, v) {
      sum.push_back(sum.back() + i);
    }
  }
  T query(size_t begin, size_t end) {
    return sum[end] - sum[begin];
  }
};

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  lli k;
  while (cin >> n >> k) {
    vector<lli> a(n);
    cin >> a;
    vector<lli> b = a;
    reverse(b.begin(), b.end());

    const int N = 5000 + 5;
    const int K = 5000 + 5;
    static bool dp1[N][K];
    static bool dp2[N][K];

    fill(&dp1[0][0], &dp1[N - 1][K - 1] + 1, false);
    fill(&dp2[0][0], &dp2[N - 1][K - 1] + 1, false);
    dp1[0][0] = dp2[0][0] = true;

    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < K; ++j) {
        dp1[i + 1][j] |= dp1[i][j];
        dp2[i + 1][j] |= dp2[i][j];
        if (j + a[i] < K) dp1[i + 1][j + a[i]] |= dp1[i][j];
        if (j + b[i] < K) dp2[i + 1][j + b[i]] |= dp2[i][j];
      }
    }

    int cnt = 0;
    for (int i = 0; i < n; ++i) {
      if (k <= a[i]) {
        ++cnt;
        continue;
      }
      vector<lli> v1, v2;
      for (int j = 0; j < K; ++j) {
        v1.push_back(dp1[i][j]);
        v2.push_back(dp2[n - i - 1][j]);
      }
      PrefixSum<lli> ps1(v1);
      PrefixSum<lli> ps2(v2);
      bool f = false;
      for (int j = 0; j <= k - 1; ++j) {
        const int p = max<int>(0, k - a[i] - j);
        // cout << a[i] << ' ' << j << ' ' << dp1[i][j] << ' ' << ps2.query(p, k - j) << ' ' << make_pair(p, k - j) << endl;
        // cout << a[i] << ' ' << j << ' ' << dp2[i][j] << ' ' << ps1.query(p, k - j) << ' ' << make_pair(p, k - j) << endl;
        f = f || (dp1[i][j]         && ps2.query(p, k - j));
        f = f || (dp2[n - i - 1][j] && ps1.query(p, k - j));
      }
      // cout << a[i] << ' ' << f << endl;
      cnt += f;
    }
    cout << n - cnt << endl;
    // break;
  }

  return 0;
}


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

int main(void) {
  char w[101];
  cin >> w;

  char abc[] = "abcdefghijklmnopqrstuvwxyz";
  int ab[strlen(abc)];
  for(int i = 0; i < strlen(abc); i++) ab[i]=0;

  for (int i = 0; i < strlen(w); i++) {
    for (int j = 0; j < strlen(abc); j++) {
      if (w[i] == abc[j]) ab[j]++;
    }
  }
  bool key = true;
  for (int i = 0; i < strlen(abc); i++) {
    if (ab[i] % 2 != 0) {key = false; break; }
  }
  if (key)
  cout << "Yes" << endl;
  else
  {
    cout << "No" << endl;
  }
  
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

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

const int INF = 1e9;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;

char grid[310][310];

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

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin>>grid[i][j];
        }
    }

    int res = 0;

    for (int B = 0; B < N; B++) {
        bool ok = true;
        for (int i = 1; i < N; i++) {
            if(!ok)break;
            for (int j = 0; j < i; j++) {
                if(grid[(i)%N][(j+B)%N]!=grid[(j)%N][(i+B)%N]){
                    ok=false;
                    break;
                }
            }
        }
        if(ok){
            res++;
        }
    }

    cout<<res*N<<endl;

    return 0;
}

Measured memory_bytes: 384
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;

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 main() {
    let a: usize = read();
    let b: usize = read();
    let k: usize = read();

    let mut ans:Vec<usize> = Vec::new();
    for i in 1..101 {
        if a % i == 0 && b % i == 0 {
            ans.push(i);
        }
    }
    println!("{}", ans[ans.len() - k]);
}

Measured memory_bytes: 4352
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <queue>
using namespace std;

int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	long long s = a;
	s += b;
	if(s&1) printf("IMPOSSIBLE\n");
	else printf("%lld\n", s/2);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline void LB(vector<T>& v, T& a) { return *lower_bound(ALL(v),a); }
template <typename T> inline void LBP(vector<T>& v, T& a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline void UB(vector<T>& v, T& a) { return *upper_bound(ALL(v),a); }
template <typename T> inline void UBP(vector<T>& v, T& a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> 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 V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; }
template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

void no() {
  cout << "No" << endl;
  exit(0);
}

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int H,W,h,w;
  cin >> H >> W >> h >> w;
  auto a = make_v<int>(H,W);
  fill_v(a,1);
  for (int i = 0; i <= H-h; i += h) {
    for (int j = 0; j <= W-w; j += w) {
      a[i+h-1][j+w-1] = -h*w;
    }
  }
  int neg = (H/h)*(W/w);
  int pos = H*W-neg;
  if (pos <= neg) no();
  int den = pos-neg*(h*w-1);
  if (den == 0) no();
  int k = (neg*h*w-pos)/den+1;
  REP(i,H) REP(j,W) {
    if (a[i][j] > 0) a[i][j] += k;
    else a[i][j] -= k*(h*w-1);
  }
  int P = 0, N = 0;
  REP(i,H) REP(j,W) {
    if (a[i][j] > 0) P += a[i][j];
    else N += a[i][j];
  }
  cout << "Yes" << endl;
  REP(i,H) cout << a[i] << endl;

  return 0;
}

Measured memory_bytes: 3328
const INF: i64 = 1e16 as i64;
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let a: Vec<i64> = sc.vec(n);
    let mut graph = vec![vec![]; n];
    for _ in 1..n {
        let u = sc.read::<usize>() - 1;
        let v = sc.read::<usize>() - 1;
        graph[u].push(v);
        graph[v].push(u);
    }

    let mut power_dp = vec![vec![]; n];
    let mut min_dp = vec![vec![]; n];
    dfs(0, 0, &a, &graph, &mut power_dp, &mut min_dp);

    for cut in 0.. {
        if power_dp[0][cut] < INF || min_dp[0][cut] < 0 {
            println!("{}", cut);
            return;
        }
    }
}

fn dfs(
    v: usize,
    p: usize,
    a: &Vec<i64>,
    graph: &Vec<Vec<usize>>,
    power_dp: &mut Vec<Vec<i64>>,
    min_dp: &mut Vec<Vec<i64>>,
) {
    power_dp[v].push(if a[v] > 0 { a[v] } else { INF });
    min_dp[v].push(a[v]);
    for &child in graph[v].iter() {
        if p == child {
            continue;
        }
        dfs(child, v, a, graph, power_dp, min_dp);
        power_dp[v] = connect(&power_dp[v], &power_dp[child], &min_dp[child], true);
        min_dp[v] = connect(&min_dp[v], &power_dp[child], &min_dp[child], false);
    }
}

fn connect(
    dp: &Vec<i64>,
    power_child: &Vec<i64>,
    min_child: &Vec<i64>,
    is_power: bool,
) -> Vec<i64> {
    let mut next = vec![INF; dp.len() + power_child.len() + 1];
    for cut in 0..dp.len() {
        if dp[cut] >= INF {
            continue;
        }
        for child_cut in 0..power_child.len() {
            let total_cut = cut + child_cut;
            if !is_power {
                chmin(&mut next[total_cut], dp[cut] + min_child[child_cut]);
            }
            if power_child[child_cut] < INF {
                chmin(&mut next[total_cut], dp[cut] + power_child[child_cut]);
            }
            if min_child[child_cut] < 0 || power_child[child_cut] < INF {
                chmin(&mut next[total_cut + 1], dp[cut]);
            }
        }
    }
    next
}

fn chmin<T: Ord>(a: &mut T, b: T) {
    if *a > b {
        *a = b;
    }
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 408444
#include <stdio.h>
#include <math.h>

int main()
{
  double x1,y1,x2,y2;
  scanf("%lf",&x1);
  scanf("%lf",&y1);
  scanf("%lf",&x2);
  scanf("%lf",&y2);
  printf("%lf\n",sqrt(pow(x2-x1,2)+pow(y2-y1,2)));
  return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <vector>
#include <sstream>
#include <cstdlib>

using namespace std;

int main(void){
    string s;
    cin >> s;
    int size = s.size();
    int num[size];
    int sign;
    int goal = 7;
    for(int i = 0;i < size;i++){
        num[i] = s[i] - '0';
    }
    for(int i = 0;i < pow(2,size-1);i++){
        int ans = num[0];
        int k = i;
        for(int j = 1;j < size;j++){
            if(k%2)ans += num[j];
            else ans -= num[j];
            k /= 2;
        }
        if(ans == goal){
            sign = i;
            break;
        }
    }
    for(int i = 0;i < size;i++){
        cout << num[i];
        if(i != size-1){
            if(sign % 2) cout << '+';
            else cout << '-';
            sign /= 2;
        }
    }
    cout << "=" << goal << endl;
}


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

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

const int MAXN = 1e5;

int n, m, arr[MAXN+10];

int main()
{
    int i, j;

    scanf("%d%d", &n, &m);
    for(i=1; i<=m; i++)
    {
        int l, r;
        scanf("%d%d", &l, &r);
        arr[l]++; arr[r+1]--;
    }
    for(i=1; i<=n; i++) arr[i]+=arr[i-1];
    int ans=0;
    for(i=1; i<=n; i++) if(arr[i]==m) ans++;
    printf("%d", ans);
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void) {

	double r;
	double X, Y;

	scanf("%lf", &r);

	X = r*r*3.141592653589;
	Y = 2 * r*3.141592653589;

	printf("%.6f %.6f\n", X, Y);

	return(0);

}


Measured memory_bytes: 2104
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, m;
    cin >> n >> m;

    ll MAXL = 0, MINR = INF;
    rep(i, m) {
        ll l, r;
        cin >> l >> r;
        r++;
        chmax(MAXL, l);
        chmin(MINR, r);
    }

    out(max(0LL, MINR - MAXL));
    re0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include<bits/stdc++.h>
#define mod 1e9+7
#define ll long long int
#define pb push_back
#define mk make_pair

using namespace std;


int main(){
   ll a,b;
    cin>>a>>b;
    if(a<=b)cout<<0<<endl;
    else
        cout<<(a-b)<<endl;
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N,K;
    Scd2(N,K);

    vi a(N),b(N);
    Rep(i,N){
        Scd2(a[i],b[i]);
    }

    ll ans = 0;
    ll tmp = 0;
    int bm = 1; // mask
    while( K >= 0 ){
        // printf ("%d\n", K );
        tmp = 0;
        Rep(i,N){
            if( (K & a[i]) == a[i] ){
                tmp += b[i];
            }
        }
        ans = max( ans, tmp );
        while( K & bm ){
            bm <<= 1;
        }
        K -= bm;
    }
    printf ("%lld\n", ans );

    return 0;
}




Measured memory_bytes: 1024
import scala.io.StdIn._
object Main extends App {

  val Array(n ,x) = readLine.trim.split(' ').map(_.toInt)
  val tests = Array.tabulate(n){_ ⇒
    val Array(b, l, u) = readLine.trim.split(' ').map(_.toLong)
    Test(b, l, u)
  }.sortBy{test ⇒
    (x - test.score) * test.upper + test.score * test.lower
  }(Ordering.Long.reverse)
  val default = tests.map{test ⇒ -test.score * test.lower}.sum
  var min = 0L
  var max = x * n.toLong
  while (min < max) {
    val mid = (max + min) / 2
    if (canWin(tests, x, mid)) {
      max = mid
    }else {
      min = mid + 1
    }
  }
  println(min)
  def canWin(tests: Array[Test], x: Long, time: Long): Boolean = {
    if (tests.length * x <= time) { return true}
    val full = (time / x).toInt
    val fullScore = (0 until full).map{i ⇒ tests(i).upper * x - tests(i).score * (tests(i).upper - tests(i).lower)}.sum
    val rest = time % x
    for ((test, i) ← tests.zipWithIndex){
      val base = if (i < full) fullScore - (tests(i).upper * x - tests(i).score * (tests(i).upper - tests(i).lower)) + (tests(full).upper * x - tests(full).score * (tests(full).upper - tests(full).lower)) else fullScore

      val add = if (rest >= test.score) test.upper * (rest - test.score) + test.lower * test.score else test.lower * rest
      if (base + add + default >= 0) return true
    }
    false
  }
  case class Test(score: Long, lower: Long, upper: Long)
}


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

ll frog(vector<ll> h,vector<ll> dp,ll n){
    for(int i=1;i<=n;i++){
        dp[i+1]=min(dp[i+1],dp[i]+abs(h[i]-h[i-1]));
        dp[i+2]=min(dp[i+2],dp[i]+abs(h[i+1]-h[i-1]));
    }
    return dp[n];
}
/*ll fg(vector<ll> h,vector<ll> dp,ll n){
    if(n==1)return 0;
    else if(n==2)return abs(h[1]-h[0]);
    dp[n]+=min(dp[])
}*/
int main() {
    ll n;cin>>n;
    vector<ll> h(n),dp(n+4,INT_MAX);
    dp[0]=0;dp[1]=0;
    for(int i=0;i<n;i++)cin>>h[i];
    cout<<frog(h,dp,n)<<"\n";

	return 0;
}


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

int main()
{
    double x,l,y,area;
    scanf("%lf",&l);
    y=l/3;
    area=y*y*y;
    printf("%.12lf\n",area);
    return 0;
}


Measured memory_bytes: 128
package main

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

func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	var n, q int
	n = nextInt()
	S := make([]int, n)

	for i := 0; i < n; i++ {
		S[i] = nextInt()
	}

	q = nextInt()
	T := make([]int, q)
	for j := 0; j < q; j++ {
		T[j] = nextInt()
	}

	ans := 0
	for _, t := range T {
		for _, s := range S {
			if t == s {
				ans++
				break
			}
		}
	}
	fmt.Println(ans)
}



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

using namespace std;
#define X first
#define Y second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define debug(x) cerr << #x << " = " << (x) << endl;
template<typename T>
ostream& operator<<(ostream& o, vector<T>& v) {
    for (auto& x : v) o << x << ' ';
    return o;
}

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    int n, k; cin >> n >> k;
    if (n == 2) {
        if (n != k) cout << "No" << endl;
        else {
            cout << "Yes" << endl;
            for (int i = 1; i <= 2*n-1; i++){
                cout << i << "\n";
            }
        }
        return 0;
    }
    if (k == 1 || k == 2*n-1) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    if (n == k){
        for (int i = 1; i <= 2*n-1; i++){
            cout << i << "\n";
        }
        return 0;
    }
    if (k < n){
        vi v = {k, 1};
        for (int i = 2; i <= n; i++){
            if (i == k) continue;
            v.push_back(i);
        }
        for (int i = n+1; i < 2*n; i++){
            cout << i << "\n";
        }
        for (int x : v)
            cout << x << "\n";
        return 0;
    }
    for (int i = n-1; i >= 1; i--){
        cout << i << "\n";
    }
    cout << k << "\n";
    cout << 2*n-1 << "\n";
    for (int i = n; i < 2*n-1; i++){
        if (i == k) continue;
        cout << i << "\n";
    }

}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=3e3+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll dp[MAXn][MAXn],sum[MAXn][MAXn];
ll d[MAXn],s[MAXn];
ll cal(ll l,ll r){
  if (dp[l][r] != -1) return dp[l][r];
  if (l == r) return dp[l][r] = d[l];
  return dp[l][r] = max(d[l]+sum[l+1][r]-cal(l+1,r),d[r]+sum[l][r-1]-cal(l,r-1));
}
int main(){
  IOS();
  ll n;
  cin >> n;
  REP (i,n) {
    cin >> d[i];
    s[i] = d[i];
    if (i != 0) s[i] += s[i-1];
  }
  REP (i,n) for (ll j=i;j<n;j++) {
    if (i == 0) sum[i][j] = s[j];
    else sum[i][j] = s[j]-s[i-1];
  }
  RST(dp,-1);
  ll ans = cal(0,n-1);
  cout << 2*ans-sum[0][n-1] << endl;
}


Measured memory_bytes: 141568
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if b-a<=k and c-a<=k and d-a<=k and e-a<=k and c-b<=k and d-b<=k and e-b<=k and d-c<=k and e-c<=k and e-d<=k:
  print("Yay!")
else:
  print(":(")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> tp;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
typedef pair<pii, int> piipi;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;
typedef pair<LL, pii> plpii;
typedef pair<LD, LD> pdd;
typedef pair<LD, int> pdi;
typedef pair<LD, LL> pdl;
typedef pair<int, LD> pid;
typedef pair<LL, LD> pld;
const int mod = 1e9 + 7;
const int hf = 999983;
const int N = 1e6;

typedef long long ll;
const ll is_query = (1LL<<62);
struct Line {
    ll m, b;
    mutable function<const Line*()> succ;
    bool operator<(const Line& rhs) const {
        if (rhs.b != is_query) return m < rhs.m;
        const Line* s = succ();
        if (!s) return 0;
        ll x = rhs.m;
        return b - s->b < (s->m - m) * x;
    }
};
struct HullDynamic : public multiset<Line> {
    void init(){
        clear();
    }
    bool bad(iterator y) {
        auto z = next(y);
        if (y == begin()) {
            if (z == end()) return 0;
            return y->m == z->m && y->b <= z->b;
        }
        auto x = prev(y);
        if (z == end()) return y->m == x->m && y->b <= x->b;
        return (LD)(x->b - y->b)*(z->m - y->m) >= (LD)(y->b - z->b)*(y->m - x->m);
    }
    void insert_line(ll m, ll b) {
        m = -m, b = -b;
        auto y = insert({ m, b });
        y->succ = [=] { return next(y) == end() ? 0 : &*next(y); };
        if (bad(y)) { erase(y); return; }
        while (next(y) != end() && bad(next(y))) erase(next(y));
        while (y != begin() && bad(prev(y))) erase(prev(y));
    }
    ll eval(ll x) {
        if(size() == 0) return 2e18;
        auto l = *lower_bound((Line) { x, is_query });
        return -(l.m * x + l.b);
    }
}hull;

LL dp[200005];
int main(){
    LL n, c, h;
    scanf("%lld%lld", &n, &c);
    hull.insert_line(0, 0);
    for(int i=1;i<=n;i++){
        scanf("%lld", &h);
        if(i == 1) dp[i] = 0;
        else dp[i] = hull.eval(h) + h*h + c;
        hull.insert_line(-2*h, dp[i]+h*h);
    }
    printf("%lld\n", dp[n]);
}


Measured memory_bytes: 20608
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define ll long long
#define pb push_back
#define itr(it, a) for(auto i:a)
int main()
{
int a;
cin>>a;
int count=0;
int ans=0;
for(int i=0;i<a;i++)
{
	int temp1,temp2;
	cin>>temp1>>temp2;
	if(abs(temp1-temp2)==0)
	{
		count++;
		ans=max(ans,count);
	}
	else
	{
		count=0;
	}
	
}
if(ans>=3)
 cout<<"Yes"<<endl;
 else
 {
	 cout<<"No"<<endl;
 }
 
return 0;
}


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

#define int long long
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()

const int mod = 1e9+7;
const int inf = 2e18;

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

	int n;
	cin>>n;

	int sum = 0;

	for(int i=1;i<=n;i++)
	{
		if(i%3!=0 && i%5!=0)
		{
			sum+=i;
		}	
	}
	cout<<sum<<'\n';
	return 0;
}	

Measured memory_bytes: 3612
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <limits.h>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <string>
using namespace std;
const int P=1e9+7;
int n,x,y,z,dp[50][1<<17],ans=1;
int main(){
    scanf("%d%d%d%d",&n,&x,&y,&z);
    for (int i=1; i<=n; i++)
    	ans=1ll*ans*10%P;
    int tmp=(1<<x-1)|(1<<x+y-1)|(1<<x+y+z-1);
    int s=(1<<x+y+z)-1;
    dp[0][0]=1;
	for (int i=1; i<=n; i++)
		for (int j=0; j<=s; j++)
            for (int k=1; k<=10; k++){
                int t=(j<<k)|(1<<k-1);
                t&=s;
                if ((t&tmp)!=tmp)
                    dp[i][t]=(dp[i][t]+dp[i-1][j])%P;
            }
	for (int i=0; i<=s; i++)
        ans=(ans-dp[n][i]+P)%P;
    printf("%d\n",ans);
}

Measured memory_bytes: 23712
from collections import *
from itertools import *
import copy
from heapq import *

S=input()
mod=10**9+7


"""def mpow(x,n):
    num=1
    while n > 0:
        if n&1:
            num=num*x%mod
        x=x*x%mod
        n=n>>1
    return(num)"""

A=0
AB=0
ABC=0
count=0
for s in S:
    if s=="A":
        A+=pow(3,count,mod)
    elif s=="B":
        AB+=A
    elif s=="C":
        ABC+=AB
    else:
        ABC=(ABC*3+AB)%mod
        AB=(AB*3+A)%mod
        A=(A*3+pow(3,count,mod) )%mod
        count+=1
print(ABC%mod)


Measured memory_bytes: 40304
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define ld long double
#define ff first
#define ss second

const long long MOD7 = 1000000007;

using namespace std;

int main() {
    ios::sync_with_stdio(0);
    int a;

    cin >> a;

    cout << a + a * a + a * a * a << endl;

    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
  int n;
  cin >> n;
  string s, t;
  cin >> s >> t;

  int ans = n * 2;
  rep(i,n) {
    string ns = s.substr(i);
    string nt = t.substr(0, n - i);
    if (ns == nt) {
      ans -= (n - i);
      break;
    }
  }
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 3636
def func(N, H_i):
    ans = 0
    sub = 0
    for i in range(1, N):
        if (H_i[i-1] >= H_i[i]):
            sub += 1
            ans = max(ans, sub)
        else:
            sub = 0
    return ans

N = int(input())
H_i = list(map(int, input().split(" ")))
print(func(N, H_i))

Measured memory_bytes: 14252
#include<iostream>
#include<stdio.h>
using namespace std;

int main()
{
	int a, b,c;

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

	if (b > a) {
		c = a;
		a = b;
		b = c;
	}

	c = b;

	while (b != 0) {
		b = a % b;
		a = c;
		c = b;
	}

	cout << a << endl;

	return 0;

}


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

int main() {
  int n,m,c;
  cin >> n >> m >> c;
  vector<int> b(m);
  for(int i=0;i<m;i++)
    cin >> b.at(i);
  vector<vector<int>> a(n,vector<int>(m));
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      cin >> a.at(i).at(j);
    }
  }
  int lsum = 0;
  int count = 0;
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      lsum += a.at(i).at(j) * b.at(j);
    }
    if( lsum + c > 0 )
      count++;
    lsum = 0;
  }
  cout << count <<endl;    
}


Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

string s;

long long calc(string s, long long n){
    if (s==""){
        return n;
    }
    long long ret=0;
    for(int i=1; i<=(int) s.size(); i++){
        ret+=calc(s.substr(i),n+stoll(s.substr(0,i)));
    }
    return ret;
}

int main(){
    cin >> s;
    long long ans = calc(s,0);
    cout << ans << endl;
}

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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  lint n;
  cin >> n;
  vector< lint > x(n);
  for (lint i=0; i<n; ++i) cin >> x[i];
  lint ans = LLONG_MAX;
  for (lint p=0; p<=100; ++p) {
    lint cur = 0;
    for (lint i=0; i<n; ++i) {
      cur += (x[i]-p) * (x[i]-p);
    }
    ans = min(ans, cur);
  }
  cout << ans << endl;
  return 0;
}


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

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n;
    cin >> n;
    vector<vector<int>> mat(n, vector<int>(n, 0));
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < n; j++) {
            cin >> mat[i][j];
        }
    }
    auto count_bit = [&] (int x) -> int {
        int res = 0;
        while (x > 0) {
            res += 1;
            x -= x & (-x);
        }
        return res;
    };
    vector<ll> state(1<<n, 0);
    state[0] = 1;
    ll mod = 1e9 + 7;
    for(int i = 1; i < (1<<n); i++) {
        int row = count_bit(i) ;
        // printf("state [%d], row = %d\n", i, row);
        for(int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                if (mat[row-1][j] == 1) {
                    state[i] += state[i - (1 << j)];
                    state[i] %= mod;
                }
            }
        }

    }
    cout << state[(1<<n)-1] << endl;
    return 0;
}




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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

const int SIZE = 100;
ll n;
ll p[SIZE];


int main(){
    cin >> n;
    ll cou = 0;
    for(int i = 0; i < n; i++){
        cin >> p[i];
        if(p[i] != i+1) ++cou;
    }
    if(cou > 2){
        cout << "NO\n";
    }
    else{
        cout << "YES\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};


int main(void) {
  int n,k,r,s,p;
  cin >> n >> k >> r >> s >> p;
  string t;
  cin >> t;
  vector<vector<bool>> a(k, vector<bool>(3,true));
  int cnt = 0;
  rep(i,n){
    int aaa = i%k;
    if(t[i] == 'r' && a[aaa][0]){
      cnt += p;
      a[aaa][0] = false;
      a[aaa][1] = true;
      a[aaa][2] = true;
    }
    else if(t[i] == 's' && a[aaa][1]) {
      cnt += r;
      a[aaa][1] = false;
      a[aaa][0] = true;
      a[aaa][2] = true;
    }
    else if(t[i] == 'p' && a[aaa][2]){
      cnt += s;
      a[aaa][2] = false;
      a[aaa][1] = true;
      a[aaa][0] = true;
    }
    else{
      a[aaa][2] = true;
      a[aaa][1] = true;
      a[aaa][0] = true;
    }
  }
  cout << cnt << endl;
  
  
  
  
         
         
  
}


Measured memory_bytes: 6528
#include <cstdio>
#include <vector>
using namespace std;

#define si static inline
#define gcu getchar_unlocked
si int in() {
	int c, n = 0;
	bool minus = false;
	if ((c = gcu()) == '-') minus = true;
	else ungetc(c, stdin);
	while ((c = gcu()) >= '0' && c <= '9') n = 10 * n + (c - '0');
	return minus ? -n : n; }
#define pcu putchar_unlocked
si void out(int n) {
	static char buf[20];
	char *p = buf;
	bool minus = false;
	if(n < 0) minus = true, n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	if (minus) *p++ = '-';
	while (p != buf) pcu(*--p); }
si void out(const char *s){while(*s)pcu(*s++);}
si void out(char c){pcu(c);}
template <typename head, typename... tail>
si void out(head&& h, tail&&... t){out(h);out(move(t)...);}

typedef vector<int> v;
struct node { int p = -1, l = -1, r = -1;};
typedef vector<node> vn;

#define pb push_back
v buf[3];
void walk(vn &t, int n)
{
	buf[0].pb(n);
	if (t[n].l != -1) walk(t, t[n].l);
	buf[1].pb(n);
	if (t[n].r != -1) walk(t, t[n].r);
	buf[2].pb(n);

}

int main()
{
	int n = in();
	vn tree(n);

	while (n--) {
		int id = in();
		node &i = tree[id];
		i.l = in();
		i.r = in();
		if (i.l >= 0) tree[i.l].p = id;
		if (i.r >= 0) tree[i.r].p = id;
	}

	int root = 0;
	while (tree[root].p != -1)
		root = tree[root].p;
	walk(tree, root);

	const char w[][20] = {"Preorder", "Inorder", "Postorder"};
	for (v &b: buf) {
		out(w[&b - &buf[0]], '\n');
		for(int n: b)
			out(' ', n);
		out('\n');
	}
}



Measured memory_bytes: 2680
#include <cstdio>
#include <iostream>

using namespace std;

//4
//1 2 2 4
//2 1 4
//3 0
//4 1 3

//0 1 0 1
//0 0 0 1
//0 0 0 0
//0 0 1 0

int main() {

	int n;
	scanf("%d", &n);

	int G[n][n];
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j)
			G[i][j] = 0;
	}

	for (int i = 0; i < n; ++i) {
		int u, k;
		scanf("%d %d", &u, &k);
		for (int j = 0; j < k; ++j) {
			int v;
			scanf("%d", &v);
			G[i][v - 1] = 1;
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j)
			if (j != 0)
				cout << " " << G[i][j];
			else
				cout << G[i][j];
		cout << endl;
	}

	return 0;

}

Measured memory_bytes: 3104
S = input()
N = len(S)
out = "Yes"
if N%2==1:
    print("No")
else:
    for i in range(0,int(N//2)):
        if (S[2*i]=="h")and(S[2*i+1]=="i"):
            continue
        else:
            out = "No"
    print(out)


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
template<class T,class Y>T LCM(T a,Y b){return (a*b)/GCD(a,b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

using vi=vector<int>;
using vii=vector<vi>;

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(),(a).end()
#define decimal(x) fixed<<setprecision(x)


int main(){
    string S;
    cin>>S;
    if(S[0]==S[2]){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

//a=97,z=122

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,k;
    cin>>n>>k;
    ll ans=0;
    for(ll i=k;i<=n+1;i++){
        ans+=i*n-i*i+i+1;
        ans=ans%1000000007;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3652
import numpy as np
N,K = map(int,input().split())
A = np.int64(input().split())

d = [0]*40
for k in range(40):
    d[k] = np.sum(A%2**(k+1)//2**k)

dd = [0]*41
for k in range(40):
    dd[k] = dd[k-1]+max(d[k],N-d[k])*2**k

dp = [0]*(40)

for k in range(40):
    if K&2**k == 0:
        dp[k] = dp[k-1]+d[k]*2**k
    else:
        dp[k] = max(dp[k-1]+(N-d[k])*2**k,dd[k-1]+d[k]*2**k)

print(dp[-1])

Measured memory_bytes: 25996