akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

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

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)


int main() {

  const ll MOD = 1e9 + 7;
  ll N, M;
  cin >> N >> M;
  vector<ll> v1(N), v2(M);
  REP(i, N) cin >> v1[i];
  REP(i, M) cin >> v2[i];

  //ll dp[N][M] = {{0}};
  vector<vector<ll>> dp(N + 1, vector<ll>(M + 1, 0LL));
  vector<vector<ll>> sum(N + 1, vector<ll>(M + 1, 0LL));
  //ll sum[N][M] = {{0}};

  REP(i, N){
    REP(j, M){
      if (v1[i] == v2[j]){
        dp[i + 1][j + 1] = (sum[i][j] + 1) % MOD;
      }
      //sum[i + 1][j + 1] = (((((sum[i + 1][j] - sum[i][j]) % MOD)  + sum[i][j + 1]) % MOD) + dp[i + 1][j + 1]) % MOD;
      sum[i + 1][j + 1] = (sum[i][j + 1] + sum[i + 1][j] + dp[i + 1][j + 1]) % MOD;
      //sum[i + 1][j + 1] %= MOD;
      sum[i + 1][j + 1] = (sum[i + 1][j + 1] + MOD - sum[i][j]) % MOD;
    }
  }
  ll ans = (sum[N][M] + 1) % MOD;
  //ll ans = 1;
  //REP(i, N)REP(j, M) ans = (ans + dp[i + 1][j + 1]) % MOD;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 62976
import Control.Monad
main = do
    n <- readLn
    numlists <- replicateM n (fmap (map read.words) getLine)
    mapM_ (yesOrNo.foldl (>>=) (Just (0,0)).map insert) numlists

yesOrNo x = case x of
              Just _ -> putStrLn "YES"
              Nothing -> putStrLn "NO"

insert n (l,r)
  | l < n = Just (n,r)
  | r < n = Just (l,n)
  | otherwise = Nothing

Measured memory_bytes: 3948
#include<bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long N;
    cin >> N;
    unsigned long long sum_all = N*(N+1)/2;
    unsigned long long max_3 = N/3;
    unsigned long long max_5 = N/5;
    unsigned long long max_15 = N/15;
    unsigned long long sum_3 = 3 * max_3 * (max_3 +1)/2;
    unsigned long long sum_5 = 5 * max_5 * (max_5 +1)/2;
    unsigned long long sum_15 = 15 * max_15 * (max_15 +1)/2;
    
    cout << sum_all - sum_3 - sum_5 + sum_15 << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#define REP(i, start, n) for(int i = start; i < n; ++i)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
#define debug2d(var)  do{std::cout << #var << " : \n";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF = 1LL<<60;

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

    vector<P> wv(N+1);
    vector<vector<ll> > dp(N+1, vector<ll>(1001*100+1));
    REP(i, 0, N+1) REP(j, 0, 1001*100+1) dp[i][j] = INF;

    REP(i, 1, N+1) cin >> wv[i].first >> wv[i].second;

    dp[0][0] = 0;

    REP(i, 1, N+1) REP(j, 0, 1001*100+1) {
        dp[i][j] = dp[i-1][j];
        if (wv[i].second <= j && dp[i-1][j-wv[i].second] < INF) {
            dp[i][j] = min(dp[i][j], dp[i-1][j-wv[i].second] + wv[i].first);
        }
    }
    
    ll ans = 0;
    REP(i, 0, 1001*100+1) {
        if (dp[N][i] <= W) ans = i;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define ll long long
#define st string
#define bl bool
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define time cerr << "\nInamika vakt-da kor kad: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
using namespace std;
void Urvatullo_Atoev()
{
    ll a,c=0,d,e=1;
    st s;
    cin>>a;
    ll b[a];
    for(ll i=0;i<a;i++)
    {
        cin>>b[i];
    }
    for(ll i=0;i<a;i++)
    {
        if(b[i]==0)
        {
            c++;
        }
    }
    if(c>0)
    {
        cout<<0;
        return;
    }
    for(ll i=0;i<a;i++)
    {
        if(b[i]<=1000000000000000000/e)
        {
            e*=b[i];
        }
        else
        {
            cout<<-1<<endl;
            return;
        }
    }
    cout<<e<<endl;
}
int main()
{
    speed;
    Urvatullo_Atoev();
    time;
}


Measured memory_bytes: 4568
#include <bits/stdc++.h>
#define For(i, l, r) for(int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
    int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar() ) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar() ) x = (x<<1) + (x<<3) + (ch ^ '0');
    return x * fh;
}

const int N = 1e5 + 1e3;
int n, a[N], mid;

int ans = 0, maxv = 0;

int main () {
	n = read();
	For (i, 1, n)
		chkmax(maxv, (a[i] = read()));
	mid = (maxv >> 1);

	For (i, 1, n)
		if (abs(ans - mid) > abs(a[i] - mid)) ans = a[i];

	printf ("%d %d\n", maxv, ans);
    return 0;
}


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

int N,M,Q;
int a[55],b[55],c[55],d[55],A[10];
int ans = 0;

void check() {
	int temp = 0;
	for (int i = 0; i < Q; i++) {
		if (A[b[i]] - A[a[i]] == c[i])
			temp += d[i];
	}
	ans = max(temp,ans);
}

void f(int depth) {
	if (depth== N) {
		check();
	} else if (depth == 0) {
		for (int i = 1; i <= M; i++) {
			A[0] = i;
			f(1);
		}
	} else {
		for (int i = A[depth-1]; i <= M; i++) {
			A[depth] = i;
			f(depth+1);
		}
	}
}

