akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;

template <typename T>
using TABLE = vector<vector<T>>;

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


int main(){
    long long N;
    cin >> N;

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

    sort(A.begin(), A.end());

    int pos = 0;
    long long max_num = A[N - 1] - A[0];

    for(int i = 1; i < N - 1; ++i){
        max_num += abs(A[i]);
    }
    cout << max_num << endl;

    long long plus_num = A[N - 1];
    long long minus_num = A[0];

    for(int i = 1; i < N - 1; ++i){
        if(A[i] >= 0){
            cout << minus_num << " " << A[i] << endl;
            minus_num -= A[i];
        }
        else{
            cout << plus_num << " " << A[i] << endl;
            plus_num -= A[i];
        }
    }

    cout << plus_num << " " << minus_num << endl;

}


Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int k, s, z = 0;
    cin >> k >> s;
    for (int i = 0; i <= k; i++) for (int j = 0; j <= k; j++) if (s - i - j >= 0 && s - i - j <= k) z++;
    cout << z;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n,mn=1e9;
	scanf("%d",&n);
	bool ok=0;
	long long s=0;
	while (n--)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		ok|=(a!=b);
		s+=a;
		if (a>b)
		mn=min(mn,b);
	}
	if (!ok)
	printf("0");
	else
	printf("%lld",s-mn);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
using namespace std;
typedef long long ll;

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

	if (s[0] == s[2])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
inline long long in(){long long x=0;char c=getchar();bool neg=false;while(c!='-'&&('0'>c||c>'9')) c=getchar();if(c=='-') neg=true,c=getchar();while('0'<=c&&c<='9') x=10*x+c-'0',c=getchar();if(neg) x=-x;return x;}
inline void out(long long x){if(x<0) putchar('-'),x=-x;if(x>9) out(x/10);putchar(x%10+'0');}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "d"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))
#define _ putchar(' ')
#define __ putchar('\n')
const int N=110;
int n,w,kq;
int a[N],b[N];
int f[N][100010];
main()
{
    fasty;
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    cin>>n>>w;
    forinc(i,1,n) cin>>a[i]>>b[i];
    f[0][0]=0;
    forinc(i,0,n-1) forinc(j,0,w) if(f[i][j]>-1)
    {
        if(j+a[i+1]<=w)
        f[i+1][j+a[i+1]]=max(f[i+1][j+a[i+1]],f[i][j]+b[i+1]);
        f[i+1][j]=max(f[i+1][j],f[i][j]);
    }
    forinc(j,0,w) kq=max(kq,f[n][j]);
    cout<<kq;
}


Measured memory_bytes: 79360
use std::io;


/// https://beta.atcoder.jp/contests/code-festival-2017-quala/tasks/code_festival_2017_qualb_b
fn main() {
    let (n, m, k) = {
        let i = read::<isize>();
        (i[0], i[1], i[2])
    };
    let mut flg = false;
    for i in 0..n + 1 { for j in 0..m + 1 {
        if i * (m - j) + j * (n - i) == k { flg = true; break; }
    }}
    if flg { println!("Yes"); }
    else { println!("No"); }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

using namespace std;

char switcher(char status)
{
    if (status == 'R')
        return 'L';
    else
        return 'R';
}

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

    char status = 'R';
    vector<int> ans(s.length(), 0);
    for (int i = 0; i < s.length() - 1; i++)
    {
        if (s[i] == 'R' && s[i + 1] == 'L')
        {
            int r_cnt = 0;
            int l_cnt = 0;
            for (int l = i; l >= 0 && s[l] == 'R'; l--)
            {
                r_cnt++;
            }
            for (int r = i + 1; r < s.length() && s[r] == 'L'; r++)
            {
                l_cnt++;
            }

            ans[i] = ans[i + 1] = (r_cnt + l_cnt) / 2;
            if ((r_cnt + l_cnt) % 2 != 0)
            {
                if (r_cnt % 2 != 0)
                    ans[i] += 1;
                else
                    ans[i + 1] += 1;
            }
        }
    }

    for (int i = 0; i < s.length(); i++)
    {
        cout << ans[i] << ' ';
    }
}

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

using namespace std;

#define endl "\n"
#define maxn 100000
#define OO 1e5
#define F first
#define S second
#define B begin()
#define E end()
#define PB push_back
#define int long long

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

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

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);


    int n,x,y;
    cin >> n >> x >> y;

    int dist[n+2][n+2];
    memset(dist,0,sizeof(dist));
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            dist[i][j]=j-i;
            dist[j][i]=j-i;
        }
    }

    int d = abs(x-y);
    d/=2;
    d--;
    dist[x][y]=1;
    for(int i=1;i<=x+d;i++)
        {
            for(int j=y-d;j<=n;j++)
            {
                dist[i][j]=min(dist[i][j],1+dist[i][x]+dist[y][j]);
                dist[j][i]=dist[i][j];
            }
        }

    int arr[n+1];
    memset(arr,0,sizeof(arr));
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
            arr[dist[i][j]]++;
        for(int i=1;i<=n-1;i++)
            cout << arr[i] << endl;
    return 0;
}


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

int N,M,K,ti;

