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

using namespace std;

typedef pair<int, int> II;
typedef pair<long long, int> LLI;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<II> VII;

#define For(i,a,b) for(int i = a;i <= b; i++)
#define Rep(i,a,b) for(int i = a;i >= b; i--)
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, f) for(auto i : f)
#define fi first
#define se second
#define pb push_back
#define sz(s) int(s.size())
#define reset(f, x) memset(f, x, sizeof(f))
#define all(x) x.begin(), x.end()
#define two(x) (1LL << x)
#define getbit(x, i) ((x >> (i-1)) & 1LL)
#define onbit(x, i) (x | (1LL << (i-1)))
#define offbit(x, i) (x & ~(1 << (i-1)))

const int N = 2000+10;
const int inf = 1e9;

int a[2*N], c[2*N];
int n, res;
int pos[2][N];
int f[N][N];
int t[2][2*N];

int update(int k, int i) {
    for(i; i <= 2*n; i += i & (-i)) t[k][i]++;
}

int get(int k, int i) {
    int res = 0;
    for(i; i; i -= i & (-i)) res += t[k][i];
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    //freopen("in.txt","r",stdin);
    //freopen("","w",stdout);
    cin >> n;
    For(i, 1, 2*n) {
        char ch;
        cin >> ch >> a[i];
        c[i] = (ch == 'B');
        pos[c[i]][a[i]] = i;
    }
    For(i, 0, n) For(j, 0, n) f[i][j] = inf;
    f[0][0] = 0;
    For(u, 0, n) {
        reset(t[1], 0);
        For(v, 0, n) {
            int i = u+v+1;
            if (u < n) {
                int p = pos[0][u+1];
                p += get(0, 2*n) - get(0, pos[0][u+1]);
                p += get(1, 2*n) - get(1, pos[0][u+1]);
                f[u+1][v] = min(f[u+1][v], f[u][v] + p - i);
            }
            if (v < n) {
                int p = pos[1][v+1];
                p += get(0, 2*n) - get(0, pos[1][v+1]);
                p += get(1, 2*n) - get(1, pos[1][v+1]);
                f[u][v+1] = min(f[u][v+1], f[u][v] + p - i);
            }
            if (v < n) update(1, pos[1][v+1]);
        }
        if (u < n) update(0, pos[0][u+1]);
    }
    cout << f[n][n];
}




Measured memory_bytes: 16128
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vll vector<ll>
#define vvll vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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

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


	ll A, B;
	cin >> A >> B;

	ll out = B;

	if (A <= 12 && A >= 6) {
		out = out / 2;
	}
	else if (A <= 5) {
		out = 0;
	}


	cout << out << endl;



	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define CL(x) ((x) * (x))
#define CR(x) (((x) * (x)) + 1)
typedef long long cc;
typedef pair <int, int> pii;
string s;
int res;
bool cant = false;
void Find(int l, int r) {
    if (l >= r) return;
    if (s[l] == s[r])
        Find(l + 1, r - 1);
    if (s[l] != s[r] && s[l] != 'x' && s[r] != 'x') {
        cant = true;
        return;
    }
    if (s[l] != s[r]) {
        res++;
        if (s[l] == 'x')
            Find(l + 1, r);
        else
            Find(l, r - 1);
    }
}
int main() {
    //freopen("input.inp", "r", stdin);
    ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> s;
    Find(0, int(s.size() - 1));
    if (cant) cout << -1; else cout << res;
    return 0;
}


Measured memory_bytes: 2768
#include <iostream>
#include <algorithm>
#include <map>

using namespace std;

const int NMAX = 2e5;

int n;
int a[NMAX + 5];

map<int,int> vals;

bool ok(int val){
	for(int num = 0;num < 30;num++){
		int suf = (val & ((1 << (num + 1)) - 1));
		int neg = ((((1 << (num + 1)) - 1) ^ suf)) + 1;
		int actual = neg + val;
		
		if(((-actual) & actual) == actual && vals[neg] > 0){
			vals[neg]--;
			return true;
		}
	}
	return false;
}

void add(int val){
	vals[val]++;
}

int main(){
	cin >> n;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
	}
	sort(a + 1,a + 1 + n);
	reverse(a + 1,a + 1 + n);
	
	int ans = 0;
	
	for(int i = 1;i <= n;i++){
		if(ok(a[i])){
			ans++;
		}
		else{
			add(a[i]);
		}
	}
	
	cout << ans;
	return 0;
}

Measured memory_bytes: 29824
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

