akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mod 1e9
#define ll long long
#define F first
#define S second
#define pii pair<int,int>
#define FOR(i,k,n) for(int i=k;i<n+k;i++)
#define ALL(x) x.begin(),x.end()
#define int ll

int tree[200005];
const int N=200005;

void update(int idx,int x,int n)
{
	while(idx<=n)
	{
		tree[idx]+=x;
		idx+=idx&(-idx);
	}
}

int query(int idx)
{
	int sum=0;
	while(idx>0)
	{
		sum+=tree[idx];
		//cout<<sum<<endl;
		idx-=idx&(-idx);
	}
	return sum;
}

main(){
	int n;cin>>n;
	int re=0;
	for(int i=0;i<n;i++){
		int q;cin>>q;
		int qq=query(q);
		if(qq==0) re++;
		update(q,1,n);
	}
	cout<<re<<endl;
}

Measured memory_bytes: 1792
#pragma region
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()
#pragma endregion


int main()
{
	int n; cin >> n;
	vector<int> h(n); rep(i, n)cin >> h[i];
	int res = 0;
	for (int i = 1; i <= 100; ++i)
	{
		int k = 0;
		while (k < n)
		{
			if (h[k] < i)++k;
			else
			{
				++res;
				while (k < n && h[k] >= i)++k;
			}
		}
	}
	cout << res << '\n';
}

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

using namespace std;



void hawawa()
{
	string str;
	cin >> str;
	int n;
	cin >> n;
	for (int i = 0; i < str.size(); i += n) {
		cout << str[i];
	}
	cout << "\n";
}

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


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b;cin>>a>>b;
    cout<<a*b<<endl;    
}

Measured memory_bytes: 3648
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <set>
#include <math.h>
#include <tuple>
#include <string.h>
#include <map>
#include <iomanip>
#include <time.h>
using namespace std;
typedef long long ll;

int n, m, id[100010];
bool vis[100010];
vector<int> G[100010], R[100010], po;

void dfs(int v) {
    if (vis[v]) return;
    vis[v] = 1;
    for (auto& i : G[v]) dfs(i);
    po.push_back(v);
}

void rev_dfs(int v, int num) {
    if (vis[v]) return;
    vis[v] = true;
    id[v] = num;
    for (auto& i : R[v]) rev_dfs(i, num);
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        R[b].push_back(a);
    }

    for (int i = 0; i < n; i++) dfs(i);
    for (int i = 0; i < n; i++) vis[i] = 0;

    int num = 0;
    reverse(po.begin(), po.end());
    for (int i = 0; i < n; i++) {
        int v = po[i];
        if (!vis[v]) {
            rev_dfs(v, num);
            num++;
        }
    }

    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int x, y;
        cin >> x >> y;
        cout << (id[x] == id[y]) << endl;
    }


}



Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
#define MOD 1000000007
#define all(c) c.begin(), c.end()
#define rep(i, s, e) for (auto i = s; i < e; i++)
#define peek(c)      \
	for (auto i : c) \
		cout << i << ' ';

void solve()
{
	ll n;
	cin >> n;
	map<ll, ll> m;
	rep(i, 0, n)
	{
		ll x;
		cin >> x;
		m[x]++;
	}
	ll res = INT_MIN;
	for (auto i : m)
	{
		ll x = i.first;
		ll prev, cur, next;
		prev = cur = next = 0;
		if (m.find(x - 1) != m.end())
			prev = m[x - 1];
		if (m.find(x) != m.end())
			cur = m[x];
		if (m.find(x + 1) != m.end())
			next = m[x + 1];
		res = max(res, prev + cur + next);
	}
	cout << res;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	cerr << "\n\n~" << 500 * clock() / CLOCKS_PER_SEC << "ms\n";
	return 0;
}

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

