akhauriyash/Code-Regression huggingface dataset:
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  dead_code,
  unused_macros
)]
//use proconio::fastout;
use proconio::input;
use proconio::marker::*;
//use std::collections::HashSet;
use std::cmp::*;
use std::collections::*;
macro_rules! debug {
  ($($a:expr),* $(,)*) => {
      #[cfg(debug_assertions)]
      eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
  };
}
fn main() {
  input! {
     H:usize,
     W:usize,
     C:(Usize1, Usize1),
     D:(Usize1, Usize1),
     S:[Chars;H]
  }
  let C: (usize, usize) = (C.0 + 2, C.1 + 2);
  let D: (usize, usize) = (D.0 + 2, D.1 + 2);
  let S: Vec<Vec<char>> = S;
  let mut kabe = vec![vec![true; W + 10]; H + 10];
  for x in 0..H {
    for y in 0..W {
      if S[x][y] == '.' {
        kabe[x + 2][y + 2] = false;
      }
    }
  }
  let kabe: Vec<Vec<bool>> = kabe;
  // Cを基準に幅優先探索。
  // (n=ワープ回数, 位置)
  let mut h = BinaryHeap::new();
  //訪問済み
  let mut v = vec![vec![false; W + 10]; H + 10];
  // ワープ回数
  let mut d = vec![vec![std::u64::MAX; W + 10]; H + 10];
  v[C.0][C.1] = true;
  d[C.0][C.1] = 0;
  h.push((Reverse(0), C.0, C.1));

  while let Some((Reverse(c), x, y)) = h.pop() {
    let mut mvcheck = |c: u64, x: usize, y: usize| {
      if !kabe[x][y] {
        if kabe[x][y] == false {
          if d[x][y] > c {
            d[x][y] = c;
            h.push((Reverse(c), x, y));
          }
        }
      }
    };
    for x1 in x - 2..=x + 2 {
      for y1 in y - 2..=y + 2 {
        if x1 == x && y1 == y {
          continue;
        }
        if (x1 == x && (y1 == y - 1 || y1 == y + 1)) || (y1 == y && (x1 == x - 1 || x1 == x + 1)) {
          mvcheck(c, x1, y1);
        } else {
          mvcheck(c + 1, x1, y1)
        }
      }
    }
  }
  let ans = d[D.0][D.1];
  if ans < std::u64::MAX {
    println!("{}", ans);
  } else {
    println!("-1");
  }
}


Measured memory_bytes: 17284
#include <bits/stdc++.h>
using namespace std;
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

using P = pair<int, int>;

// dp[bit][k] := bitが立っている場所のカードをソートして並べた時、
// 最後の数がkである時の操作回数の最小値
vector<vector<int>> dp((1 << 18) + 10, vector<int>(60, INF));

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<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];
    }
    dp[0][0] = 0;

    for(int bit = 0; bit < (1 << n); bit++) {
        // 今何枚並べているか
        int np = __builtin_popcount(bit);
        for(int k = 0; k <= 50; k++) {
            if(dp[bit][k] == INF) {
                continue;
            }
            int cost = 0;
            // 次に置くカードを決める
            for(int i = 0; i < n; i++) {
                // もしi番目のカードを既に使っていたらだめ
                if(bit & (1 << i)) {
                    continue;
                }
                // 位置の相対的な偶奇で表か裏かが決まる
                int next = (abs(i - np) % 2 == 0 ? a[i] : b[i]);
                // 次に置くカードによって広義単調増加になるならば更新
                if(next >= k) {
                    chmin(dp[bit | (1 << i)][next], dp[bit][k] + cost);
                }
                cost++;
            }
        }
    }
    int ans = INF;
    for(int i = 0; i <= 50; i++) {
        chmin(ans, dp[(1 << n) - 1][i]);
    }
    cout << (ans == INF ? -1 : ans) << endl;
}

Measured memory_bytes: 71936
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

const int MAX=10000;

int V;
vector<int> G[MAX];
vector<int> rG[MAX];
vector<int> vs;
bool used[MAX];
int cmp[MAX];

void add_edge(int from,int to)
{
	G[from].push_back(to);
	rG[to].push_back(from);
	return;
}

void dfs(int v)
{
	used[v]=true;
	for(int i=0;i<G[v].size();i++)
	{
		if(!used[G[v][i]])dfs(G[v][i]);
	}
	vs.push_back(v);
	return;
}

void rdfs(int v,int k)
{
	used[v]=true;
	cmp[v]=k;
	for(int i=0;i<rG[v].size();i++)
	{
		if(!used[rG[v][i]])rdfs(rG[v][i],k);
	}
	return;
}

int ssc()//Strongly Connected Component
{
	memset(used,0,sizeof(used));
	vs.clear();
	for(int v=0;v<V;v++)
	{
		if(!used[v])dfs(v);
	}
	memset(used,0,sizeof(used));
	int k=0;
	for(int i=vs.size()-1;i>=0;i--)
	{
		if(!used[vs[i]])rdfs(vs[i],k++);
	}
	return k;
}

int main()
{
	int E;
	cin>>V>>E;
	for(int i=0;i<E;i++)
	{
		int u,v;
		cin>>u>>v;
		add_edge(u,v);
	}
	int k=ssc();
	cout<<(k!=V)<<endl;
	return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)   for(signed i=0; i<n; i++)
