akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

struct edge {
  ll to;
  ll cost;
};
typedef pair<long long, long long> P_dij;	

 /* params	
 * @s -> start, n -> 要素数, G -> グラフ, d -> 結果(参照渡し)	
 * グラフの要素を0 ~ n - 1として見る	
*/	
void dijkstra(const long long s, const long long n,	
  vector< vector<edge> > const &G, vector<long long> & d){	
  d.resize(n);	
  for(int i=0; i<n; i++) d[i] = INF; 	
  priority_queue<P_dij, vector<P_dij>, greater<P_dij>> que;	
  d[s] = 0;	
  que.push(P_dij(0, s));	
  while (!que.empty()) {	
    P_dij p = que.top();	
    que.pop();	
    long long v = p.second;	
    if(d[v] < p.first)continue;	
    for(int i=0;i<G[v].size(); i++){	
      edge e = G[v][i];	
      if(d[e.to] > d[v] + e.cost){	
        d[e.to] = d[v] + e.cost;	
        que.push(P_dij(d[e.to], e.to));	
      }	
    }	
  }	
}	



int main() {
  int n;
  cin >> n;
  ll u,v,w;
  vector< vector<edge> > G(n);
  rep(i,n-1) {
    cin >> u >> v >> w;
    u--, v--;
    G[u].push_back({v,w});
    G[v].push_back({u,w});
  }

  vector<ll> d, d2;
  vector<bool> ans(n);
  
  dijkstra(0, n, G, d);
  
  ans[0] = 1;
  ll cnt = 0, tm = 0;
  for (int i = 1; i < n; ++i) {
    if (d[i] % 2 == 0) {
      ans[i] = 1;
    } else {
      cnt += 1;
      tm = i;
    }
  }
  
  /*
  if (cnt == 1) {
    dijkstra(0, n, G, d2);
    for (int i = 0; i < n; ++i) {
      if (i == tm) continue;
      if (d2[i] % 2 == 0) {
        ans[i] = 0;
        break;
      }
    }
  }*/
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 8704
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        try(Scanner sc = new Scanner(System.in)){
            while(true){
                int n = sc.nextInt();
                if(n==0){
                    break;
                }
                int[]scores = new int[n];
                for(int i=0;i<scores.length;i++){
                    scores[i]=sc.nextInt();
                }
                double average=0, variance=0;
                double sum=0,a=0;
                for(int i=0;i<scores.length;i++){
                    sum=sum+scores[i];
                 }
                 average=sum/n;
                 for(int i=0;i<scores.length;i++){
                     a+=((scores[i]-average)*(scores[i]-average));
                 }
                 variance=a/n;
                 System.out.println(Math.sqrt(variance));
            }
        }

    }
}


Measured memory_bytes: 31640
n=int(input())
a=list(map(int,input().split()))
b=[0]
c=[0]
d=[0]
e=[0]
count=0
count2=0
count3=0
count4=0
for i in range(n):
  a[i]-=i
a.sort()
for i in range(n-1):
  count+=a[i+1]-a[i]
  count3+=a[n-i-1]-a[n-i-2]
  b.append(count)
  d.append(count3)
for i in range(n-1):
  count2+=b[i+1]
  count4+=d[i+1]
  c.append(count2)
  e.append(count4)
ans=10**18
for i in range(n):
  ans=min(ans,c[-1]-c[i]-b[i]*(n-i-1)+e[-1]-e[n-i-1]-d[n-i-1]*i)
print(ans)

Measured memory_bytes: 49772
from heapq import heappop, heappush
def inpl(): return list(map(int, input().split()))
N, M = inpl()
A = [0]*M
B = [0]*M
C = [0]*M
for m in range(M):
    A[m], B[m] = inpl()
    c = 0
    for x in inpl():
        c += pow(2, x-1)
    C[m] = c
DP = [10**9]*pow(2, N)
DP[0] = 0
for i in range(pow(2, N)):
    if DP[i] > 10**8:
        continue
    for m in range(M):
        DP[i|C[m]] = min(DP[i|C[m]], DP[i] + A[m])
print(DP[-1] if DP[-1] < 10**9 else -1)

Measured memory_bytes: 45928
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[3],k,sum,i;
	for(i=0;i<3;i++)
	scanf("%d",&a[i]);
	scanf("%d",&k);
	sort(a,a+3);
	for(i=1;i<=k;i++){
		a[2]=a[2]*2;
	}
	sum=a[0]+a[1]+a[2];
	printf("%d",sum);
	return 0;
}

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

using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << " = " << x << endl

const long long MOD = 1000000007;


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

    ll a = x-k+1;
    cout << a;
    for(ll i = a+1; i < x+k; i++){
        cout << " " << i;
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 100005;
int a[MAXN],n,k;
struct Edge{
	int to,next;
}e[MAXN];
int head[MAXN],cnt;
inline void insert(int u,int v)
{
	e[++cnt].to=v,e[cnt].next=head[u],head[u]=cnt;
}
int ans=0,dep[MAXN],root;
bool vis[MAXN];
void dfs(int x,int fa)
{
	vis[x]=true;
	for(int i=head[x];i;i=e[i].next){
		int v=e[i].to;
		dfs(v,x);
		dep[x]=max(dep[x],dep[v]);
	}
	++dep[x];
	if(dep[x]>=k && fa && fa!=root){
		dep[x]=0;
		++ans;
	}		
}
int in[MAXN];
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1,to;i<=n;++i){
		scanf("%d",&to);
		if(i!=1)insert(to,i);
		if(i==1 && to!=1)++ans;
	}
	root=1,dfs(1,0);
	printf("%d\n",ans);
	return 0;
}


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

