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

int main() {
  int N,M;
  cin >> N >> M;
  
  vector<int> count(N);
  
  for (int i = 0; i < M; i++) {
    int a,b;
    cin >> a >> b;
    
    count.at(a - 1)++;
    count.at(b - 1)++;
  }
  
  for (int i = 0; i < N; i++) {
    cout << count.at(i) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;

int vec[2001];
int dp[2001][2001][2];
int n;

// 현재 x, y까지 먹힌 상태고 tu의 차례일 때.
int go(int x, int y, int tu) {
	if (x == n || y == n) return abs(vec[x] - vec[y]);
	if (dp[x][y][tu] != -1) return dp[x][y][tu];
	
	int mav;
	if (tu == 0) {
		mav = 0;
		mav = max(mav, go(max(x, y) + 1, y, tu));
		mav = max(mav, go(max(x, y) + 1, y, tu ^ 1));
	}
	else {
		mav = 1e9;
		mav = min(mav, go(x, max(x, y) + 1, tu));
		mav = min(mav, go(x, max(x, y) + 1, tu ^ 1));
	}

	return dp[x][y][tu] = mav;
}

int main() {
	memset(dp, -1, sizeof(dp));
	int z, w;
	scanf("%d %d %d", &n, &z, &w);
	
	for (int i = 1; i <= n; i++)
		scanf("%d", &vec[i]);
	vec[0] = w;
	
	printf("%d", go(0, 0, 0));
}

Measured memory_bytes: 31744
from collections import deque
H,W,N = map(int,input().split())
graph = []
S = None
for i in range(H):
  row = list(input())
  if "S" in row:
    s = row.index("S")
    S = (i,s)
  graph.append(row)

def bfs(S, target):
  q = deque([S])
  visited = set()
  step = 0

  while q:
    l = len(q)
    next_q = deque()

    for _ in range(l):
      r,c = q.popleft()
      if graph[r][c] == str(target):
        return step, r, c
      visited.add((r,c))

      for x,y in [(1,0), (0,1), (-1,0), (0,-1)]:
        nr,nc = r+x,c+y
        if nr<0 or nc<0 or nr>=H or nc>=W: continue
        if (nr,nc) in visited: continue
        if (nr,nc) in next_q: continue
        if graph[nr][nc] == target:
          return step+1, nr, nc
        if graph[nr][nc] != "X":
          next_q.append((nr,nc))

    step += 1
    q = next_q

res = 0
for i in range(1, N+1):
  steps, x,y = bfs(S, i)
  S = (x,y)
  res += steps
  # print(i, steps, (x,y))

print(res)





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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007)
#define IINF (1<<28)
#define LINF (1LL<<60)
#define rep(i, n)      REP(i, 0, (n))
#define repc(i, n)     REPC(i, 0, (n))
#define REP(i, n, m)   for (int i = (int)(n); i <  (int)(m); i++)
#define REPC(i, n, m)  for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
#define yesno(cond)       YESNO((cond), "Yes", "No")
#define YESNO(cond, a, b) cout << ((cond) ? (a) : (b)) << "\n"

namespace solver {
  using namespace std;
  typedef long long ll;

  int N, as[410];
  ll sum[410], dp[410][410];

  void init() {
    cin >> N;
    rep(i, N) {
      cin >> as[i];
    }
  }

  ll rec(int l, int r) {
    if(dp[l][r] >= 0) return dp[l][r];
    if(r-l == 1) return dp[l][r] = 0;
    if(r-l == 2) return dp[l][r] = sum[r] - sum[l];
    dp[l][r] = LINF;
    REPC(m, l+1, r-1) dp[l][r] = min(dp[l][r], sum[r] - sum[l] + rec(l, m) + rec(m, r));
    return dp[l][r];
  }

  void solve() {
    rep(i, N) sum[i+1] = sum[i] + as[i];
    memset(dp, -1, sizeof dp);
    cout << rec(0, N) << "\n";
  }
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 1664
P[100005],M[100005],v[100005],i,j,N,Q,t;long long r;char q[100005];
int main()
{
	for(;scanf("%d%d",&N,&Q),N;)
	{
		for(i=r=0;i<N;P[i]=i,M[i]=0,i++);
		M[1]=1;
		for(i=2;i<=N;P[i]=t,i++)scanf("%d\n",&t);
		for(i=0;i<Q;i++)
		{
			scanf("%c %d\n",&q[i],&v[i]);
			if(q[i]=='M')M[v[i]]++;
		}
		for(i=Q-1;i>=0;i--)
		{
			if(q[i]=='M')M[v[i]]--;
			else
			{
				for(t=v[i];!M[t];t=P[t]);
				r+=t;
			}
		}
		printf("%lld\n",r);
	}
	return 0;
}

Measured memory_bytes: 1872
#include <bits/stdc++.h>
using namespace std;
long long f(int N, long long C, const vector<long long>& X, const vector<long long>& V) {
	long long r = 0;
	vector<long long> a1(N+1);
	vector<long long> a2(N+1);
	for (int i = 0; i < N; ++ i) a1[i+1] = a1[i] + V[i];
	for (int i = 0; i < N; ++ i) a2[i+1] = a2[i] + V[N-1-i];

	for (int i = 0; i < N; ++ i) r = max(r, a1[i+1]-X[i]);

	vector<long long> a3(N+1);
	for (int i = 0; i < N; ++ i) a3[i+1] = a1[i+1] - 2*X[i];

	vector<long long> a4(N+1);
	for (int i = 0; i < N; ++ i) a4[i+1] = a2[i+1] - (C-X[N-1-i]);

	vector<long long> a5(N+1);
	for (int i = 0; i < N; ++ i) {
		a5[i+1] = max(a5[i], a4[i+1]);
	}

	for (int i = 0; i < N; ++ i) {
		//cerr << a3[i+1] + a5[N-1-i] << endl;
		r = max(r, a3[i+1] + a5[N-1-i]);
	}

	return r;
}
int main() {
	int N;
	long long C;
	cin >> N >> C;
	vector<long long> X(N), V(N);
	for (int i = 0; i < N; ++ i) cin >> X[i] >> V[i];
	long long r = f(N,C,X,V);
	reverse(X.begin(), X.end());
	reverse(V.begin(), V.end());
	for (auto& x : X) x = C - x;
	r = max(r, f(N,C,X,V));
	cout << r << endl;
}


Measured memory_bytes: 5808
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;
const int MAXN = 305;

lint ipow(lint x, lint p){
	lint ret = 1, piv = x % mod;
	while(p){
		if(p&1) ret *= piv;
		piv *= piv;
		ret %= mod;
		piv %= mod;
		p >>= 1;
	}
	return ret % mod;
}

int n, d[MAXN];
lint fact[MAXN], invf[MAXN];
lint dp[MAXN][MAXN][MAXN];

lint f(int x, int y, int z){
	if(x == n) return (y == 0 && z == 0);
	if(y < 0 || z < 0) return 0;
	if(~dp[x][y][z]) return dp[x][y][z];
	lint ans = f(x + 1, y, z);
	if(d[x] > 1) ans += f(x + 1, y - 1, z - (d[x] - 2)) * (d[x] - 1);
	ans %= mod;
	return dp[x][y][z] = ans;
}

int main(){
	fact[0] = 1;
	for(int i=1; i<MAXN; i++) fact[i] = fact[i-1] * i % mod;
	for(int i=0; i<MAXN; i++) invf[i] = ipow(fact[i], mod-2);
	cin >> n;
	for(int i=0; i<n; i++) cin >> d[i];
	if(count(d, d + n, 2) == n){
		cout << fact[n-1] * ipow(2, mod - 2) % mod<< endl;
		return 0;
	}
	memset(dp, -1, sizeof(dp));
	lint ret = 0;
	for(int i=3; i<=n; i++){
		for(int j=1; j<=n; j++){
			lint ans = fact[n - 1 - i] * fact[i - 1] % mod;
			ans *= j;
			ans %= mod;
			ans *= f(0, i, j);
			ans %= mod;
			ret += ans;
		}
	}
	/*
	for(int i=1; i<(1<<n); i++){
		int ndg = 0, cnt = 0;
		lint ans = 1;
		for(int j=0; j<n; j++){
			if((i >> j) & 1){
				ans *= d[j] - 1;
				ans %= mod;
				cnt++;
				ndg += d[j] - 2;
			}
		}
		lint ans = fact[n - 1 - cnt] * fact[cnt - 1] % mod;
		ans *= ndg;
		ans %= mod;
		ret += ans;
	}*/
	ret %= mod;
	for(int j=0; j<n; j++) ret *= invf[d[j] - 1], ret %= mod;
	ret %= mod;
	ret *= (mod + 1) / 2;
	cout << ret % mod << endl;
}


Measured memory_bytes: 221952
#pragma GCC optimize("O3")
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

template<typename T> void fastin(T &num) {
  bool negative = false;
  T c;
  num = 0;
  c = getchar();
  if (c == '-') {
    negative = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) num = (num << 3) + (num << 1) + c - 48;
  if (negative) num *= -1;
}

template<typename T> void fastout(T &n) {
  T N = n, rev, count = 0;
  rev = N;
  if (N == 0) { 
    putchar('0');
    putchar('\n');
    return;
  }
  while ((rev % 10) == 0) { 
    ++count; rev /= 10;
  }
  rev = 0;
  while (N != 0) { 
    rev = (rev << 3) + (rev << 1) + N % 10;
    N /= 10;
  }
  while (rev != 0) { 
    putchar(rev % 10 + '0');
    rev /= 10;
  }
  while (count--) putchar('0');
  putchar('\n');
}

int main(){
    int N; fastin(N);
    vector<int> v(N);
    for (int i = 0; i < N; ++i) {
        fastin(v[i]); v[i] -= (i + 1);
    }
    sort(v.begin(), v.end());
    
    int b = v[N / 2];

    int64_t answer = 0;
    for (int i = 0; i < N; ++i) {
        answer += abs(v[i] - b);
    }
    
    fastout(answer);

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int n,k,d,c,i,j;
  scanf("%d%d",&n,&k);
  int a[n+2],count=n;
  for(i=0;i<n+1;i++)
    a[i]=0;
  for(i=0;i<k;i++){
    scanf("%d",&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(a[c]==0)
        count--;
      a[c]=1;
    }
  }
  printf("%d\n",count);
  return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max<R>(x,0.0));}

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

// Problem Specific Parameter:

int main(void){
	int n,k,x,y;
	cin >> n >> k >> x >> y;
	cout << min(n,k)*x+max(0,n-k)*y << endl;
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template<class T> using Tree = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define trav(t,a) for (auto& t: a)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;

#define f first
#define s second
#define pb push_back
#define sz(x) (int)(x).size()

const int MOD = 1000000007;
const double INF = 1e18;
const int MX = 100005;

int N,t;
vi adj[MX];
pi bound[MX];

int get(pi p) {
	int res = 0;
	FOR(i,p.f,p.s+1) res ^= 1<<i;
	return res;
}

map<int,bool> m;
vi ed;

int dfs(int x, int y) {
	int res = 0;
	bound[x].f = t++;
	trav(i,adj[x]) if (i != y) {
		int t = dfs(i,x)+1;
		res ^= t;
	}
	bound[x].s = t-1;
	return res;
}

bool win(int x) {
	if (m.count(x)) return m[x];
	trav(t,ed) if (x&t) if (!win(x^t)) return m[x] = 1;
	return m[x] = 0;
}

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> N;
	F0R(i,N-1) {
		int a,b; cin >> a >> b;
		adj[a].pb(b), adj[b].pb(a);
	}
	int x = dfs(1,0);
	if (x) cout << "Alice";
	else cout << "Bob";
}

Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-14

#define all(v) v.begin(),v.end()
// #define INF
// #define mp
// #define pb

// #define fi
// #define se

// #define each

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

typedef long long ll;

int main(){
	while(1){
		stack <char> st;
		string s = "";
		char q;
		q = getchar();
		//cout<<q<<endl;
		if(q=='\n'){
			q = getchar();
			if(q=='.'){
				return 0;
			}
		}
		
		s += q;

		while(1){
			string c;
			cin>>c;
			if(c[c.size()-1]!='.') s+= (' '+c);
			else{
				s += (' '+c);
				break;
			}
		}
		//cout<<s<<endl;
		if(s[0]=='.'&& s.size()==1) break;
		rep(i,s.size()){
			switch(s[i]){
				case '[': st.push('[');
				break;
				case '(': st.push('(');
				break;
				case ']': 
					if(st.empty()){
						cout << "no" << endl;
						goto END;
					}
					if(st.top()!='['){
						cout << "no" << endl;
						goto END;
					}else{
						st.pop();
					}
				break;
				case ')':
					if(st.empty()){
						cout << "no" << endl;
						goto END;
					}
					if(st.top()!='('){
					cout << "no" << endl;
					goto END;
					}else{
						st.pop();
					}
				break;
			}
		}
		if(!st.empty()) cout <<"no"<<endl;
		else cout << "yes"<<endl;
		END:;
	}
	return 0;
}

Measured memory_bytes: 3132
import           Control.Arrow ((&&&))
import           Control.Monad (replicateM)
import           Data.Function (on)
import           Data.List     (sort)
import           Data.Tuple    (swap)

main :: IO ()
main = do
  n <- readLn
  as <- replicateM n readLn
  print $ f n as

f :: Int -> [Int] -> Int
f n as = max (sum' cs1) (sum' cs2)
  where
    (cs1, cs2) = coefficients n
    sum' = sum . (zipWith (*) `on` sort) as

coefficients :: Int -> ([Int], [Int])
coefficients n | n < 2 = undefined
coefficients n = unzip $ zipWith ($) (cycle [id, swap]) $ map (id &&& negate) ns
  where
    ns = [1] ++ replicate (n - 2) 2 ++ [1]


Measured memory_bytes: 69756
n, m = map(int,input().split())
height = list(map(int,input().split()))
route = [set() for i in range(n)]
for i in range(m):
    a, b = map(int,input().split())
    if not (b - 1) in route[a - 1]:
        route[a - 1].add(b - 1)
        route[b - 1].add(a - 1)

out = 0
for i in range(n):
    if len(route[i]) == 0:
        out += 1
    else:
        flg = 1
        for j in route[i]:
            if height[i] <= height[j]:
                flg = 0
                break
        if flg == 1:
            out += 1

print(out)

Measured memory_bytes: 45352
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin>>N;
    
    cout1(N*(N+1)/2)
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//const ll MOD = 1000000007;
const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    fio();

    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int s1 = h1 * 60 + m1, s2 = h2 * 60 + m2;
    cout << s2 - s1 - k << endl;
}