int main() {
	cin >> N >> M >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--; b[i]--;
	}
	f(0);
	cout << ans;
	return 0;
}




Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define ll long long
const int N=100005;
using namespace std;
ll a,b,c,k,ans;
int main(){
	cin>>a>>b>>c>>k;
	if(a>k) ans+=k,k=0;
	else ans+=a,k-=a;
	if(k>=b) k-=b;
	if(k>0) ans-=k;
	cout<<ans;
    return 0;
}

Measured memory_bytes: 3620
import sys
from heapq import heappush, heappop
#input = sys.stdin.readline

def main():
    n=int(input())
    ba=[]
    for i in range(n):
        a,b=map(int,input().split())
        ba.append((b,a))
    ba.sort()
    asum=0
    ans='Yes'
    for b,a in ba:
        asum+=a
        if asum>b:
            ans='No'
            break
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 29584
#include<bits/stdc++.h>
using namespace std;
#define nn 400008
#define mod 1000000007
#define ll long long
namespace mymyth{
	ll f[nn],rf[nn];
	ll qpow(ll x,ll y)
	{
		ll res=1;
		while(y)
		{
			if(y&1) res=res*x%mod;
			y=y/2;x=x*x%mod;
		}return res;
	}
	void ini()
	{
		f[0]=1;
		for(int i=1;i<nn;i++) f[i]=f[i-1]*i%mod,rf[i]=qpow(f[i],mod-2);
	}
};
using namespace mymyth;
#define pii pair<int,int> 
#define mp make_pair
vector<int> v[nn];
int n;pii dot[nn];
#define err {puts("0");exit(0);}
void adde(int x,int y)
{
	v[x].push_back(y);
	v[y].push_back(x);
}
int vis[nn];
int siz[nn],esiz[nn];
int pa[nn];vector<int> cir;
vector<int> all;int dep[nn];
void dfs(int x,int p)
{
	siz[x]=1;esiz[x]=0;vis[x]=1;
	all.push_back(x);
	pa[x]=p,dep[x]=dep[p]+1;
	for(int i=0;i<v[x].size();i++)
	{
		int y=v[x][i];
		if(y==p) continue;//there cant be a multi-edge
		if(!vis[y])
		{
			dfs(y,x);
			siz[x]+=siz[y];
			esiz[x]+=1+esiz[y];
		}
		else if(dep[y]<dep[x] and cir.size()==0)
		{
			esiz[x]++;
			int t=x;
			while(x!=pa[y]) 
				cir.push_back(x),x=pa[x];
			x=t;
		}
		else if(dep[y]<dep[x] and cir.size())
		{
			err;
		} 
	}
}

unordered_map<int,vector<int> >trans ;
vector<int> g[nn];int gs[nn];ll dp[nn];
void give(int x,int y)
{
//	cout<<x<<"-"<<y<<"\n";
	g[x].push_back(y);
	g[y].push_back(x);
}
void gfs(int x,int p)
{
	gs[x]=1;dp[x]=1;
	for(int i=0;i<g[x].size();i++)
	{
		int y=g[x][i];if(y==p) continue;
		gfs(y,x);
		dp[x]=dp[x]*dp[y]%mod*rf[gs[y]]%mod;gs[x]+=gs[y];
	}
	dp[x]=dp[x]*f[gs[x]-1]%mod;
}
int cf[nn];
ll solve()
{
	trans.clear();
	for(int i=0;i<all.size();i++)
	{
		int x=all[i],y=pa[x];g[all[i]].clear();cf[all[i]]=0;
//		cout<<x<<"->"<<y<<"\n";
			trans[y].push_back(x);
	}
	g[0].clear();//system("pause");
	for(int i=0;i<all.size();i++)
	{
		int x=all[i],y=pa[x];vector<int> tmp=trans[x];
		for(int j=0;j<tmp.size();j++)
			if(tmp[j]<y) give(all[i],tmp[j]),cf[tmp[j]]=1; 
	}
	for(int i=0;i<all.size();i++) if(!cf[all[i]]) give(all[i],0);
	gfs(0,-1);
	return dp[0];
}

int vp[nn];
void vps(int x,int p)
{
	pa[x]=p;vp[x]=1;
	for(int i=0;i<v[x].size();i++)
	{
		if(v[x][i]==p or vp[v[x][i]]) continue;
		vps(v[x][i],x); 
	}
}
int main()
{
	ini();
	scanf("%d",&n);
	for(int i=1;i<=n*2;i++)
	{
		scanf("%d%d",&dot[i].first,&dot[i].second);
		adde(dot[i].first,dot[i].second+n);
	}
	ll ans=1;
	for(int i=1;i<=n*2;i++) 
	{
		if(!vis[i])
		{
			cir.clear();all.clear();
			dfs(i,0);int cn=cir.size();
			if(siz[i]!=esiz[i]) err;
			for(int j=0;j<cn;j++)
				vp[cir[j]]=1,pa[cir[j]]=cir[(j+1)%cn];
			for(int j=0;j<cn;j++)
				vps(cir[j],pa[cir[j]]);
			ll res=solve();
			for(int j=0;j<cn;j++)
				pa[cir[j]]=cir[(j-1+cn)%cn];
			res+=solve();
			ans=res%mod*ans%mod*rf[all.size()]%mod;
		}
	}
	printf("%lld\n",ans*f[n+n]%mod);
	return 0;
}

Measured memory_bytes: 76444
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>

using namespace std;

#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair

typedef pair<string, int> P;
typedef pair<P, int> PI;

