akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
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 (b<a) { a=b; return 1; } return 0; }

//mint
#define MOD 998244353

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

class mint{
    typedef long long ll;
public:
    mint(const ll a){
        _val = a%_mod;
    }
    mint(){
        _val=0;
    }
    mint& operator+=(const mint other){
        _val = (_val + other._val)%_mod;
        return *this;
    }
    mint& operator-=(const mint other){
        _val = (_val - other._val)%_mod;
        return *this;
    }
    mint& operator*=(const mint other){
        _val = (_val * other._val)%_mod;
        return *this;
    }
    explicit operator ll() {return _val;}
    ll _val;
    static void setmod(ll mod){_mod = mod;}
    static ll _mod;
};

mint operator*(const mint mi, const mint mj){
    return mint(mi._val * mj._val);
}
mint operator+(const mint mi, const mint mj){
    return mint(mi._val + mj._val);
}
mint operator-(const mint mi, const mint mj){
    return mint(mi._val - mj._val);
}
ostream& operator<<(ostream& out, mint mi){
    out << mi._val;
    return out;
}
ll mint::_mod;

//mint end
int main(){
    ll k, ans=0;
    cin >> k;
    mint::setmod(k);
    mint a(7);

    rep(i,k+1){
        ans++;
        if(a._val==0){
            cout << ans << endl;
            break;
        }
        a = a*10+7; 
    }
    if(a._val!=0){
        cout << -1 << endl;
    }
    return 0;
}


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

int main(){
	string s;
	cin>>s;
	
	llong sum=0;
	llong cnt=0;
	for(int i=0;i<s.size();++i){
		if(s[i]=='B') cnt++;
		else sum+=cnt;
	}
	
	cout<<sum<<endl;
}//解説参考.

