akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;

vector<ll> A;
vector<ll> dp;

ll solve(int l, int N){
    if(N-l==3){
        return max({A[N-3], A[N-2], A[N-1]});
    }
    ll ans1 = A[l] + solve(l+2,N);
    ll ans2 = A[l+1] + max(dp[l+3],dp[l+4]);
    ll ans3 = dp[l+2];
    return max({ans1,ans2,ans3});
}

int main() {
    int N; cin >> N;
    A.resize(N,0);
    REP(i,N) cin >> A[i];

    dp.resize(N,-LINF);

    dp[N-1] = A[N-1];
    dp[N-2] = A[N-2];
    for(int i=N-1; i>=2; i--){
        if((N-1-i)%2 ==0){
            if(i>=3) dp[i-3] = max(dp[i-3], dp[i]+A[i-3]);
        }
        dp[i-2] = max(dp[i-2], dp[i]+A[i-2]);
    }
    //REP(i,N) cout << dp[i] << endl;
   

    if(N%2==0){
        cout << max(dp[0],dp[1]) << endl;
    }else{
        cout <<  solve(0, N) << endl;
    }

    return 0;
}

Measured memory_bytes: 9564
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    double A, B, P, Q, R;
    cin >> A >> B >> P >> Q >> R;

    double ans = (P * B + Q * A + R * B) / (Q + R);

    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}
 
 



Measured memory_bytes: 3280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n, m;
  cin >> n >> m;
  vi k(m);
  vii s(m, vi(n,-1));
  vi p(m);
  rep(i,m){
    cin >> k[i];
    rep(j, k[i]){
      cin >> s[i][j];
    }
  }
  rep(i,m){
    cin >> p[i];
  }
  ll ans = 0;
  for (ll tmp = 0; tmp < (1 << n); tmp++){
    bitset<10> b(tmp);
    bool tof = true;
    rep(i,m){
      ll count = 0;
      rep(j,k[i]){
        if(b[s[i][j]-1]){
          count++;
        }
      }
      if(count%2!=p[i]){
      tof = false;
      }
    }
    if(tof){
      ans++;
    }
  }
  print(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
   char c;
   cin >> c;
   cout<<(char)(c+1)<<endl;
   return 0;
}

Measured memory_bytes: 256
package main

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

func abs(n int) int {
	if n < 0 {
		return -n
	} else {
		return n
	}
}

func pow(a int, b int) int {
	ans := 1
	for i:=0; i < b; i++ {
		ans *= a
	}
	return ans
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	
	X, _ := strconv.Atoi(sc.Text())

	max := 1
	for b := 1; b < X; b++ {
		for p := 2; p < X ; p++ {
			exp := pow(b, p)
			if exp > X {
				break
			}

			if max < exp {
				max = exp
			}


		}
	}

	fmt.Println(max)

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);
	map <long long int, int> M;
	long long int curr = 0, ans = 0;
	M[0] = 1;
	for (int i = 0; i < n; ++i)
	{
		int x;
		scanf("%d", &x);
		curr+=x;
		ans+=M[curr];
		M[curr]++;
	}
	printf("%lld\n", ans);
	return 0;
}

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

