akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

const int MOD = 1e9+7;
class mint {
    ll x;
public:
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {}
    
    mint operator -() const {
        return mint(-x);
    }
    
    mint &operator +=(const mint &a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator -=(const mint &a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }

    mint &operator *=(const mint &a) {
        (x *= a.x) %= MOD;
        return *this;
    }

    mint operator +(const mint &a) const {
        mint res(*this);
        return res += a;
    }

    mint operator-(const mint &a) const {
        mint res(*this);
        return res -= a;
    }

    mint operator *(const mint &a) const {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(MOD - 2);
    }

    mint &operator /=(const mint &a) {
        return (*this) *= a.inv();
    }

    mint operator /(const mint &a) const {
        mint res(*this);
        return res /= a;
    }

    friend ostream &operator<<(ostream& os, const mint &m) {
        os << m.x;
        return os;
    }
};

const int MAX = 2000010;
mint fac[MAX], finv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i-1] * mint(i);
        finv[i] = finv[i-1] * mint(i).inv();
    }
}

mint COM (int n, int k) {
    if (n < k) return mint(0);
    if (n < 0 || k < 0) return mint(0);
    // o(k)
    // if (k < MAX) {
    //     mint ret(1);
    //     Rep (i, k) {
    //         ret *= mint(n-i);
    //         ret /= mint(k-i);
    //     }
    //     return ret;
    // }

    return fac[n] * finv[k] * finv[n-k];
}

mint s(ll r, ll c) {
    mint a(0);
    Rep (i, r+1) a += COM(i+1+c, c);
    return a;
}

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

    ll r1, c1, r2, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    r1--; c1--;

    COMinit();

    // cout << s(r2, c2) << "\n";

    cout << s(r2, c2) - s(r1, c2) - s(r2, c1) + s(r1, c1) << endl;
}

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

int main(){
  int N;
  cin >> N;
  vector<string> S(N);
  for(int i=0; i<N; i++){
    cin >> S.at(i);
  }
  int AC=0, WA=0, TLE=0, RE=0;
  for(int i=0; i<N; i++){
    if(S.at(i)=="AC") AC++;
    if(S.at(i)=="WA") WA++;
    if(S.at(i)=="TLE") TLE++;
    if(S.at(i)=="RE") RE++;
  }
  cout << "AC x " << AC << endl;
  cout << "WA x " << WA << endl;
  cout << "TLE x " << TLE << endl;
  cout << "RE x " << RE << endl;
  return 0;
}

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