bool comp(const PI& lh, const PI& rh) {
  return lh.first.first < rh.first.first || (lh.first.first == rh.first.first && lh.first.second > rh.first.second);
}
int main() {
  int N;
  cin >> N;

  vector<PI> sp;
  for (int i = 0; i < N; ++i) {
    string S;
    int p;
    cin >> S >> p;
    sp.PB(MP(MP(S, p), i + 1));
  }
  sort(ALL(sp),comp);
  for(vector<PI>::iterator it = sp.begin(); it != sp.end(); ++it)
    cout << (*it).second << endl;
  return 0;
}


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

using namespace std;

#define debug (cout << "Sehen Sie mich!" << endl)

int main()
{
        int a, b, i;
        string s;

        cin >> a >> b >> s;

        for (i = 0; i < a; i++)
                if (!isdigit(s[i])) {
                        cout << "No" << endl;
                        return 0;
                }
        if (s[i] != '-') {
                cout << "No" << endl;
                return 0;
        }

        for (i++; i < a + b; i++)
                if (!isdigit(s[i])) {
                        cout << "No" << endl;
                        return 0;
                }

        cout << "Yes" << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:tt)*) => (if cfg!(debug_assertions) {print!("[DEBUG] "); println!($($arg)*)});
}

const MOD: i64 = 1e9 as i64 + 7;

pub fn mod_pow(mut x: i64, mut n: i64) -> i64 {
    let mut res = 1i64;
    while n > 0 {
        if n % 2 == 1 {
            res = res * x % MOD;
        }
        x = x * x % MOD;
        n /= 2;
    }
    res
}

pub fn inv(x: i64) -> i64 {
    mod_pow(x, MOD - 2)
}

fn f(x: usize, y: usize, fact: &Vec<i64>) -> i64 {
    fact[x + y] * inv(fact[x]) % MOD * inv(fact[y]) % MOD
}

const N: usize = 200000;

fn main() {
    let mut rd = reader::Reader::new();

    let mut fact: Vec<i64> = vec![0; N];
    fact[0] = 1;
    for i in 1..N {
        fact[i] = fact[i - 1] * i as i64 % MOD;
    }

    let h: usize = rd.next();
    let w: usize = rd.next();
    let a: usize = rd.next();
    let b: usize = rd.next();

    let mut ans = 0;
    for i in 0..w - b {
        let f1 = f(h - a - 1, b + i, &fact);
        let f2 = f(a - 1, w - b - 1 - i, &fact);
        ans += f1 * f2;
        ans %= MOD;
    }
    print!("{}", ans);
}

mod reader {
    use std::fmt::Debug;
    use std::str::FromStr;
    use std::collections::VecDeque;
    use std::io::{self, Read};

    fn _read_line() -> String {
        let mut buf = String::new();
        let _ = io::stdin().read_to_string(&mut buf);
        buf
    }

    fn _read_vec_deque_string() -> VecDeque<String> {
        _read_line()
            .split_whitespace()
            .map(|s| s.to_string())
            .collect()
    }

    #[allow(dead_code)]
    pub struct Reader {
        buf: VecDeque<String>,
    }

    #[allow(dead_code)]
    impl Reader {
        pub fn new() -> Reader {
            Reader { buf: VecDeque::new() }
        }

        fn update_buf(&mut self) {
            if self.buf.is_empty() {
                self.buf = _read_vec_deque_string();
            }
        }

        pub fn next<T>(&mut self) -> T
            where
                T: FromStr,
                T::Err: Debug,
        {
            self.update_buf();
            self.buf.pop_front().unwrap().parse::<T>().unwrap()
        }

        pub fn next_n<T>(&mut self, n: usize) -> Vec<T>
            where
                T: FromStr,
                T::Err: Debug,
        {
            let mut vec: Vec<T> = Vec::with_capacity(n);

            for _ in 0..n {
                vec.push(self.next());
            }
            vec
        }
    }
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;
    vector<int> a(N);
    bool one = false;
    REP(i,N){
        a[i] = S[i] - '0';
        a[i]--;
        if(a[i] & 1) one = true;
    }
    if(!one) REP(i, N) a[i] /= 2;
    
    int ans = 0;
    REP(i,N){
        // _(n-2)C_i
        if(a[i] == 1 && ((N-1) & i) == i) ans ^= 1;
    }
    if(!one) ans *= 2;
    cout << ans << endl;
}


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

int main() {

  const int max = 100000;
  
  bool* p;
  p = new bool[max];

  for(int i = 0; i < max; ++i) {
    p[i] = true;
  }

  p[0] = p[1] = false;
  for(int i = 2; i < max; ++i) {
    if( p[i] ) {
      for(int j = i*2; j < max; j += i) {
	p[j] = false;
      }
    }
  }

  std::vector<int> pv;
  for(int i = 0; i < max; ++i) {
    if( p[i] ) {
      pv.push_back(i);
    }
  }
  
  int N;
  int temp;
  int ans = 0;
  std::cin >> N;

  for(int i = 0; i < N; ++i) {
    std::cin >> temp;
    for(int j = 0; j < pv.size(); ++j) {
      if( temp % pv[j] == 0 && pv[j] != temp ) {
	goto label_1;
      }
    }
    ans += 1;
  label_1:
    ;
  }
    

  std::cout << ans << std::endl;

  delete [] p;
  
  return 0;
}

Measured memory_bytes: 1344
import sys
input = sys.stdin.readline
def main():
    N = int(input())
    W = list(map(int, input().split()))
    left = 0
    right = sum(W)
    ans = 100000
    for i in range(N):
        left += W[i]
        right -= W[i]
        SA = abs(right-left)
        ans = min(ans, SA)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<cmath>
