akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    vector<int> x(n), y(n);
    vector<char> d(n);
    For(i, n){
        cin >> x[i] >> y[i] >> d[i];
    }

    constexpr ll Inf = 1e18;
    
    auto f = [&](double t){
        double xmin = 1e17, xmax = -1e17;
        double ymin = 1e17, ymax = -1e17;
        For(i, n){
            double x0 = x[i] + t*(d[i] == 'R' ? 1 : d[i] == 'L' ? -1 : 0);
            double y0 = y[i] + t*(d[i] == 'U' ? 1 : d[i] == 'D' ? -1 : 0);
            Mini(xmin, x0);
            Maxi(xmax, x0);
            Mini(ymin, y0);
            Maxi(ymax, y0);
        }
        return (double)((xmax - xmin > 1e9 || ymax - ymin > 1e9) ? Inf : (xmax - xmin)*(ymax - ymin));
    };
    
    ll lb = 0, ub = 1e15;
    while(abs(ub - lb) > 3){
        ll m1 = (2*lb+ub) / 3;
        ll m2 = (lb+2*ub) / 3;
        ll fm1 = f(m1), fm2 = f(m2);
        if(fm2 == Inf || fm1 <= fm2) ub = m2;
        else lb = m1;
        //printf("f(%lld) = %lld, f(%lld) = %lld\n", m1, fm1, m2, fm2);
    }
    
    double ans = Inf;
    for(double t = max(lb - 0.5, 0.0); t < ub + 0.5 + 0.25; t += 0.5){
        Mini(ans, f(t));
        //printf("f(%.1f) = %.3f\n", t, f(t));
    }
    printf("%.3f\n", ans);
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 10000000;
static const ll MOD = 1000000007;

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

int main(){
	int n, k;
	cin >> n >> k;
	int count = 0;
	rep(i, n){
		int h;
		cin >> h;
		if(k <= h) count++;
	}
	cout << count << endl;
	return 0;
}



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

using namespace std;

#define lint long long

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


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

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> l(m);
    vector<int> r(m);
    int l_max = 0, r_min = 1e6;
    rep(i, m){
        cin >> l[i] >> r[i];
        l_max = max(l_max, l[i]);
        r_min = min(r_min, r[i]);
    }
    int ans = r_min - l_max + 1;
    if(ans > 0) cout << ans << endl;
    else        cout << 0 << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