Measured memory_bytes: 3640
using System;

namespace atcoderA
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);
            Console.WriteLine(b - a == c - b ? "YES" : "NO");
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <sstream>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
  ll n; cin>>n;
  ll ans = 0;
  reps(i,n-1){
    // if(i==n) continue;
    ans += i;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

int main(){
  char x,y;
  cin >> x >> y;
  if(x<y) cout << "<" << endl;
  if(x>y) cout << ">" << endl;
  if(x==y) cout << "=" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int i,a[n];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    float c[n],b;
    c[0]=(float)a[0];
    for(i=1; i<=n; i++)
    {
        c[i]=(float)a[i];
        b=(c[i]+c[i-1])/2;
        c[i]=b;
        b=0;
    }
    cout<<c[n-1]<<endl;
    return 0;
}


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

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long int lo;
#define pb push_back
#define st first
#define nd second
#define inf (int)1e9
#define N (int)1e5 * 5
#define mod (int)1e9 + 7
#define all(x) (x).begin(), (x).end()
int in(){ int a; cin >> a; return a; }

void solve(){
	lo n;
	cin >> n;
	string ans;
	while(n > 0){
		int m = (n - 1) % 26;
		ans += m + 'a';
		n = (n - m) / 26;
	}
	reverse(all(ans));
	cout << ans << endl;
}

int main(){
  	ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0); cerr.tie(0);
	// freopen("gir.gir", "r", stdin);
	// freopen("cik.cik", "w", stdout);
	int t = 1;
	// cin >> t;
	while(t--){
		solve();
	}
	return 0;
}

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