int main() {
    long a, b, x, ans;
    cin >> a >> b >> x;
    ans = b / x - (a / x + ((a % x)? 1 : 0)) + 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    n, a, b = inl()
    if a > b:
        a, b = b, a
    if (b - a) % 2 == 0:
        return (b - a) // 2

    d1 = a - 1
    d2 = n - b
    if d1 < d2:
        return d1 + 1 + (b - a) // 2
    else:
        return d2 + 1 + (b - a) // 2


print(solve())


Measured memory_bytes: 9092
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <vector>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;

int main() {
  int N, M, T;
  cin >> N >> M >> T;
  vector<int> A(N);
  int ans = 0, now = 0;
  REP(i, N) {
    int A;
    cin >> A;
    if (A - now >= M) {
      ans += A - now - M;
    }
    now = A + M;
  }
  ans += max(0, T - now);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3096
#include <cstdio>
#include <vector>
#include <algorithm>
#include <vector>
#include <cstdint>

using namespace std;

struct Add {
    int64_t operator ()(int64_t lhs, int64_t rhs) {
        return lhs + rhs;
    }
} add;

template <class T>
struct SegmentTree {
    size_t m, n;
    T e;
    vector<T> tree, buffer;
    SegmentTree(size_t m, T e=T()): m(m), n(1), e(e) {
        while (n <= m) n <<= 1;
        tree.assign(n<<1, e);
        buffer.assign(n<<1, e);
    }
    void range_modify(size_t l, size_t r, T x, size_t i, size_t a, size_t b) {
        if (l <= a && b <= r) {
            // [a, b) contains [l, r)
            tree[i] += x;
        } else if (a < r && l < b) {
            // [a, b) overlaps [l, r)
            buffer[i] += (min(r, b)-max(l, a)) * x;
            size_t c=(a+b)>>1;
            range_modify(l, r, x, i<<1|0, a, c);
            range_modify(l, r, x, i<<1|1, c, b);
        }
    }
    T range_query(size_t l, size_t r, size_t i, size_t a, size_t b) {
        if (b <= l || r <= a) {
            // [a, b) does not overlap [l, r)
            return e;
        } else if (l <= a && b <= r) {
            // [a, b) contains [l, r)
            return buffer[i] + tree[i]*(b-a);
        }

        // [a, b) overlaps [l, r)
        size_t c=(a+b)>>1;
        T vl=range_query(l, r, i<<1|0, a, c);
        T vr=range_query(l, r, i<<1|1, c, b);

        return add(vl, vr) + tree[i]*(min(r, b)-max(l, a));
    }
    void range_modify(size_t l, size_t r, T x) {
        range_modify(l, r, x, 1, 0, n);
    }
    void modify(size_t i, T x) {
        range_modify(i, i+1, x, 1, 0, n);
    }
    T range_query(size_t l, size_t r) {
        return range_query(l, r, 1, 0, n);
    }
    T range_query() {
        return range_query(0, m, 1, 0, n);
    }
};

int main() {
    size_t n;
    int q;
    scanf("%zu %d\n", &n, &q);

    SegmentTree<int64_t> tree(n);
    for (int i=0; i<q; ++i) {
        int query;
        scanf("%d", &query);

        if (query == 0) {
                size_t s, t;
                int64_t x;
                scanf("%zu %zu %lld", &s, &t, &x);
                --s, --t;
                tree.range_modify(s, t+1, x);
        } else if (query == 1) {
                size_t s, t;
                scanf("%zu %zu", &s, &t);
                --s, --t;
                printf("%lld\n", tree.range_query(s, t+1));
        } else {
            break;
        }
    }

    return 0;
}

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

using namespace std;

int main()
{
	int t;
	t=1;
	while(t--)
	{
	
    int k,n,a[100001],i;
    
    cin>>n>>k;
	
	for(i=0;i<n;i++)
	cin>>a[i];
	
	sort(a,a+n);
	
	int sum=0;
	for(i=0;i<k;i++)
	{
		sum=sum+a[i];
		
		}	
	
	cout<<sum<<endl;
	
	}



}


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

using namespace std;
int dp[(1<<13)+5][2],X,Y,x,o,te;
int C(int x,int y) {return ((x>>y)&1);}
int dq(int tt,int o)
{
    if ((tt&X)==X) return 1;
    if ((tt&Y)==Y) return 0;
    if (dp[tt][o]>-1) return dp[tt][o];
    if (o==0)
    {

       bool kt=false;int kq=0;
       for (int i=0;i<13;++i)
          if (C(tt,i)==0)
            {
              if (i<12 && C(tt,i+1) && C(X,i))
              {
                kt=true;
                kq=max(kq,dq(tt+(1<<i),1));
              }
              if (i>0 && C(tt,i-1) && C(X,i))
              {
                kt=true;
                kq=max(kq,dq(tt+(1<<i),1));
              }
            }

      if (!kt) kq=dq(tt,1);
      return dp[tt][o]=kq;

    }
    else
    {
       bool kt=false;int kq=1;
       for (int i=0;i<13;++i)
          if (C(tt,i)==0)
            {
              if (i<12 && C(tt,i+1) && C(Y,i))
              {
                kt=true;
                kq=min(kq,dq(tt+(1<<i),0));
              }
              if (i>0 && C(tt,i-1) && C(Y,i))
              {
                kt=true;
                kq=min(kq,dq(tt+(1<<i),0));
              }
            }

      if (!kt) kq=dq(tt,0);
      return dp[tt][o]=kq;
    }
}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>te;
    while (te--)
    {
        X=0;
       memset(dp,-1,sizeof(dp));
       for (int i=1;i<=6;++i)
       {
           cin>>x;
           x--;
           X+=(1<<x);
       }
       Y=(1<<13)-1-(1<<6)-X;
       if (dq(1<<6,0)==1) cout<<"yes";else cout<<"no";
       cout<<'\n';
    }
    return 0;
}



Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int sum ;
    if(n%1000==0)
    {
        sum = 0;
    }
    else
    {
        sum = 1000-n%1000;
    }
    cout<< sum <<endl;
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(aa) (aa).begin(), (aa).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
//#define SIZE 200105
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
typedef pair<pair<ll, ll>,int> PP;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
typedef pair<pill,int> PA;
//ll MOD;
ll MOD = 998244353;
//ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	ll weight;
};