using namespace std;
int main(){
    
    //変数：銀行の数 「 n 」、預ける年数 「 y 」、銀行の銀行番号 「 b 」、年利率を表す整数「 r 」、金利の種類「 t 」と置く
    int n, y, b, r, t;
    
    //変数：出力したい銀行の番号「 bankNo 」
    int bankNo;
    
    //変数：単利または複利の計算結果「 ans」、全ての銀行で最も高いお金「 maxMoney 」
    double ans, maxMoney;
    
    
    //繰返し：銀行の数 「 n 」の数が [ 0 ] になるまで繰り返す
    while(cin >> n, n){
        
        //入力：預ける年数 「 y 」を入力
        cin >> y;
        
        //代入：2回目以降に影響がでないために「 maxMoney 」を初期化している.
        maxMoney=0;
        
        //繰返し：銀行の数 「 n 」の数だけ繰り返す
        for(int i=0;i<n;i++){
            
            //入力：銀行の銀行番号 「 b 」、年利率を表す整数「 r 」、金利の種類「 t 」を入力
            cin >> b >> r >> t;
            
            //判定：金利の種類「 t 」が[ 0  OR  1 ]か判定　➡　式が変化するから
            if(t==1){
                ans = 1.0 + y*(double)r/100.0;    
            }
            else{
                ans = pow(1.0+(double)r/100.0,y);
            }
         
        //判定：今回の元利が最大値か判定する　そして、最大値なら銀行番号　➡　 今回は繰返しでの値「  b 」 となる。
            if(maxMoney < ans){
                maxMoney = ans;
                bankNo=b;
            }
        }
        
    //出力：銀行の番号を出力
    cout << bankNo <<endl;
    
    }
}



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

string s;
int n;

bool pal(string a)
{
	for(int i = 0;i<a.size()/2;i++)if(a[i]!=a[a.size()-1-i])return false;
	return true;
}