int main()
{
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  long long int INF = 1000000007;
  long long int acnt = 0;
  for (int i = 0; i < N - 1; i++)
  {
    for (int j = i + 1; j < N; j++)
    {
      if (A[i] > A[j])
        acnt++;
    }
  }
  sort(A.begin(), A.end(), greater<int>());
  vector<int> B(N);
  long long int acnt3 = 0;
  for (int i = 0; i < N - 1; i++)
  {
    for (int j = 0; j < N; j++)
    {
      if (A[i] > A[j])
        B[i]++;
    }
  }
  for (int i = 0; i < N; i++)
  {
    acnt3 += (B[i] * (((K % INF) * ((K - 1) % INF) / 2) % INF))%INF;
  }
  long long int ans = (acnt * K) % INF + acnt3;
  ans %= INF;
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	int N, M;
	cin >> N >> M;
	vector<ll> a(N), b(N), c(M), d(M);
	rep(i, N) {
		cin >> a[i] >> b[i];
	}
	rep(i, M) {
		cin >> c[i] >> d[i];
	}

	ll mn;
	int cp;
	rep(i, N) {
		mn = INF;
		rep(j, M) {
			if (mn > abs(a[i] - c[j]) + abs(b[i] - d[j])) {
				mn = abs(a[i] - c[j]) + abs(b[i] - d[j]);
				cp = j;
			}
		}
		cout << cp + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
ll n,q,t[100001],u[100001],a[100000],x;
int main(void){
  cin>>n>>q;
  for(int i=0;i<n;i++){
    cin>>a[i];
    t[i+1]=t[i]+a[i];
    u[i+1]=(i?u[i-1]:0)+a[i];
  }
  while(q--){
    cin>>x;
    ll ub=0,lb=n+1,m;
    while(ub+1<lb){
      m=(lb+ub)/2;
      if(abs(a[n-m]-x)>abs(a[n-(m+1)/2]-x))lb=m;
      else ub=m;
    }
cout<<t[n]-t[n-(ub+1)/2]+u[max(n-ub-(ub&1),0LL)]<<endl;
  }
}


Measured memory_bytes: 4096
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

const LL MOD = 1e9 + 7;
long long dp[210000][5];

void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}

int main() {
    string s; cin >> s;

    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;

    rep(i, s.size()) {
        rep(j, 5) {
            if (s[i] != '?') add(dp[i + 1][j], dp[i][j]);
            else add(dp[i + 1][j], dp[i][j] * 3 % MOD);
        }

        if (s[i] == 'A' || s[i] == '?') add(dp[i+1][1], dp[i][0]);
        if (s[i] == 'B' || s[i] == '?') add(dp[i+1][2], dp[i][1]);
        if (s[i] == 'C' || s[i] == '?') add(dp[i+1][3], dp[i][2]);
    }
    cout << dp[s.size()][3] << endl;
}


Measured memory_bytes: 9080
require 'pp'
IS_DEBUG = true
# IS_DEBUG = false
def dputs str
	if(IS_DEBUG)
		puts str
	end
end
def dpp str
	if(IS_DEBUG)
		pp str
	end
end

require 'pp'

INT_MAX = 999999999999999999999999

N,M=gets.chomp.split(' ').map{|n| n.to_i}
X=gets.chomp.split(' ').map{|n| n.to_i}.sort
Y=gets.chomp.split(' ').map{|n| n.to_i}.sort
mod = 10**9 + 7
xsum = 0
ysum = 0
X.each_with_index{|x,i| i=i+1; xsum += -(N-i)*x + (i-1)*x}
Y.each_with_index{|y,i| i=i+1; ysum += -(M-i)*y + (i-1)*y}
puts xsum * ysum % mod



Measured memory_bytes: 21204
#pragma region Macros

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

using ll = long long;
#define int ll
using vi = vector<int>;
using vvi = vector<vi>;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

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

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << endl
#define debug_4(x1, x2, x3, x4) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5) cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

#pragma endregion

void Main() {
    int N, Y;
    cin >> N >> Y;

    REP(i, N + 1) {
        for (int j = 0; j < N + 1 - i; j++) {
            debug(i, j, N - i - j);
            if (Y - (10000 * i + 5000 * j) == 1000 * (N - i - j)) {
                cout << i << " " << j << " " << (N - i - j);
                return;
            }
        }
    }

    cout << "-1 -1 -1";
}

#pragma region main
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    cout << flush;
}
#pragma endregion