int main()
{
    ti = 0;
    cin>>N>>M>>K;

    for(int i = 0;i<=N;i++)
    {
        for(int j = 0;j<=M;j++)
        {
            if(K == i*M+j*N-i*j*2)
            {
                ti = 1;
                break;
            }
        }
        if(ti==1) break;
    }
    if(ti==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int yen, happiness = 0;
    cin >> yen;
    while (yen > 0){
        if (yen >= 500){
            happiness += 1000;
            yen -= 500;
        } else if (yen >= 100){
            happiness += 100;
            yen -= 100;
        }else if (yen >= 50){
            happiness += 50;
            yen -= 50;
        }else if (yen >= 10){
            happiness += 10;
            yen -= 10;
        }else if (yen >= 5){
            happiness += 5;
            yen -= 5;
        }else {
            yen -= yen;
        }
    }
    cout << happiness;
}

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

struct UnionFind{
    vector<int> par;
    UnionFind(int N) : par(N){
        for(int i = 0; i < N; i++){
            par[i] = -1;
        }
    }
    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return;
        else{
            if(par[rx] > par[ry]) swap(rx, ry);
            par[rx] += par[ry];
            par[ry] = rx;
       }
    }
    bool same(int x, int y){
        return root(x) == root(y);
    }
    void check(){
        for(auto x : par){
            cout << x << " ";
        }
        cout << endl;
    }
};

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

    int n, m;
    cin >> n >> m;

    UnionFind UF(n + m);
    for(int i = 0; i < n; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int l;
            cin >> l;
            UF.unite(i, n + l - 1);
        }
    }

    int parent = -1e9;
    for(int i = 0; i < n; i++){
        if(i == 0){
            parent = UF.root(i);
        }else{
            if(parent != UF.root(i)){
                cout << "NO" << endl;
                return 0;
            }
        }
    }

    cout << "YES" << endl;

    return 0;
}

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

using namespace std;
using ll = long long int;

const ll MOD = 1e9 + 7;

ll pow_fast(ll n, ll k) {
  if (k == 0) {
    return 1LL;
  }
  if (k == 1) {
    return n;
  }

  if (k % 2 == 0) {
    ll tmp = pow_fast(n, k / 2);
    return tmp * tmp % MOD;
  } else {
    ll tmp = pow_fast(n, (k - 1) / 2);
    tmp *= tmp;
    tmp %= MOD;
    return tmp * n % MOD;
  }
}

template <typename T>
class stack {
 private:
  vector<T> _vec;

 public:
  stack(){};

  void push(T n) {
    _vec.push_back(n);
    return;
  }

  void pop() {
    if (this->empty()) {
      return;
    }
    _vec.erase(_vec.end() - 1);
    _vec.shrink_to_fit();
    return;
  }

  size_t size() { return _vec.size(); }

  T top() { return _vec[this->size() - 1]; }
  bool empty() { return _vec.empty(); }
};

bool isOk(string s) {
  if (s.size() % 2 == 1){ 
    return false;
  }
  string pre = s.substr(0, s.size() / 2);
  string suf = s.substr(s.size() / 2, s.size() / 2);
  return pre == suf;
}
int main() {
  string s;
  cin >> s;

  map<char, ll> mp;
  for (ll i = 0; i < 26; i++)
  {
    mp[(char)('a' + i)] = 0;
  }
  
  for (ll i = 0; i < s.size(); i++)
  {
    mp[s[i]] += 1;
  }
  
  for (ll i = 0; i < 26; i++)
  {
    if (mp[(char)('a' + i)] == 0) {
      cout << (char)('a' + i) << endl;
      return 0;
    }
  }
  cout << "None" << endl;
}

Measured memory_bytes: 3724
# vim: set fileencoding=utf-8:


def main():
    N = input()
    C = [0] * (N - 1)
    S = [0] * (N - 1)
    F = [0] * (N - 1)

    for i in xrange(N - 1):
        C[i], S[i], F[i] = map(int, raw_input().split())

    t = 0
    for j in xrange(N - 1):
        for i in xrange(N - 1):
            if i + j == N - 1:
                break
            t = spend_waited_time(t, S[i + j], F[i + j])
            t += C[i + j]

        print(t)
        t = 0

    print(0)


def spend_waited_time(t, S, F):
    if t <= S:  # 始発がまだなら
        t = S
    elif S < t:  # 始発済みなら、次の電車まで何秒待つ？
        a = (t - S) % F
        if a == 0:
            pass
        else:
            t += F - abs(a)

    return t


if __name__ == "__main__":
    main()


Measured memory_bytes: 2696
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define pii pair<int, int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORR(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) FORR(i,n,0)
#define ALL(c) ((c).begin(),(c).end())
#define PB(a) push_back(a)
#define EMPB(...) emplace_back(__VA_ARGS__)
#define EMP(...) emplace(__VA_ARGS__)
#define MP(a,b) make_pair(a,b)
#define MT(...) make_tuple(__VA_ARGS__)
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define PW(n) (1LL<<(n))
using namespace std;
template <class T> inline bool CHMIN(T& a, T b) { if(a>b) { a=b; return 1; } return 0; }
template <class T> inline bool CHMAX(T& a, T b) { if(a<b) { a=b; return 1; } return 0; }
template <class T> inline void SORT(T& a) { sort(ALL(a)); }
template <class T> inline void REV(T& a) { reverse(ALL(a)); }
template <class T> inline void UNI(T& a) { SORT(a); a.erase(unique(ALL(a)),a.end()); }
template <class S, class T> ostream& operator<<(ostream& os, const pair<S,T> a) {
  return os << a.first << ' ' << a.second;
}
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int N,K;
string S;

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N >> K >> S;
  int l = 0, r = 0;
  int cnt = 0;
  int ans = 0;
  while (l < N) {
    while (r < N && cnt < K) {
      if (S[r] == '0') {
        cnt++;
        while (r < N && S[r] == '0') r++;
      } else {
        while (r < N && S[r] == '1') r++;
      }
    }
    while (r < N && S[r] == '1') r++;
    CHMAX(ans,r-l);
    if (l < N && S[l] == '1') {
      while (l < N && S[l] == '1') l++;
    }
    while (l < N && S[l] == '0') l++;
    if (l == N) break;
    cnt--;
  }
  cout << ans << endl;

  return 0;
}

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