int T;
int sigcheck(ll num){
	int ret=0;
	while(num){
		num/=2;
		ret++;
	}
	return ret;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>T;
	while(T--){
		int N;
		cin>>N;
		ll A[205];
		rep(i,N)cin>>A[i];
		string str;
		cin>>str;
		vector<ll> zeros;
		bool ans=true;
		for(int i=N-1;i>=0;i--){
			if(str[i]=='0'){
				
				ll temp=A[i];
				
				rep(k,zeros.size()){
					if(sigcheck(temp)==sigcheck(zeros[k])){
						temp=temp^zeros[k];
					}
				}
				if(temp!=0){
					zeros.pb(temp);
					sort(all(zeros));
					reverse(all(zeros));
				}
			}else{
				
				//A[i]がzerosの線形和でかけるか
				ll temp=A[i];
				rep(k,zeros.size()){
					if(sigcheck(temp)==sigcheck(zeros[k])){
						temp=temp^zeros[k];
						//cout<<zeros[k]<<" "<<temp<<endl;
					}
				}
				if(temp!=0)ans=false;
			}
			
		}
		if(ans)cout<<0<<endl;
		else cout<<1<<endl;
	}
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int n;

int parent(int i) {
	return i / 2;
}

int left(int i) {
	return 2 * i;
}

int right(int i) {
	return 2 * i + 1;
}

void swap(int *x, int *y) {
	int tmp;

	tmp = *x;
	*x = *y;
	*y = tmp;
}

void maxHeapify(int *A, int i) {
	int l, r, largest;

	l = left(i);
	r = right(i);

	if (l <= n && A[l] > A[i]) largest = l;
	else largest = i;

	if (r <= n && A[r] > A[largest]) largest = r;
	if (largest != i) {
		swap(&A[i], &A[largest]);
		maxHeapify(A, largest);
	}
}

void heapIncreaseKey(int *A, int i, int key) {
	if (key >= A[i]) {
		A[i] = key;
		while (i > 1 && A[parent(i)] < A[i]) {
			swap(&A[i], &A[parent(i)]);
			i = parent(i);
		}
	}
}

void maxHeapInsert(int *A, int key) {
	n++;
	A[n] = -32768;
	heapIncreaseKey(A, n, key);
}

int heapExtractMax(int *A) {
	int max;

	if (n >= 1) {
		max = A[1];
		A[1] = A[n];
		n--;
		maxHeapify(A, 1);
		return max;
	}

	return -1;
}

main() {
	int *node;
	int key;
	char order[8];

	node = (int*)malloc(sizeof(int) * (2000000 + 1));

	while (1) {
		scanf("%s", &order);
		if (!strcmp(order, "insert")) {
			scanf("%d", &key);
			maxHeapInsert(node, key);
		}
		else if (!strcmp(order, "extract")) printf("%d\n", heapExtractMax(node));
		else if (!strcmp(order, "end")) break;
	}

	free(node);

	return 0;
}

Measured memory_bytes: 6044
#include<iostream>
#include<cstring>
using namespace std;
int ans = 0, k, n, m;
char a[100][100];
bool vis[1000];
void dfs(int i, int flag, int sum) {
    if (i > n && flag) {i = 0, flag = 0;}
    if (i >= m  && !flag) {
        if (sum == k)  ans++;
        return;
    }
    if (sum < k) return;
    if (flag) {
        dfs(i+1, flag, sum);
        vis[i] = 1;
        int x = 0;
        for (int j = 0; j < m; j++) 
            if (a[i][j] == '#')  x++;
        dfs(i+1, flag, sum-x);
        vis[i] = 0;
    }
    else {
        dfs(i+1, flag, sum);
        int x = 0;
        for (int j = 1; j <= n; j++) {
            if (a[j][i] == '#' && !vis[j]) x++;
        }
        dfs(i+1, flag, sum-x);
    }
}
int main() {
    cin >> n >> m >> k;
    int sum = 0;;
    for (int i = 1; i <= n; i++) 
        cin >> a[i];
    for (int i = 1; i <= n; i++) 
        for (int j = 0; j < m; j++)
            if (a[i][j] == '#') sum++;
   // for (int i = 1; i <= n; i++) cout << a[i] << endl;   
    dfs(1, 1, sum);
    cout << ans <<'\n';
    system("pause");
}


Measured memory_bytes: 3148
import sys
N, M = map(int, input().split())
k_list_list = []
for m in range(M):
    k_list_list.append(list(map(int, input().split()[1:])))
p_list = list(map(int, input().split()))
    
def add_num(on_off_list_list):
    new_list = []
    for on_off_list in on_off_list_list:
        for i in [[0], [1]]:
            new_list.append(on_off_list+i)
    return new_list

def create_on_off_list(N):
    on_off_list_list = [[]]
    for n in range(N):
        on_off_list_list = add_num(on_off_list_list)
    return on_off_list_list

def check(k_list, p, on_off_list):
    total = 0
    for k in k_list:
        k -= 1
        swich = on_off_list[k]
        if swich == 1:
            total += 1
    if total%2 == p:
        return True
    else:
        return False

def main():
    on_off_list_list = create_on_off_list(N)
    ans = 0
    for on_off_list in on_off_list_list:
        for k_list, p in zip(k_list_list, p_list):
            if check(k_list, p, on_off_list): continue
            else: break
        else:
            ans += 1
    print(ans)
    
main()

Measured memory_bytes: 3188
fun main(args : Array<String>) {
    val (N, K) = readLine()!!.split(" ").map { it.toLong() }

    var count = 0L
    // Fix b
    (1..N).forEach { b ->
        val p = (N / b)
        val numberOfACandidates = (b - K) * p
        val remainders = N % b
            count += listOf(0, numberOfACandidates).max()!! + listOf(0, remainders - K + 1).max()!!
        if (K == 0L) {
            count--
        }
    }

    println(count)
}

Measured memory_bytes: 42324
INF = 10 ** 9 + 7

S = input()
# dp[i][j]はうしろからi桁を13で割った余りがjであるものの個数
dp = [[0] * 13 for _ in range(len(S) + 1)]
dp[0][0] = 1
mul = 1

for i in range(len(S)):
    x = S[-(i + 1)]
    if x == "?":
        for k in range(10):
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                dp[i + 1][(mul * k + j) % 13] %= INF
    else:
        k = int(x)
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            dp[i + 1][(mul * k + j) % 13] %= INF
    mul = mul * 10 % 13  # 計算量削減のためここで13で割っている

print(dp[len(S)][5])

Measured memory_bytes: 62300
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=4e5+10,oo=0x3f3f3f3f,MOD=1e9+7;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    int a,b,x;
    cin>>a>>b>>x;
    cout<<(a+b>=x&&x>=a?"YES":"NO")<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in();
    deque<int> A(0);
    A.push_back(in());
    REP(i,N-1){
        int val = in();
        auto Iter = lower_bound(ALL(A),val);
        if(Iter - A.begin() == 0){
            A.push_front(val);
        }else{
            A[Iter - A.begin() - 1] = val;
        }
    }
    cout << A.size() << "\n";
}

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