ll mod=1e9+7;

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m,mod=1e9+7,ans=0,tmp;cin>>n>>m;
  lvector fact(m+1,1),inv(m+1,1);
  for(ll i=1;i<=m;++i) fact[i]=(fact[i-1]*i)%mod;
  inv[m]=modinv(fact[m]);
  for(ll i=m;i>0;--i) inv[i-1]=(inv[i]*i)%mod;
  rep(i,n+1) {
    tmp=(fact[n]*inv[i])%mod;
    tmp*=inv[n-i];tmp%=mod;
    tmp*=(fact[m]*inv[m-n])%mod;tmp%=mod;
    tmp*=(fact[m-i]*inv[m-n])%mod;tmp%=mod;
    if(i&1) tmp=-tmp;
    ans+=tmp;
    while(ans<0) ans+=mod;
    ans%=mod;
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 11116
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
ll INF = 1LL << 50;

void solve(long long N, long long M, long long R, std::vector<long long> r, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C){
    vector<vll > d(N, vll(N, INF));
    rep(i, N){
        d[i][i] = 0;
    }
    rep(i, M){
        d[A[i]-1][B[i]-1] = C[i];
        d[B[i]-1][A[i]-1] = C[i];
    }
    rep(k, N){
        rep(i, N){
            rep(j, N){
                d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
            }
        }
    }
    ll ans = INF;
    rep(i, r.size())
        r[i] -= 1;
    sort(r.begin(), r.end());
    do{
        ll tmp = 0;
        rep(i, r.size()-1){
            tmp += d[r[i]][r[i+1]];
        }
        ans = min(ans, tmp);
    } while(next_permutation(r.begin(), r.end()));
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    long long R;
    scanf("%lld",&R);
    std::vector<long long> r(R);
    for(int i = 0 ; i < R ; i++){
        scanf("%lld",&r[i]);
    }
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    std::vector<long long> C(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
        scanf("%lld",&C[i]);
    }
    solve(N, M, R, std::move(r), std::move(A), std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef long long ll;

using namespace std;

int main(int argc, const char * argv[]) {
    ll N;
  	ll i,j,k;
  	cin >> N;
  	ll first_max = 0;
  	ll second_max = 0;
  	vector<ll> A(N);
  	for(i=0;i<N;i++){
      	cin >> A[i];
      	if(A[i]>first_max){
          	second_max = first_max;
          	first_max = A[i];
        }else if(A[i] > second_max){
          	second_max = A[i];
        }
    }
  	if(first_max==second_max){
      for(i=0;i<N;i++){
        cout << first_max << endl;
      }
    }else{
      for(i=0;i<N;i++){
        if(A[i] == first_max){
          cout << second_max << endl;
        }else{
          cout << first_max << endl;
        }
      }
    }
    
    return 0;
}

Measured memory_bytes: 3200
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const P p1, const P p2){ return p1.first < p2.first;};
bool p_comp_fg(const P p1, const P p2){ return p1.first > p2.first;};
bool p_comp_ss(const P p1, const P p2){ return p1.second < p2.second;};
bool p_comp_sg(const P p1, const P p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ll N, K; cin >> N >> K;
    vl as(N, 0); REP(i, N){
        cin >> as[i];
    }
    
    vvl dp(43, vl(2, -(1LL << 60))); dp[42][0] = 0;
    for (ll i = 41; i >= 0; i--) {
        ll c = 0;
        REP(j, N) if(as[j] >> i & 1) c++;
        ll tmp_o = (N - c) * (1LL << i); ll tmp_z = c * (1LL << i);
        if((K >> i) & 1){
            dp[i][0] = max(dp[i][0], dp[i+1][0] + tmp_o);
            dp[i][1] = max(dp[i][1], dp[i+1][0] + tmp_z);
        }
        else{
            dp[i][0] = max(dp[i][0], dp[i+1][0] + tmp_z);
        }
        dp[i][1] = max(dp[i][1], dp[i+1][1] + max(tmp_z, tmp_o));
    }
    cout << max(dp[0][0], dp[0][1]) << endstr;
    return 0;
}


Measured memory_bytes: 1152
import java.util.*;
import java.util.stream.Stream;

public class Main{
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.nextLine());
        int[] a = Stream.of(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        
        boolean allneg = true;
        for(int i=0; i<n; i++){
            if(a[i]>=0) allneg = false;
        }
        
        ArrayList<Integer> ans = new ArrayList<>();
        long max = -10_000_000_000_000L;
        
        if(!allneg){
            boolean[][] mi = new boolean[2][n/2+1];
            long[] scr = new long[2];
            for(int i=0; i<2; i++){
                for(int j=i; j<n; j+=2){
                    if(a[j]<0){
                        mi[i][j/2] = true;
                    }else{
                        scr[i] += a[j];
                    }
                }
            }
            int idx = (scr[0] > scr[1])? 0:1;
            max = scr[idx];
            //
            int size = n;
            
            if(idx==1){
                ans.add(1);
                size -= 1;
            }
            
            if(size%2==0){
                ans.add(size);
                size -= 1;
            }
            
            for(int i=n/2; i>=0; i--){
                if(mi[idx][i]){
                    int t = i*2+1;
                    ans.add(t);
                    if(t == 1){
                        ans.add(t);
                    }else if(t == size){
                        ans.add(t-1);
                    }
                    size -= 2;
                }
            }
            
            while(size>1){
                ans.add(2);
                size -= 2;
            }
        }else{
            int idx = 0;
            for(int i=0; i<n; i++){
                if(a[i] > max){
                    max = a[i];
                    idx = i;
                }
            }
            for(int i=0; i<idx; i++){
                ans.add(1);
            }
            for(int i=n-idx; i>1; i--){
                ans.add(i);
            }
        }
        
        System.out.println(max);
        System.out.println(ans.size());
        for(int i=0; i<ans.size(); i++){
            System.out.println(ans.get(i));
        }
    }
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  if (K == 1) {
    cout << 0 << '\n';
  } else {
    cout << N - K << '\n';
  }
  return 0;
}


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

const int MOD = 1000000007;

const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

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

    bool flag = true;
    int size = S.size();
    rep(i, size)
    {
        char c = S.at(i);
        if (i % 2 == 1) {
            if (c == 'R') {
                flag = false;
                break;
            }
        } else {
            if (c == 'L') {
                flag = false;
                break;
            }
        }
    }

    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<queue>
using namespace std;
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> A(N), B(M), C(M);
  priority_queue<pair<int, int>> q;
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  for(int i=0;i<M;i++){
    cin >> B.at(i) >> C.at(i);
  }
  for(int i=0;i<N;i++){
    q.push(make_pair(A.at(i), 1));
  }
  for(int i=0;i<M;i++){
    q.push(make_pair(C.at(i), B.at(i)));
  }
  long long sum =0;
  for(int i=0;i<N;i++){
    auto p = q.top();
    q.pop();
    sum += p.first;
    if(p.second > 1){
      p.second --;
      q.push(p);
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3572
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=1e9+7,MAX=1e6+1;

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n;
    cin>>n;
    int res=1;
    if(n%2==0||n%5==0)
        return cout<<-1,0;
    int x=7%n;
    while(x!=0){
        x=(((x%n)*(10%n))%n+7%n)%n;
        res++;
    }
    cout<<res;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

int main () {
    ios::sync_with_stdio(0), cin.tie(0);
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = 0;
    ll cnt = n / (a + b);
    ans += cnt * a;
    n %= (a + b);
    if (n >= a) ans += a;
    else ans += n;
    cout << ans;
    return (0);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdint.h>

#define SQ(X) \
  ( (X) * (X) )
#define REDUCE(N,D) \
  { const int G__19 = gcd ( N, D ); \
    (N) /= G__19; (D) /= G__19; \
  }

#if 0
static int
sqrt2 (
  uint64_t a
  )
{
  uint64_t res = a;

  while ( a < SQ( res ) || a >= SQ( res + 1 ) )
  {
    res = ( SQ( res ) + a ) / 2 / res;
  }

  return ( res );
}
#endif

static int
sqrt3 (
  uint64_t a,
  uint64_t w
  )
{
  uint64_t res = a * w;

  a *= SQ( w );
  while ( a < SQ( res ) || a >= SQ( res + 1 ) )
  {
    res = ( SQ( res ) + a ) / 2 / res;
  }

  return ( res );
}

static int
gcd (
  int a,
  int b
  )
{
  do
  {
    const int t = a;
    a = b % a;
    b = t;
  }
  while ( a );

  return ( b );
}

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    int ln = 0,     ld = 1
      , un = 10000, ud = 1;
    int p, n;

    scanf ( "%d%d", &p, &n );
    if ( !( p | n ) ) break ;

    for ( i = 1; i <= n; ++i )
    {
      int t = sqrt3 ( p, i );

      if ( t > n ) continue ;

      if ( t * ld > ln * i )
        { ln = t; ld = i; }
      if ( t < n && ( t + 1 ) * ud < un * i )
        { un = t + 1; ud = i; }
    }

    REDUCE( ln, ld ); REDUCE( un, ud );
    printf ( "%d/%d %d/%d\n", un, ud, ln, ld );
  }

  return ( 0 );
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	int a,b,c,d,e,f,k,l,m,n,x,y,z;
	int ans;
	String[] S;

	Main(){
		// 整数の入力
		n = sc.nextInt();
		d = sc.nextInt();
		double[][] X = new double[n][d];

		ans = 0;

		for(int i=0;i<n;i++){
			for(int j=0;j<d;j++){
				X[i][j]=sc.nextDouble();
			}
		}

		for(int i=0;i<n-1;i++){
			for(int i2=i+1;i2<n;i2++){
				double sum = 0;
				for(int j=0;j<d;j++){
					sum += Math.pow(X[i][j]-X[i2][j],2);
				}
				ans += intCheck(sum)?1:0;
			}
		}

		// 出力
		System.out.println(ans);
	}

	boolean intCheck(double d){
      		double dd = Math.sqrt(d);
		return (dd-(double)((int)dd))==0?true:false;
	}

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

Measured memory_bytes: 23252
#include <stdio.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    int b,i,j,f,r,v,n,fl[10][12] = {{}};
    
    cin >>n;
    for(i = 0;i < n;i++){
        cin >>b>>f>>r>>v;
        fl[r-1][(b*3-1)+(f-3)] += v;
    }
    for(i = 0;i < 12;i++){
        for(j = 0;j < 10;j++){
            printf(" %d",fl[j][i]);
        }
        printf("\n");
        if((i+1)%3 == 0 && i != 11){
            printf("####################\n");
        }
    }
    
    
    return 0;
}



Measured memory_bytes: 3216
import math
import sys
H,W = map(int,input().split())
#print(H,W)
if(H == 1 or W == 1):
    print(1)
    sys.exit()

set_num = int(H/2)
#print(set_num)
number = int(set_num * W)
#print(number ,set_num)
amari = H - int(set_num) * 2
#print(number,amari)
number += amari * math.ceil(W/2)
print(int(number))

Measured memory_bytes: 3064
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}
int ctoi(char c){
  if(c>='0'&&c<='9'){
    return c-'0';
  }
  return 0;
}


//cout << setprecision(123)<<ans;
//int a=atoi(S.c_str());
//string S=to_string(a);
//int &a=b;
int main(){
  string S;
  cin>>S;
  int N=S.size(),ans=0;
  if(N%2==1){
    for(int i=0;i<N/2;i++){
      if(S[i]!=S[N-1-i])ans++;
    }
  }
  else{
    for(int i=0;i<N/2;i++){
      if(S[i]!=S[N-1-i])ans++;
    }
  }
  cout<<ans<<endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];

    sort(V.rbegin(), V.rend());
    ll ans = V[0] - V[N-1];
    queue<int> pvec,mvec;
    pvec.push(V[0]);
    mvec.push(V[N-1]);
    rep(i,1,N-1){
        ans += abs(V[i]);
        if(V[i] >= 0)pvec.push(V[i]);
        else mvec.push(V[i]);
    }
    
    cout << ans << endl;
    ll sum = mvec.front();
    mvec.pop();
    while(pvec.size() > 1){
        cout << sum << " " << pvec.front() << endl;
        sum -= pvec.front();
        pvec.pop();
    }
    cout << pvec.front() << " " << sum << endl;
    sum = pvec.front() - sum;
    while(!mvec.empty()){
        cout << sum << " " << mvec.front() << endl;
        sum -= mvec.front();
        mvec.pop();
    }
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int main(){
	getline(cin,s1);
	s2=s1;
	reverse(s2.begin(),s2.end());
	for(int i=0;i<s2.size();++i)
		s2[i]=='b'?s2[i]='d':s2[i]=='d'?s2[i]='b':s2[i]=='p'?s2[i]='q':s2[i]='p';
	if(s1==s2)	puts("Yes");
	else	puts("No");
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;



int main()
{
    int a,b,c;
    cin>>a;
    if(a==1)
        printf("Hello World\n");
    else
    {
        cin>>b>>c;
        printf("%d\n",b+c);
    }



    return 0;
}



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

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0;i<n;i++)
	{
		cin >> a[i];
		a[i]--;
	}

	int cnt = 0;
	for(int i = 0 ;i<n;i++)if(i==a[a[i]])cnt++;
	cout<<cnt/2<<endl;
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<math.h>
using ll = long long;
using namespace std;
const ll M = 1000000007;
int main(){
    int n; cin >> n;
    ll luca[87];
    luca[0] = 2; luca[1] = 1;
    if(n == 1) cout << 1 << endl;
    else {
        for(int i = 2; i <= n; i++){
            luca[i] = luca[i-1] + luca[i-2];
        }
        cout << luca[n] << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
        int i, j, k, h[10000], w[10000], sum=0;
        for(k=0;k<10000;k++){
                scanf("%d %d", &h[k], &w[k]);
                if(h[k]==0 && w[k]==0)
                        break;
                sum++;
        }
        for(k=0;k<sum;k++){
                for(i=0;i<h[k];i++){
                        for(j=0;j<w[k];j++){
                                if(i!=0 && i!=h[k]-1 && j!=0 && j!=w[k]-1)
                                        putchar('.');
                                else
                                        putchar('#');
                        }
                        putchar('\n');
                }
                putchar('\n');
        }
        return 0;
}


Measured memory_bytes: 2032
#include<stdio.h>
int main(void)
{
    int cnt,max=0,i;
    char str[10];
    scanf("%s",str);
    cnt=0;
    for(i=0;i<3;i++){
        if(str[i]=='R') cnt++;
        else{
            if(max<cnt) max=cnt;
            cnt=0;
        }
    }
    if(max<cnt) max=cnt;
    printf("%d\n",max);
    return 0;
}

Measured memory_bytes: 1724
class Game
  def initialize
    @card_num = 0
    @a_cards = []
    @b_cards = []
    @a_total = 0
    @b_total = 0
  end

  def input card_num
    @card_num = card_num
    card_num.times do
      a,b = gets.chomp.split(' ').map{|x|x.to_i}
      @a_cards << a
      @b_cards << b
    end
  end

  def exec
    @card_num.times do |idx|
      if @a_cards[idx] > @b_cards[idx]
        @a_total = @a_total + @a_cards[idx] + @b_cards[idx]
      elsif @a_cards[idx] < @b_cards[idx]
        @b_total = @b_total + @a_cards[idx] + @b_cards[idx]
      else
        @a_total += @a_cards[idx]
        @b_total += @b_cards[idx]
      end
    end
  end

  def print
    puts "#{@a_total} #{@b_total}"
  end
end

class AllGame
  def initialize
    @game_num = 0
    @games = []
  end

  def input
    loop do
      card_num = gets.chomp.to_i
      return @game_num if card_num == 0
      game = Game.new
      game.input card_num
      @games << game
      @game_num += 1
    end
  end

  def exec
    @games.each do |game|
      game.exec
    end
  end

  def print
    @games.each do |game|
      game.print
    end
  end
end

all_game = AllGame.new
all_game.input
all_game.exec
all_game.print

Measured memory_bytes: 6576
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

#define rep(i, n) for(int i=0; i<(n); ++i)
#define max  2000001
#define mod 1000000007

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
    
    int n;
    int l[max];
    int cnt=0;
    
    scanf("%d", &n);
    rep(i, n){
        scanf("%d", &l[i]);
    }
    
    rep(i, n){
        for (int j=0; j<i; j++) {
            for (int k=0; k<j; k++) {
                if (l[i]+l[j]>l[k]&&l[j]+l[k]>l[i]&&l[k]+l[i]>l[j]&&l[i]!=l[j]&&l[i]!=l[k]&&l[j]!=l[k]) {
                    cnt++;
                }
            }
        }
    }
    
    printf("%d", cnt);
    
    return 0;
}


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

// 
int main() {
    int N;
    cin >> N;
    int D[N][2];
    for (int i = 0; i < N; i++) {
        cin >> D[i][0];
        cin >> D[i][1];
    }

    for (int i = 0; i < N - 2; i++) {
        if (D[i][0] == D[i][1] && D[i + 1][0] == D[i + 1][1] && D[i + 2][0] == D[i + 2][1]) {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}


Measured memory_bytes: 3636
#include<iostream>
#include<math.h>
using namespace std;
int a[11][11];
int main()
{
	int n, d, i, j, k, s, sum = 0;
	scanf("%d%d", &n, &d);
	for (i = 0; i < n; i++)
		for (j = 0; j < d; j++)
			scanf("%d", &a[i][j]);
	for (i = 0; i < n - 1; i++)
		for (j = i + 1; j < n; j++)
		{
			s = 0;
			for (k = 0; k < d; k++)
				s += pow(a[i][k] - a[j][k], 2);
			if (s == pow(int(sqrt(s)), 2))
				sum++;
		}
	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

ans = ""
N = int(input())
while N > 0:
    tmp = N % 26
    if tmp == 0:
        ans += chr(26+96)
        if N == 26:
            break
        N //= 26
        N -= 1
        
    else:    
        ans += chr(tmp+96)
        N //= 26

print(ans[::-1])

Measured memory_bytes: 61524
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

N = read()
a = reads()

b = [(-a[i], i) for i in range(N)]
b.sort()
b.append((0, -1))
# print(b)

result = [0] * N

m = b[0][1]
j = 0
for i in range(1, N+1):
  if b[j][0] != b[i][0]:
    # print(j, i, (b[i][0] - b[j][0]))
    result[m] += (b[i][0] - b[j][0]) * i
    j = i
  m = min(m, b[i][1])

# print(" ".join(str(k) for k in result))
for i in range(N):
  print(result[i])


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

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

  if(s=="SUN") res=7;
  if(s=="MON") res=6;
  if(s=="TUE") res=5;
  if(s=="WED") res=4;
  if(s=="THU") res=3;
  if(s=="FRI") res=2;
  if(s=="SAT") res=1;
  
  cout << res << endl;
}

Measured memory_bytes: 256
use std::env;
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let A = read::<i32>();
    let B = read::<i32>();

    println!("{}", (A+B)%24);
}


Measured memory_bytes: 4352
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main(void){
    ll n, d;
    cin >> n >> d;
    int ans = 0;
    REP(i,n){
        ll x = in(), y = in();
        ans += (x * x + y * y <= d * d);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int D,N;

    cin >> D >> N;
    if(D == 0){
        if(N == 100){
            cout << 101 << endl;
        }
        else{
            cout << N << endl;
        }
    }
    else if(D == 1){
        if(N == 100){
            cout << 10100 << endl;
        }
        else{
            cout << N*100 << endl;
        }
    }
    else{
        if(N == 100){
            cout << 1010000 << endl;
        }
        else{
            cout << N*10000 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
def judge():
    global num, a, b, c, d, q
    point = 0
    for i in range(q):
        if (num[b[i]] - num[a[i]] == c[i]):
            point += d[i]
    return point


def mk_num(i):
    global mx_p
    global m
    for j in range(num[i-1], m):
        num[i] = j
        if (i == n):
            tmp = judge()
            if (mx_p < tmp):
                mx_p = tmp
        else:
            mk_num(i+1)


n, m, q = map(int, input().split())
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q

for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

num = [0] * (n+1)
mx_p = 0

mk_num(1)
print(mx_p)


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

using namespace std;

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

typedef long long ll;
ll mod=998244353;

int main()
{
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	a--;
	b--;
	c--;
	d--;
	string s;
	cin >> s;
	bool muri=false;
	for(int i=a; i<c; i++)
	{
		if(s[i]=='#' && s[i+1]=='#') muri=true;
	}
	for(int i=b; i<d; i++)
	{
		if(s[i]=='#' && s[i+1]=='#') muri=true;
	}
	if(d<c)
	{
		bool tmp=true;
		for(int i=b-1; i<=d-1; i++)
		{
			if(s[i]=='.' && s[i+1]=='.' && s[i+2]=='.') tmp=false;
		}
		if(tmp) muri=true;
	}
	if(muri) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 640
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

H, W = 100, 100

def main():
    a, b = rli()
    grid = [['#' if j < H//2 else '.' for _ in range(W)] for j in range(H)]
    for i in range(a-1):
        x = i*2 % W
        y = (i*2 // W)*2
        grid[y][x] = '.'
    for i in range(b-1):
        x = i*2 % W
        y = 2*(i*2 // W)+H//2+1
        grid[y][x] = '#'
    print(H, W)
    for col in grid:
        print("".join(col))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
number=int(input().rstrip())
A,B=input().rstrip().split()
score=input().rstrip().split()
score=list(map(int,score))

score.append(int(A)+1)
score.append(int(B)+1)
score.sort()
n1=score.index(int(A)+1)
n2=score.index(int(B)+1)-score.index(int(A)+1)-1
n3=number-score.index(int(B)+1)+1
#print(n1)
#print(n2)
#print(n3)
#print(score)
print(min(n1,n2,n3))

Measured memory_bytes: 3064
#include <stdio.h>

typedef long long ll;

ll MOD = 1000000007ll;

ll combination(ll n,ll r);
void calc();

ll fact[200050];

int main() {

	calc();

	ll H, W, A, B;

	scanf("%lld %lld %lld %lld",&H,&W,&A,&B);

	ll i;

	ll ans = 0;

	for (i = 0; i <= H - A - 1; i++) {
		ll a = combination(B+i-1,i);
		a *= combination(H - 1 - i + W - 1 - B, W - 1 - B);
		a %= MOD;
		ans += a;
		ans %= MOD;
	}
	printf("%lld\n",ans);

	return 0;
}
ll mod_pow(ll a, ll n) {
	ll s;
	if (n == 0) { return 1; }
	if (n == 1) { return (a%MOD); }
	s = mod_pow(a, n / 2);
	if (n % 2 == 0) {
		return (s*s) % MOD;
	}
	else {

		ll r = a;

		r *= s;
		r %= MOD;

		r *= s;
		r %= MOD;

		return r;
	}
}
ll combination(ll n, ll r) {

	ll ret = fact[n];

	ret *= mod_pow(fact[r], MOD - 2);
	ret %= MOD;

	ret *= mod_pow(fact[n-r], MOD - 2);
	ret %= MOD;

	return ret;

}
void calc() {

	ll i;

	ll r = 1;

	fact[0] = 1;

	for (i = 1; i <= 200010; i++) {
		r *= i;
		r %= MOD;
		fact[i] = r;
	}

}

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

int main()
{
    int A,B;
    scanf("%d %d",&A,&B);
    if((A+B)%3==0||A%3==0||B%3==0)
        printf("Possible\n");
    else
        printf("Impossible\n");
    return 0;
}


Measured memory_bytes: 128
/* 
 * Project: AtCoder Beginners Contest 141 B - Tap Dance
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/08/20
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstdint>
#include <cstring>
using namespace std;

char s[100];

void solve() {

    uint32_t length = strlen(s);
    for (int i=0;i<length;i++) {
        if ((i+1)&1) {
            if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
                printf("No\n");
                return;
            }
        } else {
            if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
                printf("No\n");
                return;
            }
        }
    }
    printf("Yes\n");

}

int main() {

    scanf("%s", s);

    solve();

}

Measured memory_bytes: 3164
N = int(input())
H = [ii for ii in map(int, input().split())]

count_ans = 1
tmp = H[0]
for ii in range(1,len(H)):
    if tmp < H[ii]:
        tmp = H[ii]
        count_ans += 1
    elif tmp == H[ii]:
        count_ans += 1

print(count_ans)

Measured memory_bytes: 3064
"use strict"

function main(input) {
  let dataList = input.split("\n");
  dataList.shift();
  dataList.pop();
  let items = dataList.map((data, index) => {
    const tmp = data.split(" ")
    return { index: index + 1, city: tmp[0], point: parseInt(tmp[1]) }
  });
  items.sort(function(a, b) {
    if (a.city < b.city) return -1
    if (a.city > b.city) return 1
    if (a.point < b.point) return 1
    if (a.point > b.point) return -1
  })
  items.forEach(item => {
    console.log(item.index);
  })
} 

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

Measured memory_bytes: 7500
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位


int main(void) {
    ll n, k;
    cin >> n >> k;
    vector<ll> c(n+1, 0);
    vector<ll> ok(n+1, 0);
    for(ll i = 1; i <= n; i++){
        ll b;
        cin >> b;
        c[i] = b;
    }
    ll next = 1;
    vector<ll> s;
    s.push_back(0);
    for(ll i = 1; i <= 210000; i++){
        ll b = c[next];
        next = b;
        s.push_back(b);
    }
   // for(ll i = 1; i <= 20; i++)
     //   cout << s[i] << endl;
    ll x = 0, y = 0;
    for(ll i = 1; i <= 200000; i++){
        ll b = s[i];
        if(ok[b]==0)
            ok[b] = i;
        else {
            x = ok[b];
            y = i;
            break;
        }
    }

    ll a = (k-x+1)%(y-x);
   // cout << x << " " << y << " " << a << endl;
    if(k<x)
        cout << s[k] << endl;
    else {
        if(a==0)
            cout << s[y-1] << endl;
        else
            cout << s[x+a-1] << endl;
    }
    return 0;
}


Measured memory_bytes: 8492
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import sys


n = int(input())
p = list(map(float, sys.stdin.readline().rstrip().split()))

dp = [0.0] * (n+1)
dp[0] = 1

for i in range(n):
  for j in range(i, -1, -1):
    dp[j+1] = dp[j]*p[i] + dp[j+1]*(1-p[i])
  dp[0] = dp[0] * (1-p[i])
print(sum(dp[n//2+1:]))

Measured memory_bytes: 41452
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner x = new Scanner(System.in);
        int s = x.nextInt();
        int prime = 0;
        for(int i=0;i<s;i++){
            if(Prime(x.nextInt())){
                prime++;
            }
        }
        System.out.println(prime);
    }
    public static boolean Prime(int p){
        boolean P =true;
        if(p<2){
            return false;
        }else{
            for(int i=2;i<=Math.sqrt(p);i++){
                if(p%i==0){
                    P = false;
                    break;
                }
            }
        }
        return P;
    }
}


Measured memory_bytes: 41140
while True:
    table = input().split()

    a = int(table[0])
    op = table[1]
    b = int(table[2])

    if op == '?':
        break

    if op == "+":
        print(a+b)
    elif op == "-":
        print(a-b)
    elif op == '/':
        print("%d"%(a/b))
    else:
        print("%d"%(a*b))


Measured memory_bytes: 5592
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        N: usize,
        M: usize,
        As: [String; N],
        Bs: [String; M],
    }

    for h in 0..N - M + 1 {
        for w in 0..N - M + 1 {
            let mut is_ok = true;
            for i in 0..M {
                if &As[h + i][w..w + M] != &Bs[i] {
                    is_ok = false;
                }
            }

            if is_ok {
                println!("Yes");
                return;
            }
        }
    }

    println!("No");
}


Measured memory_bytes: 2204
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define LEN(x) (int)x.size()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
using namespace std;
typedef int64_t i64;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;

signed main()
{
  int N; cin >> N;
  vector<int> a(N);
  for(int i = 0; i < N; ++i) {
    cin >> a[i];
  }

  sort(ALL(a));
  a.erase(unique(ALL(a)), a.end());

  cout << a.size() << endl;

  return 0;
}



Measured memory_bytes: 256
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>
#include<limits>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int n;
    cin>>n;
    VI h(n);
    rep(i,n) cin>>h[i];

    bool flag=true;
    for(int i=n-1;i>0;i--){
        if(h[i]<h[i-1]){
            if(h[i-1]-h[i]==1) h[i-1]--;
            else flag=false;
        }
    }

    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()

struct UnionFind {
  vector<int> par;
  vector<int> sizes;

  UnionFind(int N) : par(N), sizes(N, 1) {
    for(int i = 0; i < N; i++) par.at(i) = i;
  }

  int find(int x) { 
    if (par.at(x) == x) return x;
    return par.at(x) = find(par.at(x));
  }

  void unite(int x, int y) {
    int rx = find(x); 
    int ry = find(y); 
    if (rx == ry) return; 
    if (sizes.at(rx) < sizes.at(ry)) swap(rx,ry);
    par.at(ry) = rx;
    sizes.at(rx) += sizes.at(ry);    
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  int size(int x){
    return sizes.at(find(x));
  }

  int num_of_connected_components(){
    int ret = 0;
    for(int i = 0; i < par.size(); i++){
      if(find(i) == i) ret++;
    }
    return ret;
  }
};

int main(){
  ll n,m; cin >> n >> m;
  UnionFind uft(n);
  vector<ll> p(n), q(n);
  // p[q[i]]=i
  REP(i,n){
    cin >> p[i];
    --p[i];
    q[p[i]] = i;
  }
  REP(i,m){
    ll x,y; cin >> x >> y;
    x--; y--;
    uft.unite(x,y);
  }
  ll ans = 0;
  REP(i,n){
    if(p[i]==i) ans++;
    else if(uft.same(i,q[i])) ans++;
  }
  cout << ans << endl;
}



Measured memory_bytes: 2560
#include <stdio.h>
int main () {
  int N;
  int A[21] = {0};
  int B[51] = {0};
  int C[51] = {0};
  int i;
  int n;
  int ans = 0;

  //入力
  scanf ("%d", &N);

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

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

  for (i = 0; i < N - 1; i++) {
    scanf ("%d", &C[i]);
  }

  //計算
  for (i = 0; i < N; i++) {
    n = A[i];
    ans += B[n - 1];

    if (A [i + 1] - A[i] == 1) {
      ans += C[n - 1];
    }
  }

  printf ("%d\n", ans);


  return 0;
}

Measured memory_bytes: 128
"use strict";
process.stdin.resume();
process.stdin.setEncoding('utf8');

var lines = []
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});

reader.on('line', (line) => {
  lines.push(line);
});

var re = /\s+|$/;
reader.on('close', () => {
    var line = lines.shift();
    const s = line;
    let n = parseInt(lines.shift());
    let cmds = [];
    for (var i=0; i<n; i++) {
	cmds.push(lines.shift().split(/\s/));
    }
    aux(s,cmds);
    //console.log(aux(a,b,c));
});

function aux(s,cmds)
{
    while (cmds.length>0) {
	let cmd = cmds.shift();
	let op = cmd[0];
	let a = parseInt(cmd[1]);
	let b = parseInt(cmd[2]);
	let p = cmd[3];
	let len =s.length;
	//console.log('s: ',s);
	if (op === "print") {
	    console.log(s.slice(a,b+1));
	} else if (op === "reverse") {
	    s = s.slice(0,a) + s.slice(a,b+1).split('').reverse().join('') + s.slice(b+1,len);
	} else if (op === "replace") {
	    s = s.slice(0,a) + p + s.slice(b+1,len);
	} else {
	    console.log("no such command: "+op);
        }
    }

    return(s);
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll x,n;
    cin >> x >> n;
    set<ll> p;
    for(i = 0;i < n;++i){
        ll tmp;
        cin >> tmp;
        p.insert(tmp);
    }
    ll tmp = -1e9;
    for(i = -200;i <= 200;++i){
        if(p.count(i)) continue;
        if(abs(x - i) < abs(x - tmp)){
            tmp = i;
        }
    }
    cout << tmp << endl;
    return 0;
}

Measured memory_bytes: 3616
#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 ALL(n) begin(n),end(n)
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> pint;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
 
bool judge(ll cut, vector<ll> logs, ll n, ll k){
	ll ans=0;
	if(cut==0) return false;
	// for(int i=0; i<(int)logs.size(); i++){
	ll cc=0;
	for(ll i=0; i<n; i++){
  
	  if(logs[i]%cut!=0) ans+=(logs[i]/cut);
    else ans+=(logs[i]/cut-1);
		// cout<<"ans["<<i<<"] = "<<ans<<endl;

		//ans = (logs[i] + cut - 1) / cut - 1;
		//if(ans > 0) cc += ans;

	  if(ans>k) return false;
		// else cout<<"ans["<<i<<"] = "<<ans<<endl;
	}
	if(ans>k) return false;
	else return true;
	//if(cc>k) return false;
	//else return true;
}
 
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n,k; cin>>n>>k;
	vector<ll> a(n,0);
	rep(i,n) cin>>a[i];

	ll ok=1000000100;
	ll ng=0;

  ll t=0;
  //int k=0;
	//while(abs(ok-ng)>1){
	while(abs(ok-ng)>1){
  
	  ll mid=(ok+ng)/2;

    if(judge(mid,a,n,k)){
        ok=mid;
				//cout<<"ok["<<k<<"] = "<<ok<<endl;
    }else{
        ng=mid;
				// cout<<"ng["<<k<<"] = "<<ng<<endl;
    }
		//cout<<"t = "<<t<<"/mid = "<<mid<<endl;
		//t++;
	}
	cout<<ok<<endl;
	return 0;
}

Measured memory_bytes: 6368
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
    cin >> s;
    for(int i=0;i<s.length()-1;i++){
        if(s[i]=='A' && s[i+1]=='C'){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	int A1, A2, A3;

	cin >> A1 >> A2 >> A3;

	if (A1 + A2 + A3 >= 22) {
		cout << "bust" << endl;
	} else {
		cout << "win" << endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <map>
#include <tuple>

#define INF 10010010010
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
using namespace std;

 

 
int main(){
    int n,m; cin >> n >> m;
   
    priority_queue<int> que;

    rep(i,n) {
        int a; cin >> a;
        que.push(a);
    }
    
    
    while (m>0) {
        int t = que.top()/2;
        que.pop();
        que.push(t);
        --m;
    }
    ll ans = 0;
    while (!que.empty()) {
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
}


Measured memory_bytes: 892
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		TreeMap <Integer, Integer> T = new TreeMap <Integer, Integer>();
		
		for (int i=0; i<N; i++){
			T.put(sc.nextInt(), 0);
		}
	
		if (T.size()!=1){
		while (T.size()>1 && T.containsKey(1)!=true){
			
			int first = T.firstKey();
			
			int second = T.lastKey();
			T.remove(second,T.get(second));
			
				
			if (second%first!=0) {
				T.put(second%first, 0);
			}
			
		}
		}
		System.out.println(T.firstKey());
		

	}

}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;

    auto d = abs(a - b);
    auto u = v - w;

    if (u <= 0 || u * t < d) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
}

Measured memory_bytes: 3632