bool cmp(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second > b.second;
	}
	else {
		return a.first > b.first;
	}
}

int main() {
	int n, h;
	cin >> n >> h;
	vector<pair<int, int>> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i].first >> v[i].second;
	int amax = 0;
	for (int i = 0; i < n; i++)
		if (amax < v[i].first)
			amax = v[i].first;
	sort(v.begin(), v.end(), cmp);
	int count = 0;
	while (v[count].second > amax && h > 0) {
		h -= v[count].second;
		count++;
	}
	if (h > 0) {
		count += h / amax;
		if (h % amax)
			count++;
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <cstdio>

int main()
{
    char in[4] = {'A', 'C', 'G', 'T'};
    char out[4] = {'T', 'G', 'C', 'A'};
    char b;
    scanf("%c", &b);
    for (int i = 0; i < 4; i++)
    {
        if (in[i] == b)
        {
            printf("%c\n", out[i]);
        }
    }

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 1e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh
int color[nax];
vector< int > g[nax];
void dfs(int u , int p , int c){
	color[u] = c;
	for(auto v : g[u]){
		if(color[v] == c){
			cout << -1 << endl;
			exit(0);
		}
		if(color[v] == 0){
			dfs(v , u , 3 - c);
		}
	}
}
int main(){
	dhoom;
	int a , b , c , d;
	cin >> a >> b >> c >> d;
	int t1 , t2;
	t1= ceil(c/(b*1.0));
	t2 = ceil(a/(d*1.0));
	if(t1 <= t2)
		cout << "Yes" << endl;
	else 
		cout << "No" <<endl;
		
}


Measured memory_bytes: 27104
#include <iostream> 
#include <algorithm> 
#include <map> 
#include <vector> 
// #include <bits/stdc++.h>
using namespace std;

int main(){
    int N;
    cin>>N;
    int n=N;
    map<string,int> m;
    while(n--){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        m[s]++;
    }
    map<string,int> :: iterator it;
    long long ans=0;
    for(it=m.begin();it!=m.end();it++){
        ans+=(long long)(it->second)*(long long)(it->second-1)/2;
    }
    cout<<ans;    
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus>=201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long X, long long Y){
  ll ans=0;
  switch (X)
  {
  case 1:
    ans+=300000;
    break;
  case 2:
    ans+=200000;
    break;
  case 3:
    ans+=100000;
    break;
  default:
    break;
  }
  switch (Y)
  {
  case 1:
    ans+=300000;
    break;
  case 2:
    ans+=200000;
    break;
  case 3:
    ans+=100000;
    break;
  default:
    break;
  }
  if(X==1&&Y==1){
    ans+=400000;
  }
  cout<<ans<<endl;
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    solve(X, Y);
    return 0;
}


Measured memory_bytes: 256
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy

def j(q):
    if q==1: print("yes")
    else:print("no")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())


#n = ip()                              #入力整数1つ
n,m= (int(i) for i in input().split())      #入力整数横2つ
#n,x,y = (int(i) for i in input().split())    #入力整数横3つ
#n,a,b,c= (int(i) for i in input().split())  #入力整数横4つ
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(h)]
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
s = [0 for i in range(n+1)]
for i in range(m):
    a,b = (int(i) for i in input().split())
    s[a]+=1
    s[b]+=1
for i in range(1,n+1):
    print(s[i])

Measured memory_bytes: 13384
#include <iostream>

#define MAX 200000
int main(void){
  int N;
  std::cin >> N;
  int P[MAX];
  int mins[MAX];
  for(int i=0;i<N;i++){
    std::cin >> P[i];
  }
  //最小値を入れていく
  mins[0] = P[0];
  for(int i=1;i<N;i++){
    int tmp = P[i];
    if(tmp < mins[i-1]){
      mins[i] = tmp;
    }else{
      mins[i] = mins[i-1];
    }
  }
  //各minsにはそれまでの最小値が記載
  //比較して足し合わせる
  int sum = 0;
  for(int i=0;i<N;i++){
    if(mins[i] >= P[i]){
      sum++;
    }
  }
  std::cout << sum << std::endl;
  return 0;
}

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

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)

const int INF = 100000000;

using namespace std;

void p(int x) {
	cout << x << endl;
}

int main() {
	int n;
	int sum = 0;
	cin >> n;
	rep(i, 1, n+1) {
		sum += i;
	}
	p(sum);

	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  auto f = [](int x) {
    cout << x << '\n';
    cout << flush;
    string s;
    cin >> s;
    if (s == "Vacant") {
      exit(0);
    } else if (s == "Male") {
      return 0;
    } else {
      return 1;
    }
  };
  int lo = 0, hi = N - 1, k = f(0);
  while (lo <= hi) {
    int mi = (lo + hi) / 2, r = f(mi) ^ (mi & 1);
    if (k == r) {
      lo = mi + 1;
    } else {
      hi = mi - 1;
    }
  }
  return 0;
}


