akhauriyash/Code-Regression huggingface dataset:
// Author: πα

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

const int N = 1e5 + 5;
vector<int> g[N+N];
bool vis[N+N];
int cl, cr, ce;

void dfs(int u)
{
    if(vis[u])
        return;
    vis[u] = 1;
    if(u < N)
        cl++, ce += g[u].size();
    else
        cr++;
    for(auto v : g[u])
        dfs(v);
}

int main()
{
    int n, u, v, i;
    long ans = 0;
    cin >> n;
    for(i = 0; i < n; ++i)
    {
        cin >> u >> v;
        v += N;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(i = 1; i < N; ++i)
        if(not vis[i])
        {
            cl = cr = ce = 0;
            dfs(i);
            ans += 1LL * cl * cr - ce;
        }
    cout << ans;
    return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
//#define int ll
//#define int __int128
//#define ll __int128
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector< vvi > vvvi;
typedef vector<short> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<ld> vld;
typedef vector<vld> vvld;
typedef vector<vvld> vvvld;
typedef vector<string> vst;
typedef vector<vst> vvst;
typedef pair<ld, ld> pld;
typedef complex<double> base;

#define inmin(a, b) a = min(a, (b))
#define inmax(a, b) a = max(a, (b))
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define sqr(x) ((x) * (x))
#define fori(i, n) for(int i = 0; i < int(n); ++i)
#define SZ(a) ((int)((a).size()))
#define triple(T) tuple<T, T, T>
#define quad(T) tuple<T, T, T, T>
#define watch(x) cerr << (#x) << " = " << (x) << endl;

const double PI = 2 * acos(0.0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng_64(chrono::steady_clock::now().time_since_epoch().count());

const string DIGITS = "0123456789";
const string ALPH = "abcdefghijklmnopqrstuvwxyz";

template <class T0, class T1>
inline ostream & operator << (ostream &out, pair<T0, T1> &a) {
    return out << "{" << a.first << ", " << a.second << "}";
}

template <class T0, class T1, class T2>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << "}";
}

template <class T0, class T1, class T2, class T3>
inline ostream & operator << (ostream &out, tuple<T0, T1, T2, T3> &a) {
    return out << "{" << get<0>(a) << ", " << get<1>(a) << ", " << get<2>(a) << ", " <<  get<3>(a) << "}";
}

template<class T>
inline ostream & operator << (ostream &out, vector<T> &a) {
    out << "[";
    fori (i, a.size())
        out << a[i] << vector<string>{", ", "]  "}[i + 1 == a.size()];
    return out;
}

void smain();

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

#ifdef RUS_HOME
    freopen("input.txt", "r", stdin);
    clock_t start = clock();
#endif
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    cout << setprecision(12) << fixed;
    smain();
#ifdef RUS_HOME
    cout << "\n\nTOTAL EXECUTION TIME: " << float( clock () - start ) /  CLOCKS_PER_SEC << endl;
#endif
}
const int oo = 1e9;
const int N = 51;
int MOD = 1e9 + 7;



void smain() {

    string s;
    cin >> s;
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3])
        cout << "Bad";
    else
        cout << "Good";

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int num = 360;
        boolean flag=false;

        while(!flag){
            if(num % n == 0){
                flag=true;
                System.out.println(num/n);
            }else{
                num+=360;
            }
        }
    }
}

Measured memory_bytes: 35796
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int N,Ma,mb;
  cin>>N;
  int A[N],B[N];
  for(int i=0;i<N;i++) cin>>A[i]>>B[i];
  mb=B[0];
  Ma=A[0];
  for(int i=1;i<N;i++){
    mb=min(B[i],mb);
    Ma=max(A[i],Ma);
  }
  cout<<mb+Ma<<endl;
}



Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <tuple>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for(int i = (int)n - 1; j <= i; --i)

constexpr ll MOD = 0x3b9aca07;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;


int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	int n, m; cin >> n >> m;
	vector<int> ans(n, -1);
	bool ok = true;
	rep(i, 0, m) {
		int a, b; cin >> a >> b;
		--a;
		if (ans[a] != -1 && ans[a] != b) ok = false;
		ans[a] = b;
	}
	if (ans[0] == 0 && n != 1) ok = false;
	if (!ok) cout << -1;
	else rep(i, 0, n) {
		if (ans[i] == -1) {
			if (i == 0 && n != 1) cout << 1;
			else cout << 0;
		}
		else cout << ans[i];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
	int s=0;
	double w=0,h=0,BMI;
	while(scanf("%d,%lf,%lf",&s,&w,&h)!=EOF){
		BMI=w/(h*h);
		if(BMI>=25)cout<<s<<endl;
	}
	return 0;
}

Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a.at(i);
  }
  for(int i=0;i<n;i++){
    if(a.at(i)%2==0&&a.at(i)%3!=0&&a.at(i)%5!=0){
      cout<<"DENIED"<<endl;
      return 0;
    }
  }
  cout<<"APPROVED"<<endl;
}


Measured memory_bytes: 3632
import java.util.*;

public class Main{
    static double[][] D;
    static String[] S;
    static int H,W;
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        H = sc.nextInt();
        W = sc.nextInt();
        S = new String[H];
        
        D = new double[H][W];
        for(int i = 0; i < H; i++){
            S[i] = sc.next();
        }
        sc.close();

