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

#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define pb  push_back

typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long ll;

using int_type = int64_t;

const int N = 2e5 + 3;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    for(int i = 2; i < SZ(s); ++i) {
        if(s[i-2] == 'A' && s[i-1] == 'B' && s[i] == 'C')
            cnt++;
    }
    cout << cnt << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
//#include <algorithm>
#include <vector>
 
int main(int argc, char* argv[])
{
    long n, k;
    scanf("%ld %ld", &n, &k);

    if(n%k==0) {
        printf("0\n");
    }
    else {
        printf("1\n");
    }

    return 0;
}


Measured memory_bytes: 128
using System.Collections.Generic;
using System;

public class P
{
    public int sum { get; set; }
    public int p { get; set; }
}

public class hello
{
    public const int MOD = 1000000007;
    public static void Main()
    {
        var alp = "abcdefghijklmnopqrstuvwxyz";
        var d = new Dictionary<char, List<int>>();
        var d2 = new Dictionary<char, P>();
        for (int i = 0; i < 26; i++)
        {
            d[alp[i]] = new List<int>();
            d2[alp[i]] = new P { p = -1 };
        }
        var n = int.Parse(Console.ReadLine().Trim());
        var s = Console.ReadLine().Trim();
        var t = Console.ReadLine().Trim();
        for (int i = 0; i < n; i++) d[s[i]].Add(i);
        var ans = goDP(d, d2, s, t, n);
        Console.WriteLine(ans);
    }
    public static int goDP(Dictionary<char, List<int>> d, Dictionary<char, P> d2, string s, string t, int n)
    {
        var dp = new int[n];
        dp[0] = 1;
        for (int i = 1; i < n; i++)
        {
            dp[i] = getSum(d, d2, dp, t[i], i);
            d2[s[i]].p++;
            d2[s[i]].sum += dp[i];
            d2[s[i]].sum %= MOD;
        }
        return dp[n - 1];
    }
    public static int getSum(Dictionary<char, List<int>> d, Dictionary<char, P> d2, int[] dp, char c, int i)
    {
        var ans = 0;
        if (d2[c].p == -1 | d2[c].sum == 0)
        {
            var pp = 0;
            foreach (var x in d[c])
                if (x < i)
                {
                    ans += dp[x];
                    ans %= MOD;
                    pp++;
                }
                else break;
            if (pp > 0) pp--;
            d2[c].p = pp;
            d2[c].sum = ans;
        }
        else ans = d2[c].sum;
        return ans;
    }
}




Measured memory_bytes: 20164
#include <iostream>

int main(){
 int N,i,j,outflag=0;
 
 std::cin >> N;

 i=0;j=0;

 while(true){
  j=0;
  if((i*4+j*7)>N)outflag=1;
  while(true){
   if((i*4+j*7)>N)break;
   if((i*4+j*7)==N){
    std::cout << "Yes";
    return 0;
   }
   ++j;
  }
  ++i;
  if(outflag)break;
 }
 std::cout << "No";
    
 return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
# coding: utf-8

def main():
    date = list(input().split('/'))
    
    if date[0] != '2018':
        date[0] = '2018'
        
    
    mojiretu = '/'.join(date)
    print(mojiretu)
    return 0


if __name__ == '__main__':
    main()

Measured memory_bytes: 2940
# 2020/04/19
# AtCoder Beginner Contest 163 - C

# Input
n = int(input())
a = list(map(int,input().split()))
alist = [0] * n

# Calc
for i in range(n-1):
    alist[a[i]-1] = alist[a[i]-1] + 1

# Output
for i in range(n):
    print(alist[i])


Measured memory_bytes: 32184
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,mod=1000000007;
const long long llinf=9223372036854775807ll;
int n,m,ai,bi,ans,q[N],head,tail,dp[N],a[N];
vector<int> v[N];
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>ai>>bi;
		v[ai].push_back(bi);
		a[bi]++;
	}
	for(int i=1;i<=n;i++)
		if(!a[i])
			q[++tail]=i;
	while(head<tail)
	{
		int x=q[++head];
		ans=max(ans,dp[x]);
		for(int i=0;i<v[x].size();i++)
		{
			int y=v[x][i];
			a[y]--;
			dp[y]=max(dp[y],dp[x]+1);
			if(!a[y])
				q[++tail]=y;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 6912
#include <stdio.h>
 
int main() {
  int N,M,C;
  scanf("%d %d %d",&N,&M,&C);
  int B[M],A[N][M];
  for (int i = 0; i < M; i++) {
    scanf("%d",&B[i]);
  }
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M ; j++) {
      scanf("%d",&A[i][j]);
    }
  }
  int solve = 0, cnt = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M ; j++) {
      solve += A[i][j]*B[j];
    }
    if (solve + C > 0) cnt++;
    solve = 0;
  }
  printf("%d\n",cnt);
  return 0;
}

Measured memory_bytes: 128
import itertools
n, m, q = map(int, input().split())
lst = [0] * q
for i in range(q):
    a, b, c, d = map(int, input().split())
    lst[i] = (a, b, c, d)
L = list(itertools.combinations_with_replacement(range(1,m+1), n))
ans = 0 
for l in L:
    point_l = 0
    for rule in lst:
        if l[rule[1]-1]-l[rule[0]-1] == rule[2]:
            point_l += rule[3]
    ans = max(ans,point_l)
print(ans)