int main() {
    int n ;
    cin >> n;
    vector<int> p(n);
    for (int i = 0; i < n; i++) cin >> p[i];

    vector<int> reverse;
    for (int i = 0; i < n; i++) {
        if (p[i] != i+1) {
            reverse.push_back(i);
        }
    }

    if (reverse.size() == 0 || reverse.size() == 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,a,b=LI()

  if (b-a)%2==0:
    return 'Alice'
  else:
    return 'Borys'

print(main())

Measured memory_bytes: 6432
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void log(A...)(A arg) {
    stderr.writeln(arg);
}
int size(T)(in T s) {
    return cast(int)s.length;
}

long lcm(long a, long b) {
    long g = gcd(a, b);
    return a / g * b;
}

void main() {
    int T; readf("%d\n", &T);
    foreach (t; 0 .. T) {
        stdout.flush;
        int H, W; readf("%d %d\n", &H, &W);
        if (H == W) {
            writeln("1 0");
            continue;
        }
        if (H > W) swap(H, W);
        if (H % 2 == 0 || W % 2 == 0) {
            writeln("1 1");
        } else {
            long g = gcd(H, W);
            H /= g; W /= g;
            long L = lcm(H, W);
            long w = (L + 1) / 2;
            long r = L / 2;
            writefln("%s %s", w, r);
        }
    }
}

Measured memory_bytes: 2532
void main() {
	auto ip = readAs!(int[]), N = ip[0], A = ip[1], B = ip[2];
	int res;
	foreach(i; 1..N+1) {
		auto s = i.to!dstring;
		int s_sum;
		foreach(j; s) {
			s_sum += j.to!int - '0';
		}
		if(s_sum >= A && s_sum <= B) res += i;
	}
	res.writeln;
 }

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 380
import java.util.*;
 
class Main{
	public static void main(String[]$){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		StringBuilder r=new StringBuilder();
		if(n==0)
			r.append(0);
		while(n!=0){
			int b=Math.abs(n%2);
			r.append(b);
			n=(n-b)/-2;
		}
		System.out.println(r.reverse());
	}
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		while(true) {
			int H = sc.nextInt();
			int W = sc.nextInt();

			if(H == 0 && W == 0) {
				break;
			}

			for(int i = 0; i < H; i++) {
				if(i ==0 || i == H -1) {
					for(int j = 0; j < W; j++) {
						System.out.print("#");
					}
					System.out.println();
				} else {
					for(int j = 0;j < W;j++) {
						if(j == 0 || j == W - 1) {
							System.out.print("#");
						} else {
							System.out.print(".");
						}
					}
					System.out.println();
				}

			}
			System.out.println();
		}
	}

}


Measured memory_bytes: 33824
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
 
int main() {
  int N, i, result = 0;
  cin >> N;
  int P[N];
  for (i = 0; i < N; i++) {
    cin >> P[i];
  }
  int tmp = P[0];
  for (i = 0; i < N; i++) {
    if (tmp >= P[i]) {
      tmp = P[i];
      result++;
    }
  }
  cout << result << endl;
  return 0;
}

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

int main() {
	int N; cin >> N;
	vector<int> vec(N);
	for(int i = 0; i < N; i++){
    	cin >> vec.at(i);
    }
  	sort(vec.begin(),vec.end());
  	reverse(vec.begin(),vec.end());
    int A = 0, B = 0;
  	for(int i = 0; i<N; i++){
    	if(i%2 == 0){
        	A += vec.at(i);
        }
      	else{
        	B += vec.at(i);
        }
    }
  	cout << A - B << endl;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define inf 1000000000000000000
#define pii pair<int, pair<int, int>>
const double pi = acos(-1);
const int sz = 1000002;
int n, m, w, h,s;

int main() {
	io
	cin>>n;
	//map<int, string>hash;
	int i = n%10;
	if(i == 2 || i == 4 || i == 5 || i == 7 || i == 9) cout<<"hon";
	if(i == 0 || i == 1 || i == 6 || i == 8) cout<<"pon";
	if(i == 3)cout<<"bon";
}





Measured memory_bytes: 3608
class ACS:
    def __init__(self, D, C, S):
        self.now = 1
        self.D = D
        self.satisfaction = 0
        self.sat_log = []
        self.C = C
        self.S = S
        self.last = [0]*26
    
    def hold_contest(self, T):
        self.satisfaction += self.S[self.now-1][T]
        self.last[T] = self.now

        for i in range(26):
            self.satisfaction -= self.C[i]*(self.now - self.last[i])
        
        self.sat_log.append(self.satisfaction)
        self.now += 1
    
    def choice_max(self):
        maxs, maxi = -(10**18), 0
        for i in range(26):
            s = self.score_check(i)
            if s >= maxs:
                maxs = s
                maxi = i
        return maxi


    def score_check(self, T):
        score = self.satisfaction + self.S[self.now-1][T]

        for i in range(26):
            if i != T:
                score -= self.C[i]*(self.now - self.last[i])
        return score

    def nd_score_check(self, Ts: list):
        last = self.last[::]
        score = self.satisfaction
        d = self.now
        # print(d)
        
        for T in Ts:
            score += self.S[d-1][T]
            last[T] = d
            for i in range(26):
                score -= self.C[i]*(d - last[i])
            d += 1
        return score

        

    def _log(self):
        print(f"\nday {self.now}\n satisfaction: {self.satisfaction}")

        


D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for _ in range(D)]

acs = ACS(D, C, S)

for d in range(D//2):
    next_contests = (0, 0)
    maxs = -(10**18)
    for i in range(26):
        for j in range(26):
            score = acs.nd_score_check([i, j])
            if maxs <= score:
                maxs = score
                next_contests = (i, j)

    acs.hold_contest(next_contests[0])
    acs.hold_contest(next_contests[1])
    print(next_contests[0]+1, next_contests[1]+1, sep='\n')
print(acs.choice_max()+1)



Measured memory_bytes: 9472
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
      int i,j,k,x,y;
      Scanner sc =new Scanner(System.in);
      for(i=0; ;i++){
          x=sc.nextInt();
          y=sc.nextInt();
          if((x==0)&&(y==0)){
              break;
          }else{
              for(j=1;j<=x;j++){
                for(k=1;k<=y;k++){
                    if((j+k)%2==0){
                        System.out.print("#");
                    }else{
                        System.out.print(".");
                    }
                }
                System.out.print("\n");
              }
              System.out.print("\n");
            }
        }
    }
}


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

struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) (1 + (int)((a) - 1)/(int)(b))
//#define int long long

bool is_palindromic(string s){
    string t = s;
    reverse(ALL(s));
    return stoi(s) == stoi(t);
}

int main() {
    int a, b;
    cin >> a >> b;
    
    int ans = 0;
    reps(i,a,b){
        ans += is_palindromic(to_string(i));
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
# import numpy as np
# import scipy as sp
# print(a,b,c,sep="") # 半角スペースなしで出力(abc)
# n=int(input())  #数値入力 「N」だけの入力のとき
# a,b=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
# c=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
# s=[list(map(int,list(input()))) for i in range(h)]  # 文字列の二次元配列入力
# s = [list(map(int, input().split())) for i in range(n)] # 数値の二次元配列入力
# import sys ; sys.exit() # プログラム終了
# from copy import deepcopy ; b=deepcopy(a)
# chr(ord('a') + 1)
# s.sort(key=lambda x: x[1], reverse=False) # 2番目の要素で昇順にソート（Trueなら降順）
#

a, b = map(int, input().split())


def ceil(a, b):
    return -(-a // b)


print(ceil(a, b))


Measured memory_bytes: 38256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<utility>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
int main(){
    int n;
    cin>>n;
    vector<pair<int, int>> v;
    int a, b;
    rep(i, n){
        cin>>a>>b;
        v.push_back(make_pair(b, a));
    }
    sort(v.begin(), v.end());
    int c=0;
    bool f=0;
    rep(i, n){
        c+=v[i].second;
        if(c>v[i].first){
            f=1;
            break;
        }
    }
    if(f==1)
    cout<<"No"<<endl;
    else
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
    string s;cin >> s;
    int ans=0;
    rep(i,s.size()-1)
    if(s[i]!=s[i+1])ans++;
    printf("%d\n",ans);
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	int x,a,b;
	scanf("%d %d %d",&x,&a,&b);
	
	if(b-a<=0){
		printf("delicious\n");
	} else if(b-a>0){
		if(b-a<=x){
			printf("safe\n");
		} else{
			printf("dangerous\n");
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

class Point
{
public:
    int y, x;
    Point(){
        y = x = 0;
    }
    Point(int y0, int x0){
        y = y0;
        x = x0;
    }
    Point operator+(const Point& p) const{
        return Point(y + p.y, x + p.x);
    }
    Point operator-(const Point& p) const{
        return Point(y - p.y, x - p.x);
    }
    Point operator*(int a) const{
        return Point(y * a, x * a);
    }
    bool operator!=(const Point& p) const{
        return y != p.y || x != p.x;
    }
};

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

    if(n % 2 == 1){
        cout << "NA" << endl;
        return 0;
    }

    vector<Point> p(n);
    for(int i=0; i<n; ++i)
        cin >> p[i].x >> p[i].y;

    for(int i=0; i<n/2; ++i){
        Point q1 = p[i] - p[i+1];
        Point q2 = p[(n/2+i+1)%n] - p[n/2+i];
        if(q1 != q2){
            cout << "NA" << endl;
            return 0;
        }
    }

    Point q = p[0] + p[n/2];
    printf("%.10f %.10f\n", (q.x / 2.0), (q.y / 2.0));

    return 0;
}

Measured memory_bytes: 1232
def solve():
    h, w = map(int, input().split())
    s = [input() for _ in range(h)]
    INF = 10 ** 9
    dp = [[0]*(w+10) for _ in range(h+10)]
    dp[0][0] = 1 if s[0][0] == '#' else 0

    for i in range(h):
        for j in range(w):
            if not i==j==0:
                dp[i][j] = INF
            if i>0:
                dp[i][j] = min(dp[i][j], dp[i-1][j] + (1 if s[i-1][j]=='.' and s[i][j]=='#' else 0))
            if j>0:
                dp[i][j] = min(dp[i][j], dp[i][j-1] + (1 if s[i][j-1]=='.' and s[i][j]=='#' else 0))

    # for i in range(h):
    #     for j in range(w):
    #         print(dp[i][j], end=' ')
    #     print()
    print(dp[h-1][w-1])


solve()

Measured memory_bytes: 3188
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

#define NUM_PROBLEMS_MAX 100
#define NUM_DRINKS_MAX   100

typedef struct
{
	unsigned int num_problems;
	unsigned int num_drinks;
	unsigned int took_time_normal [NUM_PROBLEMS_MAX];
	unsigned int index_doped      [NUM_DRINKS_MAX  ];
	unsigned int took_time_doped  [NUM_DRINKS_MAX  ];
} abc050b_t;

void abc050b_get_data (      abc050b_t const * test_data);
void abc050b_answer   (const abc050b_t const * test_data);

int main (void)
{
	// variables for `main`
	abc050b_t test_data;

	// STEP.01
	// read out the given data
	abc050b_get_data(&test_data);

	// STEP.02
	// calculate & output the points
	abc050b_answer(&test_data);

	// STEP.END
	return EXIT_SUCCESS;
}

void abc050b_get_data (abc050b_t const * test_data)
{
	// local variables for this function
	int retval_scanf;

	retval_scanf = scanf( "%d", &(*test_data).num_problems );

	for (unsigned int iter = 0; iter < (*test_data).num_problems; ++iter)
	{
		retval_scanf =
			scanf(
				"%d",
				&(*test_data).took_time_normal[iter]
			);
	}

	retval_scanf = scanf( "%d", &(*test_data).num_drinks );

	for (unsigned int iter = 0; iter < (*test_data).num_drinks; ++iter)
	{
		retval_scanf =
			scanf(
				"%d %d",
				&(*test_data).index_doped    [iter],
				&(*test_data).took_time_doped[iter]
			);
	}
}

void abc050b_answer (const abc050b_t const * test_data)
{
	// local variables for this function
	unsigned int sum_took_time = (unsigned int)0;

	// STEP.01
	// calculate the summation of the time it task to solve individual problems
	for (unsigned int iter = 0; iter < (*test_data).num_problems; ++iter)
	{
		sum_took_time += (*test_data).took_time_normal[iter];
	}

	// STEP.02
	// print the answer of this task to the console
	for (unsigned int iter = 0; iter < (*test_data).num_drinks; ++iter)
	{
		printf( "%d\n", sum_took_time - (*test_data).took_time_normal[ (*test_data).index_doped[iter] - 1 ] + (*test_data).took_time_doped[iter] );
	}
}

Measured memory_bytes: 128
while True:
    N = int(input())
    if N == 0:
        break

    a = []
    cnt = 0
    for l in range(N):
        a.append(int(input()))
    for i in range(N-1, 0, -1):
        for j in range(i):
            if a[j] > a[j+1]:
                a[j], a[j+1] = a[j+1], a[j]
                cnt += 1

    print(cnt)



Measured memory_bytes: 5600
import sys
input = sys.stdin.readline
import math

"""
内部の点が絡むものは、曲線で結んでホモトピーで変形すれば、無視できる
境界の2点を結ぶものたちだけが問題
"""

R,C,N = map(int,input().split())
pts = [] # 角度、番号
is_inner = lambda x,y:  0 < x < R and 0 < y < C
for i in range(N):
    x1,y1,x2,y2 = map(int,input().split())
    if is_inner(x1,y1) or is_inner(x2,y2):
        continue
    pts.append((math.atan2(y1 - C/2, x1 - R/2),i))
    pts.append((math.atan2(y2 - C/2, x2 - R/2),i))
pts.sort()

arr = []
for _, i in pts:
    if arr and arr[-1] == i:
        arr.pop()
        continue
    arr.append(i)

answer = 'NO' if arr else 'YES'
print(answer)

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

int main(){
	int n;
	scanf("%d", &n);
	int ans = 0;
	for(int i=1;i<=n;i+=2){
		int cnt = 0;
		for(int j=1;j<=i;j++){
			if(i%j == 0) cnt++;
		}
		if(cnt == 8) ans++;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b % mod; if (a >= mod) a -= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12); // debuged
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int r, g, b;
    cin >> r >> g >> b;
    int k;
    cin >> k;
    // b > g > r
    int cnt = 0;
    while (r >= g) {
        g *= 2;
        ++cnt;
    }
    while (g >= b) {
        b *= 2;
        ++cnt;
    }
    if (cnt <= k) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main() {
  int i, a[i], l;
  cin >> i;
  int j = 0;
  while ( cin >> l ){
    a[j] = l;
    j++;
  }
  bool loopend = false;
  int output = 0;
  int k = 0;
  while ( !loopend ){
  while ( k < i ){
    if ( a[k] % 2 ){
     loopend = true;
     break;
    }
    a[k] = a[k] / 2;
    k++;
  }
    if ( k == i ){
      output++;
      k = 0;
    }
  }
  cout << output << endl;
}

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

#define INF (INT64_MAX)
#define MOD (1000000000+7)
#define MAX 100000

int main() {
	int a, b, c;

	cin >> a >> b >> c;

	int ans = 0;
	if( a + b == c || a + c == b || b + c == a ) {
		ans = 1;
	}

	if( ans ) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
const int N=100001;
using namespace std;
int main(){
    int n,x[N],y[N],t[N];
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>t[i]>>x[i]>>y[i];
    }
    for(int i=1;i<=n;i++)
        if(x[i]+y[i]>t[i]||(t[i]-x[i]-y[i])%2!=0){
          cout<<"No";
          return 0;   
        }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 1408
n = int(input())
data = list(map(int, input().split()))

def insertion_sort(A, N):
    print(*A)
    for i in range(1, N):
        v = A[i]
        j = i - 1
        while j >= 0 and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
        print(*A)

insertion_sort(data, n)

Measured memory_bytes: 8200
#include <iostream>
#include <vector>
#include <iomanip>
#include <cmath>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
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; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;


int main() { 
    int N, i;
    cin >> N >> i;
    print(N-i+1);
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
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; }
using namespace std;

struct RollingHash{ //ローリングハッシュ法
private:
    const int mod1 = 1031326447, mod2 = 993766717;
    const int base1 = 281, base2 = 383;
    vector<int> hash1, hash2, pow1, pow2;
public:
    string str;
    RollingHash(const string& s) : str(s) { //初期化
        int sz = (int)s.size();
        hash1 = hash2 = vector<int>(sz + 1, 0);
        pow1 = pow2 = vector<int>(sz + 1, 1);
        rep(i, sz){
            hash1[i + 1] = (hash1[i] * base1 + s[i]) % mod1;
            hash2[i + 1] = (hash2[i] * base2 + s[i]) % mod2;
            pow1[i + 1] = pow1[i] * base1 % mod1;
            pow2[i + 1] = pow2[i] * base2 % mod2;
        }
    }
    inline pair<int, int> get(int l, int r){ //[l, r)
        int res1 = ((hash1[r] - hash1[l] * pow1[r - l]) % mod1 + mod1) % mod1;
        int res2 = ((hash2[r] - hash2[l] * pow2[r - l]) % mod2 + mod2) % mod2;
        return pair<int, int>(res1, res2);
    }
    inline void add_str(const string& s){ //string型を連結
        int ns = (int)str.size(), ms = (int)s.size();
        str += s;
        hash1.resize(ns + ms + 1); hash2.resize(ns + ms + 1);
        pow1.resize(ns + ms + 1); pow2.resize(ns + ms + 1);
        for(int i = ns; i < ns + ms; i++){
            hash1[i + 1] = (hash1[i] * base1 + s[i - ns]) % mod1;
            hash2[i + 1] = (hash2[i] * base2 + s[i - ns]) % mod2;
            pow1[i + 1] = pow1[i] * base1 % mod1;
            pow2[i + 1] = pow2[i] * base2 % mod2;
        }
    }
    inline void add_char(const char& c){ //char型を連結
        str += c;
        hash1.push_back((hash1.back() * base1 + c) % mod1);
        hash2.push_back((hash2.back() * base2 + c) % mod2);
        pow1.push_back((pow1.back() * base1) % mod1);
        pow2.push_back((pow2.back() * base2) % mod2);
    }
    inline void add_rh(const RollingHash& rh){ //rhを連結
        add_str(rh.str);
    }
    inline size_t size(){ //strのsizeを返す
        return str.size();
    }
};

signed main(void){

    int N, M;
    string S;
    cin >> N >> M >> S;

    RollingHash rh(S);
    set<pair<int, int>> st;

    int l = 0, r = 1;
    rep(loop, M){
        string q; cin >> q;
        if(q == "L++")l++;
        if(q == "L--")l--;
        if(q == "R++")r++;
        if(q == "R--")r--;
        st.insert(rh.get(l, r));
    }

    cout << st.size() << endl;
    return 0;

}



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

bool mat[21][21];
int n,a,b;
int dp[1<<21];
const int MOD=1000000007;

int cntOne(int x) {
    int y=0;
    while(x>0) {
        y+=x%2;
        x/=2;
    }
    return y;
}

int main() {
    cin >> n;
    for (int i=0;i<n;i++) {
        for (int j=0;j<n;j++) {
            cin >> mat[i][j];
        }
    }

    dp[0]=1;
    for (int mask=0;mask<(1<<n);mask++) {
        a=cntOne(mask);
        for (int i=0;i<n;i++) {
            if (mask&(1<<i) || mat[a][i]==0) {continue;}
            int mask2=(mask|(1<<i));
            dp[mask2]+=dp[mask];
            dp[mask2]%=MOD;
        }
    }
    cout << dp[(1<<n)-1] << endl;
}


Measured memory_bytes: 11776
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <list>
#include <cstring>
#include <stack>
   
using namespace std;

int main()
{
    int n;
    while(1){
        cin >> n;
        if(n == 0) break;
        long long int nowmap[51] = {};
        vector<vector<int> > schedule(31);
        for(int i = 1; i < n + 1; i++){
            int f;
            cin >> f;
            for(int j = 0; j < f; j++){
                int d;
                cin >> d;
                schedule[d].push_back(i);
            }
        }
        for(int i = 1; i < n + 1; i++){
            nowmap[i] = (long long int)1 << (i - 1);
            // cout << nowmap[i] << endl;
        }
        // cout << n << endl;
        long long int maxmap = (long long int)1 << n;
        maxmap--;
        // cout << maxmap << endl;
        for(int i = 1; i < 31; i++){
            // cout << "day : " << i << endl;
            long long int gatheredmap = 0;
            for(int j = 0; j < schedule[i].size(); j++){
                // cout << schedule[i][j] << endl;
                gatheredmap |= (long long int)nowmap[schedule[i][j]];
            }
            // cout << gatheredmap << endl;
            // cout << (long long int)1 << n << endl;
            if(gatheredmap == maxmap){
                cout << i << endl;
                break;
            }
            for(int j = 0; j < schedule[i].size(); j++){
                nowmap[schedule[i][j]] = gatheredmap;
            }
            if(i == 30) cout << -1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1232