Measured memory_bytes: 644
#include<cstdio>
#include<iostream>
#include<map>
#include<cmath>
using namespace std;
map<long long,bool> m;
int main()
{
    int n;
    cin>>n;
    bool flag=true;
    int cnt=0;
    char pre;
    while(n--)
    {
        string s;
        cin>>s;
        if(!flag) continue;
        if(cnt!=0)
        {
            if(s[0]!=pre) flag=false;
            else pre=s[s.size()-1];
        }
        else cnt=1,pre=s[s.size()-1];
        long long t=0;
        for(int i=0;i<s.size();i++)
            t+=(long long)(s[i]-'a'+1)*pow(27,(long long)i);
        if(m[t]) flag=false;
        else m[t]=true;
    }
    if(flag)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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

using namespace std;

int64_t calc(std::vector<int64_t> as) {
  int64_t const n = as.size();
  if (n == 1) {
    return 0;
  }
  for (int64_t i = 0; i < n; ++i) {
    as[i] -= i + 1;
  }
  std::sort(as.begin(), as.end());
  int64_t const b_min = as.front();
  int64_t const b_max = as.back();
  int64_t const b_mid = as[n / 2];
  int64_t sad_mid = 0;
  for (int64_t i = 0; i < n; ++i) {
    sad_mid += std::abs(as[i] - b_mid);
  }
  if (sad_mid == 0) {
    return 0;
  }
  int64_t ret = sad_mid;
  auto const over_b_mid_itr =
      std::upper_bound(as.begin() + n / 2, as.end(), b_mid);
  auto over_b_itr = over_b_mid_itr;
  int64_t over_b_idx = over_b_itr - as.begin();
  int64_t b = b_mid + 1;
  for (; b <= b_max; ++b) {
    int64_t const sad = ret + over_b_idx - (n - over_b_idx);
    if (sad == 0) {
      return 0;
    }
    if (sad > ret) {
      break;
    }
    ret = sad;
    over_b_itr = std::upper_bound(over_b_itr, as.end(), b);
    over_b_idx = over_b_itr - as.begin();
  }
  if (ret == sad_mid) {
    auto ge_b_itr = std::lower_bound(as.begin(), over_b_mid_itr, b_mid);
    int64_t ge_b_idx = ge_b_itr - as.begin();
    b = b_mid - 1;
    for (; b >= b_min; --b) {
      int64_t const sad = ret + (n - ge_b_idx) - ge_b_idx;
      if (sad == 0) {
        return 0;
      }
      if (sad > ret) {
        break;
      }
      ret = sad;
      ge_b_itr = std::lower_bound(as.begin(), over_b_mid_itr, b);
      ge_b_idx = ge_b_itr - as.begin();
    }
  }
  return ret;
}

int main() {
  int64_t n;
  std::cin >> n;
  std::vector<int64_t> as(n);
  for (int64_t i = 0; i < n; ++i) {
    std::cin >> as[i];
  }
  std::cout << calc(as) << std::endl;
  return 0;
}


Measured memory_bytes: 3328
#include<stdio.h>
#define MAX 100000

typedef long long llong;
int n, k;
llong T[MAX];


int check(llong P){
  int i = 0,j;
  for(j = 0 ; j < k ; j++){
    llong s = 0;
    while(s + T[i] <= P){
      s += T[i];
      i++;
      if(i == n) return n;
    }
  }
  return i;
}


int solve(){
  llong left = 0;
  llong right = 100000 * 10000;
  llong mid;
  while(right - left > 1){
    mid = (left + right) / 2;
    int v = check(mid);
    if(v >= n) right = mid;
    else left = mid;
  }

  return right;
}


int main(){
  int i;
  
  scanf("%d %d", &n, &k);
  for(i = 0 ; i < n ; i++) scanf("%d", &T[i]);
  llong ans = solve();
  printf("%d\n", ans);

  return 0;
}


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

// @author: pashka

vector<vector<int>> g;
vector<int> sz;
vector<long> s1;
vector<long> s2;

const long MOD = 1000000007;

vector<long> fact;
vector<long> inv_fact;

long calc_c(int n, int k) {
    long res = fact[n];
    res *= inv_fact[k];
    res %= MOD;
    res *= inv_fact[n - k];
    res %= MOD;
    return res;
}

long power(long a, long b) {
    long res = 1;
    while (b > 0) {
        if (b & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        b /= 2;
    }
    return res;
}

long inv(long a) {
    return power(a, MOD - 2);
}

void dfs1(int x, int p) {
    s1[x] = 1;
    for (int y : g[x]) {
        if (y == p) continue;
        dfs1(y, x);
        sz[x] += sz[y];
        s1[x] *= s1[y];
        s1[x] %= MOD;
        s1[x] *= calc_c(sz[x], sz[y]);
        s1[x] %= MOD;
    }
    sz[x]++;
}

vector<long> res;

void dfs2(int x, int p) {
    long ss0 = s1[x];
    ss0 = ss0 * s2[x];
    ss0 %= MOD;
    int n = g.size();
    ss0 *= calc_c(n - 1, sz[x] - 1);
    ss0 %= MOD;
    res[x] = ss0;
    for (int y : g[x]) {
        if (y == p) continue;        
        long ss = ss0;
        ss *= inv(s1[y]);
        ss %= MOD;
        ss *= inv(calc_c(n - 1, sz[y]));
        ss %= MOD;       
        s2[y] = ss;        
        dfs2(y, x);
    }
}

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    fact.resize(n + 1);
    inv_fact.resize(n + 1);
    fact[0] = inv_fact[0] = 1;
    for (int i = 1; i <= n; i++) {
        fact[i] = (fact[i - 1] * i) % MOD;
        inv_fact[i] = inv(fact[i]);
    }

    s1.resize(n);
    sz.resize(n);

    s2.resize(n);
    dfs1(0, -1);
    s2[0] = 1;
    res.resize(n);
    dfs2(0, -1);
    
    for (auto x : res) {
        cout << x << "\n";
    }

    return 0;
}

Measured memory_bytes: 22516
<?php
$A = trim(fgets(STDIN));
$B = trim(fgets(STDIN));

$al = strlen($A);
$bl = strlen($B);

if ($al > $bl) {
    echo "GREATER";
    exit;
} elseif($al < $bl) {
    echo "LESS";
    exit;
}

for ($i = 0; $i < $al; $i++) {
    $a = intval(substr($A, $i, 1));
    $b = intval(substr($B, $i, 1));
    if($a > $b) {
        echo "GREATER";
        exit;
    } elseif($a < $b) {
        echo "LESS";
        exit;
    }
    if ($i == $al - 1) {
        echo "EQUAL";
    }
}

Measured memory_bytes: 3700
#include<stdio.h>
int main(){
	int n,k,x,y,p;
	scanf("%d%d%d%d",&n,&k,&x,&y);
	if (n>k){
		p = x * k + y * (n - k);
		printf("%d\n",p);
		}
		else {
			p = x * n;
			printf("%d\n",p);
			}
	return 0;
	}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <bits/stdc++.h>
#include <set>
#include <list> //list<???> a; a.push_back ,insert(追加したい要素),a.sort(),参照できない
#include <vector> //vector<???> a; a.push_back,sort(a.begin(),a.end());a[i]
//配列 int a[N];a[i]=追加したい要素;sort(a,a+N);a[i]
using namespace std;
typedef long  ll;
#define rep(i,n) for(int i=0;i<(n);i++)


//using namespace std;
//


int main(){
  int a,b;
  string op;
  cin>>a>>op>>b;

  if(op=="+"){
    cout<<a+b<<endl;

  }else{
    cout<<a-b<<endl;
  }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

struct UnionFind{
  vector<int> v;
  UnionFind(int n) : v(n, -1) {}
  void init(){ for(int i = 0;i < v.size();i++)v[i]=-1; }
  int find(int x) { return v[x] < 0 ? x : v[x] = find(v[x]); }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (-v[x] < -v[y]) swap(x, y);
    v[x] += v[y]; v[y] = x;
    return true;
  }
  bool root(int x) { return v[x] < 0; }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -v[find(x)]; }
};

struct edge{
  ll f,t,c;
};

bool operator<(const edge& a,const edge& b){return a.c < b.c;}

ll n,m,k;
ll col[101010];
vector<edge> es;