Measured memory_bytes: 21520
///                       BISMILLAHIR RAHMANIR RAHEEM
///                  ||\  ||    /\    ||''\   ||  ||\  /||
///                  || \ ||   /__\   ||   |  ||  || \/ ||
///                  ||  \||  /    \  ||../   ||  ||    ||
#include<bits/stdc++.h>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test IOS long long t;cin >> t;while(t--)
typedef long long v99;
using namespace std;
int main()
{
    int s,w;cin>>s>>w;
    if(s<=w) cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl;
    return 0;
}///...........Alhamdulillah.........///







Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<21)

bool cmp(pair<int,string> a , pair<int,string> b){
	return a.first > b.first;
}
int main(){
	int n,c=0;
	while(cin >> n,n){
		if(c++)cout << endl;
		vector< pair<int,string> >data; 
		rep(i,n){
			int a,b,c;
			string s;
			cin >> s >>  a >> b >> c;
			data.push_back(make_pair(a*3+c,s));
		}
		stable_sort(data.begin(),data.end(),cmp);
		rep(i,n)
			cout << data[i].second << "," << data[i].first << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
  int i, n;
  cin >> n;
  vector<pair<int, int>> a(n);
  for(i=0; i<n; i++){
    cin >> a[i].first;
    a[i].second=i+1;
  }
  sort(a.begin(), a.end());
  for(i=0; i<n-1; i++)
    cout << a[i].second << " ";
  cout << a[n-1].second << endl;
  return 0;
}

Measured memory_bytes: 1664
import java.util.*;
class Main {
    static char[] c;
    static long total;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        c = str.toCharArray();
        dfs(0, 0, c[0]-'0');
        System.out.println(total);
    }
    public static void dfs(int depth, long sum, long carry) {
        if(depth+1 == c.length) {
            System.err.println(depth+" "+sum+" "+carry);
            total += sum+carry;
            return;
        }
        System.err.println(sum);
        dfs(depth+1, sum+carry, (long)(c[depth+1]-'0'));
        dfs(depth+1, sum, carry*10+(long)(c[depth+1]-'0'));
    }
}

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

long long r = 1e9+7;

int main(){
    long long n, k;
    cin >> n >> k;

    vector<long long> a(n);

    for(long long i = 0; i < n; i++){
        cin >> a[i];
    }

    long long count_in = 0;
    for(long long i = 0; i < n; i++){
        for(long long j = i+1; j < n; j++){
            if(a[i] > a[j]){
                count_in++;
            }
        }
    }

    long long count_out = 0;
    for(long long i = 0; i < n; i++){
        for(long long j = 0; j < n; j++){
            if(a[i] > a[j]){
                count_out++;
            }
        }
    }

   
    long long ans = 0;
    ans += count_in*k;
    ans = ans % r;

    long long p = (k*(k-1)/2)%r;
    ans = ans + (count_out*p)%r;
    ans %= r;
    cout << ans << endl;
   
    return 0;

}

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

const int INF = 1e8;