int main()
{
	cin >> s;
	n = s.size();
	if(s.substr(0,(n-1)/2)!=s.substr((n+1)/2,n))cout << "No";
	else if(pal(s.substr(0,(s.size()-1)/2))==false)cout << "No";
	else cout << "Yes";
	return 0;
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use proconio::marker::Chars;

macro_rules! echo {
  ($val:expr) => {
    println!("{}", $val);
  }
}

#[fastout]
fn main() {
  input!{
    s: Chars,
    t: Chars
  };

  let mut ans = 0;
  for i in 0..s.len() {
    if s[i] != t[i] {
      ans += 1;
    }
  }
  echo!(ans);
}


Measured memory_bytes: 3996
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds; 
using ll = long long int;
#define INF             1e14
#define dd              double
#define MOD             1000000007
#define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl              cout<<endl
#define fill(a,val)     memset(a,val,sizeof(a))
#define mp              make_pair
#define endl            "\n"
#define pb              push_back
#define ff              first    
#define ss              second
#define SIZE            200005
#define all(v)          v.begin(),v.end()
#define s(ar,n)         sort(ar,ar+n)
#define rs(ar,n)        sort(ar, ar+n, greater<ll>()) 
#define oa(a,n)         for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n)         for(ll i=0;i<n;i++)cin>>a[i];
#define maxa(ar,N)      *max_element(ar,ar+N)
#define mina(ar,N)      *min_element(ar,ar+N)
#define fastio()        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define printclock      cerr<<"Time : "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// find_by_order() - 0 indexing
// order_of_key() - number of elements strictly smaller
ll power(ll x, ll y){
    ll res=1;x=x;
    while(y>0){
        if(y&1)
            res = (res*x);
        y = y>>1;
        x = (x*x);
    }
    return res;
}  
ll logtwo(ll n){
    if(n==1)
        return 0;
    return logtwo(n/2)+1;
}
//---------------------------------------GL HF------------------------------------------------------
// -------------------------------------ManavJ07----------------------------------------------------
signed main()
{
	fastio();   
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
	int t=1;
	//cin>>t;
	while(t--)
	{
		ll N;
		cin>>N;
		ll a,sum=0;;
		map<ll,ll> ma;
		for(ll i=0;i<N;i++){
			ll a;
			cin>>a;
			ma[a]++;
			sum+=a;
		}
		ll M;
		cin>>M;
		while(M--){
			ll c,d;
			cin>>c>>d;
			sum-=(ma[c]*c);
			sum+=(ma[c]*d);
			ma[d]+=ma[c];
			ma[c]=0;
			cout<<sum<<endl;
		}
	}
}

Measured memory_bytes: 9556
import sys
max_num = 1000000007
input = sys.stdin.readline
N, M = map(int, input().split())
A = [int(input()) for i in range(M)]

stairs = [1] * (N+1)
for i in A:
    stairs[i] = 0

for i in range(1, N):
    if stairs[i+1] != 0:
        stairs[i+1] = stairs[i] + stairs[i-1]
print(stairs[N] % max_num)

Measured memory_bytes: 470520
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <math.h>
using namespace std;

int main(){
	int b1,b2,b3,s,o,n;
	string c;
	cin>>n;
	for(int i=0;i<n;i++){
		b1=0;b2=0;b3=0;s=0;o=0;
		while(o<3){
			cin>>c;
			if(c=="HIT"){
				if(b3){s++;b3=0;}
				if(b2){b3=1;b2=0;}
				if(b1)b2=1;
				b1=1;
			}
			else if(c=="HOMERUN"){
				if(b1&&b2&&b3)s+=4;
				else if(b1&&b2||b2&&b3||b3&&b1)s+=3;
				else if(b1||b2||b3)s+=2;
				else s++;
				b1=0;b2=0;b3=0;
			}
			else o++;
		}
		cout<<s<<endl;
	}
}

Measured memory_bytes: 0
#include "iostream"
#include "string"
#include "vector"
#include "algorithm"
#include "functional"
#include "cmath"

using namespace std;

string go_right_up(int x, int y) {
    return string(x, 'R') + string(y, 'U');
}

string go_left_down(int x, int y) {
    return string(x, 'L') + string(y, 'D');
}

int main() {
    // get values from input
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    // main procedure
    int dx = tx - sx;
    int dy = ty - sy;

    string answer = "";

    // first going and back
    answer += go_right_up(dx, dy) + go_left_down(dx, dy);

    // second going
    answer += "D" + go_right_up(dx + 1, dy + 1) + "L";

    // second back
    answer += "U" + go_left_down(dx + 1, dy + 1) + "R";

    // output
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    class UnionFind(initSize: Int) {
        private val parent = IntArray(initSize) { it }
        private val size = LongArray(initSize) { 1L }

        fun root(x: Int): Int {
            if (x == parent[x]) return x

            val xr = root(parent[x])
            parent[x] = xr
            return xr
        }

        fun unite(x: Int, y: Int) {
            val xr = root(x)
            val yr = root(y)
            if (xr == yr) return

            if (size[xr] >= size[yr]) {
                size[xr] += size[yr]
                parent[yr] = xr
            } else {
                size[yr] += size[xr]
                parent[xr] = yr
            }
        }

        fun isSame(x: Int, y: Int): Boolean = root(x) == root(y)

        fun size(x: Int): Long = size[root(x)]
    }

    val (n, m, k) = readLine()!!.split(" ").map { it.toInt() }
    val friendList = (0 until m).map { readLine()!!.split(" ").map { it.toInt() - 1 }.let { it[0] to it[1] } }
    val blockList = (0 until k).map { readLine()!!.split(" ").map { it.toInt() - 1 }.let { it[0] to it[1] } }

    val uf = UnionFind(n)
    val friendOrBlocked = IntArray(n)
    for (ab in friendList) {
        val (a, b) = ab
        uf.unite(a, b)

        friendOrBlocked[a]++
        friendOrBlocked[b]++
    }
    for (cd in blockList) {
        val (c, d) = cd
        if (uf.isSame(c, d)) {
            friendOrBlocked[c]++
            friendOrBlocked[d]++
        }
    }

    val answer = friendOrBlocked.mapIndexed { index, l ->
        uf.size(index) - l - 1
    }.joinToString(" ")
    println(answer)
}

Measured memory_bytes: 88836
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

const INF: usize = std::usize::MAX;

fn main() {
   input! {
      n: usize,
      a: [usize; n]
   }
   let mut dp = vec![vec![INF; n + 1]; n + 1];
   for i in 0..n {
      dp[i][i + 1] = 0;
   }

   for l in 2..n + 1 {
      for i in 0..n - l + 1 {
         for m in i + 1..i + l {
            dp[i][i + l] = std::cmp::min(dp[i][i + l], dp[i][m] + dp[m][i + l]);
         }
         for j in i..i + l {
            dp[i][i + l] += a[j];
         }
      }
   }
   println!("{}", dp[0][n]);
}



Measured memory_bytes: 4352
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a, &b)

	ans := "No"
	for n := range []int{1, 2, 3} {
		if a*b*n%2 == 1 {
			ans = "Yes"
			break
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
import java.awt.Point;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[][] X = new int[N+2][N+2];
		boolean[][] gone = new boolean[N+2][N+2];
		int ans = 0;
		for(int i = 1; i <= N/2; i++) {
			for(int j = i+1; j <= N-i; j++) {
				X[i+1][j] = i;
				X[j][i+1] = i;
				X[N-i][j] = i;
				X[j][N-i] = i;
			}
		}
		int[] dx = {-1, 1, 0, 0};
		int[] dy = {0, 0, 1, -1};
		Queue<Point> q = new ArrayDeque<>();
		for(int i = 0; i < N*N; i++) {
			int P = sc.nextInt();
			int y = P -(P - 1) / N * N;
			int x = (P + N - 1) / N;
			ans += X[x][y];
			gone[x][y] = true;
			q.add(new Point(x, y));
			while(q.size() > 0) {
				Point n = q.poll();
				int d = X[n.x][n.y];
				for(int j = 0; j < 4; j++) {
					if(gone[n.x][n.y]) {
						if(X[n.x+dx[j]][n.y+dy[j]] > d) {
							q.add(new Point(n.x+dx[j], n.y+dy[j]));
							X[n.x+dx[j]][n.y+dy[j]] = d; 
						}
					}
					else if(X[n.x+dx[j]][n.y+dy[j]] > d + 1) {
						q.add(new Point(n.x+dx[j], n.y+dy[j]));
						X[n.x+dx[j]][n.y+dy[j]] = d + 1; 
					}
				}
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 64660
n = int(input())
num = list(map(int,input().split()))
c2,c4,ce=0,0,0
for i in range(n):
  if num[i]%4 ==0:
    c4 += 1
  elif num[i]%2 ==0:
    c2 = 1
  else:
    ce +=1
if ce ==0:
  print('Yes')
elif c2 + ce <= c4 +1:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 14252
A,B=list(map(int,input().split()))
S=input()
flag=True
if len(S)!=A+B+1:
    flag=False
for i in range(len(S)):
    if i<A or i>A:
        if S[i]!="0" and S[i]!="1" and S[i]!="2" and S[i]!="3" and S[i]!="4" and S[i]!="5" and S[i]!="6" and S[i]!="7" and S[i]!="8" and S[i]!="9":
            flag=False
    else:
        if S[i]!="-":
            flag=False
if flag:
    print("Yes")
else:
    print("No")

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

using namespace std;

int main(){
  int n,m; cin >> n>> m;
  long long a=0,b=0;
  int tmp;
  for(int i=0;i<n;++i) {
    cin >> tmp;
    a+=tmp;
  }
  for(int i=0;i<m;++i) {
    cin >> tmp;
    b+=tmp;
  }
    cout << a*b << endl;
  
  return 0;
} 



Measured memory_bytes: 3100
#include "bits/stdc++.h"


// vector
#define MAX_ELE(vec) *max_element(vec.begin(), vec.end())
#define SORT(vec) sort(vec.begin(), vec.end());


// ---------------------------------------

// string
#define TO_UP(str) transform(str.cbegin(), str.cend(), str.begin(), ::toupper)

// ---------------------------------------



using namespace std;

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

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

    

    int N, K;
    int h[100000];
    long long dp[100000];

    cin >> N >> K;
    
    for (int i = 0; i < N; i++)
    {
        dp[i] = INFINITY;
        cin >> h[i];
    }
    
    dp[0] = 0;

    for (int i = 1; i < N; i++)
    {
        if(i < K){
            for (int j = 1; j < i+1; j++)
            {
                chmin(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
            }
        }else{
            for (int j = 1; j < K+1; j++)
            {
                chmin(dp[i], dp[i-j] + abs(h[i] - h[i-j]));
            }
        }
    }
    
    cout << dp[N-1] << "\n";

}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
set<int>s;
int main(void)
{
    int n;
    cin>>n;
    int temp;
    for(int i=0;i<n;++i)
    {
        cin>>temp;
        s.insert(temp);
    }
    cout <<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc138/tasks/abc138_c

#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int n, q;
    cin >> n >> q;
    vector<vector<int>> vec(n, vector<int>());
    for (int i=0; i<n-1; i++) {
        int a, b;
        cin >> a >> b;
        vec.at(a-1).push_back(b);
    }
    vector<int> ans(n);
    for (int i=0; i<q; i++) {
        int p, x;
        cin >> p >> x;
        ans.at(p-1) += x;
    }
    for (int i=0; i<n; i++) {
        int c;
        c = ans.at(i);
        for (int j=0; j<vec.at(i).size(); j++) {
            ans.at(vec.at(i).at(j)-1) += c;
        }
    }
    for (int i=0; i<n; i++) {
        if (i==0) {
            cout << ans.at(i);
        } else {
            cout << " " << ans.at(i);
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 14080
#include<iostream>
#include<algorithm>

#define MAX_N 200010

const int INF=1<<30;

int MaxProfit(const int n,const int R[]){
    int max_diff[MAX_N],min=R[0];
    max_diff[0]=-INF;
    for(int i=1;i<n;i++){
        max_diff[i]=std::max(max_diff[i-1],R[i]-min);
        min=std::min(min,R[i]);
    }
    return max_diff[n-1];

}

int main(void){
    int n;
    int R[MAX_N];
    std::cin>>n;
    for(int i=0;i<n;i++)
        std::cin>>R[i];
    std::cout<<MaxProfit(n,R)<<std::endl;
    return 0;
}


Measured memory_bytes: 4660
import sys
n=10**6
p=[1]*n
p[0],p[1]=0,0
for i in xrange(2,int(n**0.5)+1):
    if p[i]==1:
        for j in xrange(i**2,n,i):
            p[j]=0
for i in xrange(2,n):
    p[i]+=p[i-1]
for line in sys.stdin.readlines():
    print p[int(line)]

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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,a,n) for(int i=(a);i<(n);i++)
int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  int n;cin>>n;
  int c[n-1],s[n-1],f[n-1];
  rep(i,n-1)cin>>c[i]>>s[i]>>f[i];
  int t;
  rep(i,n){
    t=0;
    rep2(j,i,n-1){
      if(t<s[j])t=s[j];
      else if(t%f[j]==0);
      else t=t+f[j]-t%f[j];
      t+=c[j];
    }
    cout<<t<<endl;
  }
}


Measured memory_bytes: 256
use std::io;

fn main() {
    let mut n=String::new();
    io::stdin().read_line(&mut n).expect("Failed to read line");
    let n: u32=n.trim().parse().expect("Failed to parse");
    if n>=1000 {
        println!("ABD");
    }else{
        println!("ABC");
    }
}


Measured memory_bytes: 4352
n,m = map(int,input().split())
h = list(map(int,input().split()))

dic = {}
for i in range(1,n+1):
    dic[i] = 1
for j in range(1,m+1):
    a,b = map(int,input().split())
    if h[a-1] < h[b-1]:
        dic[a] = 0
    elif h[a-1] > h[b-1]:
        dic[b] = 0
    else:
        dic[a] = 0
        dic[b] = 0
lis = list(dic.values())

print(lis.count(1))

Measured memory_bytes: 24564
A,B,C = sorted(map(int,input().split()))
ans = 0

for n in range(50):
  if A==B==C:
    break
  elif A<C and B<C:
    A+=1
    B+=1
    ans+=1
  elif A<C and B==C:
    A+=2
    ans+=1
  else:
    B+=1
    C+=1
    ans+=1
    
print(ans)

Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ff first
#define ss second
#define endl '\n'
#define MAX INT_MAX
#define MIN INT_MIN
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define sz(a) (int)((a).size())
#define all(a) a.begin(),a.end()
#define loopf(i,a,b) for(int i = a;i < b;i++)
#define loopb(i,a,b) for(int i = a;i >= b;i--)
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;


const int ma=1e5+5;
vector<int> edges[ma];
int dist[ma]={0};
bool vis[ma]={false};
int indegree[ma]={0};

void dfs(int a)
{ 
  assert(!vis[a]);
    vis[a]=true;
    for(int b: edges[a])
    {
      dist[b]=max(dist[b],dist[a]+1);
      indegree[b]--;
      if(indegree[b]==0)
      dfs(b);
    }
  
}

int32_t main()
{
    fast

   int test=1;
   //cin>>test;

  while(test--)
  {
  int n,m,x,y;
  cin>>n>>m;

  for(int i=1;i<=m;i++)
  {
    cin>>x>>y;
    edges[x].pb(y);
    indegree[y]++;
  }

  for(int i=1;i<=n;i++)
  {
    if(!vis[i] && indegree[i]==0)dfs(i);
  }

  int ans=0;
  for(int i=1;i<=n;i++)ans=max(ans,dist[i]);

    cout<<ans;

  //while loop ending 
  }



return 0;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    ll A = 0;
    REP(i,0,N) {
        ll a;
        cin >> a;
        A |= a;
    }

    ll cnt = 0;
    while((A & 1) == 0) {
        A >>= 1;
        ++cnt;
    }
    PR(cnt);



    return 0;
}

/*



*/

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

using namespace std;



vector<int> xorsum(long X){
    vector<int> ans;
    for (int i = 1; i <= 40; i++){
        if (i == 1){
            long m = X % 4;
            if (m == 0 || m == 3) ans.push_back(0);
            else ans.push_back(1);
            continue;
        }
        long mod = X % static_cast<long>(pow(2, i));
        if (mod < pow(2, i - 1)) ans.push_back(0);
        else if (mod % 2 == 0) ans.push_back(1);
        else ans.push_back(0);
    }
    
    return ans;
}

int main(){
    long A, B;
    cin >> A >> B;
    if (A != 0) A--;
    auto ax = xorsum(A);
    auto bx = xorsum(B);

    long ans = 0;
    for (int i = 0; i < 40; i++){
        int c = ax[i] ^ bx[i];
        ans += static_cast<long>(pow(2, i)) * c;
    }
    cout << ans << endl;

}


Measured memory_bytes: 504
#include<bits/stdc++.h>
#define ll long long
#define PI 3.14159265
using namespace std;
void solve(){
	ll n,w;
	cin>>n>>w;
	ll a[n][2];
	for(ll i=0; i<n; ++i){
		cin>>a[i][0]>>a[i][1];
	}
	cout<<endl;
	ll dp[w+1][n+1];
	for(int i=0; i<=w; ++i){
		for(int j=0; j<=n; ++j){
			if(i==0 || j==0){
				dp[i][j] = 0;
			}else if(a[j-1][0] <= i){
				dp[i][j] = max(dp[i - a[j-1][0]][j-1]+a[j-1][1], dp[i][j-1]);
			}else{
				dp[i][j] = dp[i][j-1];
			}
		}
	}
	
	cout<<dp[w][n]<<"\n";
	
	
}
int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t;
    t = 1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 79232
#include<cstdio>
#include<cmath>
#include<algorithm>

using namespace std;
const int maxn=200005;
const int inf=0x3f3f3f3f;

int dp[maxn],a[maxn],n;

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) dp[i]=(i==1?0:inf);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=2;i<=n;i++) dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),i>2?dp[i-2]+abs(a[i]-a[i-2]):inf);
	printf("%d\n",dp[n]);
 } 