int main(){
	cin>>n>>m>>k;
  rep(i,n){
    cin>>col[i];
    col[i]--;
  }
  ll crtidx=k;
  rep(i,n)if(col[i]==-1)col[i]=crtidx++;
  rep(i,m){
    ll a,b,c;
    cin>>a>>b>>c;
    a--; b--;
    a=col[a];
    b=col[b];
    es.push_back((edge){a,b,c});
  }
  ll res=0,en=0;
  UnionFind uf(crtidx);
  sort(all(es));
  rep(i,m){
    edge e=es[i];
    ll u=e.f,v=e.t;
    if(uf.same(u,v))continue;
    uf.unite(u,v);
    res+=e.c;
    en++;
    if(en>=k-1)break;
  }
  if(en<k-1)cout<<-1<<endl;
  else cout<<res<<endl;

	return 0;
}


Measured memory_bytes: 5620
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll int64_t 
#define f(i,s,e) for(i=s;i<e;++i)
#define endl << "\n"
#define sp << " "
#define INF INFINITY
#define mset(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI acos(-1) 
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define eb(a) emplace_back(a)
#define print(x) for(auto it:x) cout<<it<<' '; cout<<"\n";

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std;

int main()
{
	FAST_IO ;
	ll i,j,k,n;
	cin >> n;
	string s;
	cin >> s;
	ll white,red,count ;
	white = red = count = 0;
	f(i,0,s.size())
	{
		if(s[i]=='W')
			white++ ;
		else
			red++ ;
	}
	if(red<white)
	{
		for(i=0;i<red;++i)
			if(s[i]=='R')
				count++ ;
		cout << red - count endl ;
	}
	else if(red==white)
	{
		for(i=0;i<red;++i)
			if(s[i]=='R')
				count++ ;
		ll count1 = 0;
		for(i=red;i<n;++i)
			if(s[i]=='W')
				count1++ ;
		cout << min(red-count,white-count1) endl ;	
	}
	else
	{
		for(i=red;i<n;++i)
			if(s[i]=='W')
				count++ ;
		cout << white - count endl ;
	}
	return 0;
}

/*
If u haven't come up with an approach yet ,skip this one
  Try this when feeling stuck -
  1. Int overflow, array bounds
  2. Special cases (n=1?)
  3. Prove your approach to yourself(mathematical induction,counter-intuitive or stronger test cases)
  4. Calm down and don't look at standings and stop thinking about rating and think about the question
  5. Just do it! 
*/ 

//Benq's advice - 
/* 
	And following advices are must for me -
	* do something instead of nothing and stay organized
	* WRITE STUFF DOWN 
*/

//#define _GLIBCXX_DEBUG 
// It will convert WA verdict to runtime error if that error is caused due to out of bound excess , declare it at the top
//#pragma GCC optimize "trapv" 
// It will convert WA to runtime error if WA was caused due to int overflow error,declare it anywhere

Measured memory_bytes: 3732
#include <cstdio>

const int maxn = 550;

int n, m;
char s[maxn * maxn], t[maxn * maxn * 2], *S, *T1, *T2;

int main() {
	fread(s, 1, 302500, stdin);
	S = s;
	while(*S < '0' || *S > '9') {
		++S;
	}
	while(*S >= '0' && *S <= '9') {
		(n *= 10) += *S++ - '0';
	}
	while(*S < '0' || *S > '9') {
		++S;
	}
	while(*S >= '0' && *S <= '9') {
		(m *= 10) += *S++ - '0';
	}
	T1 = t;
	T2 = T1 + n * (m + 1) + 1;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			while(*S != '.' && *S != '#') {
				++S;
			}
			if(*S++ == '#') {
				*T1++ = '#';
				*T2++ = '#';
			}
			else {
				if((i & 1) && j < m || j == 1) {
					*T1++ = '#';
					*T2++ = '.';
				}
				else {
					*T2++ = '#';
					*T1++ = '.';
				}
			}
		}
		*T1++ = '\n';
		*T2++ = '\n';
	}
	*T1++ = '\n';
	fwrite(t, 1, T2 - t, stdout);
	return 0;
}

Measured memory_bytes: 1408
N, M = map(int, input().split())

cnt=[0]*N
ans=[0]*N

ac=0
wa=0

for i in range(M):
    p, s = input().split()
    p=int(p)-1
    
    if ans[p] == 1:
        continue
    elif s == 'AC':
        ans[p]=1
        ac+=1
        wa+=cnt[p]
    else:
        cnt[p]+=1
    
print(ac, wa)