Measured memory_bytes: 852
n = int(input())
s = input()
acc_cnt_a = [0] * n
acc_cnt_b = [0] * n
acc_cnt_ab = [0] * n
c_loc = []
cnt_a = 0
cnt_b = 0
cnt_ab = 0
for i, c in enumerate(s):
    if c == 'D':
        cnt_a += 1
    elif c == 'M':
        cnt_b += 1
        cnt_ab += cnt_a
    elif c == 'C':
        c_loc.append(i)
    acc_cnt_a[i] = cnt_a
    acc_cnt_b[i] = cnt_b
    acc_cnt_ab[i] = cnt_ab

q = int(input())
buf = []
for k in map(int, input().split()):
    ans = 0
    for r in c_loc:
        l = r - k
        if l >= 0:
            rejected_a = acc_cnt_a[l]
            cnt_internal_b = acc_cnt_b[r] - acc_cnt_b[l]
            cnt_internal_ab = acc_cnt_ab[r] - acc_cnt_ab[l]
            ans += cnt_internal_ab - rejected_a * cnt_internal_b
        else:
            ans += acc_cnt_ab[r]
    buf.append(ans)
print('\n'.join(map(str, buf)))


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

#define ll              long long
#define Ull             unsigned long long
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

const int N = 2;
const ll MOD = 1e9 + 7;


/*bool comp(const pii &p1, const pii &p2)
{

}*/


void Solve()
{

	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll len = s.length();
	if (len <= n)
		cout << s << "\n";

	else
	{
		string ans = "";
		for (ll i = 0; i < n; i++)
			ans += s[i];

		ans += "...";
		cout << ans << "\n";
	}

}


int main()
{

	FastRead;
	int T = 1;
	//cin>>T;
	while (T--)
	{
		Solve();
	}

	return 0;
}


Measured memory_bytes: 3616
#include <iostream>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int l,m=0,sum=0;
    int i=0;
    while(i<n){
        i++;
        cin >> l;
        if(m<l) m=l;
        sum+=l;
    }
    if(sum>2*m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
if __name__ == '__main__':
    output = []
    while True:
        x, y = map(int, raw_input().split(' '))
        if x == 0 and y == 0:
            break
        else:
            if x > y:
                output.append('%d %d' % (y, x))
            else:
                output.append('%d %d' % (x, y))

    for line in output:
        print line

Measured memory_bytes: 4296
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    ll n;
    cin >> n;
    vector<ll> a(5);
    rep(i, 5) cin >> a[i];
    
    ll mi = *min_element(all(a));
    ll grp = (n + mi - 1) / mi;

    put(4 + grp);    

    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main()
{
    int a, b, x;
    scanf("%d %d %d", &a, &b, &x);
    
    if (a < x && b > x - a || a == x) {
        printf("YES\n");
    } else {
        printf("NO\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N=3e3+7;
long long dp[N][N][4],v[N][N];

int main()
{
	int r,c,n;
	scanf("%d%d%d",&r,&c,&n);
	for(int i=0;i<n;i++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		scanf("%lld",&v[x][y]);
	}
	for(int i=1;i<=r;i++)
	{
		for(int j=1;j<=c;j++)
		{
			int is=v[i][j]?1:0;
			for(int t=0;t<=3;t++)
				dp[i][j][0]=max(dp[i][j][0],dp[i-1][j][t]);
			if(is)
				dp[i][j][1]=dp[i][j][0]+v[i][j];

			for(int k=0;k<=3;k++)
			{
				dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k]);
				if(is&&k)
					dp[i][j][k]=max(dp[i][j][k],dp[i][j-1][k-1]+v[i][j]);
			}

		}
	}
	long long ans=0;
	for(int t=0;t<=3;t++)
		ans=max(ans,dp[r][c][t]);
	printf("%lld\n",ans);
}


Measured memory_bytes: 356100
#include<stdio.h>
 
int main() {
    int N;
    int i;
    int a, b, c;
 
    scanf("%d\n", &N);
 
    for(i = 0; i < N; i++) {
        scanf("%d %d %d", &a, &b, &c);
        if (a > b && a > c)
            if (a*a == b*b + c*c)
                printf("YES\n");
            else
                printf("NO\n");
        else if(b > a && b > c)
            if(b*b == a*a + c*c)
                printf("YES\n");
            else
                printf("NO\n");
        else
            if(c*c == a*a + b*b)
                printf("YES\n");
            else
                printf("NO\n");
    }
    return 0;
}

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

int main() {
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  int L = S.length();
  vector<int> f(L, 0);

  /* 'AC'を発見したら1 */
  for (int i = 1; i < L; i++)
    if (S[i - 1] == 'A' && S[i] == 'C') f[i] = 1;
  /* i番目までに出てきた'AC'の累積和をf[i]に格納 */
  for (int i = 1; i < L; i++) f[i] += f[i - 1];

  /* l, q 入力部分 */
  vector<int> l(Q, 0), r(Q, 0);
  for (int i = 0; i < Q; i++) {
    cin >> l[i] >> r[i];
    l[i]--;
    r[i]--;
  }

  /* f[右端]-f[左端] で[l, r]に含まれる'AC'の個数が得られる */
  for (int i = 0; i < Q; i++) cout << f[r[i]] - f[l[i]] << endl;
}

Measured memory_bytes: 4540
N = int(input())
C = input()

r = 0
w = 0
for c in C:
    if c == 'R':
        r += 1
    else:
        w += 1

if w == 0 or r == 0:
    print(0)
    exit(0)

ans = 0
if r < w:
    for rx in range(r):
        if C[rx] != 'R':
            ans += 1
else:
    for wx in range(w):
        if C[N-1-wx] != 'W':
            ans += 1

print(ans)

Measured memory_bytes: 9352
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <string>
using namespace std; typedef long long ll; const ll INF=1e16; typedef pair<int,int> P;

int main() {
  ll a,b,c,k; cin>>a>>b>>c>>k;
  // b+c a+c a+b
  // 2a+b+c a+2b+c a+b+2c
  // p0+a p0+b p0+c
  // p1+p0+a p1+p0+b p1+p0+c
  if (k%2) cout<<b-a<<endl;
  else cout<<a-b<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    int b,f,r,v;
    int a[4][3][10] = {};
    for(int i=0;i<n;i++){
        cin>>b>>f>>r>>v;
        a[b-1][f-1][r-1]+=v;
    }
    for(int i=0;i<4;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<10;k++) cout << " " << a[i][j][k];
            cout << endl;
        }
        if(i!=3) cout << "####################" << endl;
    }
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
#define INF 1e17
#define int long long

#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__) 
void DBG() {
  cerr << "]\n";
}
template<typename T, typename ...Args> void DBG(T first, Args... args) {
  cerr << first; if (sizeof...(args))cerr<<", "; DBG(args...);
}

/////////////////////////// GLOBAL ///////////////////////////

/////////////////////////// GLOBAL ///////////////////////////

void solve() {
  int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++) cin>>arr[i];
  int m = INF;
  int d;
  int s = 0;
  for(int i=0;i<n-1;i++){
    if(arr[i+1] < arr[i]){
      d = arr[i] - arr[i+1];
      arr[i+1] += d;
      s += d;
    }
  }
  cout<<s<<"\n";

}


