akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#pragma optimize("unroll-loops");
#pragma optimize("Ofast");
// #include "pch.h"    
using namespace std;

#ifdef DEBUG_BUILD
#  define DEBUG(x) cerr << x
#else
#  define DEBUG(x) do {} while (1)
#endif

#define imie(x) do { std::cerr << #x << ": " << x << std::endl; } while (0)

using ll = long long;
const ll nax = 1e7 + 10;
const int mod = 1e9 + 7;
vector<int> primes;

int main() {
    
    int x, legs;
    cin >> x >> legs;
    
    
    for(int a = 0; a <= 1000; ++a) {
        for(int b = 0; b <= 1000; ++b) {
            if(2*a + 4*b == legs) {
                if(a + b == x) {
                    cout << "Yes\n";
                    return 0;
                }
            }
        }
    }
    
    cout << "No\n";
}





















Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define INIT(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define INIT2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

#define umap unordered_map
//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}


string p[4] = {"dream", "dreamer", "erase", "eraser"};

int main(){
  string s; cin>>s;
  reverse(ALL(s));
  REP(i,4){ reverse(ALL(p[i])); }
  int s_size = s.size();
  bool r = false;
  while(1){
    string p5 = s.substr(0,5);
    string p6 = s.substr(0,6);
    string p7 = s.substr(0,7);
    if(p5==p[0] || p5==p[2]){
      if(s_size==5){ r = true; break;}
      s_size -= 5;
      s = s.substr(5,s_size);
    }else if(p6==p[3]){
      if(s_size==6){ r = true; break;}
      s_size -= 6;
      s = s.substr(6,s_size);
    }else if(p7==p[1]){
      if(s_size==7){ r = true; break;}
      s_size -= 7;
      s = s.substr(7,s_size);
    }else{break;}
  }
  cout << (r?LINY:LINN);
}

Measured memory_bytes: 512
import java.util.Scanner;

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

		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int area = a * b;
		int round = (a + b) * 2;
		System.out.println(area + " " + round);

	}
}

Measured memory_bytes: 17160
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>

using namespace std;

int main()
{
    int N, A;
    if (scanf("%d%d", &N, &A) < 2) return 0;

    printf("%s\n", A < N % 500 ? "No" : "Yes");

    return 0;
}


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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

vector<LL> find_divisors(LL n) {
  vector<LL> res;
  for (LL i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) {
        res.push_back(n / i);
      }
    }
  }
  return res;
}

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

  LL ans = 0;

  auto v1 = find_divisors(n - 1);
  ans += sz(v1) - 1;

  auto v2 = find_divisors(n);
  for (auto &d : v2) {
    if (d == 1) {
      continue;
    }
    LL m = n;
    while (m % d == 0) {
      m /= d;
    }
    if (m % d == 1) {
      ans++;
    }
  }

  cout << ans << '\n';

  return 0;
}

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

#define ll long long
#define ar array

void solve() {
}

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

  int X, Y;
  cin >> X >> Y;
  for (int i=0; i<=X; i++) {
    if (4*i + 2*(X-i) == Y) {
      cout << "Yes" << "\n";
      return 0;
    }
  }
  cout << "No"  << "\n";
  return 0;
}


Measured memory_bytes: 3676
#include <stdio.h>

#define TRUE 1
#define FALSE 0

int judge_hit(int *r, int *a) {
    int hit;
    int i;
    
    hit = 0;
    for(i = 0; i < 4; i++){
        if (r[i] == a[i]){
            hit++;
        }
    }   

    return hit;
}

int judge_blow(int *r, int *a){
    int blow;
    int i,j;
    
    blow = 0;
    for(i = 0; i < 4; i++){
        for(j = 0; j < 4; j++){
            if((i != j) && (r[i] == a[j])){
                blow++;
            }
        }
    }   

    return blow;
}

int main(){
    char buf[40];
    int r[4],a[4];
    int i;
    
    while(1){
        fgets(buf,40,stdin);

        if(buf[0] == '0' && buf[1] == ' ' && buf[2] == '0'){
            break;
        }

        for(i=0;i<4;i++){
            r[i] = buf[i]   - 48;
            a[i] = buf[i+5] - 48;
        }
        
        printf("%d %d\n",judge_hit(r,a),judge_blow(r,a));
    }
    
    return 0;
}

Measured memory_bytes: 524
s = input()
t = input()
slen = len(s)
tlen = len(t)
ans = 10**20
temp = 0

for start in range(0,slen-tlen+1):
    temp = 0
    for i in range(0,tlen):
        if t[i] != s[start+i]:
            temp += 1
    ans = min(ans,temp)
print(ans)


Measured memory_bytes: 9108
#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 PI 3.14159265359
#define eps (1e-8)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.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("input.txt");ofstream coutt("output.txt");

string k;
int D;
int dp[10000][100][2];

int f(int indx,int sum,int nine){
    if(indx==k.size())return sum==0;
    if(dp[indx][sum][nine]!=-1)return dp[indx][sum][nine];
    int ans=0;
    int e = nine?9:(k[indx]-'0');
    for(int i=0;i<=e;i++){
        ans=(ans+f(indx+1,(sum+i)%D,nine||(i<e)))%MOD;
    }
    return dp[indx][sum][nine]=ans;
}

signed main(){
    FASTER;
    memset(dp,-1,sizeof dp);
    cin>>k>>D;
    cout<<(f(0,0,0)-1+MOD)%MOD;
}

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

#define ll long long
#define pii pair<ll, ll>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define rev(a) reverse(all(a)
bool isPrime(ll n) 
{ 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
    // This is checked so that we can skip 
    // middle five numbers in below loop 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
} 
   