int main(){
	int N;
	scanf("%d",&N);
	if((N==1)||(N==2)||(N==3)||(N==5)||(N==6)||(N==9)||(N==10)||(N==13)||(N==17))printf("No");
	else printf("Yes");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
ll a[210000];
int main(){
    ll n,k,ans=0;
    cin>>n>>k;
    rep(i,0,n)cin>>a[i];
    rep(i,0,n){
        if(k<=a[i])ans++;
    }
    cout<<ans;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (auto &e : a) cin >> e;
  for (auto &e : b) cin >> e;

  vector<ll> d(n + 1), s(n + 1);
  for (int i = 0; i < n; i++) d[i + 1] = a[i] - b[i];
  sort(begin(d) + 1, end(d));
  for (int i = 0; i < n; i++) s[i + 1] = s[i] + d[i + 1];
  int p = lower_bound(begin(d) + 1, end(d), 0) - begin(d);
  int r = -1;
  for (int i = 0; i <= n; i++) {
    if ((s[p - 1] - s[0]) + (s[n] - s[n - i]) >= 0) {
      r = p - 1 + i;
      break;
    }
  }
  cout << r << endl;
}


Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main(){
    long n,k;
    cin>>n>>k;
    int rous[n];
    int rouh[n];
    int j=0;
    int u=0;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        if(x<0){
            rouh[j]=x;
            j++;
        }
        else {
            rous[u]=x;
            u++;
        }
    }
    
    if(u==0){
        int min=abs(rouh[j-k]);
        cout<<min;
        return 0;
    }
    if(j==0){
        int min=rous[k-1];
        cout<<min;
        return 0;
    }
    
    int min=0;
    int f=0;

  //  cout<<u<<j;
    
   /* for(int i=0;i<j;i++){
        cout<<rouh[i]<<endl;
    }*/
    //cout<<j<<"uu"<<endl;
    
   for(int i=0;i<u+1;i++){//sei
       for(int t=0;t<j+1;t++){//hu
            
           int times=0;
            int timeh=0;
            int time=0;
            int timemini=0;
            
            if((i+t)==k){
                
                if(i==0){
                    timeh=rouh[j-t];
                    times=0;
                }else if(t==0){
                    timeh=0;
                    times=rous[i-1];
                }else{
                    timeh=rouh[j-t];
                    times=rous[i-1];
                }
                
                //cout<<i<<' '<<t<<' '<<times<<' '<<timeh<<endl;
                int a=times*2+abs(timeh);
                int b=abs(timeh)*2+times;
                
                if(a>b){
                    timemini=b;
                }else{
                    timemini=a;
                }
                if(f==0){
                    f=1;
                    min=timemini;
                }else {
                if(timemini<min){
                    min=timemini;
                }
                }
                
            }
        }
    }
    
    cout<<min;

return 0;
}

Measured memory_bytes: 640
N = int(input())
adj = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int, input().split())
    adj[a-1].append(b-1)
    adj[b-1].append(a-1)

def bfs(i):
    global depth
    depth = [0] * N
    s = [i]
    depth[i] = 1
    while s:
        v = s.pop()
        for u in adj[v]:
            if not depth[u]:
                depth[u] = depth[v] + 1
                s.append(u)

bfs(0)
i = depth.index(max(depth))
bfs(i)

print('Second' if max(depth) % 3 == 2 else 'First')


Measured memory_bytes: 48688
#include <bits/stdc++.h>
using namespace std;
#define fo(i,ini,n) for(int i=ini;i<n;i++)
#define rfo(i,ini,n) for(int i=ini;i>=n;i--)
int const inf=1e9+7;
typedef long long ll;

int main(){
	int t=1;
	while(t--){
		ll n,W,v,w;
		cin>>n>>W;
		vector<ll>dp(100001,inf);
		dp[0]=0;
		fo(i,0,n){
			cin>>w>>v;
			rfo(j,100001-v,0){
				dp[j+v]=min(dp[j+v],dp[j]+w);
				
			}
		}
		rfo(i,100000,0){
			if(dp[i]<=W){
			cout<<i<<endl;
			break;
			}
		}
	}

	return 0;
}


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

XOR, SUM = 0, 0
r, ans = 0, 0

for l in range(N):
    while r < N and XOR ^ A[r] == SUM + A[r]:
        XOR ^= A[r]
        SUM += A[r]
        r += 1

    ans += (r - l)
    XOR ^= A[l]
    SUM -= A[l]

print(ans)


Measured memory_bytes: 24840
/*
对初始的A序列添加一个A[N + 1] = A[1] xor A[2] xor ... xor A[N]，容易发现题目给定的操作就是在swap(A[i], A[N + 1])，同时A[N + 1] = A[1] xor A[2] xor ... xor A[N]的性质一直满足。无解可以判断
可以发现，N + 1这个位置的用处是一个“中间站”
把所有A[i] != B[i]的位置提出来，对于剩下的位置，考虑某一种方案中，如果要把A[i]的值赋给A[j]，就i -> j连一条边，最优方案中显然每个点入度 = 出度 = 1，可以看成置换P，形成了若干个环
考虑两个不同的环中有两个点a和b满足A[a] = A[b]，那么可以swap(P[a], P[b])，来做到合并2个环同时保持合法。这样可以使得每个权值相同的点都在同一个环上。下面考虑每个环，设环大小为n 
(1)对于含有N + 1的环，可以考虑从该点出发在环上走，走到x时swap(A[P[x]], A[N + 1])，不走到N + 1的后继（swap(A[N + 1], A[N + 1])无意义），就可以用n - 1次操作完成该环的赋值了
(2)若不存在环(1)，但是存在权值 = A[N + 1]的点的环，可以考虑从该点出发在环上走，走到x时swap(A[P[x]], A[N + 1])，走到N + 1的后继，就可以用n次操作完成该环的赋值了 
(3)对于剩下的环，从任意一个点s出发，先swap(A[s], A[N + 1])，然后从该点开始在环上走，走到x时swap(A[P[x]], A[N + 1])，就可以用n + 1次操作完成该环的赋值了
故Ans = Sum{[A[x] != B[x]]   |   1 <= x <= N} + (3)环的数量 - [N + 1在一个环中]，考虑如何最小化(3)环的数量
*/
/*
把权值作为点建图，当A[x] != B[x]时就B[x] -> A[x]连一条边。对于每个点都满足入度 = 出度 = 该权值的点有多少个，所以每个底图联通块都存在欧拉回路
显然一个欧拉回路能够构造出来一个置换P的环，所以连完边直接算答案 
*/