int main(){
    ll n,m; cin >> n >> m;
    vector<ll> a(m);
    ll sum = 0;
    rep(i,m){
        cin >> a[i];
        sum += a[i];
    }
    if(n- sum >= 0) cout << n - sum << endl;
    else cout << -1 << endl;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
 
#define ff first
#define ss second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;

int cnt[100005];
bool v[100005];

int main(){
	int n,m,a;
	char s[3];

	scanf("%d%d", &n, &m);

	int ac = 0, p = 0;
	for(int i = 0; i < m; i++) {
		scanf("%d %s", &a, s);
		if(v[a]) continue;
		if(s[0] == 'W') cnt[a]++;
		else v[a] = true, ac++, p+=cnt[a];
	}

	printf("%d %d\n", ac, p);

	return 0;
}

Measured memory_bytes: 768
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=min(a)+min(b)
for _ in range(M):
  x,y,c=map(int,input().split())
  ans=min(ans,a[x-1]+b[y-1]-c)
print(ans)

Measured memory_bytes: 18736
n,k = map(int, input().split())
v = list(map(int, input().split()))


ans = 0

for i in range(1, k + 1):
    if i <= n:
        for j in range(i + 1):
            l = v[:j] + v[n - i + j:]
            l.sort()
            kari = sum(l)
            for x in range(min(k - i, i)):
                if l[x] >= 0:
                    break
                kari -= l[x]
            ans = max(ans, kari)

print(ans)

Measured memory_bytes: 40428
N,X,Y = map(int, input().split())
l = [0]*N
X -= 1
Y -= 1
for i in range(N-1):
  for j in range(i+1,N):
    k = min(abs(j-i),abs(X-i)+abs(Y-j)+1,abs(X-j)+abs(Y-i)+1)
    l[k] += 1
for i in range(1,N):
  print(l[i])

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

using namespace std;
template <class T> using V = vector<T>;
typedef pair<int, int> P;

int n;
char s[123456];

void imp() {
    puts("-1");
    exit(0);
}

int main() {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    bool ok = (s[1] == '1' && s[n] == '0');
    for (int i = 1; i < n; i++) {
        ok &= (s[i] == s[n-i]);
    }
    if (!ok) imp();

    V<int> a;
    for (int i = 1; i <= n; i++) {
        if (s[i] == '1') a.push_back(i);
    }

    int m = int(a.size())+1;
    V<P> ans;
    for (int i = 0; i < int(a.size()); i++) {
        ans.emplace_back(i, i+1);
    }
    for (int i = 1; i < int(a.size()); i++) {
        int c = a[i] - a[i-1] - 1;
        for (int j = 0; j < c; j++) {
            ans.emplace_back(i, m);
            m++;
        }
    }

    if (m != n) imp();
    else {
        for (auto &e : ans) {
            printf("%d %d\n", e.first+1, e.second+1);
        }
    }
    return 0;
}

Measured memory_bytes: 2804
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

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

    int k = 1;
    int sum = 0;

    while ( sum < n ) {
        sum += k;
        ++k;
    }

    int dif = sum - n;

    for ( int i = 1; i < k; ++i ) {
        if ( i != dif ) {
            cout << i << endl;
        }
    }

    return 0;
}

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    int n; cin >> n;
    vector<ll> t(n);
    vector<ll> a(n);
    rep(i,n)
    {
        cin >> t[i] >> a[i];
    }
    ll taka = 1;
    ll ao = 1;
    ll ltaka;
    ll lao;
    rep(i,n)
    {
        taka = max((taka - 1) / t[i] + 1, (ao - 1) / a[i] + 1)*t[i];
        ao = max((taka - 1) / t[i] + 1, (ao - 1) / a[i] + 1)*a[i];
    }
    cout << taka+ao << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
#define P pair<int,int>
//printf("%.12Lf\n",);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}
int sankaku(int a){
	return a*(a+1)/2;
} 
int XOR(int a,int b){
	int ni=1;
	rep(0,i,41){
		n2[i]=ni;
		ni*=2;
	}
	rep(0,i,41)nis[i]=0;
	for(int i=40;i>=0;i-=1){
		if(a>=n2[i]){
			nis[i]++;
			a-=n2[i];
		}
		if(b>=n2[i]){
			nis[i]++;
			b-=n2[i];
		}	
	}
	int sum=0;
	rep(0,i,41)sum+=(nis[i]%2*n2[i]);
	return sum;
}
int a[114514],b[114514];
int kosu[114514];
bool red[114514];
signed main(){
	ic(n) ic(m)
	rep(0,i,m){
		cin>>a[i]>>b[i];
		a[i]-=1;
		b[i]-=1;
	}	
	red[0]=true;
	rep(1,i,n)red[i]=false;
	rep(0,i,n)kosu[i]=1;
	rep(0,i,m){
		kosu[b[i]]++;
		kosu[a[i]]-=1;
		if(red[a[i]])red[b[i]]=true;	
		if(kosu[a[i]]==0)red[a[i]]=false;
	}
	int ans=0;
	rep(0,i,n)if(red[i])ans++;	
	c(ans)
}