int main() {
    ll n;
    cin >> n;
    if(isPrime(n)){
        cout << n-1 << endl;
    }
    else{
        for(ll i=sqrt(n); i>=1; i--){
            if(n%i==0){
                cout << i+n/i-2 << endl;
                return 0;
            }
        }
    }
	return 0;
}

Measured memory_bytes: 256
// _______  _____  _______  _____  _______ _______ _____ _______ _____ _    _ _______ 
// |       |     | |  |  | |_____] |______    |      |      |      |    \  /  |______ 
// |_____  |_____| |  |  | |       |______    |    __|__    |    __|__   \/   |______ 
//
//  _____   ______  _____   ______  ______ _______ _______ _______ _____ __   _  ______   /
// |_____] |_____/ |     | |  ____ |_____/ |_____| |  |  | |  |  |   |   | \  | |  ____  / 
// |       |    \_ |_____| |_____| |    \_ |     | |  |  | |  |  | __|__ |  \_| |_____| .  
//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
const ll INF=1e18+7;
const ll MOD=1e9+7;

class UnionFind{
public:
	vector<int> par;
	//0-indexed
	void init(int n = 1) {
		par.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i;
	}
	int root(int x = 1){
		if(par[x]==x)return x;
		else{
			return par[x] = root(par[x]);
		}
	}
	void unite(int x = 1,int y = 1){
		x = root(x);
		y = root(y);
		if(x==y)return;
		else par[x] = y;
	}
};