        int count = 0;
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if(S[i].charAt(j) == '#')
                    count++;
            }
        }
       
        for(int i = 0; i < H; i++){
           Arrays.fill(D[i], Double.POSITIVE_INFINITY);
        }
        D[0][0] = 0;

        dps(0, 0);

        /*for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                System.out.print(D[i][j] + " ");
            }
            System.out.println();
        }*/
        if(D[H-1][W-1] != Double.POSITIVE_INFINITY)
            System.out.println(H*W-(int)D[H-1][W-1]-count-1);
        else
            System.out.println(-1);
    }

    static void dps(int i, int j){
            if(i+1<H && S[i+1].charAt(j) == '.' ){
                if(D[i][j]+1 >= D[i+1][j]){}
                else {
                    D[i+1][j] = D[i][j]+1;
                    dps(i+1, j);
                }
            }
            if(i-1>=0 && S[i-1].charAt(j) == '.' ){
                if(D[i][j]+1 >= D[i-1][j]){}
                else {
                    D[i-1][j] = D[i][j]+1;
                    dps(i-1, j);
                }
            }
            if(j+1<W && S[i].charAt(j+1) == '.'){
                if(D[i][j]+1 >= D[i][j+1]){}
                else {
                    D[i][j+1] = D[i][j]+1;
                    dps(i, j+1);
                }
            }
            if(j-1>=0 && S[i].charAt(j-1) == '.'){
                if(D[i][j]+1 >= D[i][j-1]){}
                else {
                    D[i][j-1] = D[i][j]+1;
                    dps(i, j-1);
                }
            }

    }
}

Measured memory_bytes: 25792
import java.util.*;

class Main {
	Scanner sc;
	int N;
	int[] P, Q;
	
	private void calc() {
		sc = new Scanner(System.in);
		N = sc.nextInt();
		P = new int[N];
		Q = new int[N];
		for (int i = 0; i < N; i++) P[i] = sc.nextInt() - 1;
		for (int i = 0; i < N; i++) Q[i] = sc.nextInt() - 1;
		
		System.out.println(Math.abs(orderOf(P)-orderOf(Q)));
	}
	
	private int orderOf(int[] T) {
		List<Integer> order = new ArrayList<>();
		for (int i = 0; i < N; i++) order.add(i);
		
		int ans = 0;
		for (int i = 0; i < N; i++) {
			int o = order.indexOf(T[i]);
			ans = ans + o * factorial(N-1-i);
			order.remove(o);
		}
		return ans;
	}
	
	private static int factorial(int n) {
		if (n == 0) return 1;
		return n*factorial(n-1);
	}
	
	public static void main(String[] args) {
		new Main().calc();
	}
}

Measured memory_bytes: 23252
import numpy as np

H, W = map(int, input().split(' '))
S = []
for i in range(H):
  S.append([x=='#' for x in input()])
# print(S)
S = np.array(S)
C = np.zeros_like(S, dtype=np.int)
for h in range(H):
  for w in range(W):
    if h == 0 and w == 0:
      C[0, 0] = S[0, 0]
      continue
    candidates = []
    if h > 0:
      if S[h, w] and not S[h-1, w]:
        candidates.append(C[h-1, w] + 1)
      else:
        candidates.append(C[h-1, w])
    if w > 0:
      if S[h, w] and not S[h, w-1]:
        candidates.append(C[h, w-1] + 1)
      else:
        candidates.append(C[h, w-1])
    C[h, w] = min(candidates)
#print(C)
print(C[H-1, W-1])


Measured memory_bytes: 12548
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    
    odd, even = 0, 0
    cnt1 = 0
    for i in range(n):
        if i % 2 == 0:
            odd += a[i]
            if odd + even <= 0:
                tmp = 1 - (odd + even)
                odd += tmp
                cnt1 += tmp
        else:
            even += a[i]
            if 0 <= odd + even:
                tmp = -1 - (odd + even)
                even += tmp
                cnt1 += abs(tmp)
    
    odd, even = 0, 0
    cnt2 = 0
    for i in range(n):
        if i % 2 == 0:
            odd += a[i]
            if 0 <= odd + even:
                tmp = -1 - (odd + even)
                odd += tmp
                cnt2 += abs(tmp)
        else:
            even += a[i]
            if odd + even <= 0:
                tmp = 1 - (odd + even)
                even += tmp
                cnt2 += tmp
    
    ans = min(cnt1, cnt2)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 63216
import itertools
N, M, Q = map(int,input().split())
L = [k+1 for k in range(M)]
S = [list(map(int,input().split())) for _ in range(Q)]
ans = 0
for e in itertools.combinations_with_replacement(L,N):
    temp = 0
    for f in S:
        a, b, c, d = f[0]-1, f[1]-1, f[2], f[3]
        if e[b]-e[a] == c:
            temp += d
    ans = max(ans,temp)
print(ans)


Measured memory_bytes: 9216
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>

#ifdef PRINTERS
#include "printers.hpp"
using namespace printers;
#define tr(a)		cerr<<#a<<" : "<<a<<endl;
#else
#define tr(a)    
#endif