Measured memory_bytes: 896
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        int n = sc.nextInt();
        int x = sc.nextInt() - 1, y = sc.nextInt() - 1;
        
        int[] ds = new int[n];
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                int d = Math.min(j - i, Math.min(Math.abs(j - x) + Math.abs(i - y) + 1, Math.abs(j - y) + Math.abs(i - x) + 1));
                ds[d]++;
            }
        }

        for (int i = 1; i < n; i++) {
            out.println(ds[i]);
        }

        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 22100
#include<algorithm>
#include<iostream>

int main(){
  int A, B, C, D, E, F; std::cin >> A >> B >> C >> D >> E >> F;
  auto maxd = 0.;
  auto maxt = 0;
  auto maxs = 0;
  for(auto a=0; 100*a*A<=F; ++a)
    for(auto b=0; 100*b*B+100*a*A<=F; ++b)
      for(auto c=0; c*C<=F and c*C<=(a*A+b*B)*E and 100*b*B+100*a*A+c*C<=F; ++c){
	auto d = (F-c*C-100*a*A-100*b*B)/D;
	auto tw = 100*a*A + 100*b*B;
	// std::cerr << tw << "tw\n";
	auto ps = tw*E/100;
	// std::cerr << ps << "ps\n";
	d = std::min(d, (ps-c*C)/D);
	// std::cerr << a << ' ' << b << ' ' << c << ' ' << d << '\n';
	if((100.*(c*C+d*D))/(100*a*A+100*b*B+c*C+d*D) >= maxd){
	  maxd = (100.*(c*C+d*D))/(100*a*A+100*b*B+c*C+d*D);
	  maxt = 100*a*A+100*b*B+c*C+d*D;
	  maxs = c*C+d*D;
	  // std::cerr << 100*a*A+100*b*B+c*C+d*D << ' ' << c*C+d*D << '\n';
	}
      }
  std::cout << maxt << ' ' << maxs << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define _LIBCPP_DEBUG 0
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;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);};};
const int MOD = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<62;