int main(){
	int N , M;
	cin >> N >> M;
	UnionFind uf;
	uf.init(N+1);
	vector<int> lang[M+1];
	FOR(i,1,N+1){
		int k;
		cin>>k;
		FOR(j,0,k){
			int la;
			cin >> la;
			lang[la].push_back(i);
		}
	}
	FOR(i,1,M+1){
		FOR(j,0,(int)lang[i].size()-1){
			uf.unite(lang[i][j],lang[i][j+1]);
		}
	}
	set<int> se;
	FOR(i,1,N+1){
		se.insert(uf.root(i));
	}
	if(se.size()==1){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 4608
#include <iostream>
#include <vector>
#include <cstring>
#include <cctype>
#include <string>
#include <cmath>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;

int main(){
	int n;
	double sum=0, ave,ss=0;
	while (1){
		cin >> n;
		if (n == 0)
			break;
		sum = 0;
		ss = 0;
		ave = 0;
		vector<int>v(n);
		for (auto pv = v.begin(); pv != v.end(); ++pv){
			cin >> *pv;
			sum += *pv;
			ss += *pv * *pv;
		}
		ave = sum / n;
		ss -= n*ave*ave;
		ss /= n;
		cout <<sqrt(ss)<<endl;
	}


}

Measured memory_bytes: 1264
n = int(input())
a = list(map(int, input().split()))
l, r = 1, n * 2
while r - l > 1:
    m = (l + r) // 2
    li = [0] * (2 * n - 1)
    for i in range(2 * n - 1):
        if a[i] >= m:
            li[i] = 1
    t = li[n - 1]
    for i in range(n - 1):
        if ((t + li[n + i] + i) & 1 == 0):
            if li[n + i] & 1:
                l = m
            else:
                r = m
            break
        if((t + li[n - i - 2] + i) & 1 == 0):
            if li[n - i - 2] & 1:
                l = m
            else:
                r = m
            break
    else:
        if (n + t) & 1:
            r = m
        else:
            l = m
print(l)


Measured memory_bytes: 25776
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
const ll N = 105, INF = 1e18;
int n, source, sink;
ll a[N], par[N];
ll cap[N][N];
vector<int> adj[N];
 
ll bfs(int source, int sink) {
	memset(par, -1, sizeof par);
	par[source] = -2;
	queue<pair<int, ll>> q;
	q.push({source, INF});
	while(!q.empty()) {
		ll u = q.front().first, flow = q.front().second;
		q.pop();
		for(auto& v : adj[u]) {
			if(par[v] == -1 && cap[u][v]) {
				par[v] = u;
				ll new_flow = min(flow, cap[u][v]);
				if(v == sink) return new_flow;
				q.push({v, new_flow});
			}
		}
	}
	return 0;
}

ll maxflow(int source, int sink) {
	ll flow = 0;
	ll newFlow;
	while((newFlow = bfs(source, sink))) {
		flow += newFlow;
		int u = sink;
		while(u != source) {
			int v = par[u];
			cap[v][u] -= newFlow;
			cap[u][v] += newFlow;
			u = v;
		}
	}
	return flow;
}
 
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	source = n+1; sink = n+2;
	ll ideal = 0;
	for(int i = 1; i <= n; i++)
		cin >> a[i], ideal += (a[i]>0)?a[i]:0;
	memset(cap, 0, sizeof cap);
	for(int i = 1; i <= n; i++) {
		if(a[i] < 0) adj[source].push_back(i), adj[i].push_back(source), cap[source][i] = -a[i];
		else adj[i].push_back(sink), adj[sink].push_back(i), cap[i][sink] = a[i];
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 2*i; j <= n; j+=i)
			adj[i].push_back(j), adj[j].push_back(i), cap[i][j] = INF;
	}
	ll mf = maxflow(source, sink);
	ll ans = ideal - mf;
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
int n,k,a[100002],dp[100002];
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)	cin>>a[i];
	memset(dp,0x3f3f3f3f,sizeof(dp));
	dp[1]=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=k;j++)
			if(i-j>0)
				dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
	cout<<dp[n]<<endl;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);
  int row, col;
  cin >> row >> col;

  vector<string> maze(row);
  rep(i, row) {
    cin >> maze[i];
  }

  int distance[50][50];
  fill(&distance[0][0], &distance[50][0], -1);
  distance[0][0] = 0;
  queue<pair<int, int>> q;
  q.push(pair<int, int>(0, 0));
  while (q.size() > 0) {
    pair<int, int> pos = q.front();
    q.pop();
    int y = pos.first;
    int x = pos.second;
    pair<int, int> dest[4] {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    for (auto& d : dest) {
      int n_y = y + d.first;
      int n_x = x + d.second; 
      if (0 <= n_y && n_y < row && 0 <= n_x && n_x < col &&
          distance[n_y][n_x] == -1 && maze[n_y][n_x] == '.') {
        distance[n_y][n_x] = distance[y][x] + 1;
        q.push(pair<int, int>(n_y, n_x));
      }
    }
  }
  if (distance[row - 1][col - 1] == -1) {
    cout << -1 << endl;
  } else {
    int num_of_black = 0;
    rep(i, row) {
      rep(j, col) {
        if (maze[i][j] == '#') num_of_black++;
      }
    }
    cout << row * col - distance[row - 1][col - 1] - 1 - num_of_black << endl;
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
ABlist = [list(map(int, input().split())) for _ in range(N)]
Alist = []
Blist = []
for A, B in ABlist:
    Alist.append(A)
    Blist.append(B)
Alist.sort()
Blist.sort()

if N % 2 == 1:
    print(Blist[(N+1)//2-1]-Alist[(N+1)//2-1]+1)
else:
    print(Blist[N//2-1]+Blist[N//2] - Alist[N//2-1]-Alist[N//2]+1)


Measured memory_bytes: 129400
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
int N;
const int Nmax = 1e5;
const double INF = 1e17;
double X[Nmax], Y[Nmax];
string D[Nmax];

int main(){
	cin >> N;
	for(int i=0; i<N; i++) cin >> X[i] >> Y[i] >> D[i];

	vector<double> ts(1, 0);

	double rmin=INF, rmax=-INF;
	double lmin=INF, lmax=-INF;
	double xmin=INF, xmax=-INF;
	double umin=INF, umax=-INF;
	double dmin=INF, dmax=-INF;
	double ymin=INF, ymax=-INF;
	for(int i=0; i<N; i++){
		if(D[i]=="R"){
			rmin = min(rmin, X[i]);
			rmax = max(rmax, X[i]);
			ymin = min(ymin, Y[i]);
			ymax = max(ymax, Y[i]);
		}
		if(D[i]=="L"){
			lmin = min(lmin, X[i]);
			lmax = max(lmax, X[i]);
			ymin = min(ymin, Y[i]);
			ymax = max(ymax, Y[i]);
		}
		if(D[i]=="U"){
			umin = min(umin, Y[i]);
			umax = max(umax, Y[i]);
			xmin = min(xmin, X[i]);
			xmax = max(xmax, X[i]);
		}
		if(D[i]=="D"){
			dmin = min(dmin, Y[i]);
			dmax = max(dmax, Y[i]);
			xmin = min(xmin, X[i]);
			xmax = max(xmax, X[i]);
		}
	}

	//cout << dmax << " " << umax << endl;

	if(rmax<lmax){
		ts.push_back((lmax-rmax)/2.0);
	}
	if(xmax<lmax){
		ts.push_back(lmax-xmax);
	}
	if(rmax<xmax){
		ts.push_back(xmax-rmax);
	}
	if(rmin<lmin){
		ts.push_back((lmin-rmin)/2.0);
	}
	if(rmin<xmin){
		ts.push_back(xmin-rmin);
	}
	if(xmin<lmin){
		ts.push_back(lmin-xmin);
	}
	if(umax<dmax){
		ts.push_back((dmax-umax)/2.0);
	}
	if(ymax<dmax){
		ts.push_back(dmax-ymax);
	}
	if(umax<ymax){
		ts.push_back(ymax-umax);
	}
	if(umin<dmin){
		ts.push_back((dmin-umin)/2.0);
	}
	if(ymin<dmin){
		ts.push_back(dmin-ymin);
	}
	if(umin<ymin){
		ts.push_back(ymin-umin);
	}

	double ans = INF;
	for(double t: ts){
		if(t<0||t>1e10) continue;
		double xmin=INF, xmax=-INF, ymin=INF, ymax=-INF;
		for(int i=0; i<N; i++){
			if(D[i]=="R"){
				xmin = min(xmin, X[i]+t);
				xmax = max(xmax, X[i]+t);
				ymin = min(ymin, Y[i]);
				ymax = max(ymax, Y[i]);
			}
			if(D[i]=="L"){
				xmin = min(xmin, X[i]-t);
				xmax = max(xmax, X[i]-t);
				ymin = min(ymin, Y[i]);
				ymax = max(ymax, Y[i]);
			}
			if(D[i]=="U"){
				xmin = min(xmin, X[i]);
				xmax = max(xmax, X[i]);
				ymin = min(ymin, Y[i]+t);
				ymax = max(ymax, Y[i]+t);
			}
			if(D[i]=="D"){
				xmin = min(xmin, X[i]);
				xmax = max(xmax, X[i]);
				ymin = min(ymin, Y[i]-t);
				ymax = max(ymax, Y[i]-t);
			}
		}
		//cout << t << " " << xmax << " " << xmin << " " << ymax << " " << ymin << endl;
		ans = min(ans, (xmax-xmin)*(ymax-ymin));
	}

	cout << setprecision(15) << fixed << ans << endl;

	return 0;
}


Measured memory_bytes: 7296
//arc076_d.cpp
//Wed Jan 15 22:47:15 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;

int n;

//Union-Find木
int par[400010]; //親
int treerank[400010]; //木の深さ

//n要素で初期化
void init(int n){
	for (int i=0;i<n;i++){
		par[i] = i;
		treerank[i] = 0;
	}
}

//木の根（親）を見つける
int find (int x){
	if (par[x] == x){
		return x;
	} else {
		return par[x] = find(par[x]);
	}
}

//xとyの属する集合の併合
void unite(int x, int y){
	x = find(x);
	y = find(y);
	if (x == y) {
		return;
	} 

	if (treerank[x] < treerank[y]){
		par[x] = y;
	} else {
		par[y] = x;
		if (treerank[x] == treerank[y]){
			treerank[x]++;
		}
	}
}

//xとyが同じグループに属するか判定
bool same(int x, int y){
	return find(x) == find(y);
}


struct edge{
	int u;
	int v;
	ll cost;
};

vector<edge> es;

bool compedge(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

ll kruskal(){
	sort(es.begin(),es.end(),compedge);
	init(n);
	ll res = 0;
	for (int i=0;i<es.size();i++){
		edge tempe = es[i];
		if (!same(tempe.u, tempe.v)){
			unite(tempe.u, tempe.v);
			res += tempe.cost;
		}
	}
	return res;
}


int main(){
	cin >> n;

	vector<P> xid,yid;
	for (int i=0;i<n;i++){
		ll x,y;
		cin >> x >> y;
		xid.push_back(P(x,i));
		yid.push_back(P(y,i));
	}

	sort(xid.begin(),xid.end());
	for (int i=1;i<n;i++){
		P temp1 = xid[i-1];
		P temp2 = xid[i];
		edge e;
		e.u = temp1.second;
		e.v = temp2.second;
		e.cost = temp2.first-temp1.first;
		es.push_back(e);
	}

	sort(yid.begin(),yid.end());
	for (int i=1;i<n;i++){
		P temp1 = yid[i-1];
		P temp2 = yid[i];
		edge e;
		e.u = temp1.second;
		e.v = temp2.second;
		e.cost = temp2.first-temp1.first;
		es.push_back(e);
	}

	ll ans = kruskal();

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 9572
n = int(input())
con = {"AC":0, "WA":0, "TLE":0, "RE":0}

for i in range(n):
    s = input()
    con[s] += 1

print("AC x {}".format(con["AC"]))
print("WA x {}".format(con["WA"]))
print("TLE x {}".format(con["TLE"]))
print("RE x {}".format(con["RE"]))

Measured memory_bytes: 69844
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
const int MAXN = 100005;

int n; ll now, ans;
bool vis[MAXN];

struct Seg{
	int id, l, r;
	Seg() {}
	Seg( int id, int l, int r ) :
		id(id), l(l), r(r) {}
} lft[MAXN], rght[MAXN];

inline bool lcmp( const Seg &a, const Seg &b ){
	return a.l > b.l;
}

inline bool rcmp( const Seg &a, const Seg &b ){
	return a.r < b.r;
}

inline void solve( int init ){
	now = 0; memset( vis, 0, sizeof vis );
	int L = 1, R = 1, pos = 0;
	for( int i = 1, t = init; i <= n; ++i, t ^= 1 ){
		if( t == 0 ){
			while( vis[lft[L].id] ) ++L;
			vis[lft[L].id] = 1;
			if( pos >= lft[L].l && pos <= lft[L].r ) continue;
			now += abs( lft[L].r - pos );
			pos = lft[L].r;
		} else{
			while( vis[rght[R].id] ) ++R;
			vis[rght[R].id] = 1;
			if( pos >= rght[R].l && pos <= rght[R].r ) continue;
			now += abs( rght[R].l - pos );
			pos = rght[R].l;
		}
	}
	ans = max( ans, now + abs(pos) );
}

int main(){
	scanf( "%d", &n );
	for( int i = 1; i <= n; ++i ){
		int x, y; scanf( "%d%d", &x, &y );
		lft[i] = Seg( i, x, y );
		rght[i] = Seg( i, x, y );
	}
	sort( lft+1, lft+n+1, rcmp );
	sort( rght+1, rght+n+1, lcmp );
	solve(0); solve(1);
	printf( "%lld\n", ans );
	return 0;
}

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

typedef long long ll;

/* メモリ食い過ぎ注意 */
#define int ll
#define ALL(v) v.begin(), v.end()
#define _REP(i, n) for (int i = 0; i < n; i++)
#define REP(n) _REP(i, n)

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n, x;
    int a[100];
    cin >> n >> x;
    REP(n)
    cin >> a[i];

    sort(a, a + n);
    int cnt = 0;
    for (int i = 0; i < n - 1; i++)
    {
        if (x >= a[i])
        {
            cnt++;
            x -= a[i];
        }
    }
    if (x == a[n - 1])
        cnt++;

    cout << cnt << endl;
}

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

#define ln "\n"
#define SORT(X) sort(X.begin(), X.end())
#define SORTi(X) sort(X.begin(), X.end(), greater<ll>())
#define REP(x, a, b) for (auto x = a; x <= b; x++)
#define REPi(x, b, a) for (auto x = b; x >= a; x--)
#define REPit(x, A) for (auto x = A.begin(); x != A.end(); x++)
#define REPr(x, A) for (auto x : A)
#define ll long long
#define ull unsigned long long
#define PB push_back
#define EB emplace_back
#define UMP unordered_map
#define UST unordered_set

using namespace std;

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

    ll N = 0;
    cin >> N;
    ll sum = 0;
    vector<ll> A(N);
    REP(i, 0, N - 1)
    {
        cin >> A[i];
        sum = sum + A[i];
    }
    SORT(A);
    if (sum % 10 == 0)
    {
        REP(i, 0, N-1)
        {
            if (A[i] % 10 != 0)
            {
                sum = sum - A[i];
                cout<<sum;
                return 0;
            }
        }
    }
    if (sum % 10 == 0)
        cout << 0 << ln;
    else
        cout << sum << ln;
    return 0;
}

Measured memory_bytes: 3536
#include<iostream>
#include<cmath>
#include<vector>
#include<bitset>
#include<bitset>
#include<string>
#include<utility>
#include<queue>

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> w(n);
    vector<int> s(n+1);
    s.at(0)=0;
    int sum=0;
    int s1=0,s_2=0;
    for(int i=0;i<n;i++){
        cin >> w.at(i);
        sum+=w.at(i);
        s.at(i+1)=s.at(i)+w.at(i);
    }
    int ans=sum;
    int temp;
    for(int t=1;t<n;t++){
        temp =abs(s.at(t)-(sum-s.at(t)));
        if(ans>temp)ans=temp;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3200
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int swap_log[1000][2];

void swap(int *A, int i, int j) {
  int temp;
  temp = A[i];
  A[i] = A[j];
  A[j] = temp;
}

void Merge(int *A, int left, int mid, int right) {
  int n1,n2,*L,*R,i,j,k;
  n1 = mid -left;
  n2 = right - mid;
  L = (int*)malloc(sizeof(int) * (n1+1));
  R = (int*)malloc(sizeof(int) * (n2+1));
  for (i = 0; i< n1; i++) L[i] = A[left+i];
  for (i = 0; i < n2; i++) R[i] = A[mid+i];
  L[n1] = INT_MAX; R[n2] = INT_MAX;
  i = 0;j = 0;
  for(k = left; k < right; k++) {
    if (L[i] < R[j]) {
      A[k] = L[i];
      i++;
    }else {
      A[k] = R[j];
      j++;
    }
  }
  free(L);
  free(R);
}

void Merge_Sort(int *A, int left, int right) {
  if(left+1 < right) {
    int mid = (left + right)/2;
    Merge_Sort(A,left,mid);
    Merge_Sort(A,mid,right);
    Merge(A,left,mid,right);
  }
}
long step_sort(int *w, int *w1, int i) {
  int j,k;
  long sum = 0;
  k = 0;
  while(w[i] != w1[i]) {
    j = 0;
    while (w[j] != w1[i]) j++;
    sum += w[i]+w[j];
    swap(w,i,j);
    swap_log[k][0] = i; swap_log[k][1] = j;
    i = j;
    k++;
  }
  swap_log[k][0] = 0; swap_log[k][1] = 0;
  return sum;
}

int search_min(int *w, int *w1,int n) {
  int i,j;
  i = 0;
  while(1) {
    j = 0;
    while(w[j] != w1[i]) j++;
    if(i != j) break;
    i++;
    if(i >= n) return n;
  }
  return j;
}

long run_log(int *w) {
  int i = 0;
  long sum = 0;
  while(swap_log[i][0] != swap_log[i][1]) {
    sum += w[swap_log[i][0]]+w[swap_log[i][1]];
    swap(w,swap_log[i][0],swap_log[i][1]);
    i++;
  }
  return sum;
}

long sub_sort(int *w, int *w1, int i) {
  long sum;

  if(w[0] != w1[0]) return LONG_MAX;
  int j = 0;
  while(w[i] != w1[j]) j++;
  sum = w[i] + w[0];
  swap(w,i,0);
  sum += run_log(w);
  sum += w[0] + w[j];
  swap(w,0,j);
  
  return sum;
}

long repeat_sort(int *w, int *w1, int n,long now) {
  int i;
  int a1[n];
  long v1,v2;
  for (i = 0; i < n; i++) a1[i]=w[i];
  i = search_min(w,w1,n);
  if(i == n) return now;
  v1 = step_sort(w,w1,i);
  v2 = sub_sort(a1,w1,i);
  long min = (v1 < v2) ? v1:v2;
  return repeat_sort(w,w1,n,now+min);
}

long much_sort(int *w, int *w1, int n) {
  int i,j;
  long sum = 0;
  char *checked = (char*)calloc(n,sizeof(char));
  i = 0;
  while(i < n) {
    j = 0;
    while(w[j] != w1[i]) j++;
    if(i != j) {
      if(w1[j] ==  w[i]) {
	sum += w[i] + w[j];
	swap(w,i,j);
      }
    }
    checked[i]=1;checked[j]=1;
    while(i < n && checked[i]!=0)i++;
  }
  free(checked);
  return sum;
}

int main()
{
  int i,n,*w,*w2;
  long sum;
  scanf("%d",&n);
  w = (int*)malloc(sizeof(int) * n);
  w2 = (int*)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) {
    scanf("%d",w+i);
    w2[i] = w[i];
  }
  Merge_Sort(w2,0,n);
  
  sum = much_sort(w,w2,n);
  sum += repeat_sort(w,w2,n,0);
  printf("%ld\n",sum);
  
  return 0;
}



Measured memory_bytes: 2840
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second
#define maxsize 1000005
using namespace std;
main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    float n;
    cin>>n;
    float p = 3.14159265359;
    printf("%.20f",2*p*n);
}

Measured memory_bytes: 3800
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

from itertools import accumulate

n,k = li()
a = li()

a_cum = list(accumulate([0] + a))
a_pl = [ai if ai>0 else 0 for ai in a]
a_left = list(accumulate([0] + a_pl))
a_right = list(accumulate([0] + a_pl[::-1]))

ans = 0

for i in range(n-k+1):
    # a[i:i+k]を黒にするとき
    cand = a_cum[i+k] - a_cum[i]
    cand += (a_left[i] + a_right[n-(i+k)])
    ans = max(ans,cand)
    
    
    # a[i:i+k]を白にするとき
    cand = 0
    cand += (a_left[i] + a_right[n-(i+k)])
    ans = max(ans,cand)
    
    
print(ans)

Measured memory_bytes: 25884
chomp(my$n=<>);
my@x=(0)x$n;
my@y=@x;
chomp(my@a=<>);
for(my$i=0;$i<$n;$i++){
 ($x[$i],$y[$i])=split/ /,$a[$i];
}
if($n==1){
 print 1;
}else{
 my%pqh;
 for(my$i=0;$i<$n;$i++){
  for(my$j=0;$j<$i;$j++){
   my($p,$q)=($x[$i]-$x[$j],$y[$i]-$y[$j]);
   $pqh{"$p".'_'."$q"}=1;
  }
 }
 my$min=50;
 foreach(keys%pqh){
  my$c=0;
  my($p,$q)=split/_/;
  my%ha;
  $ha{$_}=1foreach(@a);
  for(my@kha=keys(%ha);keys(%ha)>0;@kha=keys(%ha)){
   $c++;
   my$khai=$kha[0];
   for(my$aip=$khai;;){
    delete$ha{$aip};
    my($xi,$yi)=split/ /,$aip;
    $aip=($xi+$p).' '.($yi+$q);
    last if(!defined$ha{$aip});
   }
   for(my$aim=$khai;;){
    delete$ha{$aim};
    my($xi,$yi)=split/ /,$aim;
    $aim=($xi-$p).' '.($yi-$q);
    last if(!defined$ha{$aim});
   }
  }
  $min=$c if($min>$c);
 }
 print$min;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdint>
#include <map>
#include <unordered_map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <sstream>

#include <boost/range/irange.hpp>
using boost::irange;

#include <boost/utility/string_ref.hpp>
using boost::string_ref;

using namespace std;

template<class T, size_t N, class F>
struct compare_n
{
    F f;
    bool operator() (const T& t1, const T& t2)
    {
        return f(get<N>(t1), get<N>(t2));
    }
};

template<size_t N, class T>
auto make_less_n(const T&)
{
    using t = typename T::value_type;
    using less = std::less<typename tuple_element<N, t>::type>;
    return compare_n<t, N, less>();
}

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

    int64_t n;
    cin >> n;
    vector<int64_t> as(n);
    for(auto& a : as) cin >> a;

    unordered_map<int64_t, int64_t> count;
    
    for(auto a : as){
        count[a]++;
        count[a+1]++;
        count[a-1]++;
    }
    
    cout << max_element(begin(count), end(count), make_less_n<1>(count))->second << '\n';
    
    return 0;
}



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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

lint dp[55][55][2505] = {0};

int main(){
    int n, a;
    cin >> n >> a;
    vector<int> x(n);
    rep(i, n){
        cin >> x[i];
    }
    rep(i, n + 1){
        dp[i][0][0] = 1;
    }
    REP(i, 1, n + 1){
        REP(j, 1, n + 1){
            rep(k, 2505){
                if(k >= x[i - 1]){
                    dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - x[i - 1]];
                }else{
                    dp[i][j][k] = dp[i - 1][j][k];
                }
            }
        }
    }
    lint ans = 0;
    REP(j, 1, n + 1){
        ans += dp[n][j][j * a];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 54400
import java.util.ArrayDeque

fun main(args: Array<String>) {
    val N = readInputLine().toInt()

    val edges = Array(100000) { mutableListOf<Pair<Int, Long>>() }

    for (i in 1 until N) {
        val (a, b, c) = readInputLine().split(" ").map { it.toInt() }
        edges[a - 1].add(Pair(b - 1, c.toLong()))
        edges[b - 1].add(Pair(a - 1, c.toLong()))
    }
    
    val (Q, K) = readInputLine().split(" ").map { it.toInt() - 1 }

    val dist = LongArray(100000) { Long.MAX_VALUE }
    
    val queue = ArrayDeque<Int>()
    queue.add(K)
    dist[K] = 0L
    
    while (!queue.isEmpty()) {
        val now = queue.poll()!!
        
        for ((k, v) in edges[now]) {
            if (dist[k] == Long.MAX_VALUE) {
                dist[k] = dist[now] + v
                queue.add(k)
            }
        }
    }

    for (i in 0..Q) {
        val (x, y) = readInputLine().split(" ").map { it.toInt() - 1 }
        println(dist[x] + dist[y])
    }
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 127580
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
const ll INF = 9e18;

ll maxlist(vector<ll> &maxindices, vector<ll> &counts) {
    ll maxval = -1;
    for (ll i = 0; i < (ll)counts.size(); i++) {
        if (maxval == counts[i]) {
            maxindices.push_back(i);
        } else if (maxval < counts[i]) {
            maxval = counts[i];
            maxindices.clear();
            maxindices.push_back(i);
        }
    }
    return maxval;
}

int main() {
    ll H, W, M;
    cin >> H >> W >> M;
    vector<ll> hcount(H, 0);
    vector<ll> wcount(W, 0);

    set<pair<ll, ll>> exist;
    for (ll i = 0; i < M; i++) {
        ll h, w;
        cin >> h >> w;
        h--;
        w--;
        hcount[h]++;
        wcount[w]++;
        exist.insert(make_pair(h, w));
    }
    vector<ll> max_hi;
    ll max_h = maxlist(max_hi, hcount);
    vector<ll> max_wi;
    ll max_w = maxlist(max_wi, wcount);

    for (auto hi : max_hi) {
        for (auto wi : max_wi) {
            auto p = make_pair(hi, wi);
            if (exist.count(p) == 0) {
                cout << max_h + max_w << endl;
                return 0;
            }
        }
    }
    cout << max_h + max_w - 1 << endl;
}


Measured memory_bytes: 35020
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

struct FenwickTree(T)
{
    import std.traits : isSigned, Unsigned;

    static if (isSigned!T)
    {
        alias U = Unsigned!T;
    }
    else
    {
        alias U = T;
    }
public:
    this(int n)
    {
        _n = n;
        data = new U[](n);
    }

    void add(int p, T x)
    {
        assert(0 <= p && p < _n);
        p++;
        while (p <= _n)
        {
            data[p - 1] += cast(U) x;
            p += p & -p;
        }
    }

    T sum(int l, int r)
    {
        assert(0 <= l && l <= r && r <= _n);
        return sum(r) - sum(l);
    }

private:
    int _n;
    U[] data;

    U sum(int r)
    {
        U s = 0;
        while (r > 0)
        {
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
}

void main()
{
    auto nq = readln.split.to!(int[]);
    auto N = nq[0];
    auto Q = nq[1];

    auto ft = FenwickTree!long(N);
    foreach (i, a; readln.split.to!(long[])) ft.add(i.to!int, a);
    while (Q--) {
        auto q = readln.split.to!(int[]);
        if (q[0] == 0) {
            ft.add(q[1], q[2]);
        } else {
            writeln(ft.sum(q[1], q[2]));
        }
    }
}

Measured memory_bytes: 28564
n, m = map(int, input().split())
l, l1, l2 = list(""), list(""), list("")
for i in range(n):
    l.append(0)
for i in range(m):
    s, c = map(int, input().split())
    if s == 1 and c == 0 and n != 1:
        print("-1")
        exit()
    if s in l1 and l2[l1.index(s)] != c:
        print("-1")
        exit()
    l1.append(s)
    l2.append(c)
for i in range(len(l1)):
        l[l1[i] - 1] = l2[i]
if l[0] == 0 and n != 1:
    l[0] = 1
a = ''
for i in range(n):
    a += str(l[i])
print(a)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;




int main(void) {
  ll q, h, s, d;
  cin >> q >> h >> s >> d;
  ll N;
  cin >> N;
  
  ll a=min(q*4, min(h*2, s));
  ll ans=min(N*a,N/2*d+((N&1) ? a : 0));
  pt(ans);
  
}



Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	int D;
	int[] c;
	int[][] s;

	int[] ans;

	long score(int[] a) {
		int[] last = new int[26];

		long res = 0;

		for (int d = 0; d < D; d++) {
			res += s[d][a[d]];
			last[a[d]] = d + 1;

			for (int j = 0; j < 26; j++) {
				res -= (c[j] * (d + 1 - last[j]));
			}
//			System.err.println(res);
		}
		return res ;
	}

	public void _main(String[] args) {
		long st = System.currentTimeMillis();
		Scanner sc = new Scanner(in);

		D = sc.nextInt();
		c = new int[26];
		for (int i = 0; i < 26; i++) {
			c[i] = sc.nextInt();
		}

		s = new int[D][26];
		for (int i = 0; i < D; i++) {
			for (int j = 0; j < 26; j++) {
				s[i][j] = sc.nextInt();
			}
		}

		sc.close();

		ans = new int[D];

		long max = score(ans);

		while (System.currentTimeMillis() - st < 1800) {

			for (int d = 0; d < D; d++) {
				for(int i=0;i<26;i++) {
					int t = ans[d];
					if(t==i) continue;
					ans[d] = i;
	
					long s = score(ans);
					if (s < max) {
						ans[d] = t;
					} else {
						max = s;
					}
				}
			}
		}

		System.err.println(max);

		for (int x : ans) {
			out.println(x + 1);
		}

	}

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


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

typedef long long i64;
#define put(n) cout<<(n)<<"\n"
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);(i)++)
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);(i)--)
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()

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

    for(int bit=0;bit<(1<<3);++bit){
        string ans = "";
        ans += num[0];
        int seven = num[0] - '0';
        for(int i=0;i<3;++i){
            if(bit & (1<<i)){
                seven += num[i+1] - '0';
                ans += "+";
            }
            else{
                seven -= num[i+1] - '0';
                ans += "-";
            }
            ans+=num[i+1];
        }
        if(seven == 7){
            ans += "=7";
            put(ans);
            return 0;
        }
    } 
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	
	int x, y, z, count = 0;
	
	while( cin >> x >> y >> z ) {
		
	for(int i=x;x<=y;x++)
	if(z % x == 0)
	count++;
	
	cout << count << "\n";
	count = 0;
	}
		
	return 0;
}


Measured memory_bytes: 3088
import java.io.*;
import java.util.*;
import java.util.function.IntPredicate;
 
public class Main{
	String S, T;
	int[] sumS;
	int[] sumT;
	int Q;
	public void solve(){
		S = next();
		T = next();
		sumS = new int[S.length() + 1];
		sumT = new int[T.length() + 1];
		for(int i = 0; i < S.length(); i++){
			sumS[i + 1] = sumS[i] + ((S.charAt(i) == 'A') ? 1 : 0);
		}

		for(int i = 0; i < T.length(); i++){
			sumT[i + 1] = sumT[i] + ((T.charAt(i) == 'A') ? 1 : 0);
		}
		
		Q = nextInt();
		for(int i = 0; i < Q; i++){
			int a = nextInt() - 1;
			int b = nextInt();
			int c = nextInt() - 1;
			int d = nextInt();
			
			int sa = sumS[b] - sumS[a];
			int sb = b - a - sa;
			
			sa %= 3;
			sb %= 3;
			
			int ta = sumT[d] - sumT[c];
			int tb = d - c - ta;
			
			ta %= 3;
			tb %= 3;
			
			if(sa == ta && sb == tb){
				out.println("YES");
			}else if((sa + 1) % 3 == ta && (sb + 1) % 3 == tb){
				out.println("YES");
			}else if((sa + 2) % 3 == ta && (sb + 2) % 3 == tb){
				out.println("YES");
			}else{
				out.println("NO");
			}
			
		}
	}

	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}
	
	
	
	public static int nextInt(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}
	
	public static long nextLong(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}
	public static String next(){
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	
	
	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}
	
	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
}

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

int main()
{
	int a, b, c, d;

	cin >> a >> b >> c >> d;

	if (a + b > c + d) {
		cout << "Left" << endl;
	}

	else if (a + b < c + d) {
		cout << "Right" << endl;
	}

	else {
		cout << "Balanced" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import heapq as hq
def main():
    n = int(input())
    a = []
    l = []
    for i in range(n):
        num = int(input())
        a.append(num)
        l.append(-1*num)
    hq.heapify(l)
    max_1 = hq.heappop(l)
    max_2 = hq.heappop(l)
    for i in a:
        if -1*i == max_1:
            print(-1*max_2)
        else:
            print(-1*max_1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 20524
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll l,r,ans=2020;
    cin >> l >> r;
    for(ll i=l;i<=r;i++){
        if(i%2019==0){
            cout << 0 << endl;
            return 0;
        }
    }
    l%=2019;
    r%=2019;
    for(ll i=l;i<r;i++){
        for(ll j=i+1;j<=r;j++){
            ans=min(ans,(i*j)%2019);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    int A, B;
    cin >> A >> B;
    if (A <= 0 && B >= 0) OUT("Zero")
    else {
        B = min(-1,B);
        if (A > 0) OUT("Positive")
        else {
            if (abs(B-A) % 2 == 0) OUT("Negative")
            else OUT("Positive")
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
    int N, T;
    cin >> N >> T;
    vector<pii> AB(N);
    for(int i = 0; i < N; ++i)
        cin >> AB[i].first >> AB[i].second;
    sort(AB.begin(), AB.end());

    vector<vector<int>> dp(N + 5, vector<int>(T + 5));
    for(int i = 0; i < N; ++i) {
        for(int j = 0; j <= T; ++j) {
            dp[i + 1][j] = max(dp[i][j], dp[i + 1][j]);
            if(j < T) {
                int k = min(j + AB[i].first, T);
                dp[i + 1][k] = max(dp[i + 1][k], dp[i][j] + AB[i].second);
            }
        }
    }
    cout << dp[N][T] << endl;
    return 0;
}


Measured memory_bytes: 35712
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#define ll long long
using namespace std;

const int N=100005;

struct node{
	int id,w;
	node(){}
	node(int id,int w):id(id),w(w){}
	friend bool operator<(node a,node b){
		return a.w>b.w;
	}
};
int n,m,x,y,r1,r2,cnt;
ll ans;
int a[N],f[N],sz[N];
priority_queue<node> q1;
priority_queue<int,vector<int>,greater<int> > q2[N];

int find(int k){
	if (f[k]!=k) f[k]=find(f[k]);
	return f[k];
}

int main(){
//	freopen("a.in","r",stdin);
//	freopen("a.out","w",stdout);
	int i; node k;
	scanf("%d%d",&n,&m);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	for (i=1;i<=n;i++) f[i]=i,sz[i]=1;
	for (i=1;i<=m;i++){
		scanf("%d%d",&x,&y); x++; y++;
		r1=find(x); r2=find(y);
		if (r1!=r2){
			if (sz[r1]>sz[r2]) swap(r1,r2);
			sz[r2]+=sz[r1];
			f[r1]=r2;
		}
	}
	for (i=1;i<=n;i++) q2[find(i)].push(a[i]);
	for (i=1;i<=n;i++)
		if (find(i)==i){
			ans+=1ll*q2[i].top(); q2[i].pop();
			if (!q2[i].empty())
				q1.push(node(i,q2[i].top()));
			cnt++;
		}
	if ((cnt-1)*2>n){
		printf("Impossible\n");
		return 0;
	}
	if (cnt==1){
		printf("0\n");
		return 0;
	}
	cnt=(cnt-1)*2-cnt;
	for (i=1;i<=cnt;i++){
		k=q1.top(); q1.pop();
		ans+=1ll*k.w;
		q2[k.id].pop();
		if (!q2[k.id].empty())
			q1.push(node(k.id,q2[k.id].top()));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7680
import math

def main():
    n, m = [int(x) for x in input().split(" ")]
    gates = []
    mi = n
    ma = 0

    for x in range(m):
        l, r = [int(x) for x in input().split(" ")]
        gates.append((l, r))

    for gate in gates:
        # print(gate)
        if ma <= gate[0]:
            ma = gate[0]

        if mi >= gate[1]:
            mi = gate[1]

    res = 0
    if mi < ma:
        res = 0
    else:
        res = mi - ma + 1

    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 16584
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
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()
{
  string s ;
  cin >> s ;
  int ans = 0 ;
  REP(i,4){
    if(s.at(i)=='+'){
      ans++ ;
    }
    else{
      ans-- ;
    }
  }
  cout <<ans <<endl;
    

  return 0 ;
}




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

int main(){
	int N;
	cin >> N;
	int a[3*N];
	for(int i=0; i<3*N; i++) cin >> a[i];
	priority_queue< int, vector<int>, greater<int> > q1;
	priority_queue<int> q2;
	long sum1 = 0, sum2 = 0;
	for(int i=0; i<N; i++){
		sum1 += a[i]; sum2 += a[3*N-1-i];
		q1.push(a[i]);
		q2.push(a[3*N-1-i]);
	}
	long long left[N+1], right[N+1];
	left[0] = sum1, right[0] = sum2;
	for(int i=N; i<2*N; i++){
		q1.push(a[i]);
		left[i-N+1] = left[i-N] + a[i] - q1.top();
		q1.pop();
	}
	for(int i=2*N-1; i>=N; i--){
		q2.push(a[i]);
		right[2*N-i] = right[2*N-i-1] + a[i] - q2.top();
		q2.pop();
	}
	long long max = left[0] - right[N];
	for(int i=1; i<=N; i++){
		if(max < left[i] - right[N-i]) max = left[i] - right[N-i];
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 3956