akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
const int MAXN = 1e6 + 5;
const int MAXM = 1e6 + 5;
const int MAXP = 1.5e6 + 5;

inline int Abs(int x){ return x<0? -x: x;}

/*
 0
1 3
 2
*/

string s[MAXN];
vector<int> dis[MAXN];

struct Node
{
	int x,y;
};

set<int> r[MAXN], c[MAXM];
queue<Node> q;

inline void push(int x,int y)
{
	r[x].erase(y);
	c[y].erase(x);
	q.push((Node){x,y});
}

int main(void)
{
	int n,m,d;
	scanf("%d%d%d",&n,&m,&d);
	int sx,sy,ex,ey;
	scanf("%d%d%d%d",&sx,&sy,&ex,&ey);
	for(int i=1; i<=n; ++i)
		cin>>s[i],
		s[i] = '@' + s[i] + '@';
	
	for(int i=1; i<=n; ++i)
	{
		dis[i].resize(m+1);
		for(int j=1; j<=m; ++j)
			dis[i][j] = -1;
	}
	
	for(int i=0; i<=n+1; ++i)
		for(int j=0; j<=m+1; ++j)
			r[i].insert(j),
			c[j].insert(i);
	
	dis[sx][sy] = 0;
	push(sx,sy);
	
	while(!q.empty())
	{
		int x = q.front().x, y = q.front().y;
		q.pop();
		
		set<int>::iterator it;
		
		static vector<Node> tmp;
		tmp.clear();
		
		it = r[x].lower_bound(y);
		while(1)
		{
			int yy = *it;
			if(yy>m) break;
			if(s[x][yy] == '@') break;
			if(yy - y > d) break;
			
			dis[x][yy] = dis[x][y] + 1;
			tmp.push_back((Node){x,yy});
			++it;
		}
		
		it = r[x].lower_bound(y);
		--it;
		while(1)
		{
			int yy = *it;
			if(yy<1) break;
			if(s[x][yy] == '@') break;
			if(y - yy > d) break;
			
			dis[x][yy] = dis[x][y] + 1;
			tmp.push_back((Node){x,yy});
			--it;
		}
		
		it = c[y].lower_bound(x);
		while(1)
		{
			int xx = *it;
			if(xx>n) break;
			if(s[xx][y] == '@') break;
			if(xx - x > d) break;
			
			dis[xx][y] = dis[x][y] + 1;
			tmp.push_back((Node){xx,y});
			++it;
		}
		
		it = c[y].lower_bound(x);
		--it;
		while(1)
		{
			int xx = *it;
			if(xx<1) break;
			if(s[xx][y] == '@') break;
			if(x - xx > d) break;
			
			dis[xx][y] = dis[x][y] + 1;
			tmp.push_back((Node){xx,y});
			--it;
		}
		
		for(int i=0; i<(int)tmp.size(); ++i)
			push(tmp[i].x, tmp[i].y);
	}
	
	printf("%d",dis[ex][ey]);
	return 0;
}

Measured memory_bytes: 437876
H,W = map(int,input().split(" "))
N = int(input())
A = list(map(int,input().split(" ")))

c = [[0]*W for i in range(H)]
x = 0
y = 0
for i in range(N):
    for j in range(A[i]):
        c[y][x] = i+1
        if y % 2:
            if x == 0:
                y += 1
            else:
                x -= 1
        else:
            if x == W - 1:
                y += 1
            else:
                x += 1

for i in range(H):
    print(' '.join(map(str,c[i])))

Measured memory_bytes: 3568
a1,b1 = map(int, input().split())
a2,b2 = map(int, input().split())
a3,b3 = map(int, input().split())

l = []
l.append(a1)
l.append(b1)
l.append(a2)
l.append(b2)
l.append(a3)
l.append(b3)
cnt1 = l.count(1)
cnt2 = l.count(2)
cnt3 = l.count(3)
cnt4 = l.count(4)

if cnt1 >= 3 or cnt2 >= 3 or cnt3 >= 3 or cnt4 >= 3  :
    print('NO')
else:
    print('YES')

Measured memory_bytes: 3064
/*..........AAKASH GOYAL............*/
/*............DAIICT................*/
 
#include <bits/stdc++.h>
using namespace std;

#define    int                      long long int

#define    f(i,j,n)                 for(int i = j; i <= n; i++)
#define    r(i,n,j)                 for(int i = n; i >= j; i--)
#define    mod                      1000000007
#define    speed                    ios_base::sync_with_stdio(false);
#define    upp                      cin.tie(NULL);
#define    pb                       push_back
#define    mp                       make_pair
#define    T                        int tt; cin >> tt; while(tt--)
#define    ff                       first
#define    ss                       second
#define    all(container)           container.begin() , container.end()
#define    sz(container)            (int)container.size()
#define    pii                      pair <int , int>
#define    ppl                      pair <int , pii>               
#define    sp(x)                    setprecision(x)