int main(void) {

    int n;
    cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    Sort(v);
    ll ans=0;
    for(int i=0;i<n-2;i++){
        for(int j=i+1;j<n-1;j++){
            int a=v[i];
            int b=v[j];
            int minc,maxc;
            auto it = lower_bound(v.begin(),v.end(), a + b);
            auto idx = it - v.begin();
            auto tmp = max(0LL, (ll)idx - j - 1);
            ans+=tmp;
        }
    }
    fin(ans);

}



Measured memory_bytes: 256
import heapq
from typing import List, Optional


def _find_cycle(incoming_edges: List[List[int]], root: int) -> Optional[List[int]]:
    in_tree = [False] * v_num
    in_tree[root] = True
    for e in incoming_edges:
        if e:
            S = []
            S.append(e[2])
            while True:
                p = incoming_edges[S[-1]][1]
                if in_tree[p]:
                    while S:
                        in_tree[S.pop()] = True
                    break
                elif p in S:
                    return S[S.index(p):]
                else:
                    S.append(p)
    return None


def _contract_cycle(digraph: List[List[List[int]]],
                    cycle_node: List[int], root: int) -> None:
    super_node = cycle_node[0]
    for edges in digraph:
        if edges:
            min_weight = edges[0][0]
            for e in edges:
                e[0] -= min_weight
                if e[1] in cycle_node:
                    e[1] = super_node
                if e[2] in cycle_node:
                    e[2] = super_node
    contracted_edges: List[List[int]] = []
    for n in cycle_node:
        for e in digraph[n]:
            if e[1] != super_node:
                heapq.heappush(contracted_edges, e)
        digraph[n].clear()
    digraph[super_node] = contracted_edges