Measured memory_bytes: 2688
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <stack>
#include <unordered_map>
#include <utility>
#include <vector>

// Aliases
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
using f32 = float;
using f64 = double;
using ll = long long;
using ull = unsigned long long;

using std::cout;
using std::cerr;
using std::cin;
using std::endl;
using std::string;
using std::vector;
using std::array;
template <class T>
using matrix = vector<vector<T>>;
template <class T>
constexpr T inf = std::numeric_limits<T>::max();
template <class T>
constexpr T neg_inf = -std::numeric_limits<T>::max();
template <class T>
constexpr T pi = static_cast<T>(3.141592653589793);

template <class T = i64>
vector<T> read_vector(const u64 n)
{
    vector<T> vec;
    vec.reserve(n);
    for (u64 i = 0; i < n; i++)
    {
        T v;
        cin >> v;
        vec.emplace_back(v);
    }

    return vec;
}

template <class T>
void print(const vector<T>& vec, const bool new_line = false)
{
    const u64 n = vec.size(); 
    if (new_line)
    {
        for (u64 i = 0; i < n; i++)
        {
            cout << vec[i];
            if (i != n - 1) { cout << '\n'; }
        }
    }
    else
    {
        for (u64 i = 0; i < n; i++)
        {
            cout << vec[i];
            if (i != n - 1) { cout << ' '; }
        }
    }

    cout << endl;
}

int main()
{
    u32 a, b;
    cin >> a >> b;
    if (a > b * 2) { cout << (a - b * 2) << endl; }
    else { cout << 0 << endl; }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin>>N;
  ll A[N+1]={},B[N+1]={};
  bool same=true;
  for(int i=0;i<N;i++){
      cin>>A[i]>>B[i];
      if(A[i]!=B[i]) same=false;
  }
  if(same){
      cout<<0<<endl;
      return 0;
  }

  ll resA=0,resB=0;
  vector<pair<ll,int>> v;
  for(int i=0;i<N;i++){
      if(A[i]<=B[i]){
          resA+=A[i];
          resB+=B[i];
      }else v.push_back(make_pair(B[i],i));
  }
  sort(v.begin(),v.end());
  ll ans=resA;

  for(int i=1;i<v.size();i++){
      ans+=A[v[i].second];
  }
  ans+=A[v[0].second]-B[v[0].second];
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 896
N = int(input())
time = 0
A = []
for i in range(N):
    a,b = map(int, input().split())
    A.append([b,a])
A.sort()
for i in range(N):
    time += A[i][1]
    if time > A[i][0]:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 76248
n = int(input())
x = [list(map(str, input().split())) for _ in range(n)]
#print(x)
rate = 380000
ans = 0
for i in range(n):
    if x[i][1]=='JPY':
        ans += float(x[i][0])
    if x[i][1]=='BTC':
        ans += float(x[i][0])*rate

print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;
import java.util.Stack;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class Main {public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		Stack<Integer> stack = new Stack<Integer>();
		Pattern p = Pattern.compile("[0-9]+");
		
		while(sc.hasNext()) {
			String s = sc.next();
			Matcher m = p.matcher(s);
			if(m.find()) stack.push(Integer.parseInt(s));
			else if(s.equals("+")) stack.push(stack.pop() + stack.pop());
			else if(s.equals("-")) stack.push((-stack.pop() + stack.pop()));
			else if(s.equals("*")) stack.push(stack.pop() * stack.pop());
		}
		
		System.out.println(stack.pop());
	}
}


Measured memory_bytes: 26316
/*
Wai u read my code xD
*/
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vi vector <ll> 
#define qu queue <ll>
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