#include <map>
#include <cstdio>

using namespace std;
const int Max_N(100050);

int N, A[Max_N], B[Max_N], Ans;
bool Flag1, Flag2;
map<int, int> In, Ot, Father;

int Get_Father(int x)
{
	return Father[x] == x ? x : Father[x] = Get_Father(Father[x]);
}

int main()
{
	scanf("%d", &N);
	for (int i = 1;i <= N;++i)
		scanf("%d", A + i), A[N + 1] ^= A[i];
	for (int i = 1;i <= N;++i)
		scanf("%d", B + i), B[N + 1] ^= B[i];
	for (int i = 1;i <= N + 1;++i)
		if (A[i] != B[i])
		{
			++Ans;
			if (!Father.count(A[i]))
				Father[A[i]] = A[i];
			if (!Father.count(B[i]))
				Father[B[i]] = B[i];
			Father[Get_Father(A[i])] = Get_Father(B[i]);
			++In[A[i]], ++Ot[B[i]];
			Flag1 |= ((A[i] == A[N + 1]) || (B[i] == B[N + 1]));
			Flag2 |= (i == N + 1);
		}
	for (map<int, int>::iterator it = In.begin();it != In.end();++it)
		if (Ot[it -> first] != it -> second)
		{
			printf("-1");
			return 0;
		}
	for (map<int, int>::iterator it = Father.begin();it != Father.end();++it)
		if (Get_Father(it -> first) == it -> first)
			++Ans;
	if (Flag2)
		Ans -= 2;
	else
		if (Flag1)
			Ans -= 1;
	printf("%d", Ans);
	return 0;
}

Measured memory_bytes: 24448
#include <bits/stdc++.h>
#define re register
#define LL long long
#define SIZE 3005
#define INF 0x7f7f7f7f
#define S size()
using namespace std;
string s1,s2,ans;
int dp[SIZE][SIZE],p[SIZE][SIZE];
inline void dfs(int i,int j)
{
	if(i==0 || j==0)
		return;
	if(p[i][j]==1)
		dfs(i-1,j-1),cout<<s1[i];
	else	if(p[i][j]==2)
		dfs(i-1,j);
	else
		dfs(i,j-1);
}
int main()
{
	s1=s2=' ';
	string a,b;
	cin>>a>>b;
	s1+=a;s2+=b;
	for(re int i=1;i<s1.S;++i)
		for(re int j=1;j<s2.S;++j)
			if(s1[i]==s2[j])
				dp[i][j]=dp[i-1][j-1]+1,p[i][j]=1;
			else if(dp[i-1][j]>dp[i][j-1])
				dp[i][j]=dp[i-1][j],p[i][j]=2;
			else
				dp[i][j]=dp[i][j-1],p[i][j]=3;
	dfs(s1.S-1,s2.S-1);
	cout<<endl;
	return 0;
}

Measured memory_bytes: 74116
#include <bits/stdc++.h>
using namespace std;
int main(){
string N;
  cin>>N;
  int n=N.size();
  int sum=0;
  for(int i=0;i<n/2;i++){
  sum+=9*pow(10,2*i);
  
  }
  if(n%2==1)
    sum+=stoi(N)-pow(10,n-1)+1;
  cout<<sum<<endl;
 
  
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long[] b = new long[n];
        long[] dif = new long[n];
        long suma = 0;
        long sumb = 0;
        for(int i=0; i<n; i++){
            a[i] = sc.nextLong();
            suma += a[i];
        }
        for(int i=0; i<n; i++){
            b[i] = sc.nextLong();
            sumb += b[i];
            dif[i] = a[i] - b[i];
        }

        if(suma < sumb){
            System.out.println(-1);
            return;
        }

        Arrays.sort(dif);
        long csum = 0;
        int ans = 0;

        for(int i=0; i<n; i++){
            if(dif[i] < 0){
                csum += dif[i];
                ans++;
            }else{
                break;
            }
        }

        for(int i=0; i<n; i++){
            if(csum >= 0) break;
            csum += dif[n-1-i];
            ans++;
            if(csum >= 0) break;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 87228
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
  string s; cin >> s;

  REP(i, (int)s.length()){
    switch(s[i]){
      case 'A': s[i] = 'T';
                break;
      case 'T': s[i] = 'A';
                break;
      case 'C': s[i] = 'G';
                break;
      case 'G': s[i] = 'C';
                break;
    }
  }

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>

bool test(const int x, const int y) { return x & 1 << y; }

int main() {
  int n;
  std::cin >> n;
  std::vector<int> v(n, 0);
  for (int i = 0; i != n - 1; i += 1) {
    int x, y, a;
    std::cin >> x >> y >> a;
    v[x] ^= a;
    v[y] ^= a;
  }
  int ans = n;
  int b = 0;
  for (const int e : v) {
    if (e == 0) {
      ans -= 1;
      continue;
    }
    if (test(b, e))
      ans -= 1;
    b ^= 1 << e;
  }
  std::vector<int> dp(b + 1, -1);
  dp[b] = 0;
  for (int s = b; s != 0; s -= 1) {
    if (dp[s] == -1)
      continue;
    int i = 16;
    while (i != 0) {
      i -= 1;
      if (test(s, i))
        break;
    }
    for (int j = 0; j != i; j += 1) {
      if (!test(s, j))
        continue;
      const int k = i ^ j;
      if (k > j)
        continue;
      int &d = dp[s ^ 1 << i ^ 1 << j ^ 1 << k];
      if (test(s, k))
        d = std::max(d, dp[s] + 1);
      else
        d = std::max(d, dp[s]);
    }
  }
  std::cout << ans - dp[0] << std::endl;
}

Measured memory_bytes: 896
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=100005;
int n,m,q,i,j,k,v[N],d[N],c[N],col[N],head[N],adj[N*2],nxt[N*2];
bool vis[N][15];
void dfs(int x,int d)
{
	if(!col[x])
		col[x]=c[i];
	vis[x][d]=true;
	if(d==0)
		return;
	for(int y=head[x];y;y=nxt[y])
		if(!vis[adj[y]][d-1])
			dfs(adj[y],d-1);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i)
	{
		scanf("%d%d",&j,&k);
		adj[i*2-1]=k;
		nxt[i*2-1]=head[j];
		head[j]=i*2-1;
		adj[i*2]=j;
		nxt[i*2]=head[k];
		head[k]=i*2;
	}
	scanf("%d",&q);
	for(i=1;i<=q;++i)
		scanf("%d%d%d",v+i,d+i,c+i);
	for(i=q;i>=1;--i)
	if(!vis[v[i]][d[i]])
		dfs(v[i],d[i]);
	for(i=1;i<=n;++i)
		printf("%d\n",col[i]);
	return 0;
}


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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] colors = new int[8];
		int ra = 0,total = 0,max;
		for(int i = 0;i <n;i++) {
			int a = sc.nextInt();
			if(1 <= a && a< 400) {
				colors[0] = 1;
			}else if(400 <= a && a< 800) {
				colors[1] = 1;
			}else if(800 <= a && a< 1200) {
				colors[2] = 1;
			}else if(1200 <= a && a< 1600) {
				colors[3] = 1;
			}else if(1600 <= a && a< 2000) {
				colors[4] = 1;
			}else if(2000 <= a && a< 2400) {
				colors[5] = 1;
			}else if(2400 <= a && a< 2800) {
				colors[6] = 1;
			}else if(2800 <= a && a< 3200) {
				colors[7] = 1;
			}else if(3200 <= a) {
				ra++;
			}
		}
		for(int i = 0;i <8;i++) {
			total = total + colors[i];
		}
		max = total +ra;
      	if(total < 1) {
			total = 1;
		}
		System.out.println(total+" "+max);
	}

}

