akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define rFORq(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
const ll p = 1000000007;
int main(){
    int H,W,K; SCD3(H,W,K);
    static ll dp[102][10] = {};
    static ll F[9] = {1,1,2,3,5,8,13,21,34};

    dp[0][1] = 1;

    FORq(i,0,H){
        FORq(j,1,W){
            ll X,Y,Z;
            X=0;Y=0;Z=0;

            if (j != 2) X = F[j-2] * F[W-j];
            else X = F[W-2];

            Y = F[j-1] * F[W-j];

            if (j != W) Z = F[j-1] * F[W-j-1];
            else Z = F[W-2];

            //printf("(i,j) = (%d,%d) , X = %lld, Y = %lld, Z = %lld\n",i,j,X,Y,Z);

            dp[i+1][j-1] = (dp[i+1][j-1] + (X * dp[i][j]) % p) % p;
            dp[i+1][j] = (dp[i+1][j] + (Y * dp[i][j]) % p) % p;
            dp[i+1][j+1] = (dp[i+1][j+1] + (Z * dp[i][j]) % p) % p;

        }
    }

    PRINTLLD(dp[H][K]);

}

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

int main(){
    string s;
    cin >> s;
    int a=0,b=0;
    ll l;
    l=s.size();
    string s2;
    rep(i,l){
        s2=s[i];
        if(s2=="0"){
            ++a;
        }
        else{
            ++b;
        }
    }

    ll ans;
    ans=2*min(a,b);
    cout << ans << endl;

    

    return 0;
}

Measured memory_bytes: 3736
#include <iostream>
#include <string.h>
using namespace std;
short dp[4001][4001];
int main(){
  string s,t;


  while(cin >> s >> t){
    memset(dp,0,sizeof(dp));
    dp[0][0] = 0;
    int ans = 0;
    for(int i = 0 ; i < s.size();i++){
      for(int j = 0 ; j < t.size();j++){
	if(s[i] == t[j]){
	  dp[i+1][j+1] = dp[i][j] + 1;
	  if(dp[i+1][j+1] > ans)ans = dp[i+1][j+1];
	}else {
	  dp[i+1][j+1] = 0;
	}
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 32480
#include <iostream>

using namespace std;

int main()
{
    int a, b, k;
    cin >> a >> b >> k;

    for(int i = a; i <= min(b, a + k - 1); i++)
    {
        cout << i << endl;
    }

    for(int i = max(b - k + 1, a + k); i <= b; i++)
    {
        cout << i << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n), c(n);
  rep(i, n) {
    cin >> a[i];
  }
  rep(i, n) {
    cin >> b[i];
  }
  rep(i, n) {
    cin >> c[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  sort(c.begin(), c.end());
  vector<int>tmp(n);
  vector<long long>cum(n);
  rep(i, n) {
    int x = b[i];
    int ok = n;
    int ng = -1;
    while(abs(ok-ng) > 1) {
      int mid = (ok + ng) / 2;
      //cout << a[mid];
      if(a[mid] >= x) {
        ok = mid;
      }
      else {
        //cout << x << ":" << ng << endl;
        ng = mid;
      }
    }
    if(i == 0) {cum[i] = ok;}
    else { cum[i] += cum[i-1] + ok; }
  }
  //rep(i, n) {
  //  cout << cum[i] << " ";
  //}
  cout << endl;
  long long sum = 0;
  rep(i, n) {
    int x = c[i];
    int ok = n;
    int ng = -1;
    while(abs(ok-ng) > 1) {
      int mid = (ok + ng) / 2;
      if(b[mid] >= x) {
        ok = mid;
      }
      else {
        ng = mid;
      }
    }
    if(ok != 0) {
      sum += cum[ok-1];
    }
  }
  //rep(i, n) {
  //  cout << a_sort[i] << " ";
  //}
  //cout << endl;
  //rep(i, n) {
  //  cout << b_sort[i] << " ";
  //}
  //cout << endl;
  cout << sum << endl;
}


Measured memory_bytes: 2560
#include<stdio.h>

int main(void){
  long long int N;
  scanf("%ld",&N);
  long long int A[N];
  int i,j;
  long long int S[N+1];
  for(i=0;i<N+1;i++){
    S[i]=0;
  }
  for(i=0;i<N;i++){
    scanf("%ld",&A[i]);
    S[i+1]=S[i]+A[i];
  }
  long long int sum=0;
  long int mod=1000000007;
  for(i=0;i<N-1;i++){
    sum+=A[i]*((S[N]-S[i+1])%mod);
    sum%=mod;
  }
 
  
  printf("%ld",sum);
  return 0;
}

Measured memory_bytes: 4856
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;int flag=0;
	cin>>n;
	while(n!=0)
	{
		if(n%10==7)
		{
			flag=1;
			break;
		}
		n/=10;
	}
	flag?cout<<"Yes"<<endl:cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>

#define true 1
#define false 0

int i,K,val=0,fin_f=false;

void count(int num,int v){
  for(i=num;i>0;i--){
    val+=v;
    K--;
    if(K==0){
      fin_f=true;
      break;
    }
  }
}

void is_fin(){
  if(fin_f==true){
    printf("%d\n",val);
    exit(0);
  }
}
int main(void){

  int A,B,C;
  scanf("%d %d %d %d",&A,&B,&C,&K);

  count(A,1);
  is_fin();
  count(B,0);
  is_fin();
  count(C,-1);
  is_fin();
  return 0;
}

Measured memory_bytes: 1732
from sys import stdin
import sys
import numpy as np
import collections
from functools import cmp_to_key

##  input functions for me
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def rip(sep = ''):
    if sep == '' :
        return map(int, input().split()) 
    else: return map(int, input().split(sep))
def ria(sep = ''): 
    return list(rip(sep))
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    S = rs()
    N = len(S)
    a = [0] * (N + 1)
    for i in range(N):
        if S[i] == '<':
            a[i + 1] = a[i] + 1
        else:
            a[i + 1] = a[i] - 1
    
    b = min(a)
    for i in range(N + 1): a[i] -= b
    l = []
    for i in range(N + 1):
        l.append((a[i],i))
    
    def cmp(_p, _q):
        if(_p[0] < _q[0]): return -1
        if(_p[0] > _q[0]): return 1
        return 0
    l = sorted(l, key=cmp_to_key(cmp))

    for dep, pos in l:
        if pos == 0:
            if S[pos] == '<':
                a[pos] = 0
            else:
                a[pos] = a[pos + 1] + 1
        elif pos == N:
            if S[pos - 1] == '>':
                a[pos] = 0
            else:
                a[pos] = a[pos - 1] + 1
        else:
            if S[pos - 1] == '<' and S[pos] == '<':
                a[pos] = a[pos - 1] + 1
            elif S[pos - 1] == '<' and S[pos] == '>':
                a[pos] = max(a[pos - 1], a[pos + 1]) + 1
            elif S[pos - 1] == '>' and S[pos] == '<':
                a[pos] = 0
            elif S[pos - 1] == '>' and S[pos] == '>':
                a[pos] = a[pos + 1] + 1
    
    print(sum(a))

if __name__ == "__main__":
    main()


Measured memory_bytes: 110912
#include <stdio.h>
int main(void){
  int a, b, c, x, i, j, fif, count;
  scanf("%d%d%d%d", &a, &b, &c, &x);
  for(i=0;i<=x/500;i++)
    for(j=0;j<=(x-500*i)/100;j++){
      fif = x-500*i-100*j;
      count += fif % 50 == 0 && c >= fif/50 && a >=i && b >=j;
    }
  printf("%d", count);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include <stdio.h>
#include <bitset>
#include<math.h>
#include<list>
#include<map>
using namespace std;
typedef long long ll;
bool serch(int n) {
	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			if (i*j == n) {
				return true;

			}
		}
	}
	return false;
}

int main() {
	int n;
	bool ans;
	cin >> n;
	ans = serch(n);
	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	double ans=0;
	rep(i,n){
		double a; string s;
		cin>>a>>s;
		if(s=="JPY")ans+=a;
		else ans+=a*380000;
	}
	fcout(10)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	priority_queue< double,vector<double>,greater<double> > a;
	for(int i=0;i<n;i++){
		double t;
		cin>>t;
		a.push(t);
	}
	for(int i=0;i<n-1;i++){
		double x=a.top();a.pop();
		double y=a.top();a.pop();
		double tmp=(x+y)/2;
		a.push(tmp);
	}
	cout<<fixed<<setprecision(6)<<a.top()<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
long long n,m,i,j,ans;
int main()
{
	cin>>n>>m;
	if (m==0)
	{
		cout<<sqr(n);
		return 0;
	}
	for (i=m+1;i<=n;i++)
	{
		long long x=i-m;
		ans+=n/i*x;
		if (n%i>=m) ans+=n%i-m+1;
	}
	cout<<ans;
	return 0; 
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void) {
	int k, a, b;
	cin >> k >> a >> b;
	string ans = "NG";
	for (int i = a; i <= b; ++i) {
		if (i % k == 0) ans = "OK";
	}
	cout << ans;
	return 0;
}

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

using namespace std;

int main() {

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

	double n;
	cin >> n;
	double x = (ceil(n / 1.08));
	if (floor(x * 1.08) == n) cout << (int) x << '\n';
	else {
		double x = floor(n / 1.08);
		if (floor(x * 1.08) == n) cout << (int) x << '\n';
		else cout << ":(\n";
	}

	return 0;
}

Measured memory_bytes: 256
s = input()

deposit = 0
score = 0
for i in s:
    if deposit > 0 and i == "g":
        deposit -= 1
        score += 1
    elif deposit == 0 and i == "g":
        deposit += 1
    elif deposit > 0 and i == "p":
        deposit -= 1
    elif deposit == 0 and i == "p":
        deposit += 1
        score -= 1
print(score)


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

int main(){
    int N,L,sum1=0,sum2=0;
    cin>>N>>L;
    int A[N];
    int m=1<<30;
    for(int i=0;i<N;i++){
        A[i]=L+i;
        m=min(m,abs(A[i]));
        sum1=sum1+A[i];
    }
    if(sum1>0){
        sum2=sum1-m;
    }
    else{
        sum2=sum1+m;
    }
    cout<<sum2<<endl;
}


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

int main() {
  int N;
  cin >> N;
  
  int A[N];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  sort(A, A+N);
  
  for (int i = 0; i < N-1; i++) {
    if (A[i] == A[i+1]) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <random>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

ll y[10000005];

int main() {
    int n, cnt = 0; cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    while(1){
        bool ok = true;
        rep(i,n){
            if(a[i]%2==0) a[i] /= 2;
            else {
                ok = false;
                break;
            }
        }
        if(!ok) break;
        else cnt++;
    }
    cout << cnt << endl;
}




Measured memory_bytes: 3628
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    for(int i = 0;i<n;i++) {
      a[i] = stdIn.nextInt();
    }
    int[] clone = new int[n-1];
    int ma = max(a);
    int k = 0;
    for(int i = 0;i<a.length;i++) {
      if(a[i]==ma) {
        k = i;
        break;
      }
    }
    un(a,clone,k);
    int ma2 = max(clone);
    for(int i = 0;i<a.length;i++) {
      if(i!=k) System.out.println(ma);
      else System.out.println(ma2);
    }
  }
  public static void un(int[] a,int[] clone,int j) {
    int k = 0;
    //System.out.println(j);
    for(int i = 0;i<a.length;i++) {
      if(i!=j)  {clone[k] = a[i];k++;}
    }
    //System.out.println("hei");
      }
  public static int max(int[] a) {
    int b = a[0];
    for(int i = 1;i<a.length;i++) {
      b = Math.max(b,a[i]);
    }
    return b;
  }
}


Measured memory_bytes: 93940
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

vector<ll> explode(string const & s, char delim) {
    vector<ll> result;
    string token;
    for (istringstream iss(s); getline(iss, token, delim);) result.push_back(stoll(token));
    return result;
}

void solve() {
    int n;
    cin >> n;
    vl a(n * 3);
    REP(i, n * 3) cin >> a[i];
    SORT(a); REV(a);
    ll ans = 0;
    REP(i, n) ans += a[2 * i + 1];
    cout << ans << endl;
}


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

using namespace std;

// 2変数の最大公約数を求める関数
int gcd_func(int a, int b)
{
	// 2変数の剰余が0になったら、『割られる数』＝『最大公約数』
	if (b == 0)
	{
		return a;
	}
	
	return gcd_func(b, a % b);
}

int main()
{
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
	{
		cin >> A[i];
	}
	
	// 累積GCD
	vector<int> leftA(N + 1, 0);
	vector<int> rightA(N + 1, 0);
	for (int i = 0; i < N; i++)
	{
		leftA[i + 1] = gcd_func(leftA[i], A[i]);
	}
	for (int i = N - 1; i >= 0; i--)
	{
		rightA[i] = gcd_func(rightA[i + 1], A[i]);
	}
	
	int answer = 0;
	
	// N個の最大公約数の最大値の計算
	for (int i = 0; i < N; i++)
	{	
		answer = max(answer, gcd_func(leftA[i], rightA[i + 1]));
	}
	
	cout << answer << endl;
	
	return 0;
}

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


int main(){
 int sum=0;
 int x;
  for(int i=0;i<5;i++){
    cin>>x;
    sum+=x;
  }
  cout << 15-sum;
  
  
 return 0;
}

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

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

long long MOD = 1000000000 + 7;
struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

int main(){
  cout << setprecision(10);
  int N; cin >> N;
  vector<pair<ll,int>> x(N), y(N);
  for(int i = 0; i < N; i++){
    ll tmp1,tmp2; cin >> tmp1 >> tmp2;
    x[i] = make_pair(tmp1, i);
    y[i] = make_pair(tmp2, i);
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());

  vector<pair<ll, pair<int,int>>> v;

  for(int i = 0; i < N-1; i++){
    ll weight_x = abs(x[i].first - x[i+1].first);
    ll weight_y = abs(y[i].first - y[i+1].first);

    v.push_back(make_pair(weight_x, make_pair(x[i].second, x[i+1].second)));
    v.push_back(make_pair(weight_y, make_pair(y[i].second, y[i+1].second)));
  }

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

  UnionFind tree(N);

  ll ans = 0;
  for(int i = 0; i < v.size(); i++){
    ll weight = v[i].first;
    int s = v[i].second.first;
    int t = v[i].second.second;

    if(tree.root(s) == tree.root(t)){
      continue;
    } else { 
      ans += weight;
      tree.unionSet(s,t);
    }
  }
  cout << ans << endl;

}


Measured memory_bytes: 10548
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define bFor(i,a,b) for(i=a;i>=b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

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

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll i,j,N,M,K;
  cin>>N>>M>>K;
  rep(i,N+1){
    rep(j,M){
      if(i*j+(N-i)*(M-j)==K){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
tmp = input().split(" ")
K = int(tmp[1])
 
num = [0 for i in range(10**5)]
for i in range(int(tmp[0])):
    tmp = input().split(" ")
    num[int(tmp[0])-1] += int(tmp[1])
    
tmp = 0
i = 0
while tmp < K:
    tmp = tmp + num[i]
    if tmp >= K:
        print(i+1)
    i = i + 1

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    for(int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    vector<int> res(N);
    for(int i = 0; i < M; ++i) {
        int B; cin >> B;
        for(int j = 0; j < N; ++j) {
            if(A[j] <= B) {
                res[j] += 1;
                break;
            }
        }
    }
    cout << max_element(begin(res), end(res)) - begin(res) + 1 << endl;
}


Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
int n,k,p[2000],ans;
int main()
{
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>p[i];
	sort(p,p+n);
	for(int i=0;i<k;i++)ans+=p[i];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

vector<int> edges[300005];

bool vis[300005];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        edges[u].push_back(n + v);
        edges[n + u].push_back(2 * n + v);
        edges[2 * n + u].push_back(v);
    }
    int s, t;
    cin >> s >> t;
    queue<int> q;
    vis[s] = true;
    q.push(s);
    int layer = -1;
    bool ok = false;
    while (!q.empty() && !ok) {
        int len = q.size();
        for (int i = 0; i < len; i++) {
            int cur = q.front(); q.pop();
            if (cur == t) { ok = true; break; }
            for (int nxt : edges[cur]) {
                if (!vis[nxt]) {
                    vis[nxt] = true;
                    q.push(nxt);
                }
            }
        }
        layer++;
    }
    if (ok) {
        cout << layer / 3 << endl;
    } else {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 20280
#include<iostream>
using namespace std;
#define M 200005
int A[M], B[M];
int main() {
	int n,cnt=0;
	scanf("%d",&n);
	for (int i=1; i<=n; i++) scanf("%d", &A[i]);
	for (int i=n; i>=1; i--) {
		for (int j=i+i; j<=n; j+=i) {
			A[i] ^= A[j];
		}
		if (A[i]) cnt++;
	}
	printf("%d\n", cnt);
	for (int i=1; i<=n; i++) {
        if (A[i]) printf("%d ", i);
    }
	return 0;
}


Measured memory_bytes: 1792
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> n >> k;
  rep(i, n) cin >> a[i];
  rep(i, n + 1) {
    rrrep(j, n - 1, -1) {
      // i-1までj+1まで
      if (j + 1 <= i - 1) continue;
      ll fu[n + 10] = {}, f_cou = 0, sousa = 0;
      cnt = 0;
      rep(z, i) {
        cnt += a[z];
        sousa++;
        if (a[z] < 0) fu[f_cou++] = a[z];
      }
      rrep(z, j + 1, n) {
        cnt += a[z];
        sousa++;
        if (a[z] < 0) fu[f_cou++] = a[z];
      }
      sort(fu, fu + f_cou);
      if (sousa > k) continue;
      rep(z, f_cou) {
        if (sousa == k) break;
        sousa++;
        cnt += fu[z] * -1;
      }
      ans = max(ans, cnt);
    }
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 256
import bisect
import heapq
from collections import Counter

N = int(input())
S = []
for n in range(N):
    string = ''.join(sorted(input()))
    S.append(string)
ans = 0
counter_s = Counter(S)
for key, value in counter_s.items():
    if value >= 2:
        ans += value * (value - 1) // 2
print(ans)

Measured memory_bytes: 19764
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n=in.nextInt();
            int w=in.nextInt();
            int[][] input=new int[n][2];
            for(int i=0;i<n;i++){
                input[i][0]=in.nextInt();
                input[i][1]=in.nextInt();
            }
            long[][] dp=new long[n+1][w+1];
            for(int i=1;i<n+1;i++){
                for(int j=1;j<w+1;j++){
                    if(j>=input[i-1][0]){
                        dp[i][j]=Math.max(dp[i-1][j-input[i-1][0]]+input[i-1][1], dp[i-1][j]);
                    }
                    else{
                        dp[i][j]=dp[i-1][j];
                    }
                }
            }
            out.println(dp[n][w]);
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

Measured memory_bytes: 126548
f=[0]*22209
def main():
    a=list(map(int,input()))
    n=len(a)
    ans=0
    d=[0]*2019
    d2=[0]*2019
    d2[a[0]]+=1
    for i in range(11):
        for j in range(2019):
            f[2019*i+j]=j
    for i in range(1,n):
        d[a[i]]+=1
        for j in range(2019):
            d[f[10*j+a[i]]]+=d2[j]
        ans+=d[0]
        for j in range(2019):
            d2[j]=d[j]
            d[j]=0
    print(ans)
main()

Measured memory_bytes: 75928
p=[]
a=[0]*2+[1]*10001
for i in range(2,int(10000**0.5)+1):
    if a[i]:
        for j in range(i*i,10001,i):
            a[j]=0
for i in range(2,10001):
    if a[i]:p+=[i]
b=[0]*5736397
for i in range(len(p)):
    c=0
    for j in range(i,len(p)):
        c+=p[j]
        b[c]+=1
while 1:
    n=int(input())
    if n==0:break
    print(b[n])

Measured memory_bytes: 52400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,s,n) for(int i = s; i < (int)(n); i++)

int main() {
  int h,w;
  cin >> h >> w;
  vector<string>data(h);
  rep(i,0,h) cin >> data[i];
  rep(i,0,w+2) cout << "#";
  cout << "" << endl;
  rep(i,0,h) cout << "#" << data[i] << "#" << endl;
  rep(i,0,w+2) cout << "#";
  cout << "" << endl;
}

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

int main(){
  long long N, M;
  cin >> N >> M;
  vector<int> A(M);
  long long sum = 0;
  for(int i = 0; i < M; i++){
    cin >> A.at(i);
    sum += A.at(i);
  }
  if(N >= sum) cout << N - sum << endl;
  else cout << -1 << endl;
  
}

Measured memory_bytes: 3620
#尺取り法的な……
#

def main():
    n,k = map(int,input().split())
    scores = [0] + list(map(int,input().split()))
    for i in range(k+1,n+1):
        if scores[i] > scores[i-k]:
            print("Yes")
        else:
            print("No")

if __name__ == '__main__':
    main()


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

using namespace std;

long long qsum[100010];

long long best[100010];

int main()  {
    int n,k;
    long long a;
    cin >> n >> k;
    for ( int c=1 ; c<=n ; c++ )
    {
        cin >> a;
        qsum[c] = qsum[c-1] + a;
        if ( a > 0 )    best[c] = best[c-1] + a;
        else    best[c] = best[c-1];
    }
    long long ans = 0;
    for ( int i=1 ; i<=n-k+1 ; i++)
    {
        long long other = best[i-1] + best[n] - best[i+k-1];
        //cout << other << endl;
        if ( qsum[i+k-1] - qsum[i-1] > 0 )  other += qsum[i+k-1] - qsum[i-1];
        ans = max ( ans , other);
    }
    cout << ans;
}


Measured memory_bytes: 1792
data = input().rstrip().split(" ")
X = int(data[0])
N = int(data[1])
if N != 0:
    num = input().rstrip().split(" ")
    number = []
    for i in num:
        number.append(int(i))

    k = 0
    while True:
        if not X-k in number:
            ans = X-k
            break
        else:
            if not X+k in number:
                ans = X+k
                break
        k +=1
else:
    ans = X        
print(ans)

Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

#define ll long long

const ll llf = (signed ll) (~0ull >> 2);

const int N = 505;

int n;
int A[N][N];
ll s[N][N];
ll dp[N][N];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if (i == j) {
				continue;
			}
			scanf("%d", A[i] + j);
			s[i][j] = A[i][j] + s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1];
		}
	}
	for (int i = 1; i <= n; i++)
		for (int j = 1; j <= n; j++)
			dp[i][j] = llf;
	dp[1][1] = 0;
	for (int i = 2; i <= n; i++) {
		dp[1][i] = dp[1][i - 1];
		for (int j = 1; j < i; j++) {
			dp[1][i] += A[j][i];
		}
	}
	for (int i = 2; i <= n; i++) {
		ll cost = 0;
		for (int b = i - 1; b; b--) {
			for (int j = b + 2; j <= i; j++)
				cost += A[b + 1][j];
			for (int a = b; a; a--) {
				dp[b + 1][i] = min(dp[b + 1][i], dp[a][b] + cost + s[i][a - 1] - s[b][a - 1]);
			}
		}
	}
	ll ans = llf;
	for (int i = 1; i <= n; i++)
		ans = min(ans, dp[i][n]);
	printf("%lld\n", ans);	
	return 0;
}


Measured memory_bytes: 5248
A, B, C = map(int, input().split())
K = int(input())

for i in range((K + 1)):
    for j in range((K + 1) - i):
        for k in range((K + 1) - i - j):
            if A * (2 ** i) < B * (2 ** j) < C * (2 ** k):
                print("Yes")
                exit()

print("No")


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

namespace competitive_programming
{
    class Program
    {
        static void Main(string[] args)
        {
            var main = new Program();
            main.solve();
        }

        void solve()
        {
            var N = int.Parse(Console.ReadLine());
            var S = Console.ReadLine();
            long rs = S.Count(c => c == 'R');
            long gs = S.Count(c => c == 'G');
            long bs = S.Count(c => c == 'B');
            long count = rs * gs * bs;

            for (int i = 0;i < N; i++)
            {
                for(int j = 1;j < N; j++)
                {
                    if (i - j < 0 || i + j >= N || i - j >=N || i + j < 0) continue;
                    if (S[i - j] != S[i] && S[i] != S[i + j] && S[i - j] != S[i + j]) count--;
                }
            }
            if (count < 0) count = 0;

            Console.WriteLine(count);
        }

        public static long Gcd(long a, long b)
        {
            Func<long, long, long> gcd = null;
            gcd = (x, y) => y == 0 ? x : gcd(y, x % y);
            return a > b ? gcd(a, b) : gcd(b, a);
        }
    }

    struct Vector2
    {
        public Vector2(long x, long y)
        {
            this.x = x;
            this.y = y;
        }
        public long x;
        public long y;
    }

    struct Vector3
    {
        public int x;
        public int y;
        public int z;
    }
}


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

string m[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};

int main() {
	string s;
	cin >> s;
	int ans;
	for(int i=0;i<7;i++) {
		if(s==m[i]) ans = i;
	}
	cout << 7-ans << endl;
}

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

#define IL __inline__ __attribute__((always_inline))

#define For(i, a, b) for (int i = a, i##end = b; i <= i##end; ++ i)
#define FOR(i, a, b) for (int i = a, i##end = b; i < i##end; ++ i)
#define Rep(i, a, b) for (int i = a, i##end = b; i >= i##end; -- i)
#define REP(i, a, b) for (int i = (a) - 1, i##end = b; i >= i##end; -- i)

typedef long long LL;

template <class T>
IL bool chkmax(T &a, const T &b) {
  return a < b ? ((a = b), 1) : 0;
}

template <class T>
IL bool chkmin(T &a, const T &b) {
  return a > b ? ((a = b), 1) : 0;
}

template <class T>
IL T mymax(const T &a, const T &b) {
  return a > b ? a : b;
}

template <class T>
IL T mymin(const T &a, const T &b) {
  return a < b ? a : b;
}

template <class T>
IL T myabs(const T &a) {
  return a > 0 ? a : -a;
}

const int INF = 0X3F3F3F3F;
const double EPS = 1E-10, PI = acos(-1.0);

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define OK DEBUG("Passing [%s] in LINE %d...\n", __FUNCTION__, __LINE__)
/*------------------------------header------------------------------*/

const int MAXN = 200000 + 5, MAXM = 2000 + 5, MOD = 1000000007, INV_2 = 500000004;

IL int add(int a, int b) {
  a += b;
  return a >= MOD ? a - MOD : a;
}

IL int sub(int a, int b) {
  a -= b;
  return a < 0 ? a + MOD : a;
}

IL int mul(int a, int b) {
  return 1LL * a * b % MOD;
}

IL int pow_mod(int a, int p) {
  int result = 1;
  for (int base = a; p; p >>= 1, base = mul(base, base)) {
    if (p & 1) {
      result = mul(result, base);
    }
  }
  return result;
}

int a[MAXN], b[MAXN], f[MAXM * 2][MAXM * 2], fac[MAXN * 4], ifac[MAXN * 4];

IL void Init(int n) {
  fac[0] = 1;
  For(i, 1, n) {
    fac[i] = mul(fac[i - 1], i);
  }
  ifac[n] = pow_mod(fac[n], MOD - 2);
  REP(i, n, 0) {
    ifac[i] = mul(ifac[i + 1], i + 1);
  }
}

IL int C(int n, int m) {
  return mul(fac[n], mul(ifac[m], ifac[n - m]));
}

int main() {
  int n;
  scanf("%d", &n);
  int max_a = 0, max_b = 0;
  For(i, 1, n) {
    scanf("%d%d", &a[i], &b[i]);
    ++ f[MAXM - a[i]][MAXM - b[i]];
    chkmax(max_a, a[i]);
    chkmax(max_b, b[i]);
  }
  For(i, MAXM - max_a, MAXM + max_a) {
    For(j, MAXM - max_b, MAXM + max_b) {
      f[i][j] = add(f[i][j], add(f[i][j - 1], f[i - 1][j]));
    }
  }
  Init(max_a * 2 + max_b * 2);
  int ans = 0;
  For(i, 1, n) {
    ans = add(ans, f[MAXM + a[i]][MAXM + b[i]]);
    ans = sub(ans, C((a[i] + b[i]) << 1, a[i] << 1));
  }
  printf("%d\n", mul(ans, INV_2));
  return 0;
}


Measured memory_bytes: 66816
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-9;
const double PI = acos(-1);
const int MOD = 998244353;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 500005;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
int arr[MAXN];
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#else
#endif
    scanf("%d", &n);
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                sum += __gcd(__gcd(i, j), k);
            }
        }
    }
    printf("%lld", sum);
    return 0;
}

Measured memory_bytes: 3820
#include<iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node{int p, l, r;};

Node T[MAX];
int n, D[MAX];

void print(int u){
  int i, c;
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].p << ", ";
  cout << "depth = " << D[u] << ", ";

  if(T[u].p == NIL) cout << "root, ";
  else if(T[u].l == NIL) cout << "leaf, ";
  else cout << "internal node, ";

  cout << "[";

  for(i = 0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) cout << ", ";
    cout << c;
  }
  cout << "]" << endl;
}

// ?????°????????±???????±???????
int rec(int u, int p){
  D[u] = p;
  if(T[u].r != NIL)
    rec(T[u].r, p);
  if(T[u].l != NIL)
    rec(T[u].l, p + 1);
  return 0;
}

int main(){
  int i, j, d, v, c, l, r;
  cin >> n;
  for(i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;

  for(i = 0; i < n; i++){
    cin >> v >> d;
    for(j = 0; j < d; j++){
      cin >> c;
      if(j == 0) T[v].l = c;
      else T[l].r = c;
      l = c;
      T[c].p = v;
    }
  }
  for(i = 0; i < n; i++){
    if(T[i].p == NIL) r = i;
  }

  rec(r, 0);

  for(i = 0; i < n; i++) print(i);

  return 0;
}

Measured memory_bytes: 5840
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
template <typename T, typename U>ostream &operator<<(ostream &out, const pair<T, U> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>void print(const ContainerType<ValueType, Args...> &c){for (const auto &v : c)cout << v << ' ';cout << '\n';} void print(){cout<<'\n';}
template <typename T, typename... Args>void print(T a, Args... args){cout << a << " ";print(args...);}
lli llipower(lli x, lli y, lli p = LLONG_MAX){lli res = 1;x = x % p;while (y > 0){if (y & 1)res = (res * x) % p;y = y >> 1;x = (x * x) % p;}return res;}

//8====================================D

int main(){
   int n,k;
   cin>>n>>k;
   int nk=k;
    vector<lli> a(n);
    fori(n) cin>>a[i];
    sort(a.begin(),a.end());
   lli ans=1;

   int i=0;
   int j=n-1;
   
   while(1){
     //  print(ans);
       if(k==0) break;
       if(k%2==1){
           ans*=a[j];
           ans %= mod;

           ans = (mod + ans) % mod;
           j--;
           k--;
       }
       else{
           if(a[i]*a[i+1]>a[j]*a[j-1]){
               ans*=a[i];
               ans %= mod;

               ans = (mod + ans) % mod;
               ans*=a[i+1];
               ans %= mod;

               ans = (mod + ans) % mod;
               i+=2;
               k-=2;
           }
           else{
               ans *= a[j];
               ans %= mod;

               ans = (mod + ans) % mod;
               ans *= a[j - 1];
               ans %= mod;

               ans = (mod + ans) % mod;
               j-= 2;
               k -= 2;
           }
       }
   }
   if(a[n-1]<0 && nk%2==1){
       ans=1;
       fori(nk){
           ans*=a[n-i-1];
           ans%=mod;
           
            ans = (mod + ans)%mod;
           
       }
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 4844
# coding:utf-8

import sys
import fractions

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


def gcd(x, y):
    if x % y == 0:
        return y
    else:
        x, y = y, x % y
        return gcd(x, y)


def main():
    n = II()
    A = LI()
    A.sort()
    A.reverse()

    pre = [0] * n
    pre[0] = A[0]
    for i in range(1, n):
        pre[i] = gcd(pre[i - 1], A[i])
    res = pre[-1]
    for i in range(n):
        t = pre[i]
        for j in range(i + 2, n):
            t = gcd(t, A[j])
            if t == pre[j - 1]:
                t = -1
                break
        res = max(res, t)

    t = A[1]
    for a in A[1:]:
        t = gcd(t, a)

    return max(res, t)


print(main())


Measured memory_bytes: 85228
use std::io::{stdin, Read};
use std::str::FromStr;

// https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[allow(dead_code)]
fn main() {
    let d = read::<usize>();
    let g = read::<usize>();
    let pc = (0..d)
        .map(|_| (read::<usize>(), read::<usize>()))
        .collect::<Vec<_>>();
    let mut candidate = usize::max_value();

    for i in 0..2_usize.pow(d as u32) {
        let mut pc = pc.clone();
        let mut ans = 0;
        let mut total = 0;
        for s in 0..d {
            if i & (1 << s) > 0 {
                let (p, c) = pc[s];
                pc[s] = (0, 0);
                total += p * (s + 1) * 100 + c;
                ans += p
            }
        }

        for j in (0..d).rev() {
            let (p, _) = pc[j];
            if total < g && p > 0 {
                let need = g - total;
                let fill = if need % ((j + 1) * 100) == 0 {
                    need / ((j + 1) * 100)
                } else {
                    need / ((j + 1) * 100) + 1
                };
                let fill2 = std::cmp::min(p, fill);
                total += fill2 * (j + 1) * 100;
                ans += fill2
            }
        }
        if total >= g {
            candidate = std::cmp::min(candidate, ans)
        }
    }
    println!("{}", candidate)
}


Measured memory_bytes: 4352
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
#include <stdio.h>

using namespace std;

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n, 0);

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

    int cnt = 0;
    for (int i = 0; i < n - 1; ++i) {
        int mini = i;
        for(int j = i + 1; j < n; ++j) {
            if(a[j] < a[mini]) {
                mini = j;
            }
        }
        swap(a[mini], a[i]);
        if (mini != i)
            ++cnt;
    }
    ostringstream os;
    for_each(a.begin(), a.end() - 1,
             [&os](const int& e){
                 os << e << " ";
             });
    os << *(a.end() - 1);
    cout << os.str() << endl;
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 3260
N = int(input())

A = 1
res = 0
count = 0


while(1):
  for a in range(A):
    if A % (a+1) == 0:
      count+=1
      
  if count == 8:
    res+=1
  count = 0
  A+=2
  if A > N:
    break

print(res)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <ctime>
#include <set>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const ll INF = 1ll<<50;
const int IINF = 1000000009;
const int maxP = 1000010;
const int maxN = 10005;
const int maxM = 200010;
int n;

int a[maxN];
int sum(int x)
{
	int ans = 0;
	while(x)
	{
		if(x%2 == 0)
		{
			ans ++;
		}
		else
		{
			break;
		}
		x = x/2;
	}
	return ans;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]); 
	}
	ll ans = 0;
	for(int i=1;i<=n;i++)
	{
		if(a[i]%2 == 0)
		{
			ans += (ll)(sum(a[i]));
		}
	}
	printf("%lld\n",ans);
	return 0;
} 

Measured memory_bytes: 256