void solve()
{
    string s; cin >> s;
    int n = s.size();
    string s1 = s;
    string s2 = s.substr(0,((n-1)/2));
    string s3 = s.substr(((n+2)/2));
    string ss1 = s1;
    string ss2 = s2;
    string ss3 = s3;
    reverse(ss1.begin(),ss1.end());
    reverse(ss2.begin(),ss2.end());
    reverse(ss3.begin(),ss3.end());
    if (s1==ss1&&s2==ss2&&s3==ss3) nout("Yes");
    else nout("No");
    //sout(ss1);sout(ss2);nout(ss3);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import os
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
#######################################################################################################
N,A,B=map(int,input().split())
r=0
if A+B<N:
    r=0
else:
    r=A+B-N
print(min(A,B),r)


Measured memory_bytes: 9932
gets
a = gets.split.map(&:to_i).sort
max = 10 ** 6
f = Array.new(max + 1, 0)
d = Array.new(max + 1, 0)
ans = 0
a.each{|n|
	if d[n] == 1
		ans -= 1
		d[n] = 0
	end
	if f[n] == 1
		next
	end
	ans += 1
	t = n
	j = 1
	while t <= max
		f[t] = 1
		t += n
	end
	d[n] = 1
}
puts ans

Measured memory_bytes: 46372
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, i=0, sum=0,start,end;
  cin >> N;

  while(i < N){
    cin >> start >> end;

    sum += end - start +1;

    i++;
  }
  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

/**
 * @author yoshizaki
 * ABC 132
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner= new Scanner(System.in);
        int problems = scanner.nextInt();
        int[] difficults = new int[problems];
        for (int i = 0; i < problems; i++) {
            difficults[i] = scanner.nextInt();
        }
        Arrays.sort(difficults);
        int under = difficults[(problems / 2) -1];
        int over = difficults[problems / 2];
        int answer = over -under;
        
        System.out.println(answer);
    }
}


Measured memory_bytes: 49908
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		String[] x = line.split(" ");
		int a = Integer.parseInt(x[0]);
		int b = Integer.parseInt(x[1]);
		if (a == b) {
			System.out.println("a == b");
		} else if (a > b) {
			System.out.println("a > b");
		} else {
			System.out.println("a < b");
		}

	}

}

Measured memory_bytes: 25904
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

ll josephus(ll n, ll k, ll s) {
  ll x = k * s;
  while (x > n) { x = ((x - n) * k - 1) / (k - 1); }
  return x;
}

int main() {
  int n, k, m;
  while (scanf("%d %d %d", &n, &k, &m), n|k|m) {
    int ans = (20000 * n + josephus(n, k, n) - (k - m + 1)) % n + 1;
    cout << ans << endl;
  }
}

Measured memory_bytes: 888
#include <tuple>
#include <vector>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
using ll	= long long;
using ull	= unsigned long long;
using ld	= long double;
using pii	= pair<int,int>;
using pll	= pair<ll,ll>;
using vi	= vector<int>;
using vb	= vector<bool>;
using vc	= vector<char>;
using vvi	= vector<vi>;
using vvb	= vector<vb>;
using vpii	= vector<pii>;
using vpll	= vector<pll>;
using vll	= vector<ll>;
using vull	= vector<ull>;
using vvll	= vector<vll>;
#define ever (;;)
#define f first
#define s second
#define pb emplace_back
#define sz size()
#define graph vector<vertex>
#define deg(X) (int)G[X].e.size()
#define INF 1234567890
#define INFll 2000000000000000000
#define maxe(X, Y) if((Y) > (X)) (X) = (Y)
#define mine(X, Y) if((Y) < (X)) (X) = (Y)
#define rep(i, begin, end) for(__typeof(end) i = (begin); i < (end); ++i)
#define repr(i, begin, end) for(__typeof(end) i = (begin)-1; i >= (end); --i)
#define bend(X) X.begin(), X.end()
pii operator+(const pii& A, const pii& B) { return {A.f+B.f, A.s+B.s}; }
pii operator-(const pii& A, const pii& B) { return {A.f-B.f, A.s-B.s}; }
pii operator-(const pii& A) { return {-A.f, -A.s}; }

//
// END OF DEFINES
//

constexpr int max_v = 1e3;
int n, k;
vi T;
vb DP;

bool in() {
    //cin >> n >> w;
    scanf("%d %d", &n, &k);
    T.resize(n);
    DP.resize(k+1);
    rep(i, 0, n)
        scanf("%d", &T[i]);

	return true;
}

ll solve() {

    rep(i, 1, k+1)
        for(auto x : T)
            if(i-x >= 0 && DP[i-x] == 0)
                DP[i] = 1;

    if(DP[k])
        printf("First\n");
    else
        printf("Second\n");

	return -INF;
}

int main() {
	int noOfTests = 1;
	//scanf("%d", &noOfTests);

	while(noOfTests --> 0) {
		if(!in()) {
			printf("popsute wejscie\n");
			continue;
		}
		ll result = solve();
		if(result == ll(-'t'))
			printf("TAK\n");
		else if(result == ll(-'n'))
			printf("NIE\n");
		else if(result != -INF)
			printf("%lld\n", result);
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  int ans = 0, m = 0;
  rep(i,n){
    int p;
    cin >> p;
    m = max(m,p);
    ans += p;
  }
  ans -= m/2;
  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;
typedef long long ll;
typedef pair<int,int>P;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

int main(){
	int n,K;cin>>n>>K;
	ll ans=0;
	for(ll i=K;i<=n+1;i++){
		ll Min=i*(i-1)/2,Max=i*(2*n-i+1)/2;
		(ans+=Max-Min+1)%=MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main()
{
    int N, M, X; cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    for (int i = 0; i < N; i++) {
        cin >> C[i];
        cin >> A[i];
    }

    int ans = INT_MAX;

    for (int pat = 1; pat < (1 << N); pat++) {
        vector<int> y(M, 0);
        int cost = 0;
        for (int i = 0; i < N; i++) {
            if (pat & (1<<i)) {
                for (int j = 0; j < M; j++) {
                    y[j] += A[i][j];
                }
                cost += C[i];
            }
        }
        if (all_of(y.begin(), y.end(), [&](int x) {return x >= X; })) {
            ans = min(ans, cost);
        }
    }

    cout << (ans == INT_MAX ? -1 : ans) << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <stack>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <iomanip>


int main()
{
	long long a, b, c, d, e, f;

	std::cin >> a >> b >> c >> d >> e >> f;

	std::map<long long, long long> m, s;

	s[0] = 1;
	m[0] = 1;

	std::stack<long long> x, z;
	x.push(0);
	z.push(0);

	while (!x.empty()) {
		long long n = x.top(); x.pop();

		m[n] = 1;
		if (m[n + 100 * a] == 0) {
			m[n + 100 * a] = 1;
			if (n + 100 * a <= 3000) x.push(n + 100 * a);
		}
		
		if (m[n + 100 * b] == 0) {
			m[n + 100 * b] = 1;
			if (n + 100 * b <= 3000) x.push(n + 100 * b);
		}
	}
	while (!z.empty()) {
		long long n = z.top(); z.pop();

		s[n] = 1;
		if (s[n + c] == 0) {
			s[n + c] = 1;
			if (n + c <= 3000) z.push(n + c);
		}

		if (s[n + d] == 0) {
			s[n + d] = 1;
			if (n + d <= 3000) z.push(n + d);
		}

	}
	long long as = 0, aw = 100 * a;
	double rate = 0;

	for (auto it : m) {
		long long suger = 0;
		for (auto jt : s) {
			if (it.first + jt.first > f) break;
			if (it.first / 100 * e >= jt.first) {
				suger = jt.first;
			}
		}
		if (it.first + suger == 0) continue;
		if (rate < (100 * suger) / (1.0 * it.first + suger)) {
			rate = (100 * suger) / (1.0 * it.first + suger);
			as = suger;
			aw = it.first;
			//std::cout << as << " " << aw << std::endl;
		}
	}

	std::cout << as + aw << " " << as << std::endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, k;

int main() {
	cin >> n >> k;
	cout << min(n % k, abs(k - n % k)) << endl;
	return 0;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV
import qualified Data.Vector.Mutable as MV
import Data.Ix
import Data.Ord (Down(Down))
import qualified Data.Sequence as Seq
-- import Control.Lens

debug = False

ts :: Show a => a -> a
ts a = if debug then traceShowId a else a


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readTuple4 :: IO (Int, Int, Int, Int)
readTuple4 = do
    [a, b, c, d] <- readInts
    return (a, b, c, d)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> Int
solve n = dfs 0 where
  dfs :: Int -> Int
  dfs num
    | num > n = 0
    | otherwise = (if is_myself_ok then (+1) else id) . sum $ (\a -> dfs $ num * 10 + a) <$> [3,5,7] where
      myself = show num
      is_myself_ok = all (`elem` myself) ['3', '5', '7']


main :: IO ()
main = do
  n <- readInt
  print $ solve n


Measured memory_bytes: 892
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
   string s;
  ios::sync_with_stdio(false);
  // string dx[4] = {"dream","erase","dreamer","eraser"};
  string dx[4] = {"maerd","esare","remaerd","resare"};
  // string t [] = {"resare","esare","remaerd","maerd"};
  cin>>s;
  reverse(all(s));
  ll idx = 0;
  string ans= "YES";
  while(idx < s.size()){
    ll flg = 0;
    // cout<<idx<<endl;
    rep(i,4) {
      // cout<<s.substr(idx,dx[i].size())<<endl;
      if(s.substr(idx,dx[i].size()) == dx[i]) {
        idx += dx[i].size();
        flg = 1;
      }
    }
    if(flg==0){
      ans= "NO";
      break;
    }

  }
  cout<<ans<<endl;



}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 512
s = input()
c = 0
for i in range(len(s)):
    if i%2==0:
        if s[i] == "R" or s[i] == "U" or s[i] == "D":
            c += 1
            continue
        else:
            print("No")
            break
    else:
        if s[i] == "L" or s[i] == "U" or s[i] == "D":
            c += 1
            continue
        else:
            print("No")
            break
if c == len(s):
    print("Yes")

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}



//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

int main() {
	int N, M;
	int X[200100] = { 0 };
	vector<int> g;
	bool flg = false;

	cin >> N >> M;

	for (int i = 0; i < M; i++)
	{
		int a, b;
		cin >> a >> b;

		if (a == 1) {
			X[b] = 1;
		}
		if (b == N) {
			g.push_back(a);
		}
	}

	for (int i = 0; i < (int)g.size(); i++)
	{
		if (X[g[i]] == 1) {
			flg = true;
			break;
		}
	}

	if (flg) {
		cout << "POSSIBLE" << endl;
	}
	else {
		cout << "IMPOSSIBLE" << endl;
	}

	return 0;
}

Measured memory_bytes: 1660
N = int(input())
S = input()

r_num = S.count("R")
g_num = S.count("G")
b_num = S.count("B")

cnt = 0

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        if not 2 * j - i < N:
            break
        if S[i] != S[j] and (S[2 * j - i] != S[i] and S[2 * j - i] != S[j]):
            cnt += 1

ans = r_num * g_num * b_num - cnt
print(ans)
        

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

void trip(int nw,int a,int b,vector<vector<int>>&mp,vector<bool>&visited){
	visited.at(nw)=true;
	for(auto&i:mp.at(nw)){
		if((nw==a&&i==b)||(i==a&&nw==b)||visited.at(i))continue;
		trip(i,a,b,mp,visited);
	}
}

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,m; cin>>n>>m;
	vector<vector<int>>mp(n+1);
	for(int i=0;i<m;++i){
		int a,b; cin>>a>>b;
		mp.at(a).emplace_back(b),mp.at(b).emplace_back(a);
	}
	int ans=0;
	for(int i=0;i<mp.size();++i){
		for(int j=0;j<mp.at(i).size();++j){
			vector<bool>v(n+1,false); v.front()=true;
			trip(1,i,mp.at(i).at(j),mp,v);
			if(any_of(v.begin(),v.end(),[](auto a){return !a;}))++ans;
		}
	}
	cout<<ans/2<<"\n"s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 2e5+2, MOD = 1e9+7;
int c[MX];
ll buk[MX], dp[MX];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	ll ans = 0;
	int n;
	cin >> n;
	for(int i=0; i<n; i++) {
		cin >> c[i];
	}
	vector<int> v;
	int j = 0;
	for(int i=0; i<n; i=j) {
		while(j < n && c[i] == c[j]) j++;
		v.push_back(c[i]);
	}
	n = v.size();
	for(int i=0; i<n; i++) {
		ans += buk[v[i]];
		ans %= MOD;
		buk[v[i]] += i ? dp[i-1]+1 : 1;
		buk[v[i]] %= MOD;
		dp[i] = ans;
	}
	cout << ((ans+1) % MOD);
}

Measured memory_bytes: 5108
// clang-format off
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
// clang-format on

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

    int u = 0;
    for (int i : a) u ^= i;
    rep(i, n) cout << (u ^ a[i]) << " \n"[i == n - 1];
    return 0;
}


Measured memory_bytes: 3972
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
//ranker
using namespace std;

#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using pis = pair<int, string>;
using psi = pair<string, int>;
using D = double;


const int Max=10000000;
bool prime[Max];
int main(void){
  string str;

  cin >> str;

  reverse(str.begin(), str.end());

  cout << str << endl;
}

Measured memory_bytes: 3056
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;
const double pi=(acos(-1));

int main(){
  cout << fixed << setprecision(15);
  ll a,b,h,m; cin >> a >> b >> h >> m;
  double theta=((double)1/30-(double)1/360)*pi*(60*h+m);
  double cc=a*a+b*b-2*a*b*cos(theta);
  double c=sqrt(cc);
  cout << c << endl;
  
}

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

using namespace std;

class Edge{
    int v, u, weight;
public:
    Edge(int s=0, int t=0, int w=0) : v(s), u(t), weight(w) {}

    int get_weight() const { return weight; }

    int node1() const{ return v; }
    int node2() const{ return u; }

    bool operator<(const Edge& e){
        return weight < e.get_weight();
    }
};

bool operator<(const Edge& e1, const Edge& e2){
    return e1.get_weight() < e2.get_weight();
}

class UnionFind{
    vector<int> parent, rank;
public:
    UnionFind(int N){
        parent.resize(N);
        rank.resize(N);
        for(int i=0;i<N;i++){
            parent[i] = i;
        }
    }

    int find(int x){
        if(parent[x] != x){
            parent[x] = find(parent[x]);
        }
        return parent[x];
    }

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

    void unite(int x, int y){
        int root_x = find(x);
        int root_y = find(y);
        if(rank[root_x] > rank[root_y]){
            parent[root_y] = root_x;
        }
        else{
            if(rank[root_x] == rank[root_y]){
                rank[root_y]++;
            }
            parent[root_x] = root_y;
        }
    }
};

int Kruskal(UnionFind& uf, vector<Edge>& edges){
    int cost = 0;
    for(int i=0;i<edges.size();i++){
        if(!uf.same(edges[i].node1(), edges[i].node2())){
            cost += edges[i].get_weight();
            uf.unite(edges[i].node1(), edges[i].node2());
        }
    }
    return cost;
}

int main()
{
    int N, M, s, t, w;
    cin >> N >> M;
    vector<Edge> edges(M);
    UnionFind uf(N);

    for(int i=0;i<M;i++){
        cin >> s >> t >> w;
        edges.at(i) = Edge(s, t, w);
    }

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

    cout << Kruskal(uf, edges) << endl;
}


Measured memory_bytes: 4088
def main():
    def cmb(n, r, mod):#コンビネーションの高速計算　
        if ( r<0 or r>n ):
            return 0
        r = min(r, n-r)
        return g1[n] * g2[r] * g2[n-r] % mod

    mod = 10**9+7 #出力の制限
    N = 10**5
    g1 = [1, 1] # 元テーブル
    g2 = [1, 1] #逆元テーブル
    inverse = [0, 1] #逆元テーブル計算用テーブル

    for i in range( 2, N + 1 ):
        g1.append( ( g1[-1] * i ) % mod )
        inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
        g2.append( (g2[-1] * inverse[-1]) % mod )

    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    A.sort()
    max=sum(cmb(i,K-1,mod)*A[i] for i in range(K-1,N))
    mi=sum(cmb(N-i-1,K-1,mod)*A[i] for i in range(0,N-K+1))
    print((max-mi)%(10**9+7))

if __name__ == '__main__':
    main()


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

int main(){
  int a,b,c[101];
  for(int i=0;i<101;i++) c[i] = 0;
  while(cin >> a >> b){
    if(a != 0 || b != 0){
      c[a]++;
      c[b]++;
    }
    else{
      string ans = "OK";
      if(c[1] != 1 || c[2] != 1) ans = "NG";
      else{
	for(int i=3;i<101;i++){
	  if(c[i] % 2 == 1){
	    ans = "NG";
	    break;
	  }
	}
      }
      cout << ans << endl;
      for(int i=0;i<101;i++) c[i] = 0;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <set>
#include <bitset>
using namespace std;

vector<pair<int, int> >locks;
set<pair<int,int> >check;

int product(int l, int r){
  return l&r;
}

int set_union(int l, int r){
  return l|r;
}

int bit(char x){
  return (x-'0');
}

int main(){
  while(1){
    int n; cin >> n;
    if(!n) break;
    locks.clear();
    check.clear();
    string s; cin >> s;
    int lock= 0;
    int xflag = 0;
    for(int i=0;i<s.size();i++){
      if(s[i] == 'u'){
	lock = 0;
	continue;
      }
      pair<int, int> p = make_pair(lock, bit(s[i]));
      if(check.find(p) == check.end()){
	locks.push_back(p);
	check.insert(p);
      }
      //      cout << static_cast<std::bitset<10> >(lock)<< endl;      
      if(lock & 1<<bit(s[i])){
	xflag = 1;
	break;
      }
      lock |= 1<<bit(s[i]);
      
    }

    if(xflag){
      cout << "UNSAFE\n";
    }else{

    while(1){
      //      cout << "x\n";
      int flag = 0;
      for(int i=0;i<locks.size();i++){
	pair<int, int> l = locks[i];
	//	cout << i << endl;
	for(int j=i+1;j<locks.size();j++){
	  pair<int, int> r = locks[j];
	  int x = set_union(l.first, r.first);
	  pair<int, int> p = make_pair(x, r.second);	  
	  if(!product(l.first, r.first) && !(l.first & 1<<r.second) && r.first & 1<<l.second  && check.find(p) == check.end()){
	    //	    for(set<char>::iterator it = l.first.begin(); it != l.first.end(); it++) cout << *it; 
	    //	    for(set<char>::iterator it = r.first.begin(); it != r.first.end(); it++) cout << *it; cout << endl;
	    // for(set<char>::iterator it = x.begin(); it != x.end(); it++) cout << *it; cout << endl;
	    //	    cout << "-------------------\n";
	    locks.push_back(p);
	    check.insert(p);
	    flag = 1;
	  }
	}
      }
      if(!flag) break;
    }
    //    cout << "----\n";
    int flag = 0;
    for(int i=0;i<locks.size();i++){
      pair<int, int> l = locks[i];
      //      cout << static_cast<std::bitset<10> >(l.first) << " " << l.second<< endl;
      for(int j=i+1;j<locks.size();j++){
	pair<int, int> r = locks[j];
	if(!product(l.first, r.first) &&
	   l.first & 1<<r.second  &&
	   r.first & 1<<l.second){
	  cout << "UNSAFE\n";
	  flag = 1;
	  i = locks.size();
	  break;
	}
      }
    }
    if(!flag) cout << "SAFE\n";
    }
  }
  return 0;
}

Measured memory_bytes: 3176
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    String s = sc.next();
    String ans = "Yes";

    if(s.charAt(2) != s.charAt(3)){
      ans = "No";
    } if(s.charAt(4) != s.charAt(5)){
      ans = "No";
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
long long n,a,b;
int main()
{
	cin>>n>>a>>b;
	if (a<b) swap(a,b);
	if ((a+b)%2==0) 
	{
		cout<<(a-b)/2<<endl;
	}
	else
	{
		cout<<min(n-a+1+(a-b-1)/2,b+(a-b-1)/2)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <map>
#include <sstream>
#include <iostream>
#include <queue>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
using namespace std;
typedef long long ll;

struct V {
  ll a, b;
  V(ll a, ll b) : a(a), b(b) {}
  V() {}
};

V vs[100000+10];

struct P {
  ll v;
  int i;
  bool isA;
};
bool operator<(const P& p1, const P& p2) {
  if(p1.v != p2.v) return p1.v < p2.v;
  return p1.i < p2.i;
}

bool st[100000+10][2];

int main(void) {
  int n;
  scanf("%d", &n);
  vector<P> ps;
  REP(i, n) {
    scanf("%lld%lld", &vs[i].a, &vs[i].b);
    ps.push_back((P){vs[i].a, i, true});
    ps.push_back((P){vs[i].b, i, false});
  }
  sort(ps.begin(), ps.end());
  ll res = 0;
  REP(i, n) {
    P p = ps[i];
    res += ps[i].v;
    st[p.i][p.isA ? 0 : 1] = true;
  }
  int nA = 0;
  int nB = 0;
  REP(i, n) {
    if(st[i][0] && !st[i][1]) {
      ++nA;
    } else if(!st[i][0] && st[i][1]) {
      ++nB;
    }
  }

  // cerr << ">" << res << endl;
  if(nA == 0 || nB == 0 || nA + nB < n) {
    // do nothing
  } else {
    // 今使ってる中で一番でかいやつのindexを取る
    int idx = -1;
    int idx2 = -1;
    int maxi = -1;
    REP(i, n) {
      REP(j, 2) {
        if(st[i][j]) {
          int v = j==0 ? vs[i].a : vs[i].b;
          if(maxi < v) {
            maxi = v;
            idx = i;
            idx2 = j;
          }
        }
      }
    }
    // idxの箇所を捨てて他の使ってない最小を採用
    ll res1 = res;
    {
      res1 -= idx2==0 ? vs[idx].a : vs[idx].b;
      int mini = 2e9;
      REP(i, n) {
        if(i != idx) {
          REP(j, 2) {
            if(!st[i][j]) {
              int v = j==0 ? vs[i].a : vs[i].b;
              if(mini > v) {
                mini = v;
              }
            }
          }
        }
      }
      res1 += mini;
    }
    // cerr << ">> " << res1 << endl;
    // idxの箇所を両取りして他の箇所でmaxを捨てる
    ll res2 = res;
    {
      res2 += idx2==0 ? vs[idx].b : vs[idx].a;
      int maxi = -1;
      REP(i, n) {
        if(i != idx) {
          REP(j, 2) {
            if(st[i][j]) {
              int v = j==0 ? vs[i].a : vs[i].b;
              if(maxi < v) {
                maxi = v;
              }
            }
          }
        }
      }
      res2 -= maxi;
    }
    res = min(res1, res2);
    // cerr << ">> " << res2 << endl;
  }
  
  printf("%lld\n", res);
  
  return 0;
}


Measured memory_bytes: 7536