#define FOR(i, k, n)    for(signed i=k; i<n; i++)
#define yn(b)   cout << ((b)?"Yes":"No") << endl
#define YN(b)   cout << ((b)?"YES":"No") << endl
#define pr(r)   cout << r << endl
#define min(x,y)    (x<y)?x:y
#define max(x,y)    (x>y)?x:y
#define ll  long long
int main(void){
    ll n, m, i, j;
    cin >> n >> m;
    pair<ll, ll> a[n];
    rep(i, n) cin >> a[i].first >> a[i].second;
    sort(a, a+n);
    ll r=0, s=0;
    j=0;
    while(r < m){
        if(r+a[j].second <= m){
            s += a[j].first*a[j].second;
            r += a[j].second;
        }else{
            s += a[j].first*(m-r);
            r = m;
        }
        j++;
    }
    pr(s);
}

Measured memory_bytes: 1792
import math
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN

r = list(map(float,input().split()))

x = Decimal(str(r[0])).quantize(Decimal('0'),rounding=ROUND_HALF_UP)
y = Decimal(str(r[1])).quantize(Decimal('0.01'),rounding=ROUND_HALF_UP)

z = x * y

z = math.floor(z)

print(z)

Measured memory_bytes: 10080
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <cassert>
#include <map>
using namespace std;

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        assert(N % 2 == 1);
        map<int, int> m;
        rep(i, N) {
            int a; cin >> a;
            m[a]++;
        }
        int margins = 0;
        for(auto p : m) if(p.second % 2 == 0) margins++;

        cout << m.size() - (margins % 2) << endl;                
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


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

#define FOR(i, a, b) for(int i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(int i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define DEBUG_PRINT(...) fprintf(stderr, __VA_ARGS__)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pi;
typedef vector<int> vi;
void print_pair(pi a){
  cerr<<"("<<a.first<<", "<<a.second<<") ";
}
template<int T1, int T2>
void print_2d(int a[T1][T2], int x, int y){
  For(i, x){
    For(j, y){
      cerr<<a[i][j]<<" ";
    }
    cerr<<endl;
  }
}

const ll MOD = 1000000007;
short N;
vector<short> nodes[5005];
ll g[5001],inv_g[5001];
ll dp[5005][5005][2];

template<typename T> 
int sgn(T val){
  return (T(0)<val)-(val<T(0));
}

tuple<long long,long long,long long> egcd(long long a,long long b){
  if(a==0||b==0)return std::make_tuple(0LL,0LL,0LL);
  long long sa=sgn(a),sb=sgn(b);
  a=std::abs(a);b=std::abs(b);
  long long p=1,q=0,r=0,s=1;
  while(b>0){
    long long c=a/b;
    long long d;
    d=a;a=b;b=d%b;
    d=p;p=q;q=d-c*q;
    d=r;r=s;s=d-c*s;
  }
  return std::make_tuple(a,p*sa,r*sb);
}

long long inverse(long long a,long long m){
  auto b=egcd(a,m);
  if(std::get<0>(b)!=1)return 0;
  return (std::get<1>(b)<0)?std::get<1>(b)+m:std::get<1>(b);
}

#define dump(x) cerr << #x << " = " << (x) << endl;
#define print_dp(i,j,k) cerr<<"dp["<<i<<"]["<<j<<"]["<<k<<"]="<<dp[i][j][k]<<endl;

int tree_dfs(int root,int parent){
  dp[root][1][0]=1;
  if(nodes[root].empty()){return 1;}
  int num=1;
  for(auto child:nodes[root]){
    if(child==parent)continue;
    auto child_num=tree_dfs(child,root);
    for (int i = child_num+num; i > 0; i--) {
      ll buf0=dp[root][i][0],buf1=dp[root][i][1];
      dp[root][i][0]=dp[root][i][1]=0;
      for (int j = max(1,i-num); j <= min(child_num,i-1); j++) {
        dp[root][i][0]+=dp[root][i-j][0]*dp[child][j][0]%MOD;
        dp[root][i][0]+=dp[root][i-j][1]*dp[child][j][1]%MOD;
        dp[root][i][0]%=MOD;
        dp[root][i][1]+=dp[root][i-j][1]*dp[child][j][0]%MOD;
        dp[root][i][1]+=dp[root][i-j][0]*dp[child][j][1]%MOD;
        dp[root][i][1]%=MOD;
      }
      for(int j = 1;i <= num && j <= child_num;j++){
        dp[root][i][0]+=buf0*dp[child][j][1]%MOD*g[j]%MOD;
        dp[root][i][0]+=buf1*dp[child][j][0]%MOD*g[j]%MOD;
        dp[root][i][0]%=MOD;
        dp[root][i][1]+=buf1*dp[child][j][1]%MOD*g[j]%MOD;
        dp[root][i][1]+=buf0*dp[child][j][0]%MOD*g[j]%MOD;
        dp[root][i][1]%=MOD;
      }
    }
    num+=child_num;
  }
  return num;
}

int main(){
  cin>>N;
  for (int i = 2; i < N+1; i+=2) {
    if(i==2){
      g[i]=1;
      continue;
    }
    g[i]=g[i-2]*(i-1)%MOD;
  }
  REP(N-1){
    short a,b;
    cin>>a>>b;
    a--;b--;
    nodes[a].push_back(b);
    nodes[b].push_back(a);
  }
  tree_dfs(0,-1);
  ll ans=0;
  FOR(i,1,N+1){ans=ans+(dp[0][i][0]-dp[0][i][1])*g[i];ans%=MOD;}
  if(ans<0){ans+=MOD;}
  cout<<ans<<endl;
  return 0;
}


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

#define ll long long
#define pb push_back
#define ins insert
#define mp make_pair
#define pii pair<int, int>
#define pil pair<int, ll>
#define pib pair<int, bool>
#define SET(a, c) memset(a, c, sizeof(a))
#define MOD 1000000007
#define enld endl
#define endl "\n"
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define FOUND(u, val) u.find(val) != u.end()
#define max_self(a, b) a = max(a, b);