int main() {
  long long N,x,M;
  cin >> N >> x;
  M = N * 2 - 1;
  if (x == 1 || x == M) {
    cout << "No" << endl;
    return 0;
  }
  else {
    cout << "Yes" << endl;
  }
  
  if (N == 2) {
    cout << 1 << endl << 2 << endl << 3 << endl;
    return 0;
  }
  
  vector<long long> ans (M,-1);
  vector<bool> used (M+1,false);
  used[x] = true;
  
  if (x < N) {
    ans[N-1] = x;
    ans[N] = x+1;
    ans[N-2] = 1;
    ans[N-3] = x+2;
    used[x+1] = true;
    used[x+2] = true;
    used[1] = true;
  }
  else {
    ans[N-1] = x;
    ans[N] = x-1;
    ans[N-2] = M;
    ans[N-3] = x-2;
    used[x-1] = true;
    used[x-2] = true;
    used[M] = true;
  }
  
  long long now = 1;
  
  for (int i=0; i<M; i++) {
    while (used[now]) {
      now++;
    }
    if (ans[i] != -1) continue;
    ans[i] = now;
    used[now] = true;
  }
  
  for (int i=0; i<M; i++) {
    cout << ans[i] << endl;
  }
  
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<long long,long long> Pdd;

int main() {
     int n;
    string s;
    cin>>n>>s;
    rep(i,s.size()){
        s[i]=char((int(s[i])-int('A')+n)%26+int('A'));
    }
    cout<<s;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#define all(a) a.begin(),a.end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef complex<ld> com;
constexpr int inf = 1000000000;
constexpr ll INF = 1000000000000000000;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.141592653589793238;
template<class T, class U> inline bool chmax(T &a, const U &b) { if (a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if (a > b) { a = b; return true; } return false; }

ll solve(vector<P> p) {
	int n = p.size();
	vector<bool> vis(n);
	priority_queue<P, vector<P>, greater<P>> left;
	priority_queue<P> right;
	rep(i, n) {
		left.push(P(p[i].second, i));
		right.push(P(p[i].first, i));
	}
	int cnt = 0; ll res = 0; ll pl = 0; bool check = false;
	while (cnt < n) {
		bool ok = false;
		if (check) {
			while (!ok) {
				P q = left.top(); left.pop();
				if (!vis[q.second]) {
					ok = true;
					vis[q.second] = true;
				}
				res += max(pl - q.first, 0LL);
				pl -= max(pl - q.first, 0LL);
				cnt++;
			}
		}
		else {
			while (!ok) {
				P q = right.top(); right.pop();
				if (!vis[q.second]) {
					ok = true;
					vis[q.second] = true;
				}
				res += max(q.first - pl, 0LL);
				pl += max(q.first - pl, 0LL);
				cnt++;
			}
		}
		check = !check;
	}
	return res + abs(pl);
}


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

	int n;
	cin >> n;
	vector<P> p(n);
	rep(i, n) cin >> p[i].first >> p[i].second;
	ll ans = solve(p);
	rep(i, n) {
		p[i].first = -p[i].first;
		p[i].second = -p[i].second;
		swap(p[i].first, p[i].second);
	}
	cout << max(ans, solve(p)) << '\n';
}

Measured memory_bytes: 8976
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
    
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
const int INF = 1000*1000*1000;
const ll LINF = (ll)1e18;
int xv[4] = {-1, 1, 0, 0};
int yv[4] = {0, 0, -1, 1};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r(R);
    REP(i, R){
        cin >> r[i];
        r[i]--;
    }
    sort(r.begin(), r.end());
    vector<vector<ll>> mp(N, vector<ll>(N, LINF/2));
    REP(i, M){
        ll a, b, c;
        cin >> a >> b >> c;
        a--;b--;
        mp[a][b] = c;
        mp[b][a] = c;
    }
    REP(i, N){
        mp[i][i] = 0;
    }
    REP(k, N){
        REP(i, N){
            REP(j, N){
                mp[i][j] = min(mp[i][j], mp[i][k] + mp[k][j]);
            }
        }
    }
//    REP(i, N){
//        REP(j, N){
//            cout << mp[i][j] << " ";
//        }
//        cout << endl;
//    }
    //iota(r.begin(), r.end(), 1);
    ll ans = LINF;
    do{
        ll sum = 0;
        REP(i, R-1){
            sum += mp[r[i+1]][r[i]];
        }
//        cout << sum << endl;
        ans = min(ans, sum);
    }while(next_permutation(r.begin(), r.end()));
    cout << ans << endl;
    return 0;
}


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

int solve(vector<int> vec, int Q){
    int m = Q-1;
    int ans = 0;
    for(int i=1; i<110; i++){
        if(vec[i] > m){
            m = vec[i];
            ans = i;
        }
    }
    return ans;
}

int main(){
    int N, Q;
    while(cin >> N >> Q, N|Q){
        vector<int> vec(110);
        
        for(int i=0; i<N; i++){
            int m; cin >> m;
            for(int j=0; j<m; j++){
                int d; cin >> d;
                vec[d]++;
            }
        }
        
        cout << solve(vec, Q) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3148
n, x = map(int, input().split())
a = list(map(int, input().split()))

ans = 0
for i in range(1, n):
    if a[i] + a[i-1] > x:
        ans += a[i] + a[i-1] - x
        a[i] = max(0, x - a[i-1])
print(ans)


Measured memory_bytes: 14132
import sys
input=sys.stdin.readline
n=int(input())
A=list(map(int,input().split()))
B=[]
for a in A:
    B.append(abs(a))
cnt=0
for a in A:
    if a==0:
        cnt=0
    if a<0:
        cnt+=1
print(sum(B)-min(B)*2 if cnt%2 else sum(B))

Measured memory_bytes: 15180
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    let mut N: String;
    input! {
        N: String
    }

    let s: char = N.chars().nth_back(0).unwrap();

    match s {
        '0' => println!("pon"),
        '1' => println!("pon"),
        '3' => println!("bon"),
        '6' => println!("pon"),
        '8' => println!("pon"),
        _ => println!("hon"),
    }
}


Measured memory_bytes: 2088
#include <stdio.h>

int DetectDiceNum( int, int );	//?????´?????°????????????
int	TrnsDicNum( int );
int	RvsDiceNum( int );

int		dicenum[6];

int		main(void)
{
	//int		dicenum[6];
	int		i;
	int		q;
	int		upper, front, side;
	int		up, fr;

	for(i=0; i<6; i++)
	{
		scanf("%d",&dicenum[i]);
	}
	scanf("%d",&q);
	for(i=0; i<q; i++)
	{
		scanf("%d",&upper);
		scanf("%d",&front);

		up = TrnsDicNum( upper );
		fr = TrnsDicNum( front );

		side = DetectDiceNum(up, fr);
		printf("%d\n",RvsDiceNum(side));
	}

	return 0;
}

int	DetectDiceNum(int up, int fr)
{

	int		labeldice[6][4] =
		{{2,3,5,4},{1,4,6,3},{1,2,6,5},{1,5,6,2},{1,3,6,4},{2,4,5,3}};

	int		i;
	int		rst;

	for(i=0; i<4; i++)
	{
		if( labeldice[up-1][i] == fr )
		{
			if( i==3 )
			{
				rst = labeldice[up-1][0];
				break;
			}
			rst = labeldice[up-1][i+1];
			break;
		}
	}
	//printf("rst=%d\n",rst);
	return rst;
}

int		TrnsDicNum( int num )
{
	int		i;
	int		rst;

	for( i=0; i<6; i++ )
	{
		if( num == dicenum[i])
		{
			rst = i+1;
		}
	}
	//printf("rst =%d\n",rst);
	return rst;
}

int		RvsDiceNum( int num )
{
	return( dicenum[num-1]);
}

Measured memory_bytes: 596
#include <stdio.h>

typedef struct {
	int key, id;
} data;

typedef struct {
	data obj[51];
	int size;
} max_heap;

void push(data x, max_heap* h)
{
	int i = ++(h->size), j = i >> 1;
	data tmp;
	h->obj[i] = x;
	while (j > 0) {
		if (h->obj[i].key > h->obj[j].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j >>= 1;
		} else break;
	}
}

data pop(max_heap* h)
{
	int i = 1, j = 2;
	data output = h->obj[1], tmp;
	h->obj[1] = h->obj[(h->size)--];
	while (j <= h->size) {
		if (j < h->size && h->obj[j^1].key > h->obj[j].key) j ^= 1;
		if (h->obj[j].key > h->obj[i].key) {
			tmp = h->obj[j];
			h->obj[j] = h->obj[i];
			h->obj[i] = tmp;
			i = j;
			j <<= 1;
		} else break;
	}
	return output;
}


int main()
{
	int i, N, K, sum = 0;
	data d;
	max_heap h;
	h.size = 0;
	scanf("%d %d", &N, &K);
	for (i = 1; i <= N; i++) {
		scanf("%d", &(d.key));
		push(d, &h);
	}
	for (i = 1; i <= K; i++) {
		d = pop(&h);
		sum += d.key;
	}
	printf("%d\n", sum);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1692
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
using namespace std;

const int N = 7777;
int a[N];
int n, m;
int col;
vector < pair <int, int> > v;
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("flow2.in", "r", stdin);
    //freopen("flow2.out", "w", stdout);
    cin >> n;
    for (int i = 1; i <= n; i++){
        int x, l;
        cin >> x >> l;
        v.pb({x, l});
    }

    sort(v.begin(), v.end());

    int ans = 0 ;
    int lst = 0;

    for (int i = 0; i < v.size(); i++){
        if (ans == 0){
            ans++;
            lst = i;
            continue;
        }
        else {
            if (v[lst].fi + v[lst].se <= v[i].fi - v[i].se){
                lst = i;
                ans++;
            }
            else {
                if (v[lst].fi + v[lst].se <= v[i].fi + v[i].se){
                    continue;
                }
                else {
                    lst = i;
                }
            }
        }
    }

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


Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int a, b, c; cin >> a >> b >> c;
  if (a == 7 && (b == 5 && c == 5)) cout << "YES" << endl;
  else if (b == 7 && (a == 5 && c == 5)) cout << "YES" << endl;
  else if (c == 7 && (a == 5 && b == 5)) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        int n = Integer.parseInt(str[0]);
        int m = Integer.parseInt(str[1]);
        str = br.readLine().split(" ");
        for(int i=0; i<m ; ++i){
            n -= Integer.parseInt(str[i]);
        }
        if(n < 0){
            System.out.println(-1);
        }else{
            System.out.println(n);
        }
    }
}


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

#define REP(i,s,n) for(int i=s; i<n; ++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX

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

/*
class Node {
public:
  int num;
  int index;
  bool operator<(const Node& b) const {
    if(num < b.num) return (num < b.num);
    else return index > b.index;
  }

  Node(){
    num=0; index=0;
  }
  Node(int n, int i) : num(n), index(i){
  }
};
*/

int main(){

  int k, t;
  cin >> k >> t;
  vector<int> a(t);
  rep(i, t) cin >> a[i];

  SORT(a);

  if(a[t - 1] <= (k + 1) / 2) cout << 0 << endl;
  else cout << (a[t - 1] - ((k + 1) / 2)) * 2 - 1 << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int i,N;
    long long sum=0;
    cin>>N;
    for(i=1;i<=N;i++)
    {
        if(i%3!=0&&i%5!=0)
            sum=sum+i;
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    double m,sum;
    cin >> n;
  
    
    while (n != 0){
          vector<int> s(n);
        sum = 0;
        for (int i = 0; i < n; i++){
            cin >> s.at(i);
            sum += s.at(i);
        }
        m = sum / n;

        sum = 0;
        for (int i = 0; i < n; i++){
            sum += (s.at(i) - m) * (s.at(i) - m);
        }
                     

        sum /= n;
        cout << fixed << setprecision(15) << sqrt(sum) << endl;
        cin >> n;
    }
}


Measured memory_bytes: 3296
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>


using namespace std;


template <class ...Args>
void Input(Args &...args)
{
	(cin >> ... >> args);
}

template <class T>
void InputArray(std::size_t size, T &t)
{
	t.resize(size);
	for (auto &e : t) {
		cin >> e;
	}
}

template <class ...Args>
void InputArray(std::size_t size, Args &...args)
{
	(InputArray(size, args), ...);
}

template <class ...Args>
void InputVerticalArray(std::size_t size, Args &...args)
{
	(args.resize(size), ...);
	for (int i = 0; i < size; i++) {
		((cin >> args[i]), ...);
	}
}

template <class ...Args>
void Output(const Args &...args)
{
	((cout << args << ' '), ...) << endl;
}

template <class ...Args>
void OutputVertical(const Args &...args)
{
	((cout << args << endl), ...);
}

template <class T>
void OutputArray(const T &t)
{
	for (const auto &e : t) {
		cout << e << ' ';
	}
	cout << endl;
}

template <class ...Args>
void OutputArray(const Args &...args)
{
	(OutputArray(args), ...);
}

template <class ...Args>
void OutputVerticalArray(const Args &...args)
{
	for (int i = 0; i < min({ args.size()... }); i++) {
		((cout << args[i] << ' '), ...) << endl;
	}
}


#define inp(type, ...) \
	type __VA_ARGS__; \
	Input(__VA_ARGS__)

#define inpa(type, size, ...) \
	type __VA_ARGS__; \
	InputArray((size), __VA_ARGS__)

#define inpva(type, size, ...) \
	type __VA_ARGS__; \
	InputVerticalArray((size), __VA_ARGS__)

#define otp(...) \
	Output(__VA_ARGS__)

#define otpv(...) \
	OutputVertical(__VA_ARGS__)

#define otpa(...) \
	OutputArray(__VA_ARGS__)

#define otpva(...) \
	OutputVerticalArray(__VA_ARGS__)

#define rep(counter, range) \
	for (int (counter) = 0; (counter) < (range); (counter)++)

#define repi(range) \
	rep(i, range)

#define rrep(counter, range) \
	for (int (counter) = (range) - 1; (counter) >= 0; (counter)--)

#define rrepi(range) \
	rrep(i, range)

#define repc(element, container) \
	for (auto &(element) : (container))

#define repe(container) \
	repc(e, container)

#define all(container) \
	(container).begin(), (container).end()

#ifdef __CCR__
#	define dlog(x) clog << #x " = " << x << endl
#else
#	define dlog(x)
#endif



int main()
{
	inp(int, n, m);
	inpva(vector<int>, m, a, b);
	repe(a) e--;
	repe(b) e--;
	
	vector<vector<int>> human(n);
	repi(m) {
		human[a[i]].push_back(b[i]);
		human[b[i]].push_back(a[i]);
	}
	
	int cnt;
	vector<bool> seen(n);
	function<void(int)> dfs;
	dfs = [&](int v) {
		if (seen[v]) return;
		seen[v] = true;
		cnt++;
		repe(human[v]) {
			dfs(e);
		}
	};
	
	int cntmax = 0;
	repi(n) {
		if (!seen[i]) {
			cnt = 0;
			dfs(i);
			if (cnt > cntmax) cntmax = cnt;
		}
	}
	
	otp(cntmax);
	
	return 0;
}


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

int main(){
  int a,b,m;
  cin >> a >> b;
  m = max(a,b);
  rep(i,m){
    if(2*i == (a+b)){
      cout << i << endl;
      return 0;
    }
  }
  puts("IMPOSSIBLE");
}


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

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


ll gcd(ll x, ll y){
    return y ? gcd(y,x%y) : x;
}

vector<pair<ll,int> > factorize(ll n){
    vector<pair<ll,int> > res;
    for(ll i=2; i*i<=n; ++i){
        if(n%i) continue;
        res.emplace_back(i,0);
        while(n%i == 0){
            n/=i;
            res.back().second++;
        }
    }
    if(n!=1) res.emplace_back(n,1);
    return res;

}

int main(){
    ll a,b;
    cin >> a >> b;
    ll g = gcd(a,b);
    auto ans = factorize(g);
    cout <<ans.size()+1<<endl;
    return 0;
}


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

#define ms(s,n) memset(s,n,sizeof(s))
#define all(a) a.begin(),a.end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mk make_pair

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vii;

const int MOD = (int) 1e9+7;
const int INF = (int) 1e9+1;
inline ll gcd(ll a,ll b){ll r;while(b){r=a%b;a=b;b=r;}return a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int n;

int main(){
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	long long res=0,inf=a[0];
	for(int i=0;i<n;i++){
		if(a[i]<=inf){
			res+=inf-a[i];
		}
		else if(a[i]>inf){
			inf=a[i];
		}
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 4372
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
using namespace std;

typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

int main() {
	int n; cin >> n;
	int ans;
	for (int i = n; i > 0; i--) {
		if (sqrt(i) == (int)sqrt(i)) {
			ans = i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;

int main(){
  int N;
  string s, t;
  cin >> N >> s >> t;
  int cnt = 0;
  REP(i,N) {
    if(s.substr(i) == t.substr(0, N - i)) {
      cnt = N - i;
      break;
    }
  }
  int res = 2 * N - cnt;
  cout << res << endl;
  return 0;
}



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

typedef long long LL;
typedef unsigned long long ULL;
using namespace std;

char a[12];
// char a[5], b[2], c[2];

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	scanf("%s", a);
	
	int x = 0, y = 0, z = 0;
	int index;
	char c;
	for(int i = 0; i < 10; i++) {
		if(a[i] != '/') { x *= 10; x += a[i] - '0'; }
		else {index = i + 1; break; }
	}
	for(int i = index; i < 10; i++) {
		if(a[i] != '/') {y *= 10; y += a[i] - '0'; }
		else {index = i + 1; break; }
	}
	for(int i = index; i < 10; i++) {
		if(a[i] != '/' && a[i] != ' ') {z *= 10; z += a[i] - '0'; }
		else {index = i + 1; break; }
	}
	// not later than April 30 , 2019 
	// prints Heisei , otherwise prints TBD .
	// printf("%d %d %d", x, y, z);
	// cout << "\n";
	if(x < 2019) { puts("Heisei"); return 0;}
	else if(x > 2019) { puts("TBD"); return 0;}
	else {
		if(y < 4) { puts("Heisei"); return 0;}
		else if(y > 4) { puts("TBD"); return 0;}
		else {
			if(z <= 30) { puts("Heisei"); }
			else { puts("TBD"); }
		}
	}
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

N, M = map(int, input().split())
G = [[] for i in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

used = [0]*N
Q1 = []
Q2 = []
def dfs(v, Q):
    if used[v]:
        return 0
    used[v] = 1
    Q.append(v+1)
    for w in G[v]:
        if dfs(w, Q):
            return 1
    return 1

if len(G[0]) == 1:
    dfs(0, Q1)
    print(len(Q1))
    print(*Q1)
else:
    used[0] = 1
    for v in G[0]:
        if dfs(v, Q1):
            break
    for v in G[0]:
        if dfs(v, Q2):
            break
    print(len(Q1) + len(Q2) + 1)
    print(*(Q1[::-1]+[1]+Q2))


Measured memory_bytes: 108508
import scala.io.StdIn.{readLine,readInt}

object Main extends App {
  var w = ""

  def shuffle(cnt:Int, w:String):String = {
    if(cnt == 0) { w }
    else {
      val m = readInt
      shuffle(cnt-1, (w drop m)+(w take m))
    }
  }

  while( { w = readLine.trim;w } != "-") {
    val n = readInt
    println(shuffle(n,w))
  }
}

Measured memory_bytes: 43704
#include <cstdio>
#include <cstring>
using namespace std;
int main() {
  char str[21];
  scanf("%s", str);
  int len = strlen(str);
  for (int i = len-1; i >= 0; i--) {
    printf("%c", str[i]);
  }
  printf("\n");
  return 0;
}

  

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using graph = vector<vector<int>>;

bool is_cyclic(const graph& G) {
	int n = G.size();
	vector<bool> used(n), on(n);
	function<bool(int)> dfs = [&](int v) {
		used[v] = on[v] = true;
		for (int w : G[v]) {
			if (on[w]) return true;
			if (!used[w] && dfs(w)) return true;
		}
		on[v] = false;
		return false;
	};
	for (int i = 0; i < n; i++) {
		if (!used[i] && dfs(i)) return true;
	}
	return false;
}

vector<int> topological_sort(const graph& g) {
	const int n = g.size();
	vector<int> in(n), st, res;
	for (int i = 0; i < n; ++i) for (auto to : g[i]) ++in[to];
	for (int i = 0; i < n; ++i) if (in[i] == 0) st.push_back(i);
	while (!st.empty()) {
		int v = st.back(); st.pop_back();
		res.push_back(v);
		for (auto to : g[v]) {
			--in[to];
			if (in[to] == 0) st.push_back(to);
		}
	}
	assert(count(in.begin(), in.end(), 0) == n);
	return res;
}

int main()
{
	int N;
	cin >> N;
	vector<vector<int>> A(N, vector<int>(N - 1));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N - 1; j++) {
			cin >> A[i][j]; --A[i][j];
		}
	}
	graph G(N * N);
	for (int i = 0; i < N; i++) {
		for (int j = 1; j < N - 1; j++) {
			int x = min(i, A[i][j - 1]) * N + max(i, A[i][j - 1]);
			int y = min(i, A[i][j]) * N + max(i, A[i][j]);
			G[x].push_back(y);
		}
	}
	if (is_cyclic(G)) {
		cout << -1 << endl;
		return 0;
	}
	vector<int> dp(N * N);
	auto vs = topological_sort(G);
	for (auto v : vs) {
		for (auto to : G[v]) {
			dp[to] = max(dp[to], dp[v] + 1);
		}
	}
	cout << *max_element(dp.begin(), dp.end()) + 1 << endl;
	return 0;
}


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

typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=100000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    else return b;
}

int main(){
    ll n,k;cin>>n>>k;
    string s;cin>>s;
    n=s.size();
    ll a[n];
    for(ll i=0;i<n;i++){
        a[i]=0;
    }
    ll i;
    ll c=0;
    for(i=0;i<n;i++){
        if(i==0){
            a[c]=1;
        }else{
            if(s[i]!=s[i-1]){
                a[c+1]++;
                c++;
            }else{
                a[c]++;
            }
        }
    }
    ll sum=0;
    ll maxi=0;
    ll j=0;
    if(s[0]=='0'){
        i=0;
        sum=a[0];
        maxi=a[0];
        for(ll i=1;i<=c;i++){
            if(i%2==1){
                sum+=a[i];
                maxi=max(maxi,sum);
            }else{
                if(j==0){
                    if(i>=2*k){
                        sum=sum+a[i]-a[j];
                        maxi=max(maxi,sum);
                        j=1;
                    }else{
                        sum=sum+a[i];
                        maxi=max(maxi,sum);
                    }
                }else{
                    sum=sum+a[i]-a[j]-a[j+1];
                    maxi=max(maxi,sum);
                    j=j+2;
                }
            }
        }
    }else{
        i=0;
        sum=a[0];
        maxi=a[0];
        for(ll i=1;i<=c;i++){
            if(i%2==0){
                sum+=a[i];
                maxi=max(maxi,sum);
            }else{
                if(j==0){
                    if(i>=2*k+1){
                        sum=sum+a[i]-a[j]-a[j+1];
                        maxi=max(maxi,sum);
                        j=j+2;
                    }else{
                        sum=sum+a[i];
                        maxi=max(maxi,sum);
                    }
                }else{
                    sum=sum+a[i]-a[j]-a[j+1];
                    maxi=max(maxi,sum);
                    j=j+2;
                }
            }
        }
    }
    cout<<maxi<<endl;
    return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from itertools import permutations

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, c = map(int, input().split())
    D = [list(map(int, input().split())) for _ in range(c)]
    grid = [list(map(int, input().split())) for _ in range(n)]

    col_cnt = [[0] * c for _ in range(3)]
    for i in range(n):
        for j in range(n):
            col = grid[i][j] - 1
            col_cnt[(i + j + 2) % 3][col] += 1

    res = f_inf
    for pattern in permutations(list(range(c)), 3):
        cost = 0
        for idx, col in enumerate(pattern):
            for k in range(c):
                cnt = col_cnt[idx][k]
                cost += D[k][col] * cnt
        res = min(res, cost)
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 11720
/*
 * ALDS1_6_A.cpp
 *
 *  Created on: Apr 30, 2018
 *      Author: 13743
 */

#include<cstdio>

int main() {
	int n;
	int A[2000001];
	int B[2000001];
	int C[10001] = {0};

	scanf("%d", &n);
	for(int i=1; i<=n; i++) {
		scanf("%d", &A[i]);
		C[A[i]]++;
	}

	for(int i=0; i<10000; i++) {
		C[i+1] += C[i];
	}

	for(int i=1; i<=n; i++) {
		B[C[A[i]]] = A[i];
		C[A[i]]--;
	}

	printf("%d", B[1]);
	for(int i=2; i<=n; i++) {
		printf(" %d", B[i]);
	}
	printf("\n");
}





Measured memory_bytes: 18380
#include<bits/stdc++.h>
#include<stdio.h>
    
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define _USE_MATH_DEFINES
#define f first
//#define s second
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define INF 1000000000000000000
#define MAXN (int)(1e7)+1
#define MOD 1000000007
    
using namespace std;
    
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pwi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vector<pair<ll,ll > > > wGraph;
typedef vector<vector<ll> > graph;
//typedef vector<vector<ll> > matrix;
    

    
int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout<<std::fixed;
    cout<<std::setprecision(2);
    
    int d, t, s;

    cin>>d>>t>>s;

    if(d<=t*s) cout<<"Yes\n";
    else cout<<"No\n";
    
    return 0;   
}

Measured memory_bytes: 3644
import sys
input = sys.stdin.readline

Q,H,S,D = map(int,input().split())
H = min(H,2*Q) # 1 リットル
S = min(S,2*H) # 2 リットル

N = int(input())
answer = 0
if N&1:
    answer += S
D = min(D,2*S)
answer += (N//2)*D
print(answer)

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

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;

vector<int> a[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;

  int n, m;
  cin >> n >> m;
  vector<int> p(m), y(m);

  rep(i, m) {
    cin >> p[i] >> y[i];
    a[p[i]-1].push_back(y[i]);
  }

  rep(i, n) {
    sort(a[i].begin(), a[i].end());
  }

  rep(i, m) {
    printf("%06d", p[i]);
    int t = lower_bound(a[p[i]-1].begin(), a[p[i]-1].end(), y[i])-a[p[i]-1].begin();
    printf("%06d\n", t+1);
  }

  return 0;
}

Measured memory_bytes: 7808
import sys
input = sys.stdin.readline
n,a,b,c=map(int,input().split())
def d(x):
	if x=="AB":
		return 0
	elif x=="BC":
		return 1
	else:
		return 2
L=[d(input().rsplit()[0]) for _ in range(n)]
ABC=[a,b,c]
ans=[]
w="ABC"
append=ans.append
sha={1:1,3:2,2:0}
for i,x in enumerate(L):
	y=(x+1)%3
	if ABC[x]==ABC[y]==0:
		print("No")
		exit()
	elif ABC[x]==ABC[y]:
		if i<n-1:
			xx=L[i+1]
			if x==xx:
				append(w[x])
				ABC[x]+=1
				ABC[y]-=1
			else:
				ss=sha[x^xx]
				if x==ss:
					append(w[x])
					ABC[x]+=1
					ABC[y]-=1
				else:
					append(w[y])
					ABC[x]-=1
					ABC[y]+=1
		else:
			append(w[x])
	else:
		if ABC[x]>ABC[y]:
			x,y=y,x
		append(w[x])
		ABC[x]+=1
		ABC[y]-=1
print("Yes")
print("\n".join(ans))

Measured memory_bytes: 11316
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] problem = new int[n+1];
        int[] wa = new int[n+1];
        for (int i = 0; i < m; i++) {
            int p = sc.nextInt();
            String s = sc.next();
            if ("AC".equals(s)) {
                problem[p] = 1;
            } else {
                if (problem[p] != 1) {
                    wa[p]++;
                }
            }
        }

        int sumWA = 0;
        int sumAC = 0;
        for (int i = 0; i < n+1; i++) {
            if (problem[i] == 1) {
                sumAC++;
                sumWA += wa[i];
            }
        }

        System.out.println(sumAC +" "+sumWA);
    }
}


Measured memory_bytes: 67884
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;

int main() {
  ll x, k, d;
  cin >> x >> k >> d;
  ll now = x > 0 ? x : -x;
  if (k < now / d) {
    cout << now - d * k << endl;
    return 0;
  }
  k -= now / d;
  now -= now / d * d;
  ll ans = k % 2 == 0 ? now : -now + d;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>
int main() 
{
	int N,K,i,n = 1;
	scanf("%d",&N);
	scanf("%d",&K);
	for(i = 0;i < N;i++)
	{
		if(n < K)
		n = 2*n;
		else
		n = n + K;
	}
	printf("%d\n",n);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <list>
#include <iomanip>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
typedef pair<int,pair<int,int> >PP;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
struct Edge
{
  int to,cost;
  Edge(int _to,int _cost):to(_to),cost(_cost){};
};
vector<Edge> edge[105];
bool visited[105][105][105];
int n,m,l,k,a,h;
bool ice[105];
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};

int dijkstra()
{
  memset(visited,false,sizeof(visited));
  priority_queue<PP,vector<PP>,greater<PP> > pq;
  pq.push(mp(0,mp(a,m)));
  while(!pq.empty())
    {
      PP p=pq.top();
      pq.pop();
      if(p.se.fi==h) return p.fi;
      int T;
      if(ice[p.se.fi]) 
	{
	  T=m-p.se.se+1;
	}
      else
	{
	  T=1;
	}
      for(int i=0;i<T;i++)
	{
	  for(int j=0;j<edge[p.se.fi].size();j++)
	    {
	      Edge e=edge[p.se.fi][j];
	      if(e.cost > p.se.se+i) continue;
	      if(visited[p.se.fi][e.to][p.se.se+i-e.cost]) continue;
	      visited[p.se.fi][e.to][p.se.se+i-e.cost]=true;
	      pq.push(mp(p.fi+i+e.cost,mp(e.to,p.se.se+i-e.cost)));
	    }
	}
    }
  return -1;
}

void init()
{
  memset(ice,false,sizeof(ice));
  for(int i=0;i<100;i++)
    {
      edge[i].clear();
    }
}
int main(int argc,char const* argv[])
{
  while(cin >> n >> m >> l >> k >> a>> h && n)
    {
      init();
      for(int i=0;i<l;i++)
	{
	  int freeze;
	  cin >> freeze;
	  ice[freeze]=true;
	}
      for(int i=0;i<k;i++)
	{
	  int x,y,t;
	  cin >> x >> y >> t;
	  edge[x].pb(Edge(y,t));
	  edge[y].pb(Edge(x,t));
	}
	    
      int ans=dijkstra();
      if(ans==-1) cout << "Help!" << endl;
      else
	{
	  cout << ans << endl;
	}
    }
  return 0;
}



Measured memory_bytes: 5348
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
using namespace std;
#define int long long
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

/* 
    D - We Love ABC
*/
//================== INPUT ========================
string S;
//=================================================

//=================================================
void input()
{
    cin >> S;
}
//=================================================

int dp[100003][4] = {}; //dp[i][j]: S[i]まででの照合具合．
// 状態遷移
vector<int> V;
void solve()
{

    int N = S.size();
    V.resize(N);
    rep(i, N)
    {
        V[i] = (S[i] == '?' ? (-1LL) : (S[i] - 'A'));
    }
    // ? : 0, A : 1, B : 2, C : 3.

    // rep(i,N){
    //     cout<<V[i] << (i==N-1 ? "\n" : " ");
    // }

    dp[0][0] = 1;
    rep(i, N)
    {
        rep(j, 4)
        {
            if (V[i] != -1)
            {
                dp[i + 1][j] += dp[i][j];
                dp[i + 1][j] %= MOD;
            }
            else
            {
                dp[i+1][j] += dp[i][j]*3;
                dp[i+1][j] %= MOD;
            }
        }
        if (V[i] == -1) {
            dp[i+1][1] += dp[i][0]; dp[i+1][1] %= MOD;
            dp[i+1][2] += dp[i][1]; dp[i+1][2] %= MOD;
            dp[i+1][3] += dp[i][2]; dp[i+1][3] %= MOD;
        }
        else {
            dp[i+1][V[i]+1] += dp[i][V[i]];
            dp[i+1][V[i]+1] %= MOD;
        }
    }
    cout<<dp[N][3]<<endl;
}

//=================================================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 4352
from sys import stdin


def solve():
    n = int(input())
    A = [int(i) for i in stdin.readline().split()]
    if n == 2: return abs(A[0] - A[1])
    curr = 0
    p2, p1 = 0, abs(A[0] - A[1])
    for i in range(2, len(A)):
        # print(p2, p1)
        # curr = min(abs(A[i] - A[i-1]), abs(A[i] - A[i-2]))
        prev2 = abs(A[i] - A[i-2]) + p2
        prev = abs(A[i] - A[i-1]) + p1
        if prev > prev2: curr = prev2
        else: curr = prev
        p2 = p1
        p1 = curr
    return curr

print(solve())

Measured memory_bytes: 50800
#include <bits/stdc++.h>
using namespace std;
#define gc getchar()
inline int read(){
	int x=0,f=1;char c=gc;
	for(;c<48||c>57;c=gc)
		if(c=='-')f=-1;
	for(;c>47&&c<58;c=gc)
		x=x*10+c-48;
	return x*f;
}
#define io read()

#define maxn 1000005
#define maxm 10000005
int n,m,a[maxn];
int st[maxn],pv[maxm],p1[maxm],tot;
int in[maxn];
inline void side(int u,int v){	
	pv[++tot]=v;
	p1[tot]=st[u];
	st[u]=tot;
	++in[v];
}

inline void init(){
	n=io;m=1<<n;
	for(int i=0;i<m;++i)a[i]=io;
	for(int i=0;i<m;++i){
		for(int b=1;b<=i;b<<=1){
			if(i&b)side(i,i^b);
		}
	}
}

int q[maxn],l,r;
int dp[maxn],ans;
struct pi{
	int x,y;
	pi(int xx=0,int yy=0):x(xx),y(yy){}
};
pi mx[maxn];

int b[100];
inline bool cmp(int x,int y){return a[x]>a[y]||a[x]==a[y]&&x>y;}

inline void solve(){
	l=1;r=0;
	for(int i=0;i<m;++i)
		if(!in[i])q[++r]=i;
	while(l<=r){
		int x=q[l++];
		for(int i=st[x];i;i=p1[i]){
			int v=pv[i];
			if(!--in[v])q[++r]=v;
		}
	}
	
	a[m]=dp[m]=0;
	for(int i=r;i;--i){
		int x=q[i];
		int cnt=0;
		b[++cnt]=x;
		b[++cnt]=m;
		for(int j=st[x];j;j=p1[j]){
			int v=pv[j];
			b[++cnt]=mx[v].x;
			b[++cnt]=mx[v].y;
		}
		sort(b+1,b+cnt+1,cmp);
		cnt=unique(b+1,b+cnt+1)-b-1;
		mx[x]=pi(b[1],b[2]);
		dp[x]=a[b[1]]+a[b[2]];
	}
	
	for(int i=1;i<m;++i)dp[i]=max(dp[i-1],dp[i]);
	for(int i=1;i<m;++i)printf("%d\n",dp[i]);
}

int main(){
	init();
	solve();
	return 0;
}

Measured memory_bytes: 54272
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    ll a[10][10]{};
    for (int i = 1; i <= N; i++) {
        string s = to_string(i);
        a[s[0] - '0'][s[s.length() - 1] - '0']++;
    }
    ll ans = 0;
    for (int i = 1; i < 10; i++) {
        for (int j = 1; j < 10; j++) {
            ans += a[i][j] * a[j][i];
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define sz(x) (int)(x.size())
#define lt(x) (int)(x.length())
#define MOD 1000000007 
#define mx 200003

long long n, a[mx], b[mx];

int main(){
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for(int i = 0; i < n; i++)
		cin >> b[i];
	queue<int> bisa;
	for(int j = 0; j < n; j++){
		int i = (j - 1 + n) % n;
		int k = (j + 1) % n;
		if(b[j] > b[i] + b[k] && b[j] > a[j])
			bisa.push(j);
		if(b[j] < a[j]){
			cout << -1 << '\n';
			return 0;
		}
	}
	long long jaw = 0;
	// debug(sz(bisa));
	// debug(bisa.front());
	while(1){
		// for(int i = 0; i < n; i++)
			// cout << b[i] << ' ';
		// cout << '\n';
		if(bisa.empty())
			break;
		int j = bisa.front();
		bisa.pop();
		// debug(j);
		int i = (j - 1 + n) % n;
		int k = (j + 1) % n;
		if(a[j] >= b[i] + b[k]){
			if((b[j] - a[j]) % (b[i] + b[k]) > 0){
				cout << -1 << '\n';
				return 0;
			}
			jaw += (b[j] - a[j]) / (b[i] + b[k]);
			b[j] = a[j];
		}
		else{
			long long sisa = b[j] % (b[i] + b[k]);
			if(sisa < a[j]){
				cout << -1 << '\n';
				return 0;
			}
			jaw += b[j] / (b[i] + b[k]);
			b[j] = sisa;
		}
		if(b[i] > (b[(i - 1 + n) % n] + b[(i + 1) % n]) && b[i] > a[i])
			bisa.push(i);
		if(b[k] > (b[(k - 1 + n) % n] + b[(k + 1) % n]) && b[k] > a[k])
			bisa.push(k);
	}
	for(int i = 0; i < n; i++){
		if(b[i] != a[i]){
			cout << -1 << '\n';
			return 0;
		}
	}
	cout << jaw << '\n';
}


Measured memory_bytes: 3840
#include<iostream>

using namespace std;

int main(){
  int data[30];
  int temp;
  for(int i=0;i<28;i++){
    cin >>temp;
    data[temp-1]=-1;
  }
  for(int i=0;i<30;i++){
    if(data[i]!=-1){
      cout << i+1<<endl;
    }
  }
}

Measured memory_bytes: 3096
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>
using namespace std;

bool first_change(const pair<string,int>& first, const pair<string,int>& second){
    return first.first < second.first;
}

bool second_change(const pair<string,int>& first, const pair<string,int>& second){
    return first.second > second.second;
}

int main(){
    int n,ans,tmp_second;
    string tmp_first;
    cin >> n;
    vector<int> a(n);
    vector< pair<string,int> > pairs(n);

    for(int i=0;i<n;i++){
        cin >> tmp_first;
        cin >> tmp_second;
        a[i] = tmp_second;
        pairs[i] = make_pair(tmp_first,tmp_second);
    }

    sort(pairs.begin(),pairs.end(),second_change);
    stable_sort(pairs.begin(),pairs.end(),first_change);

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(a[j] == pairs[i].second){
                cout << j+1 << endl;
                break;
            }
        }
    }

    /**
    for(int i=0;i<n;i++){
        cout << pairs[i].first << " " << pairs[i].second <<endl;
    }
    **/

}


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

using namespace std;

int N, K;
set<int>S;

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

    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    cin >> N >> K;
    int D, a;
    while (K--){
        cin >> D;
        while (D--){
            cin >> a;
            S.insert(a);
        }
    }
    cout << N - int(S.size()) << "\n";
    return 0;
}

Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define ll long long
#define mset(s, _) memset(s, _, sizeof s)
#define ALL(a) (a).begin(), (a).end()
using namespace std;

int main(void) {
  vector<ll> a;
  int n;
  cin >> n;
  ll A;
  rep(i, 0, n - 1) {
    cin >> A;
    if (A == 0) {
      cout << 0 << endl;
      return 0;
    }
    a.push_back(A);
  }

  ll prod = 1;
  rep(i, 0, n - 1) {
    if (a[i] <= 1000000000000000000 / prod) {
      prod *= a[i];
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << prod << endl;
  return 0;
}


Measured memory_bytes: 4320
s = input()

k = int(input())

n = len(s)

res = 0

i = 0
l = 1

R = []

while i<n :
    if i==n-1 :
        R.append(l)
        break
    if s[i]==s[i+1] :
        l = l+1
    else :
        R.append(l)
        l = 1
    i = i+1

m = len(R)
for i in range(m) :
    if i==0 :
        if s[0]==s[n-1] :
            res += R[i]//2
        else :
            res += R[0]//2*k;
    elif i==m-1:
        if s[0]==s[n-1] :
            res += (R[m-1]+R[0])//2*(k-1)
            res += R[m-1]//2
        else :
            res += R[m-1]//2*k
    else :
        res += R[i]//2*k
#for x in R :print(x,end=" ")

if len(R)==1 :
    print(n*k//2)
else:
    print(res)


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

int main(){
    int h, w;
    cin >> h >> w;

    vector<string> s(h), rs(h);
    for(int i=0; i<h; i++){
        string a;
        cin >> a;
        s[i] = a;
        reverse(a.begin(),a.end());
        rs[i] = a;
    }

    // +45/-45 degree direction
    vector<vector<int>> ne(h+w, vector<int>(w+1)), nw(h+w, vector<int>(w+1));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if( s[i][j] == '#') ne[i+j][j+1] = 1;
            if(rs[i][j] == '#') nw[i+j][(w-1)-j+1] = 1;
        }
    }
    // cumulative sum
    for(int i=0; i<h+w; i++){
        for(int j=0; j+1<=w; j++){
            ne[i][j+1] += ne[i][j];
            nw[i][j+1] += nw[i][j];
        }
    }

    long long int ans = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            //cout << "(" << i << "," << j << ")" << endl;
            for(int k=1; k<h+w; k++){
                //cout << k << " : ";

                if(i+k < h 
                && j+k < w 
                && s[i+k][j] == '#' 
                && s[i][j+k] == '#'
                && i+j-k >= 0) ans += ne[i+j-k][j] - ne[i+j-k][max(0,j-k)];
                //cout << ans << " ";

                if(i-k >= 0 
                && j-k >= 0
                && s[i-k][j] == '#'
                && s[i][j-k] == '#'
                && i+j+k < h+w) ans += ne[i+j+k][min(j+k+1,w)] - ne[i+j+k][j+1];
                //cout << ans << " ";

                if(i+k <  h 
                && j-k >= 0
                && s[i+k][j] == '#'
                && s[i][j-k] == '#'
                && i+((w-1)-j)-k >= 0)  ans += nw[i+((w-1)-j)-k][min(j+k,w)] - nw[i+((w-1)-j)-k][j];
                //cout << ans << " ";

                if(i-k >= 0 
                && j+k <  w
                && s[i-k][j] == '#'
                && s[i][j+k] == '#'
                && i+((w-1)-j)+k < h+w) ans += nw[i+((w-1)-j)+k][j+1] - nw[i+((w-1)-j)+k][max(0,j-k+1)];
                //cout << ans << endl;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5288