int main(){
  int a,b,c,h=0,t=0;
  char s;
  while(cin>>a>>s>>b>>s>>c){
    if(a==b)h++;
    else if(a*a+b*b==c*c)t++;
  }
  cout<<t<<endl<<h<<endl;
  return 0;
}

Measured memory_bytes: 2996
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <stdio.h>

int main()
{
    int h,a;
    scanf("%d %d",&h,&a);
    if(h%a==0)
    printf("%d",h/a);
    else
    printf("%d",(h/a)+1);
}


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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair

using namespace std;

using uint=unsigned int;
using ll=long long;

uint xor128(){
	static uint d[]={1145141919,1919810893,810893364,364114514};
	uint t=d[0]^(d[0]<<11);
	REP(i,3)
		d[i]=d[i+1];
	return d[3]=d[3]^(d[3]>>19)^(t^(t>>8));
}

struct Node{
	Node *l,*r;
	uint pri;
	int s,v,mn;
} buf[200000];

using NP=Node*;

NP newNode(int v){
	static int c=0;
	buf[c]=Node{NULL,NULL,xor128(),1,v,v};
	return &buf[c++];
}

const int inf=1145141919;

inline int Mini(NP x){
	return x?x->mn:inf;
}

inline int Size(NP x){
	return x?x->s:0;
}