Measured memory_bytes: 21716
def root(x):
    path = []
    while P[x] != x:
        path.append(x)
        x = P[x]
    for node in path:
        P[node] = x
    return x
def check(x,y):
    if root(x) == root(y):
        return 1
    else:
        return 0
def unite(x,y):
    P[root(x)] = root(y)        

n,q = map(int,input().split())
P = [i for i in range(n)]
for j in range(q):
    s = list(map(int,input().split()))
    if s[0] == 0:
        unite(s[1],s[2])
    else:
        print(check(s[1],s[2]))
    #print(P)    



Measured memory_bytes: 5996
INFTY = (1<<30)
$h = 0
$a = []

def maxHeapify(i)
	l = 2 * i
	r = 2 * i + 1
	
	if l <= $h && $a[l] > $a[i]
		largest = l
	else
		largest = i
	end
	largest = r if r <= $h && $a[r] > $a[largest]

	if largest != i
		$a[i], $a[largest] = $a[largest], $a[i]
		maxHeapify(largest)
	end
end

def extract()
	return -INFTY if $h < 1
	maxv = $a[1]
	$a[1] = $a[$h]
	$h -= 1
	maxHeapify(1)
	return maxv
end

def increaseKey(i, key)
	return if key < $a[i]
	$a[i] = key
	while i > 1 && $a[i / 2] < $a[i]
		$a[i], $a[i / 2] = $a[i / 2], $a[i]
		i = i / 2
	end
end

def insert(key)
	$h += 1
	$a[$h] = -INFTY
	increaseKey($h, key)
end

loop do
	line = gets.split
	break if line[0] == "end"
	if line[0] == "insert"
		insert(line[1].to_i)
	else
		puts extract()
	end
end

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

using namespace std;

#define sp << " " <<
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define int long long
#define double long double
#define INF 1e18
#define PI 3.14159265359

int power(int p,int y)
{
    int res=1;
    p=p%mod;
    while(y>0)
    {
        if(y&1)
            res=(res*p)%mod;
        y=y>>1;
        p=(p*p)%mod;
    }
    return res;
}

/*
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int dice()
{
    uniform_int_distribution<int> uid(0,1);//specify l and r.
    return uid(rng) ;
}

int read()
{
       int cc = getc(stdin);
       for (;cc < '0' || cc > '9';)  cc = getc(stdin);
       int dp = 0;
       for (;cc >= '0' && cc <= '9';)
       {
          dp = dp * 10 + cc - '0';
          cc = getc(stdin);
       }
      return dp;
}

inline void print(int n)
{
  if (n == 0)
  {
    putchar('0');
    putchar('\n');
  }
  else if (n == -1)
  {
    putchar('-');
    putchar('1');
    putchar('\n');
  }
  else
  {
    char buf[20];
    buf[19] = '\n';
    int i = 18;
    while (n)
    {
      buf[i--] = n % 10 + '0';
      n /= 10;
    }
    while (buf[i] != '\n')
      putchar(buf[++i]);
  }
}

int n;

vector<vector<int>> mat_mul(vector<vector<int>> a,vector<vector<int>> b)
{
    int n=5;
	vector<vector<int>> t(n,vector<int>(n,0));
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		{
			for(int k=0;k<n;k++)
			{
				t[i][j]+=((a[i][k]*b[k][j])%mod);
				t[i][j]%=mod;
			}
		}
	}
	return t;
}

vector<vector<int>> pow_mat(vector<vector<int>> mat_a,int p)
{
	if(p==1)
        return mat_a;
	vector<vector<int>> temp=pow_mat(mat_a,p/2);
	vector<vector<int>> res=mat_mul(temp,temp);
	if(p&1)
        res=mat_mul(res,mat_a);
	return res;
}
*/

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n,k;
    cin >> n >> k;
    int a[n+1];
    for(int i=1;i<n+1;i++)
        cin >> a[i];
	map<int,int> p;
	int d[n+1]={0};
	int s=0;
	p[s]++;
	int dp=0;
	for(int i=1;i<=n;i++)
	{
		if(i>=k)
			p[d[i-k]-(i-k)]--;
		s=(s+a[i])%k;
		d[i]=s;
		dp+=p[s-i];
		dp+=p[s-i+k];
		p[s-i]++;
	}
    cout << dp;
    return 0;
}


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