int32_t main() {
  #ifndef ONLINE_JUDGE
  clock_t tStart = clock();
  freopen("in.txt", "r", stdin);
  //freopen("output.txt","w",stdout);
  #endif 
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
  // cin >> t;
  for (int tt=1;tt<=t;tt++) {
    //cout << "Case #"<<tt<<": ";
    solve();
  }
  #ifndef ONLINE_JUDGE
    cerr << "\nRun Time -> "<<(double)(clock()-tStart)/CLOCKS_PER_SEC <<" sec\n";
  #endif
}


Measured memory_bytes: 5176
N = int(input())
A = list(map(int, input().split()))
B = A[:]

# evenがプラスの時
sum_even = 0
ans_even = 0

for i in range(N):
  sum_even += A[i]
  if i % 2 == 0:
    if sum_even <= 0:
      ans_even += abs(sum_even) + 1
      sum_even += abs(sum_even) + 1
  else:
    if sum_even >= 0:
      ans_even += abs(sum_even) + 1
      sum_even -= abs(sum_even) + 1

# oddがプラスの時
sum_odd = 0
ans_odd = 0
for i in range(N):
  sum_odd += A[i]
  if i % 2 == 1:
    if sum_odd <= 0:
      ans_odd += abs(sum_odd) + 1
      sum_odd += abs(sum_odd) + 1
  else:
    if sum_odd >= 0:
      ans_odd += abs(sum_odd) + 1
      sum_odd -= abs(sum_odd) + 1

answer = min(ans_even, ans_odd)
print(str(answer))


Measured memory_bytes: 20092
N,A,B,K = map(int,input().split())
MOD = 998244353

if (A+B)*N < K:
    print(0)
    exit()

