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

struct BIT{
  
  int n;
  int bit[300000];
  
  void init(int num){
    int two=1;
    while(two < num) two *= 2;
    n = two;
    fill(bit,bit+300000,0);
  }
  
  void add(int a,int w){
    for(int i=a;i<=n;i+=i&-i){
      bit[i] += w;
    }
  }
  
  int sum(int a){
    int ret = 0;
    for(int i=a;i>0;i-=i&-i){
      ret += bit[i];
    }
    return ret;
  }

};

typedef pair<long long,int> PA;
int s[100010],a[100010];
long long b[100010],po[100010]={};
vector<PA> vec;

int main(){
  
  int n,c;
  BIT bit;
  
  cin >> n >> c;
  for(int i=0;i<c;i++){
    cin >> s[i];
    if(s[i] == 0){
      cin >> a[i] >> b[i];
      po[a[i]] += b[i];
      vec.push_back(PA(po[a[i]],-a[i]));
    }
    if(s[i] == 1){
      cin >> a[i];
    }
  }
  
  bit.init(n+c);
  for(int i=1;i<=n;i++){
    po[i] = 0;
    vec.push_back(PA(0,-i));
    bit.add(i,1);
  }
  
  sort(vec.begin(),vec.end());
  
  int t,l,r,mid;
  
  for(int i=0;i<c;i++){
    
    if(s[i] == 0){
      t = lower_bound(vec.begin(),vec.end(),PA(po[a[i]],-a[i]))-vec.begin();
      bit.add(t+1,-1);
      po[a[i]] += b[i];
      t = lower_bound(vec.begin(),vec.end(),PA(po[a[i]],-a[i]))-vec.begin();
      bit.add(t+1,1);
    }
    
    if(s[i] == 1){
      l = 0;
      r = vec.size()-1;
      while(l < r){
	mid = (l+r)/2;
	if( bit.sum(mid+1) < n-a[i]+1){
	  l = mid+1;
	} else if(mid>0 && bit.sum(mid+1) == bit.sum(mid)){
	  r = mid-1;
	} else {
	  r = mid;
	}
      }
      cout << -vec[r].second << " " << vec[r].first << endl;
    }
    
  }
  return(0);
}



Measured memory_bytes: 10552
from collections import deque

def main():
  H,W,K=map(int,input().split())
  x1,y1,x2,y2 = map(lambda x: int(x)-1,input().split())
  S=[list(input()) for _ in range(H)]
  INF = 10**20

  def bfs(x0,y0,x_goal,y_goal):
    seen = [[0 for i in range(W)] for j in range(H)]
    d = [[INF for i in range(W)] for j in range(H)]
    d[x0][y0] = 0
    todo = deque()
    seen[x0][y0] = 1
    todo.append((x0,y0))
    while todo:
      x0,y0 = todo.popleft()
      dx,dy = (1,-1,0,0),(0,0,1,-1)
      for i in range(4):
        for k in range(K):
          x,y = x0+dx[i]*(k+1), y0+dy[i]*(k+1)
          if x<0 or x>=H:break
          if y<0 or y>=W:break
          if d[x][y] < d[x0][y0] + 1: break
          if S[x][y]=='@':break
          if seen[x][y]: continue
          seen[x][y] = 1
          todo.append((x,y))
          d[x][y] = d[x0][y0] + 1
          if x==x_goal and y == y_goal: return d[x][y]
    return d[x_goal][y_goal]

  ans = bfs(x1,y1,x2,y2)
  print(ans if ans < INF else -1)
  
if __name__ == "__main__":
  main()

Measured memory_bytes: 224956
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int sum1 = vec.at(0);
  int sum2 = vec.at(1);
    
    for (int i = 2; i < N; i+= 2) {
    sum1 += vec.at(i);
      }
    for (int i = 3; i < N; i+= 2) {
    sum2 += vec.at(i);
  }

  cout << sum1 - sum2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;



int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n,t;
    cin>>n>>t;
    vector<ll> v;
    for(ll i=0;i<n;i++){
        ll k;
        cin>>k;
        v.pb(k);
    }
    vector<ll> profit;
    ll bigcount=v[n-1];
    for(ll i=n-2;i>=0;i--){
        if(v[i]>bigcount){
            bigcount=v[i];
        }
        else if(bigcount>v[i]){
            profit.pb(bigcount-v[i]);
        }
    }
    ll ans=1;
    sort(profit.begin(),profit.end());
    for(ll i=profit.size()-2;i>=0;i--){
        if(profit[i]!=profit[i+1]){
            break;
        }
        else{
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2548
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner (System.in)){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int[][] A = new int[n][m];
			int[] b = new int[m];
			int[] c = new int[n];

			// Aを読み取る
			for (int i=0; i < n; i++) {
				for (int j=0; j < m; j++) {
					A[i][j] = sc.nextInt();
				}
			}

			// bを読み取る
			for (int i=0; i < m; i++) {
					b[i] = sc.nextInt();
			}

			// cを計算する
			for (int i=0; i < n; i++) {
					c[i] = 0;
					for (int j=0; j < m; j++) {
						c[i] += A[i][j]*b[j];
					}
			}
			for (int i=0; i < n; i++) {
				System.out.println(c[i]);
			}
		}
	}
}



Measured memory_bytes: 40828
// #pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vll = vector<ll>;
using vii = vector<int>;
using pii = pair<int, int>;
template <typename T = vii> 
using vec = vector<T>;

const ll INF = 1e18, MOD = 1e9 + 7;

const int MAX = 1e6;