# In[12]:


import collections


# In[22]:


N = int(input())
S = []
for _ in range(N):
    S.append(input())


# In[26]:


mylist = collections.Counter(sorted(S)).most_common()
cnt_tmp = mylist[0][1]
for word, cnt in mylist:
    if cnt != cnt_tmp:
        break
    print(word)
    cnt_tmp = cnt


# In[ ]:






Measured memory_bytes: 49256
// I am Varun Das from Jadavpur University
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
#define INF LLONG_MAX
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
 
int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//cout<<fixed<<setprecision(12);
int n,w;
cin>>n>>w;
vector<ll>dp(w+1,0);
loop(i,0,n){
    ll weight,val;
    cin>>weight>>val;
    for(int weight_already = w-weight; weight_already >= 0; --weight_already){
        dp[weight_already + weight] = max(dp[weight_already + weight],dp[weight_already] + val); 
    }
}
ll ans=0;
loop(i,0,w+1) ans=max(ans,dp[i]);
// cout<<endl;
// loop(i,0,w+1) cout<<dp[i]<<" ";
cout<<ans;
 
	return 0;
}	

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
using namespace std;
typedef double  dbl;
typedef long long int lld;
#define PI 3.14159265358979323
#define foi(i,n) for(i = 0; i < n; i+=1)
#define fod(i,n) for(i=n-1; i >=0; i-=1)
#define MAX std::numeric_limits<lld>::max()
#define MIN std::numeric_limits<lld>::min()
#define FastIO  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int main ()
{
	FastIO
	lld n, i;
	cin >> n;
	cout << (n*n*n);
	return 0;
}

Measured memory_bytes: 256
#include <math.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <sstream>
#include <vector>

using namespace std;
using Graph = vector<vector<int>>;

using ll = long long;
typedef pair<ll, ll> P_ll;
typedef pair<int, int> P;

const ll INF_ll = 1e17;
const int INF = 1e8;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  vector<ll> up_down(N, 0);
  vector<ll> peak_idxs;
  cin >> A[0];
  ll prev_up_down = 0;
  for (ll i = 1; i < N; i++) {
    cin >> A[i];
    if (A[i - 1] == A[i]) {
      up_down[i] = 0;
      continue;
    }
    if (A[i - 1] < A[i]) {
      up_down[i] = 1;
    } else {
      up_down[i] = -1;
    }

    if (up_down[i] * prev_up_down < 0) {
      peak_idxs.push_back((i - 1) * prev_up_down);
      prev_up_down = up_down[i];
    }
    if (prev_up_down == 0) {
      prev_up_down = up_down[i];
    }
  }
  if (up_down[N - 1] == 0 && prev_up_down > 0) {
    peak_idxs.push_back(N - 1);
  }

  // cout << endl;
  // for (ll i = 0; i < N; i++) {
  //   cout << up_down[i] << endl;
  // }
  // cout << endl;

  ll ans = 1000;
  if (peak_idxs.size() == 0) {
    if (A[0] < A[N - 1]) {
      ll stock_num = 1000 / A[0];
      ans = (A[N - 1] - A[0]) * stock_num + 1000;
    }
    cout << ans << endl;
    return 0;
  }
  ll buy_v;

  if (peak_idxs[0] > 0) {
    buy_v = A[0];
  } else {
    buy_v = A[abs(peak_idxs[0])];
    peak_idxs.erase(peak_idxs.begin());
  }

  if (peak_idxs.size() % 2 == 0) {
    if (A[abs(peak_idxs[peak_idxs.size() - 1])] < A[N - 1]) {
      peak_idxs.push_back(N - 1);
    } else {
      peak_idxs.pop_back();
    }
  }

  // for (ll i = 0; i < peak_idxs.size(); i++) {
  //   cout << peak_idxs[i] << endl;
  // }
  ll c = 1000;
  ll stock_num = c / buy_v;
  c = c - stock_num * buy_v;
  for (ll i = 0; i < (ll)peak_idxs.size(); i++) {
    if (peak_idxs[i] < 0) {
      buy_v = A[abs(peak_idxs[i])];
      stock_num = c / buy_v;
      c = c - stock_num * buy_v;
      // cout << buy_v << "," << stock_num << "," << c << endl;
      continue;
    }
    c = c + stock_num * A[peak_idxs[i]];
  }
  cout << c << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define M 1000000007
#define pb push_back
#define ll long long int
using namespace std;

int main()
{
	string s,t;
	cin>>s>>t;
	int n = s.length(), m = t.length();
	int dp[n+1][m+1];
	int choice[n+1][m+1];
	int i,j;
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=m;j++)
		{
			if(i==0 || j==0)
			{
				dp[i][j] = 0;
				choice[i][j]=0;
				continue;
			}
			if(s[i-1]==t[j-1])
			{
				dp[i][j] = 1+dp[i-1][j-1];
				choice[i][j] = 3;
			}
			else
			{
				dp[i][j] = max(dp[i][j-1],dp[i-1][j]);
				if(dp[i][j] == dp[i-1][j])
					choice[i][j] = 1;
				else
					choice[i][j] = 2;
			}
		}
	}
	i = n,j = m;
	string ans;
	while(i!=0 && j!=0)
	{
		if(choice[i][j]==3)
		{
			ans.push_back(s[i-1]);
			i--;j--;
		}
		else if(choice[i][j]==1)
			i--;
		else
			j--;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans;
	return 0;

}