#include <string>
#include <vector>
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
#include <algorithm>
//#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//#include <cmath>
//#include <cstring>
//#include <sstream>
//#include <stack>
//#include <queue>

// 1 if win. 0 if loss
bool state[100002];
bool calculated[100002];
int n, k;
vi ar;

void recurse(int pos) {
    calculated[pos] = 1;
    bool loserAccessible = false;
    for (int i : ar) {
        if (i + pos <= k) {
            if (!calculated[i + pos]) recurse(i + pos);
            if (!state[i + pos]) loserAccessible = 1;
        } else
            break;
    }
    state[pos] = loserAccessible;
}

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

    cin >> n >> k;
    ar.resize(n);
    for (int i = 0; i < n; i++) cin >> ar[i];
    sort(all(ar));

    for (int i = k; i > k - ar[0]; i--) state[i] = 0, calculated[i] = 1;
    recurse(0);
    cout << (state[0] ? "First" : "Second");
}

Measured memory_bytes: 11656
import heapq

n, m = map(int, input().split())
ab = sorted([list(map(int, input().split())) for i in range(n)])
c = [[]] * m
a, b = ab[0]
last = a
ad = [b]
for i in range(1, n):
    a, b = ab[i]
    if a == last:
        ad.append(b)
    else:
        if last <= m:
            c[last - 1] = ad
        ad = [b]
    last = a
if a <= m:
    c[a - 1] = ad
a = [3, 0, 2, 6]
choice = []
heapq.heapify(choice)
ans = 0
for i in range(m):
    for j in c[i]:
        heapq.heappush(choice, -j)
    if choice:
        ans -= heapq.heappop(choice)
print(ans)


Measured memory_bytes: 34368
def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    *A, = map(int, input().split())

    tot = sum(A)

    ctr = [0] * (10 ** 5 + 1)
    for x in A:
        ctr[x] += 1

    ans = []
    Q = int(input())
    for _ in range(Q):
        B, C = map(int, input().split())

        tot -= ctr[B] * B
        tot += ctr[B] * C

        ctr[C] += ctr[B]
        ctr[B] = 0

        ans.append(tot)

    print(*ans, sep='\n')


if __name__ == '__main__':
    main()

# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 21328
N = int(input())
Monster = list(map(int, input().split()))
Yusha = list(map(int, input().split()))

total = 0

for i in range(N+1):
    if i > 0:
        Min = min(Monster[i], Yusha[i-1])
        Monster[i] -= Min
        Yusha[i-1] -= Min
        total += Min

    if i < N:
        Min = min(Monster[i], Yusha[i])
        Monster[i] -= Min
        Yusha[i] -= Min
        total += Min

print(total)

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,a,n) for(int i=a;i<=n;i++)
#define repb(i,a,n) for(int i=a;i>=n;i--)
#define trav(a,x) for(auto a=x.begin();a!=x.end();a++)
#define all(x) x.begin(),x.end()
#define fst first
#define snd second
#define pb push_back
#define mp make_pair
typedef long double ld;
typedef pair <int,int> pii;
typedef vector <int> vi;
typedef long long ll;


void pre(){

}

void solve(){
  int n,k; cin>>n>>k;
  vi v1(n);
  rep(i,n) cin>>v1[i];
  sort(all(v1));
  ll sum=0;
  rep(i,k) sum+=v1[i];
  cout<<sum<<"\n";
}

int main(){
  // #ifndef ONLINE_JUDGE
  //   freopen("in.txt","r",stdin);
  // #endif
  ios_base::sync_with_stdio(0); cin.tie(0);
  pre();
  int t; t=1;
  rep(i,t) solve();
  return 0;
}


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

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

	int a[n+5][3];

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

	int dp[3][n+1];

	memset(dp,0,sizeof(dp));

	for(int i=0;i<3;i++){
		dp[i][0]=a[0][i];
	}

	for(int i=1;i<n;i++){
		dp[0][i]=max(dp[1][i-1],dp[2][i-1])+a[i][0];
		dp[1][i]=max(dp[0][i-1],dp[2][i-1])+a[i][1];
		dp[2][i]=max(dp[1][i-1],dp[0][i-1])+a[i][2];
	}

	/*for(int i=0;i<3;i++){
		for(int j=0;j<n+1;j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}*/
	int res=max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]));
	cout<<res<<endl;
	return 0;
}
		


Measured memory_bytes: 2560
fun main(args: Array<String>) {
    val n = readLine()?.toInt() ?: return
    val s = readLine() ?: return
    val a = hashMapOf<Char, Int>().apply {
        repeat(26) {
            this['A' + it] = it
        }
    }
    val i = hashMapOf<Int, Char>().apply {
        repeat(26) {
            this[it] = 'A' + it
        }
    }
    s.mapNotNull {
        val c = a[it]!!
        val index = c + n
        if (index >= 26) {
            i[index - 26]
        } else {
            i[index]
        }
    }.joinToString("").let {
        println(it)
    }
}

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

using namespace std;

int main() {
    long long n;
    cin>>n;
    cout<<n*(n+1)/2-3*(n/3*(n/3+1)/2)-5*(n/5*(n/5+1)/2)+15*(n/15*(n/15+1)/2);
    return 0;
}

Measured memory_bytes: 3616
N=int(input())
C=[0]*(N-1)
S=[0]*(N-1)
F=[0]*(N-1)
for i in range(N-1):
  C[i],S[i],F[i]=map(int,input().split())