#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define endl        '\n'
#define rep(i,a,b)	for(int i=a;i<b;i++)
using namespace std;
int dp[2003][2003];
int x[2003][2003];
int l[2003][2003];
int u[2003][2003];
int dp2[2003][2003];
void solve(){
	int N,M,Q;
	cin>>N>>M>>Q;
	rep(i,1,N+1){
		string s;
		cin>>s;
		rep(j,1,M+1)x[i][j]=(s[j-1]=='1');
		rep(j,1,M+1)dp[i][j]=dp[i][j-1]+x[i][j];
		rep(j,1,M+1)dp[i][j]+=dp[i-1][j];
	}
	rep(i,1,N+1){
		rep(j,1,M+1){
			l[i][j]=(x[i][j] and x[i][j-1]);
			u[i][j]=(x[i][j] and x[i-1][j]);
		}
		rep(j,1,M+1)l[i][j]+=l[i][j-1],u[i][j]+=u[i][j-1];
		rep(j,1,M+1)l[i][j]+=l[i-1][j],u[i][j]+=u[i-1][j];
	}
	while(Q--){
		int x1,y1,x2,y2;
		cin>>x1>>y1>>x2>>y2;
		int ans=dp[x2][y2]+dp[x1-1][y1-1]-dp[x2][y1-1]-dp[x1-1][y2];
		//(x1,y1+1)..(x2,y2) - lsum
		//(x1+1,y1)..(x2,y2) - usum
		ans-=l[x2][y2]+l[x1-1][y1]-l[x1-1][y2]-l[x2][y1];
		ans-=u[x2][y2]+u[x1][y1-1]-u[x2][y1-1]-u[x1][y2];
		cout<<ans<<endl;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 65920
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp;

#[fastout]
fn main() {
  input! {
    a: i64,
    b: i64,
    c: i64,
    mut k: i64,
  }
  let mut sum = 0;
  let ca = cmp::min(a, k);
  sum += ca;
  k -= ca;
  let cb = cmp::min(b, k);
  k -= cb;
  let cc = cmp::min(c, k);
  sum -= cc;

  println!("{}", sum);
}


Measured memory_bytes: 2172
MOD = 998244353
N, S = map(int, input().split())
A = list(map(int, input().split()))

dp = [[0 for i in range(S + 1)] for j in range(N + 1)]

dp[0][0] = 1

for i in range(N):
    for j in range(S + 1):
        dp[i+1][j] += dp[i][j] * 2
        dp[i+1][j] %= MOD
        if j + A[i] <= S:
            dp[i + 1][j + A[i]] += dp[i][j]
            dp[i + 1][j + A[i]] %= MOD
print(dp[N][S])


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

int main() {
    int n, k, x, ans = 0;
    cin >> n >> k;
    rep(i, n) {
        cin >> x;
        if(2 * x <= 2 * (k - x)) {
            ans += 2 * x;
        }
        else {
            ans += 2 * (k - x);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
int n, k;
int dp[101][100001];
int S[101][100001];
int a[100001];
int main()
{
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  cin >> n >> k;
  for(int i = 1;i <= n;i++)
    cin >> a[i];
  dp[0][0] = 1;
  S[0][0] = 1;
  for(int i = 1;i <= k;i++)
    S[0][i] = 1;
  for(int i = 1;i <= n;i++){
    for(int j = 0;j <= k;j++){
      dp[i][j] = ((1LL * S[i - 1][j] - (j - a[i] - 1 >= 0 ? S[i - 1][j - a[i] - 1] : 0)) % MOD + MOD) % MOD;
    }
    S[i][0] = dp[i][0];
    for(int j = 1;j <= k;j++)
      S[i][j] = (1ll * S[i][j - 1] + dp[i][j]) % MOD;
  }
  cout << dp[n][k];
  return 0;
}


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

int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  int n,m;
  priority_queue<ll>d;
  priority_queue<ll>t;
  cin >> n ;
  rep(i,n){
    ll D;
    cin >> D;
    d.push(D);
  }
  cin >> m;
  rep(i,m){
    ll T;
    cin >> T;
    t.push(T);
  }
  
  if(n<m){
    cout<<"NO"<<endl;
    return 0;
  }
  else{
    while(t.size()&&d.size()){
      if(d.top()!=t.top()){
        d.pop();
      }
      else{
        d.pop();
        t.pop();
      }
    }
    if(t.size()==0 && d.size()>=0){
      cout<<"YES"<<endl;
    }
    else cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 4848
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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<_>>()
    };

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"7 4"# => "6",
// r#"24"# => "No",
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: f64,
        b: f64,
    }

    (((a + b) / 2f64).round() as i64).to_string()
}

Measured memory_bytes: 4352
#include<iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
#define req(i,n) for(int i = 1;i <= n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define ALL(a)  (a).begin(),(a).end()
#define fix  fixed << setprecision(10)
const ll INF = (1LL << 60);
string s, t; ll n, m, p, q, ans = 0, sum = 0, num = 0;
const int MAX = 510000;
const int MOD = 1000000007;
int main() {
    cin >> n >> m; vector<int> a(n,1);
    vector<bool> b(n ,false);
    b[0] = true;
    rep(i, m) {
        cin >> p >> q;
        --a[p - 1]; ++a[q - 1];
        if (b[p - 1])b[q - 1] = true;
        if (a[p - 1] == 0)b[p - 1] = false;
    }
    rep(i, n) {
        if (b[i])sum++;
    }
    cout << sum << endl;
}

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

int main(){
  int a,b,k;
  cin >> a >> b >> k;
  int cnt=0;
  
  for(int i=100;i>0;i--){
    if(a%i==0&&b%i==0){
      cnt++;
    }
    if(cnt==k){
      cout << i << endl;
      break;
    }
  }
}
      

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

int N;
vector<int> H;

int main() {
    string answer = "Yes";
    cin >> N;
    for(int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        H.emplace_back(tmp);
    }
    H[0] -= 1;
    for(int i = 1; i < N; i++) {
        if(H[i] - H[i - 1] == 0) continue;
        else if(H[i] - H[i - 1] > 0) {
            H[i] -= 1;
            continue;
        }
        else {
            answer = "No";
            break;
        }
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 892
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 205050

ll n,m;
ll p;

main(){
    n=in();
    int p[200];
    int a=in(),b=in();
    rep(i,n)p[i]=in();
    int s[3]={};
    rep(i,n){
        if(p[i]<=a){
            s[0]++;
        }
        else if(p[i]>b)s[2]++;
        else s[1]++;
    }
    cout<<min({s[0],s[1],s[2]});
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using pll = pair<ll,ll>;
using Graph = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i,l,r) for(ll i = (l); i <= (ll)(r); i++)
#define rep3(i,l,r) for(ll i = (l); i >= (ll)(r); i--)
#define dup(x,y) (((x)+(y)-1)/(y)) // x/yの除算の切り上げ
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int inf = 1001001001;
const ll INF = 1LL << 60;
const ll mod = 1000000007; //1000000007
const ld pi = acos(-1);
 
//xor演算
//a^b=b^a
//a^(b^c)=(a^b)^c
//a^a=0
//a+b=a^b + 2(a&b)
//(4a)^(4a+1)^(4a+2)^(4a+3)=0

//セグメント木
//全て添字で扱うこと
// segment_tree seg;
// seg.build(配列名, 単位元)で宣言
// seg.build(a,0)
struct segment_tree{
    ll n; //vの要素数
    ll m; //葉の数
    vector<ll> v; //セグ木本体．ただの配列を使う
    ll id_e; //単位元 区間の和なら0、区間の積なら1、最大値なら-1とか、最小値ならINF、最大公約数なら0
 
    //二項演算
    ll binary_op(ll a,ll b){
        return max(a,b);//処理 区間の和ならa+b、区間の積ならa*b、最大値ならmax(a,b)、最初値ならmin(a,b)、最大公約数ならgcd(a,b)
    }
 
    //初期化関数．数列と単位元を受け取って初期化
    void build(vector<ll> a,ll b){
        id_e = b;
        m = 1;
        while(m<(ll)a.size()) m*=2; //aの項数以上の2べきのうち最小のものを求める
        n = 2*m-1;
        v.resize(n);
        for (ll i=0; i<(ll)a.size(); i++) v[m-1+i]=a[i]; //葉(1段目)の値
        for (ll i=a.size(); i<m; i++) v[m-1+i]=id_e; //葉(1段目)の右端の0埋め
        for (ll i=m-2; i>=0; i--){ //2段目以降を順番に埋めていく
        v[i]=binary_op(v[2*i+1],v[2*i+2]);
        }
    }
 
    //ある項の値をbに書き換え
    void update(ll a,ll b) {
        a+=(m-1);
        v[a]=b; //葉(1段目)を書き換え
        while((a-1)/2 != a){ //2段目以降を順番に書き換え
            a=(a-1)/2;
            v[a]=binary_op(v[2*a+1],v[2*a+2]);
        }
    }
 
    //区間和の補助関数
    //cur:今見ている頂点の，配列vでの添字
    //[l, r]:v[cur]がカバーする区間
    ll seg_sub(ll a,ll b,ll cur,ll l,ll r){
        if(a<=l && r<=b) return v[cur]; //今見ている頂点のカバーする区間が，[a,b]に完全に収まっている場合
        if(r<a || b<l) return id_e; //今見ている頂点のカバーする区間が，[a,b]と全く被っていない場合
        return binary_op( //今見ている頂点のカバーする区間が，[a,b]と一部被っている場合
            seg_sub(a,b,2*cur+1,l,(l+r)/2),
            seg_sub(a,b,2*cur+2,(l+r)/2+1,r)
        );
    }
 
    //区間[a, b]の和
    //最上段の頂点から子へ再帰していく
    ll partial_sum(ll a,ll b){return seg_sub(a,b,0,0,m-1);}
    };
 
 
int main(){
 
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n){
        cin >> a[i];
    }
    segment_tree seg;
    seg.build(a,0);
    rep(i,n){
        if(i==0){
            cout << seg.partial_sum(1,n-1) << endl;
            continue;
        }
        if(i==n-1){
            cout << seg.partial_sum(0,n-2) << endl;
            continue;
        }
        cout << max(seg.partial_sum(0,i-1),seg.partial_sum(i+1,n-1)) << endl;
    }

 
 
 
}

Measured memory_bytes: 10576
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
if A - B >= 0 :
    C = A - B
else:
    C = B - A
X = V - W
Z = T * X
if C - Z > 0:
    print("NO")
else:
    print("YES")

Measured memory_bytes: 9188
#include<stdio.h>
int main()
{
        int a,b;

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

        if(((a>0)&&(a<10))&&((b>0)&&(b<10))){
                int s;
                s=a*b;
                printf("%d\n",s);
        }
        else{
                 printf("-1\n");
        }

        return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
using namespace std;
typedef long long ll;
 
int main(){
	ios::sync_with_stdio(false);
	int H,W,D,Q;
	cin>>H>>W>>D;
	vector<vector<tuple<int,int,int,int>>> tab(D,vector<tuple<int,int,int,int>>());
	for(int i=1;i<=H;i++){
		for(int j=1;j<=W;j++){
			int n;
			cin>>n;
			tab[n%D].push_back(make_tuple(n,i,j,0));
		}
	}
	cin>>Q;
	vector<int> L(Q),R(Q);
	for(int i=0;i<Q;i++) cin>>L[i]>>R[i];
	for(int i=0;i<D;i++) sort(tab[i].begin(),tab[i].end());
	for(int i=0;i<D;i++){
		for(int j=0;j<tab[i].size();j++){
			if(j==0) continue;
			get<3>(tab[i][j]) = get<3>(tab[i][j-1]) + abs(get<1>(tab[i][j])-get<1>(tab[i][j-1])) + abs(get<2>(tab[i][j])-get<2>(tab[i][j-1]));
		}
	}
	for(int i=0;i<Q;i++){
		cout<<get<3>(tab[R[i]%D][(R[i]-1)/D])-get<3>(tab[L[i]%D][(L[i]-1)/D])<<endl;
	}
	return 0;
}

Measured memory_bytes: 6144
#include <iostream>
#include <sstream>

int main () {
  int n1,cnt=0;
  std::cin>>n1;
  int S[n1];
  for(int i=0;i<n1;i++){
    std::cin>>S[i];
  }
  int n2;
  std::cin>>n2;
  int T[n2];
  for(int i=0;i<n2;i++){
    std::cin>>T[i];
  }
  for(int i=0;i<n2;i++){
    for(int j=0;j<n1;j++){
      if(S[j]==T[i]){
	cnt++;
	break;
      }
    }
  }

  std::cout<<cnt<<'\n';
  return 0;
}


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

template<typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}

const int maxn = 15;

int n;
pair<int,int> g[maxn];

double dist(int i, int j) {
  double xVal = (g[i].first - g[j].first)*(g[i].first - g[j].first);
  double yVal = (g[i].second - g[j].second)*(g[i].second - g[j].second);
  return sqrt(xVal + yVal);
}

int main() {

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

  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> g[i].first >> g[i].second;
  }

  int occ = 1;
  for (int i = 1; i <= (n-1); i++) {
    occ = occ * i;
  }

  double ans = 0;
  for (int i = 1; i <= (n-1); i++) {
    for (int j = i+1; j <= n; j++) {
      ans += dist(i,j)*occ*2;
    }
  }

  cout << fixed << setprecision(12) << ans/(occ*n) << endl;

  return 0;
}


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

int main(){
  int N;
  cin >> N;
  double A = 0, B = 0, ans;
  for(int i = 0; i < N; i++){
    cin >> A;
    A = 1 / A;
    B += A;
  }
  ans = 1 / B;
  cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;

const int nax = 1e5 + 5;
vector<int> edges[nax];
int in_degree[nax]; // the number of edges going to 'b'
int dist[nax];
bool visited[nax];

void dfs(int a) {
        visited[a] = true;
        for(int b = 0 ; b<edges[a].size();b++) {
            if(!visited[edges[a][b]])dfs(edges[a][b]);
            dist[a] = max(dist[a],dist[edges[a][b]]+1);
        }

}

int main() {
    int n, m;
    cin>>n>>m;
    while(m--) {
        int a, b;
        cin>>a>>b;
        edges[a].push_back(b);
    }
    for(int i = 1; i <= n; ++i) {
        if(!visited[i]) {
            dfs(i);
        }
    }
    int answer = 0;
    for(int i = 1; i <= n; ++i) {
        answer = max(answer, dist[i]);
    }
    cout<<answer;
}


Measured memory_bytes: 12268
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	pre := 0
	ans := 0
	for i := 0; i < n; i++ {
		var h int
		fmt.Scan(&h)
		if pre <= h {
			ans++
			pre = h
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
char s[MAXN];
int main() {
	scanf("%s", s + 1);
	int n = strlen(s + 1);
	ll ans = 0; int now = 0, pos = 1;
	while (pos <= n) {
		if (s[pos] == 'A') now++, pos++;
		else if (s[pos] == 'B' && s[pos + 1] == 'C') ans += now, pos += 2;
		else now = 0, pos++;
	}
	writeln(ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define LOCAL
#pragma region Macros
typedef long long ll;
#define ALL(x) (x).begin(),(x).end()
const long long MOD=1e9+7;
// const long long MOD=998244353;
const int INF=1e9;
const long long IINF=1e18;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
const char dir[4]={'D','R','U','L'};

template<typename T>
istream &operator>>(istream &is,vector<T> &v){
    for (T &x:v) is >> x;
    return is;
}
template<typename T>
ostream &operator<<(ostream &os,const vector<T> &v){
    for (int i=0;i<v.size();++i){
        os << v[i] << (i+1==v.size()?"": " ");
    }
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const pair<T,U> &p){
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template<typename T,typename U>
ostream &operator<<(ostream &os,const map<T,U> &m){
    os << '{';
    for (auto itr=m.begin();itr!=m.end();++itr){
        os << '(' << itr->first << ',' << itr->second << ')';
        if (++itr!=m.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os,const set<T> &s){
    os << '{';
    for (auto itr=s.begin();itr!=s.end();++itr){
        os << *itr;
        if (++itr!=s.end()) os << ',';
        --itr;
    }
    os << '}';
    return os;
}

void debug_out(){cerr << '\n';}
template<class Head,class... Tail>
void debug_out(Head&& head,Tail&&... tail){
    cerr << head;
    if (sizeof...(Tail)>0) cerr << ", ";
    debug_out(move(tail)...);
}
#ifdef LOCAL
#define debug(...) cerr << " ";\
cerr << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << '\n';\
cerr << " ";\
debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

template<typename T> T gcd(T x,T y){return y!=0?gcd(y,x%y):x;}
template<typename T> T lcm(T x,T y){return x/gcd(x,y)*y;}

template<class T1,class T2> inline bool chmin(T1 &a,T2 b){
    if (a>b){a=b; return true;} return false;
}
template<class T1,class T2> inline bool chmax(T1 &a,T2 b){
    if (a<b){a=b; return true;} return false;
}
#pragma endregion

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,X,T; cin >> N >> X >> T;
    cout << T*((N+X-1)/X) << '\n';
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,sum=0;
  cin>>n;
  vector<int> l(n);
  for(int i=0;i<n;i++){
    cin>>l[i];
  }
  sort(l.begin(),l.end());
  for(int i=0;i<n-1;i++){
    sum+=l[i];
  }
  if(l[n-1]<sum)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}
  

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,k;
    while(cin>>n>>k){
        double ans = 0.0f;
        for(int i=1;i<=n;i++){
            int t = i;
            double p = 1.0f;
            
            while(t<k){
                t = (t*2);
                p /= 2.0f;
            }

            ans += ((1/(double)n) * p);
        }
        printf("%.12f\n",ans);
    }

    return 0;
 
}

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

#define ran 101101

int n;
int dp[ran][3];

int main() {
	scanf("%d", &n);
	for(int i=1;i<=n;i++) {
		int a[3]; 
		for(int j=0;j<3;j++)scanf("%d", &a[j]);
		for(int j=0;j<3;j++)
			for(int k=0;k<3;k++) {
				if(k==j) continue;
				dp[i][j] = max(dp[i][j], dp[i-1][k] + a[j]);
			}
	}
	printf("%d\n", max(dp[n][0], max(dp[n][1], dp[n][2])));
	
	return 0;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

bool isprime(int x){
	for (int i = 2; i*i<=x; i++){
		if(x%i==0)return false;
	}
	return true;
}

int main()
{
	int x;
	cin>>x;
	while(!isprime(x))x++;
	cout<<x<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <functional>
using namespace std;
using ll = long long;
#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
constexpr int MAX_N = 2e5;
int h[MAX_N], a[MAX_N];
template<class T> struct SegTree {
  private:
    int size;
    vector<T> v;
    using F = function<T(T,T)>;
    T default_value; F f;
  public:
    constexpr SegTree(int n, T default_value, F f) : default_value(default_value), f(f) {
      size = 1; while (size < n) size *= 2;
      v.resize(2 * size - 1, default_value);
    }
    constexpr void update(int index, T val) {
      index = index + size - 1;
      v[index] = val;
      while (index > 0) {
        index = (index - 1) / 2;
        v[index] = f(v[2 * index + 1], v[2 * index + 2]);
      }
    }
    constexpr T query(int l, int r) { return query(l, r, 0, size, 0); }
    constexpr T query(int l, int r, int cur_l, int cur_r, int index) {
      if (cur_r <= l || r <= cur_l) return default_value;
      if (l <= cur_l && cur_r <= r) return v[index];

      int mid = (cur_l + cur_r) / 2;
      return f(query(l, r, cur_l, mid, 2 * index + 1), query(l, r, mid, cur_r, 2 * index + 2));
    }
};

constexpr int INF = 1e9;
int main() {
  int in(N);

  SegTree<ll> T(N+1, -INF, [](ll a, ll b){return max(a, b);}); // 範囲max
  T.update(0, 0);

  rep(i, N) cin >> h[i];
  rep(i, N) cin >> a[i];

  rep(i, N) T.update(h[i], T.query(0, h[i]) + a[i]);

  cout << T.query(0, N+1) << endl;
  return 0;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >>A >>B >>C >>D;
  if (A+B>C+D) {
   cout << "Left" <<endl;
  }
   else if (A+B==C+D) {
   cout << "Balanced" <<endl;
  }
  else cout << "Right" <<endl;  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#define int long long
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, m;
int x[1000], y[1000], z[1000];
int a[1000];

signed main() {
	int i, j;
	
	cin >> n >> m;
	rep(i, n) cin >> x[i] >> y[i] >> z[i];
	
	int ans = 0;
	rep(i, 8) {
		rep(j, n) {
			a[j] = 0;
			if (i % 2 == 1) a[j] -= x[j]; else a[j] += x[j];
			if ((i / 2) % 2 == 1) a[j] -= y[j]; else a[j] += y[j];
			if ((i / 4) % 2 == 1) a[j] -= z[j]; else a[j] += z[j];
		}
		sort(a, a + n, greater<int>());
		
		int score = 0;
		rep(j, m) {
			score += a[j];
		}
		ans = max(ans, score);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.ArrayList;
import java.util.List;


class Main {
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			
			int verticalLine = Integer.parseInt(br.readLine());//???????????¬??°
			int horizontalLine = Integer.parseInt(br.readLine());//?¨?????????°
			List<Integer> lots = new ArrayList<>();//?????????????´????????????????
			
			for(int i=0; i<verticalLine; i++){
				lots.add(i+1);//???????????????????????????????????????????????? ex) ???????????°??????1??????????????????[1], 2??????????????????[2]...
			}
			
			for(int j=1; j<horizontalLine+1; j++){
				String line = br.readLine();
				String[] dataSet = line.split(",");
				
				lots = swap(lots, Integer.parseInt(dataSet[0]), Integer.parseInt(dataSet[1]));
			}
			
			for(int k=0; k<lots.size(); k++){
				System.out.println(lots.get(k));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/*
	 * ???????????\????????????????????????
	 * @param ??????????????????????´???????????????????
	 * @param ??\????????????????????????????????????
	 * @param ??\????????????????????????????????????
	 *
	 */
	private static List<Integer> swap(List<Integer> lots, int index1, int index2) {
		int tmp = lots.get(index1-1);
		lots.set(index1-1, lots.get(index2-1));
	    lots.set(index2-1, tmp);
	    return lots;
	}
}

Measured memory_bytes: 24028
#!/usr/bin python3
# -*- coding: utf-8 -*-

# ループを検索して計算量圧縮
# 0->1->...->st->st+1->...->st+lp-1-┐
#             └─────────────────────┘
#                       lp

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

def next(x):
    ret = pow(x,2,m)
    return ret

seen = set([])
seqs = []
for i in range(m+1):
    seen.add(x)
    seqs.append(x)
    x = next(x)
    if x in seen:
        break
start = seqs.index(x)
lp = len(seqs) - start

lpsum = sum(seqs[start:])
lptimes = (n-(start+lp)+(lp-1))//lp
ret_sum = lpsum * lptimes
n -= lp * lptimes
ret_sum += sum(seqs[:n])
ret_val = seqs[n-1]

print(ret_sum)
#print(ret_val)

Measured memory_bytes: 13116
import sys
max_int = 1000000001  # 10^9+1
min_int = -max_int

n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
a_ = a[::-1]

sum = 0
prev_min = 0
prev_max = 0

prev = []

for num, one in enumerate(a_):
    prev_min = (prev_min + 1) // 2 + one
    prev_max += one
    level_maximum = 2 ** (len(a) - 1 - num)
    if prev_min > level_maximum:
        print(-1)
        exit()

    prev_max = min(level_maximum, prev_max)
    prev.append([prev_min, prev_max])

prev = prev[::-1]

sum = 0
available = 1
for one in zip(prev, a):
    available = min(available, one[0][1])
    sum += one[1]
    available -= one[1]
    sum += available

    available *= 2

print(sum)

Measured memory_bytes: 92208
from collections import defaultdict, deque, Counter
import sys
import bisect
import heapq
import math

# input = sys.stdin.readline

sys.setrecursionlimit(1000000000)

MIN = -10 ** 9
MOD = 10 ** 9 + 7

ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"


def main():
    N = int(input())
    S = input()

    res = ""
    for i in range(len(S)):
        c = S[i]
        ind = ALPHA.index(c)
        kk = (ind + N) % len(ALPHA)
        res += ALPHA[kk]
    print(res)

    # A, B = [int(a) for a in input().split()]


if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define MAX 305


using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll MOD = 1000000007;

int n;
ll A[300005],ans=0,maxA=-1;

int GetDigit(ll num){
    int digit=0;
    while(num!=0){
        num /= 2;
        digit++;
    }
    return digit;
}

int main(){
  cin >> n;
  rep(i,n){
    cin >> A[i];
    if(maxA<A[i]){
      maxA=A[i];
    }
  }
  int dig=GetDigit(maxA);
  for(int i=0;i<=dig;i++){
    ll zero=0,one=0;
    rep(j, n){
      if((A[j]>>i)&1){
        one++;
      } else {
        zero++;
      }
    }
    //ans+=one*zero*(1<<i);
    ll num=one*zero;
    rep(k,i){
      num=(num*2)%MOD;
    }
    ans+=num;
    ans%=MOD;
  }
  cout << ans << endl;
  return 0;
}


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

int sum(int x)
{
	int re;
	re=0;
	while(x!=0)
	  {	
	  	re+=x%10;
	  	x/=10;
	  }
	 return re; 
}

int main() {
	int i,n,a,b,ans=0; cin>>n>>a>>b;
	for(i=1;i<=n;i++)
	  {
	  	  if(sum(i)>=a && sum(i)<=b)
	  	    ans+=i;
	  }
	 cout<<ans<<"\n"; 
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fastio     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define debug(x)   cerr<<#x<<": "<<x<<endl;
#define all(x)     (x).begin() , (x).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl       '\n'
#define MAX        1000000
typedef long long int ll;
using namespace std;

const ll mod = 1e9+7;





void solve(){
    ll k;
    cin>>k;
    ll ans=0;
    for(ll i=1;i<=k;++i){
        for(ll j=1;j<=k;++j){
            for(ll l=1;l<=k;l++){
                ans += __gcd(__gcd(i , j) , l);
            }
        }
    }
    cout<<ans;
}





int main(){
    fastio
    int test=1;
    while(test--)
        solve();
    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
const int N=100001;

ll n;
vector<ll> adj[N];
ll dp[N][2];

ll solve(ll src,bool boundto,ll pr){
	
	if(dp[src][boundto]!=-1)
	return dp[src][boundto];
	
	ll ans=0;
	ll w1=1;
	for(auto child : adj[src]){
		if(child!=pr){
			w1=(w1*solve(child,0,src))%mod;
		}
	}
	ans+=w1;
	if(!boundto){
		ll w2=1;
	    for(auto child : adj[src]){
		if(child!=pr){
			w2=(w2*solve(child,1,src))%mod;
		}
	}	
	ans=(ans+w2)%mod;
	}
	return dp[src][boundto]=ans;
}

int main(){
   cin>>n;
   for(ll i=0;i<n-1;i++){
   	ll u,v;
   	cin>>u>>v;
   	adj[u].push_back(v);
    adj[v].push_back(u);   
   }	
   memset(dp,-1,sizeof(dp));
   cout<<solve(1,0,-1)<<endl;
}

Measured memory_bytes: 15616
M=998244353
N=int(input())
d=[0]*90001
d[0]=1
e=[0]*90001
e[0]=1
z=1
s=0
for _ in range(N):
	a=int(input())
	i=s
	while i>=0:
		d[i+a]+=d[i]
		d[i+a]%=M
		d[i]*=2
		d[i]%=M
		e[i+a]+=e[i]
		e[i+a]%=M
		i-=1
	s+=a
	z=z*3%M
for i in range(s+1>>1,s+1):
	z-=d[i]*3
	z%=M
print([(z+e[s//2]*3)%M,z][s%2])


Measured memory_bytes: 44652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll N;
struct Node {
  ll x, y;
  Node() = default;
  Node(int a, int b) : x(a), y(b) {}
  friend bool operator<(const Node& n1, const Node& n2) {
    if (n1.x != n2.x) return n1.x < n2.x;
    return n1.y < n2.y;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  vector<Node> v(N);
 
  int vmin = INT_MAX;
  int imin = -1;
  int vmax = INT_MIN;
  int imax = -1;
  for (int i = 0; i < N; ++i) {
    int x, y;
    cin >> x >> y;
    if (x > y) swap(x, y);
    v[i].x = x;
    v[i].y = y;
  }
 
  sort(v.begin(), v.end());
 
  for (int i = 0; i < N; ++i) {
    int x = v[i].x;
    int y = v[i].y;
    if (vmin > x) {
      vmin = x;
      imin = i;
    }
 
    if (vmax < y) {
      vmax = y;
      imax = i;
    }
  }
 
  ll ret = 1LL << 62;
  const ll rmin = vmin;
  // if bmax = vmax;
  ll bmax = vmax;
 
  ll rmax = rmin;
  ll bmin = bmax;
 
  for (auto& n : v) {
    rmax = max(rmax, n.x);
    bmin = min(bmin, n.y);
  }
 
  ret = min(ret, (rmax - rmin) * (bmax - bmin));
  // if rmax = vmax;
  rmax = vmax;
 
  multiset<int> st;
  vector<Node> bv;
  for (int i = 0; i < N; ++i) {
    if (i != imin && i != imax) {
      bv.push_back(v[i]);
      st.insert(v[i].x);
    }
  }
  st.insert(v[imin].y);
  st.insert(v[imax].x);
 
  bmin = *st.begin();
  bmax = *st.rbegin();
  ret = min(ret, (rmax - rmin) * (bmax - bmin));
  for (int i = 0; i < bv.size(); ++i) {
    auto const& c = bv[i];
    // if (c.x > *st.begin()) break;
    st.erase(st.find(c.x));
    st.insert(c.y);
    bmin = *st.begin();
    bmax = *st.rbegin();
 
    ret = min(ret, (rmax - rmin) * (bmax - bmin));
  }
 
  cout << ret << endl;
}

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

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    string S;

    ist >> S;

    /* ------- 計算 ------- */

    string ans = "No";

    for (int i = 0; i < S.length()/2; i = i + 2)
    {
        if (S[i] == 'h' && S[i + 1] == 'i')
        {
            ans = "Yes";
        }
        else
        {
            ans = "No";
        }
    }

    if(S.length() %2==1 ){
        ans = "No";
    }

    ost << ans << endl;
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


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

using namespace std;

int main(){
    int N; cin >> N;
    vector<long long> a(N+1);
    for(int i=0; i<=N; ++i){
        cin >> a[i];
    }

    //from back to top; calculate available nodes
    vector<pair<long long, long long> > available_range(N+1);
    for(int i=N; i>=0; --i){
            long long mmin;
            long long mmax; 
        if( i == N){
            mmin = a[i];
            mmax = a[i]; 

        }else{
            mmin = (available_range[i+1].first + 1 )/2;
            if(mmin == 0) mmin = 1;
            mmin += a[i];
            mmax = available_range[i+1].second + a[i];
        }
        available_range[i].first = mmin;
        available_range[i].second = mmax;
    }

    //check if the depth array is avalable or not. if root[0] contains 1, then it should be fine.
    if(available_range[0].first == 1 || available_range[0].second < 1){
        long long res = 1;
        // long long pre_available_edge = 1;
        // long long curr_available_edge = 1;
        long long next_available_edge = 1;
        for(long long i=1; i<available_range.size(); ++i){           
            next_available_edge = next_available_edge * 2;
            next_available_edge = min(next_available_edge, available_range[i].second);
            res += next_available_edge;
            next_available_edge -= a[i];
            // curr_available_edge = min( pre_available_edge * 2, available_range[i].second);
            // res += curr_available_edge;
            // pre_available_edge = curr_available_edge;
            // pre_available_edge -= a[i];
        }
        cout << res << endl;
    }else{
        cout << -1 << endl;
    }

}

Measured memory_bytes: 5644
#include<cstring>
#include<iostream>
#include<algorithm>
#include<string>
#define rep(i,n) for (int i = 0; i <= (n); ++i)
using ll = long long;
using namespace std;

int main() {
    int n;
    cin >> n;
    ll ans = n * n * n;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main (){
	
	int a,b,i;
	
	scanf("%d",&a);
	scanf("\n%d",&b);
	
	if(a==1 && b==2 || a==2 && b==1){
		printf("3\n");
	}else if (a==1 && b==3 || a==3 && b==1){
		printf("2\n");
	}else {
		printf("1\n");
	}
return 0;
}


Measured memory_bytes: 3140
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		int counter = 0;
		for(int i = 0;i < (S.length() - T.length() + 1);i++){
			int count2 = 0;
			for(int j = 0;j < T.length();j++){
				if(S.charAt(i + j) == T.charAt(j)){
					count2++;
				}
			}
			counter = Math.max(counter,count2);
		}
		System.out.println(T.length() - counter);
	}
}

Measured memory_bytes: 27004
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
#define lambdify(x) [&](auto &&...args){ return x(forward<decltype(args)>(args)...); }
template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	long long n;
	cin >> n;
	int res = 0;
	for(auto p = 2LL; p * p <= n; ++ p){
		if(n % p == 0){
			int cnt = 0;
			while(n % p == 0){
				n /= p;
				++ cnt;
			}
			int t = 1;
			while((t + 2) * (t + 1) / 2 <= cnt){
				++ t;
			}
			res += t;
		}
	}
	if(n > 1){
		++ res;
	}
	cout << res;
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

Measured memory_bytes: 3652