akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const int INF = 100000000;
 
int main(){
    int n;
    cin >> n;
    vector<ll> a(n + 1), b(n);
    for(int i = 0; i < n + 1; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }

    ll count = 0;
    for(int i = n - 1; i >= 0; i--){
        if(b[i] > a[i + 1]){
            count += a[i + 1];
            if(b[i] - a[i + 1] <= a[i]){
                count += b[i] - a[i + 1];
                a[i] = a[i] - (b[i] - a[i + 1]);
            }else{
                count += a[i];
                a[i] = 0;
            }
        }else{
            count += b[i];
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int gcd(int x,int y)
{
    while(x!=0&&y!=0)
    {
        if(x>=y)
            x=x%y;
        else if(y>x)
            y=y%x;
    }
    if(x>=y)
        return x;
    else
        return y;
}
int main()
{
    long long k;
    cin>>k;
    long long a,b,c;
    long long sum;
    if(k>=1&&k<=200)
    {
        sum=0;
        for(a=1; a<=k; a++)
        {
            for(b=1; b<=k; b++)
            {
                for(c=1; c<=k; c++)
                {
                    sum+=gcd(gcd(a,b),c);
                }
            }
        }
        cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
#define MAXN 100005
bool chkX[MAXN], chkY[MAXN], visit[MAXN];
vector<int> xline[MAXN], yline[MAXN];
int X[MAXN], Y[MAXN];
int main() {
	int N;
	cin >> N;
	ll ans = -N;

	for (int i = 0; i < N; i++) {
		int x, y;
		cin >> x >> y;
		X[i] = x;
		Y[i] = y;
		xline[x].push_back(i);
		yline[y].push_back(i);
	}

	for (int i = 0; i < N; i++) {
		if (visit[i]) continue;
		visit[i] = true;
		set<int> xdist, ydist;
		xdist.clear();
		ydist.clear();

		queue<int> q;
		q.push(i);
		while (q.size()) {
			int c = q.front(); q.pop();
			int x = X[c];
			int y = Y[c];
			xdist.insert(x);
			ydist.insert(y);

			if (chkX[x] == false) {
				chkX[x] = true;
				for (auto nx : xline[x]) {
					if (visit[nx] == false) {
						visit[nx] = true;
						q.push(nx);
					}
				}
			}

			if (chkY[y] == false) {
				chkY[y] = true;
				for (auto ny : yline[y]) {
					if (visit[ny] == false) {
						visit[ny] = true;
						q.push(ny);
					}
				}
			}
		}

		ans += (ll)xdist.size() * (ll)ydist.size();
	}

	cout << ans << endl;
	return 0;

}

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

#define M1 1000000007
#define M2 1000000009
#define ll long long 
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define INF 1001001001
#define PI 3.1415926535897932384626
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define f0(i, n) for (int i = 0; i < (int)(n); ++i)
#define f1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define fc0(i,l,r) for(int i = (int)(l); i<(int)(r); ++i)
#define fc1(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define fr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii; 
 
void init()
{
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
      freopen("error.txt", "w", stderr);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
}
 
signed main()
{
    init();

    ll n;
    cin>>n;
    int a[10050];
    memset(a,0,sizeof(a));
    f1(i,100){f1(j,100){f1(k,100){int v=i*i+j*j+k*k+i*j+j*k+i*k;if(v<10050)a[v]+=1;}}}

    f0(i,n){cout<<a[i+1]<<endl;}

    cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define LL long long
using namespace std;
int main(){
    LL n;
    vector<LL> vc;
    while(cin>>n){
        LL temp=n,res=0;
        if(n==0){return 0;}
        for(int i=1; i*i<=n; i++){
            if(n%i==0){
                if(0==n%i){
                    res+=i;
                    if(i!=n/i){res+=n/i;}
                }
            }
        }
        res-=temp;
        cout << (res==temp?"perfect number":res<temp?"deficient number":"abundant number") << endl;
    }    
    return 0;
}

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

int main()
{
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    
    int dx,dy;
    dx = x2-x1;
    dy = y2-y1;
    
    cout << x2-dy << " " 
        << y2+dx << " "
        << x1-dy << " "
        << y1+dx << endl;
    
}



Measured memory_bytes: 3636
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
3 4 6
0 0
0 2
0 3
1 1
2 1
2 3

output:
3
"""

import sys


def generate_adj_table(_edges):
    for edge in _edges:
        vx, vy = map(int, edge)
        init_adj_table[vx].append(vy)

    return init_adj_table


def graph_dfs(current, matching, visited):
    for adj in range(y_num):
        if (not visited[adj]) and adj in adj_table[current]:
            visited[adj] = True
            if matching[adj] == -1 or graph_dfs(matching[adj], matching, visited):
                matching[adj] = current
                return True
    return False


def mbm():
    matching = [-1] * y_num
    res = 0
    for v in range(x_num):
        visited = [False] * y_num
        if graph_dfs(v, matching, visited):
            res += 1
    # print(matching)
    return res


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    x_num, y_num, e_num = map(int, _input[0].split())
    edges = map(lambda x: x.split(), _input[1:])

    init_adj_table = [[] for _ in range(x_num)]
    adj_table = generate_adj_table(edges)
    print(mbm())

Measured memory_bytes: 8524
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

n=input()
tmp=0
for x in n:
    tmp+=int(x)
YesNo(tmp%9==0)

Measured memory_bytes: 67948
#include<bits/stdc++.h>
#define int long long
#define ld long double
#define ri register int
#define il inline
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define all(x) x.begin(),x.end() 
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define per(i,a,b) for(ri i=(a);i>=(b);--i)
#define ls (x<<1)
#define rs (x<<1|1)
#define mid (l+r>>1)
#define db(x) cout << "#x:" << x << endl
#define dd() cout << "Out put!\n"
const int mod=1e9+7,maxn=1000010;
const double eps=1e-8,pi=acos(-1.0);
const int inf=0x7f7f7f7f;
using namespace std;
int a[maxn],b[maxn],v[maxn];
string s;
signed main()
{
	ios::sync_with_stdio(0);
		int n,m,k;
		cin >> n >> m >>k;
		rep(i,1,n)
			cin >> a[i];
		rep(i,1,m)
			cin >> b[i];
		a[0] = b[0] = 0;
		rep(i,1,n)
			a[i] += a[i-1];
		rep(i,1,m)
			b[i] += b[i-1];
		int ans = 0;
		rep(i,0,n)
		{
			if(k < a[i])	
				break;
			int res = 0;
			int x = upper_bound(b+1,b+1+m,k-a[i])-b-1;
			res = i+x;
			ans = max(ans,res);
		//	cout << i <<" " << x << endl;
		}
		cout << ans << endl;
}


Measured memory_bytes: 6820
import sys,os,io
# input = sys.stdin.readline
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

N = int(input())
edge = [[] for _ in range(N)]
for i in range(N-1):
  a,b = list(map(int, input().split()))
  edge[a-1].append(b-1)
  edge[b-1].append(a-1)
mod = 10**9+7

def fact(N):
  ans = [1]*(N+1)
  for i in range(1,N+1):
    ans[i] = ans[i-1]*i%mod
  return ans

def combs_mod(n,k):
  #nC0からnCkまで
  inv = [1]*(k+1)
  for i in range(1,k+1):
    inv[i] = pow(i,mod-2,mod)
  ans = [1]*(k+1)
  for i in range(1,k+1):
    ans[i] = ans[i-1]*(n+1-i)*inv[i]%mod
  return ans

def dfs(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  fac = fact(N)
  while stack:
    v = stack[-1]
    marker = 0
    for u in edge[v]:
      if u==parent[v]:
        continue
      if parent[u]==N: #子へ降ろす
        marker = 1
        parent[u] = v
        stack.append(u)
      else: #子から吸い上げる
        part_num[v] += part_num[u]
        ans[v] *= pow(fac[part_num[u]],mod-2,mod)*ans[u]%mod
        ans[v] %= mod
    if marker==0:
      stack.pop()
      ans[v] *= fac[part_num[v]-1]
      ans[v] %= mod
  return

def dfs2(start):
  stack = [start]
  parent = [N]*N
  parent[start] = -1
  p_value = [0]*N
  combs = combs_mod(N-1,N-1)
  while stack:
    v = stack.pop()
    for i,u in enumerate(edge[v]):
      if u==parent[v]:
        continue
      parent[u]=v
      p_value[u] = ans[v]*pow(ans[u]*combs[part_num[u]],mod-2,mod)%mod
      ans[u] *= combs[part_num[u]-1]*p_value[u]
      ans[u] %= mod
      stack.append(u)
  return

ans = [1]*N
part_num = [1]*N
dfs(0)
dfs2(0)
print(*ans, sep='\n')

Measured memory_bytes: 191864
#include<iostream>
#include<stdio.h>
#include<vector>//s1.erase(n)=文字列s1の、n文字目以降削除
#include<algorithm>//辞書順=next_permutation
#include<set>
#include<string>//char 小文字のほうが32大きい
#include<sstream>
#include<string.h>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap=数値交換
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())
#define asas int ans=0
#define llcncn llint cnt=0
#define llasas llint ans=0
#define str string
#define please return
#define AC 0
#define Rapid cin.tie(0);ios::sync_with_stdio(false)
#define Pi 3.1415926535897932384626
#define nine 1000000000

using namespace std;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {

	int a, b;
	cin >> a >> b;
	cout << a * b - a - b + 1 << rt;

	please AC;
}

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

int main(){
  int N;
  long long x;
  cin >> N >> x;
  vector<long long> a(N);
  for(int i=0; i<N; i++) cin >> a.at(i);
  sort(a.begin(), a.end());
  long long ans=0;
  for(int i=0; i<N; i++){
    x-=a.at(i);
    if(x>=0) ans++;
  }
  if(x>0) ans=N-1;
  
  cout << ans << endl;
}

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

int main(){
    int n; cin >> n;
    vector<int> lis(8, 0);
    int count = 0;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        if(a <= 399){
            lis[0]++;
        }else if(a <= 799){
            lis[1]++;
        }else if(a <= 1199){
            lis[2]++;
        }else if(a <= 1599){
            lis[3]++;
        }else if(a <= 1999){
            lis[4]++;
        }else if(a <= 2399){
            lis[5]++;
        }else if(a <= 2799){
            lis[6]++;
        }else if(a <= 3199){
            lis[7]++;
        }else{
            count++;
        }
    }
    int ans1 = 0;
    for(int i = 0; i < 8; i++){
        if(lis[i] > 0){
            ans1++;
        }
    }
    cout << max(ans1, 1) << " " << ans1 + count << endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

from functools import lru_cache

A, B, C, X, Y = map(int, input().split())

# 4通りしかない

# A, Bをそれぞれ買う
ans = A * X + B * Y

# AB + A or B
if X < Y:
    tmp = X * (2 * C)
    tmp += abs(X - Y) * B
else:
    tmp = Y * (2 * C)
    tmp += abs(X - Y) * A
ans = min(ans, tmp)

# AB
ans = min(ans, max(X, Y) * (2 * C))

print(ans)


Measured memory_bytes: 9540
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cstdio>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007
#define MAXS(x,y) (x = max(x,y))
#define MINS(x,y) (x = min(x,y))

using namespace std;

typedef long long int ll;

const ll INF=(ll)1e18;

vector<int> pre, in, post;

int N, M;

vector<vector<int> > e;
vector<vector<int> > r;

vector<int> depth;
vector<int> parent;
vector<int> par_size;
queue<pair<int, pair<int, int> > > que;

void wfs(int n, int d, int p){

  depth[n] = d;

  REP(i, e[n].size())que.push(make_pair(e[n][i], make_pair(d+1, n)));

  while(!que.empty()){
    pair<int, pair<int,int> > p = que.front();
    que.pop();

    if(par_size[p.first] > 1){
      par_size[p.first] -= 1;
      continue;
    }

    depth[p.first] = p.second.first;
    parent[p.first] = p.second.second;
    REP(i, e[p.first].size()){
      que.push(make_pair(e[p.first][i], make_pair(p.second.first+1, p.first)));
    }
  }
}

int main(){
  cin >> N >> M;

  e.resize(N+1);
  r.resize(N+1);
  par_size.resize(N+1);
  parent.resize(N+1);


  depth.resize(N+1);
  REP(i,N+1)depth[i] = -1;

  REP(i,N+M-1){
    int a, b;
    cin >> a >> b;
    e[a].push_back(b);
    r[b].push_back(a);
  }

  int root = -1;
  FOR(i,1,N+1){

    if(r[i].size() == 0){
      root = i;
    }
    par_size[i] = r[i].size();
  }

  wfs(root, 1, 0);

  FOR(i,1,N+1){
    cout << parent[i] << endl;
  }
}



Measured memory_bytes: 12928
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int main()  {
    int n,a;
    cin>>n>>a;
    ll x[n];
    for(int i=0;i<n;i++)    {
        cin>>x[i];
        x[i]-=a;
    }
    ll dp[n+1][2*a*n+1]={};
    dp[0][n*a]=1;
    for(int i=0;i<n;i++)
        for(int j=0;j<2*a*n;j++)    {
            if(j-x[i]<0 || j-x[i]>2*a*n)    {
                dp[i+1][j+1]=dp[i][j+1];
            }
            else
                dp[i+1][j+1]=dp[i][j+1]+dp[i][j+1-x[i]];
        }
    cout<<dp[n][a*n]-1<<endl;
    return 0;
}


Measured memory_bytes: 5600
"use strict";

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }

function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }

function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

!function () {
  function splitNum(line) {
    return (Array.isArray(line) ? line : line.split(/\s+/)).map(function (n) {
      return parseInt(n);
    });
  }

  !function (input) {
    var lines = input.split("\n");

    var _splitNum = splitNum(lines[0]),
        _splitNum2 = _slicedToArray(_splitNum, 2),
        N = _splitNum2[0],
        M = _splitNum2[1];

    var lrs = lines.slice(1, M + 1).map(function (line) {
      var _splitNum3 = splitNum(line),
          _splitNum4 = _slicedToArray(_splitNum3, 2),
          L = _splitNum4[0],
          R = _splitNum4[1];

      return {
        L: L,
        R: R
      };
    });
    var min = 1,
        max = N;
    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;

    try {
      for (var _iterator = lrs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var _step$value = _step.value,
            L = _step$value.L,
            R = _step$value.R;
        if (L > min) min = L;
        if (R < max) max = R;
      }
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion && _iterator.return != null) {
          _iterator.return();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }

    console.log(Math.max(0, max - min + 1));
  }(require("fs").readFileSync("/dev/stdin", "utf8"));
}();


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

int main() {
    string s;
    cin>>s;
    stack<int> pending;
    int ans = 0;
    for(int i = 0; i< s.length();i++){
        if(s[i] == 'S'){
            pending.push(i);
        } else {
          if (!pending.empty()) {
            pending.pop();
            ans++;
          }
        }
    }
    cout<<s.length() -(ans*2)<<endl;
    return 0;
}


Measured memory_bytes: 900
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using vpii = vector<pair<int, int>>;
using vpll = vector<pair<ll, ll>>;
// ceil() 切り上げ, floor() 切り捨て

int		main(void)
{
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> B(M);
	for (int i = 0; i < M; i++)
		cin >> B[i];
	int sum, ans= 0;
	for (int i = 0; i < N; i++)
	{
		sum = 0;
		for (int j = 0; j < M; j++)
		{
			int A;
			cin >> A;
			sum += A * B[j];
		}
		if (sum+C > 0)
			ans++;
	}
	cout << ans << endl;
}



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

using namespace std;

using ll= long long;

#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solve(){
	string a,b;
	cin>>a>>b;
	for(int i=0;i<sz(a);i++){
		if(a[i]!=b[i]){
			cout<<"No\n";
			return ;
		}
	}
	if(sz(a)+1==sz(b)){
		cout<<"Yes\n";
	}else
	{
		cout<<"No\n";
	}
	
}

int32_t main(){
	IOS

	int t;
	t=1;
	while(t--){
		solve();
	}
	return 0;
}

/*
   check for overflows int long long
   correct size of array
*/

Measured memory_bytes: 3612
n=int(input())
p=list(map(int,input().split()))
q=[j for j in range(1,n+1)]
cnt=0
for i in range(n):
  if p[i]!=q[i]:cnt+=1
    
if cnt==2 or cnt==0:
  print("YES")
else:
  print("NO")
    
  

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n,k;cin>>n>>k;
    vi a(n),b;
    int sum=0;
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    b.PB(1);b.PB(sum);
    for(int i=2;i*i<=sum;++i){
        if(sum%i==0){
            b.PB(i);
            if(i!=sum/i){
                b.PB(sum/i);
            }
        }
    }
    sort(all(b));
    int ans=1;
    for(int i=0;i<b.size();++i){
        vi c(n);
        rep(j,n){
            c[j]=a[j]%b[i];
        }
        sort(all(c));
        deque<int>d;
        rep(j,n){
            d.PB(c[j]);
        }
        int sum1=0,sum2=0;
        while(!d.empty()){
            while(sum1>=sum2&&!d.empty()){
                int u=d.back();
                d.pop_back();
                sum2+=b[i]-u;
            }
            while(sum1<sum2&&!d.empty()){
                int f=d.front();
                d.pop_front();
                sum1+=f;
            }
        }
        if(sum1<=k)ans=b[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {
	ll N;
	cin >> N;
	if (N < 105) {
		cout << 0 << endl;
	}
	else if (N < 135) {
		cout << 1 << endl;
	}
	else if (N < 165) {
		cout << 2 << endl;
	}
	else if (N < 189) {
		cout << 3 << endl;
	}
	else if (N < 195) {
		cout << 4 << endl;
	}
	else {
		cout << 5 << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <algorithm>
#include <cstdint>
#include <utility>
#include <iomanip>
#include <cstring>
using namespace std;
typedef long long ll;

int par[100005];

int root(int a) {
    if(par[a] == 0) return a;
    par[a] = root(par[a]);
    return par[a];
}
bool sme(int a,int b) {
    return root(a) == root(b);
}
void uni(int a,int b) {
    if(!sme(a,b))
        par[root(a)] = root(b);
}

int main() {
    int n,m;
    for(int i = 0;i < 100005;i++) par[i] = 0;
    cin >> n >> m;
    set<int> r;
    for(int i = 0;i < m;i++) {
        int x,y,z;
        cin >> x >> y >> z;
        uni(x,y);
    }
    for(int i = 1;i <= n;i++) {
        r.insert(root(i));
    }
    cout << r.size() << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

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

const int MAX_K = 80*160*10+1;
bool dp[81][81][MAX_K];

int A[81][81];
int B[81][81];

int main(){
    int H, W;
    cin >> H >> W;
    rep(i, H) rep(j, W) cin >> A[i][j];
    rep(i, H) rep(j, W) cin >> B[i][j];
    dp[0][0][abs(A[0][0]-B[0][0])] = true;
    rep(i, H) rep(j, W) rep(k, MAX_K) if(dp[i][j][k]) {
        if(i+1 < H) {
            int nxt;
            nxt = abs(k + abs(A[i+1][j] - B[i+1][j]));
            if(nxt < MAX_K) dp[i+1][j][nxt] = true;
            nxt = abs(k - abs(A[i+1][j] - B[i+1][j]));
            if(nxt < MAX_K) dp[i+1][j][nxt] = true;
        }
        if(j+1 < W) {
            int nxt;
            nxt = abs(k + abs(A[i][j+1] - B[i][j+1]));
            if(nxt < MAX_K) dp[i][j+1][nxt] = true;
            nxt = abs(k - abs(A[i][j+1] - B[i][j+1]));
            if(nxt < MAX_K) dp[i][j+1][nxt] = true;
        }
    }
    int ans = INF;
    rep(i, MAX_K) {
        if(dp[H-1][W-1][i]) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

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

  unsigned long long int p = 1;
  for (int i=1; i<=n; ++i) {
    p = p * i % (1000000000+7);
  }

  cout << p << endl;

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    int size = 3 * n;
    int a[size];
    for(int i = 0;i < size;i++)
    {
        cin >> a[i];
    }
    sort(a,a + size,greater<int>());
    int last = 2 * n;
    long long int ans = 0;
    for(int i = 1;i < last;i+=2)
    {
        ans += a[i];
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>

#define X first
#define Y second
#define pb push_back
#define int long long

using namespace std;

void pudge(){
    int n, k = 0, ans = 0, t = 5;
    cin >> n;
    if (n % 2) { cout << 0; return; }
    while(t <= n){
        ans += n / t / 2;
        t *= 5;
    }
    cout << ans << '\n';
}

signed main(){
#ifdef LOCAL
    freopen("pudge.in", "r", stdin);
    freopen("pudge.out", "w", stdout);
#endif
    ios_base::sync_with_stdio;
    cin.tie(0);
    cout.tie(0);

    pudge();

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    bool a = false;
    ll b = 0 ;
    ll c = 0;
    
    string str;
    cin >> str;
    if(str[0] == 'A') a = true;
    for(ll i = 2; i <= str.size()-2; i++){
        if(str[i] == 'C') b++;
    }
    rep(i, str.size()){
        if('a' <= str[i] && str[i] <= 'z'){
            c ++;
        }
    }
    if(a && (b==1) && (c == str.size()-2)){
        cout << "AC" << endl;
    }
    else cout << "WA" << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
inp = input()
inpmax, inplen = 0, 0
for inp_c in inp:
  if inp_c in 'ATCG':
    inplen += 1
  else:
    inpmax = max(inpmax, inplen)
    inplen = 0
inpmax = max(inpmax, inplen)
print(inpmax)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long int ll;
vector<int> v[100010];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s,t;
    cin >> s >> t;
    int ans = 0;
    rep(i,3){
        if(s[i]==t[i]){
            ans++;
        }
    }
    cout << ans << endl;
}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?b:a;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?a:b;}

namespace ae86
{
	const int bufl = 1<<15;
	
	char buf[bufl],*s=buf,*t=buf;
	
	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}
	
	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 100007;

int n,m,hav[_]={0},got[_]={0};

int main()
{
	n=ty(),m=ty(),hav[1]=1;
	for(int i=1;i<=n;i++)got[i]=1;
	for(int i=1,a,b;i<=m;i++)
	{
		a=ty(),b=ty(),got[b]++,hav[b]|=hav[a];
		if(--got[a]==0)hav[a]=0;
	}
	int cnt=0;
	for(int i=1;i<=n;i++)cnt+=hav[i];
	printf("%d\n",cnt);

	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
    long long int a,b,c,d,ans1,ans2,ans3,ans4;
    int i = 0;
    scanf("%lld %lld %lld %lld", &a,&b,&c,&d);
    ans1 = a * c;
    ans2 = b * d;
    ans3 = a * d;
    ans4 = b * c;
    if(ans1 >= ans2 && ans1 >= ans3 && ans1 >= ans4){
        printf("%lld\n", ans1);
    }else if(ans2 >= ans1 && ans2 >= ans3 && ans2 >= ans4){
        printf("%lld\n", ans2);
    }else if(ans3 >= ans2 && ans3 >= ans1 && ans3 >= ans4){
        printf("%lld\n", ans3);
    }else if(ans4 >= ans2 && ans4 >= ans3 && ans4 >= ans1){
        printf("%lld\n", ans4);
    }
    return 0;
}


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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

bool check(string s)
{
    li n=s.length();

    bool ans=true;

    f(i,0,n/2-1)
    {
        if(s[i]!=s[n-i-1])
        {
            ans=false;
        }
    }

    return ans;
}

int main()
{    
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    string s;

    cin>>s;

    li n=s.length();

    string t1,t2;

    t1=s.substr(0,(n-1)/2);
    t2=s.substr((n+1)/2,n-1);

    // cout<<t2;

    if(check(s) && check(t1) && check(t2))
    {
        cout<<"Yes";
    }
    else
        cout<<"No";

    return 0;
}

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

int main(){
	string str,op;
	string tmp;
	string p;
	int a , b; 
	int q;
	int i , j;
	cin>>str;
	cin>>q;
	for(i=0; i<q ; i++){
		cin>>op;
		cin>> a >> b;
		if(op=="print"){
			cout << str.substr(a,b-a+1) << endl;
		} else if (op=="reverse"){
			tmp=str.substr(a,b-a+1);
			for(j=0;j<tmp.length();j++){
				str[a+j]=tmp[tmp.length()-1-j];
			}
		} else if (op=="replace"){
			cin>>p;
			//for(j=0;j<b;j++){
				//str[a+j]=p[j];
				str=str.replace(a , b-a+1 , p);
			//}
		}
	}
	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

class Edge{
public:
	int edge_dist;
	int cost;
	Edge() : edge_dist(0), cost(0) {}
	Edge(int _dist, int _cost) : edge_dist(_dist), cost(_cost) {}
};

bool operator==(const Edge &a, const Edge &b){
	return (a.cost == b.cost);
}
bool operator!=(const Edge &a, const Edge &b){
	return !(a == b);
}
bool operator<(const Edge &a, const Edge &b){
	return (a.cost < b.cost);
}
bool operator>=(const Edge &a, const Edge &b){
	return !(a < b);
}
bool operator>(const Edge &a, const Edge &b){
	return (a.cost > b.cost);
}
bool operator<=(const Edge &a, const Edge &b){
	return !(a > b);
}
class Prim{
	vector< int > vlist; //??¢?´¢?????? -> 1 / else -> 0
	vector< vector< Edge > > edge;
	vector< Edge > tree;
	priority_queue< Edge, vector< Edge >, greater< Edge > > priq;
	
public:
	
	void Init(int size){
		vlist.clear();
		edge.clear();
		
		vlist.resize(size);
		edge.resize(size);
	}
	
	void Put(int s, int t, int cost){
		edge[s].push_back(Edge(t, cost));
	}
	
	int Run(){
		int sum_cost = 0;
		
		vlist[0] = 1;
		for(vector< Edge >::iterator it = edge[0].begin(); it != edge[0].end(); ++it){
			priq.push(*it);
		}
		
		while(!priq.empty()){
			
			Edge ed = priq.top();
			priq.pop();
			
			if(vlist[ed.edge_dist])continue;
			
			tree.push_back(ed);
			vlist[ed.edge_dist] = 1;
			sum_cost += ed.cost;
			
			for(vector< Edge >::iterator it = edge[ed.edge_dist].begin(); it != edge[ed.edge_dist].end(); ++it){
				if(vlist[(*it).edge_dist] == 0){
					priq.push(*it);
				}
			}
		}
		return sum_cost;
	}
};

int main(){
	
	int v, e, s, t, w;
	Prim prim;
	
	while(cin >> v >> e, v || e){
		
		prim.Init(v);
		
		for(int i = 0; i < e; ++i){
			cin >> s >> t >> w;
			
			prim.Put(s, t, w);
			prim.Put(t, s, w);
		}
		
		cout << prim.Run() << endl;
	}
}

Measured memory_bytes: 1212
include Math

until (n = $<.gets.to_i).zero?
  points = Array.new(n) { Complex(*$<.gets.split(",").map(&:to_f))  }
  ym = points.map(&:imaginary).max
  start_po = po0 = points.find {|po| po.imaginary == ym}
  prev_arg = PI
  
  result = loop do
    points = (points - [start_po] + [po0]).uniq
    selected = points.map {|po| [po - start_po, po]}
      .reject {|pos| pos.first == 0}
      .sort_by {|pos| a = pos.first.angle + PI - prev_arg; a >= 0 ? a : a + 2 * PI}
      .first.last
    points.select! {|po| po != start_po}
    if selected == po0
      break points.size - 1
    else
      prev_arg = (selected - start_po).angle + PI
      start_po = selected
    end
  end
  
  puts result
end


Measured memory_bytes: 7004
N = int(input())
A = list(map(int, input().split()))

not_in = [0 for i in range(N+1)]
not_in[0] = A[0]
for i in range(1, N+1):
  not_in[i] = not_in[i-1] * 2 + A[i]

if not_in[N] > 2 ** N:
  print(-1)
else:
  in_num = 0
  up = A[N]
  for i in range(N-1,-1,-1):
    in_temp = min(2 ** i - not_in[i], up)
    in_num += in_temp
    up = in_temp + A[i]
  print( in_num + sum(A) )


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


int main(){
    int a;  cin >> a;
    cout << fixed <<setprecision(8);
    double c=a;
    int b;
    b = (a+1)/2;
    cout << b/c << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define Fast ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD 1000000007
using namespace std;

int m,n;
int arr[1001][1001];
ll solve(int i, int j) {
    if(i==m-1 && j==n-1) return 1;
    if(i>m-1 || j>n-1) return 0;

    ll ans=0;
    if(arr[i+1][j]) ans+=solve(i+1, j)%MOD;
    if(arr[i][j+1]) ans+=solve(i, j+1)%MOD;

    return ans%MOD;
}

int main() {
    Fast
    
    cin>>m>>n;
    for(int i=0; i<m; i++) {
        for(int j=0; j<n; j++) {
            char x; cin>>x;
            if(x=='.') arr[i][j]=1;
            else arr[i][j]=0;
        }
    }

    //cout<<solve(0, 0)<<endl;

    ll dp[m][n];
    bool chk=false;

    for(int i=0; i<n; i++) {
        if(arr[0][i]==0) chk=true;

        if(chk) dp[0][i]=0;
        else dp[0][i]=1;
    }
    chk=false;
    for(int i=0; i<m; i++) {
        if(arr[i][0]==0) chk=true;

        if(chk) dp[i][0]=0;
        else dp[i][0]=1;
    }

    for(int i=1; i<m; i++) {
        for(int j=1; j<n; j++) {
            if(arr[i][j]==0) dp[i][j]=0;
            else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
        }
    }

    cout<<dp[m-1][n-1];
}

Measured memory_bytes: 12032
N, M, Q = map(int, input().split())
X=[0]*Q
for i in range(Q):
    X[i] = list(map(int, input().split()))
from itertools import combinations_with_replacement
def solve(N,M,Q,X):
    ans = 0
    for c in combinations_with_replacement(range(1,M+1), N-1):
        A = [1]+list(c)
        score = 0
        for x in X:
            if A[x[1]-1]-A[x[0]-1]==x[2]:
                score += x[3]
        ans = max(ans,score)
    return ans
print(solve(N,M,Q,X))

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

int main(){
  int N;
  cin >> N;
  if (N%1111==0)
    cout << "Yes" << endl;
  else if (N%(N/1000*1000)%111==0 || (N/10)%111==0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)
const ll mod = 1e9+7;
int main(){
   int n;
   cin >> n;
   ll ans=1;
   map<int,int> m;
   for (int t=1;t <= n;t++){
     int tmp;
     tmp=t;
    for (int i=2;i*i <= t;i++){
     while(tmp%i==0){
       if (tmp%i==0){
         m[i]++;
         tmp/=i;
       }
      }
    }
    if (tmp != 1) m[tmp]++;
   }
   for (auto q:m){
     //printf("q.first : %d q.second : %d\n",q.first, q.second);
     ans*=(ll)(q.second +1);
     ans%=mod;
   }
   cout << ans << endl;


   return 0;
}



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

int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}

int lower_bound(int *data,int num,int key){
	int min,max,mid;
	min = 0;
	max = num;
	mid = (min+max)/2;
	while((min+1 != mid || mid+1 != max) && mid!= min){
		if(key > data[mid]) min = mid;
		else max = mid+1;
		mid = (min+max)/2;
	}
	if(data[min] >= key) return min;
	if(data[mid] >= key) return mid;
	if(data[max] >= key) return max;
	return num;
}


int main(void){
	int N,i;
	long long x,y,ans = 0;
	scanf("%d",&N);
	int a[N],b[N],c[N];
	for(i=0;i<N;i++) scanf("%d",&a[i]);
	for(i=0;i<N;i++) scanf("%d",&b[i]);
	for(i=0;i<N;i++) scanf("%d",&c[i]);
	qsort(a, N, sizeof(int), compare_int);
	qsort(b, N, sizeof(int), compare_int);
	qsort(c, N, sizeof(int), compare_int);
	for(i=0;i<N;i++){
		x = lower_bound(a,N,b[i]);
		y = lower_bound(c,N,b[i]+1);
		ans += x*(N-y);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1e9 + 7;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    lint N;
    cin >> N;
    lint A, B;
    cin >> A >> B;
    if((A + B) % 2){
        cout << min(A + (B - A - 1) / 2, N - B + 1 + (B - A - 1) / 2) << endl;
    }else{
        cout << (B - A) / 2 << endl;
    }
}





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

int main(){
  char vowel;
  cin >> vowel;
  
  if(vowel=='a' || vowel=='i' || vowel=='u' || vowel=='e' || vowel=='o'){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

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

    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> key; 
    for(int i = 0; i< m; ++i)
    {
        int a, b;
        cin >> a >> b;
        int s = 0;
        for(int j =0; j < b; ++j)
        {
            int c; cin >> c;
            c--;
            s |= (1 << c);
        }
        key.emplace_back(s,a);
    }
    const int INF  = 1001001001;

    vector<int> dp(1 << n, INF);
    dp[0] = 0;
    for(int s = 0; s < (1 << n); ++s)
    {
        for(int i = 0; i< m; ++i)
        {
            int t = s | key[i].first;
            int cost  = dp[s] + key[i].second;
            dp[t] = min(dp[t],cost); 
        }
    }

    int ans = dp.back();
    if(ans == INF) cout << -1 << '\n';
    else cout << ans <<'\n';
    return 0;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#define ll long long

using namespace std;

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if( a + b + c >= 22 ){
    cout << "bust" << endl;
  }
  else{
    cout << "win" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n; cin>>n;
    vector<ll> a(n),s(n+1);
    rep(i,n) cin>>a[i];
    rep(i,n) {
        s[i+1] = s[i]+a[i];
    }
    ll ans = LINF;
    
    for (int i = 1; i < n; ++i) {
        ll tmp = abs(s[i]-(s[n]-s[i]));
        chmin(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)

const int pinf=((int)2e18);
const int ninf=((int)-2e18);
const int mod=1000000007;

using namespace std;

int power(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)
        return power((x*x)%M,n/2,M);
    else
        return (x*power((x*x)%M,(n-1)/2,M))%M;
}

bool check_prime(int n)
{
    if(n<2)
        return false;
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}

int setbits(int n)
{
    int count=0;
    while(n)
    {
        if(n%2==1)
            count++;
        n>>=1;
    }
    return count;
}

int lcm(int a,int b)
{
    return (a*b)/__gcd(a,b);
}

bool vowel(char c)
{
    return(c=='a' or c=='e' or c=='i' or c=='o' or c=='u' or c=='A' or c=='E' or c=='I' or c=='U' or c=='O');
}

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int x,n;
    cin>>x>>n;
    if(n==0)
    {
        cout<<x;
        return 0;
    }
    vector <int> a(n);
    map <int,int> m;
    loop(i,0,n)
    {
        cin>>a[i];
        m[a[i]]++;
    }

    int mn=pinf;

    loop(i,-200,201)
    {
        if(abs(i-x)<mn and !m[i])
        {
            mn=abs(i-x);
        }
    }

    loop(i,-200,201)
    {
        if(abs(i-x)==mn and !m[i])
        {
            cout<<i;
            return 0;
        }
    }



    return 0;
}


Measured memory_bytes: 3692
S = input()

A, B = int(S[:2]), int(S[2:])

x = 0 <= A <= 99 and 1 <= B <= 12
y = 1 <= A <= 12 and 0 <= B <= 99

if x and y:
    print('AMBIGUOUS')
elif x:
    print('YYMM')
elif y:
    print('MMYY')
else:
    print('NA')


Measured memory_bytes: 2940