int32_t main()
{
    speed upp
    int n,c=1;
    cin>>n;
    int a[n+1];
    f(i,1,n)
        cin>>a[i];
    f(i,1,n)
        if(a[i]==c)
            c++;
    if(c==1)
        cout<<"-1";
    else
        cout<<n-c+1;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 1; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

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

    double n;
    cin >> n;
    cout << fixed << setprecision(10) << (n - (int)n / 2) / n << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define g(a, b) __gcd((a), (b))
#define l(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

std::vector<std::pair<char, long long> > runlength(std::string str)
{
        std::vector<std::pair<char, long long> > enc;
        long long strsize = static_cast<long long>(str.size());

        char now = str[0];
        long long cnt = 0;
        for (long long i = 0; i < strsize; ++i) {
                if (str[i] == now) {
                        ++cnt;
                } else {
                        enc.push_back(std::pair<char, long long>(now, cnt));
                        now = str[i];
                        cnt = 1;
                }
        }
        enc.push_back(std::pair<char, long long>(now, cnt));
        return enc;
}

int main()
{
        string S;
        cin >> S;
        auto x = runlength(S);
        cout << len(x) - 1 << endl;
}

Measured memory_bytes: 2676
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <queue>
int score[201] = { 0 };
int choice[4][201] = { 0 };
using namespace std;
int main() {
	int n;
	scanf("%d", &n);
	for (int i = 1;i <= n;++i) scanf("%d%d%d", &choice[1][i], &choice[2][i], &choice[3][i]);
	for (int i = 1;i <= 3;++i) {
		int bad[201] = { 0 };
		for (int q = 1;q <= n;++q) {
			bad[choice[i][q]] += 1;
		}
		for (int q = 1;q <= n;++q) {
			if (bad[choice[i][q]] == 1) {
				score[q] += choice[i][q];
			}
		}
	}
	for (int i = 1;i <= n;++i) {
		printf("%d\n", score[i]);
	}
}


Measured memory_bytes: 1032
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iostream>
#include <iterator>

using namespace std;
long A[100000];
long sumO[100000],sumE[100000],sum[100000];
//TODO two way search
int solve(long X, int N){
	int ub = N+1,lb = 1,t;
	t = (ub + lb)/2;
	while(ub - lb >1){
		if(abs(A[N-t]-X) > abs(A[N-(t+1)/2]-X)){
			ub = t;
		}else{
			lb = t;
		}
		t = (ub+lb)/2;
	}
	// for(int i=1;i<N+1;i++){
	// 	if(abs(A[N-i]-X) > abs(A[N-(i+1)/2]-X)) return i-1;
	// }
	return t;
}

void calcSum(int N){
	sumE[0] = A[0];
	sumO[0] = long(0);
	sum[0] = A[0];
	for(int i=1;i<N;i++){
		sum[i] = sum[i-1]+A[i];
		sumE[i] = sumE[i-1] + (i%2 == 0 ? A[i] : long(0));
		sumO[i] = sumO[i-1] + (i%2 == 1 ? A[i] : long(0)); 
	}
}

int main(void){
	int N,Q;
	long X[100000];
	cin >> N >> Q;
	for(int i=0;i < N;i++){
		cin >> A[i];
	}
	calcSum(N);

	for(int i=0;i < Q;i++){
		cin >> X[i];
	}
	for(int i=0;i < Q;i++){
		int a = solve(X[i],N);
		long sum1 = sum[N-1] - sum[N -(a+1)/2 -1];
		long sum2;
		if(N!=a){
			if(N%2 == 0)sum2 = sumO[N - a - 1];
			else sum2 = sumE[N - a - 1];
		}else{
			sum2 = long(0);
		}
		// for(int j=N -((a+1)/2)*2 -1;j>=0;j-=2){
		// 	sum2 += A[j];
		// }
		cout << sum1 + sum2 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(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 maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int N;
    cin >> N;
    
    string S, T;
    cin >> S >> T;
    
    REP(i, N) {
        cout << S[i] << T[i];
    }
    cout << endl;

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

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int a, b, c, x;
    int A=0;
    
    scanf("%d %d %d", &a, &b, &c);
    
    for(x=a; x<=b; x++){
        if((c%x)==0){
            A++;
        }
    }
    printf("%d\n", A);
    return 0;
}

Measured memory_bytes: 596
N = int(input())
flag = 1
for a in range(-119, 119):
    for b in range(-119, 119):
        if a**5 - b**5 == N:
            A = str(a)
            B = str(b)
            flag = 0
    if flag ==0:
        break
print(A + " " +B)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
  int n,k;cin>>n>>k;
  int a=1;
  rep(i,n){
    if(a*2>a+k)a+=k;
    else a*=2;
  }
  cout<<a<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

int N;
int A[100000];

int ans_x[100000];
int ans_y[100000];

signed main()
{
	cin >> N;
	REP(i, N) cin >> A[i];


	int max_val = INT_MIN;
	int min_val = INT_MAX;
	int max_i = -1;
	int min_i = -1;

	for (int i = 0; i < N; i++)
	{
		if (max_val < A[i])
		{
			max_val = A[i];
			max_i = i;
		}
	}

	for (int i = 0; i < N; i++)
	{
		if (min_val > A[i] && i != max_i)
		{
			min_val = A[i];
			min_i = i;
		}
	}

	vector<int> p_list;
	vector<int> m_list;
	for (int k = 0; k < N; k++)
	{
		if (k != max_i && k != min_i)
		{
			if (A[k] > 0)
			{
				p_list.push_back(A[k]);
			}
			else
			{
				m_list.push_back(A[k]);
			}
		}
	}
	RSORT(p_list);
	SORT(m_list);

	int ans_cnt = 0;
	for (int n : p_list)
	{
		ans_x[ans_cnt] = min_val;
		ans_y[ans_cnt] = n;
		ans_cnt++;
		min_val -= n;
	}
	for (int n : m_list)
	{
		ans_x[ans_cnt] = max_val;
		ans_y[ans_cnt] = n;
		ans_cnt++;
		max_val -= n;
	}

	ans_x[N - 2] = max_val;
	ans_y[N - 2] = min_val;
	cout << (max_val - min_val) << endl;
	for (int k = 0; k < N - 1; k++)
	{
		cout << ans_x[k] << " " << ans_y[k] << endl;
	}

}









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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ASC(x) sort(ALL((x)))
#define DESC(x) sort(ALL((x)),greater<ll>())
#define REV(x) reverse(ALL((x)))
#define eb emplace_back


ll bellmanFord(vector<vector<pair<ll,ll>>> G, ll s, ll t)
{
    ll N = SZ(G);
    vec D(N, INF);
    queue<ll> Q;
    
    D[s] = 0;
    bool updated = false;
    REP(i,0,N) {
        updated = false;
        REP(j,0,N) {
            FORR(e,G[j]) {
                ll nv = e.first;
                ll nd = D[j] + e.second;
                if(nd < D[nv]) {
                    D[nv] = MIN(D[nv],nd);
                    updated = true;
                }
            }    
        }
        if(!updated) break;
    }

    if(!updated) return MAX(-D[t],0);
    else return -1;
}

int main()
{
    ll N, M, P;
    cin >> N >> M >> P;
    vec A(M), B(M), C(M);
    mat G_tmp1(N), G_tmp2(N);
    vector<vector<pair<ll,ll>>> G(N);
    REP(i,0,M) {
        cin >> A[i] >> B[i] >> C[i];
        --A[i]; --B[i];
        G_tmp1[A[i]].eb(B[i]);
        G_tmp2[B[i]].eb(A[i]);
    }

    queue<ll> Q1;
    Q1.push(0);
    vector<bool> F1(N, false);
    F1[0] = true;
    while(!Q1.empty()) {
        ll v = Q1.front(); Q1.pop();
        FORR(nv,G_tmp1[v]) {
            if(!F1[nv]) {
                Q1.push(nv);
                F1[nv] = true;
            }
        }
    }

    queue<ll> Q2;
    Q2.push(N-1);
    vector<bool> F2(N, false);
    F2[N-1] = true;
    while(!Q2.empty()) {
        ll v = Q2.front(); Q2.pop();
        FORR(nv,G_tmp2[v]) {
            if(!F2[nv]) {
                Q2.push(nv);
                F2[nv] = true;
            }
        }
    }

    REP(i,0,M) {
        if(F1[A[i]] && F2[B[i]]) G[A[i]].eb(B[i], P - C[i]);
    }

    ll ans = bellmanFord(G, 0, N-1);
    PR(ans);

    return 0;
}

/*



*/

Measured memory_bytes: 4372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+10;
int n,h,f[N],mn=1e9+10;
int main()
{
	scanf("%d%d",&h,&n);
	h=1e4-h;
	for (int i=0;i<=2e4+10;i++) f[i]=1e9;
	f[h]=0;
	for (int i=1,a,b;i<=n;i++)
	{
		scanf("%d%d",&a,&b);
		for (int j=h;j<=2e4;j++)
			if (h+a<=2e4) f[j+a]=min(f[j+a],f[j]+b);
	}
	for (int i=1e4;i<=2e4;i++) mn=min(mn,f[i]);
	printf("%d\n",mn);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long a, b;
  cin >> a >> b;
  if (a > 0 && b > 0) cout << "Positive" << endl;
  else if (b < 0 && a < 0) {
    if ((b - a) % 2 == 1) cout << "Positive" << endl;
    else if ((b - a) % 2 == 0) cout << "Negative" << endl;
  }
  else if (a <= 0 && 0 <= b) cout << "Zero" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;

int main(){
	int n;
    cin>>n;
    vector<int> a(n+1);
    REP(i,n){
        cin>>a[i+1];
    }
    vector<int> b(n+1,0);
    vector<int> ans;
    for(int i=n;i>=1;i--){
        int sum=0;
        for(int j=i;j<=n;j+=i){
            if(b[j]) sum++;
        }
        if(sum%2!=a[i]){
             b[i]=1;
            ans.push_back(i);}
    }
    OUT(SZ(ans));
    REP(i,SZ(ans)){
        OUT(ans[i]);
    }
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    if(n == 1) cout << "Hello World" << endl;
    else if (n == 2){
        int a, b;
        cin >> a >> b;
        cout << a+b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h> 
#include<string.h>
int main()
{
    int i,ans=0;
    char srx[21],sry[21]={"CODEFESTIVAL2016"};
    gets(srx);//还是使用C语言gets的我是不是很蠢...
    for(i=0;i<strlen(srx);i++)
    if(srx[i]!=sry[i])
    ans++;//其实也可以是ans=15; if(srx[i]==sry[i]）ans--;
    printf("%d\n",ans);//回车这种东西不用说...
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <vector>
#include <queue>
#include <assert.h>
#include <map>
#include <set>
#include <bitset>
#include <iomanip>
#include <stack>
// #include <unordered_map>
#include <cmath>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
// #define INF 0x7f7f7f7f  //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.14159265358979323846264338327950254
#define pb push_back
#define ll long long
#define debug cout << "debug\n";
#define STDIN                      \
    freopen("in.txt", "r", stdin); \
    freopen("out.txt", "w", stdout);
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);
#define scai(x) scanf("%d", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define scaf(x) scanf("%lf", &x)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define For(m, n) for (int i = m; i < n; i++)
#define PII pair<int, int>
#define PLL pair<long, long>
#define ft first
#define sd second
#define pb push_back
#define ST(x, y, z) sort(x + y, x + z);
#define lson o << 1, l, mid
#define rson o << 1 | 1, mid + 1, r
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define ROF(i, a, b) for (int i = (a); i >= (b); i--)
#define MEM(x, v) memset(x, v, sizeof(x))
#define rep(i, a, b) for (register int i = a; i <= b; i++)
#define rrep(i, a, b) for (register int i = a; i >= b; i--)
#define PIII pair<int, PII>
#define re read()
#define case  \
    int T;    \
    cin >> T; \
    rep(_, 1, T)
// #define int ll
#define LL long long
#define int ll
inline int read()
{
    char tempt = getchar();
    int x = 0, f = 0;
    while (tempt < '0' || tempt > '9')
        f |= tempt == '-', tempt = getchar();
    while (tempt >= '0' && tempt <= '9')
        x = x * 10 + tempt - '0', tempt = getchar();
    return f ? -x : x;
}

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

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

const int N = 2e5 + 10;
int a[N];
signed main()
{
    //STDIN
    int n; cin >> n;
    rep(i,1, n) cin >> a[i];
    sort(a+1, a + 1 + n);
    reverse(a+1, a+1+n);
    vector<int> vec;
    vec.push_back(0);
    vec.push_back(a[1]);
    for (int i = 2; i <= n; i++)
    {
        vec.push_back(a[i]);
        vec.push_back(a[i]);
    }
    int ans = 0;
    for (int i = 0; i < n; i++) ans += vec[i];
    
    cout << ans << endl;

}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi a(n), b(n);
    REP(i, n) cin >> a[i] >> b[i];
    vector<pair<int,int>> diff(n);
    REP(i, n) diff[i] = make_pair(a[i] + b[i], i);
    sort(diff.begin(), diff.end(), greater<pair<int,int>>());
    ll ans = 0;
    for(int i = 0; i < n; i += 2) {
        ans += a[diff[i].second];
    }
    for(int i = 1; i < n; i += 2) {
        ans -= b[diff[i].second];
    }
    cout << ans << endl;

    return 0;
}

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

int main()
{
	int a[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};
	int x,y;
	cin>>x>>y;
	if(a[x]==a[y])
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 256
import copy

n = int(input())

tList = list(map(int,input().split()))

m = int(input())

pList = []
for i in range(m):
  pList.append(list(map(int,input().split())))

tpList =  copy.copy(tList)
for j in pList:
  tpList[j[0]-1]=j[1]
  print(sum(tpList))
  tpList = copy.copy(tList)





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

int main () {
  int A, B, C, ans;
  cin >> A >> B >> C;
  
  if (max({A,B,C}) == A) {
    ans = A*10+B+C;
  }
    if (max({A,B,C}) == B) {
    ans = A+B*10+C;
  }
  if (max({A,B,C}) == C) {
    ans = A+B+C*10;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define FORR(i, m, n) for(ll i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n)
#define MAX 100000
#define inf 1000000007
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main() {
    //cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, ans;
    cin >> a >> b >> c;
    ans = 0;
    ll m = max(a, b);
    m = max(m, c);
    ll s = a + b + c;

    if(m%2 == s%2) ans = (3*m - s)/2;
    else ans = (3*(m+1) - s)/2;

    cout << ans <<"\n";
	return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define dbg(x) cout << #x << " = " << x << endl
#define all(x) x.begin(), x.end()

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;

const int MAX = 1e5;
const int INF = 1e9;
vi stone(MAX + 5);
vi dp(MAX + 5, -1);
int n;

int sol(int i){
    if(i >= n) return INF;
    if(i == n - 1) return 0;
    if(dp[i] != -1) return dp[i];
    dp[i] = sol(i + 1) + abs(stone[i] - stone[i + 1]);
    if(i + 2 < n){
        dp[i] = min(dp[i], sol(i + 2) + abs(stone[i] - stone[i + 2]));
    }
    return dp[i];
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #else
        #define endl '\n'
    #endif
    cin >> n;
    for(int i = 0; i < n; ++i)
        cin >> stone[i];
    cout << sol(0) << endl;
    return 0;
}

Measured memory_bytes: 7088
#include <bits/stdc++.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() {
  int N, K;
  cin >> N >> K;
  vector<int> V(N);
  rep(i, N) cin >> V[i];
  
  int ans = 0, r, total, t;
  for (int k = 1; k <= min(K, N); k++) {
    t = K - k;  // number of operatation C and D
    for (int l = 0; l <= k; l++) {
      r = k - l;
      vector<int> T;
      for (int i = 0; i < l; i++) T.push_back(V[i]);
      for (int i = N - r; i < N; i++) T.push_back(V[i]);
      sort(T.begin(), T.end());
      rep(i, t) if (T[i] < 0) T[i] = 0;
      total = 0;
      for (int x: T) total += x;
      if (total > ans) ans = total;
    }
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main()
{
    int n,k;
    scanf("%d %d",&n,&k);
    if(k*2-1<=n)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>

typedef long long int lli;

lli cnt[26];
char s[200002];

int main()
{
	scanf("%s", s);
	lli i = 0;
	while (s[i] != '\0') {
		cnt[s[i] - 'a']++;
		i++;
	}
	lli ans = 1 + i * (i - 1) / 2;
	for (int j = 0; j < 26; j++) {
		ans -= cnt[j] * (cnt[j] - 1) / 2;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define maxN 52
#define maxD 102

using namespace std;
int n, p;

int nrOdd = 0;
long long ans;

int main()
{
    scanf("%d %d", &n, &p);
    p %= 2;

    for (int i = 1; i <= n; ++ i)
    {
        int x;
        scanf("%d", &x);
        if (x & 1)
            ++ nrOdd;
    }
    if ((p & 1) && nrOdd)
        ans = 1LL << (n - 1);
    else if (p % 2 == 0 && nrOdd)
        ans = 1LL << (n - 1);
    else if (p % 2 == 0 && !nrOdd)
        ans = 1LL << n;

    printf("%lld", ans);
    return 0;
}


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

using namespace std;
typedef long long ll;
int MAX = 10005;

int main() {
  int n;
  scanf("%d", &n);
  int ans = 0;
  for (int i=0; i<n; i++) {
    ll a;
    scanf("%lld", &a);
    while(a%2 == 0) {
      a /= 2;
      ans++;
    }
  }
  printf("%d\n", ans);
  return 0;
}


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

using namespace std;
using ll = long long;

const ll MAX { 110 }, A { 1 }, C { 2 }, G { 3 }, T { 4 }, MOD { 1000000007 };

ll st[MAX][2*MAX];

int encode(int a, int b, int c)
{
    return 25 * a + 5 * b + c;
}

void decode(int n, int&a, int &b, int& c)
{
    c = n % 5;
    n /= 5;

    b = n % 5;
    n /= 5;

    a = n;
}


ll dp(int idx, int N, int mask)
{
    if (idx == N)
        return 1;

    if (st[idx][mask] != -1)
        return st[idx][mask];

    int x, y, z;
    decode(mask, x, y, z);

    // A e T sempre podem ser adicionados
    ll ans = (dp(idx + 1, N, encode(y, z, T)) + dp(idx + 1, N, encode(y, z, A))) % MOD;

    // C só pode adicionado se não violar a regra (não pode formar AGC ou GAC ou AxGC)
    if (encode(0, A, G) != encode(0, y, z) and 
        encode(0, G, A) != encode(0, y, z) and
        encode(A, G, 0) != encode(x, y, 0) and
        encode(A, 0, G) != encode(x, 0, z))
            ans = (ans + dp(idx + 1, N, encode(y, z, C))) % MOD;

    // G só pode adicionado se não violar a regra (não pode formar ACG)
    if (encode(0, A, C) != encode(0, y, z))
        ans = (ans + dp(idx + 1, N, encode(y, z, G))) % MOD;

    st[idx][mask] = ans;

    return ans;
}

int solve(int N)
{
    memset(st, -1, sizeof st);

    return dp(0, N, 0);
}

int main()
{
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    auto ans = solve(N);

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

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

	int N, M, X, Y; cin >> N >> M >> X >> Y;
	vector<int> x(N+1, 0), y(M+1, 0);
	rep (i,N){
		cin >> x[i];
	} // end rep
	x[N] = X;
	rep (j,M){
		cin >> y[j];
	} // end rep
	y[M] = Y;

	sort(ALL(x));
	sort(ALL(y));

	bool ok = (x[N] < y[0] ? true : false);
	cout << (ok ? "No War" : "War") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

i64 H, W;
i64 N;
i64 sr, sc;

string S, T;

bool solve(i64 X, i64 x, const vector<i64>& ss, const vector<i64>& tt, bool check) {
  i64 LL = 0;
  i64 RR = 0;
  i64 n = ss.size();
  i64 now = x;
  i64 plus = 0;
  //cout << "solve" << endl;
  for(int i = 0;i < n;i++) {
    if(ss[i] == 1) RR++;
    else if(ss[i] == -1) LL++;
    if(tt[i] == -1) {
      //cout << now << " " << RR << " " << LL << endl;
      if(check && now - LL <= 0) {
        i64 ddd = LL - now + 1;
        if(plus < ddd) return false;
        plus -= ddd;
        now += ddd;
        if(now > X) return false;
      }
      {
        now += RR;
        if(now > X) return false;
        if(now >= 2) { now--; plus++; }
      }
      LL = 0;
      RR = 0;
    }
  }
      if(check && now - LL <= 0) {
        i64 ddd = LL - now + 1;
        if(plus < ddd) return false;
        plus -= ddd;
        now += ddd;
        if(now > X) return false;
      }
      {
        now += RR;
        if(now > X) return false;
        if(now >= 2) { now--; plus++; }
      }
  return true;
}

int main() {
  cin >> H >> W >> N;
  cin >> sr >> sc;
  cin >> S >> T;
  {
    vector<i64> ss(N, 0);
    vector<i64> tt(N, 0);
    for(int i = 0;i < N;i++) {
      if(S[i] == 'U') ss[i] = 1;
      if(S[i] == 'D') ss[i] = -1;
      if(T[i] == 'U') tt[i] = 1;
      if(T[i] == 'D') tt[i] = -1;
    }
    if(!solve(H, H - sr + 1, ss, tt, true)) {
      //cout << 1 << endl;
      cout << "NO" << endl;
      return 0;
    }
  }
  {
    vector<i64> ss(N, 0);
    vector<i64> tt(N, 0);
    for(int i = 0;i < N;i++) {
      if(S[i] == 'D') ss[i] = 1;
      if(S[i] == 'U') ss[i] = -1;
      if(T[i] == 'D') tt[i] = 1;
      if(T[i] == 'U') tt[i] = -1;
    }
    if(!solve(H, sr, ss, tt, false)) {
      //cout << 2 << endl;
      cout << "NO" << endl;
      return 0;
    }
  }

  {
    vector<i64> ss(N, 0);
    vector<i64> tt(N, 0);
    for(int i = 0;i < N;i++) {
      if(S[i] == 'R') ss[i] = 1;
      if(S[i] == 'L') ss[i] = -1;
      if(T[i] == 'R') tt[i] = 1;
      if(T[i] == 'L') tt[i] = -1;
    }
    if(!solve(W, sc, ss, tt, true)) {
      //cout << 3 << endl;
      cout << "NO" << endl;
      return 0;
    }
  }
  {
    vector<i64> ss(N, 0);
    vector<i64> tt(N, 0);
    for(int i = 0;i < N;i++) {
      if(S[i] == 'L') ss[i] = 1;
      if(S[i] == 'R') ss[i] = -1;
      if(T[i] == 'L') tt[i] = 1;
      if(T[i] == 'R') tt[i] = -1;
    }
    if(!solve(W, W - sc + 1, ss, tt, false)) {
      //cout << 4 << endl;
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
}


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

const int N = 2e5 + 10;
vector<int> G[N];

vector<int> a;
vector<int> ans;

void dfs(int v, int p, vector<int> &curr, int curr_ans) {
    
    int val = a[v];
    int pos = lower_bound(curr.begin(), curr.end(), val) - curr.begin();
    int pre = curr[pos];
    curr[pos] = val;
    ans[v] = max(curr_ans, pos + 1);
    for(int u : G[v]) if(u != p) {
        dfs(u, v, curr, ans[v]);  
    }
    curr[pos] = pre;
}

int main() {
    ios::sync_with_stdio(false);
    int n; cin >> n;
    a.resize(n); for(int &i : a) cin >> i;
    for(int i = 0; i < n - 1; i++) {
        int u, v; cin >> u >> v; --u; --v;
        G[u].push_back(v);
        G[v].push_back(u);
    }

    ans.resize(n);
    vector<int> start(n, 1e9 + 1000);
    dfs(0, -1, start, 0);
    for(int i : ans) cout << i << "\n";

    return 0;
}

Measured memory_bytes: 30832
# https://atcoder.jp/contests/abc128/submissions/11722664

def main():
    from collections import deque, namedtuple
    from heapq import heappush, heappop
    from operator import attrgetter
    import sys

    input = sys.stdin.readline
    Event = namedtuple('Event', 'pos start end')
    UC = namedtuple('UC', 'pos end')  # UnderConstruction

    N, Q = map(int, input().split())

    events = []
    for _ in range(N):
        s, t, x = map(int, input().split())
        e = Event(pos=x, start=s - x, end=t - x)  # 時間[s-x,t-x)にpos=0にいるとpos=xで工事中
        events.append(e)
    events.sort(key=attrgetter('start'))
    events = deque(events)

    D = (int(input()) for _ in range(Q))

    ans = []
    h = []
    for d in D:
        while events and events[0].start <= d:
            e = events.popleft()
            heappush(h, UC(pos=e.pos, end=e.end))

        while h and h[0].end <= d:
            heappop(h)

        ans.append(h[0].pos if h else -1)

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


if __name__ == '__main__':
    main()


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

#define INF INT_MAX
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,a,n) for(int i=0;i<n;i++)

using namespace std;

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

	string s;
	cin >> s;
	int ans = 0;
	int temp = 0;
	for(int i = 0;i < s.size();i++){
		if(s[i] == 'A' || s[i] == 'T' || s[i] == 'C' || s[i] == 'G'){
			temp++;
			if(i == s.size()-1){
				if(temp > ans){
					ans = temp;
				}
			}
		}else{
			if(temp > ans){
				ans = temp;
			}
			temp = 0;
		}
	}
	cout << ans << endl;
   
	return 0;
}


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

int main() {
  unsigned long long int x;
  cin >> x;

  if(x==1){
    cout << 0 << endl;
  }
  else if(x==0){
    cout << 1 << endl;
  }

  /*vector<unsigned long long int> input_vec(N);
  for (int i = 0; i < N; i++) {
    cin >> input_vec.at(i);
  }

  for (int i = 0; i < input_vec.size(); i ++){
    cout << input_vec.at(i) << endl;
  }*/
}


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int a[200000];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, k;
    cin >> n >> k;
    for (int i=0; i<n; i++)
        cin >> a[i];

    for (int i=k; i<n; i++)
        cout << (a[i] > a[i-k] ? "Yes" : "No") << "\n";

    return 0;
}


Measured memory_bytes: 4336
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

const int MAX = 3100000;

long long 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 COM(long n, long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long Calc(long r,long c){
    long tmp = 0;
    for(int i=c+1;i<=c+1+r;i++){
        tmp += COM(i,c);
        tmp %= MOD;
    }
    return tmp;
}

int main() {
    // 前処理
    COMinit();
    long r1,c1,r2,c2;
    cin >> r1 >> c1 >> r2 >> c2;
    long a = Calc(c1-1,r1-1);
    long b = Calc(c2,r1-1);
    long c = Calc(c1-1,r2);
    long d = Calc(c2,r2);
    cout << (d - b - c + a + MOD) % MOD << endl;
}

Measured memory_bytes: 72960
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;

#define len length()
#define sz size()
#define rep(i, n) for(int i = 0; i < n; i++)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define veci(a, n) vector<int> a(n)
#define vecs(a, n) vector<string> a(n)
#define vecc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)

int main(){
    int A, B, K;
    cin >> A >> B >> K;
    K--;

    for(int i=A; i<=B; i++){
        if((i<=A+K)||(B-K<=i)) cout << i << endl;
    }

    return 0;
}

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

int main(){
    unsigned long long N,K,prevN;

    scanf("%lld %lld", &N, &K);

    N = (N % K);
    if(N == 0){
        printf("0");
        return 0;
    }

    N = (N % K);
    while(1){
        prevN = N;
        if(N > K){
            N = N - K;
        }else{
            N = K - N;
        }
        if ((prevN < N) || ( N < 0 ))
        {
            printf("%lld", prevN);
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
#include <numeric>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <stack>

using namespace std;

#define rep(i,n) for(int i = 0; i<n ; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)
#define REPSTR(i,s) for(int i=0; (s)[i]; i++)
#define REPITR(i,s) for(auto i=(s).begin(); i!=(s).end();i++)

#define RANGE(a,i,b) ((a)<=(i)&&(i)<=(b))

#define pb push_back
#define mp make_pair

#define ALL(a) (a).begin(), (a).end()

#define EXIST(s,x) ((s).find(x)!=(s).end())

#define SET(a,c) memset(a,c,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))

#ifdef _DEBUG
#define DEBUG(x) cerr<<#x<<":"<<x<<endl
#else
#define DEBUG(x)
#endif

#define PRINTJOIN(x,n) rep(i,n){if(i)cout<<" ";cout<<x[i];}cout<<endl 

#define INF 1001001001
#define LLINF 1001001001001001001LL

typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef stringstream SS;

#define PQ priority_queue

#define FST first
#define SEC second

int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//------------------HEAD---------------------

const int MAX = 1505*1505;

int H[MAX];
int h[1500];
int sh[1500];

int W[MAX];
int w[1500];
int sw[1500];

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
    while(1){
    fill(H, H+MAX, INF);
    fill(W, W+MAX, INF);
    int N, M;
    cin>>N>>M;
    if(N==0&&M==0) break;
    rep(i,N){
        cin>>h[i];
        if(i==0) sh[i]=h[i];
        else sh[i] = sh[i-1]+h[i];
    }
    rep(i, M){
        cin>>w[i];
        if(i==0) sw[i]=w[i];
        else sw[i] = sw[i-1]+w[i];
    }

    rep(i,N)rep(j,i+1){
        // j~iを使う場合
        H[i+j*N] = sh[i] - (j==0?0:sh[j-1]);
    }
    rep(i,M)rep(j,i+1){
        // j~iを使う場合
        W[i+j*M] = sw[i] - (j==0?0:sw[j-1]);
    }
    sort(H, H+MAX);
    sort(W, W+MAX);
    int i, j;
    i=j=0;
    int ans=0;
    while(H[i]!=INF || W[j]!= INF){
        while(H[i]!=W[j] && (H[i]!=INF || W[j]!= INF)){
            ++(H[i]<W[j]?i:j);
        }
        int n,m,k;
        if(H[i]==INF)break;
        n=m=0;
        k=H[i];
        while(H[i]==k){
            ++i;
            ++n;
        }
        while(W[j]==k){
            ++j;
            ++m;
        }
        ans+=n*m;
    }
    cout<<ans<<endl;
}
	return 0;
}


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

bool sortBySec(const pair <int, int> &a, const pair <int, int> &b){
    return (a.second < b.second);
}

int main(){

    int n, a, b;
    long long curr = 0;

    cin >> n;
    vector <pair <int, int>> v;
    for(int i = 0; i < n; i++){
        cin >> a >> b;
        v.push_back({a, b});
    }
    sort(v.begin(), v.end(), sortBySec);
    for(auto i : v){
        if(curr + i.first > i.second){
            cout << "No" << endl;
            return 0;
        }
        curr += i.first;
    }
    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <array>
#include <tuple>
#include <utility>
#include <numeric>
#include <iomanip>
#include <cctype>
#include <cmath>
#include <assert.h>
#include <cstdlib>
#include <list>
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
 
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {
    return s << "(" << p.first << ", " << p.second << ")";
}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s << "[";
    for (int i = 0; i < v.size(); i++) s << (i == 0 ? "" : ", ") << v[i];
    s << "]";
    return s;
}
 
#define ALL(a) (a).begin(), (a).end()
 
ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
 
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
 
int main() {
    int N;
    cin >> N;
    vector<ll> T(N);
    for (int i = 0; i < N; i++) {
        cin >> T[i];
    }
    ll val = 1;
    for (int i = 0; i < N; i++) {
        val = lcm(val, T[i]);
    }
    cout << val << endl;
 
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int ans=1;
  if(n==1){cout<<0<<endl;return 0;}
  rep(i,n){
    ans*=9;
    ans%=MOD;
  }
  ans*=2;
  ans%=MOD;
  int ans2=1;
  rep(i,n){
    ans2*=8;
    ans2%=MOD;
  }
  ans-=ans2;
   while(ans<0) ans+=MOD;
  int num=1;
  rep(i,n){
    num*=10;
    num%=MOD;
  }
  ans=num-ans;
   while(ans<0) ans+=MOD;
  cout<<ans<<endl;
  


  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

int main() {
    ll x;
    cin >> x;

    if(x >= 30) {
        out("Yes");
    }
    else {
        out("No");
    }
    
    re0;
}

Measured memory_bytes: 3628
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <cstring>
#include <queue>
#include <sys/time.h>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ( (a)/__gcd((a),(b))*(b) )

template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}

int board[10][10];
int dx[] = {0,1,0,-1,1,-1,1,-1};
int dy[] = {1,0,-1,0,1,-1,-1,1};

int rev(int c,int x,int y,int d ,int depth,int flag){
	if(depth == 0 && board[y][x] != -1 && flag == 0) return 0;
	//cout << x << " " << y << " " << board[y][x] << endl;
	if(depth != 0 && board[y][x] == -1) return 0;
	if(depth == 1 && board[y][x] == c) return 0;
	if(depth >= 2 && c == board[y][x]){ return depth-1; }
	int r = rev(c,x+dx[d],y+dy[d],d,depth+1,flag);
	if(r){
		if(flag) board[y][x] = c;
		
		return r;
	}
	return 0;
	
}

int ableCnt(int c,int x,int y,bool flag){
	int cnt = 0;
	rep(i,8){
		cnt += rev(c,x,y,i,0,flag);
	}
	return cnt;
}


int main(){
	int turn = 0;
	rep(i,10)rep(j,10)board[i][j] = -1;
	for(int i = 1 ; i <= 8 ; i++)
	for(int j = 1 ; j <= 8 ; j++){char c; cin >> c; board[i][j] = c == '.' ? -1 : c == 'o' ? 0 : 1;}
	bool prev_passed = 0;

	while(1){
		int mx = -1 , px = -1, py = -1;
		if(turn == 0){
			rep(i,8)rep(j,8){
				 int get = ableCnt(turn,j+1,i+1,0);
				 if( mx < get){
					mx = get;
					px = j+1;
					py = i+1;
				 }
			}
		}else{
			for(int i = 7 ; i >= 0 ; i--){
				for(int j = 7 ; j >= 0 ; j--){
				 int get = ableCnt(turn,j+1,i+1,0);
				 if( mx < get){
					mx = get;
					px = j+1;
					py = i+1;
				 }
				}
			}
		}
		
		if(mx == 0){
			if(prev_passed)break;
			else prev_passed = true;
		}else{
			ableCnt(turn,px,py,1);
			prev_passed = false;
		}
		turn ^= 1;
	}
	rep(i,8){ rep(j,8) cout << (board[i+1][j+1]==-1?'.':board[i+1][j+1]==0?'o':'x');cout << endl;}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define INF 0x7f7f7f7f

using namespace std;

int n;
int a;
multiset<int>s;

int main()
{
    scanf("%d",&n);
    s.insert(-1);
    for(int i = 1;i <= n;i++)
    {
        scanf("%d",&a);
        multiset<int>::iterator it = s.lower_bound(a);
        if(it != s.begin())
            s.erase(--it);
        s.insert(a);
    }
    printf("%d\n",s.size());
    return 0;
}


Measured memory_bytes: 4992
S = list(input())
N = len(S)

cnt = 0
l = 0
r = N-1
while l<=r:
    if S[l]=="x" and S[r]!="x":
        l += 1
        cnt += 1
    elif S[l]!="x" and S[r]=="x":
        r += -1
        cnt += 1
    elif S[l]=="x" and S[r]=="x":
        l += 1
        r += -1
    elif S[l]!="x" and S[r]!="x":
        if S[l]==S[r]:
            l += 1
            r += -1
        else:
            cnt = -1
            break
print(cnt)

Measured memory_bytes: 49904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 2020;
const ll M = 998244353;
ll dc[MN*2][MN*2];
ll ch(ll n, ll k) {
	if(k < 0 || k > n) {return 0;}
	if(k <= 0 || k >= n) {return 1;}
	if(dc[n][k] != -1) {return dc[n][k];}
	ll res = ch(n-1,k-1) + ch(n-1,k);
	if(res >= M) {res -= M;}
	return dc[n][k] = res;
}
ll mul(ll a, ll b) {
	return (a*b)%M;
}
int main() {
	memset(dc,-1,sizeof(dc));
	ll n,k;
	cin >> k >> n;
	for(ll i=2;i<=2*k;i++) {
		ll ko = min(i/2,(2*k+2-i)/2);
		ll res = 0;
		int sn = 1;
		for(int i=0;i<=ko;i++) {
			res += sn*mul(ch(ko,i),ch(n+k-1-2*i,k-1));
			sn *= -1;
		}
		res = ((res%M)+M)%M;
		cout << res << '\n';
	}
}


Measured memory_bytes: 131244
#include <iostream>
#include <string>
using namespace std;
int main(){
	string ans = "AKIHABARA";
	string check = "KIHBR";
	string str;
	int i = -1,pos;
	cin >> str;
	if(str.length() < ans.length() && str.find("KIH") != -1){
		while((pos = str.find('A')) != -1){
			if(i == pos)
				break;
			str.erase(str.begin() + pos);
			i = pos;
		}
		if(str == check)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}else{
		if(str == ans)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
N, L = list(map(int, input().split()))
a = [(abs(L+i-1), L+i-1) for i in range(1, N+1)]
b = [L+i-1 for i in range(1, N+1)]
a = sorted(a, key=lambda x: x[0])

print(sum(b)-sorted(a)[0][1])


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n,x,ans;
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) 
	{
	scanf("%d",&x);
	if (x&1) ans=1; }
	if (!ans) cout << "second" << endl; else cout << "first" << endl;
}

Measured memory_bytes: 256