int main() {
    cin.tie(NULL);
    ios_base::sync_with_stdio(false);
    // freopen("in.in", "r", stdin);

    int n;
    cin >> n;
    vii v(n);
    for (int &e : v) {
        cin >> e;
    }   
    sort(v.begin(), v.end());
    pair<double, int> res(INF, INF); 
    for (int i = 0; i < n; i++) {
        res = min(res, {abs(double(v.back()) / 2 - v[i]), i});
    }
    cout << v.back() << ' ' << v[res.second] << '\n';
}

Measured memory_bytes: 640
import collections
n = int(input())
s = [input() for i in range(n)]
s = collections.Counter(s)
m = 0
ans = []

for i in s.values():
  m = max(m,i)

for k, j in s.items():
  if j == m:
    ans.append(k)
ans.sort()

for i in range(len(ans)):
  print(ans[i])
#print(*ans, sep = "\n")


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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int cnt = 1, mx = 1;
  for(int i = 1; i < n; i++) {
    if(s[i-1] == s[i]) {
      cnt++;
      mx = max(mx, cnt);
    } else {
      cnt = 1;
    }
  }
  if(mx >= 3) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <ios> 
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
//const int MAX=;
//const int MOD=1e9+7;

int lp2(int a){
	int b=log2(a);
	int c=pow(2,b+1);
	return c;
}

