akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

int n, s;
int x[100009];
ll p[100009];

int par[100009];

ll dp[100009];
ll solve(int i) {
    if(dp[i]) return dp[i];
    return dp[i] = (~par[i] ? solve(par[i]) + abs(x[i] - x[par[i]])
                            : abs(x[i] - s));
}

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

    cin >> n >> s;
    rep(i, n) cin >> x[i] >> p[i];

    memset(par, -1, sizeof(par));
    int a = 0, b = n - 1;

    while(x[a] < s && s < x[b]) {
        if(p[a] >= p[b]) {
            p[a] += p[b];
            par[b] = a;
            b--;
        } else {
            p[b] += p[a];
            par[a] = b;
            a++;
        }
    }

    ll res = -inf;
    rep(i, n) chmax(res, solve(i));

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 2560
# 不幸な人の最少人数は1人
# 同じ向きを向いている人を1人に圧縮すると、[L,R,L,...,L], [L,R,L,...,R],[R,L,R,...,R],[R,L,R,...,L]のいずれかの配列が得られる
# [L,R,L,...,L], [R,L,R,...,R]については1回操作を行うごとに不幸な人が常に2人減る。(配列長-2)回操作を行ったら終了
# [L,R,L,...,R], [R,L,R,...,L]については、(配列長)/2)回目の操作のみ不幸な人を1人だけ減らし、他の操作では2人不幸な人を減らす

N, K = map(int, input().split())
S = list(input())

# 同じ方向を向いている人の圧縮処理
S_pack = [S[0]]
for direction in S:
    if S_pack[-1] != direction:
        S_pack.append(direction)

n_unhappy = len(S_pack)

if n_unhappy%2 == 1:
    n_unhappy = max(n_unhappy - K*2, 1)
elif K >= n_unhappy/2:
    n_unhappy = 1
else:
    n_unhappy -= K*2

print(N - n_unhappy)

Measured memory_bytes: 4652
import java.util.Scanner;
//import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        
        int n = stdIn.nextInt();
        //double[] v = new double[n];
        PriorityQueue<Double> v = new PriorityQueue<Double>();
        for(int i = 0;i < n;i++){
            v.add(stdIn.nextDouble());
        }
        while(v.size() >= 2){
            double x = v.poll();
            double y = v.poll();
            v.add((x+y)/2);
        }
        System.out.println(v.peek());
        
        
    }

}

Measured memory_bytes: 23380
#include <iostream>
#include <limits.h>
using namespace std;

int main(void){
    long long a, b, x;
    cin >> a >> b >> x;
    if (b == 0) cout << "1";
    else if (a == 0) cout << b / x + 1;
    else cout << b / x - (a - 1) / x;
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val P = readLine()!!.split(" ").map(String::toInt).toMutableList()
    val Q = readLine()!!.split(" ").map(String::toInt).toMutableList()
    val score1 = calc(P, N)
    val score2 = calc(Q, N)
    println(Math.abs(score1 - score2))
}

fun calc(a: MutableList<Int>, N: Int): Int {
    var score = 1
    for (i in 0 until N) {
        score += (a[i] - 1) * fact(N - i - 1)
        for (j in i+1 until N) {
            if (a[i] < a[j]) a[j]--
        }
    }
    return score
}

fun fact(d: Int): Int {
    var a = 1
    for (i in 1..d) a *= i
    return a
}

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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)
typedef long long ll;
typedef pair <int, int> P;
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; }
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;