Measured memory_bytes: 4596
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define REEP(i, N) for(ll i = N - 1; i >= 0; --i)
#define FOR(i,m,n) for(ll i = m; i < n; ++i)
#define RFOR(i,m,n) for(ll i = n - 1; i >= m; --i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define PB push_back
#define KIRIAGE(a, b) a += (b - a % b) % b // a を b の倍数値まで増やす
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;} // a / b 以上の最小整数
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	ll N,M;
	cin>>N>>M;
	vector<ll> red(N, false);
	red[0] = true;
	vector<ll> s(N, 1);
	REP(i,M) {
		ll x, y;
		cin>>x>>y;
		--x;
		--y;
		if(red[x]) {
			if(s[x] <= 1) red[x] = false;
			red[y] = true;
			--s[x];
			++s[y];
		}
		else {
			--s[x];
			++s[y];
		}
	}
	ll sum = 0;
	REP(i, N) {
		if(red[i]) ++sum;
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 1792
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<f64>();
    let (a, b, h, m) = (v[0], v[1], v[2], v[3]);
    let h_angle = (h + m / 60.0) / 12.0 * 2.0 * std::f64::consts::PI;
    let m_angle = m / 60.0 * 2.0 * std::f64::consts::PI;

    let h_x = a * h_angle.sin();
    let h_y = a * h_angle.cos();

    let m_x = b * m_angle.sin();
    let m_y = b * m_angle.cos();

    let ans = (h_x - m_x).hypot(h_y - m_y);
    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2904
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <utility>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <limits.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const int MOD = 1000000007;

signed main(){
	string s,t;
	cin>>s>>t;
	int q;
	cin>>q;
	int as[114514]={},at[114514]={},bs[114514]={},bt[114514]={};
	for(int i=0;i<(int)s.size();i++){
		if(s[i]=='A'){
			as[i]=as[max(i-1,0)]+1;
			bs[i]=bs[max(i-1,0)];
		}else{
			bs[i]=bs[max(i-1,0)]+1;
			as[i]=as[max(i-1,0)];
		}	
	}
	for(int i=0;i<(int)t.size();i++){
		if(t[i]=='A'){
			at[i]=at[max(i-1,0)]+1;
			bt[i]=bt[max(i-1,0)];
		}else{
			bt[i]=bt[max(i-1,0)]+1;
			at[i]=at[max(i-1,0)];
		}	
	}
	for(int i=0;i<q;i++){
		int a,b,c,d;
		cin>>a>>b>>c>>d;
		int ba=as[b-1]-as[a-2],bb=bs[b-1]-bs[a-2],ea=at[d-1]-at[c-2],eb=bt[d-1]-bt[c-2];
		int ca=ea-ba,cb=eb-bb;
		bool ans=false;
		for(int x=0;x<3;x++){
			for(int y=0;y<3;y++){
				if((2*x-y)%3==(ca%3+3)%3&&(2*y-x)%3==(cb%3+3)%3)ans=true;

			}	
		}
		if(ans)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 2688
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <random>
#include <iomanip>
#include <unordered_map>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
//const double EPS = 1e(-12);
const double pi = acos(-1);
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 < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

ll arr[100010];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(10);

    ll N, M;
    cin >> N >> M;
    arr[0] = arr[1] = 1;
    for (int i = 1; i <= 100000; ++i)
    {
        arr[i] = arr[i - 1] * i;
        arr[i] %= MOD;
    }
    if (N < M)
        swap(N, M);

    if (N == M + 1)
    {
        cout << arr[N] * arr[M] % MOD << endl;
    }
    else if (N == M)
    {
        cout << arr[N] * arr[M] * 2 % MOD << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    public static void Main()
    {


        var N = int.Parse(Console.ReadLine());

        List<int> list = new List<int>();

        for (int i = 0; i < N; i++)
        {
            var line = int.Parse(Console.ReadLine());
            list.Add(line); 
        }

        int max = list.Max();
        List<int> list2 = new List<int>(list);
        list2.Remove(max);
        int max2 = list2.Max();

        for (int i = 0; i < N; i++)
        {
            if(list[i] == max)
            {
                Console.WriteLine(max2);
            }
            else
            {
                Console.WriteLine(max);
            }
        }  
    }
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long

const long long MOD = 1000000007;

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main(){
  int n,m,a,b;
  cin >> n >> m;
  UnionFind uf(n);
  rep(i,m){
    cin >> a >> b;
    a--;b--;
    if(!uf.same(a,b)){
      uf.unite(a,b);
    }
  }
  int ans=0;
  rep(i,n) ans=max(ans,uf.size(i));
  cout << ans << endl;
}


Measured memory_bytes: 4044
#include<cstdio>
#include<algorithm>

using namespace std;

int main(){
	int n,m;
	while(scanf("%d%d",&n,&m),n){
		int N[128]={0};
		int M[128]={0};
		int N_sum = 0;
		int M_sum = 0;
		bool flg = false;
		for(int i = 0 ; i < n; i++){
			scanf("%d",&N[i]);
			N_sum += N[i];
		}
		for(int i = 0; i < m; i++){
			scanf("%d",&M[i]);
			M_sum += M[i];
		}
		int res1=100000,res2=1000000;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m ; j++){
				int N_sub = N_sum;
				int M_sub = M_sum;
				N_sum -= N[i];
				M_sum += N[i];
				N_sum += M[j];
				M_sum -= M[j];
				if(N_sum == M_sum){
					if(res1+res2 > N[i]+M[j]){
						res1 = N[i];
						res2 = M[j];
					}
					flg = true;
				}
				N_sum = N_sub;
				M_sum = M_sub;
			}
		}
		if(flg) printf("%d %d\n",res1,res2);
		else puts("-1");
	}
	return 0;
}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N;i++)
    {
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    int Alice = 0;
    int Bob = 0;
    for (int i = 0; i < N; i++)
    {
        if(i % 2 == 1){
            Alice += A[i];
        }
        else{
            Bob += A[i];
        }
    }
    cout << abs(Alice - Bob) << endl;
}


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

using namespace std;

int main(){
    int N;
    //都市の数,Nを定義
    int M;
    //道路の数,Mを定義
    cin >> N >> M;
    //N,Mの順で標準入力
    vector <int> num(N);
    for (int i = 0; i < M; i++){
        int Na;
        //他の都市Na
        int Nb;
        //他の都市Nb
        //それぞれの都市が他の都市に繋がる道路を何本もっているか保持する配列(Num)を用意する
        cin >> Na >> Nb;
        //道路の本数分入力を受け取る
        num [Na-1]++;
        num [Nb-1]++;
        //受け取った入力の道路に繋がっている都市の配列(Num)へカウント+1する
    }
    for (int i = 0; i < num.size(); i++){
        cout << num[i] << endl;
        //Numの要素を書き出す
    }
}

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

using namespace std;

typedef long long ll;

ll P[66][202020], L[66][202020];
ll A[404040], C[202020];
vector <ll> S;
ll n, k;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll i, j, l, p;
	
	cin >> n >> k;
	
	for(i=0; i<n; i++){
		cin >> A[i];
		A[n + i] = A[i];
	}
	
	for(i=n+n-1; i>=0; i--){
		if(i < n){
			L[0][i] = C[A[i]] - i + 1;
			P[0][i] = (C[A[i]] + 1) % n;
		}
		C[A[i]] = i;
	}
	
	for(i=1; i<60; i++){
		for(j=0; j<n; j++){
			L[i][j] = min((ll)1e18, L[i - 1][j] + L[i - 1][P[i - 1][j]]);
			P[i][j] = P[i - 1][P[i - 1][j]];
		}
	}
	
	for(l=0, p=0; l<n*k; ){
		for(i=59; i>=0 && l<n*k; i--){
			if(l + L[i][p] <= n * k){
				l += L[i][p];
				p = P[i][p];
			}
		}
		if(l == n * k) break;
		S.push_back(A[p]);
		l ++; p = (p + 1) % n;
	}
	
	for(ll &t: S) cout << t << " ";
	
	cout << "\n";
	
	return 0;
}

