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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

int main(){

    int n;
    cin>>n;
    vi l(n);
    rep(i,n)cin>>l[i];

    int ans=0;
    sort(all(l));

    rep(i,n-2){
        repa(j,i+1,n-1){
            if(l[i]==l[j])continue;
            repa(k,j+1,n){
                if(l[j]==l[k])continue;
                if(l[i]+l[j]>l[k]){
                    // cerr<<l[i]<<","<<l[j]<<","<<l[k]<<"\n";
                    ans++;
                }
            }
        }
    }

    cout<<ans<<"\n";

    return 0;

}

Measured memory_bytes: 3628
w, h, n = map(int,input().split())

hani = [0,w,0,h]

for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:

        hani[0] = max(hani[0],x)
    elif a == 2:
        hani[1] = min(hani[1],x)
    elif a == 3:
        hani[2] = max(hani[2],y)
    else:
        hani[3] = min(hani[3],y)

print(max(0,hani[1]-hani[0]) * max(0,hani[3]-hani[2]))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
const int N=2e5+10;
typedef long long ll;

int n;
ll a[N];

int main()
{
	cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	ll sum=0;
	for(int i=1; i<n; i++)
	{
		if(a[i]<a[i-1])
		{
			sum+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	cout<<sum;
}

Measured memory_bytes: 5060
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(void){
  int N,i;
  int total=0;
  int *a;
  scanf("%d", &N);
  a = (int*)malloc(sizeof(int) * N);
  for(i=0;i<N;i++){
  scanf("%d",&a[i]);
  }
  for(i=0;i<N;i++){
    while(a[i]%2==0){
      a[i]=a[i]/2;
      total++;
    }
  }
  printf("%d",total);
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
#define key 1e9
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
template<class T> inline void chmax(T& a, T b) {
	a = std::max(a, b);
}
template<class T> inline void chmin(T& a, T b) {
	a = std::min(a, b);
}
const int MAX = 330000;
int fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		finv[i] = finv[i - 1] * inv[i] % mod;
	}
}

// 二項係数計算
long long COMB(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n % i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
struct edge { int to, cost; };
int par[114514], rrank[114514];//親、木の深さ
void init(int n) {
	rep(i, n) {
		par[i] = i;
		rrank[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x) {
		return x;
	}
	else return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rrank[x] < rrank[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (rrank[x] == rrank[y])rrank[x]++;
	}
}
bool same(int x, int y) {
	return find(x) == find(y);
}
int keta(int x) {
	int ans = 0, n = 1;
	while (n <= x) {
		ans++;
		n *= 10;
	}
	return ans;
}
signed main() {
	int a, b;
	cin >> a >> b;
	if (a == b) {
		rep(i, a)cout << b;
	}
	else {
		rep(i, max(a, b))cout << min(a, b);
	}
	ggr
}


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

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

  int a = n/2+1;
  double b = n;
  double ans;

  if (n%2==0)
  ans = 1./2.;
  else
  ans = a/b;
  
  cout << ans << endl;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9;
int n,A,B,C;
vector<int> x;
int dfs(int now,int a,int b,int c)
{
	if (now==n)
	{
		if (min(min(a,b),c)>0) return abs(A-a)+abs(B-b)+abs(C-c)-30;
		else return INF;
	}
	else
	{
		int res0=dfs(now+1,a,b,c);
		int res1=dfs(now+1,a+x[now],b,c)+10;
		int res2=dfs(now+1,a,b+x[now],c)+10;
		int res3=dfs(now+1,a,b,c+x[now])+10;
		return min(min(res0,res1),min(res2,res3));
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>A>>B>>C;
	x.resize(n,0);
	for (int i=0;i<n;++i) cin>>x[i];
	cout<<dfs(0,0,0,0);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define ep emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  string s; cin >> s;

  bool ok = true;
  rep(i, si(s)) {
    if (i % 2 && s[i] == 'R') ok = false;
    else if (i % 2 == 0 && s[i] == 'L') ok = false;
  }

  if (ok) cout << "Yes\n";
  else cout << "No\n";

  return (0);
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define MOD2 (998244353)
#define MOD3 (1000000009)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
ifstream cinn("ride.in");ofstream coutt("ride.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), 

int n;
int Tsum=0;
int v[105];

signed main(){
    FASTER;
    cin>>n;
    for(int i=0;i<n;i++)cin>>v[i],Tsum+=v[i];
    
    int ans=INF;
    for(int i=0,sum=0;i<n-1;i++){
        sum+=v[i];
        ans=min(ans,abs(Tsum-sum-sum));
    }
    cout<<ans;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int m[51][51];
int w, h;
const int dx[] = {-1, 0, 1, -1, 1, -1, 0, 1};
const int dy[] = {-1, -1, -1, 0, 0, 1, 1, 1};

void dfs(int x, int y)
{
    m[y][x] = 0;
    for (int i = 0; i < 8; i++) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        
        if (nx < 0 || ny < 0 || nx >= w || ny >= h)
            continue;
        else if (m[ny][nx] == 1)
            dfs(nx, ny);
    }
}

int main()
{
    while (cin >> w >> h, w || h) {
        int isl = 0;

        for (int i = 0; i < h; i++)
            for (int j = 0; j < w; j++)
                cin >> m[i][j];

        for (int i = 0; i < h; i++) 
            for (int j = 0; j < w; j++)
                if (m[i][j] == 1) {
                    isl++;
                    dfs(j, i);
                }

        cout << isl << endl;
    }

    return 0;
}

Measured memory_bytes: 1236
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;

const int MOD = 1000000007;
const int INF = 1000000000;

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


int main(){
    VI t(2);
    VLL a(2), b(2);
    REP(i, 2) cin >> t[i];
    REP(i, 2) cin >> a[i];
    REP(i, 2) cin >> b[i];
    ll p = (a[0] - b[0]) * t[0], q = (a[1] - b[1]) * t[1];
    if(p > 0){p *= -1; q *= -1;}
    if(p+q < 0){
        cout << 0 << "\n"; return 0;
    }
    if(p+q == 0){
        cout << "infinity\n"; return 0;
    }
    ll k = (-p)/(p+q);
    ll ans = 2 * k;
    if((-p) % (p+q)) ++ans;
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std ;
char a[105];

int main()
{
	int  n,k,x,y,a = 0;
	cin >>n>>k>>x>>y;
	if (n>k)
	{
		a=k* x + (n-k)*y;
	}
	else
	{
		a=n*x;
	}
	cout<<a<<endl ;
	return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int n,m;
	cin >>n >> m;
	cout << (m%n == 0 ? m+n : m-n) << endl;
}


Measured memory_bytes: 256
import sys

def resolve():
    N, M = map(int, input().split())
    if N >= M // 2:
        ans = M // 2
        print(ans)
        return

    x = (M - 2*N) // 4

    N += x
    M -= 2 * x

    ans = min(N, M // 2)
    print(ans)
    return



if __name__ == "__main__":
    resolve()


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

    int main() {
        string str; cin >> str;
        std::vector<int> v(26);
        rep(i,str.size()){
            int x = str[i] - 'a';
            v[x]++;
        }

        for(int a: v){
            if(a&1){
                cout << "No" << endl;
                return 0;
            }
        }

        cout <<"Yes" << endl;

        return 0;
    }


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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define endl "\n"     
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

const int N=1e3+5;
const int M=2e4+2;

int n;
int cache[N][M];

struct data
{
     int w,s,v;
};
data a[N];

bool cmp(data x,data y)
{
     return (x.w+x.s<y.w+y.s);
}

int dp(int pos,int weight)
{
     if(pos==n+1)
          return 0;
     int &ans=cache[pos][weight];
     if(ans!=-1)
          return ans;
     ans=dp(pos+1,weight);
     if(a[pos].s>=weight)
          ans=max(ans,a[pos].v+dp(pos+1,weight+a[pos].w));
     return ans;     
}

int32_t main()
{
     IOS;
     
     memset(cache,-1,sizeof cache);
     cin>>n;
     for(int i=1;i<=n;i++)
          cin>>a[i].w>>a[i].s>>a[i].v;
     sort(a+1,a+1+n,cmp);
     cout<<dp(1,0);
     return 0;
}


Measured memory_bytes: 157440
#include <bits/stdc++.h>
// #define vec(v) vector<int>(v)
// #define be(v) (v).begin(), (v).end()
// #define pb(q) push_back(q)
// #define mapci(mp) map<char*,int>(mp)
// #define mapcc(mp) map<char*,char*>(mp)
// typedef long long ll;
using namespace std;

int main(){

    int a,p;

    cin>>a>>p;

    cout<<(a*3+p)/2<<endl;

    return 0;
}

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

using namespace std;

int gcd(int a, int b) {
    if (a < b) {
        swap(a, b);
    }
    if (!(a%b)) {
        return b;
    } else {
        return gcd(b, a%b);
    }
}

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

    int ans = gcd(A[0], A[1]);
    for (int i = 2; i < N; i++) {
        ans = gcd(ans, A[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int N;
typedef long long ll;
map<ll,ll> f,f_;
const int T=1;
ll mod=1145141919;
ll ex(ll x,ll p){
	ll a=1;
	if(p<0) return 0;
	while(p){
		if(p%2) a=a*x%mod;
		x=x*x%mod;
		p/=2;
	}
	return a;
}
void add(ll &x,ll y){
	x+=y;
	x%=mod;
}

const ll ccc=1000000;
bool prime[ccc+1];
vector<ll> pr;
void makeprime(){
	ll i,j;
	for(i=2;i<=ccc;i++) prime[i]=true;
	for(i=2;i*i<=ccc;i++) if(prime[i]) for(j=2;j*i<=ccc;j++) prime[j*i]=false;
	for(i=2;i<=ccc;i++) if(prime[i]) pr.push_back(i);
}

map<ll,int> fac;
vector<ll> ds;
void dfs(map<ll,int>::iterator it,ll d){
	if(it==fac.end()){
		ds.pb(d);
		return;
	}
	ll p=it->fs,q=it->sc,t=1;
	auto it2=it;
	it2++;
	rep(i,q/2+1){
		dfs(it2,d*t);
		t*=p;
	}
}
int main(){
	makeprime();
	cin>>N;
	rep(i,N){
		ll a,b;
		cin>>a>>b;
		f_[a]+=b;
	}
	for(auto p:f_) if(p.sc!=0) f[p.fs]=p.sc;
	if(f.empty()){
		puts("Yes 1");
		return 0;
	}
	ll c=abs(f.begin()->sc);
//	show(c);
	ll tmp=c;
	for(ll p:pr){
		while(tmp%p==0) tmp/=p,fac[p]++;
	}
	if(tmp>1){
		ll a=round(sqrt(tmp));
		if(a*a==tmp) fac[a]=2;
	}
	dfs(fac.begin(),1);
	sort(all(ds));
	for(ll a:ds){
		bool ok=1;
		ll x=0;
		for(auto p:f) add(x,p.sc%mod*ex(a,p.fs));
		if(x!=0) ok=0;
		x=0;
		for(auto p:f) add(x,-p.sc%mod*p.fs%mod*ex(a,p.fs-1));
		if(x!=0) ok=0;
		if(ok){
			cout<<"Yes "<<a<<endl;
			return 0;
		}
	}
	puts("No");
}

Measured memory_bytes: 2968
# 2019/08/09

from itertools import accumulate

n=int(input())
a=list(map(int,input().split()))

acc=list(accumulate(a))

ans=float('inf')
for i in range(n-1):
    ans=min(ans,abs(acc[i]-(acc[-1]-acc[i])))
    
print(ans)

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

using namespace std;

vector <int> v;

int main() {
	int n , k;
	ios::sync_with_stdio(0);
	cin >> n >> k;
	string s;
	cin >> s;
	int ans = 0;
	for(int i = 1 ; i < s.length() ; i++) {
		if(s[i] == s[i - 1])ans++;
	}
	ans = min(2 * k + ans , n -1); 
	cout << ans << "\n";
	return 0;
}



Measured memory_bytes: 512
import sys

N,M = (int(x) for x in input().split())
li = []
for i in range(M):
  a,b = (int(x) for x in input().split())
  li.append([i,a,b,""])

li.sort(key=lambda x: x[2])

cnt = [1]*N
for i in range(M):
  li[i][3] = str(li[i][1]).zfill(6) + str(cnt[li[i][1]-1]).zfill(6)
  cnt[li[i][1]-1] += 1
  
li.sort(key=lambda x: x[0])
for i in range(M):
  print(li[i][3])

Measured memory_bytes: 33044
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val y = sc.nextLong()
    println(problem085c(n, y))
}

fun problem085c(n: Int, y: Long): String {
    for (i in 0..n) {
        for (j in 0..n) {
            if (i + j > n) break
            val k = n - i - j
            if (i + j + k == n && i * 10000L + j * 5000L + 1000L * k == y) {
                return "$i $j $k"
            }
        }
    }
    return "-1 -1 -1"
}

Measured memory_bytes: 31392
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

// inf
constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> red(n), blue(n);
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        red[i] = {x, y};
    }
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        blue[i] = {x, y};
    }
    sort(blue.begin(), blue.end());
    int ans = 0;
    for (const auto &b : blue) {
        int maxy = -inf;
        auto matched = red.end();
        for (auto it = red.begin(); it != red.end(); ++it) {
            if ((*it).first < b.first && (*it).second < b.second && (*it).second > maxy) {
                matched = it;
                maxy = (*it).second;
            }
        }
        if (matched != red.end()) {
            ++ans;
            red.erase(matched);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//深さ優先探索のテンプレ.デフォルトでは参照渡ししたsetに探索済みの頂点が格納される.
//graphは隣接リスト.vは探索開始地点.seenは空のセット
void dfs(vector<vector<int>> &graph, int v,vector<ll> &ans,ll now,set<int> seen){
	seen.insert(v);
	ans[v] += now;
	for (int i = 0; i < graph[v].size(); i++)
	{
		int nxt = graph[v][i];
		if (seen.count(nxt)) continue;
		dfs(graph, nxt, ans,ans[v],seen);
	}
}

int main(){
	int n;
	cin >> n;
	priority_queue<double, vector<double>, greater<double>> que;
	rep(i,n){
		double a;
		cin >> a;
		que.push(a);
	}
	while (que.size() != 1)
	{
		double a, b;
		a = que.top();
		que.pop();
		b = que.top();
		que.pop();
		que.push((a + b) / 2);
	}
	cout << que.top() << endl;

	return 0;
}



Measured memory_bytes: 256
N=int(input())
V=list(map(int,input().split()))
C=list(map(int,input().split()))
dif=[]
count=0
for i in range(N):
    dif.append(int(V[i]-C[i]))

dif.sort(reverse=True)

i=0
for i in range(N):
    if dif[i]>=0:
        count=count+dif[i]
    else:
        break

print(count)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp> 
//using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define f2(i,a,b) for(int i=a;i>b;i--)
#define f3(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define ncr(n,r) fact[n]*modInv(fact[r])*modInv(fact[n-r])
#define mod 1000000007
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define make_graph(k) int x,y; f0(i,0,k){cin>>x>>y; adj[x].pb(y); adj[y].pb(x);}
#define test int t;cin>>t;while(t--)

signed main()
{
    fast

    int n;
    cin>>n;

    vector<int> a(n);
    f0(i,0,n) cin>>a[i];

    sort(all(a),greater<int>());
    int ans = 0;
    int cur = 1;
    f0(i,1,n)
    {
        ans += a[i-1];
        cur++;
        if(cur==n) break;
        ans += a[i];
        cur++;
        if(cur==n) break;
    }
    cout<<ans;
}

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

using namespace std;

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

    int a, b;
    cin >> a >> b;

    int cur = 1;
    int ans = 0;
    while (cur < b) {
        cur += a - 1;
        ans++;
    }

    cout << ans << endl;
}

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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    int H[N];
    int A[M];
    int B[M];

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

    for (int j = 0; j < M; ++j) {
        int tmpA, tmpB;
        cin >> tmpA >> tmpB;
        A[j] = tmpA;
        B[j] = tmpB;
    }

    bool isAlive[N];
    for (int k = 0; k < N; ++k) {
        isAlive[k] = true;
    }

    for (int l = 0; l < M; ++l) {
        if(H[A[l] - 1] > H[B[l] - 1]){
            isAlive[B[l]- 1] = false;
        }else if(H[A[l] - 1] < H[B[l] - 1]){
            isAlive[A[l] - 1] = false;
        } else{
            isAlive[A[l] - 1] = false;
            isAlive[B[l] - 1] = false;
        }
    }

    int count = 0;

    for (int m = 0; m < N; ++m) {
        if(isAlive[m]){
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 4428
#include <iostream>
#include <iomanip>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=2e6+5;

int prime[MAX+1];
bool isp[MAX+1];

int main(){
	//入力
	lli M,Q;
	cin >>M>>Q;
	if(M==1){
		cout<<Q;
		return 0;
	}
	
	lli N=sqrt(Q);
	int p = 0;
	//初期化
	for(int i=0;i<=N;i++)
		isp[i]=true;
	isp[0]=isp[1]=false;
	//2以上で素数ならふるい落とす
	for(int i=2;i<=N;i++){
		if(isp[i]){
			p++;
			prime[p]=i;
			for(int j=2*i;j<=N;j+=i) isp[j]=false;
		}
	}
	
	int ans=1;
	rep1(i,p){
		lli t=Q;
		int x=0;
		while(t%prime[i]==0){
			x++;
			t/=prime[i];
		}
		ans*=pow(prime[i],x/M);
	}
	cout<<ans;
	
}


Measured memory_bytes: 3328
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <functional>
#include <numeric>
#include <math.h>
#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(void) {
	double D, T, S;
	cin >> D >> T >> S;
	if (D / S <= T) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3720
list = STDIN.gets.strip.split(/\s/).map(&:to_i)
# p list
# p list.sort.reverse

sortReverse = list.sort.reverse

sum  = 0
cost = 0
for i in 0..2 do
    if i == 0 then
      cost = 0
    else
      cost = sortReverse[i-1] - sortReverse[i]
    end
    sum = sum + cost
    # puts  "sum: #{sum}"
    # puts "i: #{i}"
    # p sortReverse[i]
end

p sum

Measured memory_bytes: 1788
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;

int main()
{
  int m, mn, mx;
  while(cin>>m>>mn>>mx) {
    if(m == 0) return 0;
    int p[m];
    FOR(i,0,m) cin >> p[i];
    int mxsa = 0;
    int ans = 0;
    FOR(i,mn,mx+1) {
      if(p[i-1] - p[i] >= mxsa) {
        mxsa = p[i-1] - p[i];
        ans = i;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int main()
{
    int a, b;
    cin >> a >> b;
    if (a <= 5)
        OP(0);
    else if (6 <= a && a <= 12)
        OP(b / 2);
    else
        OP(b);
    return 0;
}

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

int main(){
  long long H, W;
  cin >> H >> W;
  long long a[H][W];
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++)
      cin >> a[i][j];
  }
  long long count = -1;
  long long answer[H * W][4];
  for (int i = 0; i < H; i++){
    for (int j = 0; j < W; j++){
      if (i == H - 1 && j == W - 1)
        break;
      if (i % 2 == 0){
        if (a[i][j] % 2 == 1){
          count += 1;
          a[i][j] -= 1;
          answer[count][0] = i;
          answer[count][1] = j;
          if (j == W - 1){
            a[i + 1][j] += 1;
            answer[count][2] = i + 1;
            answer[count][3] = j;
          }
          else{
            a[i][j + 1] += 1;
            answer[count][2] = i;
            answer[count][3] = j + 1;
          }
        }
      }
      else{
        if (a[i][W - 1 - j] % 2 == 1){
          count += 1;
          a[i][W - 1 - j] -= 1;
          answer[count][0] = i;
          answer[count][1] = W - 1 - j;
          if (j == W - 1){
            a[i + 1][W - 1 - j] += 1;
            answer[count][2] = i + 1;
              answer[count][3] = W - 1 - j;
          }
          else{
            a[i][W - 2 - j] += 1;
            answer[count][2] = i;
            answer[count][3] = W - 2 - j;
          }
        }
      }
    }
  }
  cout << count + 1 << endl;
  for (int i = 0; i < count + 1; i++){
    cout << answer[i][0] + 1 << " " << answer[i][1] + 1 << " " << answer[i][2] + 1 << " " << answer[i][3] + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 9472
#include <cstdio>
#include <cstdlib>
#include <algorithm>
int main()
{
	char buf[16];
	int v[8];
	int n = atoi(fgets(buf, 16, stdin));
	while (n--) {
		fgets(buf, 16, stdin);
		std::sort(buf, buf + 8);
		int a = atoi(buf);
		std::reverse(buf, buf + 8);
		int b = atoi(buf);
		printf("%d\n", b - a);
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] ary = sc.next().toCharArray();
		int num=0;
		for (char c : ary) {
			if(c == '+') num++;
			else num--;
		}
		System.out.println(num);
	}
}



Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int g[100010];
vector<int> to[100010];

class UnionFind {
  public:
    // 親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> Parent;

    // 作る時はParentの値を全て-1にする
    // こうすると全てバラバラが表現できる。
    UnionFind(int N) {
      Parent = vector<int>(N, -1);
    }

    // Aがどのグループに属しているか調べる
    int root(int A) {
      if(Parent[A] < 0) return A;
      return Parent[A] = root(Parent[A]);
    }

    int size(int A) {
      return -Parent[root(A)]; // 親を取ってきたい
    }

    bool connect(int A, int B) {
      // AとBを直接繋ぐのではなく、root(A)をroot(B)をくっつける
      A = root(A);
      B = root(B);
      if(A == B) {
        //すでにくっついているからくっつけない
        return false;
      }

      // 大きい方に小さい方をくっつけたい
      // 代償が逆だったらひっくり返す
      if(size(A) < size(B)) swap(A, B);
      // Aのsizeを更新
      Parent[A] += Parent[B];
      // Bの親をAに変更する
      Parent[B] = A;

      return true;
    }

    bool same(int A, int B) {
      return root(A) == root(B);
    }
};

int main() {
  int N, M, K; cin >> N >> M >> K;
  UnionFind uni(N);
  for(int i = 0; i < M; i++) {
    int a, b; cin >> a >> b; a--, b--;
    g[a]++; g[b]++;
    uni.connect(a, b);
  }

  for(int i = 0; i < K; i++) {
    int a, b; cin >> a >> b; a--, b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }

  for(int i = 0; i < N; i++) {
    int ans = uni.size(i) - 1 - g[i];
    for(int u: to[i]) {
      if(uni.same(i, u)) ans--;
    }
    cout << ans;
    if(i == N-1) cout << endl;
    else cout << " ";
  }
  return 0;
}


Measured memory_bytes: 6784
from math import factorial as f
n, m = map(int, input().split())
mod = 10 ** 9 + 7
if abs(n - m) == 1:
    res = f(n) * f(m)
    print(res % mod)
elif n == m:
    res = f(n) * f(m) * 2
    print(res % mod)
else:
    print(0)


Measured memory_bytes: 11024
n, m, x = map(int, input().split())
a = [int(i) for i in input().split()]

a.append(x)
a.sort()
position = a.index(x)+1

if position == 0 or position == m+1:
	print(0)
else:
	if (m+1)-position <= (m+1)/2:
		print(m+1-position)
	else:
		print(position-1)

Measured memory_bytes: 3060
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

#DIV = (10**9) + 7
DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N= iRaw()
    ans = 0
    for i in range(1,N+1):
        d = N//i
        ans+=i*d*(d+1)//2
    print(ans)

main()

Measured memory_bytes: 67912
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N, M;
  cin >> N >> M;
  priority_queue<long> pq;
  rep (i, N) {
    long A;
    cin >> A;
    pq.push(A);
  }
  rep (i, M) {
    long current = pq.top();
    pq.pop();
    current /= 2;
    pq.push(current);
  }
  long ans = 0;
  while (pq.size()) {
    long current = pq.top();
    pq.pop();
    ans += current;
  }
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 1400
#include<cstdio>
#include<iostream>
#include<vector>
#include<tuple>
#include<queue>
#include<algorithm>
#include<string.h>
#include<math.h>

using namespace std;


int main(int argc, char* argv[]){
  long long int K;
  scanf("%lld", &K);
  long long int ans;
  if(K%2 == 0){
    ans = (K/2) * (K/2);
  }
  else{
    ans = ((K/2)+1)*(K/2);
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 764
/*ヽ｀、ヽ｀｀、ヽ｀ヽ｀、、ヽ ｀ヽ 、ヽ｀｀ヽヽ｀ヽ、ヽ｀
ヽ｀、ヽ｀｀、ヽ 、｀｀、 ｀、ヽ｀ 、｀ ヽ｀ヽ、ヽ ｀、ヽ｀｀、
ヽ、｀｀、｀、ヽ｀｀、 、ヽヽ｀、｀、、ヽヽ、｀｀、 、 ヽ｀、
ヽ｀｀、 ヽ｀ヽ｀、、ヽ ｀ヽ 、 ヽ｀｀｀｀ヽヽヽ｀、、ヽ｀、、ヽ*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long   ll;
typedef long double ld;
typedef complex< ld > cd;
 
typedef pair<int, int> pi;
typedef pair<ll, ll>   pl;
typedef pair<ld, ld>   pd;
 
typedef vector< int > vi;
typedef vector< ld >  vd;
typedef vector< ll >  vl;
typedef vector< pi >  vpi;
typedef vector< pl >  vpl;
typedef vector< cd >  vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a)    for (int i=0; i<(a); i++)
#define rep1(i, a, b) for (int i = (b)-1; i >= a; i--)
#define rep(i, a)     for (int i = (a)-1; i >= 0; i--)
#define trav(a, x)    for (auto& a : x)
#define uid(a, b)     uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f  first
#define s  second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	  int n;
 	 cin >> n;
 	 vector<int> v(n);
 	 for(int i=0;i<n;i++){
 	   cin>>v[i];
	  }
	  sort(v.begin(),v.end());
	  double ans=v[0];
	  for(int i=0;i<n-1;i++){
	    ans=(ans+(double)v[i+1])/(double)2;
	  }
	  cout<<ans<<endl;
		return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3780
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String s=sc.next();
		sc.close();


		if(s.equals("zyxwvutsrqponmlkjihgfedcba"))
			System.out.print(-1);
		else {


			int n= s.length();
			char ch[]=new char[n+1];
			for(int i=0;i<n;i++) {
				ch[i]=s.charAt(i);
			}
			ch[n]=0;

			if(n==26) {
				int shou=0;
				for(int i=25;i>=0;i--) {
					if(ch[i]>ch[i-1]) {
						shou=i-1;
						break;
					}
				}
				for(int i=25;i>shou;i--) {
					if(ch[i]>ch[shou]) {
						ch[shou]=ch[i];
						break;
					}
				}

				for(int i=0;i<=shou;i++) {
					System.out.print(ch[i]);
				}
			}
			else {
				boolean hantei=true;
				for(char c=97;c<=123;c++) {
					for(int j=0;j<n;j++) {
						if(c==ch[j]) {
							hantei=false;
							break;
						}
					}
					if(hantei) {
						ch[n]=c;
						break;
					}
					hantei=true;
				}

				for(int i=0;i<=n;i++) {
					System.out.print(ch[i]);
				}
			}
		}

	}

}


Measured memory_bytes: 23124
/*input
2
*/
#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define MAX 100005
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define ff first
#define ss second
#define T int t;cin>>t;while(t--)
using namespace std;

int sum(int n){
    return (n*(n+1))/2;
}

signed main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                ans += __gcd(__gcd(i,j),k);
            }
        }
    }
    cout << ans << '\n';
}


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

int main(){

    int k,x;
    cin>>k>>x;

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







    return 0;
}

Measured memory_bytes: 256
import math

A, B, H, M = map(int, input().split())

theta = abs(30 * H + 0.5 * M - 6 * M)
if theta > 180:
    theta = 360 - theta

ans = math.sqrt(A ** 2 + B ** 2 - (2 * A * B * math.cos(math.radians(theta))))
print(ans)

Measured memory_bytes: 9416
N, A, B = map(int, input().split())
S = input()

ps = A + B
a,b = 0,0
for i in range(N):
    if S[i] == "c" or a >= ps:
        print("No")
        continue
    if S[i] == "b":
        b += 1
        if b > B:
            print("No")
            continue
    a += 1
    print("Yes")

Measured memory_bytes: 9240
#include<iostream>
#include<string>
#include<vector>

struct rl{
	int idx;
	int r;
	int l;
};

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

	std::vector<rl> rlList;
	std::vector<int> ansList(s.size(), 0);

	for(int i=0; i<s.size()-1; i++)
		if(s[i]=='R' && s[i+1]=='L')
			rlList.push_back({i,0,0});


	for(int i=0; i<rlList.size(); i++){
		for(int j= rlList[i].idx; j>=0; j--){
			if(s[j]!='R')
				break;

			if((rlList[i].idx-j) % 2 == 0)
				rlList[i].r++;
			else
				rlList[i].l++;
		}

		for(int j= rlList[i].idx+1; j<s.size(); j++){
			if(s[j]!='L')
				break;

			if((j-rlList[i].idx) % 2 == 0)
				rlList[i].r++;
			else
				rlList[i].l++;
		}
	}

	for(int i=0; i<rlList.size(); i++){
		ansList[rlList[i].idx]= rlList[i].r;
		ansList[rlList[i].idx+1]= rlList[i].l;
	}

	for(int i=0; i<ansList.size(); i++)
		std::cout<<ansList[i]<<" ";
	std::cout<<std::endl;
}

Measured memory_bytes: 1724
#include<bits/stdc++.h>
//#define local
#define forn(a,n) for(int i = a; i < n; i++)


using namespace std;

typedef long long int ll;
typedef vector<int> vec;
typedef vector<ll> vecl;
typedef unsigned long long int ull;
typedef vector<ull> vecu;


void print(const vec &a)
{
    forn(0,a.size())
        cout << a[i] << " ";
    cout << "\n";
}


void solve()
{
  int n;
  cin >> n;
  vecl a(n);
  forn(0, n)
    cin >> a[i];
    ll ans = 0;
   forn(1,n)
   {
       if(a[i] < a[i - 1])
        {
            ans += a[i-1] - a[i];
            a[i] = a[i-1];
        }
   }
   cout << ans;
   
    
}

int main()
{
    #ifdef local
        freopen("input.txt", "r", stdin);
    #endif

        solve();
}

Measured memory_bytes: 4836
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    set<string> list;
    map<string, int> S, T;

    int N; cin >> N;
    REP(i, 0, N) {
        string s; cin >> s;
        S[s]++;
        list.insert(s);
    }

    int M; cin >> M;
    REP(i, 0, M) {
        string t; cin >> t;
        T[t]++;
        list.insert(t);
    }

    int yen = 0;
    for (auto itr = list.begin(); itr != list.end(); itr++) {
        yen = max(yen, S[*itr] - T[*itr]);
    }
    cout << yen << endl;


    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class UF_tree:
    def __init__(self, n):
        self.root = [-1] * (n + 1)  # -1ならそのノードが根,で絶対値が木の要素数
        self.rank = [0] * (n + 1)

    def find(self, x):  # xの根となる要素番号を返す
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find(self.root[x])
            return self.root[x]

    def isSame(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.rank[x] < self.rank[y]:
            self.root[y] += self.root[x]
            self.root[x] = y
        else:
            self.root[x] += self.root[y]
            self.root[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def size(self, x):
        return -self.root[self.find(x)]


if __name__ == "__main__":
    N, M = map(int, input().split())
    uf = UF_tree(N)
    edge = [0] * (N + 1)
    for _ in range(M):
        a, b = map(int, input().split())
        uf.unite(a, b)
        edge[a] += 1
        edge[b] += 1

    x_root = uf.size(1)
    y_root = uf.size(2)
    if x_root < y_root:
        t = 2
    else:
        t = 1

    ans = 0
    other = N - uf.size(1) - uf.size(2)  # 1とも2ともつながってないやつ
    for x in range(1, N + 1):
        if uf.isSame(x, 1):
            if t == 2:
                other_v = 0
            else:
                other_v = other
            self_v = uf.size(1) - edge[x] - 1
            ans += other_v + self_v
        elif uf.isSame(x, 2):
            if t == 1:
                other_v = 0
            else:
                other_v = other
            self_v = uf.size(2) - edge[x] - 1
            ans += other_v + self_v
        else:
            root_v = uf.size(t)
            other_v = other - edge[x] - 1
            ans += other_v + root_v

    print(ans//2)

Measured memory_bytes: 6900
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(li i=0;i<n;i++)
#define li long long int
#define ll long long int
#define pb push_back
#define all(v) sort(v.begin(),v.end())
const int N = 40043;
const ll mod = 1e9 + 7;
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define f first
#define s second
int gcd(int a,int b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    return (a*b)/gcd(a,b);
}
li pow(li a,li b,li mo)
{
    if(a==0)
    return 1;
    li u=pow(a,b/2,mo);
    u=(u%mod*u%mod)%mo;
    if(b%2==1)
    u=(u%mod*a%mod)%mod;
    return u;
}
ll power(ll a,ll b)
{
    ll ans=1;
	while(b)
	{
		if(b&1) ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}
 
li xx,yy,dd;
void equation(li a,li b)
{
    if(b==0)
    {
        xx=1;
        yy=0;
        dd=a;
    }
    else
    {
        equation(b,a%b);
        li temp=xx;
        xx=yy;
        yy=temp-(a/b)*yy;
    }
}
li inverse(li a,li m)
{
    equation(a,m);
    return(xx%m+m)%m;
}
bool compare(const char &i, char &j)
{
    
    return i > j;
    
}
void solve()
{
   li n;
   cin>>n;
   li a[n];
   rep(i,n)
   cin>>a[i];
   li dp[n],dp1[n];
   dp[0]=0;
   for(li i=1;i<n;i++)
   {
       dp[i]=dp[i-1]^a[i-1];
   }
   dp1[n-1]=0;
   for(li i=n-2;i>=0;i--)
   {
       dp1[i]=dp1[i+1]^a[i+1];
   }
   rep(i,n)
   {
       li o=dp[i]^dp1[i];
       cout<<o<<" ";
   }
   
       
   
}
int main()
{
    li t;
    t=1;
    while(t--)
    solve(),cout<<endl;
    
}

Measured memory_bytes: 8256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main(void) {
	string a, b, c; cin >> a >> b >> c;
	int x = 0, y = 0, z = 0;

	char q = a[0]; x += 1;

	while (1) {
		if (q == 'a') { q = a[x]; x++; }
		else if (q == 'b') { q = b[y]; y++; }
		else if (q == 'c') { q = c[z]; z++; }

		if (x > a.size()) { cout << "A" << endl; return 0; }
		if (y > b.size()) { cout << "B" << endl; return 0; }
		if (z > c.size()) { cout << "C" << endl; return 0; }
	}
	return 0;
}



Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main {
    public static void main(String[] args) {
        try {
        	BufferedReader kb = new BufferedReader( new InputStreamReader( System.in ) );
        	
        	int n = Integer.parseInt( kb.readLine( ) );
        	Set<String> dict = new HashSet<String>();
			String[] str = new String[3];
			for( int i=0; i<n; i++ ) {
				str = kb.readLine( ).split( " " );
				if( "insert".equals( str[0] ) ) {
					dict.add( str[1] );
				} else if( "find".equals( str[0] ) ) {
					if( dict.contains( str[1] ) ) {
						System.out.println( "yes" );
					} else {
						System.out.println( "no" );
					}
				}
			}
        } catch( IOException e ) {
            System.err.println( e );
        }
    }
}

Measured memory_bytes: 323248
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        boolean flg = true;

        ArrayList<Integer> intList = new ArrayList<Integer>();

         while(flg) {

            int n = scan.nextInt();
            int m = scan.nextInt();
            int p = scan.nextInt();

            scan.nextLine();

               // 選手数
            int num = 0;
            int xm = 0;

            if (n == 0 && m == 0 && p == 0) {
                flg = false;
            } else {
                for (int i = 0; i < n; i++) {
                    int x = scan.nextInt();

                    if (i == m - 1) {
                        xm = x;
                    }
                    num = num + x;
                }
                scan.nextLine();

                int y = 0;

                if (xm != 0) {
                    y = (int)((double)num * (100 - p) / xm);
                }

                intList.add(y);
            }
        }
        

        scan.close();

        for(int j : intList) {
            System.out.println(j);
        }
    }
}


Measured memory_bytes: 40300