akhauriyash/Code-Regression huggingface dataset:
// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

// AtCoder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//


#define _USE_MATH_DEFINES
#include<math.h>

//#include<cmath>

#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>



//#include "Ants.h"
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<n;i++)
#define show(s) cout<<s<<endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define LINF (1000000000000000000ll)
typedef pair < int, int> P;
ll gcd(ll a, ll b) {//最大公約数を求める///最大公倍数a*b/gcd(a,b)
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcd(ll a, ll b) {//最小公倍数を求める　b=0のときaを返す
	if (b == 0) return a;
	return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p;
}
int digiter(ll num) {
	int dig;
	vector<int>p;
	while (num) {
		dig = num % 10;
		p.push_back(dig);
		num /= 10;
	}
	return p.size();
}
vector<int> convert(string s) {
	vector<int> d;
	ll n = s.size();
	rep(i, n) {
		d.push_back(s[i]-'0');
	}
	return d;
}
int H, W, K;
string S[100];
int  c[10][10000];
int main()
{
	cin >>H>>W>>K;
	rep(i, H) {
			cin >> S[i];
	
	}

	int ans = INF;
	rep(div, (1 << (H - 1))) {
		int g = 0; int num = 0;
		vector<int>id(H);
		rep(row, H) {
			id[row] = g;
			if ((div >> row) & 1) {
				g++;
			}

		}
		
		g++;
		rep(i, g) rep(j, W)c[i][j] = 0;
		rep(i, H)rep(j, W)c[id[i]][j] += (S[i][j] - '0');
		num = g - 1;vector<int>now(g);
		auto add = [&](int j) {
			rep(i, g) now[i] += c[i][j]; //cout << "worked" << endl;
			rep(i, g)if (now[i] > K)return false;
			
			return true;
		};
		rep(j, W) {
			if (!add(j)) {
				num++;
				now = vector<int>(g);
				if (!add(j)) {
					num = INF;
					break;
				}
			}
		}
		
		//cout << num << endl;
		ans = min(ans, num);
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
import std.stdio;
import std.conv;
import std.algorithm;
import std.string;
import std.file;
import std.math;

int main() {
	string l;
	while((l = readln(), l.length)){
		l = l.split("\n")[0];
		string[] cols = l.split;
		if(cols.length < 8) break;
		
		float x1, y1, x2, y2, x3, y3, xp, yp;
		x1 = to!float(cols[0]), y1 = to!float(cols[1]);
		x2 = to!float(cols[2]), y2 = to!float(cols[3]);
		x3 = to!float(cols[4]), y3 = to!float(cols[5]);
		xp = to!float(cols[6]), yp = to!float(cols[7]);
		
		cfloat z1, z2, z3;
		z1 = (x1 - xp) + (y1 - yp) * 1.0i;
		z2 = (x2 - xp) + (y2 - yp) * 1.0i;
		z3 = (x3 - xp) + (y3 - yp) * 1.0i;
		
		cfloat r1, r2, r3;
		r1 = z2 / z1;
		r2 = z3 / z2;
		r3 = z1 / z3;
		
		if(r1.im > 0 && r2.im > 0 && r3.im > 0 || r1.im < 0 && r2.im < 0 && r3.im < 0) printf("YES\n");
		else printf("NO\n");
		}
	return 0;
	}

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

const int P = 3005;

int p, u;
bool neg;
vector<int> fi = {1}, se = {1};

vector<int> operator*(vector<int> &a, vector<int> &b)
{
    int sz = min((int)a.size() + (int)b.size() - 1, p - 1);
    vector<int> ans(sz, 0);
    for (int i = 0; i < (int)a.size(); i++)
        for (int j = 0; j < (int)b.size(); j++)
            (ans[(i + j) % (p - 1)] += a[i] * b[j]) %= p;
    return ans;
}

vector<int> operator^(vector<int> cur, int p)
{
    if (p == 1)
        return cur;
    vector<int> tmp = cur ^ (p / 2);
    tmp = tmp * tmp;
    if (p & 1)
        tmp = tmp * cur;
    return tmp;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> p >> u;
    neg = (u == 1);
    for (int i = 1; i < p; i++)
    {
        cin >> u;
        vector<int> cur = {p - i, 1};
        if (u == neg)
            fi = fi * cur;
        else
            se = se * cur;
    }
    (++se[0]) %= p;
    fi = fi ^ (p - 1);
    fi = fi * se;
    if (neg)
        for (int &v : fi)
            v = (p - v) % p;
    fi.push_back(fi[0]);
    fi[0] = neg;
    for (int &v : fi)
        cout << v << " ";
}


Measured memory_bytes: 488
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n, k;
	cin >> n >> k;
	cout << (n-k)+1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	while(1)
	{
	int a[3]; cin >> a[0] >> a[1] >> a[2] ;
	if(a[0]==0 && a[1]==0 && a[2]==0) break;
	int n ; cin >>  n ;
	sort(a,a+3);
	long sum=a[0]*a[0]+a[1]*a[1];
	while(n--)
	{
		long tmp; cin >> tmp;
		if(4*tmp*tmp<=sum) cout << "NA" << endl;
		else cout << "OK" << endl;
	}
	}
}

Measured memory_bytes: 1168
#include <iostream>
#include <queue>
#include <vector>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
int a[200000];
int b[200000];

signed main() {
	int i;
	
	typedef pair<int, int> P;
	priority_queue<P> que;
	
	cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	
	int eqCnt = 0;
	rep(i, n) {
		if (a[i] > b[i]) { cout << -1 << endl; return 0; }
		if (a[i] == b[i]) { eqCnt++; }
	}
	
	rep(i, n) que.push(P(b[i], i));
	
	int ans = 0;
	while (!que.empty()) {
		P now = que.top(); que.pop();
		int iter = now.second;
		int hoge = b[(iter - 1 + n) % n] + b[(iter + 1) % n];
		
		int cnt = min((b[iter] + hoge - 1) / hoge, (b[iter] - a[iter]) / hoge);
		if (cnt <= 0) continue;
		b[iter] -= cnt * hoge;
		ans += cnt;
		
		if (b[iter] < a[iter]) { cout << -1 << endl; return 0; }
		if (b[iter] == a[iter]) { eqCnt++; }
		else { que.push(P(b[iter], iter)); }
	}
	if (eqCnt < n) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}

Measured memory_bytes: 9584
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<climits>

int main(){
	int n, h, w;
	int ans=0;

	std::vector<int> aList;
	std::vector<int> bList;

	std::cin>>n>>h>>w;

	aList.resize(n);
	bList.resize(n);
	for(int i=0; i<n; i++)
		std::cin>>aList[i]>>bList[i];

	for(int i=0; i<n; i++)
		if(h<=aList[i] && w<= bList[i])
			ans++;

		std::cout<<ans<<std::endl;

	return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;

typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;

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

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

int main(){

    bool flag=false;
    ll ans=0,sum=0;

    int k,a,b;
    cin>>k>>a>>b;

    //cout <<fixed<<setprecision(16)<< << endl;

    if(a/k != b/k || (a%k==0) || (b%k==0))cout << "OK" <<endl;
    else cout << "NG" <<endl;

    return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<cstdint>
#include<vector>
#include<map>
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;

ll nCr(ll n, ll r) {
	if (r > n) { return 0; }
	if (r * 2 > n) r = n - r;
	ll dividend = 1;
	ll divisor = 1;
	for (ll i = 1; i <= r; ++i) {
		dividend *= (n - i + 1);
		divisor *= i;
	}
	return dividend / divisor;
}
ll sumdigit(ll n) {
	ll dig = 0, sum = 0;
	while (n) {
		dig = n % 10;
		sum = sum + dig;
		n = n / 10;
	}
	return sum;
}



int main() {
	int n = 0, q = 0;
	int s[100000] = {}, t[50000] = {};
	int left = 0, right = 0, mid = 0;
	int count = 0;
	std::cin >> n;
	rep(i, n) {
		std::cin >> s[i];
	}
	std::cin >> q;
	rep(i,q) {
		std::cin >> t[i];
	}
	rep(i, q) {
		mid = 0;
		left = 0;
		right = n;
		while (left < right) {
			mid = (left + right) / 2;
			if (s[mid] == t[i]) {
				count++;
				break;
			}
			else if (t[i] < s[mid]) {
				right = mid;
			}
			else {
				left = mid + 1;
			}
		}
	}
	std::cout << count << std::endl;
}


Measured memory_bytes: 3692
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <numeric>
#include <regex>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
#define modulo 1000000007 // 10^9 + 7
#define INF 1000000000 // 10^9


const int MAX_H = 51;
const int MAX_W = 51;
int d[MAX_W][MAX_H];    

char maze[MAX_W][MAX_H];

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

bool isPossible(int x, int y) {
	if (x < 0 || W <= x || y < 0 || H <= y) return false;
	else {
		if (maze[x][y] == '.') return true;
		else return false;
	}
}

void input() {
	cin >> H >> W;
	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++) {
			cin >> maze[x][y];
			if (maze[x][y] == '.') num_of_w++;
		}
	}
}


void bfs() {
	queue<P> q;

	// すべての点をINFで初期化
	for (int i = 0; i < W; i++) {
		for (int j = 0; j < H; j++) d[i][j] = INF;
	}

	// スタート地点をqueueに入れる
	q.push(P(0, 0));
	d[0][0] = 1;

	//キューが空になるまで続ける
	while (!q.empty()) {

		// キューの先頭を取り出す
		P p = q.front(); q.pop();
		// 取り出してきた状態がゴールなら終わり
		if (p.first == W-1 && p.second == H-1) break;

		// 移動4方向をループ
		for (int i = 0; i < 4; i++) {
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];

			// 移動可能で未探索なら
			if (isPossible(nx,ny) && d[nx][ny] == INF) {
				// 移動可能ならキューに入れる
				q.push(P(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}
	}
}

int main() {
	input();
	bfs();

	if (d[W - 1][H - 1] != INF) cout << num_of_w - d[W - 1][H - 1] << endl;
	else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
/*
*
*	AUTHOR :- @soham01
*		// "WORK HARD AND NEVER GIVE UP" //
*
*/
#include "bits/stdc++.h"

using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> //find_by_order(), order_of_key()
#define pb push_back
#define mp make_pair 
#define vi vector<long long int >
#define vb vector<bool>
#define vs vector<string>
#define vd vector<double>
#define vvi vector<vector<long long int> >
#define vp vector<pair<long long int , long long int > >
#define seti set<long long int >
#define setc set<char>
#define setd set<double>
#define mod 1000000009
#define endl '\n'
typedef long long int lli;

// ITS MY REQUEST TO PLEASE PLEASE DO LOOK AT THE CONSTRAINS GIVEN CAREFULLY
// DO CHECK FOR CORNER CASES

/*-------LET THE GAME BEGIN-----------*/

void solve()
{
	lli a,b;
  cin >> a >> b;
  if(b>=a)
  {
    cout << "unsafe" << endl;
  }else{
    cout << "safe" << endl;
  }
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
		solve();
	return 0;
}





Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#define REP(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll n, k, a[200010];

int main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> k >> n;
  REP(i, n) cin >> a[i];
  ll ans = 0;
  for(int i = 0; i < n; ++i) ans += a[i];
  cout << (ans >= k ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  char s1[100],s2[100],s3[100];
  scanf("%s %s %s",&s1,&s2,&s3);
  printf("%c%c%c",s1[0] - 32,s2[0] - 32,s3[0] - 32);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define pi acos(-1.0)
#define ms(a, x) memset(a, x, sizeof(a))
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define binarycount __builtin_popcount(x)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define debug(x) cout<<x<<'\n'
#define pii pair<ll,pair<ll,ll> >
using namespace std;
const int inf = 0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9+7;
const double eps = 1e-8;
ll gcd(ll a, ll b) {return b==0?a:gcd(b, a%b);}
ll lcm(ll a, ll b) {return a/gcd(a, b)*b;}
ll powmod(ll a,ll b){
    ll ans = 1, pow = a;
    while(b) { if(b&1) ans = (ans*pow)%mod; pow = (pow*pow)%mod; b >>= 1; }
    return ans;
}
ll mul(ll a,ll b){//大数取模乘法防止溢出
    ll ans=0;
    a%=mod,b%=mod;
    while(b) { if(b&1) ans = (ans+a)%mod; a = (a*2)%mod; b >>= 1; }
    return ans;
}
//(b/a)%p=b*a^(p-2)%p
int pr(ll num){//判断素数
     if(num == 1) return 0;
     if(num ==2|| num==3 ) return 1 ;
     if(num %6!= 1&&num %6!= 5) return 0 ;
     int tmp =sqrt( num);
     for(int i= 5;i <=tmp; i+=6 )
          if(num %i== 0||num %(i+ 2)==0 )return 0 ;
     return 1 ;
}
int Day(int y,int m, int d){
    if(m==1||m==2) { m+=12; y--; }
    int w=(d+2*m+3*(m+1)/5+y+y/4-y/100+y/400)%7;
    return w+1;
}
inline int read() {
    int c = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        c = c * 10 + ch - '0';
        ch = getchar();
    }
    return c * f;
}

//#pragma comment(linker, "/STACK:1024000000,1024000000")//外挂开栈
//stable_sort 排序不处理相同元素
//map<int,int>::reverse_iterator rit;
//for(rit=mp.rbegin();rit!=mp.rend();rit++)
//vec动态二维数组
//vector<vector<int>> g(26,vector<int>(100005));
//初始化vec里面套了n个vec

//lower_bound(begin,end,num) 有序数列中返回第一个>=num的数字的地址
//upper_bound( begin,end,num) 返回第一个>num的数字的地址

const int maxn=1e5+5;
int main(){

    ll a,b,n;
    cin>>a>>b>>n;
    cout<<floor(a*(min((b-1),n))/b)<<endl;
    return 0;
}


Measured memory_bytes: 3728
#include <stdio.h>
#include <string.h>

int main(void) {
    char s[55];

    scanf(" %s", s);
    int len = strlen(s);
    for (int i = 0; i < len - 8; i++) {
        printf("%c", s[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 128
# 木によってLISを作り、dfsで抜けるときにLISをその前の状態まで復元する

import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def mina1(x):
    return int(x) - 1


def read_ints(mina=None):
    ret = map(int, read().split())
    if mina == None:
        return list(ret)
    else:
        return list(map(lambda x: x - mina, ret))


def read_a_int():
    return int(read())


from bisect import bisect_left, bisect_right
from collections import defaultdict
N = read_a_int()
A = read_ints()
tree = defaultdict(lambda: [])
for _ in ra(N - 1):
    u, v = read_ints(mina=1)
    tree[u].append(v)
    tree[v].append(u)

LIS = []
ans = [0] * N  # 各ノードのlen(LIS)を記録


def dfs(now, p):  # 現在のノード、親
    a = A[now]
    # LISの更新
    idx = bisect_left(LIS, a)
    is_append = False
    if idx == len(LIS):
        LIS.append(a)
        is_append = True
    else:
        old = LIS[idx]   # なんの値だったか持っておく
        LIS[idx] = a  # aに更新

    ans[now] = len(LIS)  # 答えを記録
    # 次のノードを探索
    for to in tree[now]:
        if to == p:
            continue
        dfs(to, now)

    # 抜けるときにLISを復元
    if is_append:
        del LIS[idx]
    else:
        LIS[idx] = old


dfs(0, -1)
print(*ans, sep='\n')


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

int count(int n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main() {
  //変数の設定
  int N;
  cin >> N;
  
  //ハッシャード数かどうか確認
  if (N % count(N) == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}



Measured memory_bytes: 256
L=[[int(i) for i in input().split()] for i in range(3)]
if L[0][1]-L[0][0]==L[1][1]-L[1][0]==L[2][1]-L[2][0] and L[0][2]-L[0][1]==L[1][2]-L[1][1]==L[2][2]-L[2][1] and L[1][0]-L[0][0]==L[1][1]-L[0][1]==L[1][2]-L[0][2] and L[2][0]-L[1][0]==L[2][1]-L[1][1]==L[2][2]-L[1][2]:
  print('Yes')
else:
  print('No')
  

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n,m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/


int main()
{
	while (1) {
		ll mi, ma;
		cin >> n >> mi >> ma;
		if (n == 0 && mi == 0 && ma == 0) {
			return 0;
		} else {
			vi v(n);
			vp vans;
			REP(i, n) cin >> v[n - i - 1];
			FOR(i, mi, ma + 1)
			{
				ll a = v[n - i] - v[n - i - 1];
				vans.push_back(make_pair(a, i));
			}
			sort(ALL(vans));
			cout << vans[vans.size() - 1].second << endl;
		}
	}
}

Measured memory_bytes: 3108
#include <algorithm>
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<list>
#include<stack>
#include<map>
#include<set>
#include<string>
#include <sstream>
#include<bitset>

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>

using namespace std;


int main(){
  long ii,jj,kk;
  vector<int> a;
  bitset<64> flg;
  bitset<64> mask[10];
  bitset<64> tmp;
  unsigned long long int val,ma;

  int q;
  int c,i,m,n,k,f;
  flg = 0;
  //cout << sizeof(unsigned long) << endl;
  //cout << sizeof(unsigned long long) << endl;
  cin >> m;

  for(ii=0;ii<m;ii++){
    cin >> k;
    mask[ii] = 0;
    
    for(jj=0;jj<k;jj++){
      cin >> f;
      mask[ii].set(f);
    }
    
  }
  //for(ii=0;ii<m;ii++){
  //  cout << mask[ii] << endl;
  //}
  cin >> q;

  for(ii=0;ii<q;ii++){


    cin >> c;
    //cout << "ii:" << ii << "c:" << c << endl;

    switch(c){

    case 0:
      cin >> i;
      if(flg.test(i)){
        cout << 1 << endl;
      }
      else{
        cout << 0 << endl;
      }
      break;
    case 1:
      cin >> m;
      //cout << "m:" << m << endl;
      flg = flg | mask[m];
      break;
    case 2:
      cin >> m;
      flg = flg & (~mask[m]);
      //flg.reset(i);
      break;
    case 3:
      // flip
      cin >> m;
      val = flg.to_ullong();
      ma = mask[m].to_ullong();
      flg = (flg & (~mask[m])) |(flg ^ mask[m]);
      //flg.flip(i);
      break;
   case 4:
     // all
     cin >> m;
     val = flg.to_ullong();
     ma = mask[ii].to_ullong();
     tmp = (~mask[m]) | (flg & mask[m]);

     if(tmp.all()){
       cout << 1 << endl;
     }
     else{
       cout << 0 << endl;
     }
     break;
    case 5:
      // any
      cin >> m;
      val = flg.to_ullong();
      ma = mask[m].to_ullong();
      tmp = flg & mask[m];

      if(tmp.any() != 0){
        cout << 1 << endl;
      }
      else{
        cout << 0 << endl;
      }      
      break;
    case 6:
      // none
      cin >> m;
      val = flg.to_ullong();
      ma = mask[m].to_ullong();

      //tmp = (flg & (~mask[m])) & (flg & mask[m]);
      tmp = flg & mask[m];
      //cout << flg << endl;
      //cout << mask[m] << endl;
      
      if(tmp.none()){
        cout << 1 << endl;
      }
      else{
        cout << 0 << endl;
      }      
      break;
    case 7:
      //count
      cin >> m;
      val = flg.to_ullong();
      ma = mask[m].to_ullong();
      tmp = flg & mask[m];
      cout << tmp.count() << endl;
      break;
    case 8:
      //val
      cin >> m;
      val = flg.to_ullong();
      ma = mask[m].to_ullong();
      tmp = flg & mask[m];
      cout << tmp.to_ullong() << endl;
      break;
    }
    //cout << flg << endl;
  }
  return 0;
}



Measured memory_bytes: 3076
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,M=map(int,input().split())
    a,b=[0]*M,[0]*M
    c=[0]*M
    for i in range(M):
        a[i],b[i]=map(int,input().split())
        l=list(map(int,input().split()))
        for box in l:
            c[i]=c[i]|(1<<(box-1))
    dp=[[INF]*(2**N) for _ in range(M+1)]
    dp[0][0]=0
    for i in range(M):
        for boxes in range(2**N):
            dp[i+1][boxes]=min(dp[i+1][boxes],dp[i][boxes])
            dp[i+1][boxes|c[i]]=min(dp[i+1][boxes|c[i]],dp[i][boxes]+a[i])
    print(dp[M][2**N-1] if dp[M][2**N-1]!=INF else -1)

if __name__ == '__main__':
    main()


Measured memory_bytes: 73456
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#define DEBUG 0
typedef long long LL;

struct Sushi {
  LL t;
  LL d;
  bool operator<(const Sushi& right) {
    return (d < right.d);
  }
};

int main() {
  int N, K; std::cin >> N >> K;
  std::vector<Sushi> sushi(N);
  for (int i = 0; i < N; ++i) {
    std::cin >> sushi[i].t >> sushi[i].d;
  }

  std::sort(sushi.rbegin(), sushi.rend());
#if DEBUG
  for (const auto& s : sushi) {
    std::cout << "(" << s.t << "," << s.d << ")  ";
  }
  std::cout << std::endl;
#endif

  // Get sushi in order of high score sushi.
  std::set<LL> p;
  std::vector<LL> rests;  // Sushis except for best score sushi for each type.
  LL score = 0;
  for (int i = 0; i < K; ++i) {
    const auto& s = sushi[i];
    score += s.d;

    if (!p.count(s.t)) {  // New
      p.insert(s.t);
    } else {
      rests.push_back(s.d);
    }
  }
  std::sort(rests.rbegin(), rests.rend());

#if DEBUG
  for (const auto& d : rests) {
    std::cout << d << " ";
  }
  std::cout << std::endl;
#endif

  int num_type = static_cast<int>(p.size());
  std::map<LL, LL> scores;
  scores[num_type] = score;

  // Calculate score for each num type.
  int index = K;
  while(index < N && !rests.empty()) {
    for (; index < N; ++index) {
      const auto& s = sushi[index];
      if (!p.count(s.t)) {
        // Exchange sushi to increase the number of type.
        score -= rests.back();
        score += s.d;
        rests.pop_back();

        // set.
        p.insert(s.t);
        scores[++num_type] = score;
        break;
      }
    }
  }

  LL max_score = 0;
  for (const auto& s : scores) {
#if DEBUG
    std::cout << s.first << ":" << s.second << "->" << s.second + s.first*s.first << std::endl;
#endif
    LL new_score = s.first*s.first + s.second;
    max_score = std::max(max_score, new_score);
  }
  std::cout << max_score << std::endl;
}


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
int digit(long long x){
	int t=0;
	while(x>0){
		x/=10;
		t++;
	}
	return t;
}
int main(){
	long long n,a,b;
	cin>>n;
	int res=digit(n);
	for(a=1;a*a<=n;a++){
		if(n%a!=0) continue;
		b=n/a;
		res=min(res,max(digit(a),digit(b)));
	}
	cout<<res;
	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++)
using ll = long long;
const ll mod = 1e9+7;

int main(){
    int n, m;
    cin >> n >> m;
    int a[n], b[m];
    vector<ll> va(n*m+1,0), vb(n*m+1,0);
    rep(i,n) {
      cin >> a[i];
      va[a[i]]++;
    }
    rep(i,m) {
      cin >> b[i];
      vb[b[i]]++;
    }
    vector<ll> num(n*m+1,0);
    rep(i,n) {
      rep(j,m) num[min(a[i],b[j])]++;
    }
    ll ans = 1, s = 0;
    for(int i = n*m; i >= 1; i--) {
      if(va[i] >= 2 || vb[i] >= 2) {
        ans = 0;
      } else if (va[i] == 1 && vb[i] == 1){
        ans *= 1;
      } else if(va[i] == 1 || vb[i] == 1) {
        (ans *= num[i]) %= mod;
      } else {
        (ans *= num[i] + s) %= mod;
      }
      s += num[i] - 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 23680
import java.util.Scanner
import scala.collection.Searching._

import scala.annotation.tailrec

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val N = sc.nextInt
    var i = 0
    while (N >= i * i) (i += 1)
    i -= 1
    println(i * i)
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)

    solve(sc)
  }
}


Measured memory_bytes: 27432
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Node{
    int key;
    struct Node* per;
    struct Node* l;
    struct Node* r;
};
typedef struct Node node;
node* insert(node* px,int k);
void printI(node* x);
void printP(node* x);

int main(void){
    int i;
    int n,k;
    node* x=NULL;
    char com[10];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s",&com);
        if(strcmp(com,"insert")==0){
            scanf("%d",&k);
            x=insert(x,k);
        }else{
            printI(x);
            printf("\n");
            printP(x);
            printf("\n");
        }
    }
    return 0;
}

node* insert(node* px,int k){
    node* x=px;
    node* y=NULL;
    node* z=(node*)malloc(sizeof(node));
    z->key=k;
    z->l=NULL;
    z->r=NULL;
    z->per=NULL;
    while(x!=NULL){
        y=x;
        if(z->key<x->key){
            x=x->l;
        }else{
            x=x->r;
        }
    }
    z->per=y;
    if(y==NULL){
        px=z;
    }else if(z->key<y->key){
        y->l=z;
    }else{
        y->r=z;
    }
    return px;
}

void printI(node* x){
    if(x->l != NULL){
        printI(x->l);
    }
    printf(" %d",x->key);
    if(x->r != NULL){
        printI(x->r);
    }
}

void printP(node* x){
    printf(" %d",x->key);
    if(x->l != NULL){
        printP(x->l);
    }
    if(x->r != NULL){
        printP(x->r);
    }
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N;
    cin >> N;
    vector<pair<ll, ll>> G[N];
    REP(i, N - 1)
    {
        ll u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        G[u].push_back(make_pair(v, w));
        G[v].push_back(make_pair(u, w));
    }

    vector<ll> dist(N, LONG_MAX);
    vector<bool> visited(N, false);
    priority_queue<pair<ll, ll>> q;
    dist[0] = 0;
    q.push(make_pair(dist[0], 0));
    while(!q.empty())
    {
        pair<ll, ll> p = q.top();
        q.pop();
        ll v = p.second;
        ll d = p.first;
        if (dist[v] < d) continue;
        for (auto iter = G[v].begin(); iter != G[v].end(); ++iter)
        {
            ll u = (*iter).first;
            ll w = (*iter).second;
            if (dist[u] > dist[v] + w)
            {
                dist[u] = dist[v] + w;
                q.push(make_pair(dist[u], u));
            } 
        } 
    }
    
    REP(i, N)
    {
        int ans = dist[i] % 2 == 0 ? 0 : 1;
        cout << ans << endl;
    }
}


Measured memory_bytes: 8704
#pragma region noncode
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SORT(v) sort(all(v))
#define TROS(v) sort(all(v), std::greater<Type>());
#pragma endregion

int main() {
    // template
    int n,d;cin>>n>>d;
    vector<ll> x(n),y(n);

    rep(i,n) cin>>x[i]>>y[i];

    int cnt=0;

    rep(i,n){
        if(sqrt(x[i]*x[i]+y[i]*y[i])<=d) ++cnt;
    }

    cout<<cnt<<endl;
}


Measured memory_bytes: 6456
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmin(x,y) x = min(x,y)

ll mod = 1000000007;
ll modsize = 100010;
vector<ll> fac(modsize);
vector<ll> inv(modsize);
vector<ll> facinv(modsize);

void modcalc(){
    if(modsize == 0) abort();
    fac[0] = 1; fac[1] = 1; inv[1] = 1;
    facinv[0] = 1; facinv[1] = 1;
    for(ll i = 2 ; i < modsize ; i++){
        fac[i] = fac[i-1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        facinv[i] = facinv[i-1] * inv[i] % mod;
    }
}

ll modinv(ll a){
    if(a==0) abort();
    ll b = mod, u = 1, v = 0;
    while(b){
        ll t = a/b;
        a -= t * b; swap(a,b);
        u -= t * v; swap(u,v);
    }
    u %= mod;
    if(u<0) u += mod;
    return u;
}

ll modpow(ll a,ll b){
    ll ans = 1;
    a %= mod;
    while(b){
        if(b&1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}

ll modcomb(ll n, ll k){
    if(n<0||k<0||n<k) return 0;
    return fac[n] * facinv[k] % mod * facinv[n-k] % mod;
}

ll modperm(ll n, ll k){
    if(n<0||k<0||n<k) return 0;
    return fac[n] * facinv[n-k] % mod;
}

ll modhom(ll n, ll k){
    if(n<0||k<0||(n==0&&k>0)) return 0;
    if(n==0&&k==0) return 1;
    return fac[n+k-1] * facinv[k] % mod * facinv[n-1] % mod;
}

ll n,k,ans;
vector<ll> to[100005];
void dfs(int v,int p=-1){
    for(int u : to[v]){
        if(u==p) continue;
        dfs(u,v);
    }
    int a = (p==-1) ? k : k-2;
    int b = (p==-1) ? to[v].size()+1 : to[v].size()-1;
    ans *= modperm(a,b);
    ans %= mod;
}

int main(){
    cin>>n>>k;
    modcalc();
    rep(i,n-1){
        int a,b; cin>>a>>b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans = 1;
    dfs(0);
    cout << ans << endl;
}

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

int main() {
	
	// 一辺の長さ
	int n;
	
	// 白で塗ったマスの数
	int a;
	
	// n, a を入力
	cin >> n >> a;
	
	// 黒マスの数
	int black = n * n - a;
	
	// 結果の出力
	cout << black << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using namespace std;
using ll = long long;
using P  = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    int X , Y;
    cin >> X >> Y;
    
    int a = 4*X-Y;

    if(a < 0 || a%2 > 0)
    {
        cout << "No" << endl;
        return 0;
    }
        a /= 2;
    int b = X -a;
    if(b < 0)
    {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    

    return 0;
}

Measured memory_bytes: 3632
N, Y = map(int, input().split())

for delim1 in range(N + 1):
    for delim2 in range(delim1, N + 1):
        yukichi = delim1
        ichiyo = delim2 - delim1
        hideyo = N - delim2
        y = yukichi * 10000 + ichiyo * 5000 + hideyo * 1000
        if y > Y:
            break
        if y == Y:
            print(yukichi, ichiyo, hideyo)
            exit(0)
else:
    print(-1, -1, -1)


Measured memory_bytes: 40556
// Dmitry _kun_ Sayutin (2019)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here
    string s;
    cin >> s;

    int ans = 0;
    pair<char, int> last = {-1, -1};
    for (int i = 0; i != SZ(s);) {
        int i0 = i;

        while (i != SZ(s) and s[i] == s[i0])
            ++i;

        int len = i - i0;
        int k = 1;

        while ((k + 1) * (k + 2) / 2  <= len)
            ++k;

        while (len != 0) {
            if (last.first != s[i0]) {
                len -= 1;
                last = {s[i0], 1};
                ++ans;
            } else {
                int take = last.second ^ 3;
                if (take <= len) {
                    len -= take;
                    last.second = take;
                    ++ans;
                } else {
                    if (i != SZ(s))
                        ++ans, ++i;
                    
                    len = 0;
                    last = {-1, -1};
                }
            }
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 720
#include<stdio.h>
int main()
{
  int n,i,A[100],B,flag=1,j=0;

  scanf("%d",&n);

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



  while(flag)
    {
      flag=0;
      for(i=n-1;i>=1;i--)
	{
	  if(A[i]<A[i-1])
	    {
	    B=A[i];
	    A[i]=A[i-1];
	    A[i-1]=B;
	    flag=1;
	    j++;
	    }
	}
    }

for(i=0;i<n-1;i++)
    {
  printf("%d ",A[i]);
    }
printf("%d\n",A[n-1]);
 printf("%d\n",j);
 
  return 0;
}

Measured memory_bytes: 600
import java.io.PrintWriter;
import java.util.Scanner;

public class Main  implements Runnable { //Runnableを実装する

    public static void main(String[] args) {

        new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); //16MBスタックを確保して実行

    }

    public void run() {
		Scanner sc = new Scanner(System.in);
		//Scanner sc = new Scanner("10");
		int n = Integer.parseInt(sc.next());
		int k = 0;
		//int k = Integer.parseInt(sc.next());
		//String str = sc.next();
		//char c[] = str.toCharArray();
		PrintWriter out = new PrintWriter(System.out);
		for (int i = 0; i * (i-1)/2 <= n; i++)
		{
			if(n==i * (i-1)/2)
			{
				k = i;
			}
		}
		if(k == 0) 
		{
			out.println("No");
		}
		else
		{
			out.println("Yes");
			out.println(k);
			int ans[][] = new int[k][n];
			
			int r = 0;
			for(int i = 0; i < k-1; i++)
			{
				int tmp = 0;
				for(int j = r; j < r+(k-1-i);j++)
				{
					ans[i][j] = 1;
					ans[i+tmp+1][j] = 1;
					tmp++;
				}
				r=r+(k-1-i);
				
			}
			for(int i = 0; i < k; i++)
			{
				out.print(k-1);
				out.print(" ");
				for(int j = 0; j < n;j++)
				{
					if(ans[i][j] == 1)
					{
						out.print(j+1);
						out.print(" ");
					}

				}
				out.println("");
			}
		}

		//out.println(ans);
		out.flush();
	}
}

Measured memory_bytes: 244272
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <bitset>
#include <cstring>
#include <cassert>

using namespace std;

const int MAXN = 100009;
const long long INF = 1000000000000000000;

struct SegmentTree {
    long long tr_min[4 * MAXN];
    long long tr_add[4 * MAXN];
    int n;

    SegmentTree(int n) : n(n) {
        memset(tr_min, 0, sizeof(tr_min));
        memset(tr_add, 0, sizeof(tr_add));
    }

    void setVal(int id, long long val) {
        setVal(0, 0, n, id, val);
    }

    void setVal(int v, int vl, int vr, int id, long long val) {
        push(v, vl, vr);
        if (vl > id || vr <= id) {
            return;
        }
        if (vr - vl == 1) {
            tr_min[v] = val;
            return;
        }
        int vm = (vl + vr) / 2;
        setVal(2 * v + 1, vl, vm, id, val);
        setVal(2 * v + 2, vm, vr, id, val);
        tr_min[v] = min(tr_min[2 * v + 1], tr_min[2 * v + 2]);
    }

    void addTree(int l, int r, long long val) {
        if (l > r)
            return;
        addTree(0, 0, n, l, r + 1, val);
    }

    long long getMin(int l, int r) {
        return getMax(0, 0, n, l, r + 1);
    }

    void push(int v, int vl, int vr) {
        tr_min[v] += tr_add[v];
        if (vr - vl > 1) {
            tr_add[2 * v + 1] += tr_add[v];
            tr_add[2 * v + 2] += tr_add[v];
        }
        tr_add[v] = 0;
    }

    void addTree(int v, int vl, int vr, int l, int r, long long val) {
        push(v, vl, vr);
        if (vl >= r || l >= vr) {
            return;
        }
        if (vl >= l && vr <= r) {
            tr_add[v] += val;
            push(v, vl, vr);
            return;
        }
        int vm = (vl + vr) / 2;
        addTree(2 * v + 1, vl, vm, l, r, val);
        addTree(2 * v + 2, vm, vr, l, r, val);
        tr_min[v] = min(tr_min[2 * v + 1], tr_min[2 * v + 2]);
    }

    long long getMax(int v, int vl, int vr, int l, int r) {
        push(v, vl, vr);
        if (vl >= r || l >= vr) {
            return INF;
        }
        if (vl >= l && vr <= r) {
            return tr_min[v];
        }
        int vm = (vl + vr) / 2;
        long long max1 = getMax(2 * v + 1, vl, vm, l, r);
        long long max2 = getMax(2 * v + 2, vm, vr, l, r);
        return min(max1, max2);
    }
};

long long x[MAXN];
long long f[MAXN];

int main() {
    int n, e, t;
    cin >> n >> e >> t;
    for (int i = 1; i <= n; ++i)
        cin >> x[i];
    x[0] = 0;
    f[0] = 0;
    SegmentTree tree(n);
    tree.addTree(0, 0, x[1] - x[0] + t);
    int idt = 0;
    for (int i = 1; i <= n; ++i) {
        f[i] = tree.getMin(0, i - 1);
        if (i == n)
            break;
        int pidt = idt;
        while ((x[i + 1] - x[idt + 1]) * 2 > t) {
            tree.setVal(idt, f[idt] + x[i + 1] - x[idt] + (x[i + 1] - x[idt + 1]) * 2);
            ++idt;
        }
        tree.setVal(i, f[i] + x[i + 1] - x[i] + t);
        tree.addTree(idt, i - 1, x[i + 1] - x[i]);
        tree.addTree(0, pidt - 1, 3 * (x[i + 1] - x[i]));
    }
    long long ans = f[n] + e - x[n];
    cout << ans << endl;
}

Measured memory_bytes: 8064
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

map<ll,ll> m;
ll A, B, C, D;
ll solve(ll N){
  if(N == 0) return 0;
  if(N == 1) return D;
  if(m.count(N)) return m[N];

  m[N] = 1e18;
  if(N / 1e9 * D < 3e9) m[N] = min(m[N] , N * D);

  m[N] = min(m[N] , A + D * (N % 2) + solve(N / 2) );
  m[N] = min(m[N] , A + D * (2 - N % 2) + solve((N + 2) / 2) );

  m[N] = min(m[N] , B + D * (N % 3) + solve(N / 3) );
  m[N] = min(m[N] , B + D * (3 - N % 3) + solve((N + 3) / 3) );

  m[N] = min(m[N] , C + D * (N % 5) + solve(N / 5) );
  m[N] = min(m[N] , C + D * (5 - N % 5) + solve((N + 5) / 5) );

  return m[N];

}

int main(){
  ll T; cin >> T;
  vector<ll> ans;
  rep(i,T){
    ll N; cin >> N; cin >> A >> B >> C >> D;
    m.clear();
    ll tmp = solve(N);
    ans.pb(tmp);
  }
  rep(i,T) cout << ans[i] << endl;
}


Measured memory_bytes: 4784
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define INF LLONG_MAX
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
int main()
{
    ll n; cin >> n;
    vector<ll> a(n);
    REP(i, n) {
        ll num; cin >> num;
        a[i] = num - (i + 1);
    }
    sort(ALL(a));
    if (a.size()) {
        ll middle = a[a.size()/2];
        ll total = 0;
        REP(i, n) {
            total += abs(a[i] - middle);
        }
        cout << total << endl;
        return 0;
    } else {
        ll total1 = 0, total2 = 0;
        REP(i, n) {
            total1 += abs(a[i] - a[a.size()/2]);
            total2 += abs(a[i] - a[a.size()/2-1]);
        }
        cout << min(total1, total2) << endl;
        return 0;
    }
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<ctype.h>
int main(void)
{
	int i,counter[26]={};
	char ch;
	while(scanf("%c",&ch)!=EOF)
	{
	    if(isupper(ch)){ch=tolower(ch);}
	    counter[ch-'a']++;
	}
	for(i=0;i<26;i++)
	{
		printf("%c : %d\n",i+'a',counter[i]);
	}
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  if (n % 2 == 1) {
    cout << n / 2 + 1 << endl;
  } else {
    cout << n / 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define vi vector < int >
#define pii pair < int, int >
#define INF (int)1e9
#define pb push_back
#define fastIO ios::sync_with_stdio(0); cin.tie(0);

int main()
{
    fastIO
    
    string a, b;
    cin >> a >> b;
    
    int n = a.size();
    bool flag = 1;
    for(int i = 0; i < n; ++i)
    {
        if(a[i] != b[i]) 
        {
            flag = 0;
            break;
        }
    }
    
    if(flag)
        cout << "Yes";
    else
        cout << "No";

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 2e5+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;
ll bin_pow(ll base,ll deg)
{
    if (deg==0)
        return 1;
    ll t=bin_pow(base,deg/2);
    if (deg&1)
        return (((t*t)%mod1)*base)%mod1;
    else
        return (t*t)%mod1;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#ifdef LOCAL
    freopen("a.in","r",stdin);
#endif
    ll n,k;
    cin>>n>>k;
    ll fact[MAXN];
    ll f=1;
    for (ll i=0;i<MAXN;i++)
        fact[i]=f,f*=(i+1),f%=mod1;
    ll ans=0;
//        if (k>=n-1) {
            for (int j = 1; j <= min(n - 2, k); j++) {
               // j+1 перегородка всего надо n-j-1 перегородок  j+1 choose n-j-1 <=> n-1 choose n-j-1
                ll y = fact[n];
                y *= bin_pow(fact[j ], mod1 - 2);
                y %= mod1;
                y *= bin_pow(fact[n - j], mod1 - 2);
                y %= mod1;
                ll x = fact[n - 1];
                x *= bin_pow(fact[n - 1 - j], mod1 - 2);
                x %= mod1;
                //  cout<<n-1-j-1<<'\n';
                x *= bin_pow(fact[j], mod1 - 2);
                x %= mod1;
                ans += (x * y) % mod1;
                ans %= mod1;
            }
            if (k >= n - 1)
                ans += n;
            ans %= mod1;
//        }
//        else
//        {
//
//        }

        cout<<ans+1;





}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    int h[100050];
    for(int i = 1; i <= n; i++){
        cin >> h[i];
    }
    int dp[100050];
    dp[1] = 0;
    h[0] = h[1];
    for(int i = 2; i <= n; i++){
        dp[i] = min(dp[i - 2] + abs(h[i - 2] - h[i]), dp[i - 1] + abs(h[i - 1] - h[i]));
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if((a==1&&b==2)||(a==2&&b==1)){
      cout<<3<<endl;
  }
  else if((a==1&&b==3)||(a==3&&b==1)){
      cout<<2<<endl;
  }
  else{
      cout<<1<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector> 
#include <algorithm>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

#define int long long

signed main() { 
    int h, w;
    cin >> h >> w;
    if(h == 1 || w == 1) {
        cout << 1 << endl;
        return 0;
    }

    if((h * w) % 2 == 0) {
        cout << h * w / 2 << endl;
        return 0;
    }

    cout << h * w / 2 + 1 << endl;
    return 0;
}

Measured memory_bytes: 3548
n=int(input())
l=[int(input()) for _ in range(n)]
l.sort()
m=sorted((-1)**(i+1) if i==0 or i==n-1 else 2*((-1)**(i+1)) for i in range(n))
f=lambda x,y:x*y
a=abs(sum(map(f,l,m)))
b=abs(sum(map(f,l[::-1],m)))
print(max(a,b))

Measured memory_bytes: 58328
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

int main()
{
	int X;
	cin >> X;
	ll tg = sqrt(X);

	while (true) {
		bool find = true;
		for (ll i = 2; i <= tg; ++i) {
			if (X % i == 0) {
				find = false;
				break;
			}
		}

		if (find) {
			cout << X << endl;
			return 0;
		}
		X += 1;
	}

	return 0;
} 


Measured memory_bytes: 3632