def edmonds_branching(digraph: List[List[List[int]]], root: int, weight: int) -> int:
    min_incoming_edges: List[List[int]] = [[]] * v_num
    for edges in digraph:
        if edges:
            min_edge = edges[0]
            min_incoming_edges[min_edge[2]] = min_edge
            weight += min_edge[0]
    C = _find_cycle(min_incoming_edges, root)
    if not C:
        return weight
    else:
        _contract_cycle(digraph, C, r)
        return edmonds_branching(digraph, root, weight)


if __name__ == "__main__":
    v_num, e_num, r = map(lambda x: int(x), input().split())
    G: List[List[List[int]]] = [[] for i in range(v_num)]

    for _ in range(e_num):
        s, t, w = map(lambda x: int(x), input().split())
        if t != r:
            heapq.heappush(G[t], [w, s, t])

    print(edmonds_branching(G, r, 0))



Measured memory_bytes: 7368
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

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

	auto result = 0;
	for (auto i = 1; i <= N; ++i)
	{
		auto temp = i;
		auto count = 0;
		while (temp > 0)
		{
			++count;
			temp /= 10;
		}
		if (count % 2 != 0)
		{
			++result;
		}
	}

	cout << result << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define ll long long
#define se second
using namespace std;

int main(){
		ll n;cin>>n;ll s[n+1],c[n+1],f[n+1];
		for(int i=1;i<=n-1;i++)
		cin>>c[i]>>s[i]>>f[i];
		
	
		for(int i=1;i<=n;i++)
		{
			ll total=0;
			for(int j=i;j<=n-1;j++)
			{
				if(total<=s[j])
				total=s[j];
				else if(total%f[j]==0);
				else
				total+=f[j]-(total%f[j]);
				
				total+=c[j];
			}
			cout<<total<<endl;
		}
		
		
		
		
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)                                                            \
  for (auto v : (V)) {                                                         \
    cout << v << " ";                                                          \
  }                                                                            \
  cout << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
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;
}
template < class T > using vec = std::vector< T >;
template < class T > void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string S;
  int K;
  cin >> S >> K;
  int N = S.size();
  map< string, int > mp;
  REP(i, N) {
    FORS(j, i + 1, i + 6) { mp[S.substr(i, j - i)]++; }
  }
  // DEBUG(mp.size());
  int cnt = 0;
  FORA(e, mp) {
    cnt++;
    if (cnt == K) {
      print(e.first);
      return 0;
    }
  }
}

Measured memory_bytes: 2432
n=int(input())
xy=[tuple(map(int,input().split())) for _ in range(n)]
pq=[]
for i in range(n):
    for j in range(n):
        if i==j:
            continue
        sx,sy=xy[i]
        gx,gy=xy[j]
        pq.append((gx-sx,gy-sy))


se=set(xy)

ans=n
for p,q in pq:
    now=0
    for x,y in xy:
        if (x+p,y+q) not in se:
            now+=1
    ans=min(ans,now)

print(ans)


Measured memory_bytes: 3316
//A-Two_Rectangles
#include <bits/stdc++.h>
using namespace std;

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

  cin>>a>>b>>c>>d;

  a*=b;
  c*=d;
  if(a>c) cout<<a<<endl;
  else cout<<c<<endl;

  return 0;
}


Measured memory_bytes: 256
def sqrt(x):
    return x ** (.5)

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

X = int(input())

if is_prime(X):
    print(X)
    exit()
if X % 2 == 0:
    X += 1
while (1):
    if is_prime(X):
        print(X)
        break
    X += 2

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

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

  string ans;
  if (d == 25) {
    ans = "Christmas";
  } else if (d == 24) {
    ans = "Christmas Eve";
  } else if (d == 23) {
    ans = "Christmas Eve Eve";
  } else {
    ans = "Christmas Eve Eve Eve";
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define rfor(i,a,b) for(ll (i) = (a); (i) > (b); --(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll t = 1;
    rep1(i, n)t *= i;
    return t;
}

ll combinations(ll n, ll k) {
    ll r = 1;
    for (ll d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

int n,m,a,b,ans = 0;
int g[8][8];
bool used[8];

void cnt(int i){
    used[i] = true;
    bool f = true;
    rep0(j, n){
        if(!used[j])f = false;
    }
    if(f)++ans;
    rep0(j, n){
        if(g[i][j] == 1 && !used[j]){
            cnt((int)j);
            used[j] = false;
        }
    }
    return;
}

int main()
{
    cin >> n >> m;
    rep0(i, m){
        cin >> a >> b;
        g[a - 1][b - 1] = 1;
        g[b - 1][a - 1] = 1;
    }
    cnt(0);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256