Measured memory_bytes: 3652
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
  int n;
  cin>>n;
  int d[50];
  rep(i,0,n) cin>>d[i];

  int ans=0;
  rep(i,0,n-1)
  rep(j,i+1,n) ans+=d[i]*d[j];

  cout<<ans<<endl;
}

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

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(lol i=0;i<lol(n);i++)
#define REPD(i,n) for(lol i=n-1;i>=0;i--)
#define FOR(i,a,b) for(lol i=a;i<=lol(b);i++)
#define FORD(i,a,b) for(lol i=a;i>=lol(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) x.begin(),x.end() //sortなどの引数を省略したい
#define SIZE(x) lol(x.size()) //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//最大値最小値
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main()
{
    lol result{0};
    lol n; cin >> n;
    //int k; cin >> k;
    /*
    vector<int> a(n);
    REP(i, n)
    {
        cin >> a[i];
    }
    */
    result = (n-2)*180;

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstring>

using namespace std;

int main() {
	int n, x, t;
	cin >> n >> x >> t;
	if(n % x) {
		int cnt = n / x + 1;
		printf("%d\n", cnt * t);
	}
	else {
		printf("%d\n", n / x * t);
	}
	return 0;
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long

static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const ll INF = 1e18;


int main() {

    int H, W;
    cin >> H >> W;
    int h=H, w=W;
    int Hcount = 0;
    int Vcount = 0;
    vector<vector<char>> a(H+10, vector<char>(W+10, '0'));
    REP(i, H)REP(j, W)cin >> a[i][j];
    vector<int> trueH(H+10, 0), trueW(W+10, 0);

	vector<bool> row(h, false);
	vector<bool> col(w, false);
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				row[i] = true;
				col[j] = true;
			}
		}
	}
 
	for (int i = 0; i < h; i++) {
		if (row[i]) {
			for (int j = 0; j < w; j++) {
				if (col[j]) {
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}

    
}

/*
みんな、くるくるぱーにな〜れ
　∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(long long int i=a; i<n; i++)
#define loop(i,a,n)	for(long long int i=a; i>=n; i--)

int main() 
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	long long int a,b;
	cin>>a>>b;
	cout<<a*b;	
	
	
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

typedef long long ll;
ll n, k, s, x, c, a[N];
bool v;
int main()
{
	ll i, j;
	cin >> n >> k;
	for (i = 0; i < n; i++) scanf("%lld", &a[i]);
	for (i = 40; i >= 0; i--) {
		x <<= 1;
		if (!((k >> i) & 1) && !v) continue;
		c = 0;
		for (j = 0; j < n; j++) c += (a[j] >> i) & 1;
		if (c < (n + 1) / 2) x++;
		else v = 1;
	}
	for (i = 0; i < n; i++) s += a[i] ^ x;
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 1024
def is_balanced(txt):
    round_brackets = []
    square_brackets = []

    for c in txt:
        try:
            if c == '(':
                round_brackets.append(len(square_brackets))
            elif c == ')':
                level = round_brackets.pop()
                if level != len(square_brackets):
                    return False
            elif c == '[':
                square_brackets.append(len(round_brackets))
            elif c == ']':
                level = square_brackets.pop()
                if level != len(round_brackets):
                    return False
        except IndexError:
            return False
    if len(round_brackets) == 0 and len(square_brackets)==0:
        return True
    else:
        return False


if __name__ == '__main__':
    # ??????????????\???
    # txt = 'So when I die (the [first] I will see in (heaven) is a score list).'
    while True:
        txt = input()
        if txt == '.':
            break

        # ??¬??§?????????????§£???
        ans = is_balanced(txt)

        # ???????????¨???
        if ans:
            print('yes')
        else:
            print('no')

Measured memory_bytes: 7452
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		char[] c = "qwertasdfgzxcvb".toCharArray();
		int[] hand = new int['Z' - 'A' + 1];
		for(char v: c) {
			hand[v - 'a'] = 1;
		}

		while (true) {
			char[] str = sc.next().toCharArray();
			if (str[0] == '#') {
				break;
			}
			int ans = 0;
			int pre = hand[str[0] - 'a'];
			for (int i = 1; i < str.length; i++) {
				if (hand[str[i] - 'a'] != pre) {
					ans++;
				}
				pre = hand[str[i] - 'a'];
			}

			System.out.println(ans);
		}
	}

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

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
	ll x,y;
	cin>>x>>y;
	ll ans=INF;
	if(x<=y) chmin(ans,y-x);
	else chmin(ans,x-y+2);
	if(x*y<=0){
		chmin(ans,abs(abs(y)-abs(x))+1);
	}
	cout<<ans<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}

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

int main(){
    int n,c,k,t[100010],ans = 1;
    cin>>n>>c>>k;
    for(int i = 0; i < n; ++ i) cin >> t[i];
    sort(t, t + n);

    int b = t[0], g = 1;
    for(int i = 1; i < n; ++ i){
        if(t[i] > b + k){
            b = t[i];
            ans++;
            g = 1;
        }else{
            g++;
        }
        if(g > c){
            b = t[i];
            ans++;
            g = 1;
        }
    }
    cout << ans << endl;

    return 0;
}


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

int main()
{
	int64_t n;
	cin >> n;
	vector<int64_t> as(n - 1), bs(n - 1), cs(n);
	for (int64_t i = 0; i < n - 1; i++)
	{
		cin >> as[i] >> bs[i];
		as[i]--;
		bs[i]--;
	}
	for (auto &c : cs)
	{
		cin >> c;
	}

	cout << accumulate(cs.begin(), cs.end(), int64_t(0)) - *max_element(cs.begin(), cs.end()) << endl;

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

	vector<vector<int64_t>> g(n);
	for (int64_t i = 0; i < n - 1; i++)
	{
		g[as[i]].emplace_back(bs[i]);
		g[bs[i]].emplace_back(as[i]);
	}

	vector<int64_t> ans(n);

	stack<pair<int64_t, int64_t>> st;
	st.push({0, -1});

	while (!st.empty())
	{
		int64_t now = st.top().first;
		int64_t par = st.top().second;
		st.pop();

		ans[now] = *cs.rbegin();
		cs.pop_back();

		for (auto &next : g[now])
		{
			if (next == par)
			{
				continue;
			}
			st.push({next, now});
		}
	}

	for (auto &x : ans)
	{
		cout << x << ' ';
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 1408
#include <algorithm>
#include <chrono>
#include <iostream>
#include <vector>

using namespace std;
using namespace std::chrono;

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i)
    cin >> a[i];
  sort(a.begin(), a.end());

  int ans = 0;
  while (a.size() > 0 && a.back() >= k)
    a.pop_back();
  n = a.size();

  if (n == 0) {
    cout << ans << endl;
    return 0;
  }

  vector<vector<bool>> le(n, vector<bool>(k, false));
  for (int i = 0; i < n; ++i) {
    if (i > 0)
      le[i] = le[i - 1];
    else
      le[i][0] = true;

    int val = a[i];
    for (int pos = k - 1; pos >= 0; --pos)
      if (le[i][pos] && pos + val < k)
        le[i][pos + val] = true;
  }

  vector<vector<int>> pref(n, vector<int>(k, 0));
  vector<vector<bool>> ge(n, vector<bool>(k, false));
  for (int i = n - 1; i >= 0; --i) {
    if (i < n - 1)
      ge[i] = ge[i + 1];
    else
      ge[i][0] = true;

    int val = a[i];
    for (int pos = k - 1; pos >= 0; --pos)
      if (ge[i][pos] && pos + val < k)
        ge[i][pos + val] = true;

    pref[i][0] = ge[i][0];
    for (int pos = 1; pos < k; ++pos)
      pref[i][pos] = pref[i][pos - 1] + (ge[i][pos] ? 1 : 0);
  }

  for (int i = 0; i < n; ++i) {
    int val = a[i];
    bool exist = false;

    for (int j = 0; j < k; ++j) {
      if (i > 0 && !le[i - 1][j])
        continue;

      int val_in_le = i == 0 ? 0 : j;

      //cout << "CURRENT ELEM : " << val << " + " << val_in_le << " ";

      int tmp = val + val_in_le;
      if (tmp >= k) {
        //cout << endl;
        exist = true;
        break;
      }

      int l = k - tmp;
      int r = k - j - 1;

      int sum = 0;
      if (l <= r && i + 1 < n) {
        sum += pref[i + 1][r];
        sum -= pref[i + 1][l - 1];
      }

      //cout << " IN MORE NEED SUM IN RANGE " << l << " " << r << " cnt = " << sum << endl;

      if (sum) {
        exist = true;
        break;
      }
    }

    ans += !exist;
  }

  cout << ans << endl;

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


Measured memory_bytes: 104832
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] array = { 1, 2, 4, 8, 16, 32, 64, 101 };
		for (int i = 0; i < array.length; i++) {
			if (array[i] > N) {
				System.out.println(array[i - 1]);
				break;
			}
		}
	}
}


Measured memory_bytes: 35748
class Cmb:
  g1=[1,1]
  g2=[1,1]
  inv=[0,1]
  def __init__(self,mod,upper_limit):
    self.mod=mod
    for i in range(2,upper_limit+1):
      Cmb.g1.append(Cmb.g1[-1]*i%mod)
      Cmb.inv.append(-Cmb.inv[mod%i]*(mod//i)%mod)
      Cmb.g2.append(Cmb.g2[-1]*Cmb.inv[-1]%mod)
  def cmb(self,n,r):
    if r<0 or n<r:
      return 0
    r=min(r,n-r)
    return Cmb.g1[n]*Cmb.g2[r]*Cmb.g2[n-r]%self.mod

k=int(input())
s=len(input())
mod=10**9+7
Cmb=Cmb(mod,k+s)
ans=1
for i in range(1,k+1):
  ans=(ans*26+Cmb.cmb(i+s-1,s-1)*pow(25,i,mod))%mod
print(ans)

Measured memory_bytes: 183640
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Senky_Bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
ll an[100005];
ll id[100005];
ll vis[100005];
ll final[100005];
ll f1[100005];
ll root(int a)
{
    if(a==id[a])
    return a;
    return id[a]=root(id[a]);
}
void union1(int a,int b)
{
    ll a1=root(a);
    ll b1=root(b);
    id[a1]=id[b1];
}
signed main()
{   
    Senky_Bansal
    IIIT_ALLAHABAD
     
    for(int i=1;i<100005;i++)
    id[i]=i;
    ll n,m;
    cin>>n>>m;
    map<ll,ll>mp,mp1;
    ll ans=0;
    ll a[m],b[m],c[m];
    for(int i=0;i<m;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
        mp[a[i]]++;
        mp[b[i]]++;
        union1(a[i],b[i]);
    }
    for(int i=0;i<m;i++)
    {
        mp1[root(a[i])]++;
        mp1[root(b[i])]++;
    }
    cout<<mp1.size()+n-mp.size()<<endl;
}
    
    
    







Measured memory_bytes: 10880
#include<bits/stdc++.h>
#define inf 1000000000
#define mod 1000000007
#define pb push_back
#define sz(v) (v).size()
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define fi first
#define se second
using namespace std;
template <class T> void chmax(T &x,T y){x=x>y?x:y;return;}
template <class T> void chmin(T &x,T y){x=x<y?x:y;return;}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;

int x;

int main()
{
	cin>>x;
	ll t1=x/500;
	x%=500;
	ll t2=x/5;
	cout<<t1*1000+t2*5<<endl;
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>
#include <string.h>
#include <cctype>
#include <set>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
	mint operator+(const mint a) const { return mint(*this) += a; }
	mint operator-(const mint a) const { return mint(*this) -= a; }
	mint operator*(const mint a) const { return mint(*this) *= a; }
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const { return pow(mod - 2); }
	mint& operator/=(const mint a) { return *this *= a.inv(); }
	mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool comp(int i, int j) {
	return i > j;
}

int nl;
int dat[200000];
int cc[100000];

int main()
{
	vector<int> ans;
	cin >> nl;
	for (int i = 0; i < nl; i++)
	{
		cin >> dat[i];
	}

	for (int i = nl; i > 0; i--)
	{
		int count = dat[i - 1];
		for (int j = i + i; j <= nl; j += i)
		{
			count += (dat[j - 1] % 2 != 0) ? 1 : 0;
		}

		if (count % 2 != 0)
		{
			dat[i - 1] = 1;
			ans.push_back(i);
		}
		else
		{
			dat[i - 1] = 0;
		}
	}

	cout << ans.size() << endl;
	if (ans.empty())
	{
		return 0;
	}
	for (int i = 0; i < ans.size() - 1; i++)
	{
		cout << ans[i] << " ";
	}
	cout << ans[ans.size() - 1] << endl;
}



Measured memory_bytes: 33656
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <numeric>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;

int main(){
	int n,K;cin >> n >> K;
	vector<int> num;
	rep(i,10) num.push_back(i);
	rep(i,K) {
		int a;cin >> a;
		rep(j,num.size()){
			if(num[j]==a) num.erase(num.begin()+j);
		}
	}
	//rep(i,num.size()) cout << num[i]<< endl;
	int ans = 100000;
	for(int a:num)for(int b:num)for(int c:num)for(int d:num)for(int e:num){
		int temp = 10000*a+1000*b+100*c+10*d+e;
		int temp2 = 1000*b+100*c+10*d+e;
		int temp3 = 100*c+10*d+e;
		int temp4 = 10*d+e;
		int temp5 = e;
		if(temp >= n) ans = min(ans,temp);
		if(temp2 >= n) ans = min(ans,temp2);
		if(temp3 >= n) ans = min(ans,temp3);
		if(temp4 >= n) ans = min(ans,temp4);
		if(temp5 >= n) ans = min(ans,temp5);
	}
	cout << ans << endl;


	
}
 
 

Measured memory_bytes: 3568
'use strict'
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],1);
  var list = myconv(input[1],4);
  var output = 0;
  for(var i = 0; i < N - 1; i++){
    var mae = list[i];
    var ato = list[i+1];
    if(mae == ato){
       output++;
      list[i+1] = -1;
       }
  }
  myout(output);
}
  
Main(myin());


Measured memory_bytes: 7372
//インクルード(アルファベット順)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素



signed main(){
  string S;
  cin>>S;
  cout<<S[0]<<S[1]<<S[2]<<endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

bool hantei(int mask, int pos){
	if(mask & (1 << pos))return true;
	else return false;
}
int board[11][10010];
int main(void){
	int r, c;
	while(1){
		cin >> r >> c;
		if(r == 0 && c == 0) return 0;
		rep(i, r) rep(j, c) cin >> board[i][j];
		long long ans = 0;
		for (int mask = 0; mask < (1 << r); ++mask){
			vector<int> sum(c, 0);//v[i] := i?????????0????????°
			for (int pos = 0; pos < r; ++pos){
				if(hantei(mask, pos)){//?????¢
					for (int i = 0; i < c; ++i){
						if(board[pos][i] == 1) sum[i]++;//0?????°?????????
					}
				}else{//????????????
					for (int i = 0; i < c; ++i){
						if(board[pos][i] == 0) sum[i]++;
					}
				}
			}
			long long tmp = 0;
			for (int i = 0; i < c; ++i){
				if(sum[i] < (double)r / 2.0) tmp += (r - sum[i]);
				else tmp += sum[i];
			}
			ans = max(ans, tmp);
		}
		printf("%lld\n", ans);
	}
}

Measured memory_bytes: 1604
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] ab = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();
            int z = 0;
            int a = ab[0];
            int b = ab[1];
            int d = b - a;
            int x = 0;
            for (int i = 1; i < d; i++)
                x += i;
            Console.WriteLine(x - a);
            //z = b - a;
            //z = z * (z + 1) / 2;
            //z = z - b;
            //Console.WriteLine(z);
        }
    }
}
//int[] N = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToArray();

Measured memory_bytes: 28312
def main(m, nx, nn):
    b = [int(input()) for i in range(m)]
    d = -1
    for i in range(nn, nx + 1):
        if d <= b[i - 1] - b[i]:
            d = b[i - 1] - b[i]
            ans = i
    print(ans)
while 1:
    m, nmin, nmax = map(int, input().split())
    if m == nmax == nmin == 0:
        break
    main(m,nmax, nmin)


Measured memory_bytes: 5620
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    n, y = map(int, input().split())
    for i in range(n + 1):
        for j in range(n + 1):
            if i + j > n: break
            price = 10000 * i + 5000 * j + 1000 * (n - i - j)
            if price > y: break
            if y == price:
                print(i, j, n - i - j)
                exit()
    print(-1, -1, -1)

main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int func(int a[],int ind,int n,int dp[])
{
    if(ind==n-1)
    return 0;
    if(dp[ind]!=-1)
    return dp[ind];
    int left=abs(a[ind]-a[ind+1])+func(a,ind+1,n,dp);
    int right=INT_MAX;
    if(ind+2<n)
    {
        right=abs(a[ind]-a[ind+2])+func(a,ind+2,n,dp);
    }
    return dp[ind]=min(left,right);
}
int main() {
	int n;
	cin>>n;
	int a[n];int dp[n];
	for(int i=0;i<n;i++)
	dp[i]=-1;
	for(int i=0;i<n;i++)
	cin>>a[i];
	cout<<func(a,0,n,dp);
	return 0;
}


Measured memory_bytes: 12100
using System;

public class Hello
{
    public static void Main()
    {
        var n = long.Parse(Console.ReadLine().Trim());
        if (n == 1) { Console.WriteLine(1); goto end; }
        var w = getNum(n);
        var te = w * (w + 1) / 2;
        if (te == n) write(w, 0);
        else
        {
            var ng = (w + 1) * (w + 2) / 2 - n;
            write(w + 1, ng);
        }
        end:;
    }
    public static void write(long n, long ng)
    {
        for (int i = 1; i <= n; i++)
            if (i != ng) Console.WriteLine(i);
    }
    public static long getNum(long n)
    {
        var ok = 1L; var ng = n;
        while (ng - ok > 1)
        {
            var mid = (ng + ok) / 2;
            if (check(mid, n)) ok = mid;
            else ng = mid;
        }
        return ok;
    }
    public static bool check(long n, long t)
    {
        var w = n * (n + 1) / 2L;
        return w <= t;
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
const int N=505;
ll n,s[N],t[N],u[N],v[N],a[N][N];
bool work(){
	for(int i=0;i<64;i++){
		for(int j=1;j<=n;j++)
			if(s[j]==0 and (u[j]&(1ull<<i)))
				for(int k=1;k<=n;k++)
					a[j][k]|=(1ull<<i);
		for(int j=1;j<=n;j++)
			if(t[j]==0 and (v[j]&(1ull<<i)))
				for(int k=1;k<=n;k++)
					a[k][j]|=(1ull<<i);
		for(int j=1;j<=n;j++){
			if(!(s[j]==1 and (u[j]&(1ull<<i))))
				continue;
			int w=0;
			for(int k=1;k<=n;k++)
				if((a[j][k]&(1ull<<i)) or (v[k]&(1ull<<i))){
					w=k;
					break;
				}
			if(w){
				a[j][w]|=(1ull<<i);
				continue;
			}
			for(int k=1;k<=n;k++){
				if(t[k]==1)continue;
				int num=0;
				for(int l=1;l<=n;l++)
					if(a[l][k]&(1ull<<i))
						num++;
				if(num<n-1){
					w=k;
					break;
				}
			}
			if(!w)return false;
			a[j][w]|=(1ull<<i);
		}
		for(int j=1;j<=n;j++){
			if(t[j]==1 and (v[j]&(1ull<<i))){
				int w=0;
				for(int k=1;k<=n;k++)
					if((a[k][j]&(1ull<<i)) or (u[k]&(1ull<<i))){
						w=k;
						break;
					}
				if(w){
					a[w][j]|=(1ull<<i);
					continue;
				}
				for(int k=1;k<=n;k++){
					if(s[k]==1)continue;
					int num=0;
					for(int l=1;l<=n;l++)
						if(a[k][l]&(1ull<<i))
							num++;
					if(num<n-1){
						w=k;
						break;
					}
				}
				if(!w)return false;
				a[w][j]|=(1ull<<i);
			}
		}
		for(int j=1;j<=n;j++){
			ll w=(1ull<<i);
			if(s[j]==0)
				for(int k=1;k<=n;k++)
					w&=a[j][k];
			else{
				w=0;
				for(int k=1;k<=n;k++)
					w|=a[j][k]&(1ull<<i);
			}
			if(w!=(u[j]&(1ull<<i)))
				return false;
		}
		for(int j=1;j<=n;j++){
			ll w=(1ull<<i);
			if(t[j]==0)
				for(int k=1;k<=n;k++)
					w&=a[k][j];
			else{
				w=0;
				for(int k=1;k<=n;k++)
					w|=a[k][j]&(1ull<<i);
			}
			if(w!=(v[j]&(1ull<<i)))return 0;
		}
	}
	return true;
}
int main(){
	n=read();
	for(int i=1;i<=n;i++)
		s[i]=read();
	for(int i=1;i<=n;i++)
		t[i]=read();
	for(int i=1;i<=n;i++)
		scanf("%llu",u+i);
	for(int i=1;i<=n;i++)
		scanf("%llu",v+i);
	if(!work())return puts("-1"),0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			printf("%llu%c",a[i][j],j==n?'\n':' ');	
	return 0;
}

Measured memory_bytes: 7384
fun main(args: Array<String>) {
	val ins = mutableListOf<Int>()
	repeat(4) {
		ins.add(readLine()!!.toInt())
	}
	var sum = 0
	if (ins[0] > ins[1]) {
		sum += ins[1]
	} else {
		sum += ins[0]
	}
	if (ins[2] > ins[3]) {
		sum += ins[3]
	} else {
		sum += ins[2]
	}
	println("${sum}")
}

Measured memory_bytes: 33656
#include <iostream>
#include <fstream>
#include <sstream>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

#define pb push_back
#define pbk pop_back
#define mp make_pair
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define foreach(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); ++i)
#define len(a) ((int) (a).size())

#ifdef CUTEBMAING
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

using namespace std;

typedef long long int64;
typedef long double ld;
typedef unsigned long long lint;

const int inf = (1 << 30) - 1;
const int64 linf = (1ll << 62) - 1;

int main() {
#ifdef XCODE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n; cin >> n;
    vector<int> a(n);
    for (auto &i : a) {
        scanf("%d", &i);
        i--;
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (i < a[i] && a[a[i]] == i) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <numeric>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> num;
	for (int i = 0; i < n; i++)
	{
		int tmp;
		cin >> tmp;
		num.push_back(tmp);
	}
	long long ans[100][21] = { 0 };

	auto it = num.begin();
	ans[0][*it] = 1;

	for (int i = 0; i < n - 1; i++)
	{
		it++;
		for (int j = 0; j < 21; j++)
		{
			if (ans[i][j] != 0)
			{
				if (j - *it >= 0)
				{
					ans[i + 1][j - *it] += ans[i][j];
				}
				if (j + *it < 21)
				{
					ans[i + 1][j + *it] += ans[i][j];
				}
			}
		}
	}

	cout << ans[n - 2][*it] << endl;

	return 0;
}

Measured memory_bytes: 3168
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>

using namespace std;
typedef long long ll;
using namespace std;
        
int main(){
    ll N;
    cin >> N;
    ll a = 10;
    ll ans = 0;
    if(N%2 == 1){
        ans = 0;
    } else {
        while(a <= N){
            ans += N/a;
            a*=5;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,sum;
  cin>>n;
  int a[n],b[n];
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  sum=0;
  for(int i=0;i<n;i++){
    int k=a[i]-b[i];
    if(k>0)
      sum=sum+k;
  }
  cout<<sum;
  return 0;
}

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

void array_swap(int a[],int n);
void swap(int& x,int& y);
int main()
{

  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++)
    cin >> a[i];

  array_swap(a,n);

  for(int i=0;i<n;i++)
    {
      cout << a[i];
      if(i==n-1)break;
      cout << " ";
    }
  cout << '\n';
  return 0;
}

void swap(int& x,int& y)
{
  int tmp=x;
  x=y;
  y=tmp;
}

void array_swap(int a[],int n)
{
  int tmp;
  for(int i=0;i<n/2;i++)
    {
      swap(a[i],a[n-1-i]);
    }
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
#include <algorithm>
#include <string>
#include <vector>
int main()
{

    char c;
    cin>>c;
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
    {
        cout<<"vowel";
    }
    else
    {
        cout<<"consonant";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using pll=pair<ll,ll>;
using plll=pair<ll,pll>;
using graph=vector<vector<int>>;

const ll MOD=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

ll abs1(ll a){
  if(a>=0)return a;
  else return -a;
}

ll pow1(ll a,ll b,ll p=LLONG_MAX){
  ll ret=1;
  while(b!=0){
    if((b&1)==1){
      ret*=a;
    }
    a*=a;
    if(a>=p)a%=p;
    b=b>>1;
  }
  return ret;
}

int digit(ll a,ll b){
  int i=0;
  while(a!=0){
    a/=b;
    i++;
  }
  return i;
}

ll gcd1(ll a,ll b){
  if(a==0 && b==0)return 0;
  ll n;
  while(a%b!=0){
    n=a%b;
    a=b;
    b=n;
  }
  return b;
}

ll solveLinear(ll n,ll m,ll c){
  if(n==0 && m==0)return 0;
  ll a[100],b[100];
  a[0]=n;b[0]=m;
  int i=1;
  while(b[i-1]!=0){
    a[i]=b[i-1];
    b[i]=a[i-1]%b[i-1];
    i++;
  }
  n=i;
  if(c%a[n-1]!=0){
    return 0;
  }
  ll x=c/a[n-1],y=0;
  for(i=1;i<n;i++){
    ll cnt=x;
    x=y;
    y=cnt-(a[n-i-1]/b[n-i-1])*y;
  }
  return x;
}

ll modRev(ll a,ll p=MOD){
  a%=p;
  ll n=solveLinear(a,p,1);
  n%=p;
  if(n<0)return n+p;
  return n;
}

ll fact(ll n,ll p=MOD){
  if(n<0)return 0;
  int i;
  ll ret=1;
  for(i=0;i<n;i++){
    ret=ret*(i+1);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll perm(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    if(ret>=p)ret%=p;
  }
  return ret;
}

ll binom(ll n,ll k,ll p=MOD){
  if(n<0 || k<0 || n<k)return 0;
  int i;
  ll ret=1,fact=1;
  for(i=0;i<k;i++){
    ret=ret*(n-i);
    fact*=i+1;
    if(ret>=p)ret%=p;
    if(fact>=p)fact%=p;
  }
  return (ret*modRev(fact))%p;
}

void pushHeap(vector<ll>& h,int n){
  int i=h.size();
  h.push_back(n);
  while(i!=0 && h[(i-1)/2]<h[i]){
    swap(h[i],h[(i-1)/2]);
    i=(i-1)/2;
  }
  h[i]=n;
}

ll popHeap(vector<ll>& h){
  int n=h.size()-1;
  if(n==-1)return 0;
  ll i,ret=h[0];
  swap(h[0],h[n]);
  h.pop_back();
  for(i=0;i<n;){
    int j=2*i+1;
    if(j>=n)break;
    if(j!=n-1 && h[j]<h[j+1])j++;
    if(h[i]<h[j]){
      swap(h[i],h[j]);
    }
    i=j;
  }
  return ret;
}

vector<int> ver;
void dfs(const graph &g,int v){
  ver[v]=1;
  for(auto i:g[v]){
    if(ver[i]!=1)continue;
    dfs(g,i);
  }
}

int bis(vector<int> v,int key){
  int left=-1,right=v.size();
  while(abs1(right-left)>1){
    int mid=left+(right-left)/2;
    if(v[mid]<=key)left=mid;
    else right=mid;
  }
  return left;
}


int main(){
  int i,j,cnt=0;
  int n,m;
  cin>>n>>m;
  graph v(m+1);
  int ma=0;
  for(i=0;i<n;i++){
    int a,b;
    cin>>a>>b;
    if(a>m)continue;
    v[a].push_back(b);
  }
  vector<ll> h;
  ll sum=0;
  for(i=1;i<=m;i++){
    for(auto j:v[i]){
      pushHeap(h,j);
    }
    if(!h.empty())sum+=popHeap(h);
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 5632
import sys
sys.setrecursionlimit(10**6)

a, b = map(int, input().split())

def rep_xor(x):
    if x%4 == 0:
        return 0^x
    elif x%4 == 1:
        return 1
    elif x%4 == 2:
        return 1^x
    else:
        return 0

if a > 0:
    fa = rep_xor(a-1)
    fb = rep_xor(b)
    ans = fa^fb
else:
    fb = rep_xor(b)
    ans = fb

print(ans)

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

signed main() {
  int n = read(), sum = 0;
  n += 2;
  vi a(n);
  a[0] = 0;
  a[n - 1] = 0;
  FOR(i, 1, n - 1) {
    a[i] = read();
    sum += abs(a[i] - a[i - 1]);
  }
  sum += abs(a[n - 1] - a[n - 2]);
  int ans;
  FOR(i, 1, n - 1) {
    ans = sum + abs(a[i + 1] - a[i - 1]);
    ans -= abs(a[i] - a[i - 1]);
    ans -= abs(a[i + 1] - a[i]);
    print(ans);
  }
}


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    int n,m,i,j,k,d=0;
    cin>>s>>t;
    n=s.size();
    m=t.size();
    int minm=m;
    for(i=0;i<=n-m;i++){
        int cnt=0;
        for(j=0;j<m;j++){
            if(s[i+j]!=t[j]){
                cnt++;
            }
        }
        if(cnt<minm){
            minm=cnt;
        }
    }
    cout<<minm<<endl;
    return 0;
}


Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

int main() {
	long N, A, B;
	std::cin >> N >> A >> B;
	long count = (N / (A + B)) * A + std::min(N % (A + B), A);
	std::cout << count;
	return 0;
}

Measured memory_bytes: 256
import queue
import copy
import math
from collections import deque
import bisect
from decimal import Decimal

# そのまま入力文字列の入力
n, m = map(int, input().split())

heights = list(map(int, input().split()))

candidate = set()

for i in range(n):
    candidate.add(i + 1)

roads = []
# 空白区切りの数値をリスト化
for i in range(0, m):
    road = list(map(int, input().split()))
    roads.append(road)

exists_road = set()
lower = set()
ans_set = set()

for road in roads:
    h0 = heights[road[0] - 1]
    h1 = heights[road[1] - 1]

    exists_road.add(road[0])
    exists_road.add(road[1])

    if h0 > h1:
        ans_set.add(road[0])
        lower.add(road[1])

    elif h0 < h1:
        ans_set.add(road[1])
        lower.add(road[0])

    else:
        ans_set.add(road[0])
        lower.add(road[0])
        ans_set.add(road[1])
        lower.add(road[1])

unvisited = candidate - exists_road
heighest = ans_set - lower

print(len(unvisited) + len(heighest))

Measured memory_bytes: 51748