inline NP Update(NP x){
	x->s=Size(x->l)+Size(x->r)+1;
	x->mn=min({x->v,Mini(x->l),Mini(x->r)});
	return x;
}

inline NP LinkL(NP x,NP l){
	x->l=l;
	return Update(x);
}

inline NP LinkR(NP x,NP r){
	x->r=r;
	return Update(x);
}

inline NP CutL(NP x){
	x->l=NULL;
	return Update(x);
}

inline NP CutR(NP x){
	x->r=NULL;
	return Update(x);
}

inline NP Merge(NP a,NP b){
	static pair<NP,bool> pl[128];
	int c=0;
	while(a&&b){
		if(a->pri>b->pri){
			pl[c++]=MP(a,true);
			a=a->r;
		}else{
			pl[c++]=MP(b,false);
			b=b->l;
		}
	}
	NP t=a?a:b;
	while(c){
		NP p=pl[--c].first;
		bool rch=pl[c].second;
		if(rch)
			LinkR(p,t);
		else
			LinkL(p,t);
		t=p;
	}
	return t;
}

using Res=Node;

inline Res Split(NP x,int k){
	if(k<=0)
		return Res{NULL,x};
	else if(x->s<=k)
		return Res{x,NULL};
	else if(k<=Size(x->l)){
		Res s=Split(x->l,k);
		return Res{s.l,Merge(s.r,CutL(x))};
	}else{
		Res s=Split(x->r,k-Size(x->l)-1);
		return Res{Merge(CutR(x),s.l),s.r};
	}
}