int main(){
  int n,m;
  while(cin >> n >> m, n){
    vector<int> c(m);
    for(int i=0;i<m;i++)cin >> c[i];
    vector<int> x(n);
    for(int i=0;i<n;i++)cin >> x[i];

    vector<int> cur(256,INF), nxt(256);
    cur[128] = 0;

    for(int i=0;i<n;i++){
      for(int j=0;j<256;j++)nxt[j] = INF;

      for(int j=0;j<256;j++){
	for(int k=0;k<m;k++){
	  int nj = min(255, max(0,j + c[k]) );
	  int dif = nj-x[i];
	  nxt[nj] = min(nxt[nj], cur[j] + dif*dif);
	}
      }
      swap(cur, nxt);
    }

    cout << *min_element(cur.begin(),cur.end()) << endl;
  }

}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	long long a[n],b[n],s=0LL,r=0LL;
	vector<long long> memo;
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		s+=a[i];
	}
	for (int i = 0; i < n; ++i)
	{
		cin>>b[i];
		s-=b[i];
		if (a[i]<b[i])
		{
			r+=b[i]-a[i];
			++ans;
		}
		else
		{
			memo.push_back(a[i]-b[i]);
		}
	}
	if (s<0)
	{
		cout<<"-1\n";
		return 0;
	}
	sort(memo.begin(), memo.end());
	reverse(memo.begin(), memo.end());
	for (auto v:memo)
	{
		if (r<=0)
		{
			break;
		}
		++ans;
		r-=v;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2680
#include <iostream>
#include <tuple>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define range(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef double db;
typedef string str;
// head

int main(){
    str s;
    cin >> s;
    bool f = true;
    range(i,2){
    if (s[i]!=s[i+1]){
        // cout << s[i] << " " << s[i+1] << endl;
        f=false;
    }
    }
    // cout << f << endl;
    if (f){
        cout << "Yes"<< endl;
        return 0;
    }
    f = true;
    range(i,1,3){
    if (s[i]!=s[i+1]){
        f=false;
    }
    }
    if (f){
        cout << "Yes"<< endl;
        return 0;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
using namespace std;

int main(){
	double x, q, y;
	while(scanf("%lf", &q), q >= 0.0){
		x = 0.5 * q;
		while(1){
			y = x * x * x - q;
			if(abs(y) < 1e-5 * q){
				break;
			}
			x -= y / (3.0 * x * x);
		}
		printf("%.6f\n", x);
	}
}

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

int main(){
  int k, n;
  cin >> k >> n;
  
  vector<int> vec(n);
  for (int i = 0; i < n; i++)
    cin >> vec.at(i);
  
  int res = 0;
  for (int i = 0; i < (n-1); i++)
    res = max(res, (vec.at(i+1)-vec.at(i)));
  res = max(res, k+vec.at(0)-vec.at(n-1));
  
  cout << k - res << endl;
    
}

Measured memory_bytes: 1024
# 20-String-Shuffle.py

# ?????£?????????
# ???????????¢????????????????????????????????? n ???????????????????±±????????£?????????????????????
# 1???????????£???????????§??????????????? h ???????????????????????¨???????????????????????????????????£????????????????±±??????????????????????????????
# ?????????????±±?????\???????????????????????????????????§?????????????????????

# abcdeefab
# ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

# ????????°???????????? h ??? 4 ??§?????£?????????????????¨????????????4?????? abcd ??????
# ??????????????? eefab ???????°??????£?????????????????§??\??????????????????????????????
# eefababcd
# ???????????£???????????????????????°??????????????????

# ?????????????±±???????????????????????????????????¨ h ???????????????????????????
# ?????????????????????????????????????????????????????°?????????????????????????????????

# Constraints
# ?????????????????????200????¶??????????
# ?????£?????????????????°???100????¶??????????

# Input
# ?????°??????????????????????????\?????¨?????????????????????????????????????????????????????\????????¢?????§?????????????????????
# ????????????????????¨????????????
# ?????£??????????????° m
# h1
# h2
#   .
#   .
# hm
# ????????????????????¨??????????????? "-" ?????¨?????\?????????????????¨????????????

# Output
# ??????????????????????????????????????????????????????????????????????????????????????????????????????

# Sample Input
# aabc
# 3
# 1
# 2
# 1
# vwxyz
# 2
# 3
# 4
# -
# Sample Output
# aabc
# xyzvw

card=[]
shuffle_times=[]
shuffle_num=[]

#??\???
while 1:
	card.append( input() )
	if card[-1]=="-":
		break;
	shuffle_times.append( int(input()) )
	# print("shuffle_times",shuffle_times)
	# print("shuffle_times[-1]",shuffle_times[-1])
	temp=[]
	for i in range(shuffle_times[-1]):
		temp.append( int(input()) )
	shuffle_num.append(temp)


#??\?????????
for i in range(len(card)-1):
	for j in range(shuffle_times[i]):
		card[i] = card[i][shuffle_num[i][j]:] + card[i][:shuffle_num[i][j]]
	
	# ??????
	print(card[i])

Measured memory_bytes: 7672
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    string s;
    cin >> s;
    bool c = false, f = false;
    repi(i, s){
        if(!c && *i == 'C'){
            c = true;
        }else if(c && !f && *i == 'F'){
            f = true;
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<functional>
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<string>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#include<ctime>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
using namespace std;
const int inf=2147483647,dx[]={-1,0,1,0},dy[]={0,-1,0,1};// 上 左 下 右
const int N=100005,M=1000005,K=200005,mod=1000000007;
const long long llinf=9223372036854775807ll;
//int & long long
int n,k,ans;
int main(){
	cin>>n>>k;
	while(n>0)
	{
		n/=k;
		ans++;
	}
	cout<<ans;
	return 0;
}

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

// UFDS for checking if two nodes are connected
int parent[100005], sz[100005];

void init(int n) {
	for (int i = 0; i <= n; i++) {
		parent[i] = i;
		sz[i] = 1;
	}
}

int find(int x) {
	if (parent[x] == x) {
		return x;
	} else {
		parent[x] = find(parent[x]);
		return parent[x];
	}
}

void merge(int x, int y) {
	x = find(x);
	y = find(y);
	if (sz[x] < sz[y]) {
		parent[x] = y;
		sz[y] += sz[x];
	} else {
		parent[y] = x;
		sz[x] += sz[y];
		sz[y] += sz[x];
	}
}

int N;
pair<int, int> X[100005], Y[100005];

vector<vector<int> > G;

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

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> X[i].first >> Y[i].first;
		X[i].second = i;
		Y[i].second = i;
	}

	sort(X, X + N);
	sort(Y, Y + N);
	for (int i = 0; i < N - 1; i++) {
		vector<int> x_edge;
		x_edge.push_back(X[i+1].first - X[i].first);
		x_edge.push_back(X[i].second);
		x_edge.push_back(X[i+1].second);
		G.push_back(x_edge);
		vector<int> y_edge;
		y_edge.push_back(Y[i+1].first - Y[i].first);
		y_edge.push_back(Y[i].second);
		y_edge.push_back(Y[i+1].second);
		G.push_back(y_edge);
	}

	// Kruskal's Algorithm
	// First sort the edges by weight in ascending order
	sort(G.begin(), G.end());

	// Initialize UFDS
	init(N);

	// To track the cost of the MST
	int cost = 0;
	// Go through edges one by one, add them into the MST as long as a cycle is not formed
	for (int i = 0; i < G.size(); i++) {
		int W = G[i][0], A = G[i][1], B = G[i][2];
		// Note: adding an edge A - B only forms a cycle if A and B are already connected via some other path
		// Two nodes are already connected, if they are in the same set
		if (find(A) != find(B)) {
			merge(A, B);
			cost += W;
		}
	}

	cout << cost << "\n";

}

Measured memory_bytes: 16588
n = int(input())
l = []
for i in range(n):
    l.append(list(map(int,input().split())))

now=0
nowx=0
nowy=0
for txy in l:
    t = txy[0] - now
    x = abs(txy[1] - nowx)
    y = abs(txy[2] - nowy)

    if t<x+y or (t-x-y) % 2 != 0:
        print("No")
        exit()

    now  = txy[0]
    nowx = txy[1]
    nowy = txy[2]
print("Yes")

Measured memory_bytes: 60248
#include<bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define F first
#define S second
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ld long double
#define pii pair <int ,int >
#define bug(x)  cout<<"passed "<<x<<endl;
#define ashar(x , y , z) cout<<setprecision(x)<<fixed<<y ; if (z==1) cout<<"\n" ;
#define ppi pair <pair <int, int > , int > 
long long const inf = 3e18, linf = 2e9, mod = 1e9+7 , inf2 = 1e12;
int const mxn = 5e5 + 10 ;
 
ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

long long  l[mxn] ;  
long long pa[mxn] ; 

int main(){
	int n , k ; 
	cin>>n>>k ; 
	for (int i = 1 ; i <= n ; i++)
		cin>>l[i] ; 
	for (int i = 1 ; i <= min (k , 100) ; i++){
		for (int j = 1 ; j <= n ; j++){
			long long L = max((long long)1, j - l[j]) ; 
			long long r = min(j + l[j] , (long long)n) ; 
			pa[L]++ ; 
			pa[r+1]-- ; 
		}
		for (int j = 1 ; j <= n ; j++){
			pa[j] +=pa[j-1] ; 
			l[j] = pa[j] ; 
		}
		for (int j = 1 ; j <= n ; j++)
			pa[j] = 0 ;
	}
	for (int i = 1 ; i <= n ; i++)
		cout<<l[i]<<" " ; 
}



Measured memory_bytes: 6704
#include<stdio.h>
#include<stdlib.h>

/*
struct node{

  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node *Node;
Node root, NIL;

void insert(int k){

  int N;
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));

  z -> key = k;
  z -> left = NIL;
  z -> right = NIL;

  while(x != NIL){

    y=x;

    if(z -> key < x -> key)
      x = x->left;
    else
      x = x -> right;
    
  }

  z -> parent = y;

  if(y == NIL) root = z;

  else {
    if( z->key < y->key)
      y -> left = z;

    else {
      y -> right = z;
    }
    
    }
}

void inorder (Node u){

  if(u==NIL) return;

  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);

}



void preorder(Node u){
  
  if(u==NIL) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
  
  }*/

int main(){
  int n,i,key;
  int array[100000];

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

  for(i=1; i<=n ;i++){
    printf("node %d: key = %d, ",i,array[i]);
    if(i/2 >= 1) printf("parent key = %d, ",array[i/2]);
    if(i*2 <= n) printf("left key = %d, ",array[i*2]);
    if(i*2+1 <= n) printf("right key = %d, ",array[i*2+1]);
    printf("\n");
    
  }
  return 0;
}



Measured memory_bytes: 2044
#include<bits/stdc++.h>
#define int long long
#define mod 1e18+10
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
int32_t main() {
	int a,b;
	cin>>a>>b;
	int av=1,ans=0;
	while(av<b)
	{
		av+=a-1;
		ans++;
	}
	cout<<ans<<"\n";
}	


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

int main(){
  using item= pair<int, int>;
  constexpr int Wmax = 100'000;
  constexpr int Dmax = 18;
  constexpr int Dhalf= 11;

  ios_base::sync_with_stdio(false);
  cin.tie(0);

  int N;
  cin >> N;

  vector<item> data(N+1);
  for(int v=1; v<=N; v++){
    cin >> data.at(v).first >> data.at(v).second;
  }

  // auto trimming= [](vector<int> *output){
  //   int val_cummax= -1;
  //   for(size_t w=0; w< output->size(); w++){
  //     val_cummax= max(val_cummax, output->at(w));
  //     output->at(w)= val_cummax;
  //   }
  // };

  const int Vupper= min(N+1, 1<< Dhalf);
  vector<vector<int>> above_half(Vupper, vector<int>(Wmax+ 1));
  for(int v=1; v<Vupper; v++){
    above_half.at(v)= above_half.at(v/2);
    auto [val_v, wgh_v]= data.at(v);
    for(int w=Wmax; w >= wgh_v; w--){
      above_half.at(v).at(w)= max(above_half.at(v/2).at(w), val_v+ above_half.at(v/2).at(w- wgh_v));
    }
    // trimming(&above_half.at(v));
  }

  int Q;
  cin >> Q;

  vector<int> answers(Q);

  int v_query; int W_query;
  for(int q=0; q<Q; q++){
    cin >> v_query >> W_query;

    if(v_query < Vupper){
      answers.at(q)= above_half.at(v_query).at(W_query);
    }
    else{
      int D_query= (32- __builtin_clz(v_query))- Dhalf;
      int v_anc= v_query >> D_query; 
 
      int ans= 0;
      for(int tmp=0; tmp<(1<< D_query); tmp++){
        bitset<Dhalf> bs(tmp);
 
        int wgh_lower= 0;
        int val_lower= 0;
        for(int i=0; i<D_query; i++){
          if(bs.test(i)){
            wgh_lower+= data.at((v_query>> i)).second;
            val_lower+= data.at((v_query>> i)).first;
          }
        }
 
        if(wgh_lower <= W_query){
          int val_upper= above_half.at(v_anc).at(W_query- wgh_lower);
 
          ans= max(ans, val_upper+ val_lower);
        }
      }
      answers.at(q)= ans;
    }
  }

  for(auto ans:answers){
    cout << ans << endl;
  }
}

Measured memory_bytes: 809588
#include <iostream>
using namespace std;
int main(void){
    int x,y;
    while(true){
     cin >>x;
     cin >>y;
     if(x==0 && y==0){
         break;
     }
     if(x<y){
         cout << x << " " << y << endl;
     }
     else{
         cout << y << " " << x << endl;
     }
    }        
}   


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int l,k;
    cin >>l >>k;

    vector<ll> dp(l+1);
    dp[1] = 1;
    if(k<=l) dp[k] = 1;
    for(int i=1; i<l; ++i){
        if(i+2<=l) dp[i+2] += dp[i];
        if(i+1+k<=l) dp[i+1+k] += dp[i];
    }

    ll ans = 0;
    rep(i,l+1) ans += dp[i];
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3108
n = int(input())
h = list(map(int,input().split()))

flg = 0

if n ==1 :
    pass
elif n>=2:
    for i in range(n-1):
        #ちょうど1段高い
        if h[i]-1 == h[i+1]:
            h[i+1] = h[i+1]+1
        #何もしない
        elif h[i] <= h[i+1]:
            pass
        else:
            flg = 1

if flg == 1:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 14396
from collections import deque


def p_g_dp():
    N, M = map(int, input().split())
    outs = [[] for _ in range(N)]
    ins = [0] * N
    for _ in range(M):
        f, t = map(int, input().split())
        outs[f - 1].append(t - 1)
        ins[t - 1] += 1
    q = deque(t for t in range(N) if ins[t] == 0)
    res = []
    dp = [0] * N
    while q:
        f = q.popleft()
        res.append(f)
        for t in outs[f]:
            ins[t] -= 1
            if ins[t] == 0:
                q.append(t)
                dp[t] = max(dp[t], dp[f] + 1)
    print(max(dp))


if __name__ == '__main__':
    p_g_dp()


Measured memory_bytes: 23860
N = int(input())

A = [[0]*10 for i in range(10)]

for i in range(1, N+1):
    A[int(str(i)[0])][int(str(i)[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += A[i][j] * A[j][i] 

print(ans)


Measured memory_bytes: 3060
from copy import deepcopy
H, W, K = map(int, input().split())
board = [[0]*(W+1) for _ in range(H+1)]
for i in range(1,H+1):
    board[i] = list(map(int, list(input())))+[0]
def drop(board_copy):
    change = True
    score = 0
    p = 0
    while change:
        change = False
        for i in range(2,H+1):
            ser = 1
            for j in range(W):
                if board_copy[i][j]>0 and board_copy[i][j]==board_copy[i][j+1]:
                    ser += 1
                else:
                    if ser>=K:
                        score += 2**p*board_copy[i][j]*ser
                        change = True
                        for k in range(i,0,-1):
                            board_copy[k][j-ser+1:j+1] = board_copy[k-1][j-ser+1:j+1]
                    ser = 1
        p += 1
    return score
ans = 0
for h in range(2,H+1):
    for w in range(W):
        board_copy = deepcopy(board)
        for k in range(h,0,-1):
            board_copy[k][w] = board[k-1][w]
        ans = max(ans,drop(board_copy))
print(ans)

Measured memory_bytes: 53212
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
 
 
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  int min_sum = 1000000000;
  for(int i = 1; i <= 100; i++){
    int sum = 0;
    rep(j,n){
      sum += (a.at(j)-i)*(a.at(j)-i);
    }
    min_sum = min(min_sum,sum);
  }
  cout << min_sum << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int INF (1<<30);

int main() {
  ll x;
  cin >> x;

  vector<ll> p5(500);
  rep(i, 500) {
    p5[i] = pow(i,5);
  }
  

  rep(a,500) {
    rep(b,500) {
      if (p5[a]+p5[b] == x) {
        cout << a << " " << -b << endl;
        return 0;
      }
      else if (p5[a]-p5[b] == x){
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 4028
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
if(a == b):
    print("YES")
else:
    if(v<=w):
        print("NO")
    else:
        Leng = abs(a-b)
        canM = abs(v-w) * t
        if(canM >= Leng):
            print("YES")
        else:
            print("NO")

Measured memory_bytes: 9136
import collections 
h,w,k = [int(x) for x in input().split()]
s = [list(input()) for _ in range(h)]
a = [[0]*w for _ in range(h)]
cnt= 1
for i in range(h):
  for j in range(w):
    if s[i][j]=="#":
      a[i][j]=cnt
      cnt+=1
for i in range(h):
  for j in range(1,w):
    if a[i][j]==0:
      a[i][j]=a[i][j-1]
for i in range(h):
  for j in range(w-2,-1,-1):
    if a[i][j]==0:
      a[i][j]=a[i][j+1]
for j in range(w):
  for i in range(1,h):
    if a[i][j]==0:
      a[i][j]=a[i-1][j]
for j in range(w):
  for i in range(h-2,-1,-1):
    if a[i][j]==0:
      a[i][j]=a[i+1][j]
for i in a:
  print(*i)

Measured memory_bytes: 8644
///Astalavista Code........~CodeSlayer007
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define pb push_back
#define mp make_pair
#define fe first
#define se second
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl
#define SPD_emergency ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
int M = 1e9 + 7;
const int N = 1e6 + 10;
const int IM = 1e15 + 37;
const int PI = 3.14159265;
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " "; cout << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << ' ' ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
inline void PP(int n) { cout << n << " ";}
inline void PP(int n, int m) { cout << n << " " << m << endl;}
inline void PP(int n, int m, int q) {  cout << n << " " << m << " " << q << endl;}
inline void PP(int n, int m, int q, int u) {  cout << n << " " << m << " " << q << " " << u << endl;}
inline void op() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
// <-------------------------------------------------------------------------------------------------------------------------------------------------------------------------> Ignore This--> setprecision memset substr pop_back  insert tuple first second push_back string continue make_pair break deque stack queue sort reverse accumulate  count lower_bound upper_bound next_permutation copy_n __builtin_popcount make_tuple
// <========================================================================================================================================================================

int a, b;
signed  main() {
    SPD_emergency
  
    int i, j, x, y, u, l;
    // int t; cin >> t; while (t--)
    {   i = j = x = y = u = l = 0;

        cin >> a >> b;
        a = a * b;
        PT(a);



        /**/

    }


    return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>

char S[100000];
int A[100000];
int I[100000];

int partition(int p, int r){
    int x = A[I[r-1]];
    int i = p;
    for(int j = p; j < r - 1; j++){
        if(A[I[j]] <= x){
            int temp = I[i];
            I[i] = I[j];
            I[j] = temp;
            i++;
        }
    }
    int temp = I[i];
    I[i] = I[r-1];
    I[r-1] = temp;
    return i;
}

void quicksort(int p, int r){
    if(r - p >= 2){
        int q = partition(p, r);
        quicksort(p, q);
        quicksort(q+1, r);
    }
}

int main(void){
    int n;
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        getchar();
        scanf("%c", &S[i]);
        scanf("%d", &A[i]);
        I[i] = i;
    }
    quicksort(0, n);
    int m = A[I[0]];
    int stable = 1;
    for(int i=1; i<n; i++){
        if(A[I[i-1]] == A[I[i]] && I[i-1] > I[i])
            stable = 0;
    }
    puts(stable ? "Stable" : "Not stable");
    for(int i=0; i<n; i++)
        printf("%c %d\n", S[I[i]], A[I[i]]);
}



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

int main() {

    string s;

    cin >> s;

    int count = 0;

    for(int i=1; i<s.size(); i++){
        if(s[i] != s[i-1]){
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[][] Z = new int[N][2];
		for(int i = 0; i < N; i++) {
			int X = sc.nextInt();
			int L = sc.nextInt();
			Z[i][0] = X - L;
			Z[i][1] = X + L;
		}
		Arrays.sort(Z, (x,y) -> x[1]-y[1]);
		int ans = 1, point = Z[0][1];
		for(int i = 1; i < N; i++) {
			if(Z[i][0] >= point) {
				ans++;
				point = Z[i][1];
			}
		}	
		System.out.println(ans);

	}

}

Measured memory_bytes: 94604
#include <iostream>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <cstring>
#include <algorithm>
#include <set>
#include <climits>
#include <numeric>

//usings
using namespace std;

//type def
typedef long long int64;
typedef pair<int, int> ii;

//consts
const int mod = 1e9 + 7;

//methods
template<typename T>
bool chmax(T& source, const T& compare_to) {
    if(source < compare_to) {
        source = compare_to;
        return true;
    }
    return false;
}

int modpow(int64 base, int n) {
    int64 ret = 1;
    while(n) {
        if(n & 1) ret = ret * base % mod;
        base = base * base % mod;
        n >>= 1;
    }
    return ret;
}

class Solution {
private:
public:
    vector<int> solve(int n, int m, vector<vector<int>>& mp) {
        vector<bool> v(n + 1);
        v[1] = true;
        queue<int> q;
        q.push(1);
        vector<int> ret(n + 1, -1);
        while(!q.empty()) {
            for(int s = q.size(); s; --s) {
                auto f = q.front(); q.pop();
                for(const auto& room : mp[f]) {
                    if(!v[room]) {
                        v[room] = 1;
                        ret[room] = f;
                        q.push(room);
                    }
                }
            }
        }
        return ret;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    vector<vector<int>> mp(n + 1);
    for(int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        mp[a].push_back(b);
        mp[b].push_back(a);
    }
    Solution sol;
    auto ret = sol.solve(n, m, mp);
    bool can = 1;
    for(int i = 2; i <= n; ++i) {
        if(ret[i] == -1) {
            can = 0;
            break;
        }
    }
    if(!can) cout << "No" << endl;
    else cout << "Yes" << endl;
    for(int i = 2; i <= n; ++i) cout << ret[i] << endl;
}

Measured memory_bytes: 10128
import java.util.*;
 
public class Main{
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String nk = scanner.nextLine();
    String s = scanner.nextLine();
    int toLowerCaseIdx = Integer.parseInt(nk.split(" ")[1]);
    StringBuilder sb = new StringBuilder(s);
    sb.replace(toLowerCaseIdx-1,toLowerCaseIdx,s.substring(toLowerCaseIdx-1,toLowerCaseIdx).toLowerCase());
    System.out.println(sb);
  }
}

Measured memory_bytes: 21204
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    vvll edges(n);
    for (ll i = 0; i < m; i++) {
        ll a, b; cin >> a >> b;
        a--, b--;
        edges[a].emplace_back(b);
        edges[b].emplace_back(a);
    }

    vll from(n, -1), dist(n, HIGHINF);
    dist[0] = 0;
    queue<ll> que; que.push(0);
    while (!que.empty()) {
        ll q = que.front(); que.pop();
        for (ll e: edges[q]) {
            if (dist[e] > dist[q] + 1) {
                from[e] = q;
                dist[e] = dist[q] + 1;
                que.push(e);
            }
        }
    }

    for (ll i = 0; i < n; i++) {
        if (dist[i] == HIGHINF) {
            cout << "No\n";
            return 0;
        }
    }

    cout << "Yes\n";
    for (ll i = 1; i < n; i++) {
        cout << from[i] + 1 << '\n';
    }
    return 0;
}


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

const int INF = 100000;

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

  int n;
  cin >> n;
  vector<int> w;
  for (auto i = 0; i < n; ++i) {
    int t;
    cin >> t;
    w.push_back(t);
  }

  vector<int> v = w;
  sort(v.begin(), v.end());

  map<int, int> m;
  for (auto i = 0; i < n; ++i) {
    m[v[i]] = i;
  }

  vector<int> u;
  for (auto i = 0; i < n; ++i) {
    u.push_back(false);
  }

  int p = 0;
  int s = 0;
  while (p < n) {
    if (u[p]) {
      ++p;
      continue;
    }
    u[p] = true;
    int t = w[p];
    int r = INF;
    int c = 1;
    int q = m[w[p]];
    if (p == q) {
      continue;
    }
    while (p != q) {
      u[q] = true;
      t += w[q];
      if (w[q] < r) {
        r = w[q];
      }
      q = m[w[q]];
      ++c;
    }
    s += min(t + (c - 2) * r, t + r + (c + 1) * v[0]);
  }

  cout << s << endl;

  return 0;
}



Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;
#define rep(i, ss, ee) for (int i = (ss); i < (ee); ++i)
#define repr(i, ss, ee) for (int i = (ss); i >= (ee); --i)

void solve() {
  int x, N;
  cin >> x >> N;
  if (N == 0) {
    cout << x << endl;
    return;
  }

  vector<bool> v(102, true);
  int a;
  rep(i, 0, N) {
    cin >> a;
    v[a] = false;
  }

  using P = pair<int, int>;
  vector<P> ans;
  rep(i, x, v.size()) {
    if (v[i]) {
      ans.emplace_back(abs(i - x), i);
      break;
    }
  }
  repr(i, x, 0) {
    if (v[i]) {
      ans.emplace_back(abs(i - x), i);
      break;
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans.front().second << endl;
}

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

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    cin>>k;
    int a[32]={1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
    cout<<a[k-1];

}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(ll a, ll b){
    cout<<(a<=8&&b<=8?"Yay!":":(")<<endl;
}

int main(){
    ll a;
    scanf("%lld",&a);
    ll b;
    scanf("%lld",&b);
    solve(a, b);
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void){
  string S;
  cin >> S;
  int ajitama,chashu,negi;
  ajitama=(S.at(0)=='o');
  chashu=(S.at(1)=='o');
  negi=(S.at(2)=='o');
  cout << 700+100*(ajitama+chashu+negi);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(a*b, c*d) << endl;
}


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

int main()
{
    int n;

    cin>>n;

    if(n>=400 && n<=599) cout<<"8"<<endl;
    else if(n>=600 && n<=799) cout<<"7"<<endl;
     else if(n>=800 && n<=999) cout<<"6"<<endl;
      else if(n>=1000 && n<=1199) cout<<"5"<<endl;
       else if(n>=1200 && n<=1399) cout<<"4"<<endl;
        else if(n>=1400 && n<=1599) cout<<"3"<<endl;
         else if(n>=1600 && n<=1799) cout<<"2"<<endl;
          else if(n>=1800 && n<=1999) cout<<"1"<<endl;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
// #define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FORE(x,c) for(auto &x:c)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=((int)(n)-1);v>=0;v--)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define SZ(c) ((int)c.size())
const int DX[9]={0,1,0,-1,1,1,-1,-1,0}, DY[9]={-1,0,1,0,-1,1,1,-1,0};
const int INF=1e9; const long long INFLL=1e18;
template<class T> ostream& operator << (ostream &os, const vector<T> &v) {
    ITR(i,v) os<<*i<<(i==end(v)-1?"":" "); return os; }
template<class T> istream& operator >> (istream &is, vector<T> &v) {
    ITR(i,v) is>>*i; return is; }
//------------------------------------------------------------------------------

signed main() {
    int k,t;
    cin>>k>>t;
    vi a(t);
    cin>>a;

    int last=-1,ans=0;
    while(k>0) {
        sort(RALL(a));
        REP(i,t) {
            if(a[i]!=0) {
                if(last==i) {
                    ans++;
                }
                last=i;
                a[i]--;
                k--;
                break;
            }
        }
        if(k==0) break;
        RREP(i,t) {
            if(a[i]!=0) {
                if(last==i) {
                    ans++;
                }
                last=i;
                a[i]--;
                k--;
                break;
            }
        }
        if(k==0) break;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace Project
{
	class MainClass
	{
		public static void Main(string[] args)
		{
			string str = Console.ReadLine();
			char[] c = new char[str.Length];
			for (int i = 0; i < str.Length; i++)
			{
				c[i] = str[i];
			}
			int n = int.Parse(Console.ReadLine());
			for (int i = 0; i < n; i++)
			{
				string[] command = Console.ReadLine().Split(' ');
				int a = int.Parse(command[1]);
				int b = int.Parse(command[2]);
				switch (command[0])
				{
					case "print":
						for (int j = a; j <= b; j++)
						{

							Console.Write(c[j]);
							if (j == b) Console.Write("\n");
						}
						break;
					case "reverse":
						char[] cr = new char[b - a + 1];
						for (int j = a; j <= b; j++)
						{
							cr[-j + b] = c[j];
						}
						for (int j = a; j <= b; j++)
						{
							c[j] = cr[j - a];
						}
						break;
					case "replace":
						for (int j = a; j <= b; j++)
						{
							c[j] = command[3][j - a];
						}
						break;
				}
			}
		}
	}
}

Measured memory_bytes: 9068
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;

const double pi=3.1415;
ll absc(ll a,ll b){return (a-b>0?a-b:b-a);
}
ll mini(ll a,ll b){return (a>b?b:a);}
ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
}
int main()
{
   int a,b,c;
   string s;
   cin>>s;
   cout<<(s=="ABC"?"ARC":"ABC");
}


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

int main() {

  ios::sync_with_stdio(false);
  cout.tie(nullptr);
  cin.tie(nullptr);

  int n;
  cin >> n;

  vector<long long> h(n + 5), dp(n + 5, 1e6);
  dp[1] = 0;

  for (int i = 1; i <= n; ++i) {
    cin >> h[i];
    if (i > 1) dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
    if (i > 2) dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
  }

  cout << dp[n] << '\n';
}

Measured memory_bytes: 1792
N = int(input())
H = list(map(int, input().split()))

for i in range(N-2, -1, -1):
    if H[i] - H[i + 1] > 1:
        print("No")
        exit(0)
    if H[i] - H[i + 1] > 0:
        H[i] -= 1
for i in range(N-1):
    if H[i] > H[i + 1]:
        print("No")
        exit(0)
print("Yes")


Measured memory_bytes: 14252
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T, typename E>
struct SkewHeap{
  typedef function<T(T, E)> F;
  typedef function<E(E, E)> G;
  typedef function<bool(T,T)> C;
  F f;
  G g;
  C c;
  E e;
  SkewHeap(F f,G g,C c,E e):f(f),g(g),c(c),e(e){}

  struct Node{
    Node *l,*r;
    T val;
    E add;
    Node(T val,E add):val(val),add(add){l=r=NULL;}
  };

  void eval(Node *a){
    if(a->add==e) return;
    if(a->l) a->l->add=g(a->l->add,a->add);
    if(a->r) a->r->add=g(a->r->add,a->add);
    a->val=f(a->val,a->add);
    a->add=e;
  }
  
  T top(Node *a){
    return f(a->val,a->add);
  }
  
  Node* push(T v){
    return new Node(v,e);
  }
  
  Node* meld(Node *a,Node *b){
    if(!a) return b;
    if(!b) return a;
    if(c(top(a),top(b))) swap(a,b);
    eval(a);
    a->r=meld(a->r,b);
    swap(a->l,a->r);
    return a;
  }
  
  Node* pop(Node* a){
    eval(a);
    auto res=meld(a->l,a->r);
    free(a);
    return res;
  }
  
};

struct APC001_D{
  struct UnionFind{
    int n;
    vector<int> r,p;
    UnionFind(){}
    UnionFind(int sz):n(sz),r(sz,1),p(sz,0){iota(p.begin(),p.end(),0);}
    int find(int x){
      return (x==p[x]?x:p[x]=find(p[x]));
    }
    bool same(int x,int y){
      return find(x)==find(y);
    }
    void unite(int x,int y){
      x=find(x);y=find(y);
      if(x==y) return;
      if(r[x]<r[y]) swap(x,y);
      r[x]+=r[y];
      p[y]=x;
    }
  };
  
  signed solve(){
    using Heap = SkewHeap<Int, Int>;
    Int n,m;
    cin>>n>>m;
    vector<Int> a(n);
    for(Int i=0;i<n;i++) cin>>a[i];
    
    Heap::F f=[](auto a,auto b){return a+b;};
    Heap::G g=[](auto a,auto b){return a+b;};
    Heap::C c=[](auto a,auto b){return a>b;};
    
    Heap heap(f,g,c,0);
    vector<Heap::Node*> v(n);
    for(Int i=0;i<n;i++) v[i]=heap.push(a[i]);
    
    UnionFind uf(n);
    for(Int i=0;i<m;i++){
      Int x,y;
      cin>>x>>y;
      x=uf.find(x);y=uf.find(y);
      uf.unite(x,y);
      if(uf.find(x)!=x) swap(x,y);
      v[x]=heap.meld(v[x],v[y]);
      v[y]=NULL;
    }
    
    if(m==n-1){
      cout<<0<<endl;
      return 0;
    }
    
    Heap::Node* base=NULL;
    
    Int ans=0,cnt=0;
    for(Int i=0;i<n;i++){
      if(uf.find(i)==i){
	ans+=heap.top(v[i]);
	v[i]=heap.pop(v[i]);
	base=heap.meld(base,v[i]);
	cnt++;
      }
    }
    
    while(m*2+cnt<(n-1)*2){
      if(base==NULL){
	cout<<"Impossible"<<endl;
	return 0;
      }
      ans+=heap.top(base);
      base=heap.pop(base);
      cnt++;
    }
  
    cout<<ans<<endl;
    return 0;
  }
  /*
    verified on 2018/02/08
    https://beta.atcoder.jp/contests/apc001/tasks/apc001_d
  */
};

signed main(){
  APC001_D ans;
  
  ans.solve();
}


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
 
signed main(){
bool a[30000]{};
int b,c,d;
cin>>b>>c>>d;
for(int e=0;e<b;e++){
    int f;
    cin>>f;
    for(int g=f-c;g<f+c;g++){
	a[g]=true;
	}
    }
    int s=0;
    for(int h=0;h<d;h++){
	if(!a[h])s++;
	}
	cout<<s<<endl;
}

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


int main() {
	string str;
	cin >> str;
	int ans=0;
	for(int i=0; i<str.size()-1; i++){
		if(str.at(i) != str.at(i+1)) ans++;
	}
	cout << ans << endl;
}


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

int main()
{
    int n, k;
    int d;
    int a;
    cin >> n >> k;
    vector<int> kodomo(n, 0);
    for (int i = 0; i < k; i++)
    {
        cin >> d;
        for (int j = 0; j < d; j++)
        {
            cin >> a;
            kodomo.at(a - 1)++;
        }
    }
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (kodomo.at(i) == 0)
        {
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3608