M = N+5
fac = [1,1] + [0]*M
finv = [1,1] + [0]*M
inv = [0,1] + [0]*M
for i in range(2,M+2):
    fac[i] = fac[i-1] * i % MOD
    inv[i] = -inv[MOD%i] * (MOD // i) % MOD
    finv[i] = finv[i-1] * inv[i] % MOD

def ncr(n,r):
    if n < r: return 0
    if n < 0 or r < 0: return 0
    return fac[n] * (finv[r] * finv[n-r] % MOD) % MOD

ans = 0
for a in range(N+1):
    rem = K - a*A
    if rem < 0: break
    b,m = divmod(rem, B)
    if m: continue
    ans += ncr(N,a) * ncr(N,b)
    ans %= MOD
print(ans)

Measured memory_bytes: 40908
#include<bits/stdc++.h>
#define reg register
using namespace std;
int n,a;
set<int>s;
int main()
{
	scanf("%d",&n);
	for(reg int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		if(s.find(a)!=s.end())s.erase(a);
		else s.insert(a);
	}
	printf("%d",s.size());
	return 0;
}

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

void solve() {
  int n;
  int64_t k;
  cin >> n >> k;

  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());

  auto pos = lower_bound(a.begin(), a.end(), 0);
  auto rpos = make_reverse_iterator(pos);
  auto non_zero_pos = upper_bound(a.begin(), a.end(), 0);

  auto pos_cnt = a.end() - pos;
  auto neg_cnt = n - pos_cnt;
  auto non_zero_pos_cnt = a.end() - non_zero_pos;
  auto zero_cnt = pos_cnt - non_zero_pos_cnt;

  constexpr int64_t limit = 1'000'000'000LL;
  int64_t left = -limit * limit;
  int64_t right = limit * limit + 1;
  while (left <= right) {
    int64_t lcnt = 0;
    int64_t ucnt = 0;
    auto mid = left + (right - left) / 2;

    if (mid == 0) {
      lcnt = neg_cnt * non_zero_pos_cnt;
      ucnt = lcnt;
      for (int i = 0; i < zero_cnt; ++i) {
        ucnt += n - 1 - i;
      }
      assert(lcnt <= ucnt);
    } else if (mid < 0) {
      for (auto it = a.begin(); it != pos; ++it) {
        auto lcmp = [=](int64_t elem, int64_t val) {
          assert(val == mid);
          return elem * *it < val;
        };
        auto ucmp = [=](int64_t val, int64_t elem) {
          assert(val == mid);
          return elem * *it > val;
        };
        auto lit = lower_bound(a.rbegin(), rpos, mid, lcmp);
        auto uit = upper_bound(lit, rpos, mid, ucmp);
        auto dl = lit - a.rbegin();
        auto du = uit - a.rbegin();
        assert(dl <= du);
        lcnt += dl;
        ucnt += du;
      }
    } else {
      for (auto it = a.begin(); it != pos; ++it) {
        auto lcmp = [=](int64_t elem, int64_t val) {
          assert(val == mid);
          return elem * *it < val;
        };
        auto ucmp = [=](int64_t val, int64_t elem) {
          assert(val == mid);
          return elem * *it > val;
        };
        auto end = make_reverse_iterator(it + 1);
        auto lit = lower_bound(rpos, end, mid, lcmp);
        auto uit = upper_bound(lit, end, mid, ucmp);
        auto dl = pos_cnt + lit - rpos;
        auto du = pos_cnt + uit - rpos;
        assert(dl <= du);
        lcnt += dl;
        ucnt += du;
      }
      for (auto it = pos; it != a.end(); ++it) {
        auto lcmp = [=](int64_t elem, int64_t val) {
          assert(val == mid);
          return elem * *it < val;
        };
        auto ucmp = [=](int64_t val, int64_t elem) {
          assert(val == mid);
          return elem * *it > val;
        };
        auto lit = lower_bound(it + 1, a.end(), mid, lcmp);
        auto uit = upper_bound(lit, a.end(), mid, ucmp);
        auto dl = lit - it - 1;
        auto du = uit - it - 1;
        assert(dl <= du);
        lcnt += dl;
        ucnt += du;
      }
    }
    assert(lcnt <= ucnt);
    if (k <= lcnt) {
      right = mid;
    } else if (ucnt < k) {
      left = mid + 1;
    } else {
      cout << mid << endl;
      return;
    }
  }
  assert(false);
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define IFOR(i,a) for(int i=(a);;i++)
#define REP(i,n)  FOR(i,0,n)
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define INPUT \
FILE *fp; \
fp=fopen("input.text","r");



int main() {
    int Mex,Fex,Rex,sum;
    char grade;
    while (1) {
        cin >> Mex >> Fex >> Rex;
        sum = Mex + Fex;
        if (Mex == -1 && Fex == -1 ) break;
        if (Mex == -1 || Fex == -1 || sum < 30) grade='F';
        
        else if (sum < 50){
            if (Rex>=50) grade='C';
            else grade='D';
        }
        else if (sum < 65) grade='C';
        else if (sum < 80) grade='B';
        else grade='A';
        cout << grade << endl;
    }
    
    return 0;
}




Measured memory_bytes: 3084
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<utility>
#include<string>
#include<cmath>
using namespace std;

int main(){
    long long n;cin >> n;
    long long ans = ((n-1)*(n))/2;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define ll long long
#define ld long double
#define ff first
#define ss second
#define rsz resize
#define ins insert 
#define mp make_pair
#define pf push_front 
#define pb push_back
#define eb emplace_back 
#define ft front() 
#define bk back()
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define deb(x) cout<<#x<<" "<<x<<'\n';
#define rep(i,a,b) for (int i = (a); i < (b); ++i)

const ll mod = 1e9+7; // 998244353;
const ll inf = 1e18; 
const ld pie = acos((ld)-1);

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



int main(){
    
	int n,x,t;
	scanf("%d%d%d",&n,&x,&t);
	if(n<=x){
		printf("%d\n",t );
	}else{
		if(n%x==0)
			printf("%d\n",(n*t/x));
		else
			printf("%d\n",(n/x + 1)*t);
	}


	return 0;

	/*STUFF TO LOOK:	
		1. Check the constraints
		2. Corner cases(n==0||n==1)
		3. Variables in loops
		4. Make sure two ints aren’t multiplied to get a long long
		5. Don't use scanf or printf while using ios_base
		6. using the local variable of the same name when global variable was required to be used
	*/
}


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

int main(){
    cin >> n >> m;
    pair<int, int> s[m];
    rep(i,m){
        cin >> s[i].second;
        cin >> s[i].first;
    }
    sort(s, s+m);
    int b = 0; //さいごに橋を取り除いた位置
    rep(i,m){
        if(s[i].second > b){ 
            b = s[i].first -1;
            ans += 1;
        }
    }
    cout << ans << endl;
}

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

int main(){
	int n; scanf("%d", &n);
	vector<vector<int> > a(10, vector<int> (10, 0));
	for(int i = 1; i <= n; i++){
		string s = to_string(i);
		int n = s.size();
		a[s[0] - '0'][s[n - 1] - '0']++;
	}
	int ans = 0;
	for(int i = 0; i < 10; i++){
		for(int j = 0; j < 10; j++) ans += a[i][j] * a[j][i];
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 3796
#include <iostream>
#include <vector>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <tuple>
#include <iomanip>
#include <random>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <chrono>
#include <stack>
#include <string>
#include <bitset>
#include <unordered_map>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x.size())
#define pb push_back
#define endl "\n" // TODO: remove
#define int long long

const int N = (int)(1e6) + 322;
const long long inf = (long long)(2e18) + 322;
const int mod = (int)(1e9) + 7; // check modulo


void solve() {
    int n, d; cin >> n >> d;
    int c= 0 ;
    for(int i = 1; i <= n; ++i) {
        int x, y; cin >> x >> y;
        if (d * d >= x * x + y * y) c++;
    }
    cout << c;
}

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

//    int test; cin >> test;
//    for(int t = 1; t <= test; ++t) {
        solve();
//    }
    return 0;
}



Measured memory_bytes: 3128
import sys
card = list(list(map(int,input().split())) for i in range(3))
n = int(input())
for i in range(n):
  x = int(input())
  for j in range(3):
    if x in card[j]:
      card[j]=list(True if s == x else s for s in card[j])
      
for i in range(3):
  if card[i] == [True,True,True]:
    print("Yes")
    sys.exit()
    break
  elif card[0][i]==True and card[1][i]==True and card[2][i] == True:
    print("Yes")
    sys.exit()
    break
if card[0][0]== True and card[1][1]==True and card[2][2]==True:
  print("Yes")
elif card[0][2]==True and card[1][1]== True and  card[2][0] ==True:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9276
#include <stdio.h>

int main(void) {
  int a,b,c,k,i;
  scanf("%d %d %d %d",&a,&b,&c,&k);
  if (a >= b && a >= c) {
    for (i = 0;i < k;i++) {
      a *= 2;
    }
  } else if (b >= a && b >= c) {
    for (i = 0;i < k;i++) {
      b *= 2;
    }
  } else {
    for (i = 0;i < k;i++) {
      c *= 2;
    }
  }
  printf("%d\n",a + b + c);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main()
{
    int N, K;
    cin >> N >> K;
    
    vector<int> p(N);
    for (int i = 0; i < N; ++i) {
        cin >> p[i];
    }

    sort(begin(p), end(p));

    int ans = 0;
    for (int i = 0; i < K; ++i) {
        ans += p[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define ll long long
#define INF 1e9
#define pb push_back
#define mp  make_pair
#define loop(a,n) for(long long i=a;i<n;i++)
#define vil vector<long long int>
#define vi vector<int>
#define sz(v) v.size()
#define setbits(x)          __builtin_popcountll(x)
#define ff first
#define ss second
using namespace std;


ll gcd(ll a, ll b) {
  if (a == 0)return b;
  return gcd(b % a, a);
}
bool isperfect(ll n) {
  ll y = sqrt(n);
  if (n % y == 0 && y * y == n)return true;
  return false;
}
bool comp(pair<int,int> a, pair<int,int> b) {
    if(a.first == b.first) return a.second>b.second;
  return a.first < b.first;
}
 ll powi(ll a, ll b) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1)ans = (ans * a);
    b = b >> 1;
    a = (a * a);
  }
  return ans;
}
bool isprime(ll n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)return false;
  }
  return true;
}
bool prime[10000000];
void seive() {

  prime[1] = true;
  for (int i = 2; i * i < 10000000; i++) {

    if (prime[i])continue;
    for (int j = i * i; j < 10000000; j += i) {
      prime[j] = true;
    }

  }
}
 vil v[200005];
 vil a(200005),p(200005);
 bool vis[200005]={false};
 ll maxi=INT_MIN;
void dfs(int s,ll atil,ll ptil){
    vis[s]=true;
    for(auto x: v[s]){
        if(!vis[x]){
            
       ll sm=(atil+a[x-1])/(ptil+p[x-1]);
       if(sm>maxi){
           maxi=sm;
          // vis[x]=true;
           dfs(x,atil+a[x-1],ptil+p[x-1]);
       }
       else if(sm==maxi){
         //  vis[x]=true;
           dfs(x,atil+a[x-1],ptil+p[x-1]);
       }
        }
    }
     
}
int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int n;cin>>n;
  vil v(n);
  
  for(int i=0;i<n;i++) cin>>v[i];
  ll x=v[0];
  for(int i=1;i<n;i++){
      x=x^v[i];
  }
  for(int i=0;i<n;i++){
      cout<<(x^v[i])<<" ";
  }
}





  

Measured memory_bytes: 12708
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#include<functional>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<bitset>
#include<assert.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
void open(const char *s){
#ifndef ONLINE_JUDGE
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
void open2(const char *s){
#ifdef DEBUG
	char str[100];sprintf(str,"%s.in",s);freopen(str,"r",stdin);sprintf(str,"%s.out",s);freopen(str,"w",stdout);
#endif
}
template <class T>
int upmin(T &a, const T &b){return (b<a?a=b,1:0);}
template <class T>
int upmax(T &a, const T &b){return (b>a?a=b,1:0);}
namespace io
{
	const int SIZE=(1<<20)+1;
	char ibuf[SIZE],*iS,*iT;
	char obuf[SIZE],*oS=obuf,*oT=oS+SIZE-1;
	int getc()
	{
		(iS==iT?iS=ibuf,iT=ibuf+fread(ibuf,1,SIZE,stdin):0);
		return iS==iT?EOF:*(iS++);
	}
	int f;
	char c;
	template <class T>
	void get(T &x)
	{
		f=1;
		for(c=getc();(c<'0'||c>'9')&&c!='-';c=getc());
		(c=='-'?f=-1,c=getc():0);
		x=0;
		for(;c>='0'&&c<='9';c=getc())
			x=x*10+c-'0';
		x*=f;
	}
	void flush()
	{
		fwrite(obuf,1,oS-obuf,stdout);
		oS=obuf;
	}
	void putc(char x)
	{
		*(oS++)=x;
		if(oS==oT)
			flush();
	}
	int a[55],t;
	template <class T>
	void put(T x)
	{
		if(!x)
			putc('0');
		x<0?putc('-'),x=-x:0;
		while(x)
		{
			a[++t]=x%10;
			x/=10;
		}
		while(t)
			putc(a[t--]+'0');
	}
	void space()
	{
		putc(' ');
	}
	void enter()
	{
		putc('\n');
	}
	struct flusher
	{
		~flusher()
		{
			flush();
		}
	}
	io_flusher;
}
const int N=100010;
vector<int> g[N];
int s1[N];
int s2[N];
int d[N];
void dfs(int x,int fa)
{
	s1[x]=0;
	int num=0;
	for(auto v:g[x])
		if(v!=fa)
		{
			dfs(v,x);
			s1[x]+=s1[v];
			if(!s1[v])
				num++;
		}
	if(num)
		s1[x]+=num-1;
}
void dfs2(int x,int fa)
{
	int temp1=s2[x];
	int temp2=(fa?(s2[x]?0:1):0);
	for(auto v:g[x])
		if(v!=fa)
		{
			temp1+=s1[v];
			temp2+=(s1[v]?0:1);
		}
	for(auto v:g[x])
		if(v!=fa)
		{
			s2[v]=temp1-s1[v]+(temp2-!s1[v]?temp2-!s1[v]-1:0);
			dfs2(v,x);
		}
}
void solve()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		d[i]=0;
		g[i].clear();
	}
	int x,y;
	for(int i=1;i<n;i++)
	{
		scanf("%d%d",&x,&y);
      x++;
      y++;
		g[x].push_back(y);
		g[y].push_back(x);
		d[x]++;
		d[y]++;
	}
	dfs(1,0);
	dfs2(1,0);
	int ans=0x7fffffff;
	for(int i=1;i<=n;i++)
		ans=min(ans,s1[i]+s2[i]+1);
	printf("%d\n",ans);
}
int main()
{
	open2("g");
		solve();
	return 0;
}