inline void Set(NP x,int k,int v){
	int ls=Size(x->l);
	if(k<ls)
		Set(x->l,k,v);
	else if(k==ls)
		x->v=v;
	else
		Set(x->r,k-ls-1,v);
	Update(x);
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

NP t[200000];

int main(){
	int n=read(),q=read();
	REP(i,n)
		t[i]=newNode(read());
	while(n>1){
		int k=n/2;
		REP(i,k)
			t[i]=Merge(t[i*2],t[i*2+1]);
		if(k*2<n)
			t[k]=t[k*2];
		n=(n+1)/2;
	}
	NP root=t[0];
	REP(_,q){
		int x=read(),y=read(),z=read();
		if(x==0){
			Res s1=Split(root,y);
			Res s2=Split(s1.r,z+1-y-1);
			Res s3=Split(s2.r,1);
			root=Merge(Merge(s1.l,s3.l),Merge(s2.l,s3.r));
		}else if(x==1){
			Res s1=Split(root,y);
			Res s2=Split(s1.r,z+1-y);
			printf("%d\n",Mini(s2.l));
			root=Merge(s1.l,Merge(s2.l,s2.r));
		}else if(x==2){
			Set(root,y,z);
		}
	}
}

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

using namespace std;
const int N=3e5+5;
int a[N];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector<pair<int,int> >v;
    for(int i=1;i<=n;i++)
    {
        int x;
        cin>>x;
        v.push_back({x,i});
    }
    sort(v.begin(),v.end());
    for(int i=0;i<v.size();i++)
    {
        if(i) cout<<" ";
        cout<<v[i].second;
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 1780
import java.util.Scanner;

public class Main
{
  public static void main(String[] args){
    Scanner s = new Scanner(System.in);
    while(s.hasNext()){
      int a = s.nextInt();
      int b = s.nextInt();
      System.out.println(Integer.toString(a+b).length());
    }
  }
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(12); 
  int n;
  double x[100], y[100], a = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> y[i];
  }
  for (int i = 0; i < n; i++) {
    a += abs(x[i] - y[i]);
  }
  cout << a << '\n';
  a = 0;
  for (int i = 0; i < n; i++) {
    a += pow(x[i] - y[i], 2);
  }
  cout << sqrt(a) << '\n';
  a = 0;
  for (int i = 0; i < n; i++) {
    a += pow(abs(x[i] - y[i]), 3);
  }
  cout << cbrt(a) << '\n';
  a = 0;
  for (int i = 0; i < n; i++) {
    a = max(a, abs(x[i] - y[i]));
  }
  cout << a << '\n';
  return 0;
}



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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define rALL(v) v.rbegin(), v.rend() 
#define pb(x) push_back(x)

using namespace std;
using ll=long long;

long mod=1e9+7;

int main() {
  int n,m;cin>>n;
  vector<int> t(n);
  int sum=0;
  rep(i,n){cin>>t[i];sum+=t[i];}
  cin>>m;
  rep(i,m){
    int p,x;cin>>p>>x;
    int ans=sum-t[p-1]+x;
    cout<<ans<<endl;
  }
}



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

int main(){
  int N;
  cin>>N;
  int a;
  int k=0;
  for(int i=0;i<N;i++){
    cin>>a;
    if(a%2)k++;
  }
  if(k%2)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    vector<double> x(n);
    vector<string> u(n);
    for (int i=0;i<n;i++){
        cin >> x[i] >> u[i];
    }

    double r=0.0;
    for (int i=0;i<n;i++){
        if(u[i] == "BTC"){
            r += x[i] * 380000.0;
        }else{
            r += x[i];
        }
    }
    cout << r << endl;
}


Measured memory_bytes: 256
class DoubleLinkedList
  Elem = Struct.new(:value, :prev, :next)

  def initialize
    @root = nil
    @last = nil
  end

  def insert(x)
    if @root
      new_elem = Elem.new(x, nil, @root)
      @root.prev = new_elem
      @root = new_elem
    else
      @root = Elem.new(x, nil, nil)
      @last = @root
    end
  end

  def delete(x)
    elem = @root
    while elem
      if elem.value == x
        elem.next.prev = elem.prev if elem.next
        elem.prev.next = elem.next if elem.prev
        @root = elem.next if @root == elem
        @last = elem.prev if @last == elem
        return
      end
      elem = elem.next
    end
  end

  def delete_first
    if @root
      new_root = @root.next
      @last = nil if @root == @last
      new_root.prev = nil if new_root
      @root.prev = nil
      @root.next = nil
      @root = new_root
    end
  end

  def delete_last
    if new_last = @last.prev
      new_last.next = nil
      @last.prev = nil
      @last = new_last
    elsif @last == @root
      @root = nil
      @last = nil
    end
  end

  def to_s
    result = String.new
    elem = @root
    while elem
      result << elem.value.to_s
      elem = elem.next
      result << " " if elem
    end

    result
  end
end

l = DoubleLinkedList.new

#l.insert(1)
#l.insert(2)
#l.insert(3)
#l.delete(3)
#l.insert(3)
#l.insert(4)
#l.delete(4)
#l.delete_first

gets.to_i.times do
  case input = gets.chomp
  when /^insert /
    l.insert input[7..-1].to_i
  when /^delete /
    l.delete input[7..-1].to_i
  when "deleteFirst"
    l.delete_first
  when "deleteLast"
    l.delete_last
  end
end

puts l.to_s



Measured memory_bytes: 57676
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mn=107;
const ll mnn=407;
ll w[mn];
ll v[mn];
ll dp[mn][mn][mnn];

int main(){
	ll N,W;cin>>N>>W;
	ll wf=-1;
	for(ll a=0;a<N;++a){cin>>w[a]>>v[a];if(wf==-1)wf=w[a];w[a]-=wf;}
	for(ll a=0;a<N;++a)for(ll b=0;b<=a;++b)for(ll c=0;c<=3*b;++c){
		dp[a+1][b][c]=max(dp[a+1][b][c],dp[a][b][c]);
		dp[a+1][b+1][c+w[a]]=max(dp[a+1][b+1][c+w[a]],dp[a][b][c]+v[a]);
	}
	ll ret=0;
	for(ll a=0;a<=N;++a)for(ll b=0;b<=3*a;++b){
		if((b+(wf*a))<=W)ret=max(ret,dp[N][a][b]);
	}
	cout<<ret<<endl;
	return 0;
}


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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  string s;
  cin >> s;

  int ans = 0;
  map<string, bool> used;
  string now = "";
  string pre = "";  
  for ( int i = 0; i < (int)s.size(); i++ ) {
    now += s[i];
    if ( now != pre ) {
      ans++;
      pre = now;
      now = "";
    }
  }

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


Measured memory_bytes: 720
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    string S;
    vector<ll> v(26);
    cin >> S;
    N = S.size();
    rep(i,N){
        v[S[i] - 'a']++;
    }
    ll sum = 0;
    rep(i,26){
        sum += v[i]*(v[i]-1)/2;
    }
    cout << N*(N-1)/2 + 1 - sum << endl;
}

Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String a = in.next();
            String b = in.next();

            int alen = a.length();
            int blen = b.length();
            if (alen > blen) {
                for (int i = 0; i < alen - blen; i++) {
                    b = "0" + b;
                }
            } else if (alen < blen) {
                for (int i = 0; i < blen - alen; i++) {
                    a = "0" + a;
                }
            }

            if (a.compareTo(b) < 0) {
                out.println("LESS");
            } else if (a.compareTo(b) > 0) {
                out.println("GREATER");
            } else {
                out.println("EQUAL");
            }

        }

    }
}