Measured memory_bytes: 73960
//B - Collecting Balls (Easy Version):
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, k, ans = 0, meio;
    cin >> n >> k;
    vector<int> balls(n);
    loop(i, 0, n) cin >> balls[i];
    sort(all(balls));
    meio = k/2;
    loop(i, 0, n) {
        if(balls[i] <= meio) ans += balls[i]*2;
        else ans += (k - balls[i]) * 2;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w, k;
    cin >> h >> w >> k;
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    vector<vector<int>> d(h + 2, vector<int>(w + 2, 1e9));
    for (int i = 0; i < w + 2; i++) {
        d[0][i] = d[h + 1][i] = 0;
    }
    for (int i = 1; i <= h; i++) {
        string s;
        cin >> s;
        d[i][0] = d[i][w + 1] = 0;
        for (int j = 0; j < w; j++) {
            if (s[j] == '@') {
                d[i][j + 1] = 0;
            }
        }
    }
    d[sx][sy] = 0;
    queue<pair<int, int>> que;
    que.emplace(sx, sy);
    vector<int> dx = {1, -1, 0, 0}, dy = {0, 0, 1, -1};
    vector<vector<bool>> was(h + 2, vector<bool>(w + 2));
    was[sx][sy] = true;
    while (!que.empty()) {
        int x, y;
        tie(x, y) = que.front();
        que.pop();
        for (int kk = 0; kk < 4; kk++) {
            int i = x, j = y;
            for (int l = 0; l < k; l++) {
                i += dx[kk], j += dy[kk];
                if (d[i][j] <= d[x][y]) {
                    break;
                }
                if (was[i][j]) {
                    continue;
                }
                was[i][j] = true;
                d[i][j] = d[x][y] + 1;
                if (i == tx && j == ty) {
                    cout << d[i][j] << '\n';
                    return 0;
                }
                que.emplace(i, j);
            }
        }
    }
    cout << -1 << '\n';
    return 0;
}


Measured memory_bytes: 18756
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	vll X;
	for(int i=0;i<N;i++){
		ll x;
		cin>>x;
		X.pb(x);
	}
	int L;
	cin>>L;
	//DP[i][j]=i番目のホテルから2^j日以内に到達可能な一番右のホテル番号
	int DP[SIZE][35]={};
	//各ホテルから1日で到達できる一番右のホテル番号を計算する
	for(int i=0;i<N;i++){
		//二分探索する
		int OK=i,NG=N;
		while(NG-OK>1){
			int MID=(OK+NG)/2;
			if(X[MID]-X[i]<=L)
				OK=MID;
			else
				NG=MID;
		}
		DP[i][0]=OK;
	}
	//DPテーブルを埋める
	for(int j=1;j<33;j++){
		for(int i=0;i<N;i++){
			DP[i][j]=DP[DP[i][j-1]][j-1];
		}
	}
	int Q;
	cin>>Q;
	for(int i=0;i<Q;i++){
		int a,b;
		cin>>a>>b;
		a--,b--;
		if(a>b)
			swap(a,b);
		//aからbにたどり着くための最小の日数を二分探索する
		int NG=0,OK=SIZE;
		while(OK-NG>1){
			int MID=(OK+NG)/2;
			//MID日でいける一番右のホテル
			int now=a;
			for(int j=0;j<32;j++){
				if(MID&(1<<j))
					now=DP[now][j];
			}
			if(b<=now)
				OK=MID;
			else
				NG=MID;
		}
		cout<<OK<<endl;
	}
	return 0;
}

Measured memory_bytes: 15476
import math
from collections import defaultdict
ml=lambda:map(int,input().split())
ll=lambda:list(map(int,input().split()))
ii=lambda:int(input())
ip=lambda:(input())

"""========main code==============="""
def fast(a,b):
    res=1
    while(b>0):
        if(b&1):
            res*=a
        a*=a    
        b>>=1
    return res
x=ii()
f=0
for i in range(-2001,2001):
    k=fast(i,5)
    for j in range(i,2001):
        p=fast(j,5)
        #print(k,p,i,j,p-k)
        if((p-k)==x):
            print(j,i)
            f=1
            break
        elif(k-p==x):
            print(i,j)
            f=1
            break
    if f:
        break


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

vector<int> b;
map<int, int> mp;

int main() {
#ifdef HOME
	freopen("atc.in", "r", stdin);
	freopen("atc.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n, m, t;

	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> t;
		mp[t]+= 1; }

	cin >> m;
	for (int i = 0; i < m; ++i) {
		cin >> t;

		int &x = mp[t];
		if (--x < 0) {
			cout << "NO" << endl;	
			return 0; } }
		
	cout << "YES" << endl;

	return 0; }


Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define brep(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<n;i++)
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
#define MOD 1e9+7

int main(void){
    int n;
    cin >> n;
    int ct1[100001];
    int ct2[100001];
    int max11 = 0;
    int max12 = 0;
    int max21 = 0;
    int max22 = 0;
    rep(i,100001){
        ct1[i]=0;
        ct2[i]=0;
    }
    rep(i,n){
        int a;
        cin >> a;
        if(i%2==0){
            ct1[a]++;
            if(a==max11)continue;
            if(ct1[a] >= ct1[max11]){
                max12 = max11;
                max11 = a;
            }
            else if(ct1[a] > ct1[max12])max12 = a;
        }
        else{
            ct2[a]++;
            if(a==max21)continue;
            if(ct2[a] >= ct2[max21]){
                max22 = max21;
                max21 = a;
            }
            else if(ct2[a] > ct2[max22])max22 = a;
        }
    }
    int ans;
    if(max11 == max21){
        int a =ct1[max12]+ct2[max21];
        int b =ct2[max22]+ct1[max11];
        if(a<=b)ans = n-b;
        else ans = n-a;
    }
    else ans =n-ct1[max11]-ct2[max21];
    //cout << ct1[max11]<<ct2[max21]<< endl;
    cout << ans << endl;
}

Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>