int main(){
	int N;
	cin>>N;
	multiset<int> s={};
	rep(i,N){
		int x;
		cin>>x;
		s.insert(x);
	}
	int ans=0;
	while(!s.empty()){
     	multiset<int>::iterator ite0;
      	ite0=s.end();
      --ite0;
		int k=*ite0;
		s.erase(ite0);
     	if(s.empty()) break;
		int l=lp2(k)-k;
		multiset<int>::iterator ite;
		ite=s.find(l);
		if(ite != s.end()){
			ans++;
			s.erase(ite);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
char c[100010];
int main(){
	int n,k;
	cin>>n>>k;
	int r,s,p;
	cin>>r>>s>>p;
	string t;
	cin>>t;
	int ans=0;
	for(int i=0;i<t.size();i++){
		if(i<k){
			if(t[i]=='r')ans+=p,c[i]='p';
			if(t[i]=='p')ans+=s,c[i]='s';
			if(t[i]=='s')ans+=r,c[i]='r';
		}
		else if(c[i-k]!=t[i]&&t[i]==t[i-k]){
			c[i]=t[i];
		}
		else{
			if(t[i]=='r')ans+=p,c[i]='p';
			if(t[i]=='p')ans+=s,c[i]='s';
			if(t[i]=='s')ans+=r,c[i]='r';
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
/*input
4 6 3
2 3 4
1 2 4
2 3 3
4 3 1
1 4 1
4 2 2
3 1 6
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define YY cout<<"YES\n"
#define NN cout<<"NO\n"
#define yy cout<<"Yes\n"
#define nn cout<<"No\n"
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=205;
const ll maxlg=__lg(maxn)+2;
const ll INF64=1000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

ll dis[maxn][maxn];
int a[maxn];

int main()
{
	IOS;
	REP(i,maxn) REP(j,maxn){
		if(i==j) dis[i][j]=0;
		else dis[i][j]=INF64;
	}
	int n,m,r;
	cin>>n>>m>>r;
	REP(i,r) cin>>a[i];
	REP(i,r) a[i]--;

	REP(i,m){
		int A,B,C;
		cin>>A>>B>>C;
		A--;B--;
		dis[A][B]=dis[B][A]=C;
	}
	REP(j,n) REP(i,n) REP(k,n){
		dis[i][k]=min(dis[i][k],dis[i][j]+dis[j][k]);
	}
	sort(a,a+r);
	ll ans=INF64;
	do{
		ll cur=0;
		REP(i,r-1){
			cur+=dis[a[i]][a[i+1]];
		}
		ans=min(ans,cur);
	}while(next_permutation(a,a+r));
	cout<<ans<<'\n';
	return 0;
}


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

#define MAX 2000000
#define INFTY (1<<30)

int H, A[MAX];

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

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

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

void maxHeapify(int i){
    int l = left(i);
    int r = right(i);
    //左の子，自分，右の子で値が最大のノードを選ぶ
    int largest;
    if(l <= H && A[l] > A[i]){
        largest = l;
    }else{
        largest = i;
    }

    if(r <= H && A[r] > A[largest]){
        largest = r;
    }

    if(largest != i){
        swap(A[i],A[largest]);
        maxHeapify(largest);
    }
}

int extract(){
    int maxv;
    maxv = A[1];
    A[1] = A[H--];
    maxHeapify(1);
    return maxv;
}

void increase(int i, int key){
    if(key < A[i]) return;
    A[i] = key;
    while(i > 1 && A[i / 2] < A[i]){
        swap(A[i], A[i / 2]);
        i = i / 2;
    }
}

void insert(int key){
    H++;
    A[H] = -INFTY;
    increase(H, key);
}

int main(){
    int key;
    char com[10];

    while(1){
        scanf("%s", com);
        if(com[0] == 'e' && com[1] == 'n') break;
        if(com[0] == 'i'){
            scanf("%d", &key);
            insert(key);
        }else{
            printf("%d\n", extract());
        }
    }

    return 0;
}


Measured memory_bytes: 7104
var
  n, i, j, k, l, min, count, temp: Integer;
  values: array [1 .. 100] of Integer;

begin
  readln(n);
  count := 0;
  min := 101;
  temp := 0;

  for i := 1 to n do
  begin
    readln(values[i]);
  end;

  for k := 1 to n do
  begin
    for l := 1+j to n do
    begin
      if (values[k] > values[l]) then
      begin
        temp := values[k];
        values[k] := values[l];
        values[l] := temp;
      end;
    end;
  end;

  for j := 1 to n do
  begin
    if (min > values[j]) then
    begin
      min := values[j];
      inc(count);
    end;
  end;

  writeln(count);

end.

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a > b){
		printf("a > b\n");
	}else if(b > a){
		printf("a < b\n");
	}else{
		printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
import sys
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n,c = na()
migi = []
sushi_m = []

for i in range(n):
  x,v = na()
  migi.append(x)
  sushi_m.append(v)

sushi_h = list(reversed(sushi_m))
hidari = [c-i for i in reversed(migi)]

m = 0
mm = 0
h = 0
hh = 0
mmigi = []
hhidari = []

for i in range(n):
  m += sushi_m[i]
  h += sushi_h[i]
  mm = max(mm,m-migi[i])
  mmigi.append(mm)
  hh = max(hh,h-hidari[i])
  hhidari.append(hh)

ans = 0
for i in range(n):#migi
  if n-i-2 >= 0 and hhidari[n-i-2]-migi[i] > 0:
    ans = max(ans, mmigi[i]+hhidari[n-i-2]-migi[i])
  else:
    ans = max(ans, mmigi[i])
    
for i in range(n):#hidari
  if n-i-2 >= 0 and mmigi[n-i-2]-hidari[i] > 0:
    ans = max(ans, hhidari[i]+mmigi[n-i-2]-hidari[i])
  else:
    ans = max(ans, hhidari[i])

print(ans)
    

Measured memory_bytes: 23736
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int d[3];
	fill(d, d + 3, 0);
	for (int i = 0; i < s.size(); i++)d[s[i] - 'a']++;
	sort(d, d + 3);
	if (d[2] - d[0] <= 1)printf("YES\n");
	else printf("NO\n");
}

Measured memory_bytes: 512
from fractions import gcd
import math

mod = 998244353

def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft

def S(x1, y1, x2, y2, x3, y3):
    return heron(math.sqrt((x1 - x2)**2 + (y1 - y2)**2), math.sqrt((x1 - x3)**2 + (y1 - y3)**2), math.sqrt((x3 - x2)**2 + (y3 - y2)**2))

def heron(a, b, c):
    try:
        d = (a + b + c) / 2
        return round(math.sqrt(d * (d - a) * (d - b) * (d - c)) * 2)
    except Exception as e:
        return 0

def main():
    n = int(input())
    h = list(map(int, input().split()))
    h = h[::-1]
    for i in range(n-1):
        if h[i] < h[i+1]:
            h[i+1] -= 1
        if h[i] < h[i+1]:
            print('No')
            return

    print('Yes')

main()


Measured memory_bytes: 16236
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int a[6],num[5]={0};
    for(int i=0;i<6;i++) cin>>a[i];
    for(int i=0;i<6;i++) num[a[i]]++;
    int x=0;
    for(int i=1;i<=4;i++){
        if(num[i]>=3) x=1;
    }
    if(x==0) cout<<"YES";
    else cout<<"NO";
}

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

int main(){
	char ch[16];
	int am,pm;
	while(cin >> ch >> am >> pm){
		cout << ch << " " << (am+pm) << " " << (am*200+pm*300) << endl;
		for(int i=0;i<16;i++){
			ch[i] = '\0';
		}
	}
	return 0;
}

Measured memory_bytes: 0
s = list(input())
memo = {}
for i in s:
    if i in memo:
        memo[i] += 1
    else:
        memo[i] = 1
flag = True
for key,val in memo.items():
    if val != 2:
        flag=False
        break
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61880
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

int main() 
{
	int N;
	cin >> N;
	long long  ans = 0;
	vector<int> data(N);
	for (int i = 0; i < N; i++)
	{
		cin >> data[i];
		ans += data[i];
	}

	long long J = round(double(ans) / N);

	int answer = 0;
	for (int i = 0; i < N; i++)
	{
		answer += (data[i] - J) * (data[i] - J);
	}

	cout << answer << endl;
	return 0;
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long int
main()
{
	int n;
	cin>>n;
	int cou=0;
	int d;
	cin>>d;
	while(n--)
	{
		int x,y;
		cin>>x>>y;
		if(d>=sqrt(x*x+y*y))
		{
			cou++;
		}
	}
	cout<<cou<<endl;
}

Measured memory_bytes: 3660
import collections
n,rev = int(raw_input()) ,False
class Node(object):
	def __init__(self, val):
		self.val = val
		self.next, self.prev = None, None

for i,ai in enumerate(map(int, raw_input().split())):
	node = Node(ai)		
	if i  == 0:
		head,tail = node,node
	else:
		if rev:
			head.prev, node.next = node, head
			head = node
		else:
			tail.next, node.prev = node, tail
			tail = node
		rev ^=  True

cur = head if not(rev) else tail  
while(cur):
	print cur.val, 
	cur = cur.next if not(rev) else cur.prev


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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n,m;cin >> n>>m;
    cout << n*m << "\n";
    return 0;
}

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

int main(){
  int N,Y;
  cin >> N >> Y;
  
  int res10000 = -1, res5000 = -1, res1000 = -1;
  for (int a = 0;a <= N;a++){
    for (int b = 0; b + a <= N;b++){
      int c =  N - a - b;
      int total = 10000*a + 5000*b + 1000*c;
      
      if(total == Y){
        res10000 = a;
        res5000 = b;
        res1000 = c;
      }
    }
  }
  cout << res10000 << " " <<  res5000 << " " << res1000 << endl;
  
}
        
    

Measured memory_bytes: 256
/****************
 *		*
 * ALDS_1_4_D   *
 * Allocation   *
 *              *
 * 2019/08/18   *
 ***************/

#include<iostream>

#define MAX_N 100000

using namespace std;

int weight[MAX_N] = {0};
long long num_weight=0;
long long num_track=0;

long long check(long long P){
  long long i=0;
  long long sum=0;
  for(long long j=0;j<num_track;j++){
    sum = 0;
    while(sum + weight[i] <= P){
      sum += weight[i];
      i++;
      if(i == num_weight) return num_weight;
    }
  }

  return i;
}
long long calc(){
  
  long long ans=0;
  long long left=0;
  long long right = 100000 * 10000;
  long long mid = 0;
  while((left + 1) < right){
    mid = (left + right)/2;
    ans = check(mid);
    if(ans >= num_weight) right=mid;
    else left=mid;
  }
  
  return right;
}

int main(void){

  long long P=0;
  cin >> num_weight >> num_track;
  for(long long i=0;i<num_weight;i++) cin >> weight[i];

  P = calc();

  cout << P << endl;
  
  return 0;
}



Measured memory_bytes: 3500
#include <iostream>
using namespace std;
using ll = long long;

ll sum(ll l, ll r){
    return (l+r)*(r-l+1)/2;
}
int main()
{
    int n, k;
    cin >> n >> k;
    long long int ans = 0;

    for(int i=k; i<=n+1; ++i){
        ll l = sum(0, i-1), r = sum(n-i+1, n);
        ans += r - l + 1;
        }


    cout << ans % 1000000007 << endl;

    return 0;
}

Measured memory_bytes: 3220
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	a := make([]int, len(s))
	for i := range s {
		a[i] = int(s[i])
	}

	var count int
	for i := 0; i < len(a)-1; i++ {
		if a[i] == a[i+1] {
			count++
			if a[i+1] == 48 {
				a[i+1] = 49
			} else {
				a[i+1] = 48
			}
		}
	}
	fmt.Println(count)
}


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

int main(){
	while(1){
		int x, y;
		cin >> x >> y;
		if(x==0 && y==0) break;
		
		if(x>y){
			int tmp = x;
			x = y;
			y = tmp;
		}
		cout << x << " " << y <<endl;
	}
}

Measured memory_bytes: 1156
tmp = [int(x) for x in raw_input().split(' ')]
N = tmp[0]
X = tmp[1]

if(X > 0.5 * N):
	X = N-X

totaldist = N
step = X
dist = N-X

while(1):
	totaldist += (dist/step) * 2 * step
	distnew = step
	stepnew = dist % step
	if(stepnew == 0):
		totaldist -= step
		break
	dist = distnew
	step = stepnew

print totaldist

Measured memory_bytes: 3072
import itertools


h, w = map(int, input().split())
c = [list(map(ord, input())) for i in range(h)]
c = list(itertools.chain.from_iterable(c))
INF = 10 ** 9
h2 = (h + 1) * (h + 1)

ans = 0
dq = [0] * h2
for wi in range(w - 1):
    for diff in range(h + 1):
        cnt1 = 0
        cnt2 = 0
        for i in range(h - diff):
            cnt1 += (c[i * w + wi] == c[(i + diff) * w + wi + 1])
            cnt2 += (c[(i + diff) * w + wi] == c[i * w + wi + 1])
        dq[diff * (h + 1)] = cnt1
        dq[diff] = cnt2
        for i in range(h - diff - 1):
            cnt1 -= (c[(h - i - 1 - diff) * w + wi] == c[(h - i - 1) * w + wi + 1])
            dq[(i + 1 + diff) * (h + 1) + i + 1] = cnt1
            cnt2 -= (c[(h - i - 1 - diff) * w + wi + 1] == c[(h - i - 1) * w + wi])
            dq[(i + 1) * (h + 1) + i + 1 + diff] = cnt2
            
    dp = [INF] * h2
    dp[0] = 0
    for i in range(h + 1):
        for j in range(h + 1):
            if i + 1 < h + 1:
                dp[(i + 1) * (h + 1) + j] = min(dp[i * (h + 1) + j] + dq[i * (h + 1) + j], dp[(i + 1) *(h + 1) + j])
            if j + 1 < h + 1:
                dp[i * (h + 1) + j + 1] = min(dp[i * (h + 1) + j] + dq[i * (h + 1) + j], dp[i * (h + 1) + j + 1])
    ans += dp[-1]

print(ans)
    

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

int base;
int tod(int b,int ka,int t,int w,int ki){
	ka+=b*20;t+=ka*20;w+=18*t;ki+=20*w;
	return base+ki;
}
bool is_uruu(int y){
	return y%4==0&&(y%100!=0||y%400==0);
}
int mn[]{31,28,31,30,31,30,31,31,30,31,30,31};
int calc(int y,int m,int d){
	int res=(y-1)*365+(y-1)/4;
	for(int i=100;i<y;i+=100){
		if(!is_uruu(i))res--;
	}
	for(int i=1;i<m;i++){
		res+=mn[i-1];if(is_uruu(y)&&i==2)res++;
	}
	return res+d;
}
int tod(int y,int m,int d){
	return calc(y,m,d)-base;
}
void tom(int day){
	int b,ka,t,w,ki;
	ki=day%20;day/=20;
	w=day%18;day/=18;
	t=day%20;day/=20;
	ka=day%20;day/=20;
	b=day%13;
	printf("%lld.%lld.%lld.%lld.%lld\n",b,ka,t,w,ki);
}
void tos(int day){
	int y,m;
	for(y=1;365+is_uruu(y)<day;y++)day-=365+is_uruu(y);
	for(m=1;mn[m-1]+(m==2&&is_uruu(y))<day;m++)day-=mn[m-1]+(m==2&&is_uruu(y));
	printf("%lld.%lld.%lld\n",y,m,day);
}
signed main() {
	base=calc(2012,12,21);
	string s;
	while(cin>>s,s!="#"){
		s+='.';
		vector<int>v;
		string t;
		for(char c:s){
			if(c=='.')v.push_back(stoi(t)),t="";
			else t+=c;
		}
		if(v.size()==3)tom(tod(v[0],v[1],v[2]));
		else tos(tod(v[0],v[1],v[2],v[3],v[4]));
	}
}

Measured memory_bytes: 3252
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((int64_t *)a) < *((int64_t *)b) ? -1 : 1;
}

int compare_f2(const void *a, const void *b) {
	return *((uint64_t *)a) > *((uint64_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
	uint64_t result = 1;

	for (uint64_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

static char S[200001];

int main(void) {
	scanf("%s", S);

	const size_t len = strlen(S);

    size_t wCount = 0;
    uint64_t sum = 0;
    for (size_t ofs = 0; ofs < len; ofs++) {
        if (S[len - ofs - 1] == 'W') {
            wCount++;
        }
        else {
            sum += (uint64_t)wCount;
        }
    }

    printf("%"PRIu64, sum);

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

ll mod = 1e9 + 7;
ll dp[1 << 21];

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


	int N;
	cin >> N;
	int A[22][22];
	rep(i, N) rep(j, N) cin >> A[i][j];

	dp[0] = 1;
	rep(i, N) {
		rep(p, 1 << N) {
			if (__builtin_popcount(p) == i) {
				rep(j, N) {
					if (A[i][j] && !(p >> j & 1)) {
						dp[p | (1 << j)] = (dp[p | (1 << j)] + dp[p]) % mod;
					}
				}
			}
		}
	}
	co(dp[(1 << N) - 1]);

	Would you please return 0;
}

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

using namespace std;


int main()
{
	int n,q,num,cnt = 0;
	vector<int> s;

	cin >> n;
	for (int i = 0; i != n; ++i)
	{
		cin >> num;
		s.push_back(num);
	} 

	sort(s.begin(), s.end());
	s.erase(unique(s.begin(), s.end()), s.end());

	cin >> q;
	for (int i = 0; i != q; ++i)
	{
		cin >> num;
		if (find(s.begin(), s.end(), num) != s.end())
		{
			++cnt;
		}
	}

	cout << cnt << endl;

	return 0;

}


Measured memory_bytes: 3164
#include <stdio.h>

int main()
{
	int N, M;
	scanf("%d%d", &N,&M);
	int a[M + 1],b[M + 1];
	int n[N + 1];
	int i = 0;
	while (i < M)
	{
		scanf("%d",&a[i]);
		scanf("%d", &b[i]);
		i++;
	}
	int j;
	i = 1;
	while (i <= N)
	{
		j = 0;
		n[i] = 0;
		while (j < M)
		{
			if (i == a[j] || i == b[j])
				n[i] += 1;
			j++;
		}
		printf("%d\n", n[i]);
		i++;
	}
	return (0);
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstring>
#include <set>
#define mes(a, b)  memset(a, b, sizeof a)
#define pb push_back
typedef unsigned long long int ull;
typedef long long int ll;
const int    maxn = 1e5 + 20;
const int    maxm = 1e5 + 10;
const ll     mod  = 1e9 + 7;
const ll     INF  = 1e18 + 100;
const int    inf  = 0x3f3f3f3f;
const double pi   = acos(-1.0);
const double eps  = 1e-8;
using namespace std;
set<int>s;
int main(){
	int x,n;cin >>x >> n;
	for(int i = -10;i <= 200;i++) s.insert(i);
	for(int i = 1;i <= n;i++) {
		int x;cin >> x;if(s.count(x)) s.erase(x);
	}
	int ans = 1000,res = 0;
	for(auto it : s) if(ans > abs(it - x)) res = it,ans = abs(it - x);
	printf("%d\n",res); 
}

Measured memory_bytes: 3812
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x;
		for (int i = 1; true; i++) {
			x = sc.nextInt();
			if (x == 0)
				break;
			System.out.printf("Case %d: %d\n", i, x);
		}
		sc.close();
	}
}



Measured memory_bytes: 65028
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#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 ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);

int main()
{
    INIT;
    string s;
    string t;
    cin >> s >> t;
    bool ans = true;
    REP(i,s.size()){
        if(s.at(i) != t.at(i)) ans = false;
    }
    if(ans && s.size() + 1 == t.size()) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    int N;
    cin >> N;
    map<string, int> mp;

    for(int i = 0; i < N; i++) {
        string s;
        cin >> s;
        mp[s]++;
    }

    cout << (int)mp.size() << endl;
    return 0;
}


Measured memory_bytes: 19104
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int N;
    cin >> N;
    vector<pair<int, int>> v;
    for(int i = 0; i < N; i++){
        int X, L;
        cin >> X >> L;
        v.push_back(make_pair(X + L,X - L));
    }
    sort(v.begin(), v.end());
    
    ll ans = 1, out = v[0].first;
    for(int i = 1; i < N; i++){
        if(out <= v[i].second){
            ans++;
            out = v[i].first;
        }
    }
    
    cout << ans << "\n";
    return 0;
}


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

long long n, t, rez;

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

  rez = n * t;

  long long cur;
  cin >> cur;

  for (int man = 2; man <= n; ++man) {
    long long newCur;
    cin >> newCur;
    rez -= max(0LL, t - (newCur - cur));
    cur = newCur;
  }

  cout << rez;

  return 0;



}


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

using namespace std;

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

    int n = s.length();

    vector<int> ans(n);
    {
        int last_r = 0;
        for (int i = 1; i < n; ++i) {
            if (s[i] == 'L') {
                ++ans[last_r + (i - last_r) % 2];
            } else if (s[i] == 'R') {
                last_r = i;
            }
        }
    }
    {
        int last_l = n - 1;
        for (int i = n - 1; i >= 0; --i) {
            if (s[i] == 'L') {
                last_l = i;
            } else if (s[i] == 'R') {
                ++ans[last_l - (last_l - i) % 2];
            }
        }
    }

    copy(ans.begin(), ans.end(), ostream_iterator<int>(cout, " "));
    cout << endl;

    return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#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 MOD 1000000007

using namespace std;

int main(void) {
	int n;
	int count = 0;

	while (cin >> n) {
		FOR(i, 0, 9) {
			FOR(t, 0, 9) {
				FOR(s, 0, 9) {
					FOR(u, 0, 9) {
						if (i + t + s + u == n) {
							count++;
						}
					}
				}
			}
		}
		cout << count << endl;
		count = 0;
	}
	
	return 0;
}

Measured memory_bytes: 3092
S = input()

a = list(map(int, S.split("/")))

if a[0] < 2019:
    ans = "Heisei"
elif a[0] == 2019 and a[1] < 4:
    ans = "Heisei"
elif a[1] == 4 and a[2] <= 30:
    ans = "Heisei"
else:
    ans = "TBD"
print(ans)

Measured memory_bytes: 3060
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let xy: Vec<(i64, i64)> = (0..n).map(|_| (read(), read())).collect();

    let par = (xy[0].0.abs() + xy[0].1.abs()) % 2;
    let mut vec: Vec<(i64, i64)> = Vec::new();
    for i in 0..n {
        let (x, y) = xy[i];
        if par != (x.abs() + y.abs()) % 2 {
            println!("{}", -1);
            return;
        }
        vec.push((x + y, x - y));
    }

    let mut d: Vec<i64> = (0..31).rev().map(|i| 1_i64 << i).collect();
    if par % 2 == 0 {
        d.push(1);
    }

    println!("{}", d.len());
    for i in 0..d.len() {
        if i != 0 {
            print!(" ");
        }
        print!("{}", d[i]);
    }
    println!();

    for i in 0..n {
        let mut xsum = 0;
        let mut ysum = 0;
        for j in 0..d.len() {
            let mut xdir = true;
            if xsum <= vec[i].0 {
                xsum += d[j];
            } else {
                xdir = false;
                xsum -= d[j];
            }

            let mut ydir = true;
            if ysum <= vec[i].1 {
                ysum += d[j];
            } else {
                ydir = false;
                ysum -= d[j];
            }

            print!("{}", 
                if xdir {
                    if ydir { "R" }
                    else { "U" }
                } else {
                    if ydir { "D" }
                    else { "L" }
                });
        }
        println!();
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int i=0;
	string s,e="keyence";
	cin>>s;
	for(int t=0;t<s.size();t++)
	{
		if(s[t]!=e[i])
		{
			s.erase(t,s.size()-7);
			break;
		}
		else
		{
			i++;
		}
	}
	if(s==e)
	{
		cout<<"YES";
	}
	else
	{
		cout<<"NO";
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  long long a[5],n;
  long long sum=0,min;
  int flag=0;
  scanf("%lld\n",&n);
  scanf("%lld\n",&a[0]);
   scanf("%lld\n",&a[1]);
   scanf("%lld\n",&a[2]);
   scanf("%lld\n",&a[3]);
   scanf("%lld\n",&a[4]);
  min=a[0];
  for(int i=1;i<5;i++){
    min=(min>a[i]) ? a[i] : min;
  }
  for(int i=0;i<5;i++){
    if(a[i]==min&&flag==0) {
      sum+=(n%a[i]) ? n/a[i]+1 : n/a[i];
      flag=1;
    } else {
      sum++;
    }
  }
  printf("%lld",sum);
  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define f first
#define s second

#define all(s) s.begin(),s.end()
#define spresent(s,v) ((s).find(v)!=s.end())
#define present(s,v) (find(all(s),v)!=s.end())

#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL)

#define fill_1d(a,val) fill(a,a+sizeof(a)/sizeof(a[0]),val)
#define fill_2d(a,val) fill(&a[0][0],&a[0][0]+sizeof(a)/sizeof(a[0][0]),val)

#define dout(i,s) cout<<"Case #"<<i<<": "<<s<<"\n"

typedef long long int ll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

typedef struct node{
	ll val,more=0,less=0;
	bool operator <(const node& a){
		return val<a.val;
	}
}node;

int main(){

	int len;
	  string s;
	  cin>>s;
	  len=s.size();
	  long long int k;
	  cin>>k;
	  ll ans=0,st=0,en=len-1;
	  if(s[0]==s[len-1]){
	    while(st<len-1 && s[st+1]==s[0])
	      ++st;
	    while(en>0 && s[en-1]==s[len-1])
	      --en;
	    if(st>=en){
	      return cout<<k*len/2,0;
	    }
	    ans=(k-1)*((st+1+(len-en))/2);
	    ans+=(st+1)/2 + (len-en)/2;
	    ++st;
	    --en;
	  }
	  while(st<en){
	    int j=st;
	    while(j<en && s[j+1]==s[st]){
	      ++j;
	    }
	    ans+=k*((j-st+1)/2);
	    st=j+1;
	  }
	  cout<<ans;
	  
	  return 0;














}

Measured memory_bytes: 384
h,w = map(int,input().split())
s = [list(input()) for i in range(h)]
vec = [-1,0,1]
for i in range(h): #H
    for j in range(w): #W
        if s[i][j] == '.':
            s[i][j] = '0'
        if s[i][j] != '#':
            for m in vec: #3
                for n in vec: #3
                    ver = i + m
                    hor = j + n
                    if 0 <= ver and ver <= h-1 and 0 <= hor and hor <= w-1 and s[ver][hor] == '#':
                        s[i][j] = str(1+int(s[i][j]))
for i in range(h):
    print(''.join(s[i]))


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<climits>

using namespace std;

static const int MAX = 100;
static const long long INFTY = (1LL<<32);

int n;
long long d[MAX][MAX];

void floyd(){
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            if(d[i][k]==INFTY) continue;
            for(int j=0;j<n;j++){
                if(d[k][j]==INFTY) continue;
                d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
}
int main(){
    int e,u,v,c;
    cin >> n >> e;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            d[i][j] = ((i==j)?0:INFTY);
        }
    }
    for(int i=0;i<e;i++){
        cin >> u >> v >> c;
        d[u][v] = c;
    }
    floyd();

    bool negative = false;
    for(int i=0;i<n;i++) if(d[i][i]<0) negative = true;
    if(negative){
        cout << "NEGATIVE CYCLE" << endl;
    }else{
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(j) cout << " ";
                if(d[i][j]==INFTY) cout << "INF";
                else cout << d[i][j];
            }
            cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
int main() {
int N; cin >> N;
vector<int> V(N);
vector<int> C(N);

for (int i = 0; i < N; i++) cin >> V[i];
for (int i = 0; i < N; i++) cin >> C[i];
 int ans = 0;
for(int i = 0; i < N; i++) {
  if (V[i] > C[i]) ans += V[i] - C[i];
}
 
cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll A[200007];

int main(){
  ll X=0;
  ll N;
  cin >> N;
  rep(i,N){
    cin >> A[i];
    X^=A[i];
  }
  rep(i,N){
    cout << (A[i]^X) << endl;
  }
}


Measured memory_bytes: 5184
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(ll x = l;x<u;x++)
#define RREP(x,l,u) for(ll x = l;x>=u;x--)
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mst(x,a) memset(x,a,sizeof(x))
#define all(a) a.begin(),a.end()
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
#define lson (ind<<1)
#define rson (ind<<1|1)
#define se second
#define fi first
#define sz(x) ((int)x.size())
#define EX0 exit(0);


typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;
typedef vector<ll> VLL;
typedef vector<int> VI;
const int block_size = 320;
typedef complex<ll> point;
const ll mod = 1e9 + 7;
const ll inf = 1e9 + 7;
const ll INF = 1e15;
const ld eps = 1e-9;
const db PI = atan(1) * 4;

template<typename T, typename S>inline bool upmin(T&a, const S&b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S>inline bool upmax(T&a, const S&b) { return a < b ? a = b, 1 : 0; }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }
ll pow(ll a, ll b) {
	if (b == 0) {
		return 1;
	}
	if (b == 1) {
		return a;
	}
	ll ans = pow(a, b / 2);
	ans *= ans;
	ans *= b % 2 == 1 ? a : 1;
	return ans;
}

#define MAXN 202
#define SOURCE 0
#define SINK 201


namespace SOLVE {
	int X, Y, E;
	int visited[MAXN] = { 0 };
	int parent[MAXN] = { 0 };
	int adjmatrix[MAXN][MAXN] = { 0 };
	
	void bfs(int v) {
		visited[v] = 1;
		REP(i, 0, MAXN) {
			if (!visited[i] && adjmatrix[v][i] > 0) {
				parent[i] = v;
				bfs(i);
			}
		}
	}


	void main() {
		int a, b, c;
		cin >> X >> Y >> E;

		REP(i, 0, X) {
			adjmatrix[SOURCE][i + 1] = 1;
		}
		REP(i, 0, Y) {
			adjmatrix[i + 101][SINK] = 1;
		}
		REP(i, 0, E) {
			cin >> a >> b;
			adjmatrix[a + 1][b + 101] = 1;

		}
		int ans = 0;

		while (1) {
			memset(visited, 0, sizeof(visited));
			memset(parent, 0, sizeof(visited));
			bfs(0);
			if (!visited[SINK]) {
				break;
			}

			int flow = 1e9;
			// go backwards, see the minimum flow
			for (int v = SINK; v != SOURCE; v = parent[v]) {
				flow = min(flow, adjmatrix[parent[v]][v]);
			}
			// go backwards and subtract the flow from all the edges. also add the flow to the reverse edge.
			for (int v = SINK; v != SOURCE; v = parent[v]) {
				adjmatrix[parent[v]][v] -= flow;
				adjmatrix[v][parent[v]] += flow;
			}
			ans += flow;
		}
		cout << ans << endl;

	
	}
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t;
	//    in(t);
	t = 1;
	while (t--) {
		SOLVE::main();

	}

	return 0;
}



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

int main(){
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    int ansa = 100 * A, ansb = 0;
    double con = 0;
    for(int i = 0 ; i < 30; i++){
        for(int j = 0; j < 30; j++){
            for(int k = 0; k < 100; k++){
                for(int l = 0; l < 100; l++){
                    //cout << i << j << k << l << endl;
                    if(100 * A * i + 100 * B * j + C * k + D * l > F) break;
                    if((A * i + B * j) * E < C * k + D * l ) break;
                    
                    int a = 100 * A * i + 100 * B * j;
                    int b = C * k + D * l;
                    double tcon = (double)b/(double)a;
                    if(con < tcon){
                        con = tcon;
                        ansa = a + b;
                        ansb = b;
                    }
                }
            }
        }
    }
    cout << ansa << " " << ansb <<endl;
}

Measured memory_bytes: 256
import java.util.*;import java.io.*;public class Main{public static void main(String[] args){Scanner sc=new Scanner(System.in);PrintWriter ou=new PrintWriter(System.out);int n=Integer.parseInt(sc.next());long[] a=new long[n];for(int i=0;i<n;i++){a[i]=Long.parseLong(sc.next());}sc.close();Arrays.sort(a);int lef=0;int rig=n;while(rig-lef>1){int che=(lef+rig)/2;boolean nowh=true;long hp=0;for(int i=0;i<=che;i++){hp+=a[i];}for(int i=che+1;i<n&&nowh;i++){if(hp*2<a[i])nowh=false;else hp+=a[i];}if(nowh)rig=che;else lef=che;}int yono=n-rig-1;for(int che=rig;che>=rig-1;che--){boolean nowh=true;long hp=0;for(int i=0;i<=che;i++){hp+=a[i];}for(int i=che+1;i<n&&nowh;i++){if(hp*2<a[i]) nowh=false;else hp+=a[i];}if(nowh)yono++;}ou.print(yono+"\n");ou.flush();}}

Measured memory_bytes: 61156
# coding: utf-8
# Your code here!
li = list(map(int,raw_input().split()))
count = 0
while True:
    if li[0]==li[1] and li[1]==li[2]:
        break
    else:
        count += 1
        li.sort()
        if li[0] == li[1]:
            li[0]+=1
            li[1]+=1
        else:
            li[0]+=2
print count 


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

int n;
int dp[100010][3];
signed main() {
	cin >> n;
	rep(i, n) {
		int a, b, c;
		cin >> a >> b >> c;
		dp[i + 1][0] = max(dp[i][1], dp[i][2]) + a;
		dp[i + 1][1] = max(dp[i][0], dp[i][2]) + b;
		dp[i + 1][2] = max(dp[i][0], dp[i][1]) + c;
	}
	cout << max({ dp[n][0],dp[n][1],dp[n][2] }) << endl;
}

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

void output(vector<int> res){
    for(int i=0;i<res.size();i++){
        if(res[i]==0) break;
        cout<<res[i];
        if(i+1!=res.size() && res[i+1]!=0) cout<<" ";
    }
    cout<<endl;
}
int k,n;
int pos;
void dec(vector<int>& v){
    if(v[pos]==1){
        v[pos]=0;
        pos--;
        return;
    }
    else if(v[pos]>1){
        v[pos]--;
        for(int j=pos+1;j<n;j++){
            v[j]=k;
        }
        pos=n-1;
    }
}
int main(){
    cin>>k>>n;
    pos=n-1;
    if(k%2==0){
        vector<int> res;
        res.push_back(k/2);
        for(int i=0;i+1<n;i++){
            res.push_back(k);
        }
        output(res);
        return 0;
    }

    vector<int> res(n);
    for(int i=0;i<n;i++) res[i]=(k+1)/2;
    
    for(int loop=0;loop<n/2;loop++){
        dec(res);
    }
    output(res);
    return 0;
}

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

int main() {
  
  int X;
  cin >> X;
  
  int uresi500 = 0;
  int uresi5 = 0;
  int uresi = 0;
  int n1 = X / 500;
  int n2 = (X - 500 * n1) / 5;
  
  for (int i = 0; i < n1; i++) {
    uresi500++;
  }
  
  for (int i = 0; i < n2; i++) {
    uresi5++;
  }
  
  uresi500 *= 1000;
  uresi5 *= 5;
  
  uresi = uresi500 + uresi5;
  
  cout << uresi <<endl;
    
}

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

H = list(map(int,input().split()))
H = [-100] + H
for i in range(N):
	if H[i] < H[i+1]:
		H[i+1] -= 1
	elif H[i] == H[i+1]:
		pass
	else:
		print("No")
		quit()
print("Yes")

Measured memory_bytes: 14252
import sys
#結局よくわからず解法見てしもた
#これで通るかな

def 解():
    iN = int(input())
    aP = [[int(_) for _ in sLine.rstrip("\n").split()] for sLine in sys.stdin.readlines()]

    i最遠 = max([ abs(iX)+abs(iY) for iX , iY in aP])

    iMod = sum(aP[0]) % 2
    for i in range(1,iN):
        if sum(aP[i]) % 2 != iMod :
            print("-1")
            exit()
    a腕 = [1]
    if iMod == 0 :
        a腕 = [1,1]
    for i in range(32):
        a腕.append(a腕[-1] * 2)
        if i最遠 // 2 < a腕[-1]:
            break
    a腕.reverse()
    iLen腕 = len(a腕)
    print(iLen腕)
    print(" ".join([str(_) for _ in a腕]))
    aRet = []
    for aE in aP:
        aCommand=[]
        iX = aE[0]
        iY = aE[1]
        for i in range(iLen腕):
            if abs(iX) > abs(iY):
                if iX < 0 :
                    iX += a腕[i]
                    aCommand.append("L")
                else:
                    iX -= a腕[i]
                    aCommand.append("R")
            else:
                if iY < 0 :
                    iY += a腕[i]
                    aCommand.append("D")
                else:
                    iY -= a腕[i]
                    aCommand.append("U")
        aRet.append("".join(aCommand))
    sys.stdout.write("\n".join(aRet) + "\n")

if __name__ == '__main__':
    解()


Measured memory_bytes: 3444
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  int N,K;
  cin>>N;
  string S;
  cin>>S;
  cin>>K;
  for(auto c:S){
    cout<<(c==S[K-1]?c:'*');
  }
  cout<<endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
Xi= list(map(int,input().split()))
ans = 0
for i in range(1,max(Xi)+1):
	total_energy =0
	for n in range(N):
		energy = (Xi[n]-i)**2
		total_energy = total_energy + energy
	if i == 1:
		ans = total_energy
	elif ans > total_energy:
		ans = total_energy
print(ans)

Measured memory_bytes: 3060