Measured memory_bytes: 23124
n,k=map(int,input().split())
p=[0]+list(map(int,input().split()))
for i in range(n+1):
  p[i]=(p[i]+1)/2
for i in range(n):
  p[i+1]+=p[i]
ans=0
for i in range(n-k+1):
  ans=max(ans,p[i+k]-p[i])
print(ans)

Measured memory_bytes: 99620
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
int main() {
  
  string A,B,C;
  cin>>A>>B>>C;
  
  deque<char> X;
  for(int i=0;i<A.size();i++){
    X.push_back(A[i]);
  }
  
  deque<char> Y;
  for(int i=0;i<B.size();i++){
    Y.push_back(B[i]);
  }
  
  deque<char> Z;
  for(int i=0;i<C.size();i++){
    Z.push_back(C[i]);
  }
  
  int check=1;
  
  string ans;
  
  
  while(true){
    if(check==1){
      if(X.empty()){
       ans="A";
       break;
      }
      if(X.front()=='a'){
        check=1;
        X.pop_front();
      }
      else if(X.front()=='b'){
        check=2;
        X.pop_front();
      }
      else if(X.front()=='c'){
        check=3;
        X.pop_front();
      }
    }
    else if(check==2){
            if(Y.empty()){
        ans="B";
        break;
    }
      if(Y.front()=='a'){
        check=1;
        Y.pop_front();
      }
      else if(Y.front()=='b'){
        check=2;
        Y.pop_front();
      }
      else if(Y.front()=='c'){
        check=3;
        Y.pop_front();
      }
    }
    else if(check==3){
       if(Z.empty()){
        ans="C";
        break;
      }
      if(Z.front()=='a'){
        check=1;
        Z.pop_front();
      }
      else if(Z.front()=='b'){
        check=2;
        Z.pop_front();
      }
      else if(Z.front()=='c'){
        check=3;
        Z.pop_front();
      }
    }
    }
  cout<<ans<<endl;
}

Measured memory_bytes: 3576
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 1 << 17, CL = 18;
char C[CM + CL], * ci = C + CL, * owa = C + CM, c;

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


	fread(ci, 1, CM, stdin);
	int N = 0;
	while ((c = *ci++) >= '0') N = N * 10 + c - '0';

	ll p[20][20] = {};
	rep(i, N) {
		if (ci - owa > 0) {
			memcpy(C, owa, CL);
			ci -= CM;
			fread(C + CL, 1, CM, stdin);
		}

		ll kari = 0;
		while ((c = *ci++) >= '0') kari = kari * 10 + c - '0';
		int d = 9;
		if (*(ci - 1) == '.') {
			while ((c = *ci++) >= '0') {
				kari = kari * 10 + c - '0';
				d--;
			}
		}

		int a = __builtin_ctzll(kari) + d;
		if (a > 18) a = 18;
		int b = d;
		while (kari % 5 == 0) {
			b++;
			kari /= 5;
		}
		p[a][b]++;
	}
	ll kotae = 0;
	rep(a, 19) rep(b, 19) if (p[a][b]) {
		ll P = p[a][b];
		for (int x = 18 - a; x <= 18; x++) {
			for (int y = 18 - b; y <= 18; y++) {
				kotae += P * p[x][y];
			}
		}
	}
	for (int a = 9; a <= 18; a++) {
		for (int b = 9; b <= 18; b++) {
			kotae -= p[a][b];
		}
	}

	printf("%lld\n", kotae / 2);

	Would you please return 0;
}