Measured memory_bytes: 199792
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

ll uni[200005];
ll root(ll u){
    if(uni[u]<0)return u;
    return uni[u]=root(uni[u]);
}
void connect(int a,int b){
    a=root(a);
    b=root(b);
    if(a==b)return;
    if(uni[a]>uni[b]){
        a^=b;
        b^=a;
        a^=b;
    }
    uni[a]+=uni[b];
    uni[b]=a;
    return;
}
ll size(ll u){
    return -uni[root(u)];
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    memset(uni,-1,sizeof(uni));
    ll n;
    cin>>n;
    ll x,y;
    bool a[100005],b[100005];
    ll c[100005],d[100005];
    for(int i=0;i<100005;i++){
        a[i]=b[i]=false;
        c[i]=d[i]=0;
    }
    for(int i=0;i<n;i++){
        cin>>x>>y;
        connect(x,y+100000);
        a[x]=b[y]=true;
    }
    for(int i=1;i<=100000;i++){
        if(a[i])c[root(i)]++;
        if(b[i])d[root(i+100000)]++;
    }
    ll num=0;
    for(int i=1;i<=100000;i++){
        num+=c[i]*d[i];
    }
    cout << num-n<<endl;
    return 0;
}





Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n; cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    sort(all(l));

    int ans = 0;
    for (int c=n-1; c>=2; c--) {
        for (int b=c-1; b>=1; b--) {
            int tmp1 = l[c]-l[b];
            int tmp2 = l[b]+l[c];
            int a = lower_bound(all(l),tmp1+1)-l.begin()-1;
            if (b-1-a<0) continue;
            ans += b-1-a;
            //if (*lower_bound(all(l),tmp1)==l[b]) 
            // int a1 = lower_bound(all(l),tmp2)-l.begin();
            // if (a1 > b) a1 = b;
            
            // int a2 = lower_bound(all(l),tmp1)-l.begin();
            // if (a1 < a2) continue;
            // ans += a1-a2;
            //cout << ans << endl;
        }
    }
    cout << ans << endl;
}

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

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

  cin >> a >> b >> c;

  int ans = 0;
  for (int i = a; i <= b; i++) {
    if (c % i == 0) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3124
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
// #define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    string s;
    cin>>s;
    vi a(26);
    rep(i,4)a[s[i]-'A']++;
    RSORT(a);
    Yes(a[0]==a[1]&&a[0]==2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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 (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
//const int MOD = 1e9 + 7;

ll N, M, K, Q;
string S;

int main() {
    cin >> N >> K;
    vector<long double> p(N);
    for (int i = 0; i < N; i++) {
        cin >> p.at(i);
    }

    long double now = 0;
    for (int i = 0; i < K; i++) {
        now += (p[i] + 1.0) / 2.0;
    }
    long double ans = now;

    for (int i = K; i < N; i++) {
        now -= (p[i - K] + 1.0) / 2.0;
        now += (p[i] + 1.0) / 2.0;
        chmax(ans, now);
    }
    cout << setprecision(11) << ans << endl;

    return 0;
}


Measured memory_bytes: 3328
#include<map>
#include<iostream>
#include<deque>
#include<algorithm>
#include<string>
#include<cctype>
#include<iomanip>
#include<vector>
#include<queue>
#include<math.h>
#include<bitset>
#include<random>
 
using namespace std;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
 
#define shosu setprecision(17)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<char,P> Q;
//ll longinf=1ll<<60;
int inf=1<<29;
ll longinf=(1ll<<60);

int dx[]={1,-1,0,0};
int dy[]={0,0,-1,1};

int N;
int M;
int ans;
vector<int> nxt[100000];
vector<int> bfr[100000];

ll dp[100001];

ll dfs(ll x){
    if(dp[x]==longinf) dp[x]=0;
    for(auto y:nxt[x]){
        if(dp[y]!=longinf){
            dp[x]=max(dp[x],dp[y]+1);
        }
        else{
            dp[x]=max(dp[x],dfs(y)+1);
        }
    }
    return dp[x];
}


signed main(){
    string s,t;
    cin>>s>>t;
    vector<int> num;
    int n,m;
    n=s.size();
    m=t.size();
    int dp[n+1][m+1];
    rep0(i,n+1)rep0(j,m+1) dp[i][j]=0;
    s='.'+s;
    t=':'+t;
    rep1(i,n){
        rep1(j,m){
            if(s[i]==t[j]){
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
        }
    }
    int j=m;
    string ans;
    /*rep1(i,n){
        rep1(j,m){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    int tmp=dp[n][m];
    int tmpi=n;
    int tmpj=m;
    for(int i=n-1;i>=0;i--){
        for(int j=m-1;j>=0;j--){
            if(dp[i+1][j]==tmp-1&&dp[i][j+1]==tmp-1&&dp[i][j]+1==dp[i+1][j+1]&&dp[i+1][j+1]==tmp&&i<tmpi&&j<tmpj){
                ans=s[i+1]+ans;
                tmp=dp[i][j];
                tmpi=i;
                tmpj=j;
                //cout<<i<<" "<<j<<endl;
            }
        }
    }
   //cout<<tmp<<endl;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 40192
fun main (args : Array<String>) {
	val (n, l) = readLine()!!.split(" ").map(String::toInt)
	val N : Int = n.toInt()
	val L : Int = l.toInt()
	
	var calc : Int
	var min : Int = 0
	var result : Int = 0
	
	for (i in 1..N) {
		calc = ( (L + i) - 1 )
		result += calc
		if (calc < 0) {
			calc = -(calc)
		}
		if (i == 1) {
			min = calc
		}
		if (min > calc) {
			min = calc
		}
	}
	//println("${result}, ${min}")
	if (result > 0) {
		return println("${result - min}")
	}
	println("${result + min}")
	
}

Measured memory_bytes: 37904
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define inf 1e+9
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

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

    int n,k,ans=0;
	cin >> n;
	vint v(n);
	int p[n];
	rep(i,n){
		cin >> v[i];
		p[i] = v[i];
	}

	std::sort(v.begin(),v.end());

	rep(i,n){
		if(p[i]!=v[i]){
			ans++;
		}
	}

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
using namespace std;

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

    int d[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &d[i]);
    }


    if (n%2 == 0){
        sort(d, d + n);

        if(d[(n/2)-1] != d[n/2]){
            sum = d[n/2] - d[(n/2)-1];
        }  
  }

    cout << sum << "\n";
     
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";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 vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	string S; cin >> S;
	vector<char> acgt = {'A', 'C', 'G', 'T'};
	int res = 0;
	int current = 0;
	REP(i, S.length()) {
		if (find(ALL(acgt), S[i]) == end(acgt)) {
			res = max(res, current);
			current = 0;
		} else {
			++current;
		}
	}
	res = max(res, current);
	cout << res << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 256
<?php
  
list($a, $b, $k) = explode(" ", trim(fgets(STDIN)));

if ($a+$b <= $k) {
    echo "0 0\n";
} else if ($k <= $a) {
    $ax = $a - $k;
    echo "$ax  $b\n";
} else {
    $bx = $b-($k-$a) <= 0 ? 0 : $b-($k-$a);
    echo "0  $bx\n";
}

Measured memory_bytes: 4728
x = gets.chomp.to_i

if x < 600
  puts 8
elsif x < 800
  puts 7
elsif x < 1000
  puts 6
elsif x < 1200
  puts 5
elsif x < 1400
  puts 4
elsif x < 1600
  puts 3
elsif x < 1800
  puts 2
else
  puts 1
end


Measured memory_bytes: 14400
#n = gets.chomp.to_i
#arr = gets.chomp.split(" ").map{|i|i = i.to_i}

a = []
a << gets.chomp.to_i
a << gets.chomp.to_i
a << gets.chomp.to_i
a << gets.chomp.to_i
a << gets.chomp.to_i

all_time = 0
amari=10
amari_pos = -1
5.times do|i|
  if (amari>(a[i]%10)) && ((a[i]%10)!=0) then
    amari = a[i]%10
    amari_pos= i 
  end
end
if amari==10 then
  amari_pos=0
end
#puts "amari=#{amari}, amari_pos=#{amari_pos}"
all_time += a[amari_pos]
a.delete_at(amari_pos)
4.times do|ii|
  i = a[ii]
  #puts "i=#{i}" 
  if ((i%10)!=0) then 
    all_time += ((i/10)*10+10)
  else 
    all_time += i
  end
end

puts all_time






Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
struct unionfind{
  vector<int> p;
  unionfind(int n){
    p = vector<int>(n, -1);
  }
  int root(int x){
    if (p[x] == -1){
      return x;
    } else {
      p[x] = root(p[x]);
      return p[x];
    }
  }
  bool same(int x, int y){
    x = root(x);
    y = root(y);
    return x == y;
  }
  void unite(int x, int y){
    x = root(x);
    y = root(y);
    if (x != y){
      p[x] = y;
    }
    return;
  }
};
int main(){
  int n, q;
  cin >> n >> q;
  unionfind S(n);
  for (int i = 0; i < q; i++){
    int t;
    cin >> t;
    if (t == 0){
      int x, y;
      cin >> x >> y;
      S.unite(x, y);
    }
    if (t == 1){
      int x, y;
      cin >> x >> y;
      if (S.same(x, y)){
        cout << 1 << endl;
      } else {
        cout << 0 << endl;
      }
    }
  }
}


Measured memory_bytes: 3188
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    s = S()
    cnt0 = s.count("0")
    cnt1 = s.count("1")

    ans = min(cnt0, cnt1)*2
    print(ans)
main()


Measured memory_bytes: 74476
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int a, b; cin >> a >> b;
    string s = string(b, (char)('0' + a));
    string t = string(a, (char)('0' + b));
    cout << (s < t ? s : t) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_lim=(n); i<i##_lim; ++i)
#define FOR(i, a, b) for (int i=(a), i##_lim=(b); i<i##_lim; ++i)
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;

int main()
{
    int N, K;
    cin >> N >> K;
    int V[N];
    REP(i, N) cin >> V[i];

    int ret = 0;
    vector<int> lv;
    int ls = 0;

    REP(l, min(N, K)+1)
    {
        if (l != 0) { ls += V[l-1]; lv.pb(V[l-1]); }
        sort(lv.begin(), lv.end());

        vector<int> rv;
        int rs = 0;
        REP(r, min(N, K)-l+1)
        {
            if (r != 0) { rs += V[N-r]; rv.pb(V[N-r]); }
            sort(rv.begin(), rv.end());

            int sum = ls + rs;
            int li = 0;
            int ri = 0;

            while (li+ri < K-(l+r))
            {
                if (lv.empty() && (ri >= rv.size() || rv[ri] >= 0)) break;
                if (rv.empty() && (li >= lv.size() || lv[li] >= 0)) break;
                if ((li >= lv.size() || lv[li] >= 0) && (ri >= rv.size() || rv[ri] >= 0)) break;
                int l = lv.empty() || li >= lv.size() ? 0 : lv[li];
                int r = rv.empty() || ri >= rv.size() ? 0 : rv[ri];
                if (l < r) sum -= lv[li++];
                else sum -= rv[ri++];
            }

            ret = max(sum, ret);
        }
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
import numpy as np
N = int(input())
F = np.array([list(map(int, input().split())) for _ in range(N)])
P = [list(map(int, input().split())) for _ in range(N)]
benefit = -float("inf")

for i in itertools.product((0, 1), repeat=10):
    if sum(i) != 0:
        C = np.array(list(i)) + F
        pre_benefit = 0
        for j in range(N):
            count = len(np.where(C[j]==2)[0])
            pre_benefit += P[j][count]
        if benefit < pre_benefit:
            benefit = pre_benefit
print(benefit)

Measured memory_bytes: 13268
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<iomanip>

using namespace std;
using ll = long long;

const int MOD = 1e9 + 7;
const int INF = numeric_limits<int>::max();
const ll LLINF = numeric_limits<ll>::max();
const double PI = acos(-1.0);

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, a, n) for (int i = a; i <= (n); ++i)

int main() {
    int A, B; cin >> A >> B;
    
    if ((A * B) & 1) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  rep(i, n) ans += (i + 1) * (i + 2) / 2;
  rep(i, n - 1) {
    ll u, v;
    cin >> u >> v;
    if(u > v) swap(u, v);
    ans -= u * (n - v + 1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3592
#include <stdio.h>


int main(void)
{
    
    while (1) {
        int num, a, b;
        int result_a = 0;
        int result_b = 0;
        int i = 0;
        
        scanf("%d\n", &num);

        if (num == 0) {
            break;
        }
        
        for (i = 0; i < num; i++) {
            scanf("%d %d\n", &a, &b);

            if (a < b) {
                result_b = result_b + a + b;
            }
            else if (a > b) {
                result_a = result_a + a + b;
            }
            else {
                result_a = result_a + a;
                result_b = result_b + b;
            }
        }
        printf("%d %d\n", result_a, result_b);
    }
    
    return 0;
}

Measured memory_bytes: 604
#include<bits/stdc++.h>
using namespace std;
#include <math.h>
#define ll long long 
// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
#define max1 1000001

//long long int mod=1e18 ;


int main(){	
	int n,w;
	cin>>n>>w;
	vector<int> we(n);
	vector<int> v(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>we[i]>>v[i];
	}
	long long int dp[n+1][w+1];
	memset(dp,0,sizeof(dp));
	for(int i=1;i<=n;i++){
		for(int j=1;j<=w;j++){
			dp[i][j]=dp[i-1][j];
			if(j-we[i-1] < 0)
				continue;
			dp[i][j]=max(dp[i][j],dp[i-1][j-we[i-1]]+v[i-1]);
		}
		//cout<<dp[i][w]<<endl;
	}
	cout<<dp[n][w]<<endl;


}
	
	
	
	





Measured memory_bytes: 79104
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;
int main() {
	cin >> N;
	set<ll> set;
	for (int i = 0; i < N; i++) {
		cin >> D;
		set.insert(D);
	}
	cout << set.size();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n; cin >> n;
  vector<vector<int>> G(n);
  vector<int> a(n), b(n);
  for(int i = 0; i < n-1; i++){
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }

  int k = 0, s = 0;
  for(int i = 0; i < n; i++){
    if(k < (int)G[i].size()) s = i;
    k = max(k, (int)G[i].size());
  }
  cout << k << endl;

  map<pair<int,int>,int> mp;
  function< void(int,int,int) > dfs =
  [&](int u, int pre, int dame){
    int color = 1;
    for(int v : G[u]){
      if(v == pre) continue;
      if(color == dame) color++;
      mp[minmax(u, v)] = color;
      dfs(v, u, color);
      color++;
    }
    return;
  };
  dfs(s, -1, -1);

  for(int i = 0; i < n-1; i++){
    cout << mp[minmax(a[i], b[i])] << endl;
  }

  return 0;
}


Measured memory_bytes: 17152
INF = 100000 * 100

def dijkstra(s: int) -> None:
	d[s] = 0	
	while True:
		mincost = INF
		for i in range(n):
			if color[i] != "BLACK" and d[i] < mincost:
				mincost = d[i]
				u = i
		if mincost == INF:
			break
		color[u] = "BLACK"
		for v in range(n):
			if color[v] != "BLACK" and M[u][v] != None:
				if d[u] + M[u][v] < d[v]:
					d[v] = d[u] + M[u][v]
					pi[v] = u
					color[v] = "GRAY"


if __name__ == "__main__":
	n = int(input())
	G = []
	M = [[None for _ in range(n)] for _ in range(n)]
	color = ["WHITE" for _ in range(n)]
	d = [INF for _ in range(n)]
	pi = [None for _ in range(n)]

	for _ in range(n):
		l = list(map(int, input().split()))
		u = l[0]
		k = l[1]
		for i in range(k):
			v = l[2 * (i + 1)]
			c = l[2 * (i + 1) + 1]
			M[u][v] = c
	dijkstra(0)
	for v in range(n):
		print(f"{v} {d[v]}")


Measured memory_bytes: 5876
n,m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(m)]

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

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

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

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


uf = UnionFind(n)
ans = [n*(n-1)//2]

for a,b in ab[::-1]:
    if not uf.same(a-1, b-1):
        ans.append(ans[-1] - uf.size(a-1) * uf.size(b-1))
    else:
        ans.append(ans[-1])
    uf.union(a-1, b-1)

for i in ans[-2::-1]:
    print(i)


Measured memory_bytes: 112728
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
char s[200010];
int main(){
    int n,a,b,c,d;scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
    scanf("%s",s+1);
    if((a<b)==(c<d)){
        bool flag=false;
        for(int i=a;i<c;i++) if(s[i]=='#'&&s[i+1]=='#') flag=true;
        for(int i=b;i<d;i++) if(s[i]=='#'&&s[i+1]=='#') flag=true;
        if(flag) puts("No");
        else puts("Yes");
    }else{
        if(a>b) {swap(a,b);swap(c,d);}
        bool flag=false;
        for(int i=b;i<d;i++) if(s[i]=='#'&&s[i+1]=='#') flag=true;
        for(int i=a;i<c;i++) if(s[i]=='#'&&s[i+1]=='#') flag=true;
        bool flag2=false;
        for(int i=b;i<=d;i++) if(s[i]=='.'&&s[i-1]=='.'&&s[i+1]=='.') flag2=true;
        if(flag||flag2==false) puts("No");
        else puts("Yes");
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> V(N), C(N);
  for (int i = 0; i < N; i++) cin >> V[i];
  for (int i = 0; i < N; i++) cin >> C[i];
  int res = 0;
  for (int i = 0; i < N; i++) res += max(0,V[i] - C[i]);
  cout << res;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

#define vvint(vec,n,m,l) vector<vector<int>> vec(n,vector<int>(m,l));
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>;
#define pint pair<int,int>;
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")


int ans[10];
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	int a, b, c;
	cin >> a >> b >> c;


	ans[a]++; ans[b]++; ans[c]++;
	if (ans[5] == 2 && ans[7] == 1)
	{
		cout << "YES";
	}
	else
	{
		cout << "NO";
	}
	cout << endl;

}

Measured memory_bytes: 256
eater::[Char] ->  Char  -> [Char]
eater ls c = case c of
             '0' -> '0':ls
             '1' -> '1':ls
             'B' -> if ls == [] then [] else tail ls

main::IO()
main=do
  str<-getLine
  putStr (reverse (foldl eater [] str))
  putStr "\n"

Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

int main() { IO;
  vector<int> v(5);
  for (auto &x : v) {
    cin >> x;
  }

  int sum = 0;
  int diff = 0;
  for (auto &x : v) {
    int t = 10 * ((x + 9) / 10);
    diff = max(diff, t - x);
    sum += t;
  }

  cout << sum - diff << endl;

  return 0;
}


Measured memory_bytes: 256