using namespace std;

int main (int argc, char * const argv[]) {
    // insert code here...
	int n;
    string a, b;
		
	cin>> n;	
	for(int i=0;i<n;i++){
		int x[81]={0}, y[81]={0}, z[81]={0};

		cin >> a;
		cin >> b;
		if(a.size()>80 || b.size()>80){
		cout << "overflow" <<endl;
		continue;
		}
		reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());
		
		for(int j=0;j<a.size();j++){
			x[j]=a[j]-'0';
		}
		for(int j=0;j<b.size();j++){
			y[j]=b[j]-'0';
		}
		
		for(int j=0;j<80;j++){
			z[j]+=x[j]+y[j];
			if(z[j]>=10){
				z[j+1]++;
				z[j]-=10;
			}
		}
		
		if(z[80]>0){
			cout << "overflow" <<endl;
		}else{
			bool flag = 0;
			for(int j=79;j>=0;j--){
				if(z[j]==0&& flag==0){
					continue;
				}else{
					flag=1;
				}
				cout<<z[j];
			}
			if(flag==0){
				cout<<0;
			}
			cout<<endl;
			
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 1208
A, B, C, D, E, F = map(int, input().split())
waters = set()
sugars = set()
for i in range(F//(A*100)+1):
    for j in range(F//(B*100)+1):
        if i!=0 or j!=0:
            if A*i*100 +B*j*100 <= F:
                waters.add(100*A*i+100*B*j)
for i in range(F//(C)+1):
    for j in range(F//(D)+1):
        if C*i +D*j <= F:
            sugars.add(C*i+D*j)

max_ratio = 0
for water in waters:
    for sugar in sugars:
        ratio =  sugar/(water+sugar)
        if water+sugar<=F and sugar<=E*(water//100):
            if ratio >= max_ratio:
                ans = (water+sugar, sugar)
                max_ratio = ratio
print(*ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll N;
  cin >> N;
  ll a[N];
  REP(i, N) { cin >> a[i]; }
  sort(a, a + N);

  ll ans1 = 0, ans2 = 0;
  ll i = N - 1;
  while (i > 0) {
    if (a[i] == a[i - 1]) {
      if (ans1 == 0) {
        ans1 = a[i];
      } else {
        ans2 = a[i];
        break;
      }
      i -= 2;
    } else {
      i--;
    }
  }
  cout << ans1 * ans2;
  return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(true){
			int n=sc.nextInt();
			if(n==0){
				break;
			}else{
				int sum=0;
				int[] s=new int[n];
				for(int i=0;i<n;i++){
					s[i]=sc.nextInt();
					sum+=s[i];
				}
				double m=(double)sum/(double)n;
				double a=0;
				for(int i=0;i<n;i++){
					a+=(s[i]-m)*(s[i]-m);
				}
				a=a/n;
				System.out.printf("%.8f\n",Math.sqrt(a));
			}
		}
	}
}

Measured memory_bytes: 32164
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include <numeric>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void printVector(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

ll gcd(ll a, ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

ll x[100000] = {};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    int N, X;
    cin >> N >> X;

    FOR(i, 0, N){
        ll val;
        cin >> val;
        x[i] = abs(val - X); 
    }

    ll answer = x[0];
    FOR(i, 1, N){
        answer = gcd(answer, x[i]);
    }

    p(answer);
    
    return 0;
}

Measured memory_bytes: 1024
a= Array.new(4){Array.new(3){Array.new(10,0)}}
n=gets.to_i
(1..n).each{|m|
  b,f,r,v=gets.split.map{|i|i.to_i-1}
  a[b][f][r]+=v+1
}
puts a.map{|i| i.map{|j| " "+j*' '}*"\n"}*"\n#{'#'*20}\n"

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  int ans=0;

  int n; cin >> n;
  vector<int> a(n); REP(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  a.push_back(0);
  int pre=0, cnt=0;
  for (int i=0; i<=n; i++) {
    if (pre!=0&&pre!=a[i]) {
      ans += cnt%2;
      cnt=0;
    }
    pre=a[i];
    cnt++;
  }

  cout << ans << endl;
}

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long int a, b, x;
    cin >> a >> b >> x;
    long long int ans;
    if (a == 0){
        ans = b / x + 1;
    }else{
        ans = (b / x) - ((a - 1) / x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace atcoderbeginnercontest160
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var b = s[2] == s[3] && s[4] == s[5];
            Console.WriteLine(b ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/
 
const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

typedef tuple<ll, ll, ll> T;

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

    ll n,a,b,c,d,e; cin >> n >> a >> b >> c >> d >> e;

    a = min(a, b);
    c = min(c, d);
    ll minv = min(a, min(c, e));

    cout << (n+minv-1)/minv + 4 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
int main(){
    ll N, M;
    cin >> N >> M;
    if(N > M / 2){
        cout << M / 2 << endl;
    }
    else if(N < M / 2){
        cout << N + (M - 2* N) / 4 << endl;
    }
    else{
        cout << N << endl;
    }
    return 0;
}

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

int main() {
  string str;
  cin >> str;
  if ((str[0] == str[1]) && (str[1] == str[2])) {
  cout << "Yes" << endl;
  }
  else if ((str[1] == str[2]) && (str[2] == str[3])) {
  cout << "Yes" << endl;
  }
  else {
  cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int a = sc.nextInt();
    int b = sc.nextInt();
    
    os.println(1 + 2 + 3 - a - b);
  }
}

Measured memory_bytes: 21844
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	d := make([]int, n)
	for i := range d {
		sc.Scan()
		d[i], _ = strconv.Atoi(sc.Text())
	}

	if len(d)%2 == 1 {
		fmt.Println(0)
		return
	}

	sort.Ints(d)

	mid1 := d[len(d)/2-1]
	mid2 := d[len(d)/2]

	if mid1 == mid2 {
		fmt.Println(0)
	} else {
		fmt.Println(mid2 - mid1)
	}
}


Measured memory_bytes: 2048
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define ll long long
#define inf (1ll<<60)
#define N 200005
#define mod 1000000007
#define rep(i,j,k) for (ll i=j;i<=k;++i)
#define per(i,j,k) for (ll i=j;i>=k;--i)
using namespace std;
inline ll read(){
	char ch=getchar(); ll x=0,f=1;
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}
ll n,l,r,now,a[N],b[N];
int main(){
	n=read();
	rep(i,1,n) a[i]=read();
	l=1; r=n; now=1;
	per(i,n,1)
		if (now){
			b[l]=a[i];
			++l; now^=1;
		}else{
			b[r]=a[i];
			--r; now^=1;
		}
	rep(i,1,n) printf("%lld ",b[i]);
}

Measured memory_bytes: 5248
def discard(c, cards):
    for card in cards:
        if c < card:
            return card
    return 0

while True:
    n = int(input())
    if n == 0: 
        break
    taro = [int(input()) for _ in range(n)]
    hanako = [x + 1 for x in range(2*n) if (x + 1) not in taro]
    taro.sort()
    hanako.sort()

    table = 0
    while True:
        if taro:
            table = discard(table, taro)
            if table:
                taro.remove(table)
            
        if not taro:
            print(len(hanako))
            print(0)
            break
        
        if hanako:
            table = discard(table, hanako)
            if table:
                hanako.remove(table)
        if not hanako:
            print(0)
            print(len(taro))
            break

Measured memory_bytes: 6724
#include<iostream>
#include<string>
#include<vector>
#define B 'B'
#define W 'W'
#define DOT '.'
#define NG '1'

using namespace std;

void Search1(vector<string>&, int, int, int, int, int&, char&);
void Search2(vector<string>&, int, int, int, int, int&, char&);

int main(){
  int i, j, w, h, count, black, white, k;
  char c;
  string s;
  vector<string> data;

  while(1){
    cin >> w >> h;
    if(w == 0 && h == 0) break;

    for(i=0; i<h; ++i){
      cin >> s;
      data.push_back(s);
    }
    for(i=0, black=0, white=0; i<h; ++i){
      for(j=0; j<w; ++j){
	if(data[i][j] == DOT){
	  count = 0;
	  c = DOT;
	  Search1(data, i, j, h, w, count, c);
	  if(c == B) black += count;
	  else if(c == W) white += count;
	}
      }
    }

    cout << black << " " << white << endl;
    data.clear();
  }
  return 0;
}

void Search1(vector<string>& data, int i, int j, int h, int w, int& count, char& c){
  data[i][j] = NG;
  ++count;
  Search2(data, i-1, j, h, w, count, c);
  Search2(data, i+1, j, h, w, count, c);
  Search2(data, i, j-1, h, w, count, c);
  Search2(data, i, j+1, h, w, count, c);
}

void Search2(vector<string>& data, int i, int j, int h, int w, int& count, char& c){
  if(i > -1 && i < h && j > -1 && j < w){
    if(data[i][j] == DOT){
      Search1(data, i, j, h, w, count, c);
    }else if(data[i][j] == B || data[i][j] == W){
      if(c == DOT) c = data[i][j];
      else if(c != data[i][j]) c = NG;
    }
  }
}

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


int main()
{
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int main(){

	int R,G;
	scanf("%d %d",&R,&G);

	printf("%d\n",2*G-R);

	return 0;
}


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

int main(){
    int board[3][3];
    int n;
    int mark[10];

    for (int i = 0; i < 3; i++){
        for (int j = 0; j < 3; j++){
            cin >> board[i][j];   
        }
        
    }

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

    
    for (int i = 0; i < n; i++){
        for (int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(mark[i]==board[j][k]){
                    board[j][k]= -1;
                }
            }   
        }
        
    }

    bool ans = false;
    
    for (int i = 0; i < 3; i++){
        if(board[i][0]==-1 && board[i][1]==-1 && board[i][2]==-1){
            ans = true;
        }
    }
    for (int i = 0; i < 3; i++){
        if(board[0][i]==-1 && board[1][i]==-1 && board[2][i]==-1){
            ans = true;
        }
    }
    if(board[0][0]==-1 && board[1][1]==-1 && board[2][2]==-1){
        ans = true;
    }
    if(board[0][2]==-1 && board[1][1]==-1 && board[2][0]==-1){
        ans = true;
    }

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

    
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int I=X;I<Y;I++)
#define INF 1e9+7
using namespace std;

int main(){
  int N,ans=0;
  cin >> N;
  vector<int> a(N);
  FOR(i,0,N)cin >> a[i];
  bool flag = 1;
  while(flag){
    flag = 0;
    FOR(i,1,N){
      if(a[i] == a[i-1]){
        a[i] = 101+i;
        ans++;
        flag = 1;
      }
    }
  }
  cout << ans << endl;
}


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

int main()
{
    int N, L;
    cin >> N >> L;
    ll sum = 0;
    int big = -13245;
    vector<int> A(N);
    int ans = 2345678;
    for (int i = 0; i < N; i++)
    {
        A[i] = i + L;
        sum += A[i];
        ans = min(ans, abs(A[i]));
        big = max(big,abs(A[i]));
    }
    if(A[N-1] < 0){
        cout << sum + ans << endl;
    }
    else{
        cout << sum - ans << endl;
    }
}


Measured memory_bytes: 256
MOD = int(1e9+7)

N = int(input())

# all posible list
Na = pow(10, N, MOD)

# number of list without 0
N0 = pow(9, N, MOD)

# number of list without both 0 and 9
N09 = pow(8, N, MOD)

M = Na - 2*N0 + N09

print(M%MOD)



Measured memory_bytes: 9148