Measured memory_bytes: 1708
n, m = map(int, input().split())
ab = []
for i in range(n):
    ai, bi = map(int, input().split())
    ab.append([ai, bi])
cd = []
for i in range(m):
    ci, di = map(int, input().split())
    cd.append([ci, di])

ans = []
for i in range(n):
    ai, bi = ab[i]
    mini = 10**10
    for j in range(m):
        cj, dj = cd[j]
        dist = abs(ai-cj) + abs(bi-dj)
        if dist < mini:
            mini = dist
            ret = j+1
    ans.append(ret)

for ret in ans:
    print(ret)

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

int main()
{
long long n ,d ,t, sum ,h,i;
cin>>n;
h=0;
sum=0;
d=0;

for(i=0 ; i<n ;i++)
{
    cin>>t;
    if(h>t) {
            d=h-t;
            sum=sum+d;
            }

    h=max(h,t);


}
cout<<sum;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using l=long long;
int main(){
  l n,m;cin>>n>>m;
  priority_queue<l>p;
  while(n--){l x;cin>>x;p.push(x);}
  while(m--){l x=p.top();p.pop();
  p.push(x>>1);}
  l a=0;
   while(!p.empty())
   {l x=p.top();p.pop();a+=x;}
  cout<<a<<endl;
  }

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int NIL = -1;
const int INF = (1<<21);
const long long MOD = 1e9+7;
const int di[] = {-1, 0, 1, 0};
const int dj[] = {0, -1, 0, 1};

int main() {
  int N, M; cin >> N >> M;
  priority_queue<pair<int, int>> PQ;
  for (int i = 0; i < N; ++i) {
    int a; cin >> a;
    PQ.push(make_pair(a, 1));
  }
  for (int i = 0; i < M; ++i) {
    int b, c; cin >> b >> c;
    PQ.push(make_pair(c, b));
  }
  long long ans = 0;
  int cnt = 0;
  while (true) {
    pair<int, int> t = PQ.top();
    for (int i = 0; i < t.second; ++i) {
      ans+= t.first;
      cnt++;
      if (cnt == N) break;
    }
    PQ.pop();
    if (cnt == N) break;
  }
  cout << ans << endl;
}


Measured memory_bytes: 5348
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stdlib.h>
#include <math.h>
#include <string>
#include <time.h>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll n, m, ans=1;

int main(void)
{
	cin>>n>>m; ll i;
	if(abs(m-n)>=2) cout<<0;
	if(abs(m-n)>=2) return 0;
	for(i=1 ; i<=n ; i++) ans=(ans*i)%mod;
	for(i=1 ; i<=m ; i++) ans=(ans*i)%mod;
	if(m==n) ans=(ans*2)%mod;
	cout<<ans; return 0;
}

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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

bool is_sorted(int n, int *p) {
    bool sorted = true;
    rep(1, n) {
        if (p[i - 1] > p[i]) {
            sorted = false;
            break;
        }
    }

    return sorted;
}

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

    int p[n];
    rep(0, n) cin >> p[i];

    int tmp, cnt = 0;
    bool sorted;
    if (is_sorted(n, p)) {
        cnt++;
    } else {
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                tmp = p[i];
                p[i] = p[j];
                p[j] = tmp;

                sorted = is_sorted(n, p);
                
                tmp = p[i];
                p[i] = p[j];
                p[j] = tmp;

                if (sorted) {
                    cnt++;
                    break;
                }
            }
        }
    }

    cout << (0 < cnt ? "YES" : "NO") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
typedef __int128_t lll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n, a, b;std::cin >> n >> a >> b;
  if(n%(a+b)>a) std::cout << (n/(a+b))*a + a << '\n';
  else std::cout << (n/(a+b))*a + n%(a+b) << '\n';
  return 0;
}


Measured memory_bytes: 888
// みなさん私はカーティキー・シャルマです。LNMIITで勉強しています。私は2年目で、コロナパンデミックが発
// 生しています。世界は終わりそうだ。だから私はそれを最大限に生きたいと思っています。それはつまり、コー
// ドを最大限に意味しているのです。私の好きなアニメは「キメツノヤイバ」で、私の一番の男の子はゼニツで、
// 私の一番の女の子はネズコです。私の好きな呼吸スタイルは息吹です。私の最高の悪魔の血の芸術は、
// ククシボによって使用される月の息です。ムーザンは亡くなり、今ではタンジローがポップの新しい魔王です。
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
      FastIO
      lld a, b;
      cin >> a >> b;
      if (a >= 13){
      	cout << b;
      }
      else{
      	if (a >= 6&& a <= 12){
      		cout << b/2;
      	}
      	else{
      		cout << "0";
      	}
      }
      return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

		public static void main(String[] args){
			Scanner sc = new Scanner(System.in);
			int M = sc.nextInt();
			int x = 0;
			if(1 <= M && M <= 23) {x = 24 + (24 - M);}
			System.out.println(x);
   }
	}

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