int main() {
	int n, h, w;
	cin >> n >> h >> w;
	int ans = 0;
	REP(i, n) {
		int a, b;
		cin >> a >> b;
		if (h <= a && w <= b)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  ll N;
  cin>>N;
  ll a[N];
  for(ll i = 0;i<N;i++){
    cin>>a[i];
  }
  ll ans = 0;
  for(ll i = 1;i<N;i++){
    if(a[i]<a[i-1]){
      ans += a[i-1]-a[i];
      a[i] = a[i-1];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5192
#include <iostream>
using namespace std;
int next[][2] = {
  { 1, 2 }, { -1, 3 }, { 1, -1 }, { 4, 5 }, { 5, 2 }, { 2, 1 },
};
int main()
{
  for(;;){
    string s;
    cin >> s;
    if(s == "#") break;
    int p = 0;
    for(int i=0; i<s.length(); i++){
      p = next[p][s[i]-'0'];
      if(p < 0) break;
    }
    if(p == 5) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}
                                                        

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

using namespace std;

int main(int argc, const char * argv[]) {
    
    int W, H, N;
    cin >> W >> H >> N;
    
    // Initialize
    vector<vector<int>> vi;
    vi.resize(W);
    for(int i = 0; i < W; i++)
    {
        vi[i].resize(H);
    }
    
    for(int i = 0; i < W; i++)
    {
        for(int j = 0; j < H; j++)
        {
            vi[i][j] = 1; // White
        }
    }
    
    int x, y, a;
    //vector<int> x(N), y(N), a(N);
    
    for(int i = 0; i < N; i++)
    {
        //cin >> x[i] >> y[i] >> a[i];
        cin >> x >> y >> a;
        
        if(a == 1)
        {
            for(int j = 0; j < x; j++)
            {
                for(int k = 0; k < H; k++)
                {
                    vi[j][k] = 0;
                }
            }
        }
        else if(a == 2)
        {
            for(int j = x; j < W; j++)
            {
                for(int k = 0; k < H; k++)
                {
                    vi[j][k] = 0;
                }
            }
        }
        else if(a == 3)
        {
            for(int j = 0; j < W; j++)
            {
                for(int k = 0; k < y; k++)
                {
                    vi[j][k] = 0;
                }
            }
        }
        else if(a == 4)
        {
            for(int j = 0; j < W; j++)
            {
                for(int k = y; k < H; k++)
                {
                    vi[j][k] = 0;
                }
            }
        }
    }
    
    int ans = 0;
    for(int j = 0; j < W; j++)
    {
        for(int k = 0; k < H; k++)
        {
            ans += vi[j][k];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define M 998244353
#define MAX_N 300000
using namespace std;
typedef long long ll;

ll fact_n[MAX_N + 1], fact_inv[MAX_N + 1];

ll mod_pow(ll a, ll n) {
	ll x = 1;
	while (n > 0) {
		if (n & 1) x = x * a % M;
		a = a * a % M;
		n >>= 1;
	}
	return x;
}


ll combination(int n, int r) {
	if (n == 0 && r == 0) return 1;
	else if (n < r || n < 0) return 0;
	
	ll com = fact_n[n] * fact_inv[r] % M;
	return com * fact_inv[n - r] % M;
}


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

	fact_n[0] = fact_inv[0] = 1;
	for (int i = 1;i <= n;i++) {
		fact_n[i] = fact_n[i - 1] * i % M;
		fact_inv[i] = mod_pow(fact_n[i], M - 2);
	}

	ll com = 0;
	for (int i = 0;i <= n;i++) {
		if (((k - a * i) % b == 0) && (k - a * i >= 0)) {
			int j = (k - a * i) / b;
			com += combination(n, i) * combination(n, j) % M;
		}
	}

	cout << com % M << endl;
    return 0;
}



Measured memory_bytes: 4992
#include <cstdio>
#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;

int main()
{
    //freopen("a.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    string str;
    cin>>str;
    bool flag=(str.length()==6);
    if(flag){
    	flag=(str[2]==str[3])&&(str[4]==str[5]);
    	if(flag)cout<<"Yes\n";
    	else cout<<"No\n";
    }
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, k;
    cin >> n >> k;

    const int MAX = 64;
    ll num = 1;
    int ans = 0;
    rep(i, MAX) {
        if (n >= num) ans = i+1;
        num *= k;
        if (num > INF) break;
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
a = [0] * (N+1)
for i in range(N):
    a[i] = list(map(int, input().split()))
dp = []
for _ in range(N+1):
    dp.append([0, 0, 0])

for n in range(N):
    for i in range(3):
        for j in range(3):
            if i == j:
                continue
            dp[n+1][i] = max(dp[n+1][i], dp[n][j] + a[n][i])
ans = max(dp[N])

print(ans)

Measured memory_bytes: 47332
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    vector<int> x;
    int N, M, cnt=1000000001;
    cin >> N >> M;
    for (int i=0;i<N;i++){
        int a;
        cin >> a;
        x.push_back(a);
    }
    sort (x.rbegin(),x.rend());
    for (int i=0;i<N-M+1;i++)
        cnt=min(cnt,x[i]-x[i+M-1]);
    cout << cnt;
    return 0;
}

Measured memory_bytes: 892
import java.util.Scanner;
import java.util.regex.*;
import java.math.*;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		//int a = sc.nextInt();
		// スペース区切りの整数の入力
		//int b = sc.nextInt();
		//int c = sc.nextInt();
		// 文字列の入力
		//String s = sc.next();
		//1文字ずつ
		//s.atChar(i);
		// 出力
		//System.out.println("");
		//double countx=0;

		int A=sc.nextInt();
		int B=sc.nextInt();
		//int Q=sc.nextInt();
		
		if((A*B)%2==1){
			System.out.println("Yes");
		
		}else{
			System.out.println("No");
		}
		
		
	}
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  if((a==b && a!=c) || (a==c && a!=b) || (b==c && a!=b)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using lint = long long;

int main() {
    std::multiset<lint> fore, back;
    // 奇数ならforeに入れる

    lint fsum = 0, bsum = 0;
    lint c = 0;

    int q;
    std::cin >> q;
    for (int p = 0; p < q; ++p) {
        int t;
        std::cin >> t;
        if (t == 1) {
            lint a, b;
            std::cin >> a >> b;
            c += b;

            if (back.empty() || a < *back.begin()) {
                fore.insert(a);
                fsum += a;
            } else {
                back.insert(a);
                bsum += a;
            }

            while (fore.size() > back.size() + 1) {
                auto it = --fore.end();
                a = *it;
                fore.erase(it);
                fsum -= a;

                back.insert(a);
                bsum += a;
            }

            while (back.size() > fore.size()) {
                auto it = back.begin();
                a = *it;
                back.erase(it);
                bsum -= a;

                fore.insert(a);
                fsum += a;
            }
        } else {
            lint x = *(--fore.end());
            std::cout << x << ' '
                      << ((lint)fore.size() * x - fsum) +
                             (bsum - (lint)back.size() * x) + c
                      << std::endl;
        }
    }
    return 0;
}


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

using LL = long long;

int main(){
    LL a,b,k;

    cin>>a>>b>>k;

    if(k<=a){
        cout<<a-k<<" "<<b<<endl;
    }else if(b-(k-a)>0){
        cout<<0<<" "<<b-(k-a)<<endl;
    }else{
        cout<<0<<" "<<0<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

for i in range(N):
    v = A[i]
    j = i-1
    while j >= 0 and A[j] > v:
        A[j+1] = A[j]
        j -= 1
        A[j+1] = v
    print(' '.join([str(i) for i in A]))



Measured memory_bytes: 5608
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


#define BOOST        ios::sync_with_stdio(false);  cin.tie(NULL); cout.tie(NULL);
#define AZ(x)        x.begin(),x.end()
#define fi           first
#define se           second
#define pb           push_back
#define emp          emplace_back
#define mp           make_pair
#define mt           make_tuple
#define debug(x)     cerr << #x << " : " << x << endl;
#define For(i,a,n)   for(auto i = a; i < n; i++)


template<typename T> using V = vector<T>;
template<typename T, typename U> using P = pair<T,U>;

typedef long long ll;
typedef long double ld;


template<typename T>
// for super_map add a parameter Y above and replace "null_type" with "Y"

// set with two additional super powers
    // find_by_order(int k) - returns k'th smallest element (0-indexed)
    // order_of_key(int k) - returns number of elements strictly smaller than k.
using super_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


const int mod = 1e9+7, N = 1e5+5;
const ll INF = 1e18;



ll power(ll a,ll b)
{
    a = a%mod;
    ll result = 1;

    while(b)
    {
        if(b&1)
            result = (result*a)%mod;
        b >>= 1, a = (a*a)%mod;
    }
    return result;
}

ll super_rand(ll n) // Random number from set [0,n-1]
{
    uniform_int_distribution<ll> uid(0, n - 1);
    return uid(rng);
}



/*



1. Make sure you're taking all the inputs.
2. In case of nested loops, remember to use different variables.
3. If in doubt, do int -> ll
4. Don't fight the question, try solving the next one.
5. ffs (positon of first set bit), clz (leading 0s, max->32), ctz (trailing 0s), popcount (set bits). Don't use any of these on 0;



*/



// Don't code anything above this //









ll dp[405][405];		// dp[i][j] : min cost incurred to combine all number from i to j;
						// dp[i][j] : min ( dp[i][j-1] , dp[i+1][j] ) + (a[i] + ... + a[j] ) 



int main()
{
    BOOST

    int n;

    cin >> n;

    ll a[n + 5] = {};

    for(int i = 0; i <= n; i++)
    	for(int j = i+1; j <= n; j++)
    		dp[i][j] = INF;

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

    for(int i=1;i<n;i++)
    	dp[i][i+1] = a[i] + a[i+1];

    for(int i = 1; i <= n; i++)
    	a[i] += a[i - 1];
    
    for(int i = n-2; i >= 1; i-- )
    	for(int j = i+2; j <= n; j++)
    		for(int k = i; k <= j; k++)
    			dp[i][j] = min(dp[i][j], dp[i][k] + dp[k+1][j] + a[j] - a[i - 1]);
    
    cout << dp[1][n] << "\n";
    return 0;
}



Measured memory_bytes: 1536
import itertools
cnt = 0
n = int(input())
p_list = list(map(int,input().split()))
q_list = list(map(int,input().split()))
    
combination = list(itertools.permutations(range(1,n+1)))
combination_list = [list(x) for x in combination]

p_i = combination_list.index(p_list)
q_i = combination_list.index(q_list)


print(abs(p_i - q_i))

Measured memory_bytes: 15092
N, x = map(int,input().split())
a = list(map(int,input().split()))

ans = 0
for k in range(1,N):
    if a[k-1] + a[k] > x:
        t = (a[k-1] + a[k]) - x
        ans += t
        if a[k] >= t:
            a[k] -= t
        else:
            a[k-1] -= t-a[k]
            a[k] = 0
print(ans)


Measured memory_bytes: 14252
#include <iostream>
using namespace std;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	int N, A, B; cin >> N >> A >> B;
	int total = 0;

	repe(i, 1, N) {
		int t = i;
		int sum = 0;

		while (1) {
			if (t == 0)break;
			sum += t % 10;
			t /= 10;
		}

		if (sum >= A && sum <= B) {
			total += i;
		}
	}
	cout << total << endl;

	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
b = [list(map(int, input().split())) for _ in range(m)]
for ans in range(10 ** (n+1)):
    if len(str(ans)) == n and all(str(b[i][1]) == str(ans)[b[i][0] - 1] for i in range(m)):
        print(ans)
        break
else:
    print(-1)


Measured memory_bytes: 38640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    vll a(n);
    rep(i, n){
        cin >> a[i];
    }
    ll s = accumulate(ALL(a), 0ll);
    ll cs = 0;
    ll ans = INF;
    rep(i, n-1){
        cs += a[i];
        ll cs2 = s - cs;
        chmin(ans, abs(cs2-cs));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long L;
using namespace std;
 
#define N 100005
#define U [N]={}
map<L,L> path[N];
L par U,dep U,siz U,hev U,cst U,add U,pos U,hl_par U,bit U,
k,n,q,a,b,c,cnt,i,p,r,ret;
void dfs(L a){
    siz[a]=1;
    for(map<L,L>::iterator I=path[a].begin();I!=path[a].end();I++){
        L d=I->first;
        if(d==par[a]) continue;
        par[d]=a;
        dep[d]=dep[a]+1;
        cst[d]=I->second;
        dfs(d);
        siz[a]+=siz[d];
        if(!hev[a] || siz[hev[a]]<siz[d])
            hev[a]=d;
    }
}
   
L edgecost(L a){
    L ret=add[a]+add[par[a]]+cst[a];
    return ret%k ? ret : 0;
}
   
L sum(L i){
    L ret=0;
    while(i){
        ret+=bit[i];
        i-=i&-i;
    }
    return ret;
}
void S(L i, L x){
    x-=sum(i+1)-sum(i);
    i++;
    while(i<N){
        bit[i]+=x;
        i+=i&-i;
    }
}
   
L cost(L a, L b){
    L p=hl_par[a], q=hl_par[b];
    if(p==q) return abs(sum(pos[a])-sum(pos[b]));
    if(dep[p]<dep[q]){
        swap(p, q);
        swap(a, b);
    }
    return sum(pos[a]) - sum(pos[p])
        + edgecost(p) + cost(par[p], b);
}
 
main(){
    cin >> n >> k;
    for(i=0; i<n-1; i++){
        cin >> a >> b >> c;
        path[a][b]=path[b][a]=c;
    }
    dfs(0);
   
    for(i=0; i<n; i++){
        if(i && hev[par[i]]==i) continue;
        L j=i;
        do{
            pos[j]=cnt++;
            hl_par[j]=i;
        }while(j=hev[j]);
    }
    
    for(i=0; i<n; i++)
        S(pos[i], edgecost(hev[i]));
    //for(i=0; i<n; i++)
     //   printf("%d ",sum(i));cout<<endl;
    
    cin >> q;
    for(i=0; i<q; i++){
        string s;
        cin>>s>>a>>b;
        if(s[0]=='a'){
            add[a]+=b;
            S(pos[a], edgecost(hev[a]));
            if(a) S(pos[a]-1, edgecost(a));
        }else{
            cout << cost(a, b) << endl;
            ret=0;
            for(;false;){
                //cout << a << b << endl;
                p=hl_par[a];
                r=hl_par[b];
                if(p==r){
                    // cout<<ret+abs(sum(pos[a])-sum(pos[b]))<<endl;
                    break;
                }
                if(dep[p]<dep[r]){
                    swap(p, q);
                    swap(a, b);
                }
                ret+=sum(pos[a])-sum(pos[p])+edgecost(p);
                //cout << "aa" << endl;
                
                a=par[p];
            }
        }
    }
}

Measured memory_bytes: 32096
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using uint64 = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << "{";
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i] << ",}"[i == vec.size() - 1];
  }
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << "{" << p.first << " " << p.second << "}";
}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

int main(){
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n, m; cin >> n >> m;
  priority_queue<int> pq;
  rep(i, n) {
    int a; cin >> a;
    pq.push(a);
  }

  rep(i, m) {
    int top = pq.top(); pq.pop();
    top >>= 1;
    pq.push(top);
  }

  int64 ans = 0;

  while (!pq.empty()) {
    ans += static_cast<int64>(pq.top());
    pq.pop();
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 892
#include <stdio.h>

int main(void)
{
	int a,b,c,d,i;
	scanf("%d %d %d",&a,&b,&c);
	
	d=c;
	for(i=0;i<10;i++){
		printf("%d\n",d*a-b);
		d=d*a-b;
	}
	
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int n;
int func(int i){
  return n-i+1;
}

int main(void){
  scanf("%d",&n);
  int a[n];
  int i;
  for(i=1; i<=n ; i++){
    scanf("%d",&a[i-1]);
  }
  int j = 1;
  printf("%d",a[func(j)-1]);
  for(j=2; j<=n ;j++){
    printf(" %d",a[func(j)-1]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
use std::io::*;
use std::str::FromStr;

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")
}

fn main() {
    let n: u32 = read();

    let mut ans = false;

    'outer: for i in 0..(n/4+1) {
        for j in 0..(n/7+1) {
            if 4*i+7*j == n {
                ans = true;
                break 'outer;
            }
        }
    }

    println!("{}", if ans {"Yes"} else {"No"});
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int n,q;
  cin>>n;
  vector<int> S;
  for(int i=0;i<n;i++){
    int t;
    cin>>t;
    S.push_back(t);
  }
  cin>>q;
  int cnt=0;
  for(int i=0;i<q;i++){
    int t;
    cin>>t;
    for(auto x:S){
      if (x==t){
	cnt++;
	break;
      }
    }
  }
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,l,n) for(size_t i=l; i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using mii = map<int,int>;
using pii = pair<int,int>;
using ti3 = tuple<int,int,int>;

int main(){
  int a,b,c; cin>>a>>b>>c;
  int a_i=a, b_i=b, c_i=c;

  if(a_i%2+b_i%2+c_i%2!=0){
    cout<<"0"<<endl;    
    return 0;
  }
  
  REP(i,30){
    a_i = (a+b+c-a_i)/2;
    b_i = (a+b+c-b_i)/2;
    c_i = (a+b+c-c_i)/2;
    if(a_i%2+b_i%2+c_i%2!=0){
      cout<<i+1<<endl;    
      return 0;
    }
  }
  cout<<"-1"<<endl;
}

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

#define rep(i, N) for (ll i = 0; i < N; i++)
#define rep1(i, N) for (ll i = 1; i <= N; i++)
#define repr(i, N) for (ll i = N-1; i >= 0; i--)
#define repr1(i, N) for (ll i = N; i > 0; i--)

#define INF 1000000007

using ll = long long;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<P> vpi;


int main() {
    ll X,ans = 0,sum = 0;
    cin >> X;

    do{
        ans++;
        sum += ans;
    }while(X > sum);

    cout << ans;
    //printf("%.15lf", ans);
    cout << "\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.function.Consumer;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int k = scanner.nextInt();
			int x = scanner.nextInt();

			List<Integer> integers = new ArrayList<Integer>();

			getMinCoodinate(integers, k, x);
			integers.add(x);
			getMaxCoodinate(integers, k, x);
			Collections.sort(integers);
			integers.forEach(new Consumer<Integer>() {
				private int index = 0;

				@Override
				public void accept(Integer t) {
					if (index == integers.size() - 1) {
						System.out.println(t);
					} else {
						System.out.print(t + " ");
					}
					index++;
				}
			});
		}

	}

	private static void getMaxCoodinate(List<Integer> integers, int k, int x) {
		for (int i = 1; i < k && k > 1; i++) {
			if (x > -1000000) {
				integers.add(--x);
			}
		}
	}

	private static void getMinCoodinate(List<Integer> integers, int k, int x) {
		for (int i = 1; i < k && k > 1; i++) {
			if (x < 1000000) {
				integers.add(++x);
			}
		}
	}

}


Measured memory_bytes: 21844
import math
import copy
#import sys
#import bisect
#input = sys.stdin.readline
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))

def main():
    #x,y = map(int,input().split())	x=1,y=2
    #a = input().split()	a=['1','2','3',...,'n']
    #a = list(map(int,input().split()))	a=[1,2,3,4,5,...,n]
    #li = input().split('T')	FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    n=int(input())
    a = list(map(int,input().split()))
    b=copy.copy(a)
    a.sort()
    for i in range(n):
        x=b[i]
        if x<=a[(n//2)-1]:
            print(a[(n//2)])
        else:
            print(a[(n//2)-1])

main()

Measured memory_bytes: 93128
MOD = 1000000007

N, M = map(int, input().split())
A = [int(input()) for _ in range(M)]

T = [0 for _ in range(N + 5)]

for a in A:
    T[a] = -1

T[0] = 1
for i in range(0, N):
    if T[i + 1] != -1 and T[i] != -1:
        T[i + 1] = (T[i + 1] + T[i]) % MOD
    if T[i + 2] != -1 and T[i] != -1:
        T[i + 2] = (T[i + 2] + T[i]) % MOD

print(T[N])


Measured memory_bytes: 7860
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define rg register
#define il inline
#define ll long long
using namespace std;
il ll gi() {
    ll res=0; char ch=0;
    while(ch<'0'|| ch>'9'){ ch=getchar(); }
    while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=getchar();
    return res;
}
il void we(ll x) {
    if(x<0) putchar('-'),x=-x;
    if(x>9) we(x/10);
    putchar(x%10+'0');
}
int main(){
    ll n,a[200009],sum=0;
    n=gi();
    for(ll i=1;i<=n;i++){
        a[i]=gi()-i;
        sum+=a[i];
    }
    sort(a+1,a+1+n);
    ll b=a[n/2],bb=a[(n+1)/2];
    ll ans1=0,ans2=0;
    for(int i=1;i<=n;i++){
        ans1+=abs(a[i]-b);
        ans2+=abs(a[i]-bb);
    }
    we(min(ans1,ans2));
    return 0;
}

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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  string s,t;
  cin >>s;
  if(s[0]=='S')t="Cloudy";
  if(s[0]=='C')t="Rainy";
  if(s[0]=='R')t="Sunny";
  cout <<t;
}

Measured memory_bytes: 3568
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll,ll> pll;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define MOD 1000000007
#define ARRAY_MAX 100005

const int INF = 1e9+7;


int main(){

    int a,b;
    int money[3] = {1000,500,100};
    int cnt[3];

    while(cin >> a >> b,a|b){
        for(int i = 0;i < 3;i++){
            cnt[i] = 0;
        }
        int change = b-a;
        for(int i = 0;i < 3;i++){
            if(change / money[i] != 0){
                cnt[3-i-1] += change/money[i];
                change -= money[i] * (change/money[i]);
            }
        }
        for(int i = 0;i < 3;i++){
            if(i == 0){
                cout << cnt[i];
            }else{
                cout << " " << cnt[i];
            }
        }
        cout << endl;

    }
    
    return 0;
}


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

using namespace std;

#define int long long
#define FR first
#define SC second
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

typedef pair<int, int> P;

const int inf = 1LL << 55;

queue<int> record;

vector<int> graph[101];
int doors[101];
int dist[101];
int d2i[101]; // ??¢?´¢???(????????????|??????????????????)??¨?????¨?????????????????°???????????????????????????????????§????????¬?????§?????¢?????????

void dfs(int& l_vis, int par)
{
  int now = l_vis;
  dist[now] = (~par ? dist[par] + 1 : 0LL);
  d2i[dist[now]] = now;
  
  while(doors[now] && record.size()) {
    //assert(record.size());
    int r = record.front(); record.pop();
    
    if(r > 0) {
      doors[now]--; l_vis++;
      graph[now].push_back(l_vis);
      graph[l_vis].push_back(now);
      doors[l_vis] = r - 1;
      dfs(l_vis, now);
    } else if(r < 0) {
      int d = r + dist[now];
      doors[now]--, doors[d2i[d]]--;
      graph[now].push_back(d2i[d]);
      graph[d2i[d]].push_back(now);
    }
    
  }
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N; cin >> N;
  while(N--) {
    for(auto& g : graph) g.clear();
    memset(doors, 0, sizeof(doors));
    memset(dist, -1, sizeof(dist));
    memset(d2i, -1, sizeof(d2i));
    
    int memo;
    while(cin >> memo, memo) record.push(memo);
    doors[0] = record.front(); record.pop();

    int l_vis = 0;
    dfs(l_vis, -1);

    rep(i, l_vis+1) {
      cout << i+1;
      sort(all(graph[i]));
      rep(j, graph[i].size()) cout << " " << graph[i][j]+1;
      cout << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	int n=read();
	set <int> s;
	rep(i,0,n)s.insert(read());
	cout<<s.size()<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
// aよりbの方が小さかったら、aの値をbの値に置き換える。(swapではない！)
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
// aよりbの方が大きかったら、aの値をbの値に置き換える。
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))

// ^= -> ビットごとの排他的論理和を計算する



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, m; cin >> n >> m;
	string s, t; cin >> s >> t;
	int l = lcm(n, m);
	for (int i = 0; i < l; i += l / n) {
		if (i % (l / m) == 0) {
			if (s[i / (l / n)] != t[i / (l / m)]) {
				cout << -1 << endl; return 0;
			}
		}
	}
	cout << l << endl;
	return 0;
}

Measured memory_bytes: 640
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

X, Y, A, B, C = LI()
p = LI()
q = LI()
r = LI()

p.sort(reverse= 1)
q.sort(reverse= 1)
r.sort(reverse= 1)

def solve():
    ans = 0
    p_selected = p[:X]
    q_selected = q[:Y]
    p_selected.sort()
    q_selected.sort()
    p_cnt = 0
    q_cnt = 0
    r_selected = r[:min((X + Y), len(r))]
    # print(p_selected, q_selected)

    ans += sum(p_selected) + sum(q_selected)
    for r_i in r_selected:
    
        if q_cnt < Y and p_cnt < X:
            if p_selected[p_cnt] >= q_selected[q_cnt]:
                if q_selected[q_cnt] < r_i:
                    ans += r_i - q_selected[q_cnt]
                    q_cnt += 1
                else:
                    return ans
            elif p_selected[p_cnt] < q_selected[q_cnt]:
                if p_selected[p_cnt] < r_i:
                    ans += r_i - p_selected[p_cnt]
                    p_cnt += 1
                else:
                    return ans
        elif q_cnt < Y and p_cnt >= X:
            if q_selected[q_cnt] < r_i:
                ans += r_i - q_selected[q_cnt]
                q_cnt += 1
            else:
                return ans
        elif p_cnt < X and q_cnt >= Y:
            if p_selected[p_cnt] < r_i:
                ans += r_i - p_selected[p_cnt]
                p_cnt += 1
            else:
                return ans

    return ans

ans = solve()

print(ans)

Measured memory_bytes: 25120
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
#define MOD (ll)(1e9+7)
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;


signed main(){
    ll h1,h2,m1,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    ll d = h2*60+m2 - (h1*60+m1) - k;
    cout << d << endl;    
    return 0;

    
}


Measured memory_bytes: 3644
N, K = map(int, input().split())
s = input().strip()
sb, eb = False, False
if s[0] == '0':
    s = '1'+s
    sb = True
if s[-1] == '0':
    s = s+'1'
    eb = True
i = 0
dp = []
while i < len(s):
    l = i
    while i < len(s) and s[i] == '1':
        i += 1
    if l < i:
        dp.append([l, i-1])
    while i < len(s) and s[i] == '0':
        i += 1


if len(dp) <= K:
    print(N)
else:
    ans = 0
    for i in range(0, len(dp)-K):
        t = dp[i+K][1]-dp[i][0]+1
        if t > ans:
            ans = t
            if (sb and i == 0) or (eb and i == (len(dp)-K-1)):
                ans -= 1
    print(ans)


Measured memory_bytes: 11380
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ull unsigned ll
#define pb push_back
#define mp make_pair
 
using namespace std;

int p[200001];
int s[200001];

void make_set(int v){
	p[v]=v;
	s[v]=1;
}

int find_set(int v){
	if(v==p[v])return v;
	return p[v]=find_set(p[v]);
}
void union_sets(int a,int b){
	a=find_set(a);b=find_set(b);
	if(a!=b){
		if(s[a]<s[b])swap(a,b);
		p[b]=a;
		s[a]+=s[b];
	}
}
int main(){
	int n;cin>>n;
	for(int i=1;i<=n;i++)make_set(i);
	int m;cin>>m;
	for(int i=1;i<=m;i++){
		int u,v;cin>>u>>v;
		union_sets(u,v);
	}
	int mx=-1;
	for(int i=1;i<=n;i++){
		int j=find_set(i);
		mx=max(mx,s[j]);
	}
	cout<<mx;
	return 0;
}
	

	



Measured memory_bytes: 5208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int a, b;
    cin >> a >> b;
    int n = b-a;
    cout << n*(n+1)/2 - b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#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(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll MOD = 1000000007;

int main() {
    int n; cin >> n;
    vector<int> s(n);
    int ans = 0;
    int d = 0;
    REP(i,n) {
        cin >> s[i];
        ans += s[i];
        d += (s[i]%10==0 ? 1 : 0);
    }
    if(d==n) ans = 0;
    sort(ALL(s));
    int index = 0;
    while (ans%10==0 && index<n && d!=n) {
        ans -= (s[index]%10!=0 ? s[index] : 0);
        index ++;
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long ll;

int main(){
    int x =0;
    int N;
    string s;
    cin >> N >> s;

    vector<int> ans = {0};
    for(int i=0;i<N;i++){
        if(s[i] == 'I'){
            x++;
            ans.push_back(x);
        }else{
            x--;
            ans.push_back(x);
        }
    }
    printf("%d\n",*max_element(ans.begin(),ans.end()));

    return 0;
}


Measured memory_bytes: 256
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int solve()
{
	int n;
	cin>>n;
	int a[n];
	forci(0,n)	cin>>a[i];
	int ans=0;
	for(int i=0;i<64;i++){
		int one=0;
		int zero=0;
		for(int j=0;j<n;j++){
			if(a[j] & (1LL<<i)){
				one++;
			}
		}
		zero=n-one;
		int x=(one*zero)%mod;
		x=(x*power(2,i))%mod;
		(ans+=x)%=mod;
	}
	cout<<ans<<endl;
	
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}







Measured memory_bytes: 5900
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cstring>

#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;

const int N = 5010, P = 1000000007;

int n;
int fac[N];
int f[N][N];
int sub[N];
vector<int> g[N];

void dfs(int u) {
  sub[u] = 1;
  f[u][1] = 1;
  for (int v : g[u])
    if (!sub[v]) {
      dfs(v);
      if (!(sub[v] & 1)) {
        for (int i = 1; i <= sub[v] / 2; ++i)
          f[v][0] = (f[v][0] + f[v][i * 2] * (ll)fac[i]) % P;
        f[v][0] = (P - f[v][0]) % P;
      }
      static int tmp[N];
      memset(tmp, 0, sizeof(tmp));
      for (int i = 0; i <= sub[u]; ++i)
        for (int j = 0; j <= sub[v]; ++j)
          tmp[i + j] = (tmp[i + j] + f[u][i] * (ll)f[v][j]) % P;
      memcpy(f[u], tmp, sizeof(tmp));
      sub[u] += sub[v];
    }
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
#endif

  scanf("%d", &n);
  for (int rep = 1; rep < n; ++rep) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  fac[0] = 1;
  for (int i = 1; i <= n; ++i)
    fac[i] = fac[i - 1] * (2 * i - 1LL) % P;
  dfs(1);
  int ans = 0;
  for (int i = 0; i <= n / 2; ++i)
    ans = (ans + fac[i] * (ll)f[1][i * 2]) % P;
  printf("%d\n", ans);

  return 0;
}



Measured memory_bytes: 98816
#include <stdio.h>
int main(void){
    // Your code here!
    int a,b;
    int seki;
    scanf("%d %d",&a,&b);
    seki=a*b;
    if(seki%2!=0){
        printf("Odd");
    }
    else{
        printf("Even");
    }
    
    return 0;
}

Measured memory_bytes: 128
def main():

    n = int(input())
    ac_count = 0
    wa_count = 0
    tle_count = 0
    re_count = 0

    for _ in range(n):
        s = input()
        if s == "AC":
            ac_count += 1
        elif s == "WA":
            wa_count += 1
        elif s == "TLE":
            tle_count += 1
        else:
            re_count += 1
        
    print("AC x {}".format(ac_count))
    print("WA x {}".format(wa_count))
    print("TLE x {}".format(tle_count))
    print("RE x {}".format(re_count))

if __name__ == "__main__":
    main()

Measured memory_bytes: 9212
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define INF 1e9

int main(){
  int n;

  cin >> n;
  vector<int> r(n),c(n),p;
  for(int i = 0 ; i < n ; i++){
    cin >> r[i] >> c[i];
  }

  p.push_back(r[0]);
  for(int i = 0 ; i < n ; i++){
    p.push_back(c[i]);
  }

  int dp[n+1][n+1];
  for(int i = 0 ; i <= n ; i++){
    dp[i][i] = 0;
  }

  for(int l = 2 ; l <= n ; l++){
    for(int i = 1 ; i <= n-l+1 ; i++){
      int j = i + l - 1;
      dp[i][j] = INF;
      for(int k = i ; k <= j-1 ; k++){
	int cost = dp[i][k] + dp[k+1][j] + p[i-1]*p[j]*p[k];
	dp[i][j] = min(dp[i][j],cost);
      }
    }
  }

  cout << dp[1][n] << endl;

  return 0;
}

Measured memory_bytes: 1256