for i in range(len(C)):
  cur=0
  for j in range(i,len(C)):
    # max(現在時刻 or S[j])より大きい最小のF[j]の倍数
    # F[j]で割ったものを切り上げてF[j]掛ければOK
    # 計算量O(N**2)->250,000
    if cur<S[j]:
      cur=S[j]
    cur=((cur+F[j]-1)//F[j])*F[j]+C[j]
  print(cur)
print(0)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
using namespace std;
typedef long long ll;
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)
 
ll gcd(ll a,ll b){
	if(b==0)return a;
	return gcd(b,a%b);
}
ll lcm(ll a,ll b){
	ll g=gcd(a,b);
	return a/g*b;
}
 
ll digitsum(ll a){
	ll x=0;
	while(a>0){
		x+=a%10;
		a/=10;
	}
	return x;
}
int main(){
	ll a,b;
	cin>>a>>b;
	if(a+b>=10)cout<<"error"<<endl;
	else cout<<a+b<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll x, y;
    cin >> x >> y;
    ll ans;
    if(x * y < 0){
        ans = abs(abs(x) - abs(y)) + 1;
    }else if(x * y == 0){
        if(x > y){
            ans = abs(x - y) + 1;
        }else{
            ans = abs(x - y);
        }
    }else{
        if(x > y){
            ans = abs(x - y) + 2;
        }else{
            ans = abs(x - y);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
"""
#decomment when needed
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
n,k = ips()
a = iprow()
km = k-1
mp = a.index(1)
left = mp
right = n-mp-1
ans  = rem
for i in range(km):
    ap = 0
    lt = max(0,left-i)
    rt = max(0,right-(km-i))
    if lt % km == 0:
        ap += lt // km
    else:
        ap += lt // km + 1
    if rt % km == 0:
        ap += rt // km
    else:
        ap += rt // km + 1
    ans = min(ans,ap)
print(ans+1)

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ll d,g; cin >> d >> g;
  vector<ll> p(d+1),c(d+1);
  for(int i = 1; i <= d; ++i)cin >> p[i] >> c[i];
  vector<int> np;
  for(int i = 1; i <= d; ++i)np.push_back(i);
  ll ans = 1001001001001001;
  do{
    ll sum = 0;
    ll cnt = 0;
    for(auto e:np){
      if(g-sum <= 0)break;
      if(g-sum > p[e]*e*100){
	sum += p[e]*e*100+c[e];
	cnt += p[e];
      } else {
	for(int i = 1; i <= p[e]; ++i){
	  sum += e*100;
	  cnt++;
	  if(g-sum <= 0)break;
	}
      }
    }
    ChangeMin(ans,cnt);
  }while(next_permutation(np.begin(), np.end()));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3636
from collections import Counter

N = int(input())
A = list(map(int, input().split()))
Q = int(input())
b_c = [list(map(int, input().split())) for i in range(Q)]

ans = sum(A)
l = Counter(A)
for i in range(Q):
    ans += l[b_c[i][0]] * (b_c[i][1] - b_c[i][0])
    l[b_c[i][1]] += l[b_c[i][0]]
    l[b_c[i][0]] = 0
    print(ans)

Measured memory_bytes: 40196
#include<iostream>
#include<cstdio>
#include<cstring>

using namespace std;
typedef long long ll;
const int maxn=2e5+5;
int a[maxn];
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        scanf("%d",&a[i]);
    ll ans=0;
    for(int i=2;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: 3992
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <stack>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#define popcount(x) __builtin_popcount(x)
#define oddparity(x) __builtin_parity(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define sf scanf
#define pf printf
#define ll long long int
using namespace std;

int w, a, b, a1, b1;

int main()
{
    sf("%d%d%d", &w, &a, &b);
    a1 = a + w;
    b1 = b + w;
    if (b >= a && b <= a1 || b1 >= a && b1 <= a1) pf("0\n");
    else {
        pf("%d\n", min(abs(a1-b), abs(a-b1)));
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <cstring>	// require memset
//#include <fstream>	// require freopen
//#include <iomanip>	// require setw

using namespace std;

typedef pair<int, int> P;

int field[10][10];


P target_pos (int target )
{
	int x, y;
	P res;

	for (x = 0; x <= 10; ++x ){
		for (y = 0; y <= 10; ++y ){
			if (field[x][y] == target ){
				res.first = x; res.second = y;
				break;
			} // end if
		} // end for
	} // end for

	return res;
}
 
bool dfs (int x, int y, int next, int n )
{
	const int dir[][2] = { 
			{ -1, -2 }, {  0, -2 }, {  1, -2 },
			{ -1,  2 }, {  0,  2 }, {  1,  2 },
			{ -2, -1 }, { -2,  0 }, { -2,  1 },
			{  2, -1 }, {  2,  0 }, {  2,  1 }
	};
	const int range[][2] = {
					{ -1, -1 }, { 0, -1 }, { 1, -1 }, 
					{ -1,  0 }, { 0,  0 }, { 1,  0 }, 
					{ -1,  1 }, { 0,  1 }, { 1,  1 } 
	};

	if (next > n ){
		return true;
	} // end if

	for (int i = 0; i < 12; ++i ){
		int nx = x + dir[i][0];
		int ny = y + dir[i][1];
		if (nx < 0 || nx >= 10 || ny < 0 || ny >= 10 ){
			continue;
		} // end if
		for (int j = 0; j < 9; ++j ){
			P t = target_pos (next );
			
			int tx = t.first  + range[j][0];
			int ty = t.second + range[j][1];
			if (nx == tx && ny == ty ){
				if (dfs (nx, ny, next + 1, n ) ){
					return true;
				} // end if
			} // end if
		} // end for
	} // end for

	return false;
}
					
int main()
{

//	cut here before submit 
//	freopen ("testcase.phyonkichi", "r", stdin );

	int px, py;

	while (cin >> px >> py && px && py ){
		memset (field, 0, sizeof (field) );
		
		int n;
		cin >> n;

		for (int i = 1; i <= n; ++i ){
			int sx, sy;
			cin >> sx >> sy;
			field[sx][sy] = i;
		} // end for

		if (dfs (px, py, 1, n ) ){
			cout << "OK" << endl;
		}else{
			cout << "NA" << endl;
		} // end if
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<cstdlib>
int sum[100001];
int main(){
    int n; scanf("%d", &n);
    int a[100002];a[0]=0;
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
        sum[i] = sum[i-1]+abs(a[i]-a[i-1]);
    }
    int i = n+1;
    a[n+1] =0;
    sum[i] = sum[i-1]+abs(a[i]-a[i-1]);

    printf("%d\n", sum[n+1]-sum[2]+abs(a[2]-a[0]));
    for(int i = 2; i <= n; i++){
        int ans = sum[i-1] + sum[n+1] - sum[i+1] + abs(a[i+1] -a[i-1]);
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 1920
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <string.h>
#include <iomanip>

using namespace std;

int main()
{
	
	int a,b,c;
	cin>> a >> b >>c;
	
	int res = int (floor(b/a));
	
	if (c<res) cout << c <<endl;
	else cout << res <<endl;
	
	
	
	
	
	
	return 0;
}



Measured memory_bytes: 256
n=int(input())
card={"S":[0]*13,"H":[0]*13,"C":[0]*13,"D":[0]*13}

for i in range(n):
    mark, number = input().split()
    card[mark][int(number)-1] = 1


for a in ("S","H","C","D"):
    for b in range(13):
        if card[a][b] == 0:
            print(a,b+1)
    

Measured memory_bytes: 7632
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import bisect
 
def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N = read()
A = [a-(N-1) for a in reads()]

def possible(x): # possible in x turns exactly
  return sum((a + x + N) // (N+1) for a in A if a + x > 0) <= x
# possible(x) -> possible(x+N)

l = -1; r = 10 ** 19
while r - l > 1:
  m = (l + r) // 2
  if possible(m):
    r = m
  else:
    l = m
ans = min(x for x in range(l - 10*N**2, l + 10*N**2) if possible(x))
print(ans)



Measured memory_bytes: 44396
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>

using namespace std;

int N,X,m[110];

int main(){

    cin>>N>>X;

    for(int i=0;i<N;i++){
        cin>>m[i];
    }

    sort(m,m+N);

    int ans=0;

    for(int i=0;i<N;i++){
        X-=m[i];
        ans+=1;
    }

    while(X>=m[0]){
        X-=m[0];
        ans+=1;
    }

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

Measured memory_bytes: 256
#include<stdio.h>
const int MOD = 1000000007;


int main(void){
  int N;
  scanf("%d",&N);

  int S = (N-1)/2 + 1;
  int cnts[100005] = {0};
  int arg;
  for(int i = 0; i < N; i++){
    scanf("%d", &arg);
    if(arg%2 == N%2){
      printf("%d",0);
      return 0;
    }else{
      //printf("%d\n",arg/2);
      cnts[arg/2]++;
    }
  }

  int ans = 1;
  for(int i = 0; i < (N+1)/2; i++){
    //printf("%d,%d\n",i,cnts[i]);
    if(i==0){
      if(N%2==1 && cnts[i]==1){
        ans *= 1;
      }else if(N%2==0 && cnts[i]==2){
        ans *= 2;
      }else{
        printf("%d",0);
        return 0;
      }
    }else{
      if(cnts[i]==2){
        ans *= 2;
      }else{
        printf("%d",0);
        return 0;
      }
    }
    ans %= MOD;
  }

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


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
int main(){
    int n;
    cin >> n;
    vector<long> a(n * 3);
    rep(i, n * 3) cin >> a[i];
    sort(a.begin(), a.end());
    long ans = 0;
    for(int i = 3 * n - 2; i >= n; i -= 2){
        ans += a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, s, n)    for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...)  type __VA_ARGS__; read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream& operator>> (istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail&... tail) { cin >> head; read(tail...); }

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x): x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

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

    var(int, N, M);
    vector<int> indeg(N);

    rep(i, 0, M) {
        var(int, a, b);
        --a, --b;
        indeg[a] ++;
        indeg[b] ++;
    }

    if (all_of(all(indeg), [](int e) { return (e % 2 == 0); })) {
        print("YES");
    } else {
        print("NO");
    }

    return 0;
}


Measured memory_bytes: 640
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
# from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

n,k = myinput()

mod = 10**9 + 7

ls = list(range(n+1))
ls2 = ls[::-1]
# print(ls2)

e = sum(ls2[:k-1])
# print(e)

count = 0
for i in range(k,n+2):
    # print("i={}".format(i))
    s = (i-1)*i//2
    e += ls2[i-1]
    count += e - s + 1
    # print(s,e,count)
print(count%mod)

Measured memory_bytes: 73212
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		String temp = scanner.nextLine();
		StringBuilder sb = new StringBuilder();

		int ans = 1000;

		for(int i = 0; i < temp.length() - 2; i ++) {

			sb.append(String.valueOf(temp.charAt(i)));
			sb.append(String.valueOf(temp.charAt(i + 1)));
			sb.append(String.valueOf(temp.charAt(i + 2)));

			int tmp = Math.abs(753 - Integer.parseInt(sb.toString()));
			ans = Math.min(ans, tmp);
			sb.setLength(0);
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 21844
def f(x):
  a = 0
  b = 0
  for e in x:
    b = [0, b+1][e]
    a = max(a, b)
  return a
def d(M):
  n = len(M)
  X=[]
  for i in range(-n+1,n):
    x = [0]*n
    for j in range(n):
      if 0<=i+j<n: x[j] = M[j][i+j]
    X.append(x)
  return X

while 1:
  n = input()
  if n==0: break
  A = []
  B = []
  for _ in [0]*n:
    e = map(int, list(raw_input()))
    A.append(e)
    B.append(e[::-1])
  print max(map(f, A+zip(*A)+d(A)+d(B)))

Measured memory_bytes: 7920
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    string a = "";

    rep(i, 0, s.size()){
        if(s[i] != 'x'){
            a += s[i];
        }
    }

    rep(i, 0, a.size()){
        if(a[i] != a[a.size() - 1 - i]){
            cout << -1 << endl;
            return 0;
        }
    }

    ll i = 0;
    ll j = s.size() - 1;
    ll ans = 0;
    while(i < j){
        if(s[i] == s[j]){
            i++;
            j--;
        }else if(s[i] == 'x'){
            i++;
            ans++;
        }else{
            j--;
            ans++;
        }
    }

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


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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0; i<N; i++){
    cin >> A.at(i);
  }
  int Sum=0;
  int Ans=1000000000;
  for(int i=-100; i<=100; i++){
    Sum=0;
    for(int j=0; j<N; j++){
      Sum+=(A.at(j)-i)*(A.at(j)-i);
    }
    Ans=min(Ans, Sum);
  }
  cout << Ans << endl;
}

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

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

	vector<int> b(n, 0);
	rep(i, n) {
		if (i % 2 == 0) {
			b[0] += a[i];
		}
		else {
			b[0] -= a[i];
		}
	}
	for (int i = 1; i < n; i++) {
		b[i] = 2 * a[i - 1] - b[i - 1];
	}
	rep(i, n) cout << b[i] << " ";
}

Measured memory_bytes: 2048
#include <stdio.h>

int main(void)
{
    int N;
    int t[110000],x[110000],y[110000];
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d%d%d",&t[i],&x[i],&y[i]);
    }
    int can=1;
    for(int i=0;i<N;i++){
        int can2=0;
        if(t[i]-x[i]-y[i]>=0&&(t[i]-x[i]-y[i])%2==0)
            can2=1;
        if(can2==0){
            can=0;
            break;
        }
    }
    if(can==1)
        printf("Yes\n");
    else
        printf("No\n");
    
    return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<string.h>
using namespace std;
int d[10005];
int main()
{
    int a,b,c,x;
    while(~scanf("%d%d%d%d",&a,&b,&c,&x)){
        x/=50;
        memset(d,0,sizeof(d));
        for(int i=0;i<=a;i++){
            for(int j=0;j<=b;j++){
                for(int k=0;k<=c;k++){
                    d[i*10+2*j+k]++;
                }
            }
        }
        printf("%d\n",d[x]);
    }
}

Measured memory_bytes: 256
#include<stdio.h>

 int main(){
     int n,m,i,j;
     int a[100][100];
     int b[1000];
     int c[1000]={0};

     scanf("%d%d",&n,&m);
     for(i=0;i<n;i++){
           for(j=0;j<m;j++){
                scanf("%d",&a[i][j]);
                }
           }
     for(i=0;i<m;i++){
            scanf("%d",&b[i]);
            }
     for(i=0;i<n;i++){
            for(j=0;j<m;j++){
                 c[i]+=a[i][j]*b[j];
                 }
            printf("%d\n",c[i]);
            }
     return 0;
     }



Measured memory_bytes: 2056
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#define REP(i,n) for (int i=0; i<(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
typedef vector<int> vi;
int main() {
	vi W(10),K(10);
	REP(i,10) scanf("%d",&W[i]);
	REP(i,10) scanf("%d",&K[i]);
	SORT(W); SORT(K);
	int w=0,k=0;
	REP(i,3) w+=W[9-i];
	REP(i,3) k+=K[9-i];
	printf("%d %d\n",w,k);
}

Measured memory_bytes: 0
function Main(input) {

  var input = input.split("\n");
  var arya = input[0].split(" ").map(val => parseInt(val, 10)).slice(0, 3);
  var n = arya[0];
  var a = arya[1];
  var b = arya[2];
  var result = 0;

  if (n*a < b) {
    console.log(n*a);
  } else {
    console.log(b);
  }


}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 22076
#include <bits/stdc++.h>
using namespace std;
string s;
bool ok(string t)
{
	string r=t;
	reverse(t.begin(),t.end());
	return r==t;
}
int main()
{
	cin>>s;
	int n=s.size();
	if(ok(s)&&ok(s.substr(0,n/2))&&ok(s.substr(n/2+1,n/2)))
		puts("Yes");
	else
		puts("No");
	return 0;
}


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

using namespace std;
int n,sum=0;

int main()
{
	cin >> n;
	for(int i=1;i<=n;i++)
	{
		int x,y;cin >> x >> y;
		sum+=(y-x+1);
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#define Min min((x[loop] - x[loop - 1])*A, B)
#define max (int)pow(10,9)
using namespace std;

int min(int, int);

int main(){
	long long int N, A, B;
	long long int x[100000];
	int loop;
	long long int ans = 0;
	int ans2 = 0;

	cin >> N >> A >> B;
	for (loop = 0; loop < N; loop++)cin >> x[loop];

	for (loop = 1; loop < N; loop++){
		ans += Min%max;
		ans2 += Min / max;
	}
	if (ans2 != 0)cout << ans2;
	cout<< ans << "\n";
	return 0;
}

int min(int a, int b){
	if (a>b)return b;
	else return a;
}


Measured memory_bytes: 1024
N = int(input())
S = input()
#print(S)
cnt = 1
S_list = [s for s in S]
#print(S_list)
for i in range(N):
    if S_list[N-1-i] != S_list[N-1-(i+1)] and N-1-(i+1)>=0:
        #S_list.insert(N-1-i,"|")
        cnt += 1
    #print(S_list)
print(cnt)

Measured memory_bytes: 4212
import itertools
n = int(input())
a = tuple(map(int, input().split()))
b = tuple(map(int, input().split()))
k = list(itertools.permutations(range(1,n+1), n))
ans_1 = 0
ans_2 = 0
for i in range(len(k)):
    if k[i] == a:
        ans_1 = i
    if k[i] == b:
        ans_2 = i
print(abs(ans_1 - ans_2))




Measured memory_bytes: 8052
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
using namespace std;
const int maxn = 3010;
int sum = 0;
int main(){
	int n;
	while(cin >> n){
		sum = 0;
		for(int i = 0;i < n;i++){
			int a;
			cin >> a;
			sum += a;
		}
		sum-=n;
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        int sum = 0;
        for(int i = 0; i < n; i++){
            sum += sc.nextInt() - 1;
        }
        
        System.out.println(sum);
        
    }
}


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

int main(){
  int N, i;
  cin >> N;
  vector<int> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  
  int sum = 1;
  int max = v[0];
  
  for(i = 1; i < N; i++){
    if(max <= v[i]){
      sum += 1;
      max = v[i];
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define ll long long
#define p pair<int, int>
using namespace std;

struct UnionFind {
    vector<int> par;
    int cnt;
    UnionFind(int n) : par(n, -1), cnt(n) {}
    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x != y) {
            if (par[y] < par[x]) swap(x, y);
            par[x] += par[y];
            par[y] = x;
            cnt--;
        }
    }
    int find(int x) { return par[x] < 0 ? x : par[x] = find(par[x]); }
    bool same(int x, int y) { return find(x) == find(y); }
    int size(int x) { return -par[find(x)]; }
    int size() { return cnt; }
};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    for (int i = 0; i < m; i++) {
        int x, y, z;
        cin >> x >> y >> z;
        x--;
        y--;
        uf.unite(x, y);
    }
    cout << uf.size() << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int ncr(int n){
  if(n>1){
    return n*(n-1)/2;
  }else{
    return 0;
  }
}
int main(){
  int N,M;
  cin >> N >> M;
  int o = ncr(N)+ncr(M);
  cout << o << std::endl;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int V, E;
vector< vector<int> > graph;
int color[100010];

Pi dfs(int u, int c) {
  Pi res(0, 0);
  color[u] = c;
  if(c == 1) res.first++;
  else res.second++;
  for(int v : graph[u]) {
    if(color[v] == c) return Pi(-1, -1);
    if(color[v] == 0) {
      Pi tmp = dfs(v, -c);
      if(tmp.first < 0) return Pi(-1, -1);
      res.first += tmp.first;
      res.second += tmp.second;
    }
  }
  return res;
}

map<int, int> mp;

int dp[100010]; // テ・ツ?凝ヲツ閉ーテ・ツ按カテゥツ卍静、ツサツ佚」ツ?催ゥツδィテ・ツ按?・ツ陳?テ」ツ??」ツ?湘」ツ?、テ」ツ?凝」ツ?ョテ・ツョツ古・ツ?ィテ、ツコツ古ゥツδィテ」ツつーテ」ツδゥテ」ツδ陛」ツつ津」ツ?湘」ツ?」テ」ツ?、テ」ツ?妥」ツ?ヲテ」ツつづ・ツョツ古・ツ?ィテ、ツコツ古ゥツδィテ」ツつーテ」ツδゥテ」ツδ陛」ツ?ォテ」ツ?ァテ」ツ?催」ツ?敕」ツ??」ツ?ェテ」ツ?ョテ」ツ?ァテ」ツ??」ツ??ヲツ?淌」ツ?佚」ツ?ォテ」ツ?湘」ツ?」テ」ツ?、テ」ツ?妥」ツ?淌」ツ??」ツ?づゥツサツ津」ツつ津」ツ?ゥテ」ツつ古」ツ??」ツ?妥・ツ「ツ療」ツつ?」ツ?崚」ツつ凝」ツ??

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

  cin >> V >> E;
  resz(graph, V);
  rep(i, E) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }

  mp.clear();
  memset(color, 0, sizeof(color));
  int v = 0; // テ、ツコツ古ゥツδィテ」ツつーテ」ツδゥテ」ツδ陛」ツ?ョテァツ可?ヲツ鳴ケテ」ツ?ァテ、ツスツ愿」ツつ古」ツつ凝ヲツ慊?・ツーツ湘」ツ?ョテゥツδィテ・ツ按?ゥツ崢?・ツ青暗」ツ?ョテ・ツ、ツァテ」ツ?催」ツ??
  rep(i, V) {
    if(color[i] != 0) continue;
    Pi p = dfs(i, 1);
    int a = min(p.first, p.second);
    int b = max(p.first, p.second);
    if(a < 0) {
      cout << -1 << endl;
      return 0;
    }
    mp[b-a]++;
    v += a;
  }

  memset(dp, -1, sizeof(dp));
  dp[0] = 0;
  for(auto p : mp) {
    int plus = p.first, num = p.second;
    rep(i, V+1) {
      if(dp[i] >= 0) dp[i] = num;
      else if(i < plus || dp[i-plus] <= 0) dp[i] = -1;
      else dp[i] = dp[i-plus]-1;
    }
  }
  int ans = 0;
  rep(i, V+1) if(dp[i] >= 0) chmax(ans, (v+i)*(V-v-i));
  cout << ans-E << endl;

  return 0;
}

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

long *tree[100001];

int main(void) {

  long n,m;
  scanf("%ld %ld", &n, &m);

	long tree_s[n+1];
	for (long i = 1; i <= n; i++) {
		tree_s[i] = 0;
	}
  long a,b;
  for (long i = 0; i < m; i++) {
    scanf("%ld %ld", &a, &b);
    tree[a] = realloc(tree[a], sizeof(long)*(tree_s[a]+2));
    tree[a][tree_s[a]] = b;
		tree_s[a]++;
		tree[b] = realloc(tree[b], sizeof(long)*(tree_s[b]+2));
    tree[b][tree_s[b]] = a;
		tree_s[b]++;
  }

  long vertices[n+1];
  for (long i = 1; i <= n; i++) {
    vertices[i] = -1;
  }
	vertices[1] = 0;

	long visited[n+1];
	visited[0] = 1;
	long head = 0;
	long tail = 0;
	long tmp_tail = 0;

  long cur;
	int flag;
  while (1) {
		flag = 0;
    for (long i = head; i <= tail; i++) {
			cur = visited[i];
    	for (long j = 0; j <= tree_s[cur]-1; j++) {
				if (vertices[tree[cur][j]] != -1) {
					continue;
				}
				vertices[tree[cur][j]] = cur;
				tmp_tail++;
				visited[tmp_tail] = tree[cur][j];
				flag = 1;
    	}
    }
		if (flag == 0) {
			break;
		}
		head = tail+1;
		tail = tmp_tail;
  }

	printf("Yes\n");

  for (long i = 2; i <= n; i++) {
  	printf("%ld\n", vertices[i]);
  }

  return 0;
}

Measured memory_bytes: 14208
N=int(input())
dic={}
Mcount=1
for i in range(N):
    tmp=input()
    if tmp in dic:
        dic[tmp]+=1
        if Mcount<dic[tmp]:
            Mcount=dic[tmp]
    else:    
        dic[tmp]=1
a = sorted(dic.items(), key=lambda x: x[0])

keys = [k for k, v in dic.items() if v == Mcount]
keys.sort()
for i in keys:
    print(i)
# ['key1', 'key2']
# ['key1', 'key2']

Measured memory_bytes: 47036
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }

ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

template<class T> ostream& operator<<(ostream& os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template <typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
	const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x)	x.begin(),x.end()

const int mod=1e9+7;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

struct compare{
	bool operator() (const int &a,const int &b) const{
		return a>b;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int n;
	cin >> n;
	vi ans(n + 1);
	for(int i = 2; i <= n; i++){
		int p;
		cin >> p;
		ans[p]++;
	}
	for(int i = 1; i <= n; i++)
		cout << ans[i] << endl;
}

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

using namespace std;

typedef long long int ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int arr[200010], arr2[200010], n;
    
    cin >> n;
    for(int i = 0; i < n; i++){
    	cin >> arr[i];
    	arr2[i] = arr[i];
	}
    
    sort(arr, arr + n);
    
    for(int i = 0; i < n; i++){
    	if(arr2[i] == arr[n - 1]){
    		cout << arr[n - 2] << endl;
		}	
		else{
			cout << arr[n - 1] << endl;
		}
	}
    
    return 0;
}



Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  //入力
  int N;
  cin >> N ;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i) ;
  }  
  
  //出力
  int now = 0 ;
  int count = 0;
  for  (int i = 0; i < N; i++) {
    now = A.at(now) - 1 ;
    count++;
    if (now == 1){  //２番目のボタンなら
      cout << count << endl;
      break;
    }
    if (count >= N){  //N回回してもダメだったら
      cout << -1 << endl;
      break;
    }
  }
}
      
    

Measured memory_bytes: 640
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		long r=0;
		for(String t:s.next().replaceAll("BC","#").split("[BC]+")) {
			long c=0;
			for(int i=t.length()-1;i>=0;--i) {
				if(t.charAt(i)=='#')
					++c;
				else
					r+=c;
			}
		}
		System.out.println(r);
	}
}


Measured memory_bytes: 33932
#include<bits/stdc++.h>
using namespace std;
int a[1000000];
int dp[1000000];
int n;
long foo(int ai)
{
    if(ai>=n)
    return INT_MAX;
    if(ai==n-1)
    return 0;
    if(dp[ai]!=-1)
    return dp[ai];
    return dp[ai]=min(abs(a[ai]-a[ai+1])+foo(ai+1),abs(a[ai]-a[ai+2])+foo(ai+2));
}
int main()
{
	memset(dp,-1,sizeof(dp));
    cin>>n;
    for(int i=0;i<n;i++)
    cin>>a[i];
    cout<<foo(0);
}

Measured memory_bytes: 7936
#include<iostream>
#include<algorithm>
using namespace std;
long long gcd(long a, long b)
{
	return a % b == 0 ? b : gcd(b, a%b);
}
int main()
{
	ios::sync_with_stdio(false);cin.tie(0); cout.tie(0);
	long m;
	while (cin >> m) {
		long long sum = gcd(2, m);
		cout << m * 2 / sum << endl;
	}
	return 0;
}

Measured memory_bytes: 256