Measured memory_bytes: 15232
import java.util.Scanner;

public class Main{
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int count = 1;
        while (true){
            int check = sc.nextInt();
            if (check == 0)
                break;
            else
                System.out.println("Case " + count + ": " + check);
            count++;
        }
    }
}



Measured memory_bytes: 41932
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a , n) for(int i = 0 ; i < n ; i++)cout << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll> 
#define inf 1000000000
#define mod 1000000007

const int max_n = 1e5 + 9;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
int main()
{
    string s;
    cin >> s;
    int n = s.size();
    if(s[0] == '0' || s[n-1] == '1'){
        cout << -1;
        return 0;
    }
    vector<int> vec;
    for(int i = 0 ; i < n-1 ; i++){
        if(s[i] != s[n-2-i]){
            cout << -1;
            return 0;
        }
        if(s[i] == '1'){
            vec.pb(i);
        }
    }

    int k = vec.size();
    int cnt = 1;
    for(int i = 0 ; i < k ; i++){
        cout << cnt << " " << cnt + 1 << endl;
        cnt++;
    }
    cnt++;
    for(int i = 1 ; i < k ; i++){
        for(int j = 0 ; j < vec[i] - vec[i-1] - 1 ; j++){
            cout << i+1 << " " << cnt++ << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2040
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using Pi_i = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;
using VLL = vector<ll>;
using VS = vector<string>;
using VC = vector<char>;
using VB = vector<bool>;

const int MOD = 1000000007;
const int INF = 1000000000;

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



VI w;
int n, k;
int checknum(ll P){ //詰める荷物の量
    int i = 0;
    for(int j = 0; j < k; ++j){
        ll s = 0;
        while(s + w[i] <= P){
            s += w[i];
            ++i;
            if(i == n) return n;
        }
    }
    return i;
}

int main(){
    int maxw = 0; cin >> n >> k;
    w.resize(n);
    REP(i, n){
        cin >> w[i]; chmax(maxw, w[i]);
    }
    ll lt = 0, rt = (ll)maxw * n;
    while(rt > lt + 1){//最後はlt:できないギリギリ rt: ギリギリ積める
        ll mid = (lt+rt)/2;
        int pos = checknum(mid);
        if(pos >= n) rt = mid;
        else lt = mid;
    }
    cout << rt << "\n";
    return 0;
}


Measured memory_bytes: 3132