const int limit = 50;

int n, m;
int a[limit], b[limit];

bool graph[limit][limit];
bool visited[limit];

void dfs(int v){
    visited[v] = true;
    for(int v2=0; v2<n; v2++){
        if(graph[v][v2]==false) continue;
        if(visited[v2]==true) continue;
        dfs(v2);
    }
}

int main(){
    cin >> n >> m;
    
    for(int i=0; i<m; i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    
    int ans=0;
    for(int i=0; i<m; i++){
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
        
        for(int j=0; j<n; j++) visited[j]=false;
        
        dfs(0);
        
        bool bridge=false;
        for(int j=0; j<n; j++) if(visited[j]==false) bridge=true;
        if(bridge) ans+=1;
        
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
from heapq import heapify, heappop, heappush

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

SUM = 0

""" 前半 """
left = a[:N]
SUM += sum(left)
heapify(left)

""" 後半 """
delete = [(i,a[i]) for i in range(N,3*N)]
delete.sort(key=lambda x:-x[1])
right = []
heapify(right)
for _ in range(N):
    tmp = delete.pop()
    SUM -= tmp[1]
    heappush(right, tmp)

ans = SUM
for i in range(N,2*N):
    # 前半
    tmp = heappop(left)
    if a[i] > tmp:
        SUM += a[i] - tmp
        heappush(left, a[i])
    else:
        heappush(left, tmp)
    
    # 後半
    tmp = heappop(right)
    if i == tmp[0]:
        while delete:
            sub = delete.pop()
            if i < sub[0]:
                break
        SUM += tmp[1] - sub[1]
        heappush(right, sub)
    else:
        heappush(right, tmp)

    ans = max(ans, SUM)

print(ans)

Measured memory_bytes: 46372
#include<bits/stdc++.h>
using namespace std;
int father[100500];
int dis[100500];
int find_father(int x) {
	if(father[x]==x)return x;
	int a1=father[x];
	int a2=find_father(father[x]);
	father[x]=a2;
	dis[x]=dis[x]+dis[a1];
	return a2;
}
int find_dis(int x) {
	if(father[x]==x)return 0;
	return find_dis(father[x])+dis[x];
}
int main(void) {
	int num,cas,L,R,D;
	cin>>num>>cas;
	for(int i=0; i<=num; i++) {
		father[i]=i;
		dis[i]=0;
	}
	while(cas--) {
		cin>>L>>R>>D;
		int fl=find_father(L);
		int fr=find_father(R);
		if(fl==fr) {
			if(dis[L]+D!=dis[R]) {
				cout<<"No"<<endl;
				return 0;
			}
		} else {
			father[fr]=fl;
			dis[fr]=find_dis(L)-find_dis(R)+D;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, ll> pil;
#define mp make_pair

const int N = (int)5e3 + 10;
const int M = 204;
int n, m;
ll a[N];
ll d[N];
ll b[N][M];
ll ans = 0;
vector<pil> c[M];

int main()
{
//    freopen("input.txt", "r", stdin);

    scanf("%d%d", &n, &m);
    for (int i = 1; i < n; i++)
    {
        scanf("%lld", &d[i]);
        a[i] = -d[i];
    }
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            scanf("%lld", &b[i][j]);
    for (int l = n - 1; l >= 0; l--)
    {
        for (int i = 0; i < m; i++)
        {
            a[l] += b[l][i];
            while(!c[i].empty())
            {
                int p = c[i].back().first;
                if (b[p][i] <= b[l][i])
                {
                    a[p] -= c[i].back().second;
                    c[i].pop_back();
                    continue;
                }
                a[p] -= c[i].back().second;
                c[i].back().second = b[p][i] - b[l][i];
                a[p] += c[i].back().second;
                break;
            }
            c[i].push_back(mp(l, b[l][i]));
        }
        ll sum = d[l];
        for (int r = l; r < n; r++)
        {
            sum += a[r];
            ans = max(ans, sum);
        }
    }
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 8448
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int gcd ( int a, int b ) {
    if ( a % b == 0 ) return b;
    return gcd( b, a % b);
}
int main(){
    int n;
    cin >> n;
    ll tmp_a;
    ll pre_a;
    ll gcd_num;
    rep(i, n) {
        pre_a = tmp_a;
        cin >> tmp_a;
        if ( i == 1 ) {
            gcd_num = gcd(tmp_a, pre_a);
        }
        else if ( i >= 2 ) {
            gcd_num = gcd(tmp_a, gcd_num);
        }
    }
    cout << gcd_num << endl;
    return 